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

Side by Side Diff: chrome/browser/ui/views/toolbar/app_menu.cc

Issue 1661673004: Enables hot-tracking for overflow extension buttons in the app menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restores hot-tracking of extension buttons in app menu with MD (nit) Created 4 years, 10 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 unified diff | Download patch
OLDNEW
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
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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:
133 enum ButtonType { 134 enum ButtonType {
135 // A rectangular button with no neighbor on the left.
134 LEFT_BUTTON, 136 LEFT_BUTTON,
137
138 // A rectangular button with neighbors on both sides.
135 CENTER_BUTTON, 139 CENTER_BUTTON,
140
141 // A rectangular button with no neighbor on the right.
136 RIGHT_BUTTON, 142 RIGHT_BUTTON,
143
144 // A rectangular button that is not a member in a group.
137 SINGLE_BUTTON, 145 SINGLE_BUTTON,
146
147 // A button with no group neighbors and a rounded background.
148 ROUNDED_BUTTON,
138 }; 149 };
139 150
140 explicit InMenuButtonBackground(ButtonType type) 151 explicit InMenuButtonBackground(ButtonType type)
141 : type_(type), left_button_(NULL), right_button_(NULL) {} 152 : type_(type), left_button_(NULL), right_button_(NULL) {}
142 153
143 // Used when the type is CENTER_BUTTON to determine if the left/right edge 154 // Used when the type is CENTER_BUTTON to determine if the left/right edge
144 // needs to be rendered selected. 155 // needs to be rendered selected.
145 void SetOtherButtons(const CustomButton* left_button, 156 void SetOtherButtons(const CustomButton* left_button,
146 const CustomButton* right_button) { 157 const CustomButton* right_button) {
147 if (base::i18n::IsRTL()) { 158 if (base::i18n::IsRTL()) {
148 left_button_ = right_button; 159 left_button_ = right_button;
149 right_button_ = left_button; 160 right_button_ = left_button;
150 } else { 161 } else {
151 left_button_ = left_button; 162 left_button_ = left_button;
152 right_button_ = right_button; 163 right_button_ = right_button;
153 } 164 }
154 } 165 }
155 166
156 // Overridden from views::Background. 167 // Overridden from views::Background.
157 void Paint(gfx::Canvas* canvas, View* view) const override { 168 void Paint(gfx::Canvas* canvas, View* view) const override {
158 CustomButton* button = CustomButton::AsCustomButton(view); 169 CustomButton* button = CustomButton::AsCustomButton(view);
159 views::Button::ButtonState state = 170 views::Button::ButtonState state =
160 button ? button->state() : views::Button::STATE_NORMAL; 171 button ? button->state() : views::Button::STATE_NORMAL;
161 int h = view->height(); 172 int h = view->height();
162 173
163 // Normal buttons get a border drawn on the right side and the rest gets 174 // 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 175 // filled in. The left or rounded buttons however do not get a line to
165 // buttons. 176 // combine buttons.
166 if (type_ != RIGHT_BUTTON) { 177 gfx::Rect bounds(view->GetLocalBounds());
178 if (type_ != RIGHT_BUTTON && type_ != ROUNDED_BUTTON) {
167 canvas->FillRect(gfx::Rect(0, 0, 1, h), 179 canvas->FillRect(gfx::Rect(0, 0, 1, h),
168 BorderColor(view, views::Button::STATE_NORMAL)); 180 BorderColor(view, views::Button::STATE_NORMAL));
181 bounds.Inset(gfx::Insets(0, 1, 0, 0));
169 } 182 }
170 183
171 gfx::Rect bounds(view->GetLocalBounds());
172 bounds.set_x(view->GetMirroredXForRect(bounds)); 184 bounds.set_x(view->GetMirroredXForRect(bounds));
173 DrawBackground(canvas, view, bounds, state); 185 DrawBackground(canvas, view, bounds, state);
174 } 186 }
175 187
176 private: 188 private:
177 static SkColor BorderColor(View* view, views::Button::ButtonState state) { 189 static SkColor BorderColor(View* view, views::Button::ButtonState state) {
178 ui::NativeTheme* theme = view->GetNativeTheme(); 190 ui::NativeTheme* theme = view->GetNativeTheme();
179 switch (state) { 191 switch (state) {
180 case views::Button::STATE_HOVERED: 192 case views::Button::STATE_HOVERED:
181 return theme->GetSystemColor( 193 return theme->GetSystemColor(
(...skipping 24 matching lines...) Expand all
206 ui::NativeTheme::kColorId_MenuBackgroundColor); 218 ui::NativeTheme::kColorId_MenuBackgroundColor);
207 } 219 }
208 } 220 }
209 221
210 void DrawBackground(gfx::Canvas* canvas, 222 void DrawBackground(gfx::Canvas* canvas,
211 const views::View* view, 223 const views::View* view,
212 const gfx::Rect& bounds, 224 const gfx::Rect& bounds,
213 views::Button::ButtonState state) const { 225 views::Button::ButtonState state) const {
214 if (state == views::Button::STATE_HOVERED || 226 if (state == views::Button::STATE_HOVERED ||
215 state == views::Button::STATE_PRESSED) { 227 state == views::Button::STATE_PRESSED) {
228 ui::NativeTheme::ExtraParams params;
229 if (type_ == ROUNDED_BUTTON) {
230 // Consistent with a hover corner radius (kInkDropSmallCornerRadius).
231 const int kBackgroundCornerRadius = 2;
232 params.menu_item.corner_radius = kBackgroundCornerRadius;
233 }
216 view->GetNativeTheme()->Paint(canvas->sk_canvas(), 234 view->GetNativeTheme()->Paint(canvas->sk_canvas(),
217 ui::NativeTheme::kMenuItemBackground, 235 ui::NativeTheme::kMenuItemBackground,
218 ui::NativeTheme::kHovered, 236 ui::NativeTheme::kHovered, bounds, params);
219 bounds,
220 ui::NativeTheme::ExtraParams());
221 } 237 }
222 } 238 }
223 239
224 ButtonType TypeAdjustedForRTL() const { 240 ButtonType TypeAdjustedForRTL() const {
225 if (!base::i18n::IsRTL()) 241 if (!base::i18n::IsRTL())
226 return type_; 242 return type_;
227 243
228 switch (type_) { 244 switch (type_) {
229 case LEFT_BUTTON: return RIGHT_BUTTON; 245 case LEFT_BUTTON: return RIGHT_BUTTON;
230 case RIGHT_BUTTON: return LEFT_BUTTON; 246 case RIGHT_BUTTON: return LEFT_BUTTON;
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 item->SetMargins(top_margin, bottom_margin); 1146 item->SetMargins(top_margin, bottom_margin);
1131 } 1147 }
1132 1148
1133 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) 1149 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU)
1134 PopulateMenu(item, model->GetSubmenuModelAt(i)); 1150 PopulateMenu(item, model->GetSubmenuModelAt(i));
1135 1151
1136 switch (model->GetCommandIdAt(i)) { 1152 switch (model->GetCommandIdAt(i)) {
1137 case IDC_EXTENSIONS_OVERFLOW_MENU: { 1153 case IDC_EXTENSIONS_OVERFLOW_MENU: {
1138 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar( 1154 scoped_ptr<ExtensionToolbarMenuView> extension_toolbar(
1139 new ExtensionToolbarMenuView(browser_, this)); 1155 new ExtensionToolbarMenuView(browser_, this));
1156 if (!extension_toolbar->ShouldShow()) {
1157 item->SetVisible(false);
1158 extension_toolbar_ = nullptr;
1159 break;
1160 }
1161 if (ui::MaterialDesignController::IsModeMaterial()) {
1162 for (int i = 0; i < extension_toolbar->contents()->child_count();
1163 ++i) {
1164 View* action_view = extension_toolbar->contents()->child_at(i);
1165 action_view->set_background(new InMenuButtonBackground(
1166 InMenuButtonBackground::ROUNDED_BUTTON));
1167 }
1168 }
1140 extension_toolbar_ = extension_toolbar.get(); 1169 extension_toolbar_ = extension_toolbar.get();
1141 if (extension_toolbar->ShouldShow()) 1170 item->AddChildView(extension_toolbar.release());
1142 item->AddChildView(extension_toolbar.release());
1143 else
1144 item->SetVisible(false);
1145 break; 1171 break;
1146 } 1172 }
1147 1173
1148 case IDC_EDIT_MENU: { 1174 case IDC_EDIT_MENU: {
1149 ui::ButtonMenuItemModel* submodel = model->GetButtonMenuItemAt(i); 1175 ui::ButtonMenuItemModel* submodel = model->GetButtonMenuItemAt(i);
1150 DCHECK_EQ(IDC_CUT, submodel->GetCommandIdAt(0)); 1176 DCHECK_EQ(IDC_CUT, submodel->GetCommandIdAt(0));
1151 DCHECK_EQ(IDC_COPY, submodel->GetCommandIdAt(1)); 1177 DCHECK_EQ(IDC_COPY, submodel->GetCommandIdAt(1));
1152 DCHECK_EQ(IDC_PASTE, submodel->GetCommandIdAt(2)); 1178 DCHECK_EQ(IDC_PASTE, submodel->GetCommandIdAt(2));
1153 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); 1179 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2));
1154 item->AddChildView(new CutCopyPasteView(this, submodel, 0, 1, 2)); 1180 item->AddChildView(new CutCopyPasteView(this, submodel, 0, 1, 2));
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 0, 1292 0,
1267 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1293 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1268 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); 1294 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU);
1269 } 1295 }
1270 1296
1271 int AppMenu::ModelIndexFromCommandId(int command_id) const { 1297 int AppMenu::ModelIndexFromCommandId(int command_id) const {
1272 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1298 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1273 DCHECK(ix != command_id_to_entry_.end()); 1299 DCHECK(ix != command_id_to_entry_.end());
1274 return ix->second.second; 1300 return ix->second.second;
1275 } 1301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698