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

Unified Diff: chrome/browser/ui/views/action_box_menu.cc

Issue 10533086: Action box menu (Closed) Base URL: svn://svn.chromium.org/chrome/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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/action_box_menu.cc
diff --git a/chrome/browser/ui/views/action_box_menu.cc b/chrome/browser/ui/views/action_box_menu.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eb340a52978212ce00d78e4895f1016d91f2bfae
--- /dev/null
+++ b/chrome/browser/ui/views/action_box_menu.cc
@@ -0,0 +1,138 @@
+// 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/action_box_menu.h"
+
+#include "chrome/browser/ui/toolbar/action_box_menu_model.h"
+#include "chrome/browser/ui/views/action_box_menu_item_view.h"
+#include "chrome/browser/ui/views/browser_action_view.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "grit/theme_resources_standard.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/views/controls/button/menu_button.h"
+#include "ui/views/controls/menu/menu_runner.h"
+#include "ui/views/view.h"
+
+using ui::MenuModel;
+using views::MenuItemView;
+using views::View;
+
+// ActionBoxMenu ---------------------------------------------------------------
+
+ActionBoxMenu::ActionBoxMenu(Browser* browser,
+ ActionBoxMenuModel* model,
+ bool bookmark_item_state)
+ : browser_(browser),
+ root_(NULL),
+ model_(model),
+ bookmark_item_state_(bookmark_item_state),
+ model_index_offset_(0) {
+ // registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
+ // content::Source<Profile>(browser_->profile()));
+}
+
+ActionBoxMenu::~ActionBoxMenu() {
+}
+
+void ActionBoxMenu::Init() {
+ DCHECK(!root_);
+ root_ = new ActionBoxMenuItemView(this);
+ root_->set_has_icons(true); // We have checks, radios and icons, set this
+ // so we get the taller menu style.
+ int id = 1;
Aaron Boodman 2012/06/12 05:53:44 This is never used for anything...? Seems like it
yefimt 2012/06/13 01:24:21 Done Original idea was that it could be called rec
+ PopulateMenu(root_, model_, &id);
+ menu_runner_.reset(new views::MenuRunner(root_));
+}
+
+void ActionBoxMenu::RunMenu(views::MenuButton* host) {
+ gfx::Point screen_loc;
+ views::View::ConvertPointToScreen(host, &screen_loc);
+ gfx::Rect bounds(screen_loc, host->size());
+ if (menu_runner_->RunMenuAt(host->GetWidget(), host, bounds,
+ MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) ==
+ views::MenuRunner::MENU_DELETED) {
+ return;
+ }
+}
+
+Browser* ActionBoxMenu::GetBrowser() const {
+ return browser_;
+}
+
+int ActionBoxMenu::GetCurrentTabId() const {
+ return 0;
+}
+
+void ActionBoxMenu::OnBrowserActionExecuted(BrowserActionButton* button) {
+}
+
+void ActionBoxMenu::OnBrowserActionVisibilityChanged() {
+}
+
+gfx::Size ActionBoxMenu::GetContentOffset() const {
+ return gfx::Size(0, 0);
+}
+
+void ActionBoxMenu::WriteDragDataForView(View* sender,
+ const gfx::Point& press_pt,
+ ui::OSExchangeData* data) {
+}
+
+int ActionBoxMenu::GetDragOperationsForView(View* sender,
+ const gfx::Point& p) {
+ return 0;
+}
+
+bool ActionBoxMenu::CanStartDragForView(View* sender,
+ const gfx::Point& press_pt,
+ const gfx::Point& p) {
+ return false;
+}
+
+void ActionBoxMenu::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+}
+
+void ActionBoxMenu::PopulateMenu(MenuItemView* parent,
+ ActionBoxMenuModel* model,
+ int* id) {
+ int menu_index = 0;
+ AddBookmarkMenuItem(parent, &menu_index, id);
+ parent->AppendSeparator();
+ menu_index++;
+ model_index_offset_ = menu_index;
+
+ for (int model_index = 0; model_index < model->GetItemCount();
+ ++model_index) {
+ MenuItemView* menu_item = parent->AppendMenuItemFromModel(model,
+ model_index, *id);
+ if (model->GetTypeAt(model_index) == MenuModel::TYPE_COMMAND) {
+ const extensions::Extension* extension =
+ model->GetActionBoxExtensionByIndex(model_index);
+ BrowserActionView* view = new BrowserActionView(extension, this);
+ browser_action_views_.push_back(view);
+ menu_item->AddChildView(view);
+ }
+ (*id)++;
+ }
+}
+
+MenuItemView* ActionBoxMenu::AddBookmarkMenuItem(MenuItemView* parent,
+ int* index, int* id) {
+ string16 label =
+ l10n_util::GetStringUTF16(bookmark_item_state_ ? IDS_TOOLTIP_STARRED :
+ IDS_TOOLTIP_STAR);
+ gfx::ImageSkia* icon =
+ ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ bookmark_item_state_ ? IDR_STAR_LIT : IDR_STAR);
+ DCHECK(icon);
+ MenuItemView* item = parent->AddMenuItemAt(*index, *id, label, *icon,
+ MenuItemView::NORMAL);
+ (*id)++;
+ (*index)++;
+ return item;
+}

Powered by Google App Engine
This is Rietveld 408576698