OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/app_menu.h" | 5 #include "chrome/browser/ui/views/toolbar/app_menu.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
26 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
28 #include "chrome/browser/ui/toolbar/app_menu_model.h" | 28 #include "chrome/browser/ui/toolbar/app_menu_model.h" |
29 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" | 29 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" |
30 #include "chrome/browser/ui/views/toolbar/app_menu_observer.h" | 30 #include "chrome/browser/ui/views/toolbar/app_menu_observer.h" |
31 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" | 31 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" |
32 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
33 #include "components/bookmarks/browser/bookmark_model.h" | 33 #include "components/bookmarks/browser/bookmark_model.h" |
34 #include "components/ui/zoom/page_zoom.h" | 34 #include "components/zoom/page_zoom.h" |
35 #include "components/ui/zoom/zoom_controller.h" | 35 #include "components/zoom/zoom_controller.h" |
36 #include "components/ui/zoom/zoom_event_manager.h" | 36 #include "components/zoom/zoom_event_manager.h" |
37 #include "content/public/browser/host_zoom_map.h" | 37 #include "content/public/browser/host_zoom_map.h" |
38 #include "content/public/browser/notification_observer.h" | 38 #include "content/public/browser/notification_observer.h" |
39 #include "content/public/browser/notification_registrar.h" | 39 #include "content/public/browser/notification_registrar.h" |
40 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.h" |
41 #include "content/public/browser/notification_types.h" | 41 #include "content/public/browser/notification_types.h" |
42 #include "content/public/browser/user_metrics.h" | 42 #include "content/public/browser/user_metrics.h" |
43 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
44 #include "extensions/common/feature_switch.h" | 44 #include "extensions/common/feature_switch.h" |
45 #include "grit/theme_resources.h" | 45 #include "grit/theme_resources.h" |
46 #include "third_party/skia/include/core/SkCanvas.h" | 46 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 int fullscreen_index) | 483 int fullscreen_index) |
484 : AppMenuView(menu, menu_model), | 484 : AppMenuView(menu, menu_model), |
485 fullscreen_index_(fullscreen_index), | 485 fullscreen_index_(fullscreen_index), |
486 increment_button_(NULL), | 486 increment_button_(NULL), |
487 zoom_label_(NULL), | 487 zoom_label_(NULL), |
488 decrement_button_(NULL), | 488 decrement_button_(NULL), |
489 fullscreen_button_(NULL), | 489 fullscreen_button_(NULL), |
490 zoom_label_max_width_(0), | 490 zoom_label_max_width_(0), |
491 zoom_label_max_width_valid_(false) { | 491 zoom_label_max_width_valid_(false) { |
492 browser_zoom_subscription_ = | 492 browser_zoom_subscription_ = |
493 ui_zoom::ZoomEventManager::GetForBrowserContext( | 493 zoom::ZoomEventManager::GetForBrowserContext(menu->browser_->profile()) |
494 menu->browser_->profile()) | |
495 ->AddZoomLevelChangedCallback( | 494 ->AddZoomLevelChangedCallback( |
496 base::Bind(&AppMenu::ZoomView::OnZoomLevelChanged, | 495 base::Bind(&AppMenu::ZoomView::OnZoomLevelChanged, |
497 base::Unretained(this))); | 496 base::Unretained(this))); |
498 | 497 |
499 decrement_button_ = CreateButtonWithAccName( | 498 decrement_button_ = CreateButtonWithAccName( |
500 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEADING_BORDER, | 499 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEADING_BORDER, |
501 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); | 500 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); |
502 | 501 |
503 zoom_label_ = new Label(base::FormatPercent(100)); | 502 zoom_label_ = new Label(base::FormatPercent(100)); |
504 zoom_label_->SetAutoColorReadabilityEnabled(false); | 503 zoom_label_->SetAutoColorReadabilityEnabled(false); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 } | 626 } |
628 | 627 |
629 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change) { | 628 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change) { |
630 UpdateZoomControls(); | 629 UpdateZoomControls(); |
631 } | 630 } |
632 | 631 |
633 void UpdateZoomControls() { | 632 void UpdateZoomControls() { |
634 WebContents* contents = GetActiveWebContents(); | 633 WebContents* contents = GetActiveWebContents(); |
635 int zoom = 100; | 634 int zoom = 100; |
636 if (contents) { | 635 if (contents) { |
637 auto zoom_controller = | 636 auto zoom_controller = zoom::ZoomController::FromWebContents(contents); |
638 ui_zoom::ZoomController::FromWebContents(contents); | |
639 if (zoom_controller) | 637 if (zoom_controller) |
640 zoom = zoom_controller->GetZoomPercent(); | 638 zoom = zoom_controller->GetZoomPercent(); |
641 increment_button_->SetEnabled(zoom < | 639 increment_button_->SetEnabled(zoom < |
642 contents->GetMaximumZoomPercent()); | 640 contents->GetMaximumZoomPercent()); |
643 decrement_button_->SetEnabled(zoom > | 641 decrement_button_->SetEnabled(zoom > |
644 contents->GetMinimumZoomPercent()); | 642 contents->GetMinimumZoomPercent()); |
645 } | 643 } |
646 zoom_label_->SetText(base::FormatPercent(zoom)); | 644 zoom_label_->SetText(base::FormatPercent(zoom)); |
647 zoom_label_max_width_valid_ = false; | 645 zoom_label_max_width_valid_ = false; |
648 } | 646 } |
649 | 647 |
650 // Returns the max width the zoom string can be. | 648 // Returns the max width the zoom string can be. |
651 int ZoomLabelMaxWidth() const { | 649 int ZoomLabelMaxWidth() const { |
652 if (!zoom_label_max_width_valid_) { | 650 if (!zoom_label_max_width_valid_) { |
653 const gfx::FontList& font_list = zoom_label_->font_list(); | 651 const gfx::FontList& font_list = zoom_label_->font_list(); |
654 int border_width = zoom_label_->border() | 652 int border_width = zoom_label_->border() |
655 ? zoom_label_->border()->GetInsets().width() | 653 ? zoom_label_->border()->GetInsets().width() |
656 : 0; | 654 : 0; |
657 | 655 |
658 int max_w = 0; | 656 int max_w = 0; |
659 | 657 |
660 WebContents* selected_tab = GetActiveWebContents(); | 658 WebContents* selected_tab = GetActiveWebContents(); |
661 if (selected_tab) { | 659 if (selected_tab) { |
662 auto zoom_controller = | 660 auto zoom_controller = |
663 ui_zoom::ZoomController::FromWebContents(selected_tab); | 661 zoom::ZoomController::FromWebContents(selected_tab); |
664 DCHECK(zoom_controller); | 662 DCHECK(zoom_controller); |
665 // Enumerate all zoom factors that can be used in PageZoom::Zoom. | 663 // Enumerate all zoom factors that can be used in PageZoom::Zoom. |
666 std::vector<double> zoom_factors = ui_zoom::PageZoom::PresetZoomFactors( | 664 std::vector<double> zoom_factors = zoom::PageZoom::PresetZoomFactors( |
667 zoom_controller->GetZoomPercent()); | 665 zoom_controller->GetZoomPercent()); |
668 for (auto zoom : zoom_factors) { | 666 for (auto zoom : zoom_factors) { |
669 int w = gfx::GetStringWidth( | 667 int w = gfx::GetStringWidth( |
670 base::FormatPercent(static_cast<int>(std::round(zoom * 100))), | 668 base::FormatPercent(static_cast<int>(std::round(zoom * 100))), |
671 font_list); | 669 font_list); |
672 max_w = std::max(w, max_w); | 670 max_w = std::max(w, max_w); |
673 } | 671 } |
674 } else { | 672 } else { |
675 max_w = gfx::GetStringWidth(base::FormatPercent(100), font_list); | 673 max_w = gfx::GetStringWidth(base::FormatPercent(100), font_list); |
676 } | 674 } |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 0, | 1255 0, |
1258 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1256 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1259 BOOKMARK_LAUNCH_LOCATION_APP_MENU); | 1257 BOOKMARK_LAUNCH_LOCATION_APP_MENU); |
1260 } | 1258 } |
1261 | 1259 |
1262 int AppMenu::ModelIndexFromCommandId(int command_id) const { | 1260 int AppMenu::ModelIndexFromCommandId(int command_id) const { |
1263 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1261 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1264 DCHECK(ix != command_id_to_entry_.end()); | 1262 DCHECK(ix != command_id_to_entry_.end()); |
1265 return ix->second.second; | 1263 return ix->second.second; |
1266 } | 1264 } |
OLD | NEW |