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

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

Issue 12039058: content: convert zoom notifications to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 473
474 // ZoomView -------------------------------------------------------------------- 474 // ZoomView --------------------------------------------------------------------
475 475
476 // Padding between the increment buttons and the reset button. 476 // Padding between the increment buttons and the reset button.
477 static const int kZoomPadding = 6; 477 static const int kZoomPadding = 6;
478 static const int kTouchZoomPadding = 14; 478 static const int kTouchZoomPadding = 14;
479 479
480 // ZoomView contains the various zoom controls: two buttons to increase/decrease 480 // ZoomView contains the various zoom controls: two buttons to increase/decrease
481 // the zoom, a label showing the current zoom percent, and a button to go 481 // the zoom, a label showing the current zoom percent, and a button to go
482 // full-screen. 482 // full-screen.
483 class WrenchMenu::ZoomView : public WrenchMenuView, 483 class WrenchMenu::ZoomView : public WrenchMenuView {
484 public content::NotificationObserver {
485 public: 484 public:
486 ZoomView(WrenchMenu* menu, 485 ZoomView(WrenchMenu* menu,
487 MenuModel* menu_model, 486 MenuModel* menu_model,
488 int decrement_index, 487 int decrement_index,
489 int increment_index, 488 int increment_index,
490 int fullscreen_index) 489 int fullscreen_index)
491 : WrenchMenuView(menu, menu_model), 490 : WrenchMenuView(menu, menu_model),
492 fullscreen_index_(fullscreen_index), 491 fullscreen_index_(fullscreen_index),
492 zoom_callback_(base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged,
493 base::Unretained(this))),
493 increment_button_(NULL), 494 increment_button_(NULL),
494 zoom_label_(NULL), 495 zoom_label_(NULL),
495 decrement_button_(NULL), 496 decrement_button_(NULL),
496 fullscreen_button_(NULL), 497 fullscreen_button_(NULL),
497 zoom_label_width_(0) { 498 zoom_label_width_(0) {
499 HostZoomMap::GetForBrowserContext(
500 menu_->browser_->profile())->AddZoomLevelChangedCallback(
501 zoom_callback_);
502
498 decrement_button_ = CreateButtonWithAccName( 503 decrement_button_ = CreateButtonWithAccName(
499 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, 504 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index,
500 NULL, IDS_ACCNAME_ZOOM_MINUS2); 505 NULL, IDS_ACCNAME_ZOOM_MINUS2);
501 506
502 zoom_label_ = new Label( 507 zoom_label_ = new Label(
503 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); 508 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
504 zoom_label_->SetAutoColorReadabilityEnabled(false); 509 zoom_label_->SetAutoColorReadabilityEnabled(false);
505 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 510 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
506 511
507 MenuButtonBackground* center_bg = new MenuButtonBackground( 512 MenuButtonBackground* center_bg = new MenuButtonBackground(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 0, horizontal_padding, 0, horizontal_padding)); 553 0, horizontal_padding, 0, horizontal_padding));
549 fullscreen_button_->set_background( 554 fullscreen_button_->set_background(
550 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON, 555 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON,
551 menu_->use_new_menu())); 556 menu_->use_new_menu()));
552 fullscreen_button_->SetAccessibleName( 557 fullscreen_button_->SetAccessibleName(
553 GetAccessibleNameForWrenchMenuItem( 558 GetAccessibleNameForWrenchMenuItem(
554 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); 559 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN));
555 AddChildView(fullscreen_button_); 560 AddChildView(fullscreen_button_);
556 561
557 UpdateZoomControls(); 562 UpdateZoomControls();
563 }
558 564
559 registrar_.Add( 565 ~ZoomView() {
560 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 566 HostZoomMap::GetForBrowserContext(
561 content::Source<HostZoomMap>( 567 menu_->browser_->profile())->RemoveZoomLevelChangedCallback(
562 HostZoomMap::GetForBrowserContext(menu->browser_->profile()))); 568 zoom_callback_);
563 } 569 }
564 570
565 // Overridden from View. 571 // Overridden from View.
566 virtual gfx::Size GetPreferredSize() OVERRIDE { 572 virtual gfx::Size GetPreferredSize() OVERRIDE {
567 // The increment/decrement button are forced to the same width. 573 // The increment/decrement button are forced to the same width.
568 int button_width = std::max(increment_button_->GetPreferredSize().width(), 574 int button_width = std::max(increment_button_->GetPreferredSize().width(),
569 decrement_button_->GetPreferredSize().width()); 575 decrement_button_->GetPreferredSize().width());
570 int zoom_padding = menu_->use_new_menu() ? kTouchZoomPadding : kZoomPadding; 576 int zoom_padding = menu_->use_new_menu() ? kTouchZoomPadding : kZoomPadding;
571 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() + 577 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() +
572 zoom_padding; 578 zoom_padding;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 virtual void ButtonPressed(views::Button* sender, 612 virtual void ButtonPressed(views::Button* sender,
607 const ui::Event& event) OVERRIDE { 613 const ui::Event& event) OVERRIDE {
608 if (sender->tag() == fullscreen_index_) { 614 if (sender->tag() == fullscreen_index_) {
609 menu_->CancelAndEvaluate(menu_model_, sender->tag()); 615 menu_->CancelAndEvaluate(menu_model_, sender->tag());
610 } else { 616 } else {
611 // Zoom buttons don't close the menu. 617 // Zoom buttons don't close the menu.
612 menu_model_->ActivatedAt(sender->tag()); 618 menu_model_->ActivatedAt(sender->tag());
613 } 619 }
614 } 620 }
615 621
616 // Overridden from content::NotificationObserver. 622 private:
617 virtual void Observe(int type, 623 void OnZoomLevelChanged(const std::string& host) {
618 const content::NotificationSource& source,
619 const content::NotificationDetails& details) OVERRIDE {
620 DCHECK_EQ(content::NOTIFICATION_ZOOM_LEVEL_CHANGED, type);
621 UpdateZoomControls(); 624 UpdateZoomControls();
622 } 625 }
623 626
624 private:
625 void UpdateZoomControls() { 627 void UpdateZoomControls() {
626 bool enable_increment = false; 628 bool enable_increment = false;
627 bool enable_decrement = false; 629 bool enable_decrement = false;
628 WebContents* selected_tab = 630 WebContents* selected_tab =
629 menu_->browser_->tab_strip_model()->GetActiveWebContents(); 631 menu_->browser_->tab_strip_model()->GetActiveWebContents();
630 int zoom = 100; 632 int zoom = 100;
631 if (selected_tab) 633 if (selected_tab)
632 zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement); 634 zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement);
633 increment_button_->SetEnabled(enable_increment); 635 increment_button_->SetEnabled(enable_increment);
634 decrement_button_->SetEnabled(enable_decrement); 636 decrement_button_->SetEnabled(enable_decrement);
(...skipping 27 matching lines...) Expand all
662 max_w = font.GetStringWidth( 664 max_w = font.GetStringWidth(
663 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); 665 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
664 } 666 }
665 667
666 return max_w + border_width; 668 return max_w + border_width;
667 } 669 }
668 670
669 // Index of the fullscreen menu item in the model. 671 // Index of the fullscreen menu item in the model.
670 const int fullscreen_index_; 672 const int fullscreen_index_;
671 673
674 content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_;
672 content::NotificationRegistrar registrar_; 675 content::NotificationRegistrar registrar_;
673 676
674 // Button for incrementing the zoom. 677 // Button for incrementing the zoom.
675 TextButton* increment_button_; 678 TextButton* increment_button_;
676 679
677 // Label showing zoom as a percent. 680 // Label showing zoom as a percent.
678 Label* zoom_label_; 681 Label* zoom_label_;
679 682
680 // Button for decrementing the zoom. 683 // Button for decrementing the zoom.
681 TextButton* decrement_button_; 684 TextButton* decrement_button_;
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 bookmark_menu_delegate_.reset( 1133 bookmark_menu_delegate_.reset(
1131 new BookmarkMenuDelegate(browser_, 1134 new BookmarkMenuDelegate(browser_,
1132 browser_, 1135 browser_,
1133 parent, 1136 parent,
1134 first_bookmark_command_id_)); 1137 first_bookmark_command_id_));
1135 bookmark_menu_delegate_->Init( 1138 bookmark_menu_delegate_->Init(
1136 this, bookmark_menu_, model->bookmark_bar_node(), 0, 1139 this, bookmark_menu_, model->bookmark_bar_node(), 0,
1137 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1140 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1138 bookmark_utils::LAUNCH_WRENCH_MENU); 1141 bookmark_utils::LAUNCH_WRENCH_MENU);
1139 } 1142 }
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