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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 473 |
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 { | |
485 public: | 484 public: |
486 ZoomView(WrenchMenu* menu, | 485 ZoomView(WrenchMenu* menu, |
487 MenuModel* menu_model, | 486 MenuModel* menu_model, |
488 int decrement_index, | 487 int decrement_index, |
489 int increment_index, | 488 int increment_index, |
490 int fullscreen_index) | 489 int fullscreen_index) |
491 : WrenchMenuView(menu, menu_model), | 490 : WrenchMenuView(menu, menu_model), |
492 fullscreen_index_(fullscreen_index), | 491 fullscreen_index_(fullscreen_index), |
493 increment_button_(NULL), | 492 increment_button_(NULL), |
494 zoom_label_(NULL), | 493 zoom_label_(NULL), |
495 decrement_button_(NULL), | 494 decrement_button_(NULL), |
496 fullscreen_button_(NULL), | 495 fullscreen_button_(NULL), |
497 zoom_label_width_(0) { | 496 zoom_label_width_(0) { |
| 497 HostZoomMap::GetForBrowserContext( |
| 498 menu_->browser_->profile())->AddZoomLevelChangedCallback( |
| 499 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, |
| 500 base::Unretained(this))); |
| 501 |
498 decrement_button_ = CreateButtonWithAccName( | 502 decrement_button_ = CreateButtonWithAccName( |
499 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, | 503 IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, |
500 NULL, IDS_ACCNAME_ZOOM_MINUS2); | 504 NULL, IDS_ACCNAME_ZOOM_MINUS2); |
501 | 505 |
502 zoom_label_ = new Label( | 506 zoom_label_ = new Label( |
503 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); | 507 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); |
504 zoom_label_->SetAutoColorReadabilityEnabled(false); | 508 zoom_label_->SetAutoColorReadabilityEnabled(false); |
505 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 509 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
506 | 510 |
507 MenuButtonBackground* center_bg = new MenuButtonBackground( | 511 MenuButtonBackground* center_bg = new MenuButtonBackground( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 0, horizontal_padding, 0, horizontal_padding)); | 552 0, horizontal_padding, 0, horizontal_padding)); |
549 fullscreen_button_->set_background( | 553 fullscreen_button_->set_background( |
550 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON, | 554 new MenuButtonBackground(MenuButtonBackground::SINGLE_BUTTON, |
551 menu_->use_new_menu())); | 555 menu_->use_new_menu())); |
552 fullscreen_button_->SetAccessibleName( | 556 fullscreen_button_->SetAccessibleName( |
553 GetAccessibleNameForWrenchMenuItem( | 557 GetAccessibleNameForWrenchMenuItem( |
554 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); | 558 menu_model, fullscreen_index, IDS_ACCNAME_FULLSCREEN)); |
555 AddChildView(fullscreen_button_); | 559 AddChildView(fullscreen_button_); |
556 | 560 |
557 UpdateZoomControls(); | 561 UpdateZoomControls(); |
| 562 } |
558 | 563 |
559 registrar_.Add( | 564 ~ZoomView() { |
560 this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | 565 HostZoomMap::GetForBrowserContext( |
561 content::Source<HostZoomMap>( | 566 menu_->browser_->profile())->AddZoomLevelChangedCallback( |
562 HostZoomMap::GetForBrowserContext(menu->browser_->profile()))); | 567 base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, |
| 568 base::Unretained(this))); |
563 } | 569 } |
564 | 570 |
565 // Overridden from View. | 571 // Overridden from View. |
566 virtual gfx::Size GetPreferredSize() OVERRIDE { | 572 virtual gfx::Size GetPreferredSize() OVERRIDE { |
567 // The increment/decrement button are forced to the same width. | 573 // The increment/decrement button are forced to the same width. |
568 int button_width = std::max(increment_button_->GetPreferredSize().width(), | 574 int button_width = std::max(increment_button_->GetPreferredSize().width(), |
569 decrement_button_->GetPreferredSize().width()); | 575 decrement_button_->GetPreferredSize().width()); |
570 int zoom_padding = menu_->use_new_menu() ? kTouchZoomPadding : kZoomPadding; | 576 int zoom_padding = menu_->use_new_menu() ? kTouchZoomPadding : kZoomPadding; |
571 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() + | 577 int fullscreen_width = fullscreen_button_->GetPreferredSize().width() + |
572 zoom_padding; | 578 zoom_padding; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 virtual void ButtonPressed(views::Button* sender, | 612 virtual void ButtonPressed(views::Button* sender, |
607 const ui::Event& event) OVERRIDE { | 613 const ui::Event& event) OVERRIDE { |
608 if (sender->tag() == fullscreen_index_) { | 614 if (sender->tag() == fullscreen_index_) { |
609 menu_->CancelAndEvaluate(menu_model_, sender->tag()); | 615 menu_->CancelAndEvaluate(menu_model_, sender->tag()); |
610 } else { | 616 } else { |
611 // Zoom buttons don't close the menu. | 617 // Zoom buttons don't close the menu. |
612 menu_model_->ActivatedAt(sender->tag()); | 618 menu_model_->ActivatedAt(sender->tag()); |
613 } | 619 } |
614 } | 620 } |
615 | 621 |
616 // Overridden from content::NotificationObserver. | 622 void OnZoomLevelChanged(const std::string& host) { |
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(); | 623 UpdateZoomControls(); |
622 } | 624 } |
623 | 625 |
624 private: | 626 private: |
625 void UpdateZoomControls() { | 627 void UpdateZoomControls() { |
626 bool enable_increment = false; | 628 bool enable_increment = false; |
627 bool enable_decrement = false; | 629 bool enable_decrement = false; |
628 WebContents* selected_tab = chrome::GetActiveWebContents(menu_->browser_); | 630 WebContents* selected_tab = chrome::GetActiveWebContents(menu_->browser_); |
629 int zoom = 100; | 631 int zoom = 100; |
630 if (selected_tab) | 632 if (selected_tab) |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 bookmark_menu_delegate_.reset( | 1130 bookmark_menu_delegate_.reset( |
1129 new BookmarkMenuDelegate(browser_, | 1131 new BookmarkMenuDelegate(browser_, |
1130 browser_, | 1132 browser_, |
1131 parent, | 1133 parent, |
1132 first_bookmark_command_id_)); | 1134 first_bookmark_command_id_)); |
1133 bookmark_menu_delegate_->Init( | 1135 bookmark_menu_delegate_->Init( |
1134 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 1136 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
1135 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1137 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1136 bookmark_utils::LAUNCH_WRENCH_MENU); | 1138 bookmark_utils::LAUNCH_WRENCH_MENU); |
1137 } | 1139 } |
OLD | NEW |