Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/action_box_menu.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" | |
| 8 #include "chrome/browser/ui/views/browser_action_view.h" | |
| 9 #include "grit/generated_resources.h" | |
| 10 #include "grit/theme_resources.h" | |
| 11 #include "ui/base/l10n/l10n_util.h" | |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 13 #include "ui/views/bubble/bubble_border.h" | |
| 14 #include "ui/views/controls/button/menu_button.h" | |
| 15 #include "ui/views/controls/menu/menu_runner.h" | |
| 16 #include "ui/views/view.h" | |
| 17 | |
| 18 #if defined(OS_WIN) | |
| 19 // Included for MENU_POPUPITEM and a few other Windows specific constants. | |
| 20 #include <vssym32.h> | |
| 21 #include "ui/base/native_theme/native_theme_win.h" | |
| 22 #endif | |
| 23 | |
| 24 //////////////////////////////////////////////////////////////////////////////// | |
| 25 // ActionBoxMenu | |
| 26 | |
| 27 ActionBoxMenu::ActionBoxMenu(Browser* browser, | |
| 28 ActionBoxMenuModel* model, | |
| 29 bool starred) | |
| 30 : browser_(browser), | |
| 31 root_(NULL), | |
| 32 model_(model), | |
| 33 starred_(starred) { | |
| 34 } | |
| 35 | |
| 36 ActionBoxMenu::~ActionBoxMenu() { | |
| 37 } | |
| 38 | |
| 39 void ActionBoxMenu::Init() { | |
| 40 DCHECK(!root_); | |
| 41 root_ = new views::MenuItemView(this); | |
| 42 root_->set_has_icons(true); | |
| 43 PopulateMenu(); | |
| 44 menu_runner_.reset(new views::MenuRunner(root_)); | |
|
Peter Kasting
2012/08/03 23:17:42
Do this in RunMenu() rather than here; this is com
yefimt
2012/08/07 00:47:06
Done.
| |
| 45 } | |
| 46 | |
| 47 void ActionBoxMenu::RunMenu(views::MenuButton* menu_button) { | |
| 48 gfx::Point screen_location; | |
| 49 views::View::ConvertPointToScreen(menu_button, &screen_location); | |
| 50 // Ignore the result since we don't need to handle a deleted menu specially. | |
| 51 ignore_result( | |
| 52 menu_runner_->RunMenuAt(menu_button->GetWidget(), | |
| 53 menu_button, | |
| 54 gfx::Rect(screen_location, menu_button->size()), | |
| 55 views::MenuItemView::TOPRIGHT, | |
| 56 views::MenuRunner::HAS_MNEMONICS)); | |
| 57 } | |
| 58 | |
| 59 void ActionBoxMenu::ExecuteCommand(int id) { | |
| 60 }; | |
| 61 | |
| 62 views::Border* ActionBoxMenu::CreateMenuBorder() { | |
| 63 // TODO(yefim): Use correct theme color on non-Windows. | |
| 64 SkColor border_color = SK_ColorBLACK; | |
| 65 #if defined(OS_WIN) | |
| 66 // TODO(yefim): Move to Windows only files if possible. | |
| 67 border_color = ui::NativeThemeWin::instance()->GetThemeColorWithDefault( | |
| 68 ui::NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR, | |
| 69 COLOR_MENUTEXT); | |
| 70 #endif | |
| 71 return views::Border::CreateSolidBorder(1, border_color); | |
| 72 } | |
| 73 | |
| 74 views::Background* ActionBoxMenu::CreateMenuBackground() { | |
| 75 // TODO(yefim): Use correct theme color on non-Windows. | |
| 76 SkColor background_color = SK_ColorWHITE; | |
| 77 #if defined(OS_WIN) | |
| 78 // TODO(yefim): Move to Windows only files if possible. | |
| 79 background_color = ui::NativeThemeWin::instance()->GetThemeColorWithDefault( | |
| 80 ui::NativeThemeWin::TEXTFIELD, EP_BACKGROUND, EBS_NORMAL, | |
| 81 TMT_BACKGROUND, COLOR_WINDOW); | |
| 82 #endif | |
| 83 return views::Background::CreateSolidBackground(background_color); | |
| 84 } | |
| 85 | |
| 86 int ActionBoxMenu::GetCurrentTabId() const { | |
| 87 return 0; | |
| 88 } | |
| 89 | |
| 90 void ActionBoxMenu::OnBrowserActionExecuted(BrowserActionButton* button) { | |
| 91 } | |
| 92 | |
| 93 void ActionBoxMenu::OnBrowserActionVisibilityChanged() { | |
| 94 } | |
| 95 | |
| 96 gfx::Point ActionBoxMenu::GetViewContentOffset() const { | |
| 97 return gfx::Point(0, 0); | |
| 98 } | |
| 99 | |
| 100 bool ActionBoxMenu::NeedToShowMultipleIconStates() const { | |
| 101 return false; | |
| 102 } | |
| 103 | |
| 104 bool ActionBoxMenu::NeedToShowTooltip() const { | |
| 105 return false; | |
| 106 } | |
| 107 | |
| 108 void ActionBoxMenu::WriteDragDataForView(views::View* sender, | |
| 109 const gfx::Point& press_pt, | |
| 110 ui::OSExchangeData* data) { | |
| 111 } | |
| 112 | |
| 113 int ActionBoxMenu::GetDragOperationsForView(views::View* sender, | |
| 114 const gfx::Point& p) { | |
| 115 return 0; | |
| 116 } | |
| 117 | |
| 118 bool ActionBoxMenu::CanStartDragForView(views::View* sender, | |
| 119 const gfx::Point& press_pt, | |
| 120 const gfx::Point& p) { | |
| 121 return false; | |
| 122 } | |
| 123 | |
| 124 void ActionBoxMenu::Observe(int type, | |
| 125 const content::NotificationSource& source, | |
| 126 const content::NotificationDetails& details) { | |
| 127 } | |
| 128 | |
| 129 void ActionBoxMenu::PopulateMenu() { | |
| 130 int item_id = 1; | |
| 131 AddBookmarkMenuItem(root_, &item_id); | |
| 132 if (model_->GetItemCount() > 0) | |
| 133 root_->AppendSeparator(); | |
| 134 | |
| 135 for (int model_index = 0; model_index < model_->GetItemCount(); | |
| 136 ++model_index) { | |
| 137 DCHECK(model_->GetTypeAt(model_index) == ui::MenuModel::TYPE_COMMAND); | |
| 138 views::MenuItemView* menu_item = root_->AppendMenuItemFromModel( | |
| 139 model_, model_index, item_id + model_index); | |
| 140 menu_item->SetMargins(0, 0); | |
| 141 const extensions::Extension* extension = | |
|
Peter Kasting
2012/08/03 23:17:42
Nit: If the extension toolbar model provides an ac
yefimt
2012/08/07 00:47:06
Would it be logical to get |menu_items| from |mode
Peter Kasting
2012/08/07 01:06:49
As you've done in patch set 20? I don't think it
| |
| 142 model_->GetActionBoxExtensionByIndex(model_index); | |
| 143 BrowserActionView* view = new BrowserActionView(extension, | |
| 144 browser_, this); | |
| 145 browser_action_views_.push_back(view); | |
| 146 menu_item->SetIconView(view); | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 views::MenuItemView* ActionBoxMenu::AddBookmarkMenuItem( | |
| 151 views::MenuItemView* parent, | |
| 152 int* item_id) { | |
| 153 string16 label = l10n_util::GetStringUTF16(starred_ ? | |
| 154 IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); | |
| 155 gfx::ImageSkia* icon = | |
| 156 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 157 starred_ ? IDR_STAR_LIT : IDR_STAR); | |
| 158 views::MenuItemView* item = | |
| 159 parent->AppendMenuItemWithIcon(*item_id, label, *icon); | |
| 160 (*item_id)++; | |
| 161 return item; | |
| 162 } | |
| OLD | NEW |