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

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: Created 8 years, 7 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
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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 if (!enclosing_window) 539 if (!enclosing_window)
540 return gfx::Rect(); 540 return gfx::Rect();
541 541
542 NSRect bounds = [cocoa_view_ bounds]; 542 NSRect bounds = [cocoa_view_ bounds];
543 bounds = [cocoa_view_ convertRect:bounds toView:nil]; 543 bounds = [cocoa_view_ convertRect:bounds toView:nil];
544 bounds.origin = [enclosing_window convertBaseToScreen:bounds.origin]; 544 bounds.origin = [enclosing_window convertBaseToScreen:bounds.origin];
545 return FlipNSRectToRectScreen(bounds); 545 return FlipNSRectToRectScreen(bounds);
546 } 546 }
547 547
548 void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) { 548 void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) {
549 current_cursor_ = cursor; 549 WebCursor web_cursor = cursor;
Avi (use Gerrit) 2012/05/24 15:14:49 Why this copy? If GetNativeCursor() isn't const, c
550 UpdateCursorIfNecessary(); 550 [cocoa_view_ updateCursor:web_cursor.GetNativeCursor()];
551 }
552
553 void RenderWidgetHostViewMac::UpdateCursorIfNecessary() {
554 // Do something special (as Win Chromium does) for arrow cursor while loading
555 // a page? TODO(avi): decide
556
557 // Don't update the cursor if a context menu is being shown.
558 if (IsShowingContextMenu())
559 return;
560
561 // Can we synchronize to the event stream? Switch to -[NSWindow
562 // mouseLocationOutsideOfEventStream] if we cannot. TODO(avi): test and see
563 NSEvent* event = [[cocoa_view_ window] currentEvent];
564 if ([event window] != [cocoa_view_ window])
565 return;
566
567 NSCursor* ns_cursor = current_cursor_.GetNativeCursor();
568 [ns_cursor set];
569 } 551 }
570 552
571 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { 553 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) {
572 is_loading_ = is_loading; 554 is_loading_ = is_loading;
573 // If we ever decide to show the waiting cursor while the page is loading 555 // If we ever decide to show the waiting cursor while the page is loading
574 // like Chrome does on Windows, call |UpdateCursorIfNecessary()| here. 556 // like Chrome does on Windows, call |UpdateCursor()| here.
575 } 557 }
576 558
577 void RenderWidgetHostViewMac::TextInputStateChanged( 559 void RenderWidgetHostViewMac::TextInputStateChanged(
578 ui::TextInputType type, 560 ui::TextInputType type,
579 bool can_compose_inline) { 561 bool can_compose_inline) {
580 if (text_input_type_ != type || can_compose_inline_ != can_compose_inline) { 562 if (text_input_type_ != type || can_compose_inline_ != can_compose_inline) {
581 text_input_type_ = type; 563 text_input_type_ = type;
582 can_compose_inline_ = can_compose_inline; 564 can_compose_inline_ = can_compose_inline;
583 if (HasFocus()) { 565 if (HasFocus()) {
584 SetTextInputActive(true); 566 SetTextInputActive(true);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // markedRange immediately after calling setMarkdText: returns the current 726 // markedRange immediately after calling setMarkdText: returns the current
745 // caret position. 727 // caret position.
746 if (![cocoa_view_ hasMarkedText]) { 728 if (![cocoa_view_ hasMarkedText]) {
747 [cocoa_view_ setMarkedRange:range.ToNSRange()]; 729 [cocoa_view_ setMarkedRange:range.ToNSRange()];
748 } 730 }
749 } 731 }
750 732
751 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { 733 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) {
752 content::RenderWidgetHostViewBase::SetShowingContextMenu(showing); 734 content::RenderWidgetHostViewBase::SetShowingContextMenu(showing);
753 735
754 // If the menu was closed, restore the cursor to the saved version initially,
755 // as the renderer will not re-send it if there was no change.
756 if (!showing)
757 UpdateCursorIfNecessary();
758
759 // Create a fake mouse event to inform the render widget that the mouse 736 // Create a fake mouse event to inform the render widget that the mouse
760 // left or entered. 737 // left or entered.
761 NSWindow* window = [cocoa_view_ window]; 738 NSWindow* window = [cocoa_view_ window];
762 // TODO(asvitkine): If the location outside of the event stream doesn't 739 // TODO(asvitkine): If the location outside of the event stream doesn't
763 // correspond to the current event (due to delayed event processing), then 740 // correspond to the current event (due to delayed event processing), then
764 // this may result in a cursor flicker if there are later mouse move events 741 // this may result in a cursor flicker if there are later mouse move events
765 // in the pipeline. Find a way to use the mouse location from the event that 742 // in the pipeline. Find a way to use the mouse location from the event that
766 // dismissed the context menu. 743 // dismissed the context menu.
767 NSPoint location = [window mouseLocationOutsideOfEventStream]; 744 NSPoint location = [window mouseLocationOutsideOfEventStream];
768 NSEvent* event = [NSEvent mouseEventWithType:NSMouseMoved 745 NSEvent* event = [NSEvent mouseEventWithType:NSMouseMoved
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 // RenderWidgetHostViewCocoa --------------------------------------------------- 1214 // RenderWidgetHostViewCocoa ---------------------------------------------------
1238 1215
1239 @implementation RenderWidgetHostViewCocoa 1216 @implementation RenderWidgetHostViewCocoa
1240 1217
1241 @synthesize selectedRange = selectedRange_; 1218 @synthesize selectedRange = selectedRange_;
1242 @synthesize markedRange = markedRange_; 1219 @synthesize markedRange = markedRange_;
1243 1220
1244 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { 1221 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r {
1245 self = [super initWithFrame:NSZeroRect]; 1222 self = [super initWithFrame:NSZeroRect];
1246 if (self) { 1223 if (self) {
1224 current_cursor_ = nil;
1225
1247 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); 1226 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper);
1248 editCommand_helper_->AddEditingSelectorsToClass([self class]); 1227 editCommand_helper_->AddEditingSelectorsToClass([self class]);
1249 1228
1250 renderWidgetHostView_.reset(r); 1229 renderWidgetHostView_.reset(r);
1251 canBeKeyView_ = YES; 1230 canBeKeyView_ = YES;
1252 focusedPluginIdentifier_ = -1; 1231 focusedPluginIdentifier_ = -1;
1253 1232
1254 // OpenGL support: 1233 // OpenGL support:
1255 handlingGlobalFrameDidChange_ = NO; 1234 handlingGlobalFrameDidChange_ = NO;
1256 [[NSNotificationCenter defaultCenter] 1235 [[NSNotificationCenter defaultCenter]
1257 addObserver:self 1236 addObserver:self
1258 selector:@selector(globalFrameDidChange:) 1237 selector:@selector(globalFrameDidChange:)
1259 name:NSViewGlobalFrameDidChangeNotification 1238 name:NSViewGlobalFrameDidChangeNotification
1260 object:self]; 1239 object:self];
1261 } 1240 }
1262 return self; 1241 return self;
1263 } 1242 }
1264 1243
1265 - (void)dealloc { 1244 - (void)dealloc {
1266 if (delegate_ && [delegate_ respondsToSelector:@selector(viewGone:)]) 1245 if (delegate_ && [delegate_ respondsToSelector:@selector(viewGone:)])
1267 [delegate_ viewGone:self]; 1246 [delegate_ viewGone:self];
1268 [[NSNotificationCenter defaultCenter] removeObserver:self]; 1247 [[NSNotificationCenter defaultCenter] removeObserver:self];
1269 1248
1249 [current_cursor_ release];
1250 current_cursor_ = nil;
1251
1270 [super dealloc]; 1252 [super dealloc];
1271 } 1253 }
1272 1254
1255 - (void)resetCursorRects {
1256 [self addCursorRect:[self visibleRect] cursor:current_cursor_];
1257 [current_cursor_ setOnMouseEntered:YES];
1258 }
1259
1273 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate { 1260 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate {
1274 delegate_ = delegate; 1261 delegate_ = delegate;
1275 } 1262 }
1276 1263
1277 - (void)gotUnhandledWheelEvent { 1264 - (void)gotUnhandledWheelEvent {
1278 if (delegate_ && 1265 if (delegate_ &&
1279 [delegate_ respondsToSelector:@selector(gotUnhandledWheelEvent)]) { 1266 [delegate_ respondsToSelector:@selector(gotUnhandledWheelEvent)]) {
1280 [delegate_ gotUnhandledWheelEvent]; 1267 [delegate_ gotUnhandledWheelEvent];
1281 } 1268 }
1282 } 1269 }
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after
2862 widget->Send(new ViewMsg_SetInLiveResize(widget->GetRoutingID(), true)); 2849 widget->Send(new ViewMsg_SetInLiveResize(widget->GetRoutingID(), true));
2863 } 2850 }
2864 2851
2865 - (void)viewDidEndLiveResize { 2852 - (void)viewDidEndLiveResize {
2866 [super viewDidEndLiveResize]; 2853 [super viewDidEndLiveResize];
2867 RenderWidgetHostImpl* widget = renderWidgetHostView_->render_widget_host_; 2854 RenderWidgetHostImpl* widget = renderWidgetHostView_->render_widget_host_;
2868 if (widget) 2855 if (widget)
2869 widget->Send(new ViewMsg_SetInLiveResize(widget->GetRoutingID(), false)); 2856 widget->Send(new ViewMsg_SetInLiveResize(widget->GetRoutingID(), false));
2870 } 2857 }
2871 2858
2859 - (void)updateCursor:(NSCursor*)cursor {
2860 if (current_cursor_ == cursor)
2861 return;
2862
2863 [current_cursor_ release];
2864 current_cursor_ = [cursor retain];
2865 [[self window] invalidateCursorRectsForView:self];
Avi (use Gerrit) 2012/05/24 15:14:49 That is... elegant. Wow.
2866 }
2867
2872 @end 2868 @end
2873 2869
2874 // 2870 //
2875 // Supporting application services 2871 // Supporting application services
2876 // 2872 //
2877 @implementation RenderWidgetHostViewCocoa(NSServicesRequests) 2873 @implementation RenderWidgetHostViewCocoa(NSServicesRequests)
2878 2874
2879 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard 2875 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard
2880 types:(NSArray*)types { 2876 types:(NSArray*)types {
2881 const std::string& str = renderWidgetHostView_->selected_text(); 2877 const std::string& str = renderWidgetHostView_->selected_text();
(...skipping 11 matching lines...) Expand all
2893 if (!string) return NO; 2889 if (!string) return NO;
2894 2890
2895 // If the user is currently using an IME, confirm the IME input, 2891 // If the user is currently using an IME, confirm the IME input,
2896 // and then insert the text from the service, the same as TextEdit and Safari. 2892 // and then insert the text from the service, the same as TextEdit and Safari.
2897 [self confirmComposition]; 2893 [self confirmComposition];
2898 [self insertText:string]; 2894 [self insertText:string];
2899 return YES; 2895 return YES;
2900 } 2896 }
2901 2897
2902 @end 2898 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698