From 92cdabdebc9082f557265390a017ad6a59df2460 Mon Sep 17 00:00:00 2001 From: "sadrul@chromium.org" Date: Wed, 13 Jul 2011 02:44:45 +0000 Subject: ClearNativeFocus: Do it from widget, with appropriate native-widget implementation. BUG=none TEST=none Review URL: http://codereview.chromium.org/7353007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92303 0039d316-1c4b-4281-b951-d872f2087c98 --- views/widget/native_widget_gtk.cc | 18 +++++++++--------- views/widget/native_widget_gtk.h | 4 +--- views/widget/native_widget_private.h | 1 + views/widget/native_widget_views.cc | 4 ++++ views/widget/native_widget_views.h | 1 + views/widget/native_widget_win.cc | 4 ++++ views/widget/native_widget_win.h | 1 + views/widget/widget.cc | 4 ++++ views/widget/widget.h | 3 +++ 9 files changed, 28 insertions(+), 12 deletions(-) (limited to 'views/widget') diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index eb614ea..199160e 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -577,15 +577,6 @@ void NativeWidgetGtk::ActiveWindowChanged(GdkWindow* active_window) { //////////////////////////////////////////////////////////////////////////////// // NativeWidgetGtk implementation: -void NativeWidgetGtk::ClearNativeFocus() { - DCHECK(!child_); - if (!GetNativeView()) { - NOTREACHED(); - return; - } - gtk_window_set_focus(GTK_WINDOW(GetNativeView()), NULL); -} - bool NativeWidgetGtk::HandleKeyboardEvent(const KeyEvent& key) { if (!GetWidget()->GetFocusManager()) return false; @@ -1278,6 +1269,15 @@ void NativeWidgetGtk::SetCursor(gfx::NativeCursor cursor) { gdk_window_set_cursor(window_contents_->window, cursor); } +void NativeWidgetGtk::ClearNativeFocus() { + DCHECK(!child_); + if (!GetNativeView()) { + NOTREACHED(); + return; + } + gtk_window_set_focus(GTK_WINDOW(GetNativeView()), NULL); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWidgetGtk, protected: diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h index 3473b33..b346e26 100644 --- a/views/widget/native_widget_gtk.h +++ b/views/widget/native_widget_gtk.h @@ -111,9 +111,6 @@ class NativeWidgetGtk : public internal::NativeWidgetPrivate, // Overridden from ui::ActiveWindowWatcherX::Observer. virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; - // Clears the focus on the native widget having the focus. - virtual void ClearNativeFocus(); - // Handles a keyboard event by sending it to our focus manager. // Returns true if it's handled by the focus manager. bool HandleKeyboardEvent(const KeyEvent& key); @@ -230,6 +227,7 @@ class NativeWidgetGtk : public internal::NativeWidgetPrivate, int operation) OVERRIDE; virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; + virtual void ClearNativeFocus() OVERRIDE; protected: // Modifies event coordinates to the targeted widget contained by this widget. diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h index dab73f2..f9ba979 100644 --- a/views/widget/native_widget_private.h +++ b/views/widget/native_widget_private.h @@ -205,6 +205,7 @@ class NativeWidgetPrivate : public NativeWidget { int operation) = 0; virtual void SchedulePaintInRect(const gfx::Rect& rect) = 0; virtual void SetCursor(gfx::NativeCursor cursor) = 0; + virtual void ClearNativeFocus() = 0; // Overridden from NativeWidget: virtual internal::NativeWidgetPrivate* AsNativeWidgetPrivate() OVERRIDE; diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index 6c6bbcc..f92627e 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -394,6 +394,10 @@ void NativeWidgetViews::SetCursor(gfx::NativeCursor cursor) { GetParentNativeWidget()->SetCursor(cursor); } +void NativeWidgetViews::ClearNativeFocus() { + GetParentNativeWidget()->ClearNativeFocus(); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWidgetViews, private: diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index d2c81fa..e3d3edc 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -114,6 +114,7 @@ class NativeWidgetViews : public internal::NativeWidgetPrivate { int operation) OVERRIDE; virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; + virtual void ClearNativeFocus() OVERRIDE; private: // These functions may return NULL during Widget destruction. diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index 8d2420e..83e6126 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -1076,6 +1076,10 @@ void NativeWidgetWin::SetCursor(gfx::NativeCursor cursor) { } } +void NativeWidgetWin::ClearNativeFocus() { + ::SetFocus(GetNativeView()); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWidgetWin, MessageLoop::Observer implementation: diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h index eb8d391..53457dc 100644 --- a/views/widget/native_widget_win.h +++ b/views/widget/native_widget_win.h @@ -265,6 +265,7 @@ class NativeWidgetWin : public ui::WindowImpl, int operation) OVERRIDE; virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; + virtual void ClearNativeFocus() OVERRIDE; protected: // Information saved before going into fullscreen mode, used to restore the diff --git a/views/widget/widget.cc b/views/widget/widget.cc index d309917..e668042 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -626,6 +626,10 @@ void Widget::SetFocusTraversableParentView(View* parent_view) { root_view_->SetFocusTraversableParentView(parent_view); } +void Widget::ClearNativeFocus() { + native_widget_->ClearNativeFocus(); +} + void Widget::UpdateFrameAfterFrameChange() { native_widget_->UpdateFrameAfterFrameChange(); } diff --git a/views/widget/widget.h b/views/widget/widget.h index 16d2d7a..3021518 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -425,6 +425,9 @@ class Widget : public internal::NativeWidgetDelegate, void SetFocusTraversableParent(FocusTraversable* parent); void SetFocusTraversableParentView(View* parent_view); + // Clear native focus set to the Widget's NativeWidget. + void ClearNativeFocus(); + // Updates the frame after an event caused it to be changed. virtual void UpdateFrameAfterFrameChange(); -- cgit v1.1