diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-20 04:22:44 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-20 04:22:44 +0000 |
commit | 3c3ba740c63a178807cc0c1a563080e0adbfe143 (patch) | |
tree | 78bcd84e7870d8009165df0e7a9fca87f4e91903 /views/widget/widget_win.cc | |
parent | 76724d00d3498f952d945d775a3f33f751624121 (diff) | |
download | chromium_src-3c3ba740c63a178807cc0c1a563080e0adbfe143.zip chromium_src-3c3ba740c63a178807cc0c1a563080e0adbfe143.tar.gz chromium_src-3c3ba740c63a178807cc0c1a563080e0adbfe143.tar.bz2 |
Relanding focus manager refactoring with build fix, see:http://codereview.chromium.org/125148BUG=NoneTEST=NoneTBR=ben
Review URL: http://codereview.chromium.org/141013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18889 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget/widget_win.cc')
-rw-r--r-- | views/widget/widget_win.cc | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 1fe3416..8f280d1 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. @@ -419,6 +419,18 @@ const Window* WidgetWin::GetWindow() const { return GetWindowImpl(hwnd_); } +FocusManager* WidgetWin::GetFocusManager() { + if (focus_manager_.get()) + return focus_manager_.get(); + + HWND root = ::GetAncestor(hwnd_, GA_ROOT); + if (!root) + return NULL; + + WidgetWin* widget = GetWidget(root); + return widget ? widget->focus_manager_.get() : NULL; +} + void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) { if (use_layered_buffer_ == use_layered_buffer) return; @@ -460,7 +472,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 +489,7 @@ void WidgetWin::DidProcessMessage(const MSG& msg) { } } -/////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // FocusTraversable View* WidgetWin::FindNextFocusableView( @@ -1039,10 +1056,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 +1066,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 |