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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
206 // WrenchMenuModel | 206 // WrenchMenuModel |
207 | 207 |
208 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, | 208 WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, |
209 Browser* browser, | 209 Browser* browser, |
210 bool is_new_menu, | 210 bool is_new_menu, |
211 bool supports_new_separators) | 211 bool supports_new_separators) |
212 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 212 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
213 provider_(provider), | 213 provider_(provider), |
214 browser_(browser), | 214 browser_(browser), |
215 tab_strip_model_(browser_->tab_strip_model()) { | 215 tab_strip_model_(browser_->tab_strip_model()), |
| 216 zoom_callback_(base::Bind(&WrenchMenuModel::OnZoomLevelChanged, |
| 217 base::Unretained(this))) { |
216 Build(is_new_menu, supports_new_separators); | 218 Build(is_new_menu, supports_new_separators); |
217 UpdateZoomControls(); | 219 UpdateZoomControls(); |
218 | 220 |
| 221 HostZoomMap::GetForBrowserContext( |
| 222 browser->profile())->AddZoomLevelChangedCallback(zoom_callback_); |
| 223 |
219 tab_strip_model_->AddObserver(this); | 224 tab_strip_model_->AddObserver(this); |
220 | 225 |
221 registrar_.Add( | |
222 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
223 content::Source<HostZoomMap>( | |
224 HostZoomMap::GetForBrowserContext(browser_->profile()))); | |
225 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 226 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
226 content::NotificationService::AllSources()); | 227 content::NotificationService::AllSources()); |
227 } | 228 } |
228 | 229 |
229 WrenchMenuModel::~WrenchMenuModel() { | 230 WrenchMenuModel::~WrenchMenuModel() { |
230 if (tab_strip_model_) | 231 if (tab_strip_model_) |
231 tab_strip_model_->RemoveObserver(this); | 232 tab_strip_model_->RemoveObserver(this); |
| 233 |
| 234 if (browser()) { |
| 235 HostZoomMap::GetForBrowserContext( |
| 236 browser()->profile())->RemoveZoomLevelChangedCallback(zoom_callback_); |
| 237 } |
232 } | 238 } |
233 | 239 |
234 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { | 240 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { |
235 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; | 241 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; |
236 } | 242 } |
237 | 243 |
238 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { | 244 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { |
239 return command_id == IDC_ZOOM_PERCENT_DISPLAY || | 245 return command_id == IDC_ZOOM_PERCENT_DISPLAY || |
240 #if defined(OS_MACOSX) | 246 #if defined(OS_MACOSX) |
241 command_id == IDC_FULLSCREEN || | 247 command_id == IDC_FULLSCREEN || |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 void WrenchMenuModel::TabStripModelDeleted() { | 420 void WrenchMenuModel::TabStripModelDeleted() { |
415 // During views shutdown, the tabstrip model/browser is deleted first, while | 421 // During views shutdown, the tabstrip model/browser is deleted first, while |
416 // it is the opposite in gtk land. | 422 // it is the opposite in gtk land. |
417 tab_strip_model_->RemoveObserver(this); | 423 tab_strip_model_->RemoveObserver(this); |
418 tab_strip_model_ = NULL; | 424 tab_strip_model_ = NULL; |
419 } | 425 } |
420 | 426 |
421 void WrenchMenuModel::Observe(int type, | 427 void WrenchMenuModel::Observe(int type, |
422 const content::NotificationSource& source, | 428 const content::NotificationSource& source, |
423 const content::NotificationDetails& details) { | 429 const content::NotificationDetails& details) { |
424 switch (type) { | 430 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
425 case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: | 431 UpdateZoomControls(); |
426 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | |
427 UpdateZoomControls(); | |
428 break; | |
429 default: | |
430 NOTREACHED(); | |
431 } | |
432 } | 432 } |
433 | 433 |
434 // For testing. | 434 // For testing. |
435 WrenchMenuModel::WrenchMenuModel() | 435 WrenchMenuModel::WrenchMenuModel() |
436 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 436 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
437 provider_(NULL), | 437 provider_(NULL), |
438 browser_(NULL), | 438 browser_(NULL), |
439 tab_strip_model_(NULL) { | 439 tab_strip_model_(NULL) { |
440 } | 440 } |
441 | 441 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 bool enable_decrement = false; | 690 bool enable_decrement = false; |
691 int zoom_percent = 100; | 691 int zoom_percent = 100; |
692 if (browser_->tab_strip_model()->GetActiveWebContents()) { | 692 if (browser_->tab_strip_model()->GetActiveWebContents()) { |
693 zoom_percent = | 693 zoom_percent = |
694 browser_->tab_strip_model()->GetActiveWebContents()->GetZoomPercent( | 694 browser_->tab_strip_model()->GetActiveWebContents()->GetZoomPercent( |
695 &enable_increment, &enable_decrement); | 695 &enable_increment, &enable_decrement); |
696 } | 696 } |
697 zoom_label_ = l10n_util::GetStringFUTF16( | 697 zoom_label_ = l10n_util::GetStringFUTF16( |
698 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 698 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
699 } | 699 } |
| 700 |
| 701 void WrenchMenuModel::OnZoomLevelChanged(const std::string& host) { |
| 702 UpdateZoomControls(); |
| 703 } |
OLD | NEW |