| Index: views/widget/widget_win.cc
|
| ===================================================================
|
| --- views/widget/widget_win.cc (revision 18879)
|
| +++ views/widget/widget_win.cc (working copy)
|
| @@ -154,8 +154,7 @@
|
| 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 @@
|
|
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| }
|
| }
|
|
|
| -///////////////////////////////////////////////////////////////////////////////
|
| +////////////////////////////////////////////////////////////////////////////////
|
| // FocusTraversable
|
|
|
| View* WidgetWin::FindNextFocusableView(
|
| @@ -1039,10 +1056,8 @@
|
| // 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 @@
|
| // 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
|
|
|