diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 20:18:54 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 20:18:54 +0000 |
commit | 0a6dc3a6ca8fd3e0d85a45fc99c646e4c68d1d6a (patch) | |
tree | 8f23cd8372918518ee812a007156497a07a41bb4 /views/controls/native | |
parent | 5f6791666943fb22e36717050383414136e5e9fc (diff) | |
download | chromium_src-0a6dc3a6ca8fd3e0d85a45fc99c646e4c68d1d6a.zip chromium_src-0a6dc3a6ca8fd3e0d85a45fc99c646e4c68d1d6a.tar.gz chromium_src-0a6dc3a6ca8fd3e0d85a45fc99c646e4c68d1d6a.tar.bz2 |
Reverting 27113, it breaks the ChomeOS build.
TBR=ben
Review URL: http://codereview.chromium.org/231022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/native')
-rw-r--r-- | views/controls/native/native_view_host.cc | 40 | ||||
-rw-r--r-- | views/controls/native/native_view_host.h | 35 | ||||
-rw-r--r-- | views/controls/native/native_view_host_gtk.cc | 27 | ||||
-rw-r--r-- | views/controls/native/native_view_host_gtk.h | 8 | ||||
-rw-r--r-- | views/controls/native/native_view_host_win.cc | 46 | ||||
-rw-r--r-- | views/controls/native/native_view_host_win.h | 18 | ||||
-rw-r--r-- | views/controls/native/native_view_host_wrapper.h | 3 |
7 files changed, 49 insertions, 128 deletions
diff --git a/views/controls/native/native_view_host.cc b/views/controls/native/native_view_host.cc index b5eb509..9cbeaf7 100644 --- a/views/controls/native/native_view_host.cc +++ b/views/controls/native/native_view_host.cc @@ -7,7 +7,6 @@ #include "base/logging.h" #include "app/gfx/canvas.h" #include "views/controls/native/native_view_host_wrapper.h" -#include "views/focus/focus_manager.h" #include "views/widget/widget.h" namespace views { @@ -21,10 +20,7 @@ const char NativeViewHost::kViewClassName[] = "views/NativeViewHost"; NativeViewHost::NativeViewHost() : native_view_(NULL), fast_resize_(false), - focus_native_view_(NULL) { - // By default we make this view the one that should be set as the focused view - // when the native view gets the focus. - focus_view_ = this; + focus_view_(NULL) { // The native widget is placed relative to the root. As such, we need to // know when the position of any ancestor changes, or our visibility relative // to other views changed as it'll effect our position relative to the root. @@ -37,12 +33,10 @@ NativeViewHost::~NativeViewHost() { void NativeViewHost::Attach(gfx::NativeView native_view) { DCHECK(!native_view_); native_view_ = native_view; - // If this NativeViewHost is the focus view, than it should obviously be - // focusable. If it is not, then it acts as a container and we don't want it - // to get focus through tab-traversal, so we make it not focusable. - SetFocusable(focus_view_ == this); - if (!focus_native_view_) - focus_native_view_ = native_view; + // If set_focus_view() has not been invoked, this view is the one that should + // be seen as focused when the native view receives focus. + if (!focus_view_) + focus_view_ = this; native_wrapper_->NativeViewAttached(); } @@ -50,7 +44,6 @@ void NativeViewHost::Detach() { DCHECK(native_view_); native_wrapper_->NativeViewDetaching(); native_view_ = NULL; - focus_native_view_ = NULL; } void NativeViewHost::SetPreferredSize(const gfx::Size& size) { @@ -64,22 +57,6 @@ void NativeViewHost::NativeViewDestroyed() { native_view_ = NULL; } -void NativeViewHost::GotNativeFocus() { - // Some NativeViewHost may not have an associated focus view. This is the - // case for containers for example. They might still get the native focus, - // if one non native view they contain gets focused. In that case, we should - // not change the focused view. - if (!focus_view_ || !focus_view_->IsFocusable()) - return; - - FocusManager* focus_manager = GetFocusManager(); - if (!focus_manager) { - NOTREACHED(); - return; - } - focus_manager->SetFocusedView(focus_view_); -} - //////////////////////////////////////////////////////////////////////////////// // NativeViewHost, View overrides: @@ -157,12 +134,7 @@ std::string NativeViewHost::GetClassName() const { } void NativeViewHost::Focus() { - FocusManager* focus_manager = GetFocusManager(); - if (!focus_manager) { - NOTREACHED(); - return; - } - focus_manager->FocusNativeView(focus_native_view_); + native_wrapper_->SetFocus(); } } // namespace views diff --git a/views/controls/native/native_view_host.h b/views/controls/native/native_view_host.h index d27a816e..679e176 100644 --- a/views/controls/native/native_view_host.h +++ b/views/controls/native/native_view_host.h @@ -42,27 +42,15 @@ class NativeViewHost : public View { // Sets a preferred size for the native view attached to this View. void SetPreferredSize(const gfx::Size& size); - // A NativeViewHost must keep the focused view in the focus manager and the - // native focus with in sync . There are 2 aspects to this: - // - when the native view receives focus, the focus manager must be notified - // that the associated view is now the focused view. - // In simple cases where the NativeViewHost directly wraps a native window - // as is, the associated view is this NativeViewHost. In other cases where - // the NativeViewHost is part of another view (such as for the TextField - // class), the actual View is not the NativeViewHost and set_focus_view() - // must be called to set the associated view before Attach() is called. - // - when the view is focused (by calling View::RequestFocus()), it must focus - // the appropriate native view. In simple cases where the native view does - // not have children or is the native view that should really get the focus, - // this works without doing anything. In case where the native view that - // should get the focus is not the native view passed to Attach(), then - // the appropriate native view should be specified to - // set_focus_native_view() before Attach() is called. + // A NativeViewHost has an associated focus View so that the focus of the + // native control and of the View are kept in sync. In simple cases where the + // NativeViewHost directly wraps a native window as is, the associated view + // is this View. In other cases where the NativeViewHost is part of another + // view (such as TextField), the actual View is not the NativeViewHost and + // this method must be called to set that. + // This method must be called before Attach(). void set_focus_view(View* view) { focus_view_ = view; } - void set_focus_native_view(gfx::NativeView native_view) { - focus_native_view_ = native_view; - } - gfx::NativeView focus_native_view() const { return focus_native_view_; } + View* focus_view() { return focus_view_; } // Fast resizing will move the native view and clip its visible region, this // will result in white areas and will not resize the content (so scrollbars @@ -76,10 +64,6 @@ class NativeViewHost : public View { // Accessor for |native_view_|. gfx::NativeView native_view() const { return native_view_; } - // Called by the NativeViewHostWrapper to notify that the |focus_native_view_| - // got focus. - void GotNativeFocus(); - void NativeViewDestroyed(); // Overridden from View: @@ -112,9 +96,6 @@ class NativeViewHost : public View { // The view that should be given focus when this NativeViewHost is focused. View* focus_view_; - // The native view that should get the focus when this View gets focused. - gfx::NativeView focus_native_view_; - DISALLOW_COPY_AND_ASSIGN(NativeViewHost); }; diff --git a/views/controls/native/native_view_host_gtk.cc b/views/controls/native/native_view_host_gtk.cc index 4b9fc0c..ea9bd62 100644 --- a/views/controls/native/native_view_host_gtk.cc +++ b/views/controls/native/native_view_host_gtk.cc @@ -48,7 +48,7 @@ void NativeViewHostGtk::NativeViewAttached() { } if (!focus_signal_id_) { - focus_signal_id_ = g_signal_connect(G_OBJECT(host_->focus_native_view()), + focus_signal_id_ = g_signal_connect(G_OBJECT(host_->native_view()), "focus-in-event", G_CALLBACK(CallFocusIn), this); } @@ -70,7 +70,7 @@ void NativeViewHostGtk::NativeViewDetaching() { destroy_signal_id_); destroy_signal_id_ = 0; - g_signal_handler_disconnect(G_OBJECT(host_->focus_native_view()), + g_signal_handler_disconnect(G_OBJECT(host_->native_view()), focus_signal_id_); focus_signal_id_ = 0; @@ -164,6 +164,11 @@ void NativeViewHostGtk::HideWidget() { gtk_widget_hide(fixed_); } +void NativeViewHostGtk::SetFocus() { + DCHECK(host_->native_view()); + gtk_widget_grab_focus(host_->native_view()); +} + //////////////////////////////////////////////////////////////////////////////// // NativeViewHostGtk, private: @@ -210,11 +215,19 @@ void NativeViewHostGtk::CallDestroy(GtkObject* object, } // static -gboolean NativeViewHostGtk::CallFocusIn(GtkWidget* widget, - GdkEventFocus* event, - NativeViewHostGtk* host) { - host->host_->GotNativeFocus(); - return false; +void NativeViewHostGtk::CallFocusIn(GtkWidget* widget, + GdkEventFocus* event, + NativeViewHostGtk* host) { + FocusManager* focus_manager = + FocusManager::GetFocusManagerForNativeView(widget); + if (!focus_manager) { + // TODO(jcampan): http://crbug.com/21378 Reenable this NOTREACHED() when the + // options page is only based on views. + // NOTREACHED(); + NOTIMPLEMENTED(); + return; + } + focus_manager->SetFocusedView(host->host_->focus_view()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/views/controls/native/native_view_host_gtk.h b/views/controls/native/native_view_host_gtk.h index 2e58bef..81a2a7a1 100644 --- a/views/controls/native/native_view_host_gtk.h +++ b/views/controls/native/native_view_host_gtk.h @@ -36,6 +36,7 @@ class NativeViewHostGtk : public NativeViewHostWrapper { virtual void UninstallClip(); virtual void ShowWidget(int x, int y, int w, int h); virtual void HideWidget(); + virtual void SetFocus(); private: // Create and Destroy the GtkFixed that performs clipping on our hosted @@ -54,9 +55,9 @@ class NativeViewHostGtk : public NativeViewHostWrapper { static void CallDestroy(GtkObject* object, NativeViewHostGtk* host); // Invoked from the 'focus-in-event' signal. - static gboolean CallFocusIn(GtkWidget* widget, - GdkEventFocus* event, - NativeViewHostGtk* button); + static void CallFocusIn(GtkWidget* widget, + GdkEventFocus* event, + NativeViewHostGtk* button); // Our associated NativeViewHost. NativeViewHost* host_; @@ -85,3 +86,4 @@ class NativeViewHostGtk : public NativeViewHostWrapper { } // namespace views #endif // VIEWS_CONTROLS_NATIVE_HOST_VIEW_GTK_H_ + diff --git a/views/controls/native/native_view_host_win.cc b/views/controls/native/native_view_host_win.cc index 3c05e2a..d1a5217 100644 --- a/views/controls/native/native_view_host_win.cc +++ b/views/controls/native/native_view_host_win.cc @@ -6,13 +6,10 @@ #include "app/gfx/canvas.h" #include "base/logging.h" -#include "base/win_util.h" #include "views/controls/native/native_view_host.h" #include "views/focus/focus_manager.h" #include "views/widget/widget.h" -const wchar_t* kNativeViewHostWinKey = L"__NATIVE_VIEW_HOST_WIN__"; - namespace views { //////////////////////////////////////////////////////////////////////////////// @@ -20,8 +17,7 @@ namespace views { NativeViewHostWin::NativeViewHostWin(NativeViewHost* host) : host_(host), - installed_clip_(false), - original_wndproc_(NULL) { + installed_clip_(false) { } NativeViewHostWin::~NativeViewHostWin() { @@ -41,32 +37,10 @@ void NativeViewHostWin::NativeViewAttached() { // Need to set the HWND's parent before changing its size to avoid flashing. SetParent(host_->native_view(), host_->GetWidget()->GetNativeView()); host_->Layout(); - - // Subclass the appropriate HWND to get focus notifications. - HWND focus_hwnd = host_->focus_native_view(); - DCHECK(focus_hwnd == host_->native_view() || - ::IsChild(host_->native_view(), focus_hwnd)); - original_wndproc_ = - win_util::SetWindowProc(focus_hwnd, - &NativeViewHostWin::NativeViewHostWndProc); - - // We use a property to retrieve the NativeViewHostWin from the window - // procedure. - ::SetProp(focus_hwnd, kNativeViewHostWinKey, this); } void NativeViewHostWin::NativeViewDetaching() { installed_clip_ = false; - - // Restore the original Windows procedure. - DCHECK(original_wndproc_); - WNDPROC wndproc = win_util::SetWindowProc(host_->focus_native_view(), - original_wndproc_); - DCHECK(wndproc == &NativeViewHostWin::NativeViewHostWndProc); - - // Also remove the property, it's not needed anymore. - HANDLE h = ::RemoveProp(host_->focus_native_view(), kNativeViewHostWinKey); - DCHECK(h == this); } void NativeViewHostWin::AddedToWidget() { @@ -142,22 +116,8 @@ void NativeViewHostWin::HideWidget() { SWP_NOREDRAW | SWP_NOOWNERZORDER); } -// static -LRESULT CALLBACK NativeViewHostWin::NativeViewHostWndProc(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param) { - NativeViewHostWin* native_view_host = - static_cast<NativeViewHostWin*>(::GetProp(window, kNativeViewHostWinKey)); - DCHECK(native_view_host); - - if (message == WM_SETFOCUS) - native_view_host->host_->GotNativeFocus(); - if (message == WM_DESTROY) - native_view_host->host_->Detach(); - - return CallWindowProc(native_view_host->original_wndproc_, - window, message, w_param, l_param); +void NativeViewHostWin::SetFocus() { + ::SetFocus(host_->native_view()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/views/controls/native/native_view_host_win.h b/views/controls/native/native_view_host_win.h index 6224693..51bc616 100644 --- a/views/controls/native/native_view_host_win.h +++ b/views/controls/native/native_view_host_win.h @@ -2,10 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef VIEWS_CONTROL_NATIVE_NATIVE_VIEW_HOST_WIN_H_ -#define VIEWS_CONTROL_NATIVE_NATIVE_VIEW_HOST_WIN_H_ - -#include "windows.h" +#ifndef VIEWS_CONTROLS_HWND_VIEW_H_ +#define VIEWS_CONTROLS_HWND_VIEW_H_ #include "base/logging.h" #include "views/controls/native/native_view_host_wrapper.h" @@ -30,14 +28,9 @@ class NativeViewHostWin : public NativeViewHostWrapper { virtual void UninstallClip(); virtual void ShowWidget(int x, int y, int w, int h); virtual void HideWidget(); + virtual void SetFocus(); private: - // Our subclass window procedure. - static LRESULT CALLBACK NativeViewHostWndProc(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param); - // Our associated NativeViewHost. NativeViewHost* host_; @@ -45,12 +38,9 @@ class NativeViewHostWin : public NativeViewHostWrapper { // visible portion of the gfx::NativeView ? bool installed_clip_; - // The window procedure before we subclassed. - WNDPROC original_wndproc_; - DISALLOW_COPY_AND_ASSIGN(NativeViewHostWin); }; } // namespace views -#endif // VIEWS_CONTROL_NATIVE_NATIVE_VIEW_HOST_WIN_H_ +#endif // VIEWS_CONTROLS_HWND_VIEW_H_ diff --git a/views/controls/native/native_view_host_wrapper.h b/views/controls/native/native_view_host_wrapper.h index 483aff5..948f0ce 100644 --- a/views/controls/native/native_view_host_wrapper.h +++ b/views/controls/native/native_view_host_wrapper.h @@ -51,6 +51,9 @@ class NativeViewHostWrapper { // is already hidden. virtual void HideWidget() = 0; + // Sets focus to the gfx::NativeView. + virtual void SetFocus() = 0; + // Creates a platform-specific instance of an object implementing this // interface. static NativeViewHostWrapper* CreateWrapper(NativeViewHost* host); |