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/wrench_menu.h" | 5 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
33 #include "grit/chromium_strings.h" | 33 #include "grit/chromium_strings.h" |
34 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
35 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
36 #include "third_party/skia/include/core/SkCanvas.h" | 36 #include "third_party/skia/include/core/SkCanvas.h" |
37 #include "third_party/skia/include/core/SkPaint.h" | 37 #include "third_party/skia/include/core/SkPaint.h" |
38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
39 #include "ui/base/layout.h" | 39 #include "ui/base/layout.h" |
40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
41 #include "ui/gfx/canvas.h" | 41 #include "ui/gfx/canvas.h" |
42 #include "ui/gfx/image/canvas_image_source.h" | |
43 #include "ui/gfx/image/image.h" | 42 #include "ui/gfx/image/image.h" |
43 #include "ui/gfx/image/image_skia_source.h" | |
44 #include "ui/gfx/skia_util.h" | 44 #include "ui/gfx/skia_util.h" |
45 #include "ui/gfx/text_utils.h" | 45 #include "ui/gfx/text_utils.h" |
46 #include "ui/views/background.h" | 46 #include "ui/views/background.h" |
47 #include "ui/views/controls/button/image_button.h" | 47 #include "ui/views/controls/button/image_button.h" |
48 #include "ui/views/controls/button/label_button.h" | 48 #include "ui/views/controls/button/label_button.h" |
49 #include "ui/views/controls/button/menu_button.h" | 49 #include "ui/views/controls/button/menu_button.h" |
50 #include "ui/views/controls/label.h" | 50 #include "ui/views/controls/label.h" |
51 #include "ui/views/controls/menu/menu_config.h" | 51 #include "ui/views/controls/menu/menu_config.h" |
52 #include "ui/views/controls/menu/menu_item_view.h" | 52 #include "ui/views/controls/menu/menu_item_view.h" |
53 #include "ui/views/controls/menu/menu_model_adapter.h" | 53 #include "ui/views/controls/menu/menu_model_adapter.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
67 using views::CustomButton; | 67 using views::CustomButton; |
68 using views::ImageButton; | 68 using views::ImageButton; |
69 using views::Label; | 69 using views::Label; |
70 using views::LabelButton; | 70 using views::LabelButton; |
71 using views::MenuConfig; | 71 using views::MenuConfig; |
72 using views::MenuItemView; | 72 using views::MenuItemView; |
73 using views::View; | 73 using views::View; |
74 | 74 |
75 namespace { | 75 namespace { |
76 | 76 |
77 // Colors used for buttons. | |
78 const SkColor kEnabledTouchBackgroundColor = SkColorSetARGB(247, 255, 255, 255); | |
79 const SkColor kHoverTouchBackgroundColor = SkColorSetARGB(247, 242, 242, 242); | |
80 const SkColor kFocusedTouchBackgroundColor = SkColorSetARGB(247, 235, 235, 235); | |
81 | |
82 const SkColor kTouchButtonText = 0xff5a5a5a; | |
83 | |
84 // Horizontal padding on the edges of the buttons. | 77 // Horizontal padding on the edges of the buttons. |
85 const int kHorizontalPadding = 6; | 78 const int kHorizontalPadding = 6; |
86 // Horizontal padding for a touch enabled menu. | 79 // Horizontal padding for a touch enabled menu. |
87 const int kHorizontalTouchPadding = 15; | 80 const int kHorizontalTouchPadding = 15; |
88 | 81 |
89 // Menu items which have embedded buttons should have this height in pixel. | 82 // Menu items which have embedded buttons should have this height in pixel. |
90 const int kMenuItemContainingButtonsHeight = 43; | 83 const int kMenuItemContainingButtonsHeight = 43; |
91 | 84 |
92 // Returns true if |command_id| identifies a bookmark menu item. | 85 // Returns true if |command_id| identifies a bookmark menu item. |
93 bool IsBookmarkCommand(int command_id) { | 86 bool IsBookmarkCommand(int command_id) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 left_button_ = right_button; | 174 left_button_ = right_button; |
182 right_button_ = left_button; | 175 right_button_ = left_button; |
183 } else { | 176 } else { |
184 left_button_ = left_button; | 177 left_button_ = left_button; |
185 right_button_ = right_button; | 178 right_button_ = right_button; |
186 } | 179 } |
187 } | 180 } |
188 | 181 |
189 // Overridden from views::Background. | 182 // Overridden from views::Background. |
190 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE { | 183 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE { |
191 CustomButton::ButtonState state = | 184 CustomButton* button = CustomButton::AsCustomButton(view); |
192 (!strcmp(view->GetClassName(), views::Label::kViewClassName)) ? | 185 views::Button::ButtonState state = |
193 CustomButton::STATE_NORMAL : static_cast<CustomButton*>(view)->state(); | 186 button ? button->state() : views::Button::STATE_NORMAL; |
194 int w = view->width(); | 187 int w = view->width(); |
195 int h = view->height(); | 188 int h = view->height(); |
196 #if defined(USE_AURA) | 189 #if defined(USE_AURA) |
197 if (use_new_menu_ && | 190 // Normal buttons get a border drawn on the right side and the rest gets |
198 view->GetNativeTheme() == ui::NativeThemeAura::instance()) { | 191 // filled in. The left button however does not get a line to combine |
199 // Normal buttons get a border drawn on the right side and the rest gets | 192 // buttons. |
200 // filled in. The left button however does not get a line to combine | 193 int border = 0; |
201 // buttons. | 194 if (type_ != RIGHT_BUTTON) { |
202 int border = 0; | 195 border = 1; |
203 if (type_ != RIGHT_BUTTON) { | 196 canvas->FillRect(gfx::Rect(0, 0, border, h), |
204 border = 1; | 197 BorderColor(view, views::Button::STATE_NORMAL)); |
205 canvas->FillRect(gfx::Rect(0, 0, border, h), | 198 } |
206 BorderColor(view, CustomButton::STATE_NORMAL)); | 199 if (use_new_menu_) { |
207 } | 200 gfx::Rect bounds(view->GetLocalBounds()); |
208 canvas->FillRect(gfx::Rect(border, 0, w - border, h), | 201 bounds.set_x(view->GetMirroredXForRect(bounds)); |
209 touch_background_color(state)); | 202 DrawBackground(canvas, view, bounds, state); |
210 return; | 203 return; |
211 } | 204 } |
205 if (use_new_menu_) | |
sky
2013/12/02 14:28:01
This shouldn't be necessary sine handled on 199, r
oshima
2013/12/02 20:00:59
oops, thank you for the catch. done.
| |
206 return; | |
212 #endif | 207 #endif |
213 const SkColor background = BackgroundColor(view, state); | 208 const SkColor border_color = BorderColor(view, state); |
214 const SkColor border = BorderColor(view, state); | |
215 switch (TypeAdjustedForRTL()) { | 209 switch (TypeAdjustedForRTL()) { |
216 // TODO(pkasting): Why don't all the following use SkPaths with rounded | 210 // TODO(pkasting): Why don't all the following use SkPaths with rounded |
217 // corners? | 211 // corners? |
218 case LEFT_BUTTON: | 212 case LEFT_BUTTON: |
219 canvas->FillRect(gfx::Rect(1, 1, w, h - 2), background); | 213 DrawBackground(canvas, view, gfx::Rect(1, 1, w, h - 2), state); |
220 canvas->FillRect(gfx::Rect(2, 0, w, 1), border); | 214 canvas->FillRect(gfx::Rect(2, 0, w, 1), border_color); |
221 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border); | 215 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color); |
222 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border); | 216 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color); |
223 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border); | 217 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color); |
224 canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border); | 218 canvas->FillRect(gfx::Rect(2, h - 1, w, 1), border_color); |
225 break; | 219 break; |
226 | 220 |
227 case CENTER_BUTTON: { | 221 case CENTER_BUTTON: { |
228 canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), background); | 222 DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state); |
229 SkColor left_color = state != CustomButton::STATE_NORMAL ? | 223 SkColor left_color = state != views::Button::STATE_NORMAL ? |
230 border : BorderColor(view, left_button_->state()); | 224 border_color : BorderColor(view, left_button_->state()); |
231 canvas->FillRect(gfx::Rect(0, 0, 1, h), left_color); | 225 canvas->FillRect(gfx::Rect(0, 0, 1, h), left_color); |
232 canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border); | 226 canvas->FillRect(gfx::Rect(1, 0, w - 2, 1), border_color); |
233 canvas->FillRect(gfx::Rect(1, h - 1, w - 2, 1), | 227 canvas->FillRect(gfx::Rect(1, h - 1, w - 2, 1), |
234 border); | 228 border_color); |
235 SkColor right_color = state != CustomButton::STATE_NORMAL ? | 229 SkColor right_color = state != views::Button::STATE_NORMAL ? |
236 border : BorderColor(view, right_button_->state()); | 230 border_color : BorderColor(view, right_button_->state()); |
237 canvas->FillRect(gfx::Rect(w - 1, 0, 1, h), right_color); | 231 canvas->FillRect(gfx::Rect(w - 1, 0, 1, h), right_color); |
238 break; | 232 break; |
239 } | 233 } |
240 | 234 |
241 case RIGHT_BUTTON: | 235 case RIGHT_BUTTON: |
242 canvas->FillRect(gfx::Rect(0, 1, w - 1, h - 2), background); | 236 DrawBackground(canvas, view, gfx::Rect(0, 1, w - 1, h - 2), state); |
243 canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border); | 237 canvas->FillRect(gfx::Rect(0, 0, w - 2, 1), border_color); |
244 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border); | 238 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color); |
245 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border); | 239 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color); |
246 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border); | 240 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color); |
247 canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border); | 241 canvas->FillRect(gfx::Rect(0, h - 1, w - 2, 1), border_color); |
248 break; | 242 break; |
249 | 243 |
250 case SINGLE_BUTTON: | 244 case SINGLE_BUTTON: |
251 canvas->FillRect(gfx::Rect(1, 1, w - 2, h - 2), background); | 245 DrawBackground(canvas, view, gfx::Rect(1, 1, w - 2, h - 2), state); |
252 canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border); | 246 canvas->FillRect(gfx::Rect(2, 0, w - 4, 1), border_color); |
253 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border); | 247 canvas->FillRect(gfx::Rect(1, 1, 1, 1), border_color); |
254 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border); | 248 canvas->FillRect(gfx::Rect(0, 2, 1, h - 4), border_color); |
255 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border); | 249 canvas->FillRect(gfx::Rect(1, h - 2, 1, 1), border_color); |
256 canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border); | 250 canvas->FillRect(gfx::Rect(2, h - 1, w - 4, 1), border_color); |
257 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border); | 251 canvas->FillRect(gfx::Rect(w - 2, 1, 1, 1), border_color); |
258 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border); | 252 canvas->FillRect(gfx::Rect(w - 1, 2, 1, h - 4), border_color); |
259 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border); | 253 canvas->FillRect(gfx::Rect(w - 2, h - 2, 1, 1), border_color); |
260 break; | 254 break; |
261 | 255 |
262 default: | 256 default: |
263 NOTREACHED(); | 257 NOTREACHED(); |
264 break; | 258 break; |
265 } | 259 } |
266 } | 260 } |
267 | 261 |
268 private: | 262 private: |
269 static SkColor BorderColor(View* view, CustomButton::ButtonState state) { | 263 static SkColor BorderColor(View* view, views::Button::ButtonState state) { |
270 ui::NativeTheme* theme = view->GetNativeTheme(); | 264 ui::NativeTheme* theme = view->GetNativeTheme(); |
271 switch (state) { | 265 switch (state) { |
272 case CustomButton::STATE_HOVERED: | 266 case views::Button::STATE_HOVERED: |
273 return theme->GetSystemColor( | 267 return theme->GetSystemColor( |
274 ui::NativeTheme::kColorId_HoverMenuButtonBorderColor); | 268 ui::NativeTheme::kColorId_HoverMenuButtonBorderColor); |
275 case CustomButton::STATE_PRESSED: | 269 case views::Button::STATE_PRESSED: |
276 return theme->GetSystemColor( | 270 return theme->GetSystemColor( |
277 ui::NativeTheme::kColorId_FocusedMenuButtonBorderColor); | 271 ui::NativeTheme::kColorId_FocusedMenuButtonBorderColor); |
278 default: | 272 default: |
279 return theme->GetSystemColor( | 273 return theme->GetSystemColor( |
280 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor); | 274 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor); |
281 } | 275 } |
282 } | 276 } |
283 | 277 |
284 static SkColor BackgroundColor(View* view, CustomButton::ButtonState state) { | 278 static SkColor BackgroundColor(const View* view, |
285 ui::NativeTheme* theme = view->GetNativeTheme(); | 279 views::Button::ButtonState state) { |
280 const ui::NativeTheme* theme = view->GetNativeTheme(); | |
286 switch (state) { | 281 switch (state) { |
287 case CustomButton::STATE_HOVERED: | 282 case views::Button::STATE_HOVERED: |
283 NOTREACHED(); | |
sky
2013/12/02 14:28:01
Why the NOTREACHED and then a valid lookup?
oshima
2013/12/02 20:00:59
I have to return something, otherwise it won't com
| |
288 return theme->GetSystemColor( | 284 return theme->GetSystemColor( |
289 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); | 285 ui::NativeTheme::kColorId_HoverMenuItemBackgroundColor); |
290 case CustomButton::STATE_PRESSED: | 286 case views::Button::STATE_PRESSED: |
291 return theme->GetSystemColor( | 287 return theme->GetSystemColor( |
292 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | 288 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); |
293 default: | 289 default: |
294 return theme->GetSystemColor( | 290 return theme->GetSystemColor( |
295 ui::NativeTheme::kColorId_MenuBackgroundColor); | 291 ui::NativeTheme::kColorId_MenuBackgroundColor); |
296 } | 292 } |
297 } | 293 } |
298 | 294 |
299 static SkColor touch_background_color(CustomButton::ButtonState state) { | 295 void DrawBackground(gfx::Canvas* canvas, |
300 switch (state) { | 296 const views::View* view, |
301 case CustomButton::STATE_HOVERED: return kHoverTouchBackgroundColor; | 297 const gfx::Rect& bounds, |
302 case CustomButton::STATE_PRESSED: return kFocusedTouchBackgroundColor; | 298 views::Button::ButtonState state) const { |
303 default: return kEnabledTouchBackgroundColor; | 299 if (state == views::Button::STATE_HOVERED) { |
300 view->GetNativeTheme()->Paint(canvas->sk_canvas(), | |
301 ui::NativeTheme::kMenuItemBackground, | |
302 ui::NativeTheme::kHovered, | |
303 bounds, | |
304 ui::NativeTheme::ExtraParams()); | |
305 return; | |
304 } | 306 } |
307 if (use_new_menu_) | |
308 return; | |
309 canvas->FillRect(bounds, BackgroundColor(view, state)); | |
305 } | 310 } |
306 | 311 |
307 ButtonType TypeAdjustedForRTL() const { | 312 ButtonType TypeAdjustedForRTL() const { |
308 if (!base::i18n::IsRTL()) | 313 if (!base::i18n::IsRTL()) |
309 return type_; | 314 return type_; |
310 | 315 |
311 switch (type_) { | 316 switch (type_) { |
312 case LEFT_BUTTON: return RIGHT_BUTTON; | 317 case LEFT_BUTTON: return RIGHT_BUTTON; |
313 case RIGHT_BUTTON: return LEFT_BUTTON; | 318 case RIGHT_BUTTON: return LEFT_BUTTON; |
314 default: break; | 319 default: break; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 // Overridden from views::View. | 366 // Overridden from views::View. |
362 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE { | 367 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE { |
363 // Normally when the mouse enters/exits a button the buttons invokes | 368 // Normally when the mouse enters/exits a button the buttons invokes |
364 // SchedulePaint. As part of the button border (MenuButtonBackground) is | 369 // SchedulePaint. As part of the button border (MenuButtonBackground) is |
365 // rendered by the button to the left/right of it SchedulePaint on the the | 370 // rendered by the button to the left/right of it SchedulePaint on the the |
366 // button may not be enough, so this forces a paint all. | 371 // button may not be enough, so this forces a paint all. |
367 View::SchedulePaintInRect(gfx::Rect(size())); | 372 View::SchedulePaintInRect(gfx::Rect(size())); |
368 } | 373 } |
369 | 374 |
370 LabelButton* CreateAndConfigureButton(int string_id, | 375 LabelButton* CreateAndConfigureButton(int string_id, |
371 MenuButtonBackground::ButtonType type, | 376 MenuButtonBackground::ButtonType type, |
372 int index, | 377 int index, |
373 MenuButtonBackground** background) { | 378 MenuButtonBackground** background) { |
374 return CreateButtonWithAccName( | 379 return CreateButtonWithAccName( |
375 string_id, type, index, background, string_id); | 380 string_id, type, index, background, string_id); |
376 } | 381 } |
377 | 382 |
378 LabelButton* CreateButtonWithAccName(int string_id, | 383 LabelButton* CreateButtonWithAccName(int string_id, |
379 MenuButtonBackground::ButtonType type, | 384 MenuButtonBackground::ButtonType type, |
380 int index, | 385 int index, |
381 MenuButtonBackground** background, | 386 MenuButtonBackground** background, |
382 int acc_string_id) { | 387 int acc_string_id) { |
383 // Should only be invoked during construction when |menu_| is valid. | 388 // Should only be invoked during construction when |menu_| is valid. |
(...skipping 10 matching lines...) Expand all Loading... | |
394 new MenuButtonBackground(type, menu_->use_new_menu()); | 399 new MenuButtonBackground(type, menu_->use_new_menu()); |
395 button->set_background(bg); | 400 button->set_background(bg); |
396 const MenuConfig& menu_config = menu_->GetMenuConfig(); | 401 const MenuConfig& menu_config = menu_->GetMenuConfig(); |
397 button->SetTextColor(views::Button::STATE_NORMAL, menu_config.text_color); | 402 button->SetTextColor(views::Button::STATE_NORMAL, menu_config.text_color); |
398 if (background) | 403 if (background) |
399 *background = bg; | 404 *background = bg; |
400 button->set_border( | 405 button->set_border( |
401 new MenuButtonBorder(menu_config, menu_->use_new_menu())); | 406 new MenuButtonBorder(menu_config, menu_->use_new_menu())); |
402 button->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 407 button->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
403 button->SetFont(menu_config.font); | 408 button->SetFont(menu_config.font); |
409 ui::NativeTheme* native_theme = button->GetNativeTheme(); | |
410 button->SetTextColor( | |
411 views::Button::STATE_DISABLED, | |
412 native_theme->GetSystemColor( | |
413 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor)); | |
414 button->SetTextColor( | |
415 views::Button::STATE_HOVERED, | |
416 native_theme->GetSystemColor( | |
417 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); | |
418 button->SetTextColor( | |
419 views::Button::STATE_PRESSED, | |
420 native_theme->GetSystemColor( | |
421 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); | |
422 button->SetTextColor( | |
423 views::Button::STATE_NORMAL, | |
424 native_theme->GetSystemColor( | |
425 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); | |
404 AddChildView(button); | 426 AddChildView(button); |
427 DCHECK(CustomButton::AsCustomButton(button)); | |
sky
2013/12/02 14:28:01
Add a comment as to why this is needed.
oshima
2013/12/02 20:00:59
Done.
| |
405 return button; | 428 return button; |
406 } | 429 } |
407 | 430 |
408 // Overridden from WrenchMenuObserver: | 431 // Overridden from WrenchMenuObserver: |
409 virtual void WrenchMenuDestroyed() OVERRIDE { | 432 virtual void WrenchMenuDestroyed() OVERRIDE { |
410 menu_->RemoveObserver(this); | 433 menu_->RemoveObserver(this); |
411 menu_ = NULL; | 434 menu_ = NULL; |
412 menu_model_ = NULL; | 435 menu_model_ = NULL; |
413 } | 436 } |
414 | 437 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 size.set_height(height); | 471 size.set_height(height); |
449 return size; | 472 return size; |
450 } | 473 } |
451 | 474 |
452 private: | 475 private: |
453 int height_; | 476 int height_; |
454 | 477 |
455 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView); | 478 DISALLOW_COPY_AND_ASSIGN(ButtonContainerMenuItemView); |
456 }; | 479 }; |
457 | 480 |
481 // Generate the button image for hover state. | |
482 class HoveredImageSource : public gfx::ImageSkiaSource { | |
483 public: | |
484 HoveredImageSource(const gfx::ImageSkia& image, SkColor color) | |
485 : image_(image), | |
486 color_(color) { | |
487 } | |
488 virtual ~HoveredImageSource() {} | |
489 | |
490 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | |
491 const gfx::ImageSkiaRep& rep = image_.GetRepresentation(scale); | |
492 SkBitmap bitmap = rep.sk_bitmap(); | |
493 SkBitmap white; | |
494 white.setConfig(SkBitmap::kARGB_8888_Config, | |
495 bitmap.width(), bitmap.height(), 0); | |
496 white.allocPixels(); | |
497 white.eraseARGB(0, 0, 0, 0); | |
498 bitmap.lockPixels(); | |
499 for (int y = 0; y < bitmap.height(); ++y) { | |
500 uint32* image_row = bitmap.getAddr32(0, y); | |
501 uint32* dst_row = white.getAddr32(0, y); | |
502 for (int x = 0; x < bitmap.width(); ++x) { | |
503 uint32 image_pixel = image_row[x]; | |
504 // Fill the non transparent pixels with |color_|. | |
505 dst_row[x] = (image_pixel & 0xFF000000) == 0x0 ? 0x0 : color_; | |
506 } | |
507 } | |
508 bitmap.unlockPixels(); | |
509 return gfx::ImageSkiaRep(white, scale); | |
510 } | |
511 | |
512 private: | |
513 | |
sky
2013/12/02 14:28:01
nit: remove newline.
oshima
2013/12/02 20:00:59
Done.
| |
514 const gfx::ImageSkia image_; | |
515 const SkColor color_; | |
516 DISALLOW_COPY_AND_ASSIGN(HoveredImageSource); | |
517 }; | |
518 | |
458 } // namespace | 519 } // namespace |
459 | 520 |
460 // CutCopyPasteView ------------------------------------------------------------ | 521 // CutCopyPasteView ------------------------------------------------------------ |
461 | 522 |
462 // CutCopyPasteView is the view containing the cut/copy/paste buttons. | 523 // CutCopyPasteView is the view containing the cut/copy/paste buttons. |
463 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { | 524 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { |
464 public: | 525 public: |
465 CutCopyPasteView(WrenchMenu* menu, | 526 CutCopyPasteView(WrenchMenu* menu, |
466 MenuModel* menu_model, | 527 MenuModel* menu_model, |
467 const ui::NativeTheme* native_theme, | 528 const ui::NativeTheme* native_theme, |
468 int cut_index, | 529 int cut_index, |
469 int copy_index, | 530 int copy_index, |
470 int paste_index) | 531 int paste_index) |
471 : WrenchMenuView(menu, menu_model) { | 532 : WrenchMenuView(menu, menu_model) { |
472 LabelButton* cut = CreateAndConfigureButton( | 533 LabelButton* cut = CreateAndConfigureButton( |
473 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL); | 534 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL); |
474 | 535 DCHECK(CustomButton::AsCustomButton(cut)); |
475 MenuButtonBackground* copy_background = NULL; | 536 MenuButtonBackground* copy_background = NULL; |
476 LabelButton* copy = CreateAndConfigureButton( | 537 CreateAndConfigureButton( |
477 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index, | 538 IDS_COPY, MenuButtonBackground::CENTER_BUTTON, copy_index, |
478 ©_background); | 539 ©_background); |
479 | |
480 LabelButton* paste = CreateAndConfigureButton( | 540 LabelButton* paste = CreateAndConfigureButton( |
481 IDS_PASTE, | 541 IDS_PASTE, |
482 menu->use_new_menu() && menu->supports_new_separators_ ? | 542 menu->use_new_menu() && menu->supports_new_separators_ ? |
483 MenuButtonBackground::CENTER_BUTTON : | 543 MenuButtonBackground::CENTER_BUTTON : |
484 MenuButtonBackground::RIGHT_BUTTON, | 544 MenuButtonBackground::RIGHT_BUTTON, |
485 paste_index, | 545 paste_index, |
486 NULL); | 546 NULL); |
487 if (menu->use_new_menu()) { | |
488 cut->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); | |
489 copy->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); | |
490 paste->SetTextColor(views::Button::STATE_NORMAL, kTouchButtonText); | |
491 } else { | |
492 SkColor text_color = native_theme->GetSystemColor( | |
493 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); | |
494 cut->SetTextColor(views::Button::STATE_NORMAL, text_color); | |
495 copy->SetTextColor(views::Button::STATE_NORMAL, text_color); | |
496 paste->SetTextColor(views::Button::STATE_NORMAL, text_color); | |
497 } | |
498 copy_background->SetOtherButtons(cut, paste); | 547 copy_background->SetOtherButtons(cut, paste); |
499 } | 548 } |
500 | 549 |
501 // Overridden from View. | 550 // Overridden from View. |
502 virtual gfx::Size GetPreferredSize() OVERRIDE { | 551 virtual gfx::Size GetPreferredSize() OVERRIDE { |
503 // Returned height doesn't matter as MenuItemView forces everything to the | 552 // Returned height doesn't matter as MenuItemView forces everything to the |
504 // height of the menuitemview. | 553 // height of the menuitemview. |
505 return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); | 554 return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); |
506 } | 555 } |
507 | 556 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 AddChildView(zoom_label_); | 631 AddChildView(zoom_label_); |
583 zoom_label_width_ = MaxWidthForZoomLabel(); | 632 zoom_label_width_ = MaxWidthForZoomLabel(); |
584 | 633 |
585 increment_button_ = CreateButtonWithAccName( | 634 increment_button_ = CreateButtonWithAccName( |
586 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index, | 635 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, increment_index, |
587 NULL, IDS_ACCNAME_ZOOM_PLUS2); | 636 NULL, IDS_ACCNAME_ZOOM_PLUS2); |
588 | 637 |
589 center_bg->SetOtherButtons(decrement_button_, increment_button_); | 638 center_bg->SetOtherButtons(decrement_button_, increment_button_); |
590 | 639 |
591 fullscreen_button_ = new FullscreenButton(this); | 640 fullscreen_button_ = new FullscreenButton(this); |
641 DCHECK(CustomButton::AsCustomButton(fullscreen_button_)); | |
592 gfx::ImageSkia* full_screen_image = | 642 gfx::ImageSkia* full_screen_image = |
593 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 643 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
594 IDR_FULLSCREEN_MENU_BUTTON); | 644 IDR_FULLSCREEN_MENU_BUTTON); |
595 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); | 645 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); |
596 if (menu->use_new_menu()) { | 646 SkColor fg_color = native_theme->GetSystemColor( |
597 zoom_label_->SetEnabledColor(kTouchButtonText); | 647 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor); |
598 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, | 648 fullscreen_button_->SetImage( |
599 kTouchButtonText); | 649 ImageButton::STATE_HOVERED, |
600 increment_button_->SetTextColor(views::Button::STATE_NORMAL, | 650 new gfx::ImageSkia(new HoveredImageSource(*full_screen_image, fg_color), |
601 kTouchButtonText); | 651 full_screen_image->size())); |
602 } else { | 652 SkColor enabled_text_color = native_theme->GetSystemColor( |
603 SkColor enabled_text_color = native_theme->GetSystemColor( | 653 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); |
604 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); | 654 zoom_label_->SetEnabledColor(enabled_text_color); |
605 zoom_label_->SetEnabledColor(enabled_text_color); | 655 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, |
606 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, | 656 enabled_text_color); |
607 enabled_text_color); | 657 increment_button_->SetTextColor(views::Button::STATE_NORMAL, |
608 increment_button_->SetTextColor(views::Button::STATE_NORMAL, | 658 enabled_text_color); |
609 enabled_text_color); | 659 SkColor disabled_text_color = native_theme->GetSystemColor( |
610 SkColor disabled_text_color = native_theme->GetSystemColor( | 660 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); |
611 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); | 661 decrement_button_->SetTextColor(views::Button::STATE_DISABLED, |
612 decrement_button_->SetTextColor(views::Button::STATE_DISABLED, | 662 disabled_text_color); |
613 disabled_text_color); | 663 increment_button_->SetTextColor(views::Button::STATE_DISABLED, |
614 increment_button_->SetTextColor(views::Button::STATE_DISABLED, | 664 disabled_text_color); |
615 disabled_text_color); | |
616 } | |
617 | |
618 fullscreen_button_->set_focusable(true); | 665 fullscreen_button_->set_focusable(true); |
619 fullscreen_button_->set_request_focus_on_press(false); | 666 fullscreen_button_->set_request_focus_on_press(false); |
620 fullscreen_button_->set_tag(fullscreen_index); | 667 fullscreen_button_->set_tag(fullscreen_index); |
621 fullscreen_button_->SetImageAlignment( | 668 fullscreen_button_->SetImageAlignment( |
622 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); | 669 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); |
623 int horizontal_padding = | 670 int horizontal_padding = |
624 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; | 671 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; |
625 fullscreen_button_->set_border(views::Border::CreateEmptyBorder( | 672 fullscreen_button_->set_border(views::Border::CreateEmptyBorder( |
626 0, horizontal_padding, 0, horizontal_padding)); | 673 0, horizontal_padding, 0, horizontal_padding)); |
627 fullscreen_button_->set_background( | 674 fullscreen_button_->set_background( |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1311 0, | 1358 0, |
1312 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1359 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1313 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1360 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
1314 } | 1361 } |
1315 | 1362 |
1316 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1363 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
1317 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1364 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1318 DCHECK(ix != command_id_to_entry_.end()); | 1365 DCHECK(ix != command_id_to_entry_.end()); |
1319 return ix->second.second; | 1366 return ix->second.second; |
1320 } | 1367 } |
OLD | NEW |