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

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

Issue 2813703003: Use NativeTheme to draw vertical menu separators. (Closed)
Patch Set: use rectf 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 =
170 bounds.Inset(gfx::Insets(0, 1, 0, 0)); 168 gfx::Rect(0, 0, MenuConfig::instance().separator_thickness, h);
169 params.menu_separator.paint_rect = &separator_bounds;
170 params.menu_separator.type = ui::VERTICAL_SEPARATOR;
171 view->GetNativeTheme()->Paint(
172 canvas->sk_canvas(), ui::NativeTheme::kMenuPopupSeparator,
173 ui::NativeTheme::kNormal, separator_bounds, params);
174 bounds.Inset(
175 gfx::Insets(0, MenuConfig::instance().separator_thickness, 0, 0));
171 } 176 }
172 177
173 // Fill in background for state. 178 // Fill in background for state.
174 bounds.set_x(view->GetMirroredXForRect(bounds)); 179 bounds.set_x(view->GetMirroredXForRect(bounds));
180 views::Button::ButtonState state =
181 button ? button->state() : views::Button::STATE_NORMAL;
175 DrawBackground(canvas, view, bounds, state); 182 DrawBackground(canvas, view, bounds, state);
176 } 183 }
177 184
178 private: 185 private:
179 static SkColor BorderColor(View* view, views::Button::ButtonState state) {
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, 186 static SkColor BackgroundColor(const View* view,
195 views::Button::ButtonState state) { 187 views::Button::ButtonState state) {
196 const ui::NativeTheme* theme = view->GetNativeTheme(); 188 const ui::NativeTheme* theme = view->GetNativeTheme();
197 switch (state) { 189 switch (state) {
198 case views::Button::STATE_PRESSED: 190 case views::Button::STATE_PRESSED:
199 return theme->GetSystemColor( 191 return theme->GetSystemColor(
200 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); 192 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
201 case views::Button::STATE_HOVERED: 193 case views::Button::STATE_HOVERED:
202 // Hovered should be handled in DrawBackground. 194 // Hovered should be handled in DrawBackground.
203 NOTREACHED(); 195 NOTREACHED();
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 0, 1228 0,
1237 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1229 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1238 BOOKMARK_LAUNCH_LOCATION_APP_MENU); 1230 BOOKMARK_LAUNCH_LOCATION_APP_MENU);
1239 } 1231 }
1240 1232
1241 int AppMenu::ModelIndexFromCommandId(int command_id) const { 1233 int AppMenu::ModelIndexFromCommandId(int command_id) const {
1242 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1234 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1243 DCHECK(ix != command_id_to_entry_.end()); 1235 DCHECK(ix != command_id_to_entry_.end());
1244 return ix->second.second; 1236 return ix->second.second;
1245 } 1237 }
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