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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 pref.Enlarge(insets.width(), insets.height()); | 105 pref.Enlarge(insets.width(), insets.height()); |
106 } | 106 } |
107 return pref; | 107 return pref; |
108 } | 108 } |
109 | 109 |
110 private: | 110 private: |
111 DISALLOW_COPY_AND_ASSIGN(FullscreenButton); | 111 DISALLOW_COPY_AND_ASSIGN(FullscreenButton); |
112 }; | 112 }; |
113 | 113 |
114 // Border for buttons contained in the menu. This is only used for getting the | 114 // Border for buttons contained in the menu. This is only used for getting the |
115 // insets, the actual painting is done in MenuButtonBackground. | 115 // insets, the actual painting is done in InMenuButtonBackground. |
116 class MenuButtonBorder : public views::Border { | 116 class MenuButtonBorder : public views::Border { |
117 public: | 117 public: |
118 MenuButtonBorder(const MenuConfig& config, bool use_new_menu) | 118 MenuButtonBorder(const MenuConfig& config, bool use_new_menu) |
119 : horizontal_padding_(use_new_menu ? | 119 : horizontal_padding_(use_new_menu ? |
120 kHorizontalTouchPadding : kHorizontalPadding), | 120 kHorizontalTouchPadding : kHorizontalPadding), |
121 insets_(config.item_top_margin, horizontal_padding_, | 121 insets_(config.item_top_margin, horizontal_padding_, |
122 config.item_bottom_margin, horizontal_padding_) { | 122 config.item_bottom_margin, horizontal_padding_) { |
123 } | 123 } |
124 | 124 |
125 // Overridden from views::Border. | 125 // Overridden from views::Border. |
126 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE { | 126 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE { |
127 // Painting of border is done in MenuButtonBackground. | 127 // Painting of border is done in InMenuButtonBackground. |
128 } | 128 } |
129 | 129 |
130 virtual gfx::Insets GetInsets() const OVERRIDE { | 130 virtual gfx::Insets GetInsets() const OVERRIDE { |
131 return insets_; | 131 return insets_; |
132 } | 132 } |
133 | 133 |
134 virtual gfx::Size GetMinimumSize() const OVERRIDE { | 134 virtual gfx::Size GetMinimumSize() const OVERRIDE { |
135 // This size is sufficient for MenuButtonBackground::Paint() to draw any of | 135 // This size is sufficient for InMenuButtonBackground::Paint() to draw any |
136 // the button types. | 136 // of the button types. |
137 return gfx::Size(4, 4); | 137 return gfx::Size(4, 4); |
138 } | 138 } |
139 | 139 |
140 private: | 140 private: |
141 // The horizontal padding dependent on the layout. | 141 // The horizontal padding dependent on the layout. |
142 const int horizontal_padding_; | 142 const int horizontal_padding_; |
143 | 143 |
144 const gfx::Insets insets_; | 144 const gfx::Insets insets_; |
145 | 145 |
146 DISALLOW_COPY_AND_ASSIGN(MenuButtonBorder); | 146 DISALLOW_COPY_AND_ASSIGN(MenuButtonBorder); |
147 }; | 147 }; |
148 | 148 |
149 // Combination border/background for the buttons contained in the menu. The | 149 // Combination border/background for the buttons contained in the menu. The |
150 // painting of the border/background is done here as TextButton does not always | 150 // painting of the border/background is done here as TextButton does not always |
151 // paint the border. | 151 // paint the border. |
152 class MenuButtonBackground : public views::Background { | 152 class InMenuButtonBackground : public views::Background { |
153 public: | 153 public: |
154 enum ButtonType { | 154 enum ButtonType { |
155 LEFT_BUTTON, | 155 LEFT_BUTTON, |
156 CENTER_BUTTON, | 156 CENTER_BUTTON, |
157 RIGHT_BUTTON, | 157 RIGHT_BUTTON, |
158 SINGLE_BUTTON, | 158 SINGLE_BUTTON, |
159 }; | 159 }; |
160 | 160 |
161 MenuButtonBackground(ButtonType type, bool use_new_menu) | 161 InMenuButtonBackground(ButtonType type, bool use_new_menu) |
162 : type_(type), | 162 : type_(type), |
163 use_new_menu_(use_new_menu), | 163 use_new_menu_(use_new_menu), |
164 left_button_(NULL), | 164 left_button_(NULL), |
165 right_button_(NULL) {} | 165 right_button_(NULL) {} |
166 | 166 |
167 // Used when the type is CENTER_BUTTON to determine if the left/right edge | 167 // Used when the type is CENTER_BUTTON to determine if the left/right edge |
168 // needs to be rendered selected. | 168 // needs to be rendered selected. |
169 void SetOtherButtons(CustomButton* left_button, CustomButton* right_button) { | 169 void SetOtherButtons(const CustomButton* left_button, |
| 170 const CustomButton* right_button) { |
170 if (base::i18n::IsRTL()) { | 171 if (base::i18n::IsRTL()) { |
171 left_button_ = right_button; | 172 left_button_ = right_button; |
172 right_button_ = left_button; | 173 right_button_ = left_button; |
173 } else { | 174 } else { |
174 left_button_ = left_button; | 175 left_button_ = left_button; |
175 right_button_ = right_button; | 176 right_button_ = right_button; |
176 } | 177 } |
177 } | 178 } |
178 | 179 |
179 // Overridden from views::Background. | 180 // Overridden from views::Background. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 case RIGHT_BUTTON: return LEFT_BUTTON; | 312 case RIGHT_BUTTON: return LEFT_BUTTON; |
312 default: break; | 313 default: break; |
313 } | 314 } |
314 return type_; | 315 return type_; |
315 } | 316 } |
316 | 317 |
317 const ButtonType type_; | 318 const ButtonType type_; |
318 const bool use_new_menu_; | 319 const bool use_new_menu_; |
319 | 320 |
320 // See description above setter for details. | 321 // See description above setter for details. |
321 CustomButton* left_button_; | 322 const CustomButton* left_button_; |
322 CustomButton* right_button_; | 323 const CustomButton* right_button_; |
323 | 324 |
324 DISALLOW_COPY_AND_ASSIGN(MenuButtonBackground); | 325 DISALLOW_COPY_AND_ASSIGN(InMenuButtonBackground); |
325 }; | 326 }; |
326 | 327 |
327 base::string16 GetAccessibleNameForWrenchMenuItem( | 328 base::string16 GetAccessibleNameForWrenchMenuItem( |
328 MenuModel* model, int item_index, int accessible_string_id) { | 329 MenuModel* model, int item_index, int accessible_string_id) { |
329 base::string16 accessible_name = | 330 base::string16 accessible_name = |
330 l10n_util::GetStringUTF16(accessible_string_id); | 331 l10n_util::GetStringUTF16(accessible_string_id); |
331 base::string16 accelerator_text; | 332 base::string16 accelerator_text; |
332 | 333 |
333 ui::Accelerator menu_accelerator; | 334 ui::Accelerator menu_accelerator; |
334 if (model->GetAcceleratorAt(item_index, &menu_accelerator)) { | 335 if (model->GetAcceleratorAt(item_index, &menu_accelerator)) { |
335 accelerator_text = | 336 accelerator_text = |
336 ui::Accelerator(menu_accelerator.key_code(), | 337 ui::Accelerator(menu_accelerator.key_code(), |
337 menu_accelerator.modifiers()).GetShortcutText(); | 338 menu_accelerator.modifiers()).GetShortcutText(); |
338 } | 339 } |
339 | 340 |
340 return MenuItemView::GetAccessibleNameForMenuItem( | 341 return MenuItemView::GetAccessibleNameForMenuItem( |
341 accessible_name, accelerator_text); | 342 accessible_name, accelerator_text); |
342 } | 343 } |
343 | 344 |
| 345 // A button that lives inside a menu item. |
| 346 class InMenuButton : public LabelButton { |
| 347 public: |
| 348 InMenuButton(views::ButtonListener* listener, |
| 349 const base::string16& text, |
| 350 bool use_new_menu) |
| 351 : LabelButton(listener, text), |
| 352 use_new_menu_(use_new_menu), |
| 353 in_menu_background_(NULL) {} |
| 354 virtual ~InMenuButton() {} |
| 355 |
| 356 void Init(InMenuButtonBackground::ButtonType type) { |
| 357 SetFocusable(true); |
| 358 set_request_focus_on_press(false); |
| 359 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 360 |
| 361 in_menu_background_ = new InMenuButtonBackground(type, use_new_menu_); |
| 362 set_background(in_menu_background_); |
| 363 |
| 364 OnNativeThemeChanged(NULL); |
| 365 } |
| 366 |
| 367 void SetOtherButtons(const InMenuButton* left, const InMenuButton* right) { |
| 368 in_menu_background_->SetOtherButtons(left, right); |
| 369 } |
| 370 |
| 371 // views::LabelButton |
| 372 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE { |
| 373 const MenuConfig& menu_config = MenuConfig::instance(theme); |
| 374 SetBorder(scoped_ptr<views::Border>( |
| 375 new MenuButtonBorder(menu_config, use_new_menu_))); |
| 376 SetFontList(menu_config.font_list); |
| 377 |
| 378 if (theme) { |
| 379 SetTextColor( |
| 380 views::Button::STATE_DISABLED, |
| 381 theme->GetSystemColor( |
| 382 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor)); |
| 383 SetTextColor( |
| 384 views::Button::STATE_HOVERED, |
| 385 theme->GetSystemColor( |
| 386 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); |
| 387 SetTextColor( |
| 388 views::Button::STATE_PRESSED, |
| 389 theme->GetSystemColor( |
| 390 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); |
| 391 SetTextColor( |
| 392 views::Button::STATE_NORMAL, |
| 393 theme->GetSystemColor( |
| 394 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); |
| 395 } |
| 396 } |
| 397 |
| 398 private: |
| 399 bool use_new_menu_; |
| 400 |
| 401 InMenuButtonBackground* in_menu_background_; |
| 402 |
| 403 DISALLOW_COPY_AND_ASSIGN(InMenuButton); |
| 404 }; |
| 405 |
344 // WrenchMenuView is a view that can contain label buttons. | 406 // WrenchMenuView is a view that can contain label buttons. |
345 class WrenchMenuView : public views::View, | 407 class WrenchMenuView : public views::View, |
346 public views::ButtonListener, | 408 public views::ButtonListener, |
347 public WrenchMenuObserver { | 409 public WrenchMenuObserver { |
348 public: | 410 public: |
349 WrenchMenuView(WrenchMenu* menu, MenuModel* menu_model) | 411 WrenchMenuView(WrenchMenu* menu, MenuModel* menu_model) |
350 : menu_(menu), | 412 : menu_(menu), |
351 menu_model_(menu_model) { | 413 menu_model_(menu_model) { |
352 menu_->AddObserver(this); | 414 menu_->AddObserver(this); |
353 } | 415 } |
354 | 416 |
355 virtual ~WrenchMenuView() { | 417 virtual ~WrenchMenuView() { |
356 if (menu_) | 418 if (menu_) |
357 menu_->RemoveObserver(this); | 419 menu_->RemoveObserver(this); |
358 } | 420 } |
359 | 421 |
360 // Overridden from views::View. | 422 // Overridden from views::View. |
361 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE { | 423 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE { |
362 // Normally when the mouse enters/exits a button the buttons invokes | 424 // Normally when the mouse enters/exits a button the buttons invokes |
363 // SchedulePaint. As part of the button border (MenuButtonBackground) is | 425 // SchedulePaint. As part of the button border (InMenuButtonBackground) is |
364 // rendered by the button to the left/right of it SchedulePaint on the the | 426 // rendered by the button to the left/right of it SchedulePaint on the the |
365 // button may not be enough, so this forces a paint all. | 427 // button may not be enough, so this forces a paint all. |
366 View::SchedulePaintInRect(gfx::Rect(size())); | 428 View::SchedulePaintInRect(gfx::Rect(size())); |
367 } | 429 } |
368 | 430 |
369 LabelButton* CreateAndConfigureButton(const ui::NativeTheme* native_theme, | 431 InMenuButton* CreateAndConfigureButton( |
370 int string_id, | 432 int string_id, |
371 MenuButtonBackground::ButtonType type, | 433 InMenuButtonBackground::ButtonType type, |
372 int index, | 434 int index) { |
373 MenuButtonBackground** background) { | 435 return CreateButtonWithAccName(string_id, type, index, string_id); |
374 return CreateButtonWithAccName( | |
375 native_theme, string_id, type, index, background, string_id); | |
376 } | 436 } |
377 | 437 |
378 LabelButton* CreateButtonWithAccName(const ui::NativeTheme* native_theme, | 438 InMenuButton* CreateButtonWithAccName(int string_id, |
379 int string_id, | 439 InMenuButtonBackground::ButtonType type, |
380 MenuButtonBackground::ButtonType type, | 440 int index, |
381 int index, | 441 int acc_string_id) { |
382 MenuButtonBackground** background, | |
383 int acc_string_id) { | |
384 // Should only be invoked during construction when |menu_| is valid. | 442 // Should only be invoked during construction when |menu_| is valid. |
385 DCHECK(menu_); | 443 DCHECK(menu_); |
386 LabelButton* button = new LabelButton(this, gfx::RemoveAcceleratorChar( | 444 InMenuButton* button = new InMenuButton( |
387 l10n_util::GetStringUTF16(string_id), '&', NULL, NULL)); | 445 this, |
| 446 gfx::RemoveAcceleratorChar(l10n_util::GetStringUTF16(string_id), |
| 447 '&', |
| 448 NULL, |
| 449 NULL), |
| 450 use_new_menu()); |
| 451 button->Init(type); |
388 button->SetAccessibleName( | 452 button->SetAccessibleName( |
389 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id)); | 453 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id)); |
390 button->SetFocusable(true); | |
391 button->set_request_focus_on_press(false); | |
392 button->set_tag(index); | 454 button->set_tag(index); |
393 button->SetEnabled(menu_model_->IsEnabledAt(index)); | 455 button->SetEnabled(menu_model_->IsEnabledAt(index)); |
394 MenuButtonBackground* bg = | 456 |
395 new MenuButtonBackground(type, menu_->use_new_menu()); | |
396 button->set_background(bg); | |
397 const MenuConfig& menu_config = menu_->GetMenuConfig(); | |
398 if (background) | |
399 *background = bg; | |
400 button->SetBorder(scoped_ptr<views::Border>( | |
401 new MenuButtonBorder(menu_config, menu_->use_new_menu()))); | |
402 button->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
403 button->SetFontList(menu_config.font_list); | |
404 button->SetTextColor( | |
405 views::Button::STATE_DISABLED, | |
406 native_theme->GetSystemColor( | |
407 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor)); | |
408 button->SetTextColor( | |
409 views::Button::STATE_HOVERED, | |
410 native_theme->GetSystemColor( | |
411 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); | |
412 button->SetTextColor( | |
413 views::Button::STATE_PRESSED, | |
414 native_theme->GetSystemColor( | |
415 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor)); | |
416 button->SetTextColor( | |
417 views::Button::STATE_NORMAL, | |
418 native_theme->GetSystemColor( | |
419 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); | |
420 AddChildView(button); | 457 AddChildView(button); |
421 // all buttons on menu should must be a custom button in order for | 458 // all buttons on menu should must be a custom button in order for |
422 // the keyboard nativigation work. | 459 // the keyboard nativigation work. |
423 DCHECK(CustomButton::AsCustomButton(button)); | 460 DCHECK(CustomButton::AsCustomButton(button)); |
424 return button; | 461 return button; |
425 } | 462 } |
426 | 463 |
427 // Overridden from WrenchMenuObserver: | 464 // Overridden from WrenchMenuObserver: |
428 virtual void WrenchMenuDestroyed() OVERRIDE { | 465 virtual void WrenchMenuDestroyed() OVERRIDE { |
429 menu_->RemoveObserver(this); | 466 menu_->RemoveObserver(this); |
(...skipping 18 matching lines...) Expand all Loading... |
448 | 485 |
449 DISALLOW_COPY_AND_ASSIGN(WrenchMenuView); | 486 DISALLOW_COPY_AND_ASSIGN(WrenchMenuView); |
450 }; | 487 }; |
451 | 488 |
452 class ButtonContainerMenuItemView : public MenuItemView { | 489 class ButtonContainerMenuItemView : public MenuItemView { |
453 public: | 490 public: |
454 // Constructor for use with button containing menu items which have a | 491 // Constructor for use with button containing menu items which have a |
455 // different height then normal items. | 492 // different height then normal items. |
456 ButtonContainerMenuItemView(MenuItemView* parent, int command_id, int height) | 493 ButtonContainerMenuItemView(MenuItemView* parent, int command_id, int height) |
457 : MenuItemView(parent, command_id, MenuItemView::NORMAL), | 494 : MenuItemView(parent, command_id, MenuItemView::NORMAL), |
458 height_(height) { | 495 height_(height) {} |
459 }; | |
460 | 496 |
461 // Overridden from MenuItemView. | 497 // Overridden from MenuItemView. |
462 virtual gfx::Size GetChildPreferredSize() const OVERRIDE { | 498 virtual gfx::Size GetChildPreferredSize() const OVERRIDE { |
463 gfx::Size size = MenuItemView::GetChildPreferredSize(); | 499 gfx::Size size = MenuItemView::GetChildPreferredSize(); |
464 // When there is a height override given, we need to deduct our spacing | 500 // When there is a height override given, we need to deduct our spacing |
465 // above and below to get to the correct height to return here for the | 501 // above and below to get to the correct height to return here for the |
466 // child item. | 502 // child item. |
467 int height = height_ - GetTopMargin() - GetBottomMargin(); | 503 int height = height_ - GetTopMargin() - GetBottomMargin(); |
468 if (height > size.height()) | 504 if (height > size.height()) |
469 size.set_height(height); | 505 size.set_height(height); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 551 |
516 } // namespace | 552 } // namespace |
517 | 553 |
518 // CutCopyPasteView ------------------------------------------------------------ | 554 // CutCopyPasteView ------------------------------------------------------------ |
519 | 555 |
520 // CutCopyPasteView is the view containing the cut/copy/paste buttons. | 556 // CutCopyPasteView is the view containing the cut/copy/paste buttons. |
521 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { | 557 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { |
522 public: | 558 public: |
523 CutCopyPasteView(WrenchMenu* menu, | 559 CutCopyPasteView(WrenchMenu* menu, |
524 MenuModel* menu_model, | 560 MenuModel* menu_model, |
525 const ui::NativeTheme* native_theme, | |
526 int cut_index, | 561 int cut_index, |
527 int copy_index, | 562 int copy_index, |
528 int paste_index) | 563 int paste_index) |
529 : WrenchMenuView(menu, menu_model) { | 564 : WrenchMenuView(menu, menu_model) { |
530 LabelButton* cut = CreateAndConfigureButton( | 565 InMenuButton* cut = CreateAndConfigureButton( |
531 native_theme, IDS_CUT, MenuButtonBackground::LEFT_BUTTON, | 566 IDS_CUT, InMenuButtonBackground::LEFT_BUTTON, |
532 cut_index, NULL); | 567 cut_index); |
533 MenuButtonBackground* copy_background = NULL; | 568 InMenuButton* copy = CreateAndConfigureButton( |
534 CreateAndConfigureButton( | 569 IDS_COPY, InMenuButtonBackground::CENTER_BUTTON, |
535 native_theme, IDS_COPY, MenuButtonBackground::CENTER_BUTTON, | 570 copy_index); |
536 copy_index, ©_background); | 571 InMenuButton* paste = CreateAndConfigureButton( |
537 LabelButton* paste = CreateAndConfigureButton( | |
538 native_theme, | |
539 IDS_PASTE, | 572 IDS_PASTE, |
540 menu->use_new_menu() && menu->supports_new_separators_ ? | 573 menu->use_new_menu() && menu->supports_new_separators_ ? |
541 MenuButtonBackground::CENTER_BUTTON : | 574 InMenuButtonBackground::CENTER_BUTTON : |
542 MenuButtonBackground::RIGHT_BUTTON, | 575 InMenuButtonBackground::RIGHT_BUTTON, |
543 paste_index, | 576 paste_index); |
544 NULL); | 577 copy->SetOtherButtons(cut, paste); |
545 copy_background->SetOtherButtons(cut, paste); | |
546 } | 578 } |
547 | 579 |
548 // Overridden from View. | 580 // Overridden from View. |
549 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 581 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
550 // Returned height doesn't matter as MenuItemView forces everything to the | 582 // Returned height doesn't matter as MenuItemView forces everything to the |
551 // height of the menuitemview. | 583 // height of the menuitemview. |
552 return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); | 584 return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); |
553 } | 585 } |
554 | 586 |
555 virtual void Layout() OVERRIDE { | 587 virtual void Layout() OVERRIDE { |
(...skipping 27 matching lines...) Expand all Loading... |
583 static const int kZoomPadding = 6; | 615 static const int kZoomPadding = 6; |
584 static const int kTouchZoomPadding = 14; | 616 static const int kTouchZoomPadding = 14; |
585 | 617 |
586 // ZoomView contains the various zoom controls: two buttons to increase/decrease | 618 // ZoomView contains the various zoom controls: two buttons to increase/decrease |
587 // the zoom, a label showing the current zoom percent, and a button to go | 619 // the zoom, a label showing the current zoom percent, and a button to go |
588 // full-screen. | 620 // full-screen. |
589 class WrenchMenu::ZoomView : public WrenchMenuView { | 621 class WrenchMenu::ZoomView : public WrenchMenuView { |
590 public: | 622 public: |
591 ZoomView(WrenchMenu* menu, | 623 ZoomView(WrenchMenu* menu, |
592 MenuModel* menu_model, | 624 MenuModel* menu_model, |
593 const ui::NativeTheme* native_theme, | |
594 int decrement_index, | 625 int decrement_index, |
595 int increment_index, | 626 int increment_index, |
596 int fullscreen_index) | 627 int fullscreen_index) |
597 : WrenchMenuView(menu, menu_model), | 628 : WrenchMenuView(menu, menu_model), |
598 fullscreen_index_(fullscreen_index), | 629 fullscreen_index_(fullscreen_index), |
599 increment_button_(NULL), | 630 increment_button_(NULL), |
600 zoom_label_(NULL), | 631 zoom_label_(NULL), |
601 decrement_button_(NULL), | 632 decrement_button_(NULL), |
602 fullscreen_button_(NULL), | 633 fullscreen_button_(NULL), |
603 zoom_label_width_(0) { | 634 zoom_label_width_(0) { |
604 zoom_subscription_ = HostZoomMap::GetForBrowserContext( | 635 zoom_subscription_ = HostZoomMap::GetForBrowserContext( |
605 menu->browser_->profile())->AddZoomLevelChangedCallback( | 636 menu->browser_->profile())->AddZoomLevelChangedCallback( |
606 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, | 637 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, |
607 base::Unretained(this))); | 638 base::Unretained(this))); |
608 | 639 |
609 decrement_button_ = CreateButtonWithAccName( | 640 decrement_button_ = CreateButtonWithAccName( |
610 native_theme, IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, | 641 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON, |
611 decrement_index, NULL, IDS_ACCNAME_ZOOM_MINUS2); | 642 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); |
612 | 643 |
613 zoom_label_ = new Label( | 644 zoom_label_ = new Label( |
614 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); | 645 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); |
615 zoom_label_->SetAutoColorReadabilityEnabled(false); | 646 zoom_label_->SetAutoColorReadabilityEnabled(false); |
616 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 647 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
617 | 648 |
618 MenuButtonBackground* center_bg = new MenuButtonBackground( | 649 InMenuButtonBackground* center_bg = new InMenuButtonBackground( |
619 menu->use_new_menu() && menu->supports_new_separators_ ? | 650 menu->use_new_menu() && menu->supports_new_separators_ ? |
620 MenuButtonBackground::RIGHT_BUTTON : | 651 InMenuButtonBackground::RIGHT_BUTTON : |
621 MenuButtonBackground::CENTER_BUTTON, | 652 InMenuButtonBackground::CENTER_BUTTON, |
622 menu->use_new_menu()); | 653 menu->use_new_menu()); |
623 zoom_label_->set_background(center_bg); | 654 zoom_label_->set_background(center_bg); |
624 const MenuConfig& menu_config(menu->GetMenuConfig()); | |
625 zoom_label_->SetBorder(scoped_ptr<views::Border>( | |
626 new MenuButtonBorder(menu_config, menu->use_new_menu()))); | |
627 zoom_label_->SetFontList(menu_config.font_list); | |
628 | 655 |
629 AddChildView(zoom_label_); | 656 AddChildView(zoom_label_); |
630 zoom_label_width_ = MaxWidthForZoomLabel(); | 657 zoom_label_width_ = MaxWidthForZoomLabel(); |
631 | 658 |
632 increment_button_ = CreateButtonWithAccName( | 659 increment_button_ = CreateButtonWithAccName( |
633 native_theme, IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, | 660 IDS_ZOOM_PLUS2, InMenuButtonBackground::RIGHT_BUTTON, |
634 increment_index, NULL, IDS_ACCNAME_ZOOM_PLUS2); | 661 increment_index, IDS_ACCNAME_ZOOM_PLUS2); |
635 | 662 |
636 center_bg->SetOtherButtons(decrement_button_, increment_button_); | 663 center_bg->SetOtherButtons(decrement_button_, increment_button_); |
637 | 664 |
638 fullscreen_button_ = new FullscreenButton(this); | 665 fullscreen_button_ = new FullscreenButton(this); |
639 // all buttons on menu should must be a custom button in order for | 666 // all buttons on menu should must be a custom button in order for |
640 // the keyboard nativigation work. | 667 // the keyboard nativigation work. |
641 DCHECK(CustomButton::AsCustomButton(fullscreen_button_)); | 668 DCHECK(CustomButton::AsCustomButton(fullscreen_button_)); |
642 gfx::ImageSkia* full_screen_image = | 669 gfx::ImageSkia* full_screen_image = |
643 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 670 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
644 IDR_FULLSCREEN_MENU_BUTTON); | 671 IDR_FULLSCREEN_MENU_BUTTON); |
645 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); | 672 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); |
646 SkColor fg_color = native_theme->GetSystemColor( | |
647 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor); | |
648 gfx::ImageSkia hovered_fullscreen_image( | |
649 new HoveredImageSource(*full_screen_image, fg_color), | |
650 full_screen_image->size()); | |
651 fullscreen_button_->SetImage( | |
652 ImageButton::STATE_HOVERED, &hovered_fullscreen_image); | |
653 fullscreen_button_->SetImage( | |
654 ImageButton::STATE_PRESSED, &hovered_fullscreen_image); | |
655 | 673 |
656 SkColor enabled_text_color = native_theme->GetSystemColor( | |
657 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); | |
658 zoom_label_->SetEnabledColor(enabled_text_color); | |
659 decrement_button_->SetTextColor(views::Button::STATE_NORMAL, | |
660 enabled_text_color); | |
661 increment_button_->SetTextColor(views::Button::STATE_NORMAL, | |
662 enabled_text_color); | |
663 SkColor disabled_text_color = native_theme->GetSystemColor( | |
664 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); | |
665 decrement_button_->SetTextColor(views::Button::STATE_DISABLED, | |
666 disabled_text_color); | |
667 increment_button_->SetTextColor(views::Button::STATE_DISABLED, | |
668 disabled_text_color); | |
669 fullscreen_button_->SetFocusable(true); | 674 fullscreen_button_->SetFocusable(true); |
670 fullscreen_button_->set_request_focus_on_press(false); | 675 fullscreen_button_->set_request_focus_on_press(false); |
671 fullscreen_button_->set_tag(fullscreen_index); | 676 fullscreen_button_->set_tag(fullscreen_index); |
672 fullscreen_button_->SetImageAlignment( | 677 fullscreen_button_->SetImageAlignment( |
673 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); | 678 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); |
674 int horizontal_padding = | 679 int horizontal_padding = |
675 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; | 680 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; |
676 fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder( | 681 fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder( |
677 0, horizontal_padding, 0, horizontal_padding)); | 682 0, horizontal_padding, 0, horizontal_padding)); |
678 fullscreen_button_->set_background( | 683 fullscreen_button_->set_background( |
679 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON, | 684 new InMenuButtonBackground(InMenuButtonBackground::SINGLE_BUTTON, |
680 menu->use_new_menu())); | 685 menu->use_new_menu())); |
681 fullscreen_button_->SetAccessibleName( | 686 fullscreen_button_->SetAccessibleName( |
682 GetAccessibleNameForWrenchMenuItem( | 687 GetAccessibleNameForWrenchMenuItem( |
683 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); | 688 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); |
684 AddChildView(fullscreen_button_); | 689 AddChildView(fullscreen_button_); |
685 | 690 |
| 691 // Need to set a font list for the zoom label width calculations. |
| 692 OnNativeThemeChanged(NULL); |
686 UpdateZoomControls(); | 693 UpdateZoomControls(); |
687 } | 694 } |
688 | 695 |
689 virtual ~ZoomView() {} | 696 virtual ~ZoomView() {} |
690 | 697 |
691 // Overridden from View. | 698 // Overridden from View. |
692 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 699 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
693 // The increment/decrement button are forced to the same width. | 700 // The increment/decrement button are forced to the same width. |
694 int button_width = std::max(increment_button_->GetPreferredSize().width(), | 701 int button_width = std::max(increment_button_->GetPreferredSize().width(), |
695 decrement_button_->GetPreferredSize().width()); | 702 decrement_button_->GetPreferredSize().width()); |
(...skipping 26 matching lines...) Expand all Loading... |
722 bounds.set_width(button_width); | 729 bounds.set_width(button_width); |
723 increment_button_->SetBoundsRect(bounds); | 730 increment_button_->SetBoundsRect(bounds); |
724 | 731 |
725 x += bounds.width() + (use_new_menu() ? 0 : kZoomPadding); | 732 x += bounds.width() + (use_new_menu() ? 0 : kZoomPadding); |
726 bounds.set_x(x); | 733 bounds.set_x(x); |
727 bounds.set_width(fullscreen_button_->GetPreferredSize().width() + | 734 bounds.set_width(fullscreen_button_->GetPreferredSize().width() + |
728 (use_new_menu() ? kTouchZoomPadding : 0)); | 735 (use_new_menu() ? kTouchZoomPadding : 0)); |
729 fullscreen_button_->SetBoundsRect(bounds); | 736 fullscreen_button_->SetBoundsRect(bounds); |
730 } | 737 } |
731 | 738 |
| 739 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE { |
| 740 WrenchMenuView::OnNativeThemeChanged(theme); |
| 741 |
| 742 const MenuConfig& menu_config = MenuConfig::instance(theme); |
| 743 zoom_label_->SetBorder(scoped_ptr<views::Border>( |
| 744 new MenuButtonBorder(menu_config, menu()->use_new_menu()))); |
| 745 zoom_label_->SetFontList(menu_config.font_list); |
| 746 zoom_label_width_ = MaxWidthForZoomLabel(); |
| 747 |
| 748 if (theme) { |
| 749 zoom_label_->SetEnabledColor(theme->GetSystemColor( |
| 750 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor)); |
| 751 gfx::ImageSkia* full_screen_image = |
| 752 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 753 IDR_FULLSCREEN_MENU_BUTTON); |
| 754 SkColor fg_color = theme->GetSystemColor( |
| 755 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor); |
| 756 gfx::ImageSkia hovered_fullscreen_image( |
| 757 new HoveredImageSource(*full_screen_image, fg_color), |
| 758 full_screen_image->size()); |
| 759 fullscreen_button_->SetImage( |
| 760 ImageButton::STATE_HOVERED, &hovered_fullscreen_image); |
| 761 fullscreen_button_->SetImage( |
| 762 ImageButton::STATE_PRESSED, &hovered_fullscreen_image); |
| 763 } |
| 764 } |
| 765 |
732 // Overridden from ButtonListener. | 766 // Overridden from ButtonListener. |
733 virtual void ButtonPressed(views::Button* sender, | 767 virtual void ButtonPressed(views::Button* sender, |
734 const ui::Event& event) OVERRIDE { | 768 const ui::Event& event) OVERRIDE { |
735 if (sender->tag() == fullscreen_index_) { | 769 if (sender->tag() == fullscreen_index_) { |
736 menu()->CancelAndEvaluate(menu_model(), sender->tag()); | 770 menu()->CancelAndEvaluate(menu_model(), sender->tag()); |
737 } else { | 771 } else { |
738 // Zoom buttons don't close the menu. | 772 // Zoom buttons don't close the menu. |
739 menu_model()->ActivatedAt(sender->tag()); | 773 menu_model()->ActivatedAt(sender->tag()); |
740 } | 774 } |
741 } | 775 } |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 model->RemoveObserver(this); | 1003 model->RemoveObserver(this); |
970 } | 1004 } |
971 if (selected_menu_model_) | 1005 if (selected_menu_model_) |
972 selected_menu_model_->ActivatedAt(selected_index_); | 1006 selected_menu_model_->ActivatedAt(selected_index_); |
973 } | 1007 } |
974 | 1008 |
975 bool WrenchMenu::IsShowing() { | 1009 bool WrenchMenu::IsShowing() { |
976 return menu_runner_.get() && menu_runner_->IsRunning(); | 1010 return menu_runner_.get() && menu_runner_->IsRunning(); |
977 } | 1011 } |
978 | 1012 |
979 const ui::NativeTheme* WrenchMenu::GetNativeTheme() const { | |
980 views::Widget* browser_widget = views::Widget::GetWidgetForNativeView( | |
981 browser_->window()->GetNativeWindow()); | |
982 DCHECK(browser_widget); | |
983 return browser_widget->GetNativeTheme(); | |
984 } | |
985 | |
986 const views::MenuConfig& WrenchMenu::GetMenuConfig() const { | |
987 return MenuConfig::instance(GetNativeTheme()); | |
988 } | |
989 | |
990 void WrenchMenu::AddObserver(WrenchMenuObserver* observer) { | 1013 void WrenchMenu::AddObserver(WrenchMenuObserver* observer) { |
991 observer_list_.AddObserver(observer); | 1014 observer_list_.AddObserver(observer); |
992 } | 1015 } |
993 | 1016 |
994 void WrenchMenu::RemoveObserver(WrenchMenuObserver* observer) { | 1017 void WrenchMenu::RemoveObserver(WrenchMenuObserver* observer) { |
995 observer_list_.RemoveObserver(observer); | 1018 observer_list_.RemoveObserver(observer); |
996 } | 1019 } |
997 | 1020 |
998 const gfx::FontList* WrenchMenu::GetLabelFontList(int command_id) const { | 1021 const gfx::FontList* WrenchMenu::GetLabelFontList(int command_id) const { |
999 if (IsRecentTabsCommand(command_id)) { | 1022 if (IsRecentTabsCommand(command_id)) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 | 1247 |
1225 // Add the menu item at the end. | 1248 // Add the menu item at the end. |
1226 int menu_index = parent->HasSubmenu() ? | 1249 int menu_index = parent->HasSubmenu() ? |
1227 parent->GetSubmenu()->child_count() : 0; | 1250 parent->GetSubmenu()->child_count() : 0; |
1228 MenuItemView* item = AddMenuItem( | 1251 MenuItemView* item = AddMenuItem( |
1229 parent, menu_index, model, i, model->GetTypeAt(i), height); | 1252 parent, menu_index, model, i, model->GetTypeAt(i), height); |
1230 | 1253 |
1231 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) | 1254 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) |
1232 PopulateMenu(item, model->GetSubmenuModelAt(i)); | 1255 PopulateMenu(item, model->GetSubmenuModelAt(i)); |
1233 | 1256 |
1234 const ui::NativeTheme* native_theme = GetNativeTheme(); | |
1235 | |
1236 switch (model->GetCommandIdAt(i)) { | 1257 switch (model->GetCommandIdAt(i)) { |
1237 case IDC_CUT: | 1258 case IDC_CUT: |
1238 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); | 1259 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); |
1239 DCHECK_LT(i + 2, max); | 1260 DCHECK_LT(i + 2, max); |
1240 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); | 1261 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); |
1241 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); | 1262 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); |
1242 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); | 1263 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); |
1243 item->AddChildView(new CutCopyPasteView(this, model, native_theme, | 1264 item->AddChildView(new CutCopyPasteView(this, model, |
1244 i, i + 1, i + 2)); | 1265 i, i + 1, i + 2)); |
1245 i += 2; | 1266 i += 2; |
1246 break; | 1267 break; |
1247 | 1268 |
1248 case IDC_ZOOM_MINUS: | 1269 case IDC_ZOOM_MINUS: |
1249 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); | 1270 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); |
1250 DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(i + 1)); | 1271 DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(i + 1)); |
1251 DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(i + 2)); | 1272 DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(i + 2)); |
1252 item->SetTitle(l10n_util::GetStringUTF16(IDS_ZOOM_MENU2)); | 1273 item->SetTitle(l10n_util::GetStringUTF16(IDS_ZOOM_MENU2)); |
1253 item->AddChildView(new ZoomView(this, model, native_theme, | 1274 item->AddChildView(new ZoomView(this, model, i, i + 1, i + 2)); |
1254 i, i + 1, i + 2)); | |
1255 i += 2; | 1275 i += 2; |
1256 break; | 1276 break; |
1257 | 1277 |
1258 case IDC_BOOKMARKS_MENU: | 1278 case IDC_BOOKMARKS_MENU: |
1259 DCHECK(!bookmark_menu_); | 1279 DCHECK(!bookmark_menu_); |
1260 bookmark_menu_ = item; | 1280 bookmark_menu_ = item; |
1261 break; | 1281 break; |
1262 | 1282 |
1263 #if defined(GOOGLE_CHROME_BUILD) | 1283 #if defined(GOOGLE_CHROME_BUILD) |
1264 case IDC_FEEDBACK: | 1284 case IDC_FEEDBACK: |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 0, | 1382 0, |
1363 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1383 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1364 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1384 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
1365 } | 1385 } |
1366 | 1386 |
1367 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1387 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
1368 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1388 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1369 DCHECK(ix != command_id_to_entry_.end()); | 1389 DCHECK(ix != command_id_to_entry_.end()); |
1370 return ix->second.second; | 1390 return ix->second.second; |
1371 } | 1391 } |
OLD | NEW |