| 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> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 20 #include "chrome/browser/bookmarks/bookmark_stats.h" | 20 #include "chrome/browser/bookmarks/bookmark_stats.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/search/search.h" | 23 #include "chrome/browser/search/search.h" |
| 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_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
| 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 27 #include "chrome/browser/ui/toolbar/app_menu_model.h" | 28 #include "chrome/browser/ui/toolbar/app_menu_model.h" |
| 28 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" | 29 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" |
| 29 #include "chrome/browser/ui/views/toolbar/app_menu_observer.h" | 30 #include "chrome/browser/ui/views/toolbar/app_menu_observer.h" |
| 30 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" | 31 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" |
| 31 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 32 #include "components/bookmarks/browser/bookmark_model.h" | 33 #include "components/bookmarks/browser/bookmark_model.h" |
| 33 #include "components/ui/zoom/page_zoom.h" | 34 #include "components/ui/zoom/page_zoom.h" |
| 34 #include "components/ui/zoom/zoom_controller.h" | 35 #include "components/ui/zoom/zoom_controller.h" |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 menu()->browser_->tab_strip_model()->GetActiveWebContents() : | 654 menu()->browser_->tab_strip_model()->GetActiveWebContents() : |
| 654 nullptr; | 655 nullptr; |
| 655 } | 656 } |
| 656 | 657 |
| 657 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change) { | 658 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change) { |
| 658 UpdateZoomControls(); | 659 UpdateZoomControls(); |
| 659 } | 660 } |
| 660 | 661 |
| 661 void UpdateZoomControls() { | 662 void UpdateZoomControls() { |
| 662 WebContents* selected_tab = GetActiveWebContents(); | 663 WebContents* selected_tab = GetActiveWebContents(); |
| 663 int zoom = 100; | 664 |
| 664 if (selected_tab) { | 665 increment_button_->SetEnabled(chrome::CanZoomIn(selected_tab)); |
| 665 auto zoom_controller = | 666 decrement_button_->SetEnabled(chrome::CanZoomOut(selected_tab)); |
| 666 ui_zoom::ZoomController::FromWebContents(selected_tab); | 667 zoom_label_->SetText(l10n_util::GetStringFUTF16Int( |
| 667 if (zoom_controller) | 668 IDS_ZOOM_PERCENT, chrome::GetZoomPercent(selected_tab))); |
| 668 zoom = zoom_controller->GetZoomPercent(); | |
| 669 increment_button_->SetEnabled(zoom < | |
| 670 selected_tab->GetMaximumZoomPercent()); | |
| 671 decrement_button_->SetEnabled(zoom > | |
| 672 selected_tab->GetMinimumZoomPercent()); | |
| 673 } | |
| 674 zoom_label_->SetText( | |
| 675 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); | |
| 676 | 669 |
| 677 zoom_label_max_width_valid_ = false; | 670 zoom_label_max_width_valid_ = false; |
| 678 } | 671 } |
| 679 | 672 |
| 680 // Returns the max width the zoom string can be. | 673 // Returns the max width the zoom string can be. |
| 681 int ZoomLabelMaxWidth() const { | 674 int ZoomLabelMaxWidth() const { |
| 682 if (!zoom_label_max_width_valid_) { | 675 if (!zoom_label_max_width_valid_) { |
| 683 const gfx::FontList& font_list = zoom_label_->font_list(); | 676 const gfx::FontList& font_list = zoom_label_->font_list(); |
| 684 int border_width = zoom_label_->border() | 677 int border_width = zoom_label_->border() |
| 685 ? zoom_label_->border()->GetInsets().width() | 678 ? zoom_label_->border()->GetInsets().width() |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 0, | 1282 0, |
| 1290 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1283 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
| 1291 BOOKMARK_LAUNCH_LOCATION_APP_MENU); | 1284 BOOKMARK_LAUNCH_LOCATION_APP_MENU); |
| 1292 } | 1285 } |
| 1293 | 1286 |
| 1294 int AppMenu::ModelIndexFromCommandId(int command_id) const { | 1287 int AppMenu::ModelIndexFromCommandId(int command_id) const { |
| 1295 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1288 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
| 1296 DCHECK(ix != command_id_to_entry_.end()); | 1289 DCHECK(ix != command_id_to_entry_.end()); |
| 1297 return ix->second.second; | 1290 return ix->second.second; |
| 1298 } | 1291 } |
| OLD | NEW |