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

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

Issue 245863002: Fix text color of WrenchMenu buttons on Linux Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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 | Annotate | Revision Log
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/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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 359
360 // Overridden from views::View. 360 // Overridden from views::View.
361 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE { 361 virtual void SchedulePaintInRect(const gfx::Rect& r) OVERRIDE {
362 // Normally when the mouse enters/exits a button the buttons invokes 362 // Normally when the mouse enters/exits a button the buttons invokes
363 // SchedulePaint. As part of the button border (MenuButtonBackground) is 363 // SchedulePaint. As part of the button border (MenuButtonBackground) is
364 // rendered by the button to the left/right of it SchedulePaint on the the 364 // 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. 365 // button may not be enough, so this forces a paint all.
366 View::SchedulePaintInRect(gfx::Rect(size())); 366 View::SchedulePaintInRect(gfx::Rect(size()));
367 } 367 }
368 368
369 LabelButton* CreateAndConfigureButton(const ui::NativeTheme* native_theme, 369 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE {
370 int string_id, 370 views::View::OnNativeThemeChanged(theme);
371 for (int i = 0; i < child_count(); ++i) {
372 if (child_at(i)->GetClassName() == views::LabelButton::kViewClassName) {
373 UpdateButtonWithNativeTheme(
374 static_cast<views::LabelButton*>(child_at(i)), theme);
375 }
376 }
377 }
378
379 LabelButton* CreateAndConfigureButton(int string_id,
371 MenuButtonBackground::ButtonType type, 380 MenuButtonBackground::ButtonType type,
372 int index, 381 int index,
373 MenuButtonBackground** background) { 382 MenuButtonBackground** background) {
374 return CreateButtonWithAccName( 383 return
375 native_theme, string_id, type, index, background, string_id); 384 CreateButtonWithAccName(string_id, type, index, background, string_id);
376 } 385 }
377 386
378 LabelButton* CreateButtonWithAccName(const ui::NativeTheme* native_theme, 387 LabelButton* CreateButtonWithAccName(int string_id,
379 int string_id,
380 MenuButtonBackground::ButtonType type, 388 MenuButtonBackground::ButtonType type,
381 int index, 389 int index,
382 MenuButtonBackground** background, 390 MenuButtonBackground** background,
383 int acc_string_id) { 391 int acc_string_id) {
384 // Should only be invoked during construction when |menu_| is valid. 392 // Should only be invoked during construction when |menu_| is valid.
385 DCHECK(menu_); 393 DCHECK(menu_);
386 LabelButton* button = new LabelButton(this, gfx::RemoveAcceleratorChar( 394 LabelButton* button = new LabelButton(this, gfx::RemoveAcceleratorChar(
387 l10n_util::GetStringUTF16(string_id), '&', NULL, NULL)); 395 l10n_util::GetStringUTF16(string_id), '&', NULL, NULL));
388 button->SetAccessibleName( 396 button->SetAccessibleName(
389 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id)); 397 GetAccessibleNameForWrenchMenuItem(menu_model_, index, acc_string_id));
390 button->SetFocusable(true); 398 button->SetFocusable(true);
391 button->set_request_focus_on_press(false); 399 button->set_request_focus_on_press(false);
392 button->set_tag(index); 400 button->set_tag(index);
393 button->SetEnabled(menu_model_->IsEnabledAt(index)); 401 button->SetEnabled(menu_model_->IsEnabledAt(index));
394 MenuButtonBackground* bg = 402 MenuButtonBackground* bg =
395 new MenuButtonBackground(type, menu_->use_new_menu()); 403 new MenuButtonBackground(type, menu_->use_new_menu());
396 button->set_background(bg); 404 button->set_background(bg);
397 const MenuConfig& menu_config = menu_->GetMenuConfig();
398 if (background) 405 if (background)
399 *background = bg; 406 *background = bg;
400 button->SetBorder(scoped_ptr<views::Border>(
401 new MenuButtonBorder(menu_config, menu_->use_new_menu())));
402 button->SetHorizontalAlignment(gfx::ALIGN_CENTER); 407 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); 408 AddChildView(button);
421 // all buttons on menu should must be a custom button in order for 409 // all buttons on menu should must be a custom button in order for
422 // the keyboard nativigation work. 410 // the keyboard nativigation work.
423 DCHECK(CustomButton::AsCustomButton(button)); 411 DCHECK(CustomButton::AsCustomButton(button));
412 UpdateButtonWithNativeTheme(button, NULL);
424 return button; 413 return button;
425 } 414 }
426 415
427 // Overridden from WrenchMenuObserver: 416 // Overridden from WrenchMenuObserver:
428 virtual void WrenchMenuDestroyed() OVERRIDE { 417 virtual void WrenchMenuDestroyed() OVERRIDE {
429 menu_->RemoveObserver(this); 418 menu_->RemoveObserver(this);
430 menu_ = NULL; 419 menu_ = NULL;
431 menu_model_ = NULL; 420 menu_model_ = NULL;
432 } 421 }
433 422
434 protected: 423 protected:
435 WrenchMenu* menu() { return menu_; } 424 WrenchMenu* menu() { return menu_; }
436 MenuModel* menu_model() { return menu_model_; } 425 MenuModel* menu_model() { return menu_model_; }
437 426
438 private: 427 private:
428 void UpdateButtonWithNativeTheme(views::LabelButton* button,
429 const ui::NativeTheme* native_theme) {
430 if (native_theme) {
431 button->SetTextColor(
432 views::Button::STATE_DISABLED,
433 native_theme->GetSystemColor(
434 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor));
435 button->SetTextColor(
436 views::Button::STATE_HOVERED,
437 native_theme->GetSystemColor(
438 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor));
439 button->SetTextColor(
440 views::Button::STATE_PRESSED,
441 native_theme->GetSystemColor(
442 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor));
443 button->SetTextColor(
444 views::Button::STATE_NORMAL,
445 native_theme->GetSystemColor(
446 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor));
447 }
448
449 MenuConfig menu_config(native_theme);
450 button->SetBorder(scoped_ptr<views::Border>(
451 new MenuButtonBorder(menu_config, menu_->use_new_menu())));
452 button->SetFontList(menu_config.font_list);
453 }
454
439 // Hosting WrenchMenu. 455 // Hosting WrenchMenu.
440 // WARNING: this may be NULL during shutdown. 456 // WARNING: this may be NULL during shutdown.
441 WrenchMenu* menu_; 457 WrenchMenu* menu_;
442 458
443 // The menu model containing the increment/decrement/reset items. 459 // The menu model containing the increment/decrement/reset items.
444 // WARNING: this may be NULL during shutdown. 460 // WARNING: this may be NULL during shutdown.
445 MenuModel* menu_model_; 461 MenuModel* menu_model_;
446 462
447 DISALLOW_COPY_AND_ASSIGN(WrenchMenuView); 463 DISALLOW_COPY_AND_ASSIGN(WrenchMenuView);
448 }; 464 };
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 529
514 } // namespace 530 } // namespace
515 531
516 // CutCopyPasteView ------------------------------------------------------------ 532 // CutCopyPasteView ------------------------------------------------------------
517 533
518 // CutCopyPasteView is the view containing the cut/copy/paste buttons. 534 // CutCopyPasteView is the view containing the cut/copy/paste buttons.
519 class WrenchMenu::CutCopyPasteView : public WrenchMenuView { 535 class WrenchMenu::CutCopyPasteView : public WrenchMenuView {
520 public: 536 public:
521 CutCopyPasteView(WrenchMenu* menu, 537 CutCopyPasteView(WrenchMenu* menu,
522 MenuModel* menu_model, 538 MenuModel* menu_model,
523 const ui::NativeTheme* native_theme,
524 int cut_index, 539 int cut_index,
525 int copy_index, 540 int copy_index,
526 int paste_index) 541 int paste_index)
527 : WrenchMenuView(menu, menu_model) { 542 : WrenchMenuView(menu, menu_model) {
528 LabelButton* cut = CreateAndConfigureButton( 543 LabelButton* cut = CreateAndConfigureButton(
529 native_theme, IDS_CUT, MenuButtonBackground::LEFT_BUTTON, 544 IDS_CUT, MenuButtonBackground::LEFT_BUTTON, cut_index, NULL);
530 cut_index, NULL);
531 MenuButtonBackground* copy_background = NULL; 545 MenuButtonBackground* copy_background = NULL;
532 CreateAndConfigureButton( 546 CreateAndConfigureButton(
533 native_theme, IDS_COPY, MenuButtonBackground::CENTER_BUTTON, 547 IDS_COPY, MenuButtonBackground::CENTER_BUTTON,
534 copy_index, &copy_background); 548 copy_index, &copy_background);
535 LabelButton* paste = CreateAndConfigureButton( 549 LabelButton* paste = CreateAndConfigureButton(
536 native_theme,
537 IDS_PASTE, 550 IDS_PASTE,
538 menu->use_new_menu() && menu->supports_new_separators_ ? 551 menu->use_new_menu() && menu->supports_new_separators_ ?
539 MenuButtonBackground::CENTER_BUTTON : 552 MenuButtonBackground::CENTER_BUTTON :
540 MenuButtonBackground::RIGHT_BUTTON, 553 MenuButtonBackground::RIGHT_BUTTON,
541 paste_index, 554 paste_index,
542 NULL); 555 NULL);
543 copy_background->SetOtherButtons(cut, paste); 556 copy_background->SetOtherButtons(cut, paste);
544 } 557 }
545 558
546 // Overridden from View. 559 // Overridden from View.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 static const int kZoomPadding = 6; 594 static const int kZoomPadding = 6;
582 static const int kTouchZoomPadding = 14; 595 static const int kTouchZoomPadding = 14;
583 596
584 // ZoomView contains the various zoom controls: two buttons to increase/decrease 597 // ZoomView contains the various zoom controls: two buttons to increase/decrease
585 // the zoom, a label showing the current zoom percent, and a button to go 598 // the zoom, a label showing the current zoom percent, and a button to go
586 // full-screen. 599 // full-screen.
587 class WrenchMenu::ZoomView : public WrenchMenuView { 600 class WrenchMenu::ZoomView : public WrenchMenuView {
588 public: 601 public:
589 ZoomView(WrenchMenu* menu, 602 ZoomView(WrenchMenu* menu,
590 MenuModel* menu_model, 603 MenuModel* menu_model,
591 const ui::NativeTheme* native_theme,
592 int decrement_index, 604 int decrement_index,
593 int increment_index, 605 int increment_index,
594 int fullscreen_index) 606 int fullscreen_index)
595 : WrenchMenuView(menu, menu_model), 607 : WrenchMenuView(menu, menu_model),
596 fullscreen_index_(fullscreen_index), 608 fullscreen_index_(fullscreen_index),
597 increment_button_(NULL), 609 increment_button_(NULL),
598 zoom_label_(NULL), 610 zoom_label_(NULL),
599 decrement_button_(NULL), 611 decrement_button_(NULL),
600 fullscreen_button_(NULL), 612 fullscreen_button_(NULL),
601 zoom_label_width_(0) { 613 zoom_label_width_(0) {
602 zoom_subscription_ = HostZoomMap::GetForBrowserContext( 614 zoom_subscription_ = HostZoomMap::GetForBrowserContext(
603 menu->browser_->profile())->AddZoomLevelChangedCallback( 615 menu->browser_->profile())->AddZoomLevelChangedCallback(
604 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, 616 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged,
605 base::Unretained(this))); 617 base::Unretained(this)));
606 618
607 decrement_button_ = CreateButtonWithAccName( 619 decrement_button_ = CreateButtonWithAccName(
608 native_theme, IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, 620 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON,
609 decrement_index, NULL, IDS_ACCNAME_ZOOM_MINUS2); 621 decrement_index, NULL, IDS_ACCNAME_ZOOM_MINUS2);
610 622
611 zoom_label_ = new Label( 623 zoom_label_ = new Label(
612 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); 624 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
613 zoom_label_->SetAutoColorReadabilityEnabled(false); 625 zoom_label_->SetAutoColorReadabilityEnabled(false);
614 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 626 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
615 627
616 MenuButtonBackground* center_bg = new MenuButtonBackground( 628 MenuButtonBackground* center_bg = new MenuButtonBackground(
617 menu->use_new_menu() && menu->supports_new_separators_ ? 629 menu->use_new_menu() && menu->supports_new_separators_ ?
618 MenuButtonBackground::RIGHT_BUTTON : 630 MenuButtonBackground::RIGHT_BUTTON :
619 MenuButtonBackground::CENTER_BUTTON, 631 MenuButtonBackground::CENTER_BUTTON,
620 menu->use_new_menu()); 632 menu->use_new_menu());
621 zoom_label_->set_background(center_bg); 633 zoom_label_->set_background(center_bg);
622 const MenuConfig& menu_config(menu->GetMenuConfig());
623 zoom_label_->SetBorder(scoped_ptr<views::Border>(
624 new MenuButtonBorder(menu_config, menu->use_new_menu())));
625 zoom_label_->SetFontList(menu_config.font_list);
626 634
627 AddChildView(zoom_label_); 635 AddChildView(zoom_label_);
628 zoom_label_width_ = MaxWidthForZoomLabel();
629 636
630 increment_button_ = CreateButtonWithAccName( 637 increment_button_ = CreateButtonWithAccName(
631 native_theme, IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON, 638 IDS_ZOOM_PLUS2, MenuButtonBackground::RIGHT_BUTTON,
632 increment_index, NULL, IDS_ACCNAME_ZOOM_PLUS2); 639 increment_index, NULL, IDS_ACCNAME_ZOOM_PLUS2);
633 640
634 center_bg->SetOtherButtons(decrement_button_, increment_button_); 641 center_bg->SetOtherButtons(decrement_button_, increment_button_);
635 642
636 fullscreen_button_ = new FullscreenButton(this); 643 fullscreen_button_ = new FullscreenButton(this);
637 // all buttons on menu should must be a custom button in order for 644 // all buttons on menu should must be a custom button in order for
638 // the keyboard nativigation work. 645 // the keyboard nativigation work.
639 DCHECK(CustomButton::AsCustomButton(fullscreen_button_)); 646 DCHECK(CustomButton::AsCustomButton(fullscreen_button_));
640 gfx::ImageSkia* full_screen_image = 647 gfx::ImageSkia* full_screen_image =
641 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 648 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
642 IDR_FULLSCREEN_MENU_BUTTON); 649 IDR_FULLSCREEN_MENU_BUTTON);
643 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image); 650 fullscreen_button_->SetImage(ImageButton::STATE_NORMAL, full_screen_image);
644 SkColor fg_color = native_theme->GetSystemColor(
645 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor);
646 gfx::ImageSkia hovered_fullscreen_image(
647 new HoveredImageSource(*full_screen_image, fg_color),
648 full_screen_image->size());
649 fullscreen_button_->SetImage(
650 ImageButton::STATE_HOVERED, &hovered_fullscreen_image);
651 fullscreen_button_->SetImage(
652 ImageButton::STATE_PRESSED, &hovered_fullscreen_image);
653
654 SkColor enabled_text_color = native_theme->GetSystemColor(
655 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor);
656 zoom_label_->SetEnabledColor(enabled_text_color);
657 decrement_button_->SetTextColor(views::Button::STATE_NORMAL,
658 enabled_text_color);
659 increment_button_->SetTextColor(views::Button::STATE_NORMAL,
660 enabled_text_color);
661 SkColor disabled_text_color = native_theme->GetSystemColor(
662 ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor);
663 decrement_button_->SetTextColor(views::Button::STATE_DISABLED,
664 disabled_text_color);
665 increment_button_->SetTextColor(views::Button::STATE_DISABLED,
666 disabled_text_color);
667 fullscreen_button_->SetFocusable(true); 651 fullscreen_button_->SetFocusable(true);
668 fullscreen_button_->set_request_focus_on_press(false); 652 fullscreen_button_->set_request_focus_on_press(false);
669 fullscreen_button_->set_tag(fullscreen_index); 653 fullscreen_button_->set_tag(fullscreen_index);
670 fullscreen_button_->SetImageAlignment( 654 fullscreen_button_->SetImageAlignment(
671 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); 655 ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE);
672 int horizontal_padding = 656 int horizontal_padding =
673 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding; 657 menu->use_new_menu() ? kHorizontalTouchPadding : kHorizontalPadding;
674 fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder( 658 fullscreen_button_->SetBorder(views::Border::CreateEmptyBorder(
675 0, horizontal_padding, 0, horizontal_padding)); 659 0, horizontal_padding, 0, horizontal_padding));
676 fullscreen_button_->set_background( 660 fullscreen_button_->set_background(
677 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON, 661 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON,
678 menu->use_new_menu())); 662 menu->use_new_menu()));
679 fullscreen_button_->SetAccessibleName( 663 fullscreen_button_->SetAccessibleName(
680 GetAccessibleNameForWrenchMenuItem( 664 GetAccessibleNameForWrenchMenuItem(
681 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); 665 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN));
682 AddChildView(fullscreen_button_); 666 AddChildView(fullscreen_button_);
683 667
668 OnNativeThemeChanged(NULL);
684 UpdateZoomControls(); 669 UpdateZoomControls();
685 } 670 }
686 671
687 virtual ~ZoomView() {} 672 virtual ~ZoomView() {}
688 673
689 // Overridden from View. 674 // Overridden from View.
690 virtual gfx::Size GetPreferredSize() OVERRIDE { 675 virtual gfx::Size GetPreferredSize() OVERRIDE {
691 // The increment/decrement button are forced to the same width. 676 // The increment/decrement button are forced to the same width.
692 int button_width = std::max(increment_button_->GetPreferredSize().width(), 677 int button_width = std::max(increment_button_->GetPreferredSize().width(),
693 decrement_button_->GetPreferredSize().width()); 678 decrement_button_->GetPreferredSize().width());
(...skipping 26 matching lines...) Expand all
720 bounds.set_width(button_width); 705 bounds.set_width(button_width);
721 increment_button_->SetBoundsRect(bounds); 706 increment_button_->SetBoundsRect(bounds);
722 707
723 x += bounds.width() + (menu()->use_new_menu() ? 0 : kZoomPadding); 708 x += bounds.width() + (menu()->use_new_menu() ? 0 : kZoomPadding);
724 bounds.set_x(x); 709 bounds.set_x(x);
725 bounds.set_width(fullscreen_button_->GetPreferredSize().width() + 710 bounds.set_width(fullscreen_button_->GetPreferredSize().width() +
726 (menu()->use_new_menu() ? kTouchZoomPadding : 0)); 711 (menu()->use_new_menu() ? kTouchZoomPadding : 0));
727 fullscreen_button_->SetBoundsRect(bounds); 712 fullscreen_button_->SetBoundsRect(bounds);
728 } 713 }
729 714
715 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE {
716 WrenchMenuView::OnNativeThemeChanged(theme);
717
718 MenuConfig menu_config(theme);
719 zoom_label_->SetBorder(scoped_ptr<views::Border>(
720 new MenuButtonBorder(menu_config, menu()->use_new_menu())));
721 zoom_label_->SetFontList(menu_config.font_list);
722 zoom_label_width_ = MaxWidthForZoomLabel();
723
724 if (theme) {
725 zoom_label_->SetEnabledColor(theme->GetSystemColor(
726 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor));
727 gfx::ImageSkia* full_screen_image =
728 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
729 IDR_FULLSCREEN_MENU_BUTTON);
730 SkColor fg_color = theme->GetSystemColor(
731 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor);
732 gfx::ImageSkia hovered_fullscreen_image(
733 new HoveredImageSource(*full_screen_image, fg_color),
734 full_screen_image->size());
735 fullscreen_button_->SetImage(
736 ImageButton::STATE_HOVERED, &hovered_fullscreen_image);
737 fullscreen_button_->SetImage(
738 ImageButton::STATE_PRESSED, &hovered_fullscreen_image);
739 }
740 }
741
730 // Overridden from ButtonListener. 742 // Overridden from ButtonListener.
731 virtual void ButtonPressed(views::Button* sender, 743 virtual void ButtonPressed(views::Button* sender,
732 const ui::Event& event) OVERRIDE { 744 const ui::Event& event) OVERRIDE {
733 if (sender->tag() == fullscreen_index_) { 745 if (sender->tag() == fullscreen_index_) {
734 menu()->CancelAndEvaluate(menu_model(), sender->tag()); 746 menu()->CancelAndEvaluate(menu_model(), sender->tag());
735 } else { 747 } else {
736 // Zoom buttons don't close the menu. 748 // Zoom buttons don't close the menu.
737 menu_model()->ActivatedAt(sender->tag()); 749 menu_model()->ActivatedAt(sender->tag());
738 } 750 }
739 } 751 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 model->RemoveObserver(this); 976 model->RemoveObserver(this);
965 } 977 }
966 if (selected_menu_model_) 978 if (selected_menu_model_)
967 selected_menu_model_->ActivatedAt(selected_index_); 979 selected_menu_model_->ActivatedAt(selected_index_);
968 } 980 }
969 981
970 bool WrenchMenu::IsShowing() { 982 bool WrenchMenu::IsShowing() {
971 return menu_runner_.get() && menu_runner_->IsRunning(); 983 return menu_runner_.get() && menu_runner_->IsRunning();
972 } 984 }
973 985
974 const ui::NativeTheme* WrenchMenu::GetNativeTheme() const {
975 views::Widget* browser_widget = views::Widget::GetWidgetForNativeView(
976 browser_->window()->GetNativeWindow());
977 DCHECK(browser_widget);
978 return browser_widget->GetNativeTheme();
979 }
980
981 const views::MenuConfig& WrenchMenu::GetMenuConfig() const {
982 return MenuConfig::instance(GetNativeTheme());
983 }
984
985 void WrenchMenu::AddObserver(WrenchMenuObserver* observer) { 986 void WrenchMenu::AddObserver(WrenchMenuObserver* observer) {
986 observer_list_.AddObserver(observer); 987 observer_list_.AddObserver(observer);
987 } 988 }
988 989
989 void WrenchMenu::RemoveObserver(WrenchMenuObserver* observer) { 990 void WrenchMenu::RemoveObserver(WrenchMenuObserver* observer) {
990 observer_list_.RemoveObserver(observer); 991 observer_list_.RemoveObserver(observer);
991 } 992 }
992 993
993 const gfx::FontList* WrenchMenu::GetLabelFontList(int command_id) const { 994 const gfx::FontList* WrenchMenu::GetLabelFontList(int command_id) const {
994 if (IsRecentTabsCommand(command_id)) { 995 if (IsRecentTabsCommand(command_id)) {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 1219
1219 // Add the menu item at the end. 1220 // Add the menu item at the end.
1220 int menu_index = parent->HasSubmenu() ? 1221 int menu_index = parent->HasSubmenu() ?
1221 parent->GetSubmenu()->child_count() : 0; 1222 parent->GetSubmenu()->child_count() : 0;
1222 MenuItemView* item = AddMenuItem( 1223 MenuItemView* item = AddMenuItem(
1223 parent, menu_index, model, i, model->GetTypeAt(i), height); 1224 parent, menu_index, model, i, model->GetTypeAt(i), height);
1224 1225
1225 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) 1226 if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU)
1226 PopulateMenu(item, model->GetSubmenuModelAt(i)); 1227 PopulateMenu(item, model->GetSubmenuModelAt(i));
1227 1228
1228 const ui::NativeTheme* native_theme = GetNativeTheme();
1229
1230 switch (model->GetCommandIdAt(i)) { 1229 switch (model->GetCommandIdAt(i)) {
1231 case IDC_CUT: 1230 case IDC_CUT:
1232 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); 1231 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i));
1233 DCHECK_LT(i + 2, max); 1232 DCHECK_LT(i + 2, max);
1234 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1)); 1233 DCHECK_EQ(IDC_COPY, model->GetCommandIdAt(i + 1));
1235 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2)); 1234 DCHECK_EQ(IDC_PASTE, model->GetCommandIdAt(i + 2));
1236 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2)); 1235 item->SetTitle(l10n_util::GetStringUTF16(IDS_EDIT2));
1237 item->AddChildView(new CutCopyPasteView(this, model, native_theme, 1236 item->AddChildView(new CutCopyPasteView(this, model,
1238 i, i + 1, i + 2)); 1237 i, i + 1, i + 2));
1239 i += 2; 1238 i += 2;
1240 break; 1239 break;
1241 1240
1242 case IDC_ZOOM_MINUS: 1241 case IDC_ZOOM_MINUS:
1243 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i)); 1242 DCHECK_EQ(MenuModel::TYPE_COMMAND, model->GetTypeAt(i));
1244 DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(i + 1)); 1243 DCHECK_EQ(IDC_ZOOM_PLUS, model->GetCommandIdAt(i + 1));
1245 DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(i + 2)); 1244 DCHECK_EQ(IDC_FULLSCREEN, model->GetCommandIdAt(i + 2));
1246 item->SetTitle(l10n_util::GetStringUTF16(IDS_ZOOM_MENU2)); 1245 item->SetTitle(l10n_util::GetStringUTF16(IDS_ZOOM_MENU2));
1247 item->AddChildView(new ZoomView(this, model, native_theme, 1246 item->AddChildView(new ZoomView(this, model, i, i + 1, i + 2));
1248 i, i + 1, i + 2));
1249 i += 2; 1247 i += 2;
1250 break; 1248 break;
1251 1249
1252 case IDC_BOOKMARKS_MENU: 1250 case IDC_BOOKMARKS_MENU:
1253 DCHECK(!bookmark_menu_); 1251 DCHECK(!bookmark_menu_);
1254 bookmark_menu_ = item; 1252 bookmark_menu_ = item;
1255 break; 1253 break;
1256 1254
1257 #if defined(GOOGLE_CHROME_BUILD) 1255 #if defined(GOOGLE_CHROME_BUILD)
1258 case IDC_FEEDBACK: 1256 case IDC_FEEDBACK:
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 0, 1354 0,
1357 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1355 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1358 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); 1356 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU);
1359 } 1357 }
1360 1358
1361 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { 1359 int WrenchMenu::ModelIndexFromCommandId(int command_id) const {
1362 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1360 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1363 DCHECK(ix != command_id_to_entry_.end()); 1361 DCHECK(ix != command_id_to_entry_.end());
1364 return ix->second.second; 1362 return ix->second.second;
1365 } 1363 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698