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 |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
15 #include "chrome/browser/bookmarks/bookmark_stats.h" | 15 #include "chrome/browser/bookmarks/bookmark_stats.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/search/search.h" | 18 #include "chrome/browser/search/search.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 22 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
23 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" | 23 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" |
24 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" | 24 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" |
25 #include "chrome/browser/ui/views/toolbar/wrench_menu_observer.h" | 25 #include "chrome/browser/ui/views/toolbar/wrench_menu_observer.h" |
| 26 #include "chrome/browser/ui/zoom/zoom_controller.h" |
| 27 #include "chrome/browser/ui/zoom/zoom_event_manager.h" |
26 #include "components/bookmarks/browser/bookmark_model.h" | 28 #include "components/bookmarks/browser/bookmark_model.h" |
27 #include "content/public/browser/host_zoom_map.h" | 29 #include "content/public/browser/host_zoom_map.h" |
28 #include "content/public/browser/notification_observer.h" | 30 #include "content/public/browser/notification_observer.h" |
29 #include "content/public/browser/notification_registrar.h" | 31 #include "content/public/browser/notification_registrar.h" |
30 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
31 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
32 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
33 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
34 #include "extensions/common/feature_switch.h" | 36 #include "extensions/common/feature_switch.h" |
35 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 int decrement_index, | 627 int decrement_index, |
626 int increment_index, | 628 int increment_index, |
627 int fullscreen_index) | 629 int fullscreen_index) |
628 : WrenchMenuView(menu, menu_model), | 630 : WrenchMenuView(menu, menu_model), |
629 fullscreen_index_(fullscreen_index), | 631 fullscreen_index_(fullscreen_index), |
630 increment_button_(NULL), | 632 increment_button_(NULL), |
631 zoom_label_(NULL), | 633 zoom_label_(NULL), |
632 decrement_button_(NULL), | 634 decrement_button_(NULL), |
633 fullscreen_button_(NULL), | 635 fullscreen_button_(NULL), |
634 zoom_label_width_(0) { | 636 zoom_label_width_(0) { |
635 zoom_subscription_ = HostZoomMap::GetForBrowserContext( | 637 content_zoom_subscription_ = HostZoomMap::GetForBrowserContext( |
636 menu->browser_->profile())->AddZoomLevelChangedCallback( | 638 menu->browser_->profile())->AddZoomLevelChangedCallback( |
637 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, | 639 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, |
638 base::Unretained(this))); | 640 base::Unretained(this))); |
| 641 |
| 642 browser_zoom_subscription_ = ZoomEventManager::GetForBrowserContext( |
| 643 menu->browser_->profile())->AddZoomLevelChangedCallback( |
| 644 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, |
| 645 base::Unretained(this))); |
639 | 646 |
640 decrement_button_ = CreateButtonWithAccName( | 647 decrement_button_ = CreateButtonWithAccName( |
641 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON, | 648 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON, |
642 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); | 649 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); |
643 | 650 |
644 zoom_label_ = new Label( | 651 zoom_label_ = new Label( |
645 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); | 652 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); |
646 zoom_label_->SetAutoColorReadabilityEnabled(false); | 653 zoom_label_->SetAutoColorReadabilityEnabled(false); |
647 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 654 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
648 | 655 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 virtual void WrenchMenuDestroyed() OVERRIDE { | 784 virtual void WrenchMenuDestroyed() OVERRIDE { |
778 WrenchMenuView::WrenchMenuDestroyed(); | 785 WrenchMenuView::WrenchMenuDestroyed(); |
779 } | 786 } |
780 | 787 |
781 private: | 788 private: |
782 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { | 789 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { |
783 UpdateZoomControls(); | 790 UpdateZoomControls(); |
784 } | 791 } |
785 | 792 |
786 void UpdateZoomControls() { | 793 void UpdateZoomControls() { |
787 bool enable_increment = false; | |
788 bool enable_decrement = false; | |
789 WebContents* selected_tab = | 794 WebContents* selected_tab = |
790 menu()->browser_->tab_strip_model()->GetActiveWebContents(); | 795 menu()->browser_->tab_strip_model()->GetActiveWebContents(); |
791 int zoom = 100; | 796 int zoom = 100; |
792 if (selected_tab) | 797 if (selected_tab) |
793 zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement); | 798 zoom = ZoomController::FromWebContents(selected_tab)->GetZoomPercent(); |
794 increment_button_->SetEnabled(enable_increment); | 799 increment_button_->SetEnabled(zoom < selected_tab->GetMaximumZoomPercent()); |
795 decrement_button_->SetEnabled(enable_decrement); | 800 decrement_button_->SetEnabled(zoom > selected_tab->GetMinimumZoomPercent()); |
796 zoom_label_->SetText( | 801 zoom_label_->SetText( |
797 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); | 802 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); |
798 | 803 |
799 zoom_label_width_ = MaxWidthForZoomLabel(); | 804 zoom_label_width_ = MaxWidthForZoomLabel(); |
800 } | 805 } |
801 | 806 |
802 // Calculates the max width the zoom string can be. | 807 // Calculates the max width the zoom string can be. |
803 int MaxWidthForZoomLabel() { | 808 int MaxWidthForZoomLabel() { |
804 const gfx::FontList& font_list = zoom_label_->font_list(); | 809 const gfx::FontList& font_list = zoom_label_->font_list(); |
805 int border_width = | 810 int border_width = |
(...skipping 17 matching lines...) Expand all Loading... |
823 max_w = gfx::GetStringWidth( | 828 max_w = gfx::GetStringWidth( |
824 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100), font_list); | 829 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100), font_list); |
825 } | 830 } |
826 | 831 |
827 return max_w + border_width; | 832 return max_w + border_width; |
828 } | 833 } |
829 | 834 |
830 // Index of the fullscreen menu item in the model. | 835 // Index of the fullscreen menu item in the model. |
831 const int fullscreen_index_; | 836 const int fullscreen_index_; |
832 | 837 |
833 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; | 838 scoped_ptr<content::HostZoomMap::Subscription> content_zoom_subscription_; |
| 839 scoped_ptr<content::HostZoomMap::Subscription> browser_zoom_subscription_; |
834 content::NotificationRegistrar registrar_; | 840 content::NotificationRegistrar registrar_; |
835 | 841 |
836 // Button for incrementing the zoom. | 842 // Button for incrementing the zoom. |
837 LabelButton* increment_button_; | 843 LabelButton* increment_button_; |
838 | 844 |
839 // Label showing zoom as a percent. | 845 // Label showing zoom as a percent. |
840 Label* zoom_label_; | 846 Label* zoom_label_; |
841 | 847 |
842 // Button for decrementing the zoom. | 848 // Button for decrementing the zoom. |
843 LabelButton* decrement_button_; | 849 LabelButton* decrement_button_; |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 0, | 1404 0, |
1399 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1405 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1400 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1406 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
1401 } | 1407 } |
1402 | 1408 |
1403 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1409 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
1404 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1410 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1405 DCHECK(ix != command_id_to_entry_.end()); | 1411 DCHECK(ix != command_id_to_entry_.end()); |
1406 return ix->second.second; | 1412 return ix->second.second; |
1407 } | 1413 } |
OLD | NEW |