Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/action_box_menu.h" | 5 #include "chrome/browser/ui/views/action_box_menu.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" | 7 #include "chrome/browser/ui/toolbar/action_box_menu_model.h" |
| 8 #include "chrome/browser/ui/views/browser_action_view.h" | 8 #include "chrome/browser/ui/views/browser_action_view.h" |
| 9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/views/bubble/bubble_border.h" | 13 #include "ui/views/bubble/bubble_border.h" |
| 14 #include "ui/views/controls/button/menu_button.h" | 14 #include "ui/views/controls/button/menu_button.h" |
| 15 #include "ui/views/controls/menu/menu_runner.h" | 15 #include "ui/views/controls/menu/menu_runner.h" |
| 16 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
| 17 | 17 |
| 18 #if defined(OS_WIN) && !defined(USE_AURA) | 18 #if defined(OS_WIN) && !defined(USE_AURA) |
| 19 // Included for MENU_POPUPITEM and a few other Windows specific constants. | 19 // Included for MENU_POPUPITEM and a few other Windows specific constants. |
| 20 #include <vssym32.h> | 20 #include <vssym32.h> |
| 21 #include "ui/base/native_theme/native_theme_win.h" | 21 #include "ui/base/native_theme/native_theme_win.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace { | |
| 25 // Converts from the index of a menu item to the id of this item. Indices are | |
|
msw
2012/08/23 22:04:40
nit: add a blank line above.
beaudoin
2012/08/24 19:34:38
Done.
| |
| 26 // 0-based but IDs cannot be 0. | |
| 27 inline int MenuIndexToItemId(int menu_index) { | |
| 28 return menu_index + 1; | |
| 29 } | |
| 30 | |
| 31 // Converts from the id of a menu item to its index. Indices are 0-based but | |
| 32 // IDs cannot be 0. | |
| 33 inline int MenuItemIdToIndex(int menu_item_id) { | |
| 34 return menu_item_id - 1; | |
| 35 } | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 24 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
| 25 // ActionBoxMenu | 40 // ActionBoxMenu |
| 26 | 41 |
| 27 ActionBoxMenu::ActionBoxMenu(Browser* browser, ActionBoxMenuModel* model) | 42 ActionBoxMenu::ActionBoxMenu(Browser* browser, ActionBoxMenuModel* model) |
| 28 : browser_(browser), | 43 : browser_(browser), |
| 29 root_(NULL), | 44 root_(NULL), |
| 30 model_(model) { | 45 model_(model) { |
| 31 } | 46 } |
| 32 | 47 |
| 33 ActionBoxMenu::~ActionBoxMenu() { | 48 ActionBoxMenu::~ActionBoxMenu() { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 47 // Ignore the result since we don't need to handle a deleted menu specially. | 62 // Ignore the result since we don't need to handle a deleted menu specially. |
| 48 ignore_result( | 63 ignore_result( |
| 49 menu_runner_->RunMenuAt(menu_button->GetWidget(), | 64 menu_runner_->RunMenuAt(menu_button->GetWidget(), |
| 50 menu_button, | 65 menu_button, |
| 51 gfx::Rect(screen_location, menu_button->size()), | 66 gfx::Rect(screen_location, menu_button->size()), |
| 52 views::MenuItemView::TOPRIGHT, | 67 views::MenuItemView::TOPRIGHT, |
| 53 views::MenuRunner::HAS_MNEMONICS)); | 68 views::MenuRunner::HAS_MNEMONICS)); |
| 54 } | 69 } |
| 55 | 70 |
| 56 void ActionBoxMenu::ExecuteCommand(int id) { | 71 void ActionBoxMenu::ExecuteCommand(int id) { |
| 72 model_->ActivatedAt(MenuItemIdToIndex(id)); | |
| 57 } | 73 } |
| 58 | 74 |
| 59 views::Border* ActionBoxMenu::CreateMenuBorder() { | 75 views::Border* ActionBoxMenu::CreateMenuBorder() { |
| 60 // TODO(yefim): Use correct theme color on non-Windows. | 76 // TODO(yefim): Use correct theme color on non-Windows. |
| 61 SkColor border_color = SK_ColorBLACK; | 77 SkColor border_color = SK_ColorBLACK; |
| 62 #if defined(OS_WIN) && !defined(USE_AURA) | 78 #if defined(OS_WIN) && !defined(USE_AURA) |
| 63 // TODO(yefim): Move to Windows only files if possible. | 79 // TODO(yefim): Move to Windows only files if possible. |
| 64 border_color = ui::NativeThemeWin::instance()->GetThemeColorWithDefault( | 80 border_color = ui::NativeThemeWin::instance()->GetThemeColorWithDefault( |
| 65 ui::NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR, | 81 ui::NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR, |
| 66 COLOR_MENUTEXT); | 82 COLOR_MENUTEXT); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 | 136 |
| 121 void ActionBoxMenu::Observe(int type, | 137 void ActionBoxMenu::Observe(int type, |
| 122 const content::NotificationSource& source, | 138 const content::NotificationSource& source, |
| 123 const content::NotificationDetails& details) { | 139 const content::NotificationDetails& details) { |
| 124 } | 140 } |
| 125 | 141 |
| 126 void ActionBoxMenu::PopulateMenu() { | 142 void ActionBoxMenu::PopulateMenu() { |
| 127 for (int model_index = 0; model_index < model_->GetItemCount(); | 143 for (int model_index = 0; model_index < model_->GetItemCount(); |
| 128 ++model_index) { | 144 ++model_index) { |
| 129 views::MenuItemView* menu_item = root_->AppendMenuItemFromModel( | 145 views::MenuItemView* menu_item = root_->AppendMenuItemFromModel( |
| 130 model_, model_index, model_index + 1); | 146 model_, model_index, MenuIndexToItemId(model_index)); |
| 131 if (model_->GetTypeAt(model_index) == ui::MenuModel::TYPE_COMMAND) { | 147 if (model_->GetTypeAt(model_index) == ui::MenuModel::TYPE_COMMAND) { |
| 132 menu_item->SetMargins(0, 0); | 148 menu_item->SetMargins(0, 0); |
| 133 if (model_->IsItemExtension(model_index)) { | 149 if (model_->IsItemExtension(model_index)) { |
| 134 const extensions::Extension* extension = | 150 const extensions::Extension* extension = |
| 135 model_->GetExtensionAt(model_index); | 151 model_->GetExtensionAt(model_index); |
| 136 BrowserActionView* view = new BrowserActionView(extension, | 152 BrowserActionView* view = new BrowserActionView(extension, |
| 137 browser_, this); | 153 browser_, this); |
| 138 // |menu_item| will own the |view| from now on. | 154 // |menu_item| will own the |view| from now on. |
| 139 menu_item->SetIconView(view); | 155 menu_item->SetIconView(view); |
| 140 } | 156 } |
| 141 } | 157 } |
| 142 } | 158 } |
| 143 } | 159 } |
| OLD | NEW |