summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-24 20:39:58 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-24 20:39:58 +0000
commit56235c632f18380a4455b6ea113cd6e2a2df0d69 (patch)
tree82150c0c7f8bb6c2c80c5580c56c9772059aa92f
parent64b29caf448b26c316533dbd98efbdc92f6163bd (diff)
downloadchromium_src-56235c632f18380a4455b6ea113cd6e2a2df0d69.zip
chromium_src-56235c632f18380a4455b6ea113cd6e2a2df0d69.tar.gz
chromium_src-56235c632f18380a4455b6ea113cd6e2a2df0d69.tar.bz2
Move some more direct uses of RootView to Widget.
The idea is to remove RootView from the public API of Views and eventually move it into the internal namespace. It is really an implementation detail of event propagation into a view hierarchy. Anyone that calls GetRootView() and does something that isn't a View method should be calling that method on the Widget instead... e.g. instead of calling GetRootView()->NotifyThemeChanged(), call GetWidget()->ThemeChanged(). The RootView is a focus traversable, which is fine, but calling code should call GetWidget()->GetFocusTraversable() to obtain it, rather than knowing RootView is-a focus traversable and just calling GetRootView(). This also changes FocusManager::ContainsView to be simpler and cross platform. Since there is one FocusManager per view hierarchy (attached to the toplevel Widget), getting the view's focus manager and comparing it to the current focus manager is a sufficient test. BUG=72040 TEST=existing unittests, none Review URL: http://codereview.chromium.org/6577017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75940 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--views/controls/tabbed_pane/native_tabbed_pane_win.cc3
-rw-r--r--views/focus/focus_manager.cc31
-rw-r--r--views/focus/focus_manager_unittest.cc3
-rw-r--r--views/view.h6
-rw-r--r--views/widget/native_widget_win.cc1
-rw-r--r--views/widget/root_view.cc4
-rw-r--r--views/widget/root_view.h4
-rw-r--r--views/widget/widget.h12
-rw-r--r--views/widget/widget_gtk.cc20
-rw-r--r--views/widget/widget_gtk.h3
-rw-r--r--views/widget/widget_impl.cc12
-rw-r--r--views/widget/widget_impl.h5
-rw-r--r--views/widget/widget_win.cc12
-rw-r--r--views/widget/widget_win.h3
-rw-r--r--views/window/non_client_view.cc2
-rw-r--r--views/window/window_gtk.cc2
16 files changed, 81 insertions, 42 deletions
diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc
index ba4ffe6..da09579 100644
--- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc
+++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc
@@ -353,7 +353,8 @@ void NativeTabbedPaneWin::ViewHierarchyChanged(bool is_add,
if (is_add && (child == this) && content_window_) {
// We have been added to a view hierarchy, update the FocusTraversable
// parent.
- content_window_->SetFocusTraversableParent(GetRootView());
+ content_window_->SetFocusTraversableParent(
+ GetWidget()->GetFocusTraversable());
}
}
diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc
index baaf2a0..ae3e760 100644
--- a/views/focus/focus_manager.cc
+++ b/views/focus/focus_manager.cc
@@ -168,27 +168,8 @@ void FocusManager::ValidateFocusedView() {
// Tests whether a view is valid, whether it still belongs to the window
// hierarchy of the FocusManager.
bool FocusManager::ContainsView(View* view) {
- DCHECK(view);
- RootView* root_view = view->GetRootView();
- if (!root_view)
- return false;
-
- Widget* widget = root_view->GetWidget();
- if (!widget)
- return false;
-
- gfx::NativeView top_window = widget_->GetNativeView();
- gfx::NativeView window = widget->GetNativeView();
- while (window) {
- if (window == top_window)
- return true;
-#if defined(OS_WIN)
- window = ::GetParent(window);
-#else
- window = gtk_widget_get_parent(window);
-#endif
- }
- return false;
+ Widget* widget = view->GetWidget();
+ return widget ? widget->GetFocusManager() == this : false;
}
void FocusManager::AdvanceFocus(bool reverse) {
@@ -235,18 +216,20 @@ View* FocusManager::GetNextFocusableView(View* original_starting_view,
// Otherwise default to the root view.
if (!focus_traversable) {
- focus_traversable = original_starting_view->GetRootView();
+ focus_traversable =
+ original_starting_view->GetWidget()->GetFocusTraversable();
starting_view = original_starting_view;
}
} else {
// When you are going back, starting view's FocusTraversable
// should not be used.
- focus_traversable = original_starting_view->GetRootView();
+ focus_traversable =
+ original_starting_view->GetWidget()->GetFocusTraversable();
starting_view = original_starting_view;
}
}
} else {
- focus_traversable = widget_->GetRootView();
+ focus_traversable = widget_->GetFocusTraversable();
}
// Traverse the FocusTraversable tree down to find the focusable view.
diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc
index f016b4b..9fc0b61 100644
--- a/views/focus/focus_manager_unittest.cc
+++ b/views/focus/focus_manager_unittest.cc
@@ -310,7 +310,8 @@ class BorderView : public NativeViewHost {
// We have been added to a view hierarchy, attach the native view.
Attach(widget_->GetNativeView());
// Also update the FocusTraversable parent so the focus traversal works.
- widget_->GetRootView()->SetFocusTraversableParent(GetRootView());
+ widget_->GetRootView()->SetFocusTraversableParent(
+ GetWidget()->GetFocusTraversable());
}
}
diff --git a/views/view.h b/views/view.h
index 4e6ace3..490662d 100644
--- a/views/view.h
+++ b/views/view.h
@@ -1093,14 +1093,12 @@ class View : public AcceleratorTarget {
// Called when the UI theme has changed, overriding allows individual Views to
// do special cleanup and processing (such as dropping resource caches).
- // To dispatch a theme changed notification, call
- // RootView::NotifyThemeChanged().
+ // To dispatch a theme changed notification, call Widget::ThemeChanged().
virtual void OnThemeChanged() { }
// Called when the locale has changed, overriding allows individual Views to
// update locale-dependent strings.
- // To dispatch a locale changed notification, call
- // RootView::NotifyLocaleChanged().
+ // To dispatch a locale changed notification, call Widget::LocaleChanged().
virtual void OnLocaleChanged() { }
// Tooltips ------------------------------------------------------------------
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index b63fb34..32e0310 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -167,7 +167,6 @@ void NativeWidgetWin::SchedulePaintInRect(const gfx::Rect& rect) {
::InvalidateRect(hwnd(), &r, FALSE);
}
-
void NativeWidgetWin::FocusNativeView(gfx::NativeView native_view) {
if (IsWindow(native_view)) {
if (GetFocus() != native_view)
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index 805e62c..d7b9007 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -140,11 +140,11 @@ void RootView::SetFocusTraversableParentView(View* view) {
// System events ---------------------------------------------------------------
-void RootView::NotifyThemeChanged() {
+void RootView::ThemeChanged() {
View::PropagateThemeChanged();
}
-void RootView::NotifyLocaleChanged() {
+void RootView::LocaleChanged() {
View::PropagateLocaleChanged();
}
diff --git a/views/widget/root_view.h b/views/widget/root_view.h
index c8df5a9..df74ede 100644
--- a/views/widget/root_view.h
+++ b/views/widget/root_view.h
@@ -96,11 +96,11 @@ class RootView : public View,
// Public API for broadcasting theme change notifications to this View
// hierarchy.
- void NotifyThemeChanged();
+ void ThemeChanged();
// Public API for broadcasting locale change notifications to this View
// hierarchy.
- void NotifyLocaleChanged();
+ void LocaleChanged();
// Overridden from FocusTraversable:
virtual FocusSearch* GetFocusSearch() OVERRIDE;
diff --git a/views/widget/widget.h b/views/widget/widget.h
index 344c26a..2e12a74 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -26,6 +26,7 @@ using ui::ThemeProvider;
namespace views {
class FocusManager;
+class FocusTraversable;
class RootView;
class TooltipManager;
class View;
@@ -241,6 +242,17 @@ class Widget {
virtual void SchedulePaintInRect(const gfx::Rect& rect) = 0;
virtual void SetCursor(gfx::NativeCursor cursor) = 0;
+
+ // Retrieves the focus traversable for this widget.
+ virtual FocusTraversable* GetFocusTraversable() = 0;
+
+ // Notifies the view hierarchy contained in this widget that theme resources
+ // changed.
+ virtual void ThemeChanged() = 0;
+
+ // Notifies the view hierarchy contained in this widget that locale resources
+ // changed.
+ virtual void LocaleChanged() = 0;
};
} // namespace views
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 8a7a906..5c6db99 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -898,6 +898,18 @@ void WidgetGtk::SetCursor(gfx::NativeCursor cursor) {
gdk_window_set_cursor(widget_->window, cursor);
}
+FocusTraversable* WidgetGtk::GetFocusTraversable() {
+ return root_view_.get();
+}
+
+void WidgetGtk::ThemeChanged() {
+ root_view_->ThemeChanged();
+}
+
+void WidgetGtk::LocaleChanged() {
+ root_view_->LocaleChanged();
+}
+
////////////////////////////////////////////////////////////////////////////////
// WidgetGtk, FocusTraversable implementation:
@@ -1730,11 +1742,9 @@ Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) {
void Widget::NotifyLocaleChanged() {
GList *window_list = gtk_window_list_toplevels();
for (GList* element = window_list; element; element = g_list_next(element)) {
- GtkWindow* window = GTK_WINDOW(element->data);
- DCHECK(window);
- RootView *root_view = FindRootView(window);
- if (root_view)
- root_view->NotifyLocaleChanged();
+ Widget* widget = GetWidgetFromNativeWindow(GTK_WINDOW(element->data));
+ if (widget)
+ widget->LocaleChanged();
}
g_list_free(window_list);
}
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index 2b8822a..a75f586 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -199,6 +199,9 @@ class WidgetGtk
virtual View* GetDraggedView();
virtual void SchedulePaintInRect(const gfx::Rect& rect);
virtual void SetCursor(gfx::NativeCursor cursor);
+ virtual FocusTraversable* GetFocusTraversable();
+ virtual void ThemeChanged();
+ virtual void LocaleChanged();
// Overridden from FocusTraversable:
virtual FocusSearch* GetFocusSearch();
diff --git a/views/widget/widget_impl.cc b/views/widget/widget_impl.cc
index ec4dceb..cd13ea8 100644
--- a/views/widget/widget_impl.cc
+++ b/views/widget/widget_impl.cc
@@ -121,10 +121,22 @@ void WidgetImpl::SetCursor(gfx::NativeCursor cursor) {
native_widget_->SetCursor(cursor);
}
+FocusTraversable* WidgetImpl::GetFocusTraversable() {
+ return root_view_.get();
+}
+
ThemeProvider* WidgetImpl::GetThemeProvider() const {
return NULL;
}
+void WidgetImpl::ThemeChanged() {
+ root_view_->ThemeChanged();
+}
+
+void WidgetImpl::LocaleChanged() {
+ root_view_->LocaleChanged();
+}
+
FocusManager* WidgetImpl::GetFocusManager() {
return GetTopLevelWidgetImpl()->focus_manager_.get();
}
diff --git a/views/widget/widget_impl.h b/views/widget/widget_impl.h
index ad0f8b8..0ba7025 100644
--- a/views/widget/widget_impl.h
+++ b/views/widget/widget_impl.h
@@ -89,10 +89,15 @@ class WidgetImpl : public internal::NativeWidgetListener,
void SetCursor(gfx::NativeCursor cursor);
+ FocusTraversable* GetFocusTraversable();
+
// Returns a ThemeProvider that can be used to provide resources when
// rendering Views associated with this WidgetImpl.
ThemeProvider* GetThemeProvider() const;
+ void ThemeChanged();
+ void LocaleChanged();
+
// Returns the FocusManager for this WidgetImpl. Only top-level WidgetImpls
// have FocusManagers.
FocusManager* GetFocusManager();
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index ebe890e..e0390d8 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -519,6 +519,18 @@ void WidgetWin::SetCursor(gfx::NativeCursor cursor) {
}
}
+FocusTraversable* WidgetWin::GetFocusTraversable() {
+ return root_view_.get();
+}
+
+void WidgetWin::ThemeChanged() {
+ root_view_->ThemeChanged();
+}
+
+void WidgetWin::LocaleChanged() {
+ root_view_->LocaleChanged();
+}
+
////////////////////////////////////////////////////////////////////////////////
// MessageLoop::Observer
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index 8eb8ff2..ca24993 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -252,6 +252,9 @@ class WidgetWin : public ui::WindowImpl,
virtual View* GetDraggedView();
virtual void SchedulePaintInRect(const gfx::Rect& rect);
virtual void SetCursor(gfx::NativeCursor cursor);
+ virtual FocusTraversable* GetFocusTraversable();
+ virtual void ThemeChanged();
+ virtual void LocaleChanged();
// Overridden from MessageLoop::Observer:
void WillProcessMessage(const MSG& msg);
diff --git a/views/window/non_client_view.cc b/views/window/non_client_view.cc
index c31dda6..a3412ce 100644
--- a/views/window/non_client_view.cc
+++ b/views/window/non_client_view.cc
@@ -58,7 +58,7 @@ void NonClientView::WindowClosing() {
void NonClientView::UpdateFrame() {
SetFrameView(frame_->CreateFrameViewForWindow());
- GetRootView()->NotifyThemeChanged();
+ GetWidget()->ThemeChanged();
Layout();
SchedulePaint();
frame_->UpdateFrameAfterFrameChange();
diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc
index e933e98..09e1984 100644
--- a/views/window/window_gtk.cc
+++ b/views/window/window_gtk.cc
@@ -263,7 +263,7 @@ bool WindowGtk::ShouldUseNativeFrame() const {
void WindowGtk::FrameTypeChanged() {
// This is called when the Theme has changed, so forward the event to the root
// widget.
- GetRootView()->NotifyThemeChanged();
+ ThemeChanged();
}
////////////////////////////////////////////////////////////////////////////////