| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 226 |
| 227 //////////////////////////////////////////////////////////////////////////////// | 227 //////////////////////////////////////////////////////////////////////////////// |
| 228 // WrenchMenuModel | 228 // WrenchMenuModel |
| 229 | 229 |
| 230 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, | 230 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, |
| 231 Browser* browser, | 231 Browser* browser, |
| 232 bool is_new_menu) | 232 bool is_new_menu) |
| 233 : ui::SimpleMenuModel(this), | 233 : ui::SimpleMenuModel(this), |
| 234 provider_(provider), | 234 provider_(provider), |
| 235 browser_(browser), | 235 browser_(browser), |
| 236 tab_strip_model_(browser_->tab_strip_model()), | 236 tab_strip_model_(browser_->tab_strip_model()) { |
| 237 zoom_callback_(base::Bind(&WrenchMenuModel::OnZoomLevelChanged, | |
| 238 base::Unretained(this))) { | |
| 239 Build(is_new_menu); | 237 Build(is_new_menu); |
| 240 UpdateZoomControls(); | 238 UpdateZoomControls(); |
| 241 | 239 |
| 242 HostZoomMap::GetForBrowserContext( | 240 zoom_subscription_ = HostZoomMap::GetForBrowserContext( |
| 243 browser->profile())->AddZoomLevelChangedCallback(zoom_callback_); | 241 browser->profile())->AddZoomLevelChangedCallback( |
| 242 base::Bind(&WrenchMenuModel::OnZoomLevelChanged, |
| 243 base::Unretained(this))); |
| 244 | 244 |
| 245 tab_strip_model_->AddObserver(this); | 245 tab_strip_model_->AddObserver(this); |
| 246 | 246 |
| 247 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 247 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 248 content::NotificationService::AllSources()); | 248 content::NotificationService::AllSources()); |
| 249 } | 249 } |
| 250 | 250 |
| 251 WrenchMenuModel::~WrenchMenuModel() { | 251 WrenchMenuModel::~WrenchMenuModel() { |
| 252 if (tab_strip_model_) | 252 if (tab_strip_model_) |
| 253 tab_strip_model_->RemoveObserver(this); | 253 tab_strip_model_->RemoveObserver(this); |
| 254 | |
| 255 if (browser()) { | |
| 256 HostZoomMap::GetForBrowserContext( | |
| 257 browser()->profile())->RemoveZoomLevelChangedCallback(zoom_callback_); | |
| 258 } | |
| 259 } | 254 } |
| 260 | 255 |
| 261 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { | 256 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { |
| 262 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; | 257 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; |
| 263 } | 258 } |
| 264 | 259 |
| 265 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { | 260 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { |
| 266 return command_id == IDC_ZOOM_PERCENT_DISPLAY || | 261 return command_id == IDC_ZOOM_PERCENT_DISPLAY || |
| 267 #if defined(OS_MACOSX) | 262 #if defined(OS_MACOSX) |
| 268 command_id == IDC_FULLSCREEN || | 263 command_id == IDC_FULLSCREEN || |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 &enable_increment, &enable_decrement); | 754 &enable_increment, &enable_decrement); |
| 760 } | 755 } |
| 761 zoom_label_ = l10n_util::GetStringFUTF16( | 756 zoom_label_ = l10n_util::GetStringFUTF16( |
| 762 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 757 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
| 763 } | 758 } |
| 764 | 759 |
| 765 void WrenchMenuModel::OnZoomLevelChanged( | 760 void WrenchMenuModel::OnZoomLevelChanged( |
| 766 const content::HostZoomMap::ZoomLevelChange& change) { | 761 const content::HostZoomMap::ZoomLevelChange& change) { |
| 767 UpdateZoomControls(); | 762 UpdateZoomControls(); |
| 768 } | 763 } |
| OLD | NEW |