diff options
-rw-r--r-- | chrome/browser/browser.cc | 9 | ||||
-rw-r--r-- | chrome/browser/browser.h | 6 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_delegate.h | 4 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_view_gtk.cc | 22 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_view_mac.mm | 11 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_view_win.cc | 5 |
6 files changed, 43 insertions, 14 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 9e7853b..0ecc721 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1797,21 +1797,18 @@ void Browser::URLStarredChanged(TabContents* source, bool starred) { window_->SetStarredState(starred); } -#if defined(OS_WIN) -// TODO(port): Refactor this to win-specific delegate? -void Browser::ContentsMouseEvent(TabContents* source, UINT message) { +void Browser::ContentsMouseEvent(TabContents* source, bool motion) { if (!GetStatusBubble()) return; if (source == GetSelectedTabContents()) { - if (message == WM_MOUSEMOVE) { + if (motion) { GetStatusBubble()->MouseMoved(); - } else if (message == WM_MOUSELEAVE) { + } else { GetStatusBubble()->SetURL(GURL(), std::wstring()); } } } -#endif void Browser::UpdateTargetURL(TabContents* source, const GURL& url) { if (!GetStatusBubble()) diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 0526a2c..9bf94b0 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -425,9 +425,9 @@ class Browser : public TabStripModelDelegate, virtual void ToolbarSizeChanged(TabContents* source, bool is_animating); virtual void URLStarredChanged(TabContents* source, bool starred); -#if defined(OS_WIN) - virtual void ContentsMouseEvent(TabContents* source, uint32 message); -#endif + // A mouse event occurred; motion==true is mouse movement, motion==false + // is the mouse leaving the view. + virtual void ContentsMouseEvent(TabContents* source, bool motion); virtual void UpdateTargetURL(TabContents* source, const GURL& url); virtual void ContentsZoomChange(bool zoom_in); diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index 74cee1e..b7b0825 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -88,8 +88,8 @@ class TabContentsDelegate : public PageNavigator { // Notification that the target URL has changed virtual void UpdateTargetURL(TabContents* source, const GURL& url) = 0; - // Notification that the target URL has changed - virtual void ContentsMouseEvent(TabContents* source, uint32 message) { } + // Notification that there was a mouse event + virtual void ContentsMouseEvent(TabContents* source, bool motion) { } // Request the delegate to change the zoom level of the current tab. virtual void ContentsZoomChange(bool zoom_in) { } diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.cc b/chrome/browser/tab_contents/web_contents_view_gtk.cc index dbb8bc9..c3345cb 100644 --- a/chrome/browser/tab_contents/web_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/web_contents_view_gtk.cc @@ -36,6 +36,22 @@ gboolean OnFocus(GtkWidget* widget, GtkDirectionType focus, return TRUE; } +// Called when the mouse leaves the widget. We notify our delegate. +gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event, + WebContents* web_contents) { + if (web_contents->delegate()) + web_contents->delegate()->ContentsMouseEvent(web_contents, false); + return FALSE; +} + +// Called when the mouse moves within the widget. We notify our delegate. +gboolean OnMouseMove(GtkWidget* widget, GdkEventMotion* event, + WebContents* web_contents) { + if (web_contents->delegate()) + web_contents->delegate()->ContentsMouseEvent(web_contents, true); + return FALSE; +} + // Callback used in WebContentsViewGtk::CreateViewForWidget(). void RemoveWidget(GtkWidget* widget, gpointer container) { gtk_container_remove(GTK_CONTAINER(container), widget); @@ -73,6 +89,12 @@ RenderWidgetHostView* WebContentsViewGtk::CreateViewForWidget( view->InitAsChild(); g_signal_connect(view->native_view(), "focus", G_CALLBACK(OnFocus), web_contents_); + g_signal_connect(view->native_view(), "leave-notify-event", + G_CALLBACK(OnLeaveNotify), web_contents_); + g_signal_connect(view->native_view(), "motion-notify-event", + G_CALLBACK(OnMouseMove), web_contents_); + gtk_widget_add_events(view->native_view(), GDK_LEAVE_NOTIFY_MASK | + GDK_POINTER_MOTION_MASK); gtk_container_foreach(GTK_CONTAINER(vbox_.get()), RemoveWidget, vbox_.get()); gtk_box_pack_start(GTK_BOX(vbox_.get()), view->native_view(), TRUE, TRUE, 0); return view; diff --git a/chrome/browser/tab_contents/web_contents_view_mac.mm b/chrome/browser/tab_contents/web_contents_view_mac.mm index c5ddaf3..a63cf86 100644 --- a/chrome/browser/tab_contents/web_contents_view_mac.mm +++ b/chrome/browser/tab_contents/web_contents_view_mac.mm @@ -264,6 +264,17 @@ void WebContentsViewMac::Observe(NotificationType type, [super keyUp:event]; } +- (void)mouseEvent:(NSEvent *)theEvent { + if (webContentsView_->GetWebContents()->delegate()) { + if ([theEvent type] == NSMouseMoved) + webContentsView_->GetWebContents()->delegate()-> + ContentsMouseEvent(webContentsView_->GetWebContents(), true); + if ([theEvent type] == NSMouseExited) + webContentsView_->GetWebContents()->delegate()-> + ContentsMouseEvent(webContentsView_->GetWebContents(), false); + } +} + // In the Windows version, we always have cut/copy/paste enabled. This is sub- // optimal, but we do it too. TODO(avi): Plumb the "can*" methods up from // WebCore. diff --git a/chrome/browser/tab_contents/web_contents_view_win.cc b/chrome/browser/tab_contents/web_contents_view_win.cc index 0446368..acd4349 100644 --- a/chrome/browser/tab_contents/web_contents_view_win.cc +++ b/chrome/browser/tab_contents/web_contents_view_win.cc @@ -470,7 +470,7 @@ void WebContentsViewWin::OnMouseLeave() { // Let our delegate know that the mouse moved (useful for resetting status // bubble state). if (web_contents_->delegate()) - web_contents_->delegate()->ContentsMouseEvent(web_contents_, WM_MOUSELEAVE); + web_contents_->delegate()->ContentsMouseEvent(web_contents_, false); SetMsgHandled(FALSE); } @@ -493,8 +493,7 @@ LRESULT WebContentsViewWin::OnMouseRange(UINT msg, // Let our delegate know that the mouse moved (useful for resetting status // bubble state). if (web_contents_->delegate()) { - web_contents_->delegate()->ContentsMouseEvent(web_contents_, - WM_MOUSEMOVE); + web_contents_->delegate()->ContentsMouseEvent(web_contents_, true); } break; default: |