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

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

Issue 23851016: Convert zoom callbacks to use CallbackRegistry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pure merge Created 7 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/wrench_menu.h" 5 #include "chrome/browser/ui/views/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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 class WrenchMenu::ZoomView : public WrenchMenuView { 521 class WrenchMenu::ZoomView : public WrenchMenuView {
522 public: 522 public:
523 ZoomView(WrenchMenu* menu, 523 ZoomView(WrenchMenu* menu,
524 MenuModel* menu_model, 524 MenuModel* menu_model,
525 const ui::NativeTheme* native_theme, 525 const ui::NativeTheme* native_theme,
526 int decrement_index, 526 int decrement_index,
527 int increment_index, 527 int increment_index,
528 int fullscreen_index) 528 int fullscreen_index)
529 : WrenchMenuView(menu, menu_model), 529 : WrenchMenuView(menu, menu_model),
530 fullscreen_index_(fullscreen_index), 530 fullscreen_index_(fullscreen_index),
531 zoom_callback_(base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged,
532 base::Unretained(this))),
533 increment_button_(NULL), 531 increment_button_(NULL),
534 zoom_label_(NULL), 532 zoom_label_(NULL),
535 decrement_button_(NULL), 533 decrement_button_(NULL),
536 fullscreen_button_(NULL), 534 fullscreen_button_(NULL),
537 zoom_label_width_(0) { 535 zoom_label_width_(0) {
538 HostZoomMap::GetForBrowserContext( 536 zoom_subscription_ = HostZoomMap::GetForBrowserContext(
539 menu->browser_->profile())->AddZoomLevelChangedCallback(zoom_callback_); 537 menu->browser_->profile())->AddZoomLevelChangedCallback(
538 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged,
539 base::Unretained(this)));
540 540
541 decrement_button_ = CreateButtonWithAccName( 541 decrement_button_ = CreateButtonWithAccName(
542 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, 542 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index,
543 NULL, IDS_ACCNAME_ZOOM_MINUS2); 543 NULL, IDS_ACCNAME_ZOOM_MINUS2);
544 544
545 zoom_label_ = new Label( 545 zoom_label_ = new Label(
546 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); 546 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
547 zoom_label_->SetAutoColorReadabilityEnabled(false); 547 zoom_label_->SetAutoColorReadabilityEnabled(false);
548 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 548 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
549 549
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON, 607 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON,
608 menu->use_new_menu())); 608 menu->use_new_menu()));
609 fullscreen_button_->SetAccessibleName( 609 fullscreen_button_->SetAccessibleName(
610 GetAccessibleNameForWrenchMenuItem( 610 GetAccessibleNameForWrenchMenuItem(
611 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); 611 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN));
612 AddChildView(fullscreen_button_); 612 AddChildView(fullscreen_button_);
613 613
614 UpdateZoomControls(); 614 UpdateZoomControls();
615 } 615 }
616 616
617 virtual ~ZoomView() { 617 virtual ~ZoomView() {}
618 Shutdown();
619 }
620 618
621 // Overridden from View. 619 // Overridden from View.
622 virtual gfx::Size GetPreferredSize() OVERRIDE { 620 virtual gfx::Size GetPreferredSize() OVERRIDE {
623 // The increment/decrement button are forced to the same width. 621 // The increment/decrement button are forced to the same width.
624 int button_width = std::max(increment_button_->GetPreferredSize().width(), 622 int button_width = std::max(increment_button_->GetPreferredSize().width(),
625 decrement_button_->GetPreferredSize().width()); 623 decrement_button_->GetPreferredSize().width());
626 int zoom_padding = menu()->use_new_menu() ? 624 int zoom_padding = menu()->use_new_menu() ?
627 kTouchZoomPadding : kZoomPadding; 625 kTouchZoomPadding : kZoomPadding;
628 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() + 626 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() +
629 zoom_padding; 627 zoom_padding;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 if (sender->tag() == fullscreen_index_) { 663 if (sender->tag() == fullscreen_index_) {
666 menu()->CancelAndEvaluate(menu_model(), sender->tag()); 664 menu()->CancelAndEvaluate(menu_model(), sender->tag());
667 } else { 665 } else {
668 // Zoom buttons don't close the menu. 666 // Zoom buttons don't close the menu.
669 menu_model()->ActivatedAt(sender->tag()); 667 menu_model()->ActivatedAt(sender->tag());
670 } 668 }
671 } 669 }
672 670
673 // Overridden from WrenchMenuObserver. 671 // Overridden from WrenchMenuObserver.
674 virtual void WrenchMenuDestroyed() OVERRIDE { 672 virtual void WrenchMenuDestroyed() OVERRIDE {
675 Shutdown();
676 WrenchMenuView::WrenchMenuDestroyed(); 673 WrenchMenuView::WrenchMenuDestroyed();
677 } 674 }
678 675
679 private: 676 private:
680 // Invoked from the destructor or when the WrenchMenu is destroyed.
681 void Shutdown() {
682 if (!menu())
683 return;
684
685 HostZoomMap::GetForBrowserContext(
686 menu()->browser_->profile())->RemoveZoomLevelChangedCallback(
687 zoom_callback_);
688 }
689
690 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { 677 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) {
691 UpdateZoomControls(); 678 UpdateZoomControls();
692 } 679 }
693 680
694 void UpdateZoomControls() { 681 void UpdateZoomControls() {
695 bool enable_increment = false; 682 bool enable_increment = false;
696 bool enable_decrement = false; 683 bool enable_decrement = false;
697 WebContents* selected_tab = 684 WebContents* selected_tab =
698 menu()->browser_->tab_strip_model()->GetActiveWebContents(); 685 menu()->browser_->tab_strip_model()->GetActiveWebContents();
699 int zoom = 100; 686 int zoom = 100;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 max_w = font.GetStringWidth( 718 max_w = font.GetStringWidth(
732 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); 719 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
733 } 720 }
734 721
735 return max_w + border_width; 722 return max_w + border_width;
736 } 723 }
737 724
738 // Index of the fullscreen menu item in the model. 725 // Index of the fullscreen menu item in the model.
739 const int fullscreen_index_; 726 const int fullscreen_index_;
740 727
741 content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; 728 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
742 content::NotificationRegistrar registrar_; 729 content::NotificationRegistrar registrar_;
743 730
744 // Button for incrementing the zoom. 731 // Button for incrementing the zoom.
745 LabelButton* increment_button_; 732 LabelButton* increment_button_;
746 733
747 // Label showing zoom as a percent. 734 // Label showing zoom as a percent.
748 Label* zoom_label_; 735 Label* zoom_label_;
749 736
750 // Button for decrementing the zoom. 737 // Button for decrementing the zoom.
751 LabelButton* decrement_button_; 738 LabelButton* decrement_button_;
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 browser_, 1254 browser_,
1268 parent, 1255 parent,
1269 first_bookmark_command_id_)); 1256 first_bookmark_command_id_));
1270 bookmark_menu_delegate_->Init(this, 1257 bookmark_menu_delegate_->Init(this,
1271 bookmark_menu_, 1258 bookmark_menu_,
1272 model->bookmark_bar_node(), 1259 model->bookmark_bar_node(),
1273 0, 1260 0,
1274 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1261 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1275 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); 1262 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU);
1276 } 1263 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/wrench_menu_model.cc ('k') | chrome/browser/ui/zoom/zoom_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698