Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 10450012: Apply a CursorRect to the extent of the render widget view for web page cursors. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Build fix -- trivial namespace update Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #include <QuartzCore/QuartzCore.h> 7 #include <QuartzCore/QuartzCore.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 if (!enclosing_window) 553 if (!enclosing_window)
554 return gfx::Rect(); 554 return gfx::Rect();
555 555
556 NSRect bounds = [cocoa_view_ bounds]; 556 NSRect bounds = [cocoa_view_ bounds];
557 bounds = [cocoa_view_ convertRect:bounds toView:nil]; 557 bounds = [cocoa_view_ convertRect:bounds toView:nil];
558 bounds.origin = [enclosing_window convertBaseToScreen:bounds.origin]; 558 bounds.origin = [enclosing_window convertBaseToScreen:bounds.origin];
559 return FlipNSRectToRectScreen(bounds); 559 return FlipNSRectToRectScreen(bounds);
560 } 560 }
561 561
562 void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) { 562 void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) {
563 current_cursor_ = cursor; 563 WebCursor web_cursor = cursor;
564 UpdateCursorIfNecessary(); 564 [cocoa_view_ updateCursor:web_cursor.GetNativeCursor()];
565 }
566
567 void RenderWidgetHostViewMac::UpdateCursorIfNecessary() {
568 // Do something special (as Win Chromium does) for arrow cursor while loading
569 // a page? TODO(avi): decide
570
571 // Don't update the cursor if a context menu is being shown.
572 if (IsShowingContextMenu())
573 return;
574
575 // Can we synchronize to the event stream? Switch to -[NSWindow
576 // mouseLocationOutsideOfEventStream] if we cannot. TODO(avi): test and see
577 NSEvent* event = [[cocoa_view_ window] currentEvent];
578 if ([event window] != [cocoa_view_ window])
579 return;
580
581 NSCursor* ns_cursor = current_cursor_.GetNativeCursor();
582 [ns_cursor set];
583 } 565 }
584 566
585 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { 567 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) {
586 is_loading_ = is_loading; 568 is_loading_ = is_loading;
587 // If we ever decide to show the waiting cursor while the page is loading 569 // If we ever decide to show the waiting cursor while the page is loading
588 // like Chrome does on Windows, call |UpdateCursorIfNecessary()| here. 570 // like Chrome does on Windows, call |UpdateCursor()| here.
589 } 571 }
590 572
591 void RenderWidgetHostViewMac::TextInputStateChanged( 573 void RenderWidgetHostViewMac::TextInputStateChanged(
592 ui::TextInputType type, 574 ui::TextInputType type,
593 bool can_compose_inline) { 575 bool can_compose_inline) {
594 if (text_input_type_ != type || can_compose_inline_ != can_compose_inline) { 576 if (text_input_type_ != type || can_compose_inline_ != can_compose_inline) {
595 text_input_type_ = type; 577 text_input_type_ = type;
596 can_compose_inline_ = can_compose_inline; 578 can_compose_inline_ = can_compose_inline;
597 if (HasFocus()) { 579 if (HasFocus()) {
598 SetTextInputActive(true); 580 SetTextInputActive(true);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 // markedRange immediately after calling setMarkdText: returns the current 742 // markedRange immediately after calling setMarkdText: returns the current
761 // caret position. 743 // caret position.
762 if (![cocoa_view_ hasMarkedText]) { 744 if (![cocoa_view_ hasMarkedText]) {
763 [cocoa_view_ setMarkedRange:range.ToNSRange()]; 745 [cocoa_view_ setMarkedRange:range.ToNSRange()];
764 } 746 }
765 } 747 }
766 748
767 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { 749 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) {
768 content::RenderWidgetHostViewBase::SetShowingContextMenu(showing); 750 content::RenderWidgetHostViewBase::SetShowingContextMenu(showing);
769 751
770 // If the menu was closed, restore the cursor to the saved version initially,
771 // as the renderer will not re-send it if there was no change.
772 if (!showing)
773 UpdateCursorIfNecessary();
774
775 // Create a fake mouse event to inform the render widget that the mouse 752 // Create a fake mouse event to inform the render widget that the mouse
776 // left or entered. 753 // left or entered.
777 NSWindow* window = [cocoa_view_ window]; 754 NSWindow* window = [cocoa_view_ window];
778 // TODO(asvitkine): If the location outside of the event stream doesn't 755 // TODO(asvitkine): If the location outside of the event stream doesn't
779 // correspond to the current event (due to delayed event processing), then 756 // correspond to the current event (due to delayed event processing), then
780 // this may result in a cursor flicker if there are later mouse move events 757 // this may result in a cursor flicker if there are later mouse move events
781 // in the pipeline. Find a way to use the mouse location from the event that 758 // in the pipeline. Find a way to use the mouse location from the event that
782 // dismissed the context menu. 759 // dismissed the context menu.
783 NSPoint location = [window mouseLocationOutsideOfEventStream]; 760 NSPoint location = [window mouseLocationOutsideOfEventStream];
784 NSEvent* event = [NSEvent mouseEventWithType:NSMouseMoved 761 NSEvent* event = [NSEvent mouseEventWithType:NSMouseMoved
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 } 1289 }
1313 1290
1314 - (void)dealloc { 1291 - (void)dealloc {
1315 if (delegate_ && [delegate_ respondsToSelector:@selector(viewGone:)]) 1292 if (delegate_ && [delegate_ respondsToSelector:@selector(viewGone:)])
1316 [delegate_ viewGone:self]; 1293 [delegate_ viewGone:self];
1317 [[NSNotificationCenter defaultCenter] removeObserver:self]; 1294 [[NSNotificationCenter defaultCenter] removeObserver:self];
1318 1295
1319 [super dealloc]; 1296 [super dealloc];
1320 } 1297 }
1321 1298
1299 - (void)resetCursorRects {
1300 if (currentCursor_) {
1301 [self addCursorRect:[self visibleRect] cursor:currentCursor_];
1302 [currentCursor_ setOnMouseEntered:YES];
1303 }
1304 }
1305
1322 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate { 1306 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate {
1323 delegate_ = delegate; 1307 delegate_ = delegate;
1324 } 1308 }
1325 1309
1326 - (void)gotUnhandledWheelEvent { 1310 - (void)gotUnhandledWheelEvent {
1327 if (delegate_ && 1311 if (delegate_ &&
1328 [delegate_ respondsToSelector:@selector(gotUnhandledWheelEvent)]) { 1312 [delegate_ respondsToSelector:@selector(gotUnhandledWheelEvent)]) {
1329 [delegate_ gotUnhandledWheelEvent]; 1313 [delegate_ gotUnhandledWheelEvent];
1330 } 1314 }
1331 } 1315 }
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
2917 widget->Send(new ViewMsg_SetInLiveResize(widget->GetRoutingID(), true)); 2901 widget->Send(new ViewMsg_SetInLiveResize(widget->GetRoutingID(), true));
2918 } 2902 }
2919 2903
2920 - (void)viewDidEndLiveResize { 2904 - (void)viewDidEndLiveResize {
2921 [super viewDidEndLiveResize]; 2905 [super viewDidEndLiveResize];
2922 RenderWidgetHostImpl* widget = renderWidgetHostView_->render_widget_host_; 2906 RenderWidgetHostImpl* widget = renderWidgetHostView_->render_widget_host_;
2923 if (widget) 2907 if (widget)
2924 widget->Send(new ViewMsg_SetInLiveResize(widget->GetRoutingID(), false)); 2908 widget->Send(new ViewMsg_SetInLiveResize(widget->GetRoutingID(), false));
2925 } 2909 }
2926 2910
2911 - (void)updateCursor:(NSCursor*)cursor {
2912 if (currentCursor_ == cursor)
2913 return;
2914
2915 currentCursor_.reset(cursor, base::scoped_policy::RETAIN);
2916 [[self window] invalidateCursorRectsForView:self];
2917 }
2918
2927 @end 2919 @end
2928 2920
2929 // 2921 //
2930 // Supporting application services 2922 // Supporting application services
2931 // 2923 //
2932 @implementation RenderWidgetHostViewCocoa(NSServicesRequests) 2924 @implementation RenderWidgetHostViewCocoa(NSServicesRequests)
2933 2925
2934 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard 2926 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard
2935 types:(NSArray*)types { 2927 types:(NSArray*)types {
2936 const std::string& str = renderWidgetHostView_->selected_text(); 2928 const std::string& str = renderWidgetHostView_->selected_text();
(...skipping 11 matching lines...) Expand all
2948 if (!string) return NO; 2940 if (!string) return NO;
2949 2941
2950 // If the user is currently using an IME, confirm the IME input, 2942 // If the user is currently using an IME, confirm the IME input,
2951 // and then insert the text from the service, the same as TextEdit and Safari. 2943 // and then insert the text from the service, the same as TextEdit and Safari.
2952 [self confirmComposition]; 2944 [self confirmComposition];
2953 [self insertText:string]; 2945 [self insertText:string];
2954 return YES; 2946 return YES;
2955 } 2947 }
2956 2948
2957 @end 2949 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698