diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-30 18:48:00 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-30 18:48:00 +0000 |
commit | 82166b65c8cdd7cb855c2d018be8c6c815324af6 (patch) | |
tree | f96034ed91ce66d6a3ba2afa07cdd4be1e55b264 /views/widget | |
parent | 7811b768ff61d58153a198a273cdb39581a77542 (diff) | |
download | chromium_src-82166b65c8cdd7cb855c2d018be8c6c815324af6.zip chromium_src-82166b65c8cdd7cb855c2d018be8c6c815324af6.tar.gz chromium_src-82166b65c8cdd7cb855c2d018be8c6c815324af6.tar.bz2 |
This CL removes the last (major) Windows specific part out of the focus manager.
It was previously landed and reverted because it broke the reliability tests.
http://codereview.chromium.org/125148
The breakage was caused by constrained windows not getting a hold of the FocusManager when in unparented tabs.
The fix is to ensure unparented tab still have a way to access their FocusManager for proper closure.
Files changed from the previous patch that need reviewing:
native_tab_contents_container_win.cc
tab_contents_view_win.h
tab_contents_view_win.cc
BUG=None
TEST=Run all tests (unit, ui, interactive). Extensively test the focus in Chrome.
Review URL: http://codereview.chromium.org/146093
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19617 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/accelerator_handler.cc | 3 | ||||
-rw-r--r-- | views/widget/root_view.cc | 21 | ||||
-rw-r--r-- | views/widget/widget.h | 9 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 43 | ||||
-rw-r--r-- | views/widget/widget_win.h | 17 |
5 files changed, 53 insertions, 40 deletions
diff --git a/views/widget/accelerator_handler.cc b/views/widget/accelerator_handler.cc index 386357f..c171b50 100644 --- a/views/widget/accelerator_handler.cc +++ b/views/widget/accelerator_handler.cc @@ -15,7 +15,8 @@ bool AcceleratorHandler::Dispatch(const MSG& msg) { bool process_message = true; if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { - FocusManager* focus_manager = FocusManager::GetFocusManager(msg.hwnd); + FocusManager* focus_manager = + FocusManager::GetFocusManagerForNativeView(msg.hwnd); if (focus_manager) { // FocusManager::OnKeyDown and OnKeyUp return false if this message has // been consumed and should not be propagated further. diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index becc57a..6082e2d 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -46,7 +46,7 @@ class PaintTask : public Task { // The target root view. RootView* root_view_; - DISALLOW_EVIL_CONSTRUCTORS(PaintTask); + DISALLOW_COPY_AND_ASSIGN(PaintTask); }; const char RootView::kViewClassName[] = "views/RootView"; @@ -262,23 +262,11 @@ void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { default_keyboard_handler_ = NULL; } - // For a given widget hierarchy, focus is tracked by a FocusManager attached - // to our nearest enclosing Window. <-- Important Assumption! - // We may not have access to our window if this function is called as a - // result of teardown during the deletion of the RootView and its hierarchy, - // so we don't bother notifying the FocusManager in that case because it - // will have already been destroyed (the Widget that contains us is - // NCDESTROY'ed which in turn destroys the focus manager _before_ the - // RootView is deleted.) -#if defined(OS_WIN) - Window* window = GetWindow(); - if (window) { - FocusManager* focus_manager = - FocusManager::GetFocusManager(window->GetNativeWindow()); + FocusManager* focus_manager = widget_->GetFocusManager(); + // An unparanted RootView does not have a FocusManager. + if (focus_manager) focus_manager->ViewRemoved(parent, child); - } ViewStorage::GetSharedInstance()->ViewRemoved(parent, child); -#endif } } @@ -521,7 +509,6 @@ void RootView::OnWidgetDestroyed() { // TODO(port): Port RootViewDropTarget and this goes away. NOTIMPLEMENTED(); #endif - widget_ = NULL; } void RootView::ProcessMouseDragCanceled() { diff --git a/views/widget/widget.h b/views/widget/widget.h index 1dabf08..9c4c5ef 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -17,6 +17,7 @@ class Rect; namespace views { class Accelerator; +class FocusManager; class RootView; class TooltipManager; class Window; @@ -105,13 +106,17 @@ class Widget { virtual Window* GetWindow() { return NULL; } virtual const Window* GetWindow() const { return NULL; } - // Get the theme provider. + // Gets the theme provider. virtual ThemeProvider* GetThemeProvider() const { return NULL; } - // Get the default theme provider; this is necessary for when a widget has + // Gets the default theme provider; this is necessary for when a widget has // no profile (and ThemeProvider) associated with it. The default theme // provider provides a default set of bitmaps that such widgets can use. virtual ThemeProvider* GetDefaultThemeProvider() { return NULL; } + + // Returns the FocusManager for this widget. + // Note that all widgets in a widget hierarchy share the same focus manager. + virtual FocusManager* GetFocusManager() { return NULL; } }; } // namespace views diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 1fe3416..8d39991 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -154,8 +154,7 @@ WidgetWin::~WidgetWin() { MessageLoopForUI::current()->RemoveObserver(this); } -void WidgetWin::Init(HWND parent, const gfx::Rect& bounds, - bool has_own_focus_manager) { +void WidgetWin::Init(HWND parent, const gfx::Rect& bounds) { if (window_style_ == 0) window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; @@ -187,8 +186,9 @@ void WidgetWin::Init(HWND parent, const gfx::Rect& bounds, root_view_->OnWidgetCreated(); - if (has_own_focus_manager) { - FocusManager::CreateFocusManager(hwnd_, GetRootView()); + if ((window_style_ & WS_CHILD) == 0) { + // Top-level widgets get a FocusManager. + focus_manager_.reset(new FocusManager(this)); } // Sets the RootView as a property, so the automation can introspect windows. @@ -266,6 +266,7 @@ void WidgetWin::Close() { // Let's hide ourselves right away. Hide(); + if (close_widget_factory_.empty()) { // And we delay the close so that if we are called from an ATL callback, // we don't destroy the window before the callback returned (as the caller @@ -419,6 +420,19 @@ const Window* WidgetWin::GetWindow() const { return GetWindowImpl(hwnd_); } +FocusManager* WidgetWin::GetFocusManager() { + if (focus_manager_.get()) + return focus_manager_.get(); + + WidgetWin* widget = static_cast<WidgetWin*>(GetRootWidget()); + if (widget && widget != this) { + // WidgetWin subclasses may override GetFocusManager(), for example for + // dealing with cases where the widget has been unparented. + return widget->GetFocusManager(); + } + return NULL; +} + void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { if (use_layered_buffer_ == use_layered_buffer) return; @@ -460,7 +474,12 @@ RootView* WidgetWin::FindRootView(HWND hwnd) { return root_view; } -/////////////////////////////////////////////////////////////////////////////// +// static +WidgetWin* WidgetWin::GetWidget(HWND hwnd) { + return reinterpret_cast<WidgetWin*>(win_util::GetWindowUserData(hwnd)); +} + +//////////////////////////////////////////////////////////////////////////////// // MessageLoop::Observer void WidgetWin::WillProcessMessage(const MSG& msg) { @@ -472,7 +491,7 @@ void WidgetWin::DidProcessMessage(const MSG& msg) { } } -/////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // FocusTraversable View* WidgetWin::FindNextFocusableView( @@ -1039,10 +1058,8 @@ LRESULT CALLBACK WidgetWin::WndProc(HWND window, UINT message, // Otherwise we handle everything else. if (!widget->ProcessWindowMessage(window, message, w_param, l_param, result)) result = DefWindowProc(window, message, w_param, l_param); - if (message == WM_NCDESTROY) { - widget->hwnd_ = NULL; + if (message == WM_NCDESTROY) widget->OnFinalMessage(window); - } if (message == WM_ACTIVATE) PostProcessActivateMessage(widget, LOWORD(w_param)); return result; @@ -1051,18 +1068,16 @@ LRESULT CALLBACK WidgetWin::WndProc(HWND window, UINT message, // static void WidgetWin::PostProcessActivateMessage(WidgetWin* widget, int activation_state) { - FocusManager* focus_manager = - FocusManager::GetFocusManager(widget->GetNativeView()); - if (!focus_manager) { + if (!widget->focus_manager_.get()) { NOTREACHED(); return; } if (WA_INACTIVE == activation_state) { - focus_manager->StoreFocusedView(); + widget->focus_manager_->StoreFocusedView(); } else { // We must restore the focus after the message has been DefProc'ed as it // does set the focus to the last focused HWND. - focus_manager->RestoreFocusedView(); + widget->focus_manager_->RestoreFocusedView(); } } } // namespace views diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index b8500c7..6ae1141 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -78,11 +78,7 @@ class WidgetWin : public Widget, // this view, you are responsible for its destruction. If this value is NULL, // the caller is responsible for populating the RootView, and sizing its // contents as the window is sized. - // If |has_own_focus_manager| is true, the focus traversal stay confined to - // the window. - void Init(HWND parent, - const gfx::Rect& bounds, - bool has_own_focus_manager); + void Init(HWND parent, const gfx::Rect& bounds); // Sets the specified view as the contents of this Widget. There can only // be one contnets view child of this Widget's RootView. This view is sized to @@ -122,6 +118,9 @@ class WidgetWin : public Widget, // Returns the RootView associated with the specified HWND (if any). static RootView* FindRootView(HWND hwnd); + // Returns the Widget associated with the specified HWND (if any). + static WidgetWin* GetWidget(HWND hwnd); + // All classes registered by WidgetWin start with this name. static const wchar_t* const kBaseClassName; @@ -230,6 +229,7 @@ class WidgetWin : public Widget, virtual ThemeProvider* GetThemeProvider() const; virtual Window* GetWindow(); virtual const Window* GetWindow() const; + virtual FocusManager* GetFocusManager(); // Overridden from MessageLoop::Observer: void WillProcessMessage(const MSG& msg); @@ -327,7 +327,6 @@ class WidgetWin : public Widget, } protected: - // Call close instead of this to Destroy the window. BOOL DestroyWindow() { DCHECK(::IsWindow(GetNativeView())); @@ -523,6 +522,12 @@ class WidgetWin : public Widget, // the TooltipManager. scoped_ptr<TooltipManagerWin> tooltip_manager_; + // The focus manager keeping track of focus for this Widget and any of its + // children. NULL for non top-level widgets. + // WARNING: RootView's destructor calls into the FocusManager. As such, this + // must be destroyed AFTER root_view_. + scoped_ptr<FocusManager> focus_manager_; + // The root of the View hierarchy attached to this window. // WARNING: see warning in tooltip_manager_ for ordering dependencies with // this and tooltip_manager_. |