diff options
54 files changed, 183 insertions, 141 deletions
diff --git a/chrome/browser/automation/testing_automation_provider_views.cc b/chrome/browser/automation/testing_automation_provider_views.cc index 9a02bb0..fd40884 100644 --- a/chrome/browser/automation/testing_automation_provider_views.cc +++ b/chrome/browser/automation/testing_automation_provider_views.cc @@ -145,11 +145,12 @@ void TestingAutomationProvider::GetFocusedViewID(int handle, int* view_id) { *view_id = -1; if (window_tracker_->ContainsHandle(handle)) { gfx::NativeWindow window = window_tracker_->GetResource(handle); - views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); + const views::Widget* widget = + views::Widget::GetWidgetForNativeWindow(window); DCHECK(widget); - views::FocusManager* focus_manager = widget->GetFocusManager(); + const views::FocusManager* focus_manager = widget->GetFocusManager(); DCHECK(focus_manager); - views::View* focused_view = focus_manager->GetFocusedView(); + const views::View* focused_view = focus_manager->GetFocusedView(); if (focused_view) *view_id = focused_view->id(); } diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc index bf03621..a32cadb 100644 --- a/chrome/browser/browser_focus_uitest.cc +++ b/chrome/browser/browser_focus_uitest.cc @@ -252,9 +252,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_BrowsersRememberFocus) { BrowserView* browser_view2 = BrowserView::GetBrowserViewForBrowser(browser2); ASSERT_TRUE(browser_view2); - views::Widget* widget2 = views::Widget::GetWidgetForNativeWindow(window2); + const views::Widget* widget2 = + views::Widget::GetWidgetForNativeWindow(window2); ASSERT_TRUE(widget2); - views::FocusManager* focus_manager2 = widget2->GetFocusManager(); + const views::FocusManager* focus_manager2 = widget2->GetFocusManager(); ASSERT_TRUE(focus_manager2); EXPECT_EQ(browser_view2->GetTabContentsContainerView(), focus_manager2->GetFocusedView()); diff --git a/chrome/browser/renderer_host/render_widget_host_view_views.cc b/chrome/browser/renderer_host/render_widget_host_view_views.cc index a13d19a..7e45bc6 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_views.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_views.cc @@ -677,7 +677,7 @@ views::TextInputClient* RenderWidgetHostViewViews::GetTextInputClient() { } bool RenderWidgetHostViewViews::GetTooltipText(const gfx::Point& p, - string16* tooltip) { + string16* tooltip) const { if (tooltip_text_.length() == 0) return false; *tooltip = tooltip_text_; diff --git a/chrome/browser/renderer_host/render_widget_host_view_views.h b/chrome/browser/renderer_host/render_widget_host_view_views.h index 05ba1f7..7fe9bd1 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_views.h +++ b/chrome/browser/renderer_host/render_widget_host_view_views.h @@ -159,7 +159,8 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView, virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; virtual bool OnMouseWheel(const views::MouseWheelEvent& event) OVERRIDE; virtual views::TextInputClient* GetTextInputClient() OVERRIDE; - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; // Overridden from TextInputClient: virtual void SetCompositionText( diff --git a/chrome/browser/ui/views/accessible_pane_view.cc b/chrome/browser/ui/views/accessible_pane_view.cc index 0a3205b..90e68d0 100644 --- a/chrome/browser/ui/views/accessible_pane_view.cc +++ b/chrome/browser/ui/views/accessible_pane_view.cc @@ -161,7 +161,7 @@ bool AccessiblePaneView::AcceleratorPressed( // Special case: don't handle any accelerators for the location bar, // so that it behaves exactly the same whether you focus it with Ctrl+L // or F6 or Alt+D or Alt+Shift+T. - views::View* focused_view = focus_manager_->GetFocusedView(); + const views::View* focused_view = focus_manager_->GetFocusedView(); if ((focused_view->GetClassName() == LocationBarView::kViewClassName || focused_view->GetClassName() == views::NativeViewHost::kViewClassName)) { return false; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc index 9333a6f..09663d8 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc @@ -150,7 +150,7 @@ class BookmarkButton : public views::TextButton { } virtual bool GetTooltipText(const gfx::Point& p, - string16* tooltip) OVERRIDE { + string16* tooltip) const OVERRIDE { gfx::Point location(p); ConvertPointToScreen(this, &location); *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle(location, url_, @@ -200,7 +200,7 @@ class BookmarkFolderButton : public views::MenuButton { } virtual bool GetTooltipText(const gfx::Point& p, - string16* tooltip) OVERRIDE { + string16* tooltip) const OVERRIDE { if (text_size_.width() > GetTextBounds().width()) *tooltip = text_; return !tooltip->empty(); diff --git a/chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.cc b/chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.cc index 8f1ed27..b7ab56d 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.cc @@ -83,7 +83,8 @@ void BookmarkMenuController::SetPageNavigator(PageNavigator* navigator) { menu_delegate_->SetPageNavigator(navigator); } -string16 BookmarkMenuController::GetTooltipText(int id, const gfx::Point& p) { +string16 BookmarkMenuController::GetTooltipText(int id, + const gfx::Point& p) const { return menu_delegate_->GetTooltipText(id, p); } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h b/chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h index 3f0591f..578ea4c 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h +++ b/chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h @@ -77,7 +77,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver, void set_observer(Observer* observer) { observer_ = observer; } // MenuDelegate methods. - virtual string16 GetTooltipText(int id, const gfx::Point& p) OVERRIDE; + virtual string16 GetTooltipText(int id, const gfx::Point& p) const OVERRIDE; virtual bool IsTriggerableEvent(views::MenuItemView* view, const views::MouseEvent& e); virtual void ExecuteCommand(int id, int mouse_event_flags); diff --git a/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc b/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc index fa2e60e..02cd6a0 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc @@ -98,11 +98,14 @@ void BookmarkMenuDelegate::SetActiveMenu(const BookmarkNode* node, menu_ = node_to_menu_map_[node]; } -string16 BookmarkMenuDelegate::GetTooltipText(int id, - const gfx::Point& screen_loc) { +string16 BookmarkMenuDelegate::GetTooltipText( + int id, + const gfx::Point& screen_loc) const { DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end()); - const BookmarkNode* node = menu_id_to_node_map_[id]; + MenuIDToNodeMap::const_iterator i = menu_id_to_node_map_.find(id); + DCHECK(i != menu_id_to_node_map_.end()); + const BookmarkNode* node = i->second; if (node->is_url()) { return BookmarkBarView::CreateToolTipForURLAndTitle( screen_loc, node->url(), node->GetTitle(), profile_); @@ -335,10 +338,10 @@ void BookmarkMenuDelegate::WillRemoveBookmarks( MenuItemView* menu = GetMenuByID(node_to_menu->second); DCHECK(menu); // If there an entry in node_to_menu_id_map_, there should // be a menu. - DCHECK(menu->GetParentMenuItem()); - changed_parent_menus.insert(menu->GetParentMenuItem()); - menu->GetParentMenuItem()->RemoveMenuItemAt( - menu->parent()->GetIndexOf(menu)); + MenuItemView* parent = menu->GetParentMenuItem(); + DCHECK(parent); + changed_parent_menus.insert(parent); + parent->RemoveMenuItemAt(menu->parent()->GetIndexOf(menu)); node_to_menu_id_map_.erase(node_to_menu); } } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h b/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h index 479cbe9..d27576b 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h +++ b/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h @@ -87,7 +87,7 @@ class BookmarkMenuDelegate : public BaseBookmarkModelObserver, bool is_mutating_model() const { return is_mutating_model_; } // MenuDelegate like methods (see class description for details). - string16 GetTooltipText(int id, const gfx::Point& p); + string16 GetTooltipText(int id, const gfx::Point& p) const; bool IsTriggerableEvent(views::MenuItemView* menu, const views::MouseEvent& e); void ExecuteCommand(int id, int mouse_event_flags); @@ -123,6 +123,7 @@ class BookmarkMenuDelegate : public BaseBookmarkModelObserver, virtual void DidRemoveBookmarks(); private: + typedef std::map<int, const BookmarkNode*> MenuIDToNodeMap; typedef std::map<const BookmarkNode*, int> NodeToMenuIDMap; typedef std::map<const BookmarkNode*, views::MenuItemView*> NodeToMenuMap; @@ -154,7 +155,7 @@ class BookmarkMenuDelegate : public BaseBookmarkModelObserver, views::Widget* parent_; // Maps from menu id to BookmarkNode. - std::map<int, const BookmarkNode*> menu_id_to_node_map_; + MenuIDToNodeMap menu_id_to_node_map_; // Mapping from node to menu id. This only contains entries for nodes of type // URL. diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc index 729428c..1899094 100644 --- a/chrome/browser/ui/views/download/download_item_view.cc +++ b/chrome/browser/ui/views/download/download_item_view.cc @@ -578,7 +578,7 @@ bool DownloadItemView::OnKeyPressed(const views::KeyEvent& event) { } bool DownloadItemView::GetTooltipText(const gfx::Point& p, - string16* tooltip) { + string16* tooltip) const { if (tooltip_text_.empty()) return false; diff --git a/chrome/browser/ui/views/download/download_item_view.h b/chrome/browser/ui/views/download/download_item_view.h index ea9ed24..f9c02b4 100644 --- a/chrome/browser/ui/views/download/download_item_view.h +++ b/chrome/browser/ui/views/download/download_item_view.h @@ -88,7 +88,8 @@ class DownloadItemView : public views::ButtonListener, virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; virtual void ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 0231536..c8dabf0 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -928,7 +928,7 @@ void BrowserView::RotatePaneFocus(bool forwards) { int count = static_cast<int>(accessible_views.size()); // Figure out which view (if any) currently has the focus. - views::View* focused_view = GetFocusManager()->GetFocusedView(); + const views::View* focused_view = GetFocusManager()->GetFocusedView(); int index = -1; if (focused_view) { for (int i = 0; i < count; ++i) { diff --git a/chrome/browser/ui/views/location_bar/star_view.cc b/chrome/browser/ui/views/location_bar/star_view.cc index 8d4c0c0..6a0cd14 100644 --- a/chrome/browser/ui/views/location_bar/star_view.cc +++ b/chrome/browser/ui/views/location_bar/star_view.cc @@ -38,7 +38,7 @@ void StarView::GetAccessibleState(ui::AccessibleViewState* state) { state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; } -bool StarView::GetTooltipText(const gfx::Point& p, string16* tooltip) { +bool StarView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { // Don't show tooltip to distract user if BookmarkBubbleView is showing. if (browser::IsBookmarkBubbleViewShowing()) return false; diff --git a/chrome/browser/ui/views/location_bar/star_view.h b/chrome/browser/ui/views/location_bar/star_view.h index 319936e..eacf925 100644 --- a/chrome/browser/ui/views/location_bar/star_view.h +++ b/chrome/browser/ui/views/location_bar/star_view.h @@ -28,7 +28,8 @@ class StarView : public views::ImageView, public BubbleDelegate { private: // views::ImageView overrides: virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; diff --git a/chrome/browser/ui/views/reload_button.cc b/chrome/browser/ui/views/reload_button.cc index 1fb81f4..460bc0a 100644 --- a/chrome/browser/ui/views/reload_button.cc +++ b/chrome/browser/ui/views/reload_button.cc @@ -124,9 +124,10 @@ void ReloadButton::OnMouseExited(const views::MouseEvent& event) { SetState(BS_NORMAL); } -bool ReloadButton::GetTooltipText(const gfx::Point& p, string16* tooltip) { - int text_id = visible_mode_ == MODE_RELOAD ? IDS_TOOLTIP_RELOAD - : IDS_TOOLTIP_STOP; +bool ReloadButton::GetTooltipText(const gfx::Point& p, + string16* tooltip) const { + int text_id = (visible_mode_ == MODE_RELOAD) ? + IDS_TOOLTIP_RELOAD : IDS_TOOLTIP_STOP; tooltip->assign(l10n_util::GetStringUTF16(text_id)); return true; } diff --git a/chrome/browser/ui/views/reload_button.h b/chrome/browser/ui/views/reload_button.h index 4b0cdc2..0fbcba5 100644 --- a/chrome/browser/ui/views/reload_button.h +++ b/chrome/browser/ui/views/reload_button.h @@ -46,7 +46,8 @@ class ReloadButton : public views::ToggleImageButton, // Overridden from views::View: virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; virtual std::string GetClassName() const OVERRIDE; private: diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc index 7705344..4fdaf77 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc @@ -51,8 +51,7 @@ void NativeTabContentsContainerGtk::RenderViewHostChanged( RenderViewHost* old_host, RenderViewHost* new_host) { // If we are focused, we need to pass the focus to the new RenderViewHost. - views::FocusManager* focus_manager = GetFocusManager(); - if (focus_manager->GetFocusedView() == this) + if (GetFocusManager()->GetFocusedView() == this) OnFocus(); } diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc index b0da53f..60bb1e1 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc +++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc @@ -437,10 +437,15 @@ views::internal::NativeWidgetDelegate* // TabContentsViewViews, views::Widget overrides: views::FocusManager* TabContentsViewViews::GetFocusManager() { - views::FocusManager* focus_manager = Widget::GetFocusManager(); + return const_cast<views::FocusManager*>( + static_cast<const TabContentsViewViews*>(this)->GetFocusManager()); +} + +const views::FocusManager* TabContentsViewViews::GetFocusManager() const { + const views::FocusManager* focus_manager = Widget::GetFocusManager(); if (focus_manager) { - // If focus_manager_ is non NULL, it means we have been reparented, in which - // case its value may not be valid anymore. + // If |focus_manager| is non NULL, it means we have been reparented, in + // which case |focus_manager_| may not be valid anymore. focus_manager_ = NULL; return focus_manager; } diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.h b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.h index acc92b0..63b88a9 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.h +++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.h @@ -121,6 +121,7 @@ class TabContentsViewViews : public views::Widget, // Overridden from views::Widget: virtual views::FocusManager* GetFocusManager() OVERRIDE; + virtual const views::FocusManager* GetFocusManager() const OVERRIDE; virtual void OnNativeWidgetVisibilityChanged(bool visible) OVERRIDE; // A helper method for closing the tab. @@ -169,7 +170,7 @@ class TabContentsViewViews : public views::Widget, // The FocusManager associated with this tab. Stored as it is not directly // accessible when un-parented. - views::FocusManager* focus_manager_; + mutable const views::FocusManager* focus_manager_; DISALLOW_COPY_AND_ASSIGN(TabContentsViewViews); }; diff --git a/chrome/browser/ui/views/tabs/base_tab.cc b/chrome/browser/ui/views/tabs/base_tab.cc index 6f38ffb..10e3fd8 100644 --- a/chrome/browser/ui/views/tabs/base_tab.cc +++ b/chrome/browser/ui/views/tabs/base_tab.cc @@ -370,7 +370,7 @@ void BaseTab::OnMouseExited(const views::MouseEvent& event) { hover_animation_->Hide(); } -bool BaseTab::GetTooltipText(const gfx::Point& p, string16* tooltip) { +bool BaseTab::GetTooltipText(const gfx::Point& p, string16* tooltip) const { if (data_.title.empty()) return false; diff --git a/chrome/browser/ui/views/tabs/base_tab.h b/chrome/browser/ui/views/tabs/base_tab.h index 5157eb6..5f42aab 100644 --- a/chrome/browser/ui/views/tabs/base_tab.h +++ b/chrome/browser/ui/views/tabs/base_tab.h @@ -91,7 +91,8 @@ class BaseTab : public ui::AnimationDelegate, virtual void OnMouseCaptureLost() OVERRIDE; virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; protected: diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc index 4ab41fe..82a9406 100644 --- a/chrome/browser/ui/views/tabs/tab.cc +++ b/chrome/browser/ui/views/tabs/tab.cc @@ -330,7 +330,7 @@ void Tab::GetHitTestMask(gfx::Path* path) const { TabResources::GetHitTestMask(width(), height(), path); } -bool Tab::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* origin) { +bool Tab::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* origin) const { origin->set_x(title_bounds_.x() + 10); origin->set_y(-views::TooltipManager::GetTooltipHeight() - 4); return true; diff --git a/chrome/browser/ui/views/tabs/tab.h b/chrome/browser/ui/views/tabs/tab.h index a395656..a7243ce 100644 --- a/chrome/browser/ui/views/tabs/tab.h +++ b/chrome/browser/ui/views/tabs/tab.h @@ -73,7 +73,7 @@ class Tab : public BaseTab { virtual bool HasHitTestMask() const OVERRIDE; virtual void GetHitTestMask(gfx::Path* path) const OVERRIDE; virtual bool GetTooltipTextOrigin(const gfx::Point& p, - gfx::Point* origin) OVERRIDE; + gfx::Point* origin) const OVERRIDE; virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; // Paint various portions of the Tab diff --git a/chrome/browser/ui/views/wrench_menu.cc b/chrome/browser/ui/views/wrench_menu.cc index 6cf17e8..ec77ab0 100644 --- a/chrome/browser/ui/views/wrench_menu.cc +++ b/chrome/browser/ui/views/wrench_menu.cc @@ -614,7 +614,7 @@ void WrenchMenu::RunMenu(views::MenuButton* host) { } string16 WrenchMenu::GetTooltipText(int id, - const gfx::Point& p) { + const gfx::Point& p) const { return is_bookmark_command(id) ? bookmark_menu_delegate_->GetTooltipText(id, p) : string16(); } diff --git a/chrome/browser/ui/views/wrench_menu.h b/chrome/browser/ui/views/wrench_menu.h index 6f08b91..d1b7d7d 100644 --- a/chrome/browser/ui/views/wrench_menu.h +++ b/chrome/browser/ui/views/wrench_menu.h @@ -40,7 +40,7 @@ class WrenchMenu : public views::MenuDelegate, void RunMenu(views::MenuButton* host); // MenuDelegate overrides: - virtual string16 GetTooltipText(int id, const gfx::Point& p) OVERRIDE; + virtual string16 GetTooltipText(int id, const gfx::Point& p) const OVERRIDE; virtual bool IsTriggerableEvent(views::MenuItemView* menu, const views::MouseEvent& e) OVERRIDE; virtual bool GetDropFormats( diff --git a/chrome/test/base/ui_test_utils_aura.cc b/chrome/test/base/ui_test_utils_aura.cc index b62ac21..cd1b549 100644 --- a/chrome/test/base/ui_test_utils_aura.cc +++ b/chrome/test/base/ui_test_utils_aura.cc @@ -20,9 +20,10 @@ bool IsViewFocused(const Browser* browser, ViewID vid) { DCHECK(browser_window); gfx::NativeWindow window = browser_window->GetNativeHandle(); DCHECK(window); - views::Widget* widget = views::Widget::GetTopLevelWidgetForNativeView(window); + const views::Widget* widget = + views::Widget::GetTopLevelWidgetForNativeView(window); DCHECK(widget); - views::FocusManager* focus_manager = widget->GetFocusManager(); + const views::FocusManager* focus_manager = widget->GetFocusManager(); DCHECK(focus_manager); return focus_manager->GetFocusedView()->id() == vid; } diff --git a/chrome/test/base/ui_test_utils_gtk.cc b/chrome/test/base/ui_test_utils_gtk.cc index 91b2bd0..166f764 100644 --- a/chrome/test/base/ui_test_utils_gtk.cc +++ b/chrome/test/base/ui_test_utils_gtk.cc @@ -47,9 +47,9 @@ bool IsViewFocused(const Browser* browser, ViewID vid) { DCHECK(browser_window); #if defined(TOOLKIT_VIEWS) gfx::NativeWindow window = browser_window->GetNativeHandle(); - views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); + const views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); DCHECK(widget); - views::FocusManager* focus_manager = widget->GetFocusManager(); + const views::FocusManager* focus_manager = widget->GetFocusManager(); DCHECK(focus_manager); return focus_manager->GetFocusedView() && focus_manager->GetFocusedView()->id() == vid; diff --git a/chrome/test/base/ui_test_utils_win.cc b/chrome/test/base/ui_test_utils_win.cc index c3c9fb1..163542a 100644 --- a/chrome/test/base/ui_test_utils_win.cc +++ b/chrome/test/base/ui_test_utils_win.cc @@ -19,9 +19,10 @@ bool IsViewFocused(const Browser* browser, ViewID vid) { DCHECK(browser_window); gfx::NativeWindow window = browser_window->GetNativeHandle(); DCHECK(window); - views::Widget* widget = views::Widget::GetTopLevelWidgetForNativeView(window); + const views::Widget* widget = + views::Widget::GetTopLevelWidgetForNativeView(window); DCHECK(widget); - views::FocusManager* focus_manager = widget->GetFocusManager(); + const views::FocusManager* focus_manager = widget->GetFocusManager(); DCHECK(focus_manager); return focus_manager->GetFocusedView()->id() == vid; } diff --git a/ui/aura/window.cc b/ui/aura/window.cc index da87e96..d7ee967 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -368,7 +368,7 @@ bool Window::CanFocus() const { internal::FocusManager* Window::GetFocusManager() { return const_cast<internal::FocusManager*>( - const_cast<const Window*>(this)->GetFocusManager()); + static_cast<const Window*>(this)->GetFocusManager()); } const internal::FocusManager* Window::GetFocusManager() const { diff --git a/views/accessibility/native_view_accessibility_win.cc b/views/accessibility/native_view_accessibility_win.cc index d9cdaac..4342517 100644 --- a/views/accessibility/native_view_accessibility_win.cc +++ b/views/accessibility/native_view_accessibility_win.cc @@ -299,10 +299,8 @@ STDMETHODIMP NativeViewAccessibilityWin::get_accFocus(VARIANT* focus_child) { if (!view_) return E_FAIL; - views::View* focus = NULL; views::FocusManager* focus_manager = view_->GetFocusManager(); - if (focus_manager) - focus = focus_manager->GetFocusedView(); + views::View* focus = focus_manager ? focus_manager->GetFocusedView() : NULL; if (focus == view_) { // This view has focus. focus_child->vt = VT_I4; diff --git a/views/controls/button/button.cc b/views/controls/button/button.cc index e9f7e2b..c43439c 100644 --- a/views/controls/button/button.cc +++ b/views/controls/button/button.cc @@ -31,7 +31,7 @@ void Button::SetAccessibleKeyboardShortcut(const string16& shortcut) { //////////////////////////////////////////////////////////////////////////////// // Button, View overrides: -bool Button::GetTooltipText(const gfx::Point& p, string16* tooltip) { +bool Button::GetTooltipText(const gfx::Point& p, string16* tooltip) const { if (tooltip_text_.empty()) return false; diff --git a/views/controls/button/button.h b/views/controls/button/button.h index f1f1a10..0884ea1 100644 --- a/views/controls/button/button.h +++ b/views/controls/button/button.h @@ -40,7 +40,8 @@ class VIEWS_EXPORT Button : public View { void SetAccessibleKeyboardShortcut(const string16& shortcut); // Overridden from View: - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; protected: diff --git a/views/controls/button/image_button.cc b/views/controls/button/image_button.cc index 76ed12c..8379b41 100644 --- a/views/controls/button/image_button.cc +++ b/views/controls/button/image_button.cc @@ -163,7 +163,7 @@ void ToggleImageButton::SetImage(ButtonState state, const SkBitmap* image) { // ToggleImageButton, View overrides: bool ToggleImageButton::GetTooltipText(const gfx::Point& p, - string16* tooltip) { + string16* tooltip) const { if (!toggled_ || toggled_tooltip_text_.empty()) return Button::GetTooltipText(p, tooltip); diff --git a/views/controls/button/image_button.h b/views/controls/button/image_button.h index 0dc3ab4..2ba26fa 100644 --- a/views/controls/button/image_button.h +++ b/views/controls/button/image_button.h @@ -96,10 +96,11 @@ class VIEWS_EXPORT ToggleImageButton : public ImageButton { void SetToggledTooltipText(const string16& tooltip); // Overridden from ImageButton: - virtual void SetImage(ButtonState aState, const SkBitmap* anImage); + virtual void SetImage(ButtonState aState, const SkBitmap* anImage) OVERRIDE; // Overridden from View: - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip); + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; private: // The parent class's images_ member is used for the current images, diff --git a/views/controls/image_view.cc b/views/controls/image_view.cc index c0dcad3..c6a5441 100644 --- a/views/controls/image_view.cc +++ b/views/controls/image_view.cc @@ -140,7 +140,7 @@ void ImageView::SetHorizontalAlignment(Alignment ha) { } } -ImageView::Alignment ImageView::GetHorizontalAlignment() { +ImageView::Alignment ImageView::GetHorizontalAlignment() const { return horiz_alignment_; } @@ -151,7 +151,7 @@ void ImageView::SetVerticalAlignment(Alignment va) { } } -ImageView::Alignment ImageView::GetVerticalAlignment() { +ImageView::Alignment ImageView::GetVerticalAlignment() const { return vert_alignment_; } @@ -159,11 +159,11 @@ void ImageView::SetTooltipText(const string16& tooltip) { tooltip_text_ = tooltip; } -string16 ImageView::GetTooltipText() { +string16 ImageView::GetTooltipText() const { return tooltip_text_; } -bool ImageView::GetTooltipText(const gfx::Point& p, string16* tooltip) { +bool ImageView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { if (tooltip_text_.empty()) return false; diff --git a/views/controls/image_view.h b/views/controls/image_view.h index 2bd4a92..8207aa3 100644 --- a/views/controls/image_view.h +++ b/views/controls/image_view.h @@ -64,21 +64,22 @@ class VIEWS_EXPORT ImageView : public View { // Set / Get the horizontal alignment. void SetHorizontalAlignment(Alignment ha); - Alignment GetHorizontalAlignment(); + Alignment GetHorizontalAlignment() const; // Set / Get the vertical alignment. void SetVerticalAlignment(Alignment va); - Alignment GetVerticalAlignment(); + Alignment GetVerticalAlignment() const; // Set / Get the tooltip text. void SetTooltipText(const string16& tooltip); - string16 GetTooltipText(); + string16 GetTooltipText() const; // Overriden from View virtual gfx::Size GetPreferredSize() OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; private: // Compute the image origin given the desired size and the receiver alignment diff --git a/views/controls/label.cc b/views/controls/label.cc index 16248d9..5473eb4 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -239,7 +239,7 @@ void Label::OnMouseExited(const MouseEvent& event) { SetContainsMouse(false); } -bool Label::GetTooltipText(const gfx::Point& p, string16* tooltip) { +bool Label::GetTooltipText(const gfx::Point& p, string16* tooltip) const { DCHECK(tooltip); // If a tooltip has been explicitly set, use it. diff --git a/views/controls/label.h b/views/controls/label.h index 1b7035c..bcc5423 100644 --- a/views/controls/label.h +++ b/views/controls/label.h @@ -186,7 +186,8 @@ class VIEWS_EXPORT Label : public View { // when the label is multiline, in which case it just returns false (no // tooltip). If a custom tooltip has been specified with SetTooltipText() // it is returned instead. - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; protected: // Called by Paint to paint the text. Override this to change how diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index 359cbb7..5de3ab3 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -1015,9 +1015,8 @@ bool MenuController::OnKeyDown(ui::KeyboardCode key_code) { // User pressed escape and only one menu is shown, cancel it. Cancel(EXIT_OUTERMOST); return false; - } else { - CloseSubmenu(); } + CloseSubmenu(); break; #if defined(OS_WIN) @@ -1175,12 +1174,11 @@ bool MenuController::ShowSiblingMenu(SubmenuView* source, void MenuController::CloseAllNestedMenus() { for (std::list<State>::iterator i = menu_stack_.begin(); i != menu_stack_.end(); ++i) { - MenuItemView* item = i->item; - MenuItemView* last_item = item; - while (item) { + MenuItemView* last_item = i->item; + for (MenuItemView* item = last_item; item; + item = item->GetParentMenuItem()) { CloseMenu(item); last_item = item; - item = item->GetParentMenuItem(); } i->submenu_open = false; i->item = last_item; @@ -1242,13 +1240,12 @@ MenuController::MenuPart MenuController::GetMenuPartByScreenCoordinateUsingMenu( MenuItemView* item, const gfx::Point& screen_loc) { MenuPart part; - while (item) { + for (; item; item = item->GetParentMenuItem()) { if (item->HasSubmenu() && item->GetSubmenu()->IsShowing() && - GetMenuPartByScreenCoordinateImpl( - item->GetSubmenu(), screen_loc, &part)) { + GetMenuPartByScreenCoordinateImpl(item->GetSubmenu(), screen_loc, + &part)) { return part; } - item = item->GetParentMenuItem(); } return part; } @@ -1364,11 +1361,10 @@ void MenuController::CommitPendingSelection() { // Stop the scrolling if none of the elements of the selection contain // the menu being scrolled. bool found = false; - MenuItemView* item = state_.item; - while (item && !found) { + for (MenuItemView* item = state_.item; item && !found; + item = item->GetParentMenuItem()) { found = (item->HasSubmenu() && item->GetSubmenu()->IsShowing() && item->GetSubmenu() == scroll_task_->submenu()); - item = item->GetParentMenuItem(); } if (!found) StopScrolling(); @@ -1424,15 +1420,16 @@ void MenuController::MenuChildrenChanged(MenuItemView* item) { const MenuItemView* ancestor = state_.item; while (ancestor && ancestor != item) ancestor = ancestor->GetParentMenuItem(); - ancestor = ancestor ? ancestor : pending_state_.item; - while (ancestor && ancestor != item) - ancestor = ancestor->GetParentMenuItem(); - - if (ancestor) { - SetSelection(item, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); - if (item->HasSubmenu()) - OpenMenuImpl(item, false); + if (!ancestor) { + ancestor = pending_state_.item; + while (ancestor && ancestor != item) + ancestor = ancestor->GetParentMenuItem(); + if (!ancestor) + return; } + SetSelection(item, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); + if (item->HasSubmenu()) + OpenMenuImpl(item, false); } void MenuController::BuildPathsAndCalculateDiff( @@ -1600,9 +1597,7 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, // static int MenuController::MenuDepth(MenuItemView* item) { - if (!item) - return 0; - return MenuDepth(item->GetParentMenuItem()) + 1; + return item ? (MenuDepth(item->GetParentMenuItem()) + 1) : 0; } void MenuController::IncrementSelection(int delta) { @@ -1637,8 +1632,8 @@ void MenuController::IncrementSelection(int delta) { } } - if (item->GetParentMenuItem()) { - MenuItemView* parent = item->GetParentMenuItem(); + MenuItemView* parent = item->GetParentMenuItem(); + if (parent) { int parent_count = parent->GetSubmenu()->GetMenuItemCount(); if (parent_count > 1) { for (int i = 0; i < parent_count; ++i) { @@ -1695,11 +1690,10 @@ void MenuController::CloseSubmenu() { DCHECK(item); if (!item->GetParentMenuItem()) return; - if (item->HasSubmenu() && item->GetSubmenu()->IsShowing()) { + if (item->HasSubmenu() && item->GetSubmenu()->IsShowing()) SetSelection(item, SELECTION_UPDATE_IMMEDIATELY); - } else if (item->GetParentMenuItem()->GetParentMenuItem()) { + else if (item->GetParentMenuItem()->GetParentMenuItem()) SetSelection(item->GetParentMenuItem(), SELECTION_UPDATE_IMMEDIATELY); - } } MenuController::SelectByCharDetails MenuController::FindChildForMnemonic( diff --git a/views/controls/menu/menu_delegate.cc b/views/controls/menu/menu_delegate.cc index f1f7488..6d5e8250 100644 --- a/views/controls/menu/menu_delegate.cc +++ b/views/controls/menu/menu_delegate.cc @@ -21,7 +21,8 @@ const gfx::Font& MenuDelegate::GetLabelFont(int id) const { return MenuConfig::instance().font; } -string16 MenuDelegate::GetTooltipText(int id, const gfx::Point& screen_loc) { +string16 MenuDelegate::GetTooltipText(int id, + const gfx::Point& screen_loc) const { return string16(); } diff --git a/views/controls/menu/menu_delegate.h b/views/controls/menu/menu_delegate.h index 700e4e84..fbae89a 100644 --- a/views/controls/menu/menu_delegate.h +++ b/views/controls/menu/menu_delegate.h @@ -69,7 +69,7 @@ class VIEWS_EXPORT MenuDelegate { // The tooltip shown for the menu item. This is invoked when the user // hovers over the item, and no tooltip text has been set for that item. - virtual string16 GetTooltipText(int id, const gfx::Point& screen_loc); + virtual string16 GetTooltipText(int id, const gfx::Point& screen_loc) const; // If there is an accelerator for the menu item with id |id| it is set in // |accelerator| and true is returned. diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index fec96ab..78fcb95 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -39,7 +39,8 @@ class EmptyMenuMenuItem : public MenuItemView { SetEnabled(false); } - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE { + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE { // Empty menu items shouldn't have a tooltip. return false; } @@ -104,7 +105,8 @@ void MenuItemView::ChildPreferredSizeChanged(View* child) { PreferredSizeChanged(); } -bool MenuItemView::GetTooltipText(const gfx::Point& p, string16* tooltip) { +bool MenuItemView::GetTooltipText(const gfx::Point& p, + string16* tooltip) const { *tooltip = tooltip_; if (!tooltip->empty()) return true; @@ -112,14 +114,14 @@ bool MenuItemView::GetTooltipText(const gfx::Point& p, string16* tooltip) { if (GetType() == SEPARATOR) return false; - MenuController* controller = GetMenuController(); + const MenuController* controller = GetMenuController(); if (!controller || controller->exit_type() != MenuController::EXIT_NONE) { // Either the menu has been closed or we're in the process of closing the // menu. Don't attempt to query the delegate as it may no longer be valid. return false; } - MenuItemView* root_menu_item = GetRootMenuItem(); + const MenuItemView* root_menu_item = GetRootMenuItem(); if (root_menu_item->canceled_) { // TODO(sky): if |canceled_| is true, controller->exit_type() should be // something other than EXIT_NONE, but crash reports seem to indicate @@ -127,10 +129,11 @@ bool MenuItemView::GetTooltipText(const gfx::Point& p, string16* tooltip) { return false; } - CHECK(GetDelegate()); + const MenuDelegate* delegate = GetDelegate(); + CHECK(delegate); gfx::Point location(p); ConvertPointToScreen(this, &location); - *tooltip = GetDelegate()->GetTooltipText(command_, location); + *tooltip = delegate->GetTooltipText(command_, location); return !tooltip->empty(); } @@ -367,20 +370,29 @@ MenuController* MenuItemView::GetMenuController() { return GetRootMenuItem()->controller_; } +const MenuController* MenuItemView::GetMenuController() const { + return GetRootMenuItem()->controller_; +} + MenuDelegate* MenuItemView::GetDelegate() { return GetRootMenuItem()->delegate_; } +const MenuDelegate* MenuItemView::GetDelegate() const { + return GetRootMenuItem()->delegate_; +} + MenuItemView* MenuItemView::GetRootMenuItem() { - MenuItemView* item = this; - while (item) { - MenuItemView* parent = item->GetParentMenuItem(); - if (!parent) - return item; + return const_cast<MenuItemView*>( + static_cast<const MenuItemView*>(this)->GetRootMenuItem()); +} + +const MenuItemView* MenuItemView::GetRootMenuItem() const { + const MenuItemView* item = this; + for (const MenuItemView* parent = GetParentMenuItem(); parent; + parent = item->GetParentMenuItem()) item = parent; - } - NOTREACHED(); - return NULL; + return item; } char16 MenuItemView::GetMnemonic() { @@ -603,10 +615,8 @@ int MenuItemView::GetDrawStringFlags() { const gfx::Font& MenuItemView::GetFont() { // Check for item-specific font. const MenuDelegate* delegate = GetDelegate(); - if (delegate) - return delegate->GetLabelFont(GetCommand()); - else - return MenuConfig::instance().font; + return delegate ? + delegate->GetLabelFont(GetCommand()) : MenuConfig::instance().font; } void MenuItemView::AddEmptyMenus() { diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h index 68d35ea..8586885 100644 --- a/views/controls/menu/menu_item_view.h +++ b/views/controls/menu/menu_item_view.h @@ -112,7 +112,8 @@ class VIEWS_EXPORT MenuItemView : public View { explicit MenuItemView(MenuDelegate* delegate); // Overridden from View: - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; // Returns the preferred height of menu items. This is only valid when the @@ -209,14 +210,15 @@ class VIEWS_EXPORT MenuItemView : public View { virtual SubmenuView* GetSubmenu() const; // Returns the parent menu item. - MenuItemView* GetParentMenuItem() const { return parent_menu_item_; } + MenuItemView* GetParentMenuItem() { return parent_menu_item_; } + const MenuItemView* GetParentMenuItem() const { return parent_menu_item_; } // Sets/Gets the title. void SetTitle(const string16& title); const string16& title() const { return title_; } // Returns the type of this menu. - const Type& GetType() { return type_; } + const Type& GetType() const { return type_; } // Sets whether this item is selected. This is invoked as the user moves // the mouse around the menu while open. @@ -251,13 +253,16 @@ class VIEWS_EXPORT MenuItemView : public View { // Returns the object responsible for controlling showing the menu. MenuController* GetMenuController(); + const MenuController* GetMenuController() const; // Returns the delegate. This returns the delegate of the root menu item. MenuDelegate* GetDelegate(); + const MenuDelegate* GetDelegate() const; void set_delegate(MenuDelegate* delegate) { delegate_ = delegate; } // Returns the root parent, or this if this has no parent. MenuItemView* GetRootMenuItem(); + const MenuItemView* GetRootMenuItem() const; // Returns the mnemonic for this MenuItemView, or 0 if this MenuItemView // doesn't have a mnemonic. diff --git a/views/controls/progress_bar.cc b/views/controls/progress_bar.cc index 0d70b7b..587e6dc 100644 --- a/views/controls/progress_bar.cc +++ b/views/controls/progress_bar.cc @@ -289,7 +289,7 @@ void ProgressBar::OnPaint(gfx::Canvas* canvas) { #endif } -bool ProgressBar::GetTooltipText(const gfx::Point& p, string16* tooltip) { +bool ProgressBar::GetTooltipText(const gfx::Point& p, string16* tooltip) const { DCHECK(tooltip); if (tooltip == NULL) return false; diff --git a/views/controls/progress_bar.h b/views/controls/progress_bar.h index c4d3f24..65247b0 100644 --- a/views/controls/progress_bar.h +++ b/views/controls/progress_bar.h @@ -39,7 +39,8 @@ class VIEWS_EXPORT ProgressBar : public View { virtual std::string GetClassName() const OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; // Sets the inclusive range of values to be displayed. Values outside of the // range will be capped when displayed. diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc index 773761d..e975e4a 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -66,7 +66,7 @@ class TabLayout : public LayoutManager { FocusManager* focus_manager = page->GetFocusManager(); DCHECK(focus_manager); - View* focused_view = focus_manager->GetFocusedView(); + const View* focused_view = focus_manager->GetFocusedView(); if (focused_view && host->Contains(focused_view) && !page->Contains(focused_view)) focus_manager->SetFocusedView(page); diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h index 8650d2c..484e441 100644 --- a/views/focus/focus_manager.h +++ b/views/focus/focus_manager.h @@ -140,7 +140,8 @@ class VIEWS_EXPORT FocusManager { void AdvanceFocus(bool reverse); // The FocusManager keeps track of the focused view within a RootView. - View* GetFocusedView() const { return focused_view_; } + View* GetFocusedView() { return focused_view_; } + const View* GetFocusedView() const { return focused_view_; } // Low-level methods to force the focus to change (and optionally provide // a reason). If the focus change should only happen if the view is diff --git a/views/view.cc b/views/view.cc index e12e83c..4f04208 100644 --- a/views/view.cc +++ b/views/view.cc @@ -869,11 +869,9 @@ bool View::AcceleratorPressed(const Accelerator& accelerator) { // Focus ----------------------------------------------------------------------- -bool View::HasFocus() { - FocusManager* focus_manager = GetFocusManager(); - if (focus_manager) - return focus_manager->GetFocusedView() == this; - return false; +bool View::HasFocus() const { + const FocusManager* focus_manager = GetFocusManager(); + return focus_manager && (focus_manager->GetFocusedView() == this); } View* View::GetNextFocusableView() { @@ -907,6 +905,11 @@ FocusManager* View::GetFocusManager() { return widget ? widget->GetFocusManager() : NULL; } +const FocusManager* View::GetFocusManager() const { + const Widget* widget = GetWidget(); + return widget ? widget->GetFocusManager() : NULL; +} + void View::RequestFocus() { FocusManager* focus_manager = GetFocusManager(); if (focus_manager && IsFocusableInRootView()) @@ -927,11 +930,11 @@ FocusTraversable* View::GetPaneFocusTraversable() { // Tooltips -------------------------------------------------------------------- -bool View::GetTooltipText(const gfx::Point& p, string16* tooltip) { +bool View::GetTooltipText(const gfx::Point& p, string16* tooltip) const { return false; } -bool View::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc) { +bool View::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc) const { return false; } diff --git a/views/view.h b/views/view.h index 0e06113..d86c805 100644 --- a/views/view.h +++ b/views/view.h @@ -652,7 +652,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Focus --------------------------------------------------------------------- // Returns whether this view currently has the focus. - virtual bool HasFocus(); + virtual bool HasFocus() const; // Returns the view that should be selected next when pressing Tab. View* GetNextFocusableView(); @@ -692,6 +692,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Widget that contains this view. This can return NULL if this view is not // part of a view hierarchy with a Widget. virtual FocusManager* GetFocusManager(); + virtual const FocusManager* GetFocusManager() const; // Request the keyboard focus. The receiving view will become the // focused view. @@ -733,12 +734,12 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Any time the tooltip text that a View is displaying changes, it must // invoke TooltipTextChanged. // |p| provides the coordinates of the mouse (relative to this view). - virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip); + virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) const; // Returns the location (relative to this View) for the text on the tooltip // to display. If false is returned (the default), the tooltip is placed at // a default position. - virtual bool GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc); + virtual bool GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* loc) const; // Context menus ------------------------------------------------------------- diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index 712bc52a..878e236 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -320,8 +320,8 @@ void RootView::OnMouseExited(const MouseEvent& event) { bool RootView::OnMouseWheel(const MouseWheelEvent& event) { MouseWheelEvent e(event, this); bool consumed = false; - View* v = GetFocusManager()->GetFocusedView(); - for (; v && v != this && !consumed; v = v->parent()) + for (View* v = GetFocusManager()->GetFocusedView(); + v && v != this && !consumed; v = v->parent()) consumed = v->OnMouseWheel(e); return consumed; } diff --git a/views/widget/tooltip_manager_gtk.cc b/views/widget/tooltip_manager_gtk.cc index 8515fa9..f9993196 100644 --- a/views/widget/tooltip_manager_gtk.cc +++ b/views/widget/tooltip_manager_gtk.cc @@ -71,7 +71,7 @@ TooltipManagerGtk::TooltipManagerGtk(NativeWidgetGtk* widget) bool TooltipManagerGtk::ShowTooltip(int x, int y, bool for_keyboard, GtkTooltip* tooltip) { - View* view = NULL; + const View* view = NULL; gfx::Point view_loc; if (keyboard_view_) { view = keyboard_view_; @@ -82,7 +82,7 @@ bool TooltipManagerGtk::ShowTooltip(int x, int y, bool for_keyboard, view_loc.SetPoint(x, y); View::ConvertPointFromWidget(view, &view_loc); } else { - FocusManager* focus_manager = widget_->GetWidget()->GetFocusManager(); + const FocusManager* focus_manager = widget_->GetWidget()->GetFocusManager(); if (focus_manager) { view = focus_manager->GetFocusedView(); if (view) diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 891bafd..6670fe84 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -388,7 +388,7 @@ void Widget::NotifyNativeViewHierarchyChanged(bool attached, Widget* Widget::GetTopLevelWidget() { return const_cast<Widget*>( - const_cast<const Widget*>(this)->GetTopLevelWidget()); + static_cast<const Widget*>(this)->GetTopLevelWidget()); } const Widget* Widget::GetTopLevelWidget() const { @@ -396,9 +396,7 @@ const Widget* Widget::GetTopLevelWidget() const { // property is gone after gobject gets deleted. Short circuit here // for toplevel so that InputMethod can remove itself from // focus manager. - if (is_top_level()) - return this; - return native_widget_->GetTopLevelWidget(); + return is_top_level() ? this : native_widget_->GetTopLevelWidget(); } void Widget::SetContentsView(View* view) { @@ -618,6 +616,11 @@ ThemeProvider* Widget::GetThemeProvider() const { } FocusManager* Widget::GetFocusManager() { + Widget* toplevel_widget = GetTopLevelWidget(); + return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; +} + +const FocusManager* Widget::GetFocusManager() const { const Widget* toplevel_widget = GetTopLevelWidget(); return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; } diff --git a/views/widget/widget.h b/views/widget/widget.h index d4b4f37..ba0445b 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -402,6 +402,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, // Note that all widgets in a widget hierarchy share the same focus manager. // TODO(beng): remove virtual. virtual FocusManager* GetFocusManager(); + virtual const FocusManager* GetFocusManager() const; // Returns the InputMethod for this widget. // Note that all widgets in a widget hierarchy share the same input method. |