Chromium Code Reviews| 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/wrench_menu_observer.h" | 24 #include "chrome/browser/ui/views/toolbar/wrench_menu_observer.h" |
| 25 #include "chrome/browser/ui/zoom/zoom_controller.h" | |
| 26 #include "chrome/browser/ui/zoom/zoom_event_manager.h" | |
| 25 #include "components/bookmarks/browser/bookmark_model.h" | 27 #include "components/bookmarks/browser/bookmark_model.h" |
| 26 #include "content/public/browser/host_zoom_map.h" | 28 #include "content/public/browser/host_zoom_map.h" |
| 27 #include "content/public/browser/notification_observer.h" | 29 #include "content/public/browser/notification_observer.h" |
| 28 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
| 29 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
| 30 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
| 31 #include "content/public/browser/user_metrics.h" | 33 #include "content/public/browser/user_metrics.h" |
| 32 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 33 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
| 34 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| (...skipping 590 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 virtual void WrenchMenuDestroyed() OVERRIDE { | 785 virtual void WrenchMenuDestroyed() OVERRIDE { |
| 779 WrenchMenuView::WrenchMenuDestroyed(); | 786 WrenchMenuView::WrenchMenuDestroyed(); |
| 780 } | 787 } |
| 781 | 788 |
| 782 private: | 789 private: |
| 783 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { | 790 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { |
| 784 UpdateZoomControls(); | 791 UpdateZoomControls(); |
| 785 } | 792 } |
| 786 | 793 |
| 787 void UpdateZoomControls() { | 794 void UpdateZoomControls() { |
| 788 bool enable_increment = false; | |
| 789 bool enable_decrement = false; | |
| 790 WebContents* selected_tab = | 795 WebContents* selected_tab = |
| 791 menu()->browser_->tab_strip_model()->GetActiveWebContents(); | 796 menu()->browser_->tab_strip_model()->GetActiveWebContents(); |
| 792 int zoom = 100; | 797 int zoom = 100; |
| 793 if (selected_tab) | 798 if (selected_tab) { |
|
Devlin
2014/06/19 21:15:29
nit: no brackets around 1-line if statements
wjmaclean
2014/06/20 22:01:33
Done.
| |
| 794 zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement); | 799 zoom = ZoomController::FromWebContents(selected_tab)->GetZoomPercent(); |
| 795 increment_button_->SetEnabled(enable_increment); | 800 } |
| 796 decrement_button_->SetEnabled(enable_decrement); | 801 increment_button_->SetEnabled(zoom < selected_tab->GetMaximumZoomPercent()); |
| 802 decrement_button_->SetEnabled(zoom > selected_tab->GetMinimumZoomPercent()); | |
| 797 zoom_label_->SetText( | 803 zoom_label_->SetText( |
| 798 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); | 804 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); |
| 799 | 805 |
| 800 zoom_label_width_ = MaxWidthForZoomLabel(); | 806 zoom_label_width_ = MaxWidthForZoomLabel(); |
| 801 } | 807 } |
| 802 | 808 |
| 803 // Calculates the max width the zoom string can be. | 809 // Calculates the max width the zoom string can be. |
| 804 int MaxWidthForZoomLabel() { | 810 int MaxWidthForZoomLabel() { |
| 805 const gfx::FontList& font_list = zoom_label_->font_list(); | 811 const gfx::FontList& font_list = zoom_label_->font_list(); |
| 806 int border_width = | 812 int border_width = |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 824 max_w = gfx::GetStringWidth( | 830 max_w = gfx::GetStringWidth( |
| 825 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100), font_list); | 831 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100), font_list); |
| 826 } | 832 } |
| 827 | 833 |
| 828 return max_w + border_width; | 834 return max_w + border_width; |
| 829 } | 835 } |
| 830 | 836 |
| 831 // Index of the fullscreen menu item in the model. | 837 // Index of the fullscreen menu item in the model. |
| 832 const int fullscreen_index_; | 838 const int fullscreen_index_; |
| 833 | 839 |
| 834 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; | 840 scoped_ptr<content::HostZoomMap::Subscription> content_zoom_subscription_; |
| 841 scoped_ptr<content::HostZoomMap::Subscription> browser_zoom_subscription_; | |
| 835 content::NotificationRegistrar registrar_; | 842 content::NotificationRegistrar registrar_; |
| 836 | 843 |
| 837 // Button for incrementing the zoom. | 844 // Button for incrementing the zoom. |
| 838 LabelButton* increment_button_; | 845 LabelButton* increment_button_; |
| 839 | 846 |
| 840 // Label showing zoom as a percent. | 847 // Label showing zoom as a percent. |
| 841 Label* zoom_label_; | 848 Label* zoom_label_; |
| 842 | 849 |
| 843 // Button for decrementing the zoom. | 850 // Button for decrementing the zoom. |
| 844 LabelButton* decrement_button_; | 851 LabelButton* decrement_button_; |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1382 0, | 1389 0, |
| 1383 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1390 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1384 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1391 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
| 1385 } | 1392 } |
| 1386 | 1393 |
| 1387 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1394 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
| 1388 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1395 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
| 1389 DCHECK(ix != command_id_to_entry_.end()); | 1396 DCHECK(ix != command_id_to_entry_.end()); |
| 1390 return ix->second.second; | 1397 return ix->second.second; |
| 1391 } | 1398 } |
| OLD | NEW |