Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/toolbar/wrench_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "chrome/browser/ui/browser_commands.h" | 26 #include "chrome/browser/ui/browser_commands.h" |
| 27 #include "chrome/browser/ui/browser_finder.h" | 27 #include "chrome/browser/ui/browser_finder.h" |
| 28 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 29 #include "chrome/browser/ui/global_error/global_error.h" | 29 #include "chrome/browser/ui/global_error/global_error.h" |
| 30 #include "chrome/browser/ui/global_error/global_error_service.h" | 30 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 31 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 31 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 33 #include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h" | 33 #include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h" |
| 34 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 34 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
| 35 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" | 35 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
| 36 #include "chrome/browser/ui/zoom/zoom_controller.h" | |
| 37 #include "chrome/browser/ui/zoom/zoom_event_manager.h" | |
| 36 #include "chrome/browser/upgrade_detector.h" | 38 #include "chrome/browser/upgrade_detector.h" |
| 37 #include "chrome/common/chrome_paths.h" | 39 #include "chrome/common/chrome_paths.h" |
| 38 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
| 39 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/common/profiling.h" | 42 #include "chrome/common/profiling.h" |
| 41 #include "components/signin/core/browser/signin_manager.h" | 43 #include "components/signin/core/browser/signin_manager.h" |
| 42 #include "components/signin/core/common/profile_management_switches.h" | 44 #include "components/signin/core/common/profile_management_switches.h" |
| 43 #include "content/public/browser/host_zoom_map.h" | 45 #include "content/public/browser/host_zoom_map.h" |
| 44 #include "content/public/browser/navigation_entry.h" | 46 #include "content/public/browser/navigation_entry.h" |
| 45 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, | 277 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, |
| 276 Browser* browser, | 278 Browser* browser, |
| 277 bool is_new_menu) | 279 bool is_new_menu) |
| 278 : ui::SimpleMenuModel(this), | 280 : ui::SimpleMenuModel(this), |
| 279 provider_(provider), | 281 provider_(provider), |
| 280 browser_(browser), | 282 browser_(browser), |
| 281 tab_strip_model_(browser_->tab_strip_model()) { | 283 tab_strip_model_(browser_->tab_strip_model()) { |
| 282 Build(is_new_menu); | 284 Build(is_new_menu); |
| 283 UpdateZoomControls(); | 285 UpdateZoomControls(); |
| 284 | 286 |
| 285 zoom_subscription_ = HostZoomMap::GetForBrowserContext( | 287 content_zoom_subscription_ = content::HostZoomMap::GetForBrowserContext( |
| 286 browser->profile())->AddZoomLevelChangedCallback( | 288 browser->profile())->AddZoomLevelChangedCallback( |
| 287 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, | 289 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, |
| 288 base::Unretained(this))); | 290 base::Unretained(this))); |
| 291 | |
| 292 browser_zoom_subscription_ = ZoomEventManager::GetForBrowserContext( | |
| 293 browser->profile())->AddZoomLevelChangedCallback( | |
| 294 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, | |
| 295 base::Unretained(this))); | |
|
sky
2014/06/24 16:23:41
What is the difference between what this function
wjmaclean
2014/06/24 18:04:07
Nothing, except the source of the events. I origin
| |
| 289 | 296 |
| 290 tab_strip_model_->AddObserver(this); | 297 tab_strip_model_->AddObserver(this); |
| 291 | 298 |
| 292 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 299 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 293 content::NotificationService::AllSources()); | 300 content::NotificationService::AllSources()); |
| 294 } | 301 } |
| 295 | 302 |
| 296 WrenchMenuModel::~WrenchMenuModel() { | 303 WrenchMenuModel::~WrenchMenuModel() { |
| 297 if (tab_strip_model_) | 304 if (tab_strip_model_) |
| 298 tab_strip_model_->RemoveObserver(this); | 305 tab_strip_model_->RemoveObserver(this); |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 // you change the order you'll need to update wrench_menu as well. | 783 // you change the order you'll need to update wrench_menu as well. |
| 777 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); | 784 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); |
| 778 AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); | 785 AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); |
| 779 AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); | 786 AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); |
| 780 #endif | 787 #endif |
| 781 | 788 |
| 782 AddSeparator(new_menu ? ui::UPPER_SEPARATOR : ui::NORMAL_SEPARATOR); | 789 AddSeparator(new_menu ? ui::UPPER_SEPARATOR : ui::NORMAL_SEPARATOR); |
| 783 } | 790 } |
| 784 | 791 |
| 785 void WrenchMenuModel::UpdateZoomControls() { | 792 void WrenchMenuModel::UpdateZoomControls() { |
| 786 bool enable_increment = false; | |
| 787 bool enable_decrement = false; | |
| 788 int zoom_percent = 100; | 793 int zoom_percent = 100; |
| 789 if (browser_->tab_strip_model()->GetActiveWebContents()) { | 794 if (browser_->tab_strip_model()->GetActiveWebContents()) { |
| 790 zoom_percent = | 795 zoom_percent = ZoomController::FromWebContents( |
| 791 browser_->tab_strip_model()->GetActiveWebContents()->GetZoomPercent( | 796 browser_->tab_strip_model()->GetActiveWebContents()) |
| 792 &enable_increment, &enable_decrement); | 797 ->GetZoomPercent(); |
| 793 } | 798 } |
| 794 zoom_label_ = l10n_util::GetStringFUTF16( | 799 zoom_label_ = l10n_util::GetStringFUTF16( |
| 795 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 800 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
| 796 } | 801 } |
| 797 | 802 |
| 798 void WrenchMenuModel::OnZoomLevelChanged( | 803 void WrenchMenuModel::OnZoomLevelChanged( |
| 799 const content::HostZoomMap::ZoomLevelChange& change) { | 804 const content::HostZoomMap::ZoomLevelChange& change) { |
| 800 UpdateZoomControls(); | 805 UpdateZoomControls(); |
| 801 } | 806 } |
| OLD | NEW |