| 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" |
| 25 #include "components/bookmarks/browser/bookmark_model.h" | 26 #include "components/bookmarks/browser/bookmark_model.h" |
| 26 #include "content/public/browser/host_zoom_map.h" | 27 #include "content/public/browser/host_zoom_map.h" |
| 27 #include "content/public/browser/notification_observer.h" | 28 #include "content/public/browser/notification_observer.h" |
| 28 #include "content/public/browser/notification_registrar.h" | 29 #include "content/public/browser/notification_registrar.h" |
| 29 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
| 30 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
| 31 #include "content/public/browser/user_metrics.h" | 32 #include "content/public/browser/user_metrics.h" |
| 32 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 33 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
| 34 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 virtual void WrenchMenuDestroyed() OVERRIDE { | 745 virtual void WrenchMenuDestroyed() OVERRIDE { |
| 745 WrenchMenuView::WrenchMenuDestroyed(); | 746 WrenchMenuView::WrenchMenuDestroyed(); |
| 746 } | 747 } |
| 747 | 748 |
| 748 private: | 749 private: |
| 749 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { | 750 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { |
| 750 UpdateZoomControls(); | 751 UpdateZoomControls(); |
| 751 } | 752 } |
| 752 | 753 |
| 753 void UpdateZoomControls() { | 754 void UpdateZoomControls() { |
| 754 bool enable_increment = false; | |
| 755 bool enable_decrement = false; | |
| 756 WebContents* selected_tab = | 755 WebContents* selected_tab = |
| 757 menu()->browser_->tab_strip_model()->GetActiveWebContents(); | 756 menu()->browser_->tab_strip_model()->GetActiveWebContents(); |
| 758 int zoom = 100; | 757 int zoom = 100; |
| 759 if (selected_tab) | 758 if (selected_tab) { |
| 760 zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement); | 759 zoom = ZoomController::FromWebContents(selected_tab)->GetZoomPercent(); |
| 761 increment_button_->SetEnabled(enable_increment); | 760 } |
| 762 decrement_button_->SetEnabled(enable_decrement); | 761 increment_button_->SetEnabled(zoom < selected_tab->GetMaximumZoomPercent()); |
| 762 decrement_button_->SetEnabled(zoom > selected_tab->GetMinimumZoomPercent()); |
| 763 zoom_label_->SetText( | 763 zoom_label_->SetText( |
| 764 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); | 764 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); |
| 765 | 765 |
| 766 zoom_label_width_ = MaxWidthForZoomLabel(); | 766 zoom_label_width_ = MaxWidthForZoomLabel(); |
| 767 } | 767 } |
| 768 | 768 |
| 769 // Calculates the max width the zoom string can be. | 769 // Calculates the max width the zoom string can be. |
| 770 int MaxWidthForZoomLabel() { | 770 int MaxWidthForZoomLabel() { |
| 771 const gfx::FontList& font_list = zoom_label_->font_list(); | 771 const gfx::FontList& font_list = zoom_label_->font_list(); |
| 772 int border_width = | 772 int border_width = |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 0, | 1362 0, |
| 1363 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1363 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1364 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); | 1364 BOOKMARK_LAUNCH_LOCATION_WRENCH_MENU); |
| 1365 } | 1365 } |
| 1366 | 1366 |
| 1367 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { | 1367 int WrenchMenu::ModelIndexFromCommandId(int command_id) const { |
| 1368 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1368 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
| 1369 DCHECK(ix != command_id_to_entry_.end()); | 1369 DCHECK(ix != command_id_to_entry_.end()); |
| 1370 return ix->second.second; | 1370 return ix->second.second; |
| 1371 } | 1371 } |
| OLD | NEW |