| 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/views/wrench_menu.h" | 5 #include "chrome/browser/ui/views/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 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // ZoomView -------------------------------------------------------------------- | 474 // ZoomView -------------------------------------------------------------------- |
| 475 | 475 |
| 476 // Padding between the increment buttons and the reset button. | 476 // Padding between the increment buttons and the reset button. |
| 477 static const int kZoomPadding = 6; | 477 static const int kZoomPadding = 6; |
| 478 static const int kTouchZoomPadding = 14; | 478 static const int kTouchZoomPadding = 14; |
| 479 | 479 |
| 480 // ZoomView contains the various zoom controls: two buttons to increase/decrease | 480 // ZoomView contains the various zoom controls: two buttons to increase/decrease |
| 481 // the zoom, a label showing the current zoom percent, and a button to go | 481 // the zoom, a label showing the current zoom percent, and a button to go |
| 482 // full-screen. | 482 // full-screen. |
| 483 class WrenchMenu::ZoomView : public WrenchMenuView, | 483 class WrenchMenu::ZoomView : public WrenchMenuView, |
| 484 public content::NotificationObserver { | 484 public content::HostZoomMap::Observer { |
| 485 public: | 485 public: |
| 486 ZoomView(WrenchMenu* menu, | 486 ZoomView(WrenchMenu* menu, |
| 487 MenuModel* menu_model, | 487 MenuModel* menu_model, |
| 488 int decrement_index, | 488 int decrement_index, |
| 489 int increment_index, | 489 int increment_index, |
| 490 int fullscreen_index) | 490 int fullscreen_index) |
| 491 : WrenchMenuView(menu, menu_model), | 491 : WrenchMenuView(menu, menu_model), |
| 492 content::HostZoomMap::Observer( |
| 493 HostZoomMap::GetForBrowserContext(menu->browser_->profile())), |
| 492 fullscreen_index_(fullscreen_index), | 494 fullscreen_index_(fullscreen_index), |
| 493 increment_button_(NULL), | 495 increment_button_(NULL), |
| 494 zoom_label_(NULL), | 496 zoom_label_(NULL), |
| 495 decrement_button_(NULL), | 497 decrement_button_(NULL), |
| 496 fullscreen_button_(NULL), | 498 fullscreen_button_(NULL), |
| 497 zoom_label_width_(0) { | 499 zoom_label_width_(0) { |
| 498 decrement_button_ = CreateButtonWithAccName( | 500 decrement_button_ = CreateButtonWithAccName( |
| 499 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, | 501 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, |
| 500 NULL, IDS_ACCNAME_ZOOM_MINUS2); | 502 NULL, IDS_ACCNAME_ZOOM_MINUS2); |
| 501 | 503 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 0, horizontal_padding, 0, horizontal_padding)); | 550 0, horizontal_padding, 0, horizontal_padding)); |
| 549 fullscreen_button_->set_background( | 551 fullscreen_button_->set_background( |
| 550 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON, | 552 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON, |
| 551 menu_->use_new_menu())); | 553 menu_->use_new_menu())); |
| 552 fullscreen_button_->SetAccessibleName( | 554 fullscreen_button_->SetAccessibleName( |
| 553 GetAccessibleNameForWrenchMenuItem( | 555 GetAccessibleNameForWrenchMenuItem( |
| 554 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); | 556 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); |
| 555 AddChildView(fullscreen_button_); | 557 AddChildView(fullscreen_button_); |
| 556 | 558 |
| 557 UpdateZoomControls(); | 559 UpdateZoomControls(); |
| 558 | |
| 559 registrar_.Add( | |
| 560 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
| 561 content::Source<HostZoomMap>( | |
| 562 HostZoomMap::GetForBrowserContext(menu->browser_->profile()))); | |
| 563 } | 560 } |
| 564 | 561 |
| 565 // Overridden from View. | 562 // Overridden from View. |
| 566 virtual gfx::Size GetPreferredSize() OVERRIDE { | 563 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 567 // The increment/decrement button are forced to the same width. | 564 // The increment/decrement button are forced to the same width. |
| 568 int button_width = std::max(increment_button_->GetPreferredSize().width(), | 565 int button_width = std::max(increment_button_->GetPreferredSize().width(), |
| 569 decrement_button_->GetPreferredSize().width()); | 566 decrement_button_->GetPreferredSize().width()); |
| 570 int zoom_padding = menu_->use_new_menu() ? kTouchZoomPadding : kZoomPadding; | 567 int zoom_padding = menu_->use_new_menu() ? kTouchZoomPadding : kZoomPadding; |
| 571 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() + | 568 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() + |
| 572 zoom_padding; | 569 zoom_padding; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 virtual void ButtonPressed(views::Button* sender, | 603 virtual void ButtonPressed(views::Button* sender, |
| 607 const ui::Event& event) OVERRIDE { | 604 const ui::Event& event) OVERRIDE { |
| 608 if (sender->tag() == fullscreen_index_) { | 605 if (sender->tag() == fullscreen_index_) { |
| 609 menu_->CancelAndEvaluate(menu_model_, sender->tag()); | 606 menu_->CancelAndEvaluate(menu_model_, sender->tag()); |
| 610 } else { | 607 } else { |
| 611 // Zoom buttons don't close the menu. | 608 // Zoom buttons don't close the menu. |
| 612 menu_model_->ActivatedAt(sender->tag()); | 609 menu_model_->ActivatedAt(sender->tag()); |
| 613 } | 610 } |
| 614 } | 611 } |
| 615 | 612 |
| 616 // Overridden from content::NotificationObserver. | 613 virtual void OnZoomLevelChanged(const std::string& host) OVERRIDE { |
| 617 virtual void Observe(int type, | |
| 618 const content::NotificationSource& source, | |
| 619 const content::NotificationDetails& details) OVERRIDE { | |
| 620 DCHECK_EQ(content::NOTIFICATION_ZOOM_LEVEL_CHANGED, type); | |
| 621 UpdateZoomControls(); | 614 UpdateZoomControls(); |
| 622 } | 615 } |
| 623 | 616 |
| 624 private: | 617 private: |
| 625 void UpdateZoomControls() { | 618 void UpdateZoomControls() { |
| 626 int zoom = 100; | 619 int zoom = 100; |
| 627 // Don't override initial states of increment and decrement buttons when | 620 // Don't override initial states of increment and decrement buttons when |
| 628 // instant extended API is enabled and mode is NTP; they are properly | 621 // instant extended API is enabled and mode is NTP; they are properly |
| 629 // updated in ToolbarView::ModeChanged() via CommandUpdater, and queried | 622 // updated in ToolbarView::ModeChanged() via CommandUpdater, and queried |
| 630 // via WrenchMenuModel::IsCommandIdEnabled() when the buttons were created | 623 // via WrenchMenuModel::IsCommandIdEnabled() when the buttons were created |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 bookmark_menu_delegate_.reset( | 1132 bookmark_menu_delegate_.reset( |
| 1140 new BookmarkMenuDelegate(browser_, | 1133 new BookmarkMenuDelegate(browser_, |
| 1141 browser_, | 1134 browser_, |
| 1142 parent, | 1135 parent, |
| 1143 first_bookmark_command_id_)); | 1136 first_bookmark_command_id_)); |
| 1144 bookmark_menu_delegate_->Init( | 1137 bookmark_menu_delegate_->Init( |
| 1145 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 1138 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
| 1146 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1139 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1147 bookmark_utils::LAUNCH_WRENCH_MENU); | 1140 bookmark_utils::LAUNCH_WRENCH_MENU); |
| 1148 } | 1141 } |
| OLD | NEW |