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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_view_mac.mm
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm
index 1d3ae76c5c430b830f661fe723811890dd0b3624..87d31b3817d6ae7570de7e542042f790135a79d3 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac.mm
@@ -546,32 +546,14 @@ gfx::Rect RenderWidgetHostViewMac::GetViewBounds() const {
}
void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) {
- current_cursor_ = cursor;
- UpdateCursorIfNecessary();
-}
-
-void RenderWidgetHostViewMac::UpdateCursorIfNecessary() {
- // Do something special (as Win Chromium does) for arrow cursor while loading
- // a page? TODO(avi): decide
-
- // Don't update the cursor if a context menu is being shown.
- if (IsShowingContextMenu())
- return;
-
- // Can we synchronize to the event stream? Switch to -[NSWindow
- // mouseLocationOutsideOfEventStream] if we cannot. TODO(avi): test and see
- NSEvent* event = [[cocoa_view_ window] currentEvent];
- if ([event window] != [cocoa_view_ window])
- return;
-
- NSCursor* ns_cursor = current_cursor_.GetNativeCursor();
- [ns_cursor set];
+ WebCursor web_cursor = cursor;
Avi (use Gerrit) 2012/05/24 15:14:49 Why this copy? If GetNativeCursor() isn't const, c
+ [cocoa_view_ updateCursor:web_cursor.GetNativeCursor()];
}
void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) {
is_loading_ = is_loading;
// If we ever decide to show the waiting cursor while the page is loading
- // like Chrome does on Windows, call |UpdateCursorIfNecessary()| here.
+ // like Chrome does on Windows, call |UpdateCursor()| here.
}
void RenderWidgetHostViewMac::TextInputStateChanged(
@@ -751,11 +733,6 @@ void RenderWidgetHostViewMac::SelectionChanged(const string16& text,
void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) {
content::RenderWidgetHostViewBase::SetShowingContextMenu(showing);
- // If the menu was closed, restore the cursor to the saved version initially,
- // as the renderer will not re-send it if there was no change.
- if (!showing)
- UpdateCursorIfNecessary();
-
// Create a fake mouse event to inform the render widget that the mouse
// left or entered.
NSWindow* window = [cocoa_view_ window];
@@ -1244,6 +1221,8 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
- (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r {
self = [super initWithFrame:NSZeroRect];
if (self) {
+ current_cursor_ = nil;
+
editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper);
editCommand_helper_->AddEditingSelectorsToClass([self class]);
@@ -1267,9 +1246,17 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
[delegate_ viewGone:self];
[[NSNotificationCenter defaultCenter] removeObserver:self];
+ [current_cursor_ release];
+ current_cursor_ = nil;
+
[super dealloc];
}
+- (void)resetCursorRects {
+ [self addCursorRect:[self visibleRect] cursor:current_cursor_];
+ [current_cursor_ setOnMouseEntered:YES];
+}
+
- (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate {
delegate_ = delegate;
}
@@ -2869,6 +2856,15 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
widget->Send(new ViewMsg_SetInLiveResize(widget->GetRoutingID(), false));
}
+- (void)updateCursor:(NSCursor*)cursor {
+ if (current_cursor_ == cursor)
+ return;
+
+ [current_cursor_ release];
+ current_cursor_ = [cursor retain];
+ [[self window] invalidateCursorRectsForView:self];
Avi (use Gerrit) 2012/05/24 15:14:49 That is... elegant. Wow.
+}
+
@end
//

Powered by Google App Engine
This is Rietveld 408576698