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

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

Issue 2813703003: Use NativeTheme to draw vertical menu separators. (Closed)
Patch Set: . Created 3 years, 8 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
« no previous file with comments | « chrome/browser/ui/libgtkui/native_theme_gtk3.cc ('k') | ui/base/models/menu_separator_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 // A button with no drawn border and a rounded background. 148 // A button with no drawn border and a rounded background.
149 ROUNDED_BUTTON, 149 ROUNDED_BUTTON,
150 }; 150 };
151 151
152 explicit InMenuButtonBackground(ButtonType type) : type_(type) {} 152 explicit InMenuButtonBackground(ButtonType type) : type_(type) {}
153 153
154 // Overridden from views::Background. 154 // Overridden from views::Background.
155 void Paint(gfx::Canvas* canvas, View* view) const override { 155 void Paint(gfx::Canvas* canvas, View* view) const override {
156 CustomButton* button = CustomButton::AsCustomButton(view); 156 CustomButton* button = CustomButton::AsCustomButton(view);
157 views::Button::ButtonState state =
158 button ? button->state() : views::Button::STATE_NORMAL;
159 int h = view->height(); 157 int h = view->height();
160 158
161 // Draw leading border if desired. 159 // Draw leading border if desired.
162 gfx::Rect bounds(view->GetLocalBounds()); 160 gfx::Rect bounds(view->GetLocalBounds());
163 if (type_ == LEADING_BORDER) { 161 if (type_ == LEADING_BORDER) {
164 // We need to flip the canvas for RTL iff the button is not auto-flipping 162 // We need to flip the canvas for RTL iff the button is not auto-flipping
165 // already, so we end up flipping exactly once. 163 // already, so we end up flipping exactly once.
166 gfx::ScopedRTLFlipCanvas scoped_canvas( 164 gfx::ScopedRTLFlipCanvas scoped_canvas(
167 canvas, view->width(), !view->flip_canvas_on_paint_for_rtl_ui()); 165 canvas, view->width(), !view->flip_canvas_on_paint_for_rtl_ui());
168 canvas->FillRect(gfx::Rect(0, 0, 1, h), 166 ui::NativeTheme::ExtraParams params;
169 BorderColor(view, views::Button::STATE_NORMAL)); 167 gfx::Rect separator_bounds = gfx::Rect(0, 0, 1, h);
tapted 2017/04/11 02:48:06 The `1` (i.e. width) on this line should be MenuCo
Evan Stade 2017/04/11 17:53:12 Done.
168 params.menu_separator.paint_rect = &separator_bounds;
169 params.menu_separator.type = ui::VERTICAL_SEPARATOR;
170 view->GetNativeTheme()->Paint(
171 canvas->sk_canvas(), ui::NativeTheme::kMenuPopupSeparator,
172 ui::NativeTheme::kNormal, separator_bounds, params);
170 bounds.Inset(gfx::Insets(0, 1, 0, 0)); 173 bounds.Inset(gfx::Insets(0, 1, 0, 0));
tapted 2017/04/11 02:48:06 This `1` should be separator_thickness too, so tha
Evan Stade 2017/04/11 17:53:12 Ick. This is reserving space in DIP, but we may on
tapted 2017/04/12 00:31:17 Acknowledged.
171 } 174 }
172 175
173 // Fill in background for state. 176 // Fill in background for state.
174 bounds.set_x(view->GetMirroredXForRect(bounds)); 177 bounds.set_x(view->GetMirroredXForRect(bounds));
178 views::Button::ButtonState state =
179 button ? button->state() : views::Button::STATE_NORMAL;
175 DrawBackground(canvas, view, bounds, state); 180 DrawBackground(canvas, view, bounds, state);
176 } 181 }
177 182
178 private: 183 private:
179 static SkColor BorderColor(View* view, views::Button::ButtonState state) {
Evan Stade 2017/04/10 21:49:33 note that this function was only ever called with
180 ui::NativeTheme* theme = view->GetNativeTheme();
181 switch (state) {
182 case views::Button::STATE_HOVERED:
183 return theme->GetSystemColor(
184 ui::NativeTheme::kColorId_HoverMenuButtonBorderColor);
185 case views::Button::STATE_PRESSED:
186 return theme->GetSystemColor(
187 ui::NativeTheme::kColorId_FocusedMenuButtonBorderColor);
188 default:
189 return theme->GetSystemColor(
190 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor);
191 }
192 }
193
194 static SkColor BackgroundColor(const View* view, 184 static SkColor BackgroundColor(const View* view,
195 views::Button::ButtonState state) { 185 views::Button::ButtonState state) {
196 const ui::NativeTheme* theme = view->GetNativeTheme(); 186 const ui::NativeTheme* theme = view->GetNativeTheme();
197 switch (state) { 187 switch (state) {
198 case views::Button::STATE_PRESSED: 188 case views::Button::STATE_PRESSED:
199 return theme->GetSystemColor( 189 return theme->GetSystemColor(
200 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); 190 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
201 case views::Button::STATE_HOVERED: 191 case views::Button::STATE_HOVERED:
202 // Hovered should be handled in DrawBackground. 192 // Hovered should be handled in DrawBackground.
203 NOTREACHED(); 193 NOTREACHED();
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 0, 1226 0,
1237 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1227 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1238 BOOKMARK_LAUNCH_LOCATION_APP_MENU); 1228 BOOKMARK_LAUNCH_LOCATION_APP_MENU);
1239 } 1229 }
1240 1230
1241 int AppMenu::ModelIndexFromCommandId(int command_id) const { 1231 int AppMenu::ModelIndexFromCommandId(int command_id) const {
1242 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1232 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1243 DCHECK(ix != command_id_to_entry_.end()); 1233 DCHECK(ix != command_id_to_entry_.end());
1244 return ix->second.second; 1234 return ix->second.second;
1245 } 1235 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtkui/native_theme_gtk3.cc ('k') | ui/base/models/menu_separator_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698