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

Side by Side Diff: chrome/browser/ui/views/recent_tabs_menu_model_delegate.cc

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
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 "chrome/browser/ui/views/recent_tabs_menu_model_delegate.h"
6
7 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h"
8 #include "chrome/browser/ui/views/menu_items_changed_delegate.h"
9 #include "ui/views/controls/menu/submenu_view.h"
10
11 RecentTabsMenuModelDelegate::RecentTabsMenuModelDelegate(
12 MenuItemsChangedDelegate* items_changed_delegate,
13 RecentTabsSubMenuModel* model,
14 views::MenuItemView* menu_item,
15 int first_command_id,
16 int max_command_id)
17 : items_changed_delegate_(items_changed_delegate),
18 model_(model),
19 menu_item_(menu_item),
20 first_command_id_(first_command_id),
21 max_command_id_(max_command_id) {
22 model_->SetMenuModelDelegate(this);
23 }
24
25 RecentTabsMenuModelDelegate::~RecentTabsMenuModelDelegate() {
26 model_->SetMenuModelDelegate(NULL);
27 }
28
29 void RecentTabsMenuModelDelegate::PopulateMenu() {
30 for (int i = 0; i < model_->GetItemCount(); ++i) {
31 items_changed_delegate_->OnItemAdded(menu_item_, i, model_, i,
32 ModelIndexToMenuItemId(i));
33 }
34 }
35
36 int RecentTabsMenuModelDelegate::GetMaxWidthForMenu(views::MenuItemView* menu) {
37 if (!menu_item_->HasSubmenu())
38 return -1;
39 const int kMaxMenuItemWidth = 320;
40 return menu->GetCommand() == menu_item_->GetCommand() ?
41 kMaxMenuItemWidth : -1;
42 }
43
44 const gfx::Font* RecentTabsMenuModelDelegate::GetLabelFontAt(
45 int item_id) const {
46 int model_index = MenuItemIdToModelIndex(item_id);
47 return model_->GetLabelFontAt(model_index);
48 }
49
50 bool RecentTabsMenuModelDelegate::GetForegroundColor(
51 int command_id,
52 bool is_hovered,
53 SkColor* override_color) const {
54 // The items for which we get a font, should be shown in black.
55 if (GetLabelFontAt(command_id)) {
56 *override_color = SK_ColorBLACK;
57 return true;
58 }
59 return false;
60 }
61
62 void RecentTabsMenuModelDelegate::OnIconChanged(int index) {
63 int id = ModelIndexToMenuItemId(index);
64 views::MenuItemView* item = menu_item_->GetMenuItemByID(id);
65 DCHECK(item);
66 gfx::Image icon;
67 if (model_->GetIconAt(index, &icon))
68 item->SetIcon(*icon.ToImageSkia());
69 }
70
71 void RecentTabsMenuModelDelegate::PrepareForChange() {
72 }
73
74 void RecentTabsMenuModelDelegate::OnItemRemoved(int index) {
75 items_changed_delegate_->OnItemRemoved(menu_item_, index,
76 ModelIndexToMenuItemId(index));
77 }
78
79 void RecentTabsMenuModelDelegate::OnItemAdded(int index) {
80 // Add menu item at |index|.
81 items_changed_delegate_->OnItemAdded(menu_item_, index, model_, index,
82 ModelIndexToMenuItemId(index));
83 }
84
85 void RecentTabsMenuModelDelegate::ChangesDone() {
86 views::SubmenuView* submenu = menu_item_->GetSubmenu();
87 for (int i = 0; i < submenu->GetMenuItemCount(); ++i) {
88 views::MenuItemView* item = submenu->GetMenuItemAt(i);
89 LOG(ERROR) << "kk done: " << i << ": cmd=" << item->GetCommand() << ", " << item ->title();
90 }
91 std::vector<int> item_ids;
92 for (int i = 0; i < model_->GetItemCount(); ++i)
93 item_ids.push_back(ModelIndexToMenuItemId(i));
94 items_changed_delegate_->UpdateMapOfMenuItemIdAndModel(model_, item_ids);
95
96 /*
97 // If menu items were removed/added (via OnItemRemoved/OnItemAdded), the
98 // indexes of unchanged items would be affected, update them in
99 // |id_to_entry_|.
100 for (WrenchMenu::IDToEntry::iterator iter =
101 wrench_menu_->id_to_entry_.begin();
102 iter != wrench_menu_->id_to_entry_.end(); ++iter) {
103 const WrenchMenu::Entry& entry = iter->second;
104 if (entry.first != model_)
105 continue;
106 int index = MenuItemIdToModelIndex(iter->first);
107 if (entry.second != index)
108 iter->second.second = index;
109 }
110 */
111
112 // In case recent tabs submenu was open when items were changing, force a
113 // ChildrenChanged().
114 menu_item_->ChildrenChanged();
115 }
116
117 int RecentTabsMenuModelDelegate::ModelIndexToMenuItemId(int model_index) const {
118 int id = first_command_id_ +
119 model_->ModelIndexToIdInParentMenu(model_index);
120 DCHECK(id >= first_command_id_ && id < max_command_id_);
121 return id;
122 }
123
124 int RecentTabsMenuModelDelegate::MenuItemIdToModelIndex(
125 int menu_item_id) const {
126 return model_->IdInParentMenuToModelIndex(
127 menu_item_id - first_command_id_);
128 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/recent_tabs_menu_model_delegate.h ('k') | chrome/browser/ui/views/wrench_menu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698