Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_BACK_FORWARD_MENU_MODEL_H_ | 5 #ifndef CHROME_BROWSER_BACK_FORWARD_MENU_MODEL_H_ |
| 6 #define CHROME_BROWSER_BACK_FORWARD_MENU_MODEL_H_ | 6 #define CHROME_BROWSER_BACK_FORWARD_MENU_MODEL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 | 11 |
| 12 class Browser; | 12 class Browser; |
| 13 class SkBitmap; | 13 class SkBitmap; |
| 14 class TabContents; | 14 class TabContents; |
| 15 class NavigationEntry; | 15 class NavigationEntry; |
| 16 | 16 |
| 17 /////////////////////////////////////////////////////////////////////////////// | 17 /////////////////////////////////////////////////////////////////////////////// |
| 18 // | 18 // |
| 19 // BackForwardMenuModel | 19 // BackForwardMenuModel |
| 20 // | 20 // |
| 21 // Interface for the showing of the dropdown menu for the Back/Forward buttons. | 21 // Interface for the showing of the dropdown menu for the Back/Forward buttons. |
| 22 // Actual implementations are platform-specific. | 22 // Actual implementations are platform-specific. |
| 23 /////////////////////////////////////////////////////////////////////////////// | 23 /////////////////////////////////////////////////////////////////////////////// |
| 24 class BackForwardMenuModel { | 24 class BackForwardMenuModel { |
| 25 public: | 25 public: |
| 26 // These are IDs used to identify individual UI elements within the | 26 // These are IDs used to identify individual UI elements within the |
| 27 // browser window using View::GetViewByID. | 27 // browser window using View::GetViewByID. |
| 28 enum ModelType { | 28 enum ModelType { |
| 29 FORWARD_MENU_DELEGATE = 1, | 29 FORWARD_MENU = 1, |
| 30 BACKWARD_MENU_DELEGATE = 2 | 30 BACKWARD_MENU = 2 |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 // Factory function. Defined in back_forward_menu_model_{platform}.cc. | 33 BackForwardMenuModel(Browser* browser, ModelType model_type); |
| 34 // This is only used in unit tests. In the browser we use the platform- | |
| 35 // specific constructors directly. | |
| 36 static BackForwardMenuModel* Create(Browser* browser, ModelType model_type); | |
| 37 | |
| 38 virtual ~BackForwardMenuModel() { } | 34 virtual ~BackForwardMenuModel() { } |
| 39 | 35 |
| 40 // Returns how many history items the menu should show. For example, if the | 36 // Returns how many history items the menu should show. For example, if the |
| 41 // navigation controller of the current tab has a current entry index of 5 and | 37 // navigation controller of the current tab has a current entry index of 5 and |
| 42 // forward_direction_ is false (we are the back button delegate) then this | 38 // forward_direction_ is false (we are the back button delegate) then this |
| 43 // function will return 5 (representing 0-4). If forward_direction_ is | 39 // function will return 5 (representing 0-4). If forward_direction_ is |
| 44 // true (we are the forward button delegate), then this function will return | 40 // true (we are the forward button delegate), then this function will return |
| 45 // the number of entries after 5. Note, though, that in either case it will | 41 // the number of entries after 5. Note, though, that in either case it will |
| 46 // not report more than kMaxHistoryItems. The number returned also does not | 42 // not report more than kMaxHistoryItems. The number returned also does not |
| 47 // include the separator line after the history items (nor the separator for | 43 // include the separator line after the history items (nor the separator for |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 // Get the display icon for the item. This should not be called on a | 97 // Get the display icon for the item. This should not be called on a |
| 102 // separator or an item that does not have an icon. | 98 // separator or an item that does not have an icon. |
| 103 const SkBitmap& GetItemIcon(int menu_id) const; | 99 const SkBitmap& GetItemIcon(int menu_id) const; |
| 104 | 100 |
| 105 // Returns true if there is an icon for this menu item. | 101 // Returns true if there is an icon for this menu item. |
| 106 bool ItemHasIcon(int menu_id) const; | 102 bool ItemHasIcon(int menu_id) const; |
| 107 | 103 |
| 108 // Does the item does something when you click on it? | 104 // Does the item does something when you click on it? |
| 109 bool ItemHasCommand(int menu_id) const; | 105 bool ItemHasCommand(int menu_id) const; |
| 110 | 106 |
| 107 #ifdef UNIT_TEST | |
| 111 // Allows the unit test to use its own dummy tab contents. | 108 // Allows the unit test to use its own dummy tab contents. |
| 112 void set_test_tab_contents(TabContents* test_tab_contents) { | 109 void set_test_tab_contents(TabContents* test_tab_contents) { |
| 113 test_tab_contents_ = test_tab_contents; | 110 test_tab_contents_ = test_tab_contents; |
| 114 } | 111 } |
| 112 #endif | |
| 115 | 113 |
| 116 // Allow the unit test to use the "Show Full History" label. | 114 // Allow the unit test to use the "Show Full History" label. |
| 117 std::wstring GetShowFullHistoryLabel() const; | 115 std::wstring GetShowFullHistoryLabel() const; |
| 118 | 116 |
| 119 // Retrieves the TabContents pointer to use, which is either the one that | 117 // Retrieves the TabContents pointer to use, which is either the one that |
| 120 // the unit test sets (using SetTabContentsForUnitTest) or the one from | 118 // the unit test sets (using SetTabContentsForUnitTest) or the one from |
| 121 // the browser window. | 119 // the browser window. |
| 122 TabContents* GetTabContents() const; | 120 TabContents* GetTabContents() const; |
| 123 | 121 |
| 124 // How many items (max) to show in the back/forward history menu dropdown. | 122 // How many items (max) to show in the back/forward history menu dropdown. |
| 125 static const int kMaxHistoryItems; | 123 static const int kMaxHistoryItems; |
| 126 | 124 |
| 127 // How many chapter-stops (max) to show in the back/forward dropdown list. | 125 // How many chapter-stops (max) to show in the back/forward dropdown list. |
| 128 static const int kMaxChapterStops; | 126 static const int kMaxChapterStops; |
| 129 | 127 |
| 130 protected: | 128 protected: |
| 131 BackForwardMenuModel() | |
| 132 : browser_(NULL), | |
| 133 test_tab_contents_(NULL), | |
| 134 model_type_(FORWARD_MENU_DELEGATE) {} | |
| 135 | |
| 136 Browser* browser_; | 129 Browser* browser_; |
|
sky
2009/06/15 15:50:50
nit: while you're here, could you move the members
| |
| 137 | 130 |
| 138 // The unit tests will provide their own TabContents to use. | 131 // The unit tests will provide their own TabContents to use. |
| 139 TabContents* test_tab_contents_; | 132 TabContents* test_tab_contents_; |
| 140 | 133 |
| 141 // Represents whether this is the delegate for the forward button or the | 134 // Represents whether this is the delegate for the forward button or the |
| 142 // back button. | 135 // back button. |
| 143 ModelType model_type_; | 136 ModelType model_type_; |
| 144 | 137 |
| 145 // Converts a menu item id, as passed in through one of the menu delegate | 138 // Converts a menu item id, as passed in through one of the menu delegate |
| 146 // functions and converts it into an absolute index into the | 139 // functions and converts it into an absolute index into the |
| 147 // NavigationEntryList vector. |menu_id| can point to a separator, or the | 140 // NavigationEntryList vector. |menu_id| can point to a separator, or the |
| 148 // "Show Full History" link in which case this function returns -1. | 141 // "Show Full History" link in which case this function returns -1. |
| 149 int MenuIdToNavEntryIndex(int menu_id) const; | 142 int MenuIdToNavEntryIndex(int menu_id) const; |
| 150 | 143 |
| 151 // Looks up a NavigationEntry by menu id. | 144 // Looks up a NavigationEntry by menu id. |
| 152 NavigationEntry* GetNavigationEntry(int menu_id) const; | 145 NavigationEntry* GetNavigationEntry(int menu_id) const; |
| 153 | 146 |
| 154 // Build a string version of a user action on this menu, used as an | 147 // Build a string version of a user action on this menu, used as an |
| 155 // identifier for logging user behavior. | 148 // identifier for logging user behavior. |
| 156 // E.g. BuildActionName("Click", 2) returns "BackMenu_Click2". | 149 // E.g. BuildActionName("Click", 2) returns "BackMenu_Click2". |
| 157 // An index of -1 means no index. | 150 // An index of -1 means no index. |
| 158 std::wstring BuildActionName(const std::wstring& name, int index) const; | 151 std::wstring BuildActionName(const std::wstring& name, int index) const; |
| 159 | 152 |
| 160 private: | 153 private: |
| 161 DISALLOW_COPY_AND_ASSIGN(BackForwardMenuModel); | 154 DISALLOW_COPY_AND_ASSIGN(BackForwardMenuModel); |
| 162 }; | 155 }; |
| 163 | 156 |
| 164 #endif // CHROME_BROWSER_BACK_FORWARD_MENU_MODEL_H_ | 157 #endif // CHROME_BROWSER_BACK_FORWARD_MENU_MODEL_H_ |
| OLD | NEW |