diff options
Diffstat (limited to 'chrome/browser/views/toolbar_view.h')
-rw-r--r-- | chrome/browser/views/toolbar_view.h | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h index 23f5232..62faebf 100644 --- a/chrome/browser/views/toolbar_view.h +++ b/chrome/browser/views/toolbar_view.h @@ -20,6 +20,7 @@ #include "chrome/browser/views/location_bar_view.h" #include "views/controls/button/menu_button.h" #include "views/controls/menu/menu.h" +#include "views/controls/menu/menu_wrapper.h" #include "views/controls/menu/view_menu_delegate.h" #include "views/view.h" @@ -36,6 +37,7 @@ class Menu2; class ToolbarView : public AccessibleToolbarView, public views::ViewMenuDelegate, public views::DragController, + public views::FocusChangeListener, public menus::SimpleMenuModel::Delegate, public LocationBarView::Delegate, public NotificationObserver, @@ -44,7 +46,7 @@ class ToolbarView : public AccessibleToolbarView, public BubblePositioner { public: explicit ToolbarView(Browser* browser); - virtual ~ToolbarView() { } + virtual ~ToolbarView(); // Create the contents of the Browser Toolbar void Init(Profile* profile); @@ -62,6 +64,25 @@ class ToolbarView : public AccessibleToolbarView, // Sets the app menu model. void SetAppMenuModel(AppMenuModel* model); + // Focuses the page menu and enters a special mode where the page + // and app menus are focusable and allow for keyboard navigation just + // like a normal menu bar. As soon as focus leaves one of the menus, + // the special mode is exited. + // + // Pass it the storage id of the view where focus should be returned + // if the user escapes, and the menu button to focus initially. If + // |menu_to_focus| is NULL, it will focus the page menu by default. + // + // Not used on the Mac, which has a "normal" menu bar. + void EnterMenuBarEmulationMode(int last_focused_view_storage_id, + views::MenuButton* menu_to_focus); + + // Add a listener to receive a callback when the menu opens. + void AddMenuListener(views::MenuListener* listener); + + // Remove a menu listener. + void RemoveMenuListener(views::MenuListener* listener); + // Accessors... Browser* browser() const { return browser_; } BrowserActionsContainer* browser_actions() const { return browser_actions_; } @@ -71,6 +92,10 @@ class ToolbarView : public AccessibleToolbarView, views::MenuButton* page_menu() const { return page_menu_; } views::MenuButton* app_menu() const { return app_menu_; } + // Overridden from views::FocusChangeListener: + virtual void FocusWillChange(views::View* focused_before, + views::View* focused_now); + // Overridden from AccessibleToolbarView: virtual bool IsAccessibleViewTraversable(views::View* view); @@ -106,6 +131,7 @@ class ToolbarView : public AccessibleToolbarView, virtual void ExecuteCommand(int command_id); // Overridden from views::View: + virtual bool AcceleratorPressed(const views::Accelerator& accelerator); virtual gfx::Size GetPreferredSize(); virtual void Layout(); virtual void Paint(gfx::Canvas* canvas); @@ -138,6 +164,13 @@ class ToolbarView : public AccessibleToolbarView, void RunPageMenu(const gfx::Point& pt); void RunAppMenu(const gfx::Point& pt); + // Check if the menu exited with a code indicating the user wants to + // switch to the other menu, and then switch to that other menu. + void SwitchToOtherMenuIfNeeded(views::Menu2* previous_menu, + views::MenuButton* next_menu_button); + + void ActivateMenuButton(views::MenuButton* menu_button); + // Types of display mode this toolbar can have. enum DisplayMode { DISPLAYMODE_NORMAL, // Normal toolbar with buttons, etc. @@ -148,6 +181,14 @@ class ToolbarView : public AccessibleToolbarView, return display_mode_ == DISPLAYMODE_NORMAL; } + // Take the menus out of the focus traversal, unregister accelerators, + // and stop listening to focus change events. + void ExitMenuBarEmulationMode(); + + // Restore the view that was focused before EnterMenuBarEmulationMode + // was called. + void RestoreLastFocusedView(); + scoped_ptr<BackForwardMenuModel> back_menu_model_; scoped_ptr<BackForwardMenuModel> forward_menu_model_; @@ -186,6 +227,24 @@ class ToolbarView : public AccessibleToolbarView, // TODO(beng): build these into MenuButton. scoped_ptr<views::Menu2> page_menu_menu_; scoped_ptr<views::Menu2> app_menu_menu_; + + // Save the focus manager rather than calling GetFocusManager(), + // so that we can remove focus listeners in the destructor. + views::FocusManager* focus_manager_; + + // Storage id for the last view that was focused before focus + // was given to one of the toolbar views. + int last_focused_view_storage_id_; + + // Vector of listeners to receive callbacks when the menu opens. + std::vector<views::MenuListener*> menu_listeners_; + + // Are we in the menu bar emulation mode, where the app and page menu + // are temporarily focusable? + bool menu_bar_emulation_mode_; + + // Used to post tasks to switch to the next/previous menu. + ScopedRunnableMethodFactory<ToolbarView> method_factory_; }; #endif // CHROME_BROWSER_VIEWS_TOOLBAR_VIEW_H_ |