Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/app_menu.h" | 5 #include "chrome/browser/ui/views/toolbar/app_menu.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
| 40 #include "content/public/browser/notification_types.h" | 40 #include "content/public/browser/notification_types.h" |
| 41 #include "content/public/browser/user_metrics.h" | 41 #include "content/public/browser/user_metrics.h" |
| 42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 43 #include "extensions/common/feature_switch.h" | 43 #include "extensions/common/feature_switch.h" |
| 44 #include "grit/theme_resources.h" | 44 #include "grit/theme_resources.h" |
| 45 #include "third_party/skia/include/core/SkCanvas.h" | 45 #include "third_party/skia/include/core/SkCanvas.h" |
| 46 #include "third_party/skia/include/core/SkPaint.h" | 46 #include "third_party/skia/include/core/SkPaint.h" |
| 47 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 48 #include "ui/base/layout.h" | 48 #include "ui/base/layout.h" |
| 49 #include "ui/base/material_design/material_design_controller.h" | |
| 49 #include "ui/base/resource/resource_bundle.h" | 50 #include "ui/base/resource/resource_bundle.h" |
| 50 #include "ui/gfx/canvas.h" | 51 #include "ui/gfx/canvas.h" |
| 51 #include "ui/gfx/font_list.h" | 52 #include "ui/gfx/font_list.h" |
| 52 #include "ui/gfx/image/image.h" | 53 #include "ui/gfx/image/image.h" |
| 53 #include "ui/gfx/image/image_skia_source.h" | 54 #include "ui/gfx/image/image_skia_source.h" |
| 54 #include "ui/gfx/skia_util.h" | 55 #include "ui/gfx/skia_util.h" |
| 55 #include "ui/gfx/text_utils.h" | 56 #include "ui/gfx/text_utils.h" |
| 56 #include "ui/views/background.h" | 57 #include "ui/views/background.h" |
| 57 #include "ui/views/controls/button/image_button.h" | 58 #include "ui/views/controls/button/image_button.h" |
| 58 #include "ui/views/controls/button/label_button.h" | 59 #include "ui/views/controls/button/label_button.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 124 |
| 124 private: | 125 private: |
| 125 DISALLOW_COPY_AND_ASSIGN(FullscreenButton); | 126 DISALLOW_COPY_AND_ASSIGN(FullscreenButton); |
| 126 }; | 127 }; |
| 127 | 128 |
| 128 // Combination border/background for the buttons contained in the menu. The | 129 // Combination border/background for the buttons contained in the menu. The |
| 129 // painting of the border/background is done here as LabelButton does not always | 130 // painting of the border/background is done here as LabelButton does not always |
| 130 // paint the border. | 131 // paint the border. |
| 131 class InMenuButtonBackground : public views::Background { | 132 class InMenuButtonBackground : public views::Background { |
| 132 public: | 133 public: |
| 134 const int kBackgroundCornerRadius = 2; | |
|
Peter Kasting
2016/02/16 21:36:15
This does not need to be class-scope; it can be fu
varkha
2016/02/17 17:52:00
Done.
| |
| 135 | |
| 133 enum ButtonType { | 136 enum ButtonType { |
| 134 LEFT_BUTTON, | 137 LEFT_BUTTON, |
| 135 CENTER_BUTTON, | 138 CENTER_BUTTON, |
| 136 RIGHT_BUTTON, | 139 RIGHT_BUTTON, |
| 137 SINGLE_BUTTON, | 140 SINGLE_BUTTON, |
| 138 }; | 141 }; |
| 139 | 142 |
| 140 explicit InMenuButtonBackground(ButtonType type) | 143 explicit InMenuButtonBackground(ButtonType type) |
| 141 : type_(type), left_button_(NULL), right_button_(NULL) {} | 144 : type_(type), left_button_(NULL), right_button_(NULL) {} |
| 142 | 145 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 156 // Overridden from views::Background. | 159 // Overridden from views::Background. |
| 157 void Paint(gfx::Canvas* canvas, View* view) const override { | 160 void Paint(gfx::Canvas* canvas, View* view) const override { |
| 158 CustomButton* button = CustomButton::AsCustomButton(view); | 161 CustomButton* button = CustomButton::AsCustomButton(view); |
| 159 views::Button::ButtonState state = | 162 views::Button::ButtonState state = |
| 160 button ? button->state() : views::Button::STATE_NORMAL; | 163 button ? button->state() : views::Button::STATE_NORMAL; |
| 161 int h = view->height(); | 164 int h = view->height(); |
| 162 | 165 |
| 163 // Normal buttons get a border drawn on the right side and the rest gets | 166 // Normal buttons get a border drawn on the right side and the rest gets |
| 164 // filled in. The left button however does not get a line to combine | 167 // filled in. The left button however does not get a line to combine |
| 165 // buttons. | 168 // buttons. |
| 169 gfx::Rect bounds(view->GetLocalBounds()); | |
| 166 if (type_ != RIGHT_BUTTON) { | 170 if (type_ != RIGHT_BUTTON) { |
| 167 canvas->FillRect(gfx::Rect(0, 0, 1, h), | 171 canvas->FillRect(gfx::Rect(0, 0, 1, h), |
| 168 BorderColor(view, views::Button::STATE_NORMAL)); | 172 BorderColor(view, views::Button::STATE_NORMAL)); |
| 173 bounds.Inset(gfx::Insets(0, 1, 0, 0)); | |
| 169 } | 174 } |
| 170 | 175 |
| 171 gfx::Rect bounds(view->GetLocalBounds()); | |
| 172 bounds.set_x(view->GetMirroredXForRect(bounds)); | 176 bounds.set_x(view->GetMirroredXForRect(bounds)); |
| 173 DrawBackground(canvas, view, bounds, state); | 177 DrawBackground(canvas, view, bounds, state); |
| 174 } | 178 } |
| 175 | 179 |
| 176 private: | 180 private: |
| 177 static SkColor BorderColor(View* view, views::Button::ButtonState state) { | 181 static SkColor BorderColor(View* view, views::Button::ButtonState state) { |
| 178 ui::NativeTheme* theme = view->GetNativeTheme(); | 182 ui::NativeTheme* theme = view->GetNativeTheme(); |
| 179 switch (state) { | 183 switch (state) { |
| 180 case views::Button::STATE_HOVERED: | 184 case views::Button::STATE_HOVERED: |
| 181 return theme->GetSystemColor( | 185 return theme->GetSystemColor( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 206 ui::NativeTheme::kColorId_MenuBackgroundColor); | 210 ui::NativeTheme::kColorId_MenuBackgroundColor); |
| 207 } | 211 } |
| 208 } | 212 } |
| 209 | 213 |
| 210 void DrawBackground(gfx::Canvas* canvas, | 214 void DrawBackground(gfx::Canvas* canvas, |
| 211 const views::View* view, | 215 const views::View* view, |
| 212 const gfx::Rect& bounds, | 216 const gfx::Rect& bounds, |
| 213 views::Button::ButtonState state) const { | 217 views::Button::ButtonState state) const { |
| 214 if (state == views::Button::STATE_HOVERED || | 218 if (state == views::Button::STATE_HOVERED || |
| 215 state == views::Button::STATE_PRESSED) { | 219 state == views::Button::STATE_PRESSED) { |
| 220 ui::NativeTheme::ExtraParams params = ui::NativeTheme::ExtraParams(); | |
| 221 if (ui::MaterialDesignController::IsModeMaterial() && | |
| 222 view->GetClassName() == views::MenuButton::kViewClassName) { | |
| 223 params.menu_item.corner_radius = kBackgroundCornerRadius; | |
| 224 } | |
| 216 view->GetNativeTheme()->Paint(canvas->sk_canvas(), | 225 view->GetNativeTheme()->Paint(canvas->sk_canvas(), |
| 217 ui::NativeTheme::kMenuItemBackground, | 226 ui::NativeTheme::kMenuItemBackground, |
| 218 ui::NativeTheme::kHovered, | 227 ui::NativeTheme::kHovered, bounds, params); |
| 219 bounds, | |
| 220 ui::NativeTheme::ExtraParams()); | |
| 221 } | 228 } |
| 222 } | 229 } |
| 223 | 230 |
| 224 ButtonType TypeAdjustedForRTL() const { | 231 ButtonType TypeAdjustedForRTL() const { |
| 225 if (!base::i18n::IsRTL()) | 232 if (!base::i18n::IsRTL()) |
| 226 return type_; | 233 return type_; |
| 227 | 234 |
| 228 switch (type_) { | 235 switch (type_) { |
| 229 case LEFT_BUTTON: return RIGHT_BUTTON; | 236 case LEFT_BUTTON: return RIGHT_BUTTON; |
| 230 case RIGHT_BUTTON: return LEFT_BUTTON; | 237 case RIGHT_BUTTON: return LEFT_BUTTON; |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1128 #endif | 1135 #endif |
| 1129 | 1136 |
| 1130 item->SetMargins(top_margin, bottom_margin); | 1137 item->SetMargins(top_margin, bottom_margin); |
| 1131 } | 1138 } |
| 1132 | 1139 |
| 1133 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) | 1140 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) |
| 1134 PopulateMenu(item, model->GetSubmenuModelAt(i)); | 1141 PopulateMenu(item, model->GetSubmenuModelAt(i)); |
| 1135 | 1142 |
| 1136 switch (model->GetCommandIdAt(i)) { | 1143 switch (model->GetCommandIdAt(i)) { |
| 1137 case IDC_EXTENSIONS_OVERFLOW_MENU: { | 1144 case IDC_EXTENSIONS_OVERFLOW_MENU: { |
| 1145 extension_toolbar_ = nullptr; | |
|
Peter Kasting
2016/02/16 21:36:15
Nit: I would probably put this inside the ShouldSh
varkha
2016/02/17 17:52:00
Done.
| |
| 1138 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar( | 1146 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar( |
| 1139 new ExtensionToolbarMenuView(browser_, this)); | 1147 new ExtensionToolbarMenuView(browser_, this)); |
| 1148 if (!extension_toolbar->ShouldShow()) { | |
| 1149 item->SetVisible(false); | |
| 1150 break; | |
| 1151 } | |
| 1152 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 1153 for (int i = 0; i < extension_toolbar->contents()->child_count(); | |
| 1154 ++i) { | |
| 1155 View* action_view = extension_toolbar->contents()->child_at(i); | |
| 1156 action_view->set_background(new InMenuButtonBackground( | |
| 1157 InMenuButtonBackground::RIGHT_BUTTON)); | |
| 1158 DCHECK(action_view->IsFocusable()); | |
| 1159 } | |
| 1160 } | |
| 1140 extension_toolbar_ = extension_toolbar.get(); | 1161 extension_toolbar_ = extension_toolbar.get(); |
| 1141 if (extension_toolbar->ShouldShow()) | 1162 item->AddChildView(extension_toolbar.release()); |
| 1142 item->AddChildView(extension_toolbar.release()); | |
| 1143 else | |
| 1144 item->SetVisible(false); | |
| 1145 break; | 1163 break; |
| 1146 } | 1164 } |
| 1147 | 1165 |
| 1148 case IDC_EDIT_MENU: { | 1166 case IDC_EDIT_MENU: { |
| 1149 ui::ButtonMenuItemModel* submodel = model->GetButtonMenuItemAt(i); | 1167 ui::ButtonMenuItemModel* submodel = model->GetButtonMenuItemAt(i); |
| 1150 DCHECK_EQ(IDC_CUT, submodel->GetCommandIdAt(0)); | 1168 DCHECK_EQ(IDC_CUT, submodel->GetCommandIdAt(0)); |
| 1151 DCHECK_EQ(IDC_COPY, submodel->GetCommandIdAt(1)); | 1169 DCHECK_EQ(IDC_COPY, submodel->GetCommandIdAt(1)); |
| 1152 DCHECK_EQ(IDC_PASTE, submodel->GetCommandIdAt(2)); | 1170 DCHECK_EQ(IDC_PASTE, submodel->GetCommandIdAt(2)); |
| 1153 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); | 1171 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); |
| 1154 item->AddChildView(new CutCopyPasteView(this, submodel, 0, 1, 2)); | 1172 item->AddChildView(new CutCopyPasteView(this, submodel, 0, 1, 2)); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1266 0, | 1284 0, |
| 1267 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1285 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1268 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1286 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
| 1269 } | 1287 } |
| 1270 | 1288 |
| 1271 int AppMenu::ModelIndexFromCommandId(int command_id) const { | 1289 int AppMenu::ModelIndexFromCommandId(int command_id) const { |
| 1272 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1290 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
| 1273 DCHECK(ix != command_id_to_entry_.end()); | 1291 DCHECK(ix != command_id_to_entry_.end()); |
| 1274 return ix->second.second; | 1292 return ix->second.second; |
| 1275 } | 1293 } |
| OLD | NEW |