Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Unified Diff: views/widget/widget_win.cc

Issue 141013: Relanding focus manager refactoring (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/widget/widget_win.h ('k') | views/window/window_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « views/widget/widget_win.h ('k') | views/window/window_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698