| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_ | 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_ |
| 6 #define CHROME_BROWSER_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_ | 6 #define CHROME_BROWSER_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "chrome/browser/favicon_service.h" |
| 14 #include "ui/base/models/menu_model.h" | 16 #include "ui/base/models/menu_model.h" |
| 15 #include "webkit/glue/window_open_disposition.h" | 17 #include "webkit/glue/window_open_disposition.h" |
| 16 | 18 |
| 17 class Browser; | 19 class Browser; |
| 18 class SkBitmap; | 20 class SkBitmap; |
| 19 class TabContents; | 21 class TabContents; |
| 20 class NavigationEntry; | 22 class NavigationEntry; |
| 21 | 23 |
| 22 /////////////////////////////////////////////////////////////////////////////// | 24 /////////////////////////////////////////////////////////////////////////////// |
| 23 // | 25 // |
| (...skipping 22 matching lines...) Expand all Loading... |
| 46 // out the total number of items to show. | 48 // out the total number of items to show. |
| 47 virtual int GetItemCount() const; | 49 virtual int GetItemCount() const; |
| 48 virtual ItemType GetTypeAt(int index) const; | 50 virtual ItemType GetTypeAt(int index) const; |
| 49 virtual int GetCommandIdAt(int index) const; | 51 virtual int GetCommandIdAt(int index) const; |
| 50 virtual string16 GetLabelAt(int index) const; | 52 virtual string16 GetLabelAt(int index) const; |
| 51 virtual bool IsItemDynamicAt(int index) const; | 53 virtual bool IsItemDynamicAt(int index) const; |
| 52 virtual bool GetAcceleratorAt(int index, | 54 virtual bool GetAcceleratorAt(int index, |
| 53 ui::Accelerator* accelerator) const; | 55 ui::Accelerator* accelerator) const; |
| 54 virtual bool IsItemCheckedAt(int index) const; | 56 virtual bool IsItemCheckedAt(int index) const; |
| 55 virtual int GetGroupIdAt(int index) const; | 57 virtual int GetGroupIdAt(int index) const; |
| 56 virtual bool GetIconAt(int index, SkBitmap* icon) const; | 58 virtual bool GetIconAt(int index, SkBitmap* icon); |
| 57 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; | 59 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; |
| 58 virtual bool IsEnabledAt(int index) const; | 60 virtual bool IsEnabledAt(int index) const; |
| 59 virtual MenuModel* GetSubmenuModelAt(int index) const; | 61 virtual MenuModel* GetSubmenuModelAt(int index) const; |
| 60 virtual void HighlightChangedTo(int index); | 62 virtual void HighlightChangedTo(int index); |
| 61 virtual void ActivatedAt(int index); | 63 virtual void ActivatedAt(int index); |
| 62 virtual void ActivatedAtWithDisposition(int index, int disposition); | 64 virtual void ActivatedAtWithDisposition(int index, int disposition); |
| 63 virtual void MenuWillShow(); | 65 virtual void MenuWillShow(); |
| 64 | 66 |
| 65 // Is the item at |index| a separator? | 67 // Is the item at |index| a separator? |
| 66 bool IsSeparator(int index) const; | 68 bool IsSeparator(int index) const; |
| 67 | 69 |
| 70 // Set the delegate for triggering OnIconChanged. |
| 71 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* menu_model_delegate); |
| 72 |
| 73 protected: |
| 74 ui::MenuModelDelegate* menu_model_delegate() { return menu_model_delegate_; } |
| 75 |
| 68 private: | 76 private: |
| 77 friend class BackFwdMenuModelTest; |
| 78 FRIEND_TEST_ALL_PREFIXES(BackFwdMenuModelTest, BasicCase); |
| 79 FRIEND_TEST_ALL_PREFIXES(BackFwdMenuModelTest, MaxItemsTest); |
| 80 FRIEND_TEST_ALL_PREFIXES(BackFwdMenuModelTest, ChapterStops); |
| 81 FRIEND_TEST_ALL_PREFIXES(BackFwdMenuModelTest, EscapeLabel); |
| 82 FRIEND_TEST_ALL_PREFIXES(BackFwdMenuModelTest, FaviconLoadTest); |
| 83 |
| 84 // Requests a favicon from the FaviconService. Called by GetIconAt if the |
| 85 // NavigationEntry has an invalid favicon. |
| 86 void FetchFavicon(NavigationEntry* entry); |
| 87 |
| 88 // Callback from the favicon service. |
| 89 void OnFavIconDataAvailable(FaviconService::Handle handle, |
| 90 history::FaviconData favicon); |
| 91 |
| 69 // Allows the unit test to use its own dummy tab contents. | 92 // Allows the unit test to use its own dummy tab contents. |
| 70 void set_test_tab_contents(TabContents* test_tab_contents) { | 93 void set_test_tab_contents(TabContents* test_tab_contents) { |
| 71 test_tab_contents_ = test_tab_contents; | 94 test_tab_contents_ = test_tab_contents; |
| 72 } | 95 } |
| 73 | 96 |
| 74 // Returns how many history items the menu should show. For example, if the | 97 // Returns how many history items the menu should show. For example, if the |
| 75 // navigation controller of the current tab has a current entry index of 5 and | 98 // navigation controller of the current tab has a current entry index of 5 and |
| 76 // forward_direction_ is false (we are the back button delegate) then this | 99 // forward_direction_ is false (we are the back button delegate) then this |
| 77 // function will return 5 (representing 0-4). If forward_direction_ is | 100 // function will return 5 (representing 0-4). If forward_direction_ is |
| 78 // true (we are the forward button delegate), then this function will return | 101 // true (we are the forward button delegate), then this function will return |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 176 |
| 154 Browser* browser_; | 177 Browser* browser_; |
| 155 | 178 |
| 156 // The unit tests will provide their own TabContents to use. | 179 // The unit tests will provide their own TabContents to use. |
| 157 TabContents* test_tab_contents_; | 180 TabContents* test_tab_contents_; |
| 158 | 181 |
| 159 // Represents whether this is the delegate for the forward button or the | 182 // Represents whether this is the delegate for the forward button or the |
| 160 // back button. | 183 // back button. |
| 161 ModelType model_type_; | 184 ModelType model_type_; |
| 162 | 185 |
| 163 friend class BackFwdMenuModelTest; | 186 // Keeps track of which favicons have already been requested from the history |
| 164 FRIEND_TEST_ALL_PREFIXES(BackFwdMenuModelTest, BasicCase); | 187 // to prevent duplicate requests, identified by NavigationEntry->unique_id(). |
| 165 FRIEND_TEST_ALL_PREFIXES(BackFwdMenuModelTest, MaxItemsTest); | 188 std::set<int> requested_favicons_; |
| 166 FRIEND_TEST_ALL_PREFIXES(BackFwdMenuModelTest, ChapterStops); | 189 |
| 167 FRIEND_TEST_ALL_PREFIXES(BackFwdMenuModelTest, EscapeLabel); | 190 // Used for loading favicons from history. |
| 191 CancelableRequestConsumerTSimple<int> load_consumer_; |
| 192 |
| 193 // Used for receiving notifications when an icon is changed. |
| 194 ui::MenuModelDelegate* menu_model_delegate_; |
| 168 | 195 |
| 169 DISALLOW_COPY_AND_ASSIGN(BackForwardMenuModel); | 196 DISALLOW_COPY_AND_ASSIGN(BackForwardMenuModel); |
| 170 }; | 197 }; |
| 171 | 198 |
| 172 #endif // CHROME_BROWSER_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_ | 199 #endif // CHROME_BROWSER_UI_TOOLBAR_BACK_FORWARD_MENU_MODEL_H_ |
| OLD | NEW |