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

Side by Side Diff: chrome/browser/ui/tabs/recently_closed_tabs_menu_model.cc

Issue 10561003: Implementaion for showing recently closed tabs list on right clicking new tab button. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 6 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 | « chrome/browser/ui/tabs/recently_closed_tabs_menu_model.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "build/build_config.h"
6
7 #include "chrome/browser/ui/tabs/recently_closed_tabs_menu_model.h"
8 #include "chrome/browser/ui/tabs/recently_closed_tabs_sub_menu_model.h"
9
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/string_number_conversions.h"
13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/event_disposition.h"
15 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
16 #include "chrome/browser/sessions/tab_restore_service_factory.h"
17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
21 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h"
23 #include "content/public/browser/favicon_status.h"
24 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/web_contents.h"
26 #include "grit/generated_resources.h"
27 #include "grit/theme_resources.h"
28 #include "grit/theme_resources_standard.h"
29 #include "grit/ui_resources.h"
30 #include "net/base/registry_controlled_domain.h"
31 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/base/text/text_elider.h"
34 #include "ui/gfx/codec/png_codec.h"
35
36
37 using content::NavigationEntry;
38
39 static const int kMaxWidth = 700;
40
41 RecentlyClosedTabsMenuModel::RecentlyClosedTabsMenuModel(Browser* browser)
42 : browser_(browser),
43 menu_model_delegate_(NULL) {
44 tab_restore_service_ =
45 TabRestoreServiceFactory::GetForProfile(browser_->profile());
46 }
47
48 RecentlyClosedTabsMenuModel::~RecentlyClosedTabsMenuModel() {
49 }
50
51 bool RecentlyClosedTabsMenuModel::HasIcons() const {
52 return true;
53 }
54
55 int RecentlyClosedTabsMenuModel::GetItemCount() const {
56 int items = GetRecentlyClosedItemCount();
57 return items;
58 }
59
60 ui::MenuModel::ItemType
61 RecentlyClosedTabsMenuModel::GetTypeAt(int index) const {
62 return TYPE_COMMAND;
63 }
64
65 int RecentlyClosedTabsMenuModel::GetCommandIdAt(int index) const {
66 return index;
67 }
68
69 TabRestoreService::Entry*
70 RecentlyClosedTabsMenuModel::GetNavigationEntryAt(int index) const {
71 TabRestoreService::Entries entries = tab_restore_service_->entries();
72 int count = 0;
73 TabRestoreService::Entry* entry;
74 for (TabRestoreService::Entries::const_iterator it = entries.begin();
75 it != entries.end(); ++it) {
76 if (count == index) {
77 entry = *it;
78 return entry;
79 }
80 count++;
81 }
82 return NULL;
83 }
84
85 string16 RecentlyClosedTabsMenuModel::GetLabelAt(int index) const {
86 int i = index;
87 TabRestoreService::Entry* entry = GetNavigationEntryAt(i);
88 // Return the entry title, escaping any '&' characters and eliding it if it's
89 // super long.
90 string16 menu_text;
91 if (entry->type == TabRestoreService::TAB) {
92 const TabRestoreService::Tab tab
93 = *static_cast<TabRestoreService::Tab*>(entry);
94 const TabNavigation& current_navigation =
95 tab.navigations.at(tab.current_navigation_index);
96 menu_text = current_navigation.title();
97 } else {
98 const TabRestoreService::Window window
99 = *static_cast<TabRestoreService::Window*>(entry);
100 std::string text = base::IntToString(window.tabs.size());
101 text = text + " Tabs";
102 menu_text = UTF8ToUTF16(text);
103 }
104 menu_text =
105 ui::ElideText(menu_text, gfx::Font(), kMaxWidth, ui::ELIDE_AT_END);
106
107 #if !defined(OS_MACOSX)
108 for (size_t i = menu_text.find('&'); i != string16::npos;
109 i = menu_text.find('&', i + 2)) {
110 menu_text.insert(i, 1, '&');
111 }
112 #endif
113
114 return menu_text;
115 }
116
117 bool RecentlyClosedTabsMenuModel::IsItemDynamicAt(int index) const {
118 return false;
119 }
120
121 bool RecentlyClosedTabsMenuModel::GetAcceleratorAt(
122 int index,
123 ui::Accelerator* accelerator) const {
124 return false;
125 }
126
127 bool RecentlyClosedTabsMenuModel::IsItemCheckedAt(int index) const {
128 return false;
129 }
130
131 int RecentlyClosedTabsMenuModel::GetGroupIdAt(int index) const {
132 return false;
133 }
134
135 NavigationEntry* nav_entry = NULL;
136 bool RecentlyClosedTabsMenuModel::GetIconAt(int index, gfx::ImageSkia* icon) {
137 TabRestoreService::Entry* entry = GetNavigationEntryAt(index);
138 if (entry->type == TabRestoreService::WINDOW) {
139 *icon = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
140 IDR_HISTORY_FAVICON);
141 } else {
142 const TabRestoreService::Tab tab
143 = *static_cast<TabRestoreService::Tab*>(entry);
144 const TabNavigation& current_navigation =
145 tab.navigations.at(tab.current_navigation_index);
146 nav_entry = current_navigation.ToNavigationEntry(index,
147 browser_->profile());
148 *icon = nav_entry->GetFavicon().bitmap;
149 }
150 return true;
151 }
152
153 ui::ButtonMenuItemModel* RecentlyClosedTabsMenuModel::GetButtonMenuItemAt(
154 int index) const {
155 return NULL;
156 }
157
158 bool RecentlyClosedTabsMenuModel::IsEnabledAt(int index) const {
159 return true;
160 }
161
162 ui::MenuModel* RecentlyClosedTabsMenuModel::GetSubmenuModelAt(int index) const {
163 return NULL;
164 }
165
166 void RecentlyClosedTabsMenuModel::HighlightChangedTo(int index) {
167 }
168
169 void RecentlyClosedTabsMenuModel::ActivatedAt(int index) {
170 ActivatedAt(index, 0);
171 }
172
173 void RecentlyClosedTabsMenuModel::ActivatedAt(int index, int event_flags) {
174 TabRestoreService::Entry* entry = GetNavigationEntryAt(index);
175 TabRestoreServiceDelegate* delegate =
176 TabRestoreServiceDelegate::FindDelegateForController(
177 &browser_->GetSelectedTabContentsWrapper()->
178 web_contents()->GetController(), NULL);
179 if (!delegate)
180 return;
181 tab_restore_service_->RestoreEntryById(delegate,
182 entry->id,
183 NEW_FOREGROUND_TAB);
184 }
185
186 void RecentlyClosedTabsMenuModel::MenuWillShow() {
187 }
188
189 int RecentlyClosedTabsMenuModel::GetRecentlyClosedItemCount() const {
190 TabRestoreService::Entries entries = tab_restore_service_->entries();
191 return entries.size();
192 }
193
194 void RecentlyClosedTabsMenuModel::SetMenuModelDelegate(
195 ui::MenuModelDelegate* menu_model_delegate) {
196 menu_model_delegate_ = menu_model_delegate;
197 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tabs/recently_closed_tabs_menu_model.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698