Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h

Issue 23530070: backup for dynamic recent tabs submenu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new RecentTabsMenuModelDelegate w/ new intf Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_RECENT_TABS_SUB_MENU_MODEL_H_ 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ 6 #define CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "chrome/browser/favicon/favicon_service.h" 11 #include "chrome/browser/favicon/favicon_service.h"
12 #include "chrome/browser/sessions/tab_restore_service.h" 12 #include "chrome/browser/sessions/tab_restore_service.h"
13 #include "chrome/browser/sessions/tab_restore_service_observer.h"
13 #include "chrome/browser/sync/glue/synced_session.h" 14 #include "chrome/browser/sync/glue/synced_session.h"
14 #include "chrome/common/cancelable_task_tracker.h" 15 #include "chrome/common/cancelable_task_tracker.h"
15 #include "ui/base/accelerators/accelerator.h" 16 #include "ui/base/accelerators/accelerator.h"
16 #include "ui/base/models/simple_menu_model.h" 17 #include "ui/base/models/simple_menu_model.h"
17 18
18 class Browser; 19 class Browser;
19 struct SessionTab; 20 struct SessionTab;
20 21
21 namespace browser_sync { 22 namespace browser_sync {
22 class SessionModelAssociator; 23 class SessionModelAssociator;
23 } 24 }
24 25
25 namespace chrome { 26 namespace chrome {
26 struct FaviconImageResult; 27 struct FaviconImageResult;
27 } 28 }
28 29
29 namespace gfx { 30 namespace gfx {
30 class Image; 31 class Image;
31 } 32 }
32 33
33 namespace ui { 34 namespace ui {
34 class AcceleratorProvider; 35 class AcceleratorProvider;
35 } 36 }
36 37
37 // A menu model that builds the contents of "Recent tabs" submenu, which include 38 // A menu model that builds the contents of "Recent tabs" submenu, which include
38 // the last closed tab and opened tabs of other devices. 39 // the recently closed tabs/windows of current device i.e. local entries, and
40 // opened tabs of other devices i.e. foreign tabs.
39 class RecentTabsSubMenuModel : public ui::SimpleMenuModel, 41 class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
40 public ui::SimpleMenuModel::Delegate { 42 public ui::SimpleMenuModel::Delegate,
43 public TabRestoreServiceObserver {
41 public: 44 public:
42 // If |associator| is NULL, default associator for |browser|'s profile will 45 // If |associator| is NULL, default associator for |browser|'s profile will
43 // be used. Testing may require a specific |associator|. 46 // be used. Testing may require a specific |associator|.
44 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, 47 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider,
45 Browser* browser, 48 Browser* browser,
46 browser_sync::SessionModelAssociator* associator); 49 browser_sync::SessionModelAssociator* associator);
47 virtual ~RecentTabsSubMenuModel(); 50 virtual ~RecentTabsSubMenuModel();
48 51
52 // Converts index in model to item Id in parent menu (i.e. wrench menu).
53 int ModelIndexToIdInParentMenu(int model_index) const;
54 // Converts item Id in parent menu (i.e. wrench menu) to index in model.
55 int IdInParentMenuToModelIndex(int id_in_parent_menu) const;
56
49 // Overridden from ui::SimpleMenuModel::Delegate: 57 // Overridden from ui::SimpleMenuModel::Delegate:
50 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 58 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
51 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 59 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
52 virtual bool GetAcceleratorForCommandId( 60 virtual bool GetAcceleratorForCommandId(
53 int command_id, 61 int command_id,
54 ui::Accelerator* accelerator) OVERRIDE; 62 ui::Accelerator* accelerator) OVERRIDE;
55 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 63 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
56 virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE; 64 virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE;
57 65
58 int GetMaxWidthForItemAtIndex(int item_index) const; 66 int GetMaxWidthForItemAtIndex(int item_index) const;
59 bool GetURLAndTitleForItemAtIndex(int index, 67 bool GetURLAndTitleForItemAtIndex(int index,
60 std::string* url, 68 std::string* url,
61 string16* title) const; 69 string16* title);
62 70
63 // Command Id for recently closed items header or disabled item to which the 71 // Command Id for recently closed items header or disabled item to which the
64 // accelerator string will be appended. 72 // accelerator string will be appended.
65 static const int kRecentlyClosedHeaderCommandId; 73 static const int kRecentlyClosedHeaderCommandId;
66 static const int kDisabledRecentlyClosedHeaderCommandId; 74 static const int kDisabledRecentlyClosedHeaderCommandId;
67 75
68 // Command Id for other devices section headers, using the device name. 76 // Command Id for other devices section headers, using the device name.
69 static const int kDeviceNameCommandId; 77 static const int kDeviceNameCommandId;
70 78
71 private: 79 private:
72 struct TabNavigationItem; 80 struct TabNavigationItem;
73 typedef std::vector<TabNavigationItem> TabNavigationItems; 81 typedef std::vector<TabNavigationItem> TabNavigationItems;
74 82
75 typedef std::vector<SessionID::id_type> WindowItems; 83 typedef std::vector<SessionID::id_type> WindowItems;
76 84
77 // Build the menu items by populating the model. 85 // Build the menu items by populating the model.
78 void Build(); 86 void Build();
79 void BuildRecentTabs(); 87 void BuildLocalEntries();
80 void BuildDevices(); 88 void BuildForeignTabs();
81 void BuildLocalTabItem(int seesion_id, 89 void BuildLocalTabItem(int seesion_id,
82 const string16& title, 90 const string16& title,
83 const GURL& url); 91 const GURL& url,
92 int curr_model_index);
93 void BuildLocalWindowItem(const SessionID::id_type& window_id,
94 int num_tabs,
95 int curr_model_index);
84 void BuildForeignTabItem(const std::string& session_tag, 96 void BuildForeignTabItem(const std::string& session_tag,
85 const SessionTab& tab); 97 const SessionTab& tab);
86 void BuildWindowItem(const SessionID::id_type& window_id, int num_tabs);
87 void AddDeviceFavicon(int index_in_menu, 98 void AddDeviceFavicon(int index_in_menu,
88 browser_sync::SyncedSession::DeviceType device_type); 99 browser_sync::SyncedSession::DeviceType device_type);
89 void AddTabFavicon(int model_index, int command_id, const GURL& url); 100 void AddTabFavicon(int command_id, const GURL& url);
90 void OnFaviconDataAvailable(int command_id, 101 void OnFaviconDataAvailable(int command_id,
91 const chrome::FaviconImageResult& image_result); 102 const chrome::FaviconImageResult& image_result);
103 void ClearLocalEntries();
104 // Converts |command_id| of menu item to index in local or foreign tab model,
105 // and return the corresponding local or foreign TabNavigationItems in
106 // |tab_items|.
107 int CommandIdToTabModelIndex(int command_id, TabNavigationItems** tab_items);
92 browser_sync::SessionModelAssociator* GetModelAssociator(); 108 browser_sync::SessionModelAssociator* GetModelAssociator();
93 109
110 // Overridden from TabRestoreServiceObserver:
111 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE;
112 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE;
113
94 Browser* browser_; // Weak. 114 Browser* browser_; // Weak.
95 115
96 browser_sync::SessionModelAssociator* associator_; // Weak. 116 browser_sync::SessionModelAssociator* associator_; // Weak.
97 117
98 // Accelerator for reopening last closed tab. 118 // Accelerator for reopening last closed tab.
99 ui::Accelerator reopen_closed_tab_accelerator_; 119 ui::Accelerator reopen_closed_tab_accelerator_;
100 120
101 // Navigation items for other devices and recent tabs. The |command_id| for 121 // Navigation items for local recently closed tabs. The |command_id| for
102 // these is set to kFirstTabCommandId plus the index into the vector. Upon 122 // these is set to kFirstLocalTabCommandId plus the index into the vector.
103 // invocation of the menu, the navigation information is retrieved from 123 // Upon invocation of the menu, the navigation information is retrieved from
104 // |tab_navigation_items_| and used to navigate to the item specified. 124 // |local_tab_navigation_items_| and used to navigate to the item specified.
105 TabNavigationItems tab_navigation_items_; 125 TabNavigationItems local_tab_navigation_items_;
106 126
107 // Window items for recently closed windows. The |command_id| for 127 // Similar to |local_tab_navigation_items_| except the tabs are foreign i.e.
108 // these is set to kFirstWindowCommandId plus the index into the vector. Upon 128 // opened tabs from other devices, and the first |command_id| is
109 // invocation of the menu, information is retrieved from |window_items_| 129 // kFirstForeignTabCommandId.
110 // and used to create the specified window. 130 TabNavigationItems foreign_tab_navigation_items_;
111 WindowItems window_items_; 131
132 // Window items for local recently closed windows. The |command_id| for
133 // these is set to kFirstLocalWindowCommandId plus the index into the vector.
134 // Upon invocation of the menu, information is retrieved from
135 // |local_window_items_| and used to create the specified window.
136 WindowItems local_window_items_;
137
138 // Index of the last local entry (recently closed tab or window) in the model.
139 int last_local_model_index_;
112 140
113 gfx::Image default_favicon_; 141 gfx::Image default_favicon_;
114 142
115 CancelableTaskTracker cancelable_task_tracker_; 143 CancelableTaskTracker local_tab_cancelable_task_tracker_;
144 CancelableTaskTracker foreign_tab_cancelable_task_tracker_;
116 145
117 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_; 146 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_;
118 147
119 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel); 148 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel);
120 }; 149 };
121 150
122 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ 151 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698