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 } |
| 45 |
| 46 void ActionBoxMenu::RunMenu(views::MenuButton* menu_button) { |
| 47 gfx::Point screen_location; |
| 48 views::View::ConvertPointToScreen(menu_button, &screen_location); |
| 49 menu_runner_.reset(new views::MenuRunner(root_)); |
| 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 const extensions::ExtensionList& action_box_items = |
| 136 model_->action_box_menu_items(); |
| 137 for (size_t model_index = 0; model_index < action_box_items.size(); |
| 138 ++model_index) { |
| 139 DCHECK(model_->GetTypeAt(model_index) == ui::MenuModel::TYPE_COMMAND); |
| 140 views::MenuItemView* menu_item = root_->AppendMenuItemFromModel( |
| 141 model_, model_index, item_id + model_index); |
| 142 menu_item->SetMargins(0, 0); |
| 143 const extensions::Extension* extension = action_box_items[model_index]; |
| 144 BrowserActionView* view = new BrowserActionView(extension, |
| 145 browser_, this); |
| 146 browser_action_views_.push_back(view); |
| 147 menu_item->SetIconView(view); |
| 148 } |
| 149 } |
| 150 |
| 151 views::MenuItemView* ActionBoxMenu::AddBookmarkMenuItem( |
| 152 views::MenuItemView* parent, |
| 153 int* item_id) { |
| 154 string16 label = l10n_util::GetStringUTF16(starred_ ? |
| 155 IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR); |
| 156 gfx::ImageSkia* icon = |
| 157 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 158 starred_ ? IDR_STAR_LIT : IDR_STAR); |
| 159 views::MenuItemView* item = |
| 160 parent->AppendMenuItemWithIcon(*item_id, label, *icon); |
| 161 (*item_id)++; |
| 162 return item; |
| 163 } |
OLD | NEW |