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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/recent_tabs_menu_model_delegate.cc
diff --git a/chrome/browser/ui/views/recent_tabs_menu_model_delegate.cc b/chrome/browser/ui/views/recent_tabs_menu_model_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ad5ff1af8a8010ae8346cf5e9c3179266aa7ed91
--- /dev/null
+++ b/chrome/browser/ui/views/recent_tabs_menu_model_delegate.cc
@@ -0,0 +1,128 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/recent_tabs_menu_model_delegate.h"
+
+#include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h"
+#include "chrome/browser/ui/views/menu_items_changed_delegate.h"
+#include "ui/views/controls/menu/submenu_view.h"
+
+RecentTabsMenuModelDelegate::RecentTabsMenuModelDelegate(
+ MenuItemsChangedDelegate* items_changed_delegate,
+ RecentTabsSubMenuModel* model,
+ views::MenuItemView* menu_item,
+ int first_command_id,
+ int max_command_id)
+ : items_changed_delegate_(items_changed_delegate),
+ model_(model),
+ menu_item_(menu_item),
+ first_command_id_(first_command_id),
+ max_command_id_(max_command_id) {
+ model_->SetMenuModelDelegate(this);
+}
+
+RecentTabsMenuModelDelegate::~RecentTabsMenuModelDelegate() {
+ model_->SetMenuModelDelegate(NULL);
+}
+
+void RecentTabsMenuModelDelegate::PopulateMenu() {
+ for (int i = 0; i < model_->GetItemCount(); ++i) {
+ items_changed_delegate_->OnItemAdded(menu_item_, i, model_, i,
+ ModelIndexToMenuItemId(i));
+ }
+}
+
+int RecentTabsMenuModelDelegate::GetMaxWidthForMenu(views::MenuItemView* menu) {
+ if (!menu_item_->HasSubmenu())
+ return -1;
+ const int kMaxMenuItemWidth = 320;
+ return menu->GetCommand() == menu_item_->GetCommand() ?
+ kMaxMenuItemWidth : -1;
+}
+
+const gfx::Font* RecentTabsMenuModelDelegate::GetLabelFontAt(
+ int item_id) const {
+ int model_index = MenuItemIdToModelIndex(item_id);
+ return model_->GetLabelFontAt(model_index);
+}
+
+bool RecentTabsMenuModelDelegate::GetForegroundColor(
+ int command_id,
+ bool is_hovered,
+ SkColor* override_color) const {
+ // The items for which we get a font, should be shown in black.
+ if (GetLabelFontAt(command_id)) {
+ *override_color = SK_ColorBLACK;
+ return true;
+ }
+ return false;
+}
+
+void RecentTabsMenuModelDelegate::OnIconChanged(int index) {
+ int id = ModelIndexToMenuItemId(index);
+ views::MenuItemView* item = menu_item_->GetMenuItemByID(id);
+ DCHECK(item);
+ gfx::Image icon;
+ if (model_->GetIconAt(index, &icon))
+ item->SetIcon(*icon.ToImageSkia());
+}
+
+void RecentTabsMenuModelDelegate::PrepareForChange() {
+}
+
+void RecentTabsMenuModelDelegate::OnItemRemoved(int index) {
+ items_changed_delegate_->OnItemRemoved(menu_item_, index,
+ ModelIndexToMenuItemId(index));
+}
+
+void RecentTabsMenuModelDelegate::OnItemAdded(int index) {
+ // Add menu item at |index|.
+ items_changed_delegate_->OnItemAdded(menu_item_, index, model_, index,
+ ModelIndexToMenuItemId(index));
+}
+
+void RecentTabsMenuModelDelegate::ChangesDone() {
+views::SubmenuView* submenu = menu_item_->GetSubmenu();
+for (int i = 0; i < submenu->GetMenuItemCount(); ++i) {
+views::MenuItemView* item = submenu->GetMenuItemAt(i);
+LOG(ERROR) << "kk done: " << i << ": cmd=" << item->GetCommand() << ", " << item->title();
+}
+ std::vector<int> item_ids;
+ for (int i = 0; i < model_->GetItemCount(); ++i)
+ item_ids.push_back(ModelIndexToMenuItemId(i));
+ items_changed_delegate_->UpdateMapOfMenuItemIdAndModel(model_, item_ids);
+
+/*
+ // If menu items were removed/added (via OnItemRemoved/OnItemAdded), the
+ // indexes of unchanged items would be affected, update them in
+ // |id_to_entry_|.
+ for (WrenchMenu::IDToEntry::iterator iter =
+ wrench_menu_->id_to_entry_.begin();
+ iter != wrench_menu_->id_to_entry_.end(); ++iter) {
+ const WrenchMenu::Entry& entry = iter->second;
+ if (entry.first != model_)
+ continue;
+ int index = MenuItemIdToModelIndex(iter->first);
+ if (entry.second != index)
+ iter->second.second = index;
+ }
+*/
+
+ // In case recent tabs submenu was open when items were changing, force a
+ // ChildrenChanged().
+ menu_item_->ChildrenChanged();
+}
+
+int RecentTabsMenuModelDelegate::ModelIndexToMenuItemId(int model_index) const {
+ int id = first_command_id_ +
+ model_->ModelIndexToIdInParentMenu(model_index);
+ DCHECK(id >= first_command_id_ && id < max_command_id_);
+ return id;
+}
+
+int RecentTabsMenuModelDelegate::MenuItemIdToModelIndex(
+ int menu_item_id) const {
+ return model_->IdInParentMenuToModelIndex(
+ menu_item_id - first_command_id_);
+}
« 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