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/i18n/number_formatting.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.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_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 ui_zoom::ZoomEventManager::GetForBrowserContext( | 531 ui_zoom::ZoomEventManager::GetForBrowserContext( |
532 menu->browser_->profile()) | 532 menu->browser_->profile()) |
533 ->AddZoomLevelChangedCallback( | 533 ->AddZoomLevelChangedCallback( |
534 base::Bind(&AppMenu::ZoomView::OnZoomLevelChanged, | 534 base::Bind(&AppMenu::ZoomView::OnZoomLevelChanged, |
535 base::Unretained(this))); | 535 base::Unretained(this))); |
536 | 536 |
537 decrement_button_ = CreateButtonWithAccName( | 537 decrement_button_ = CreateButtonWithAccName( |
538 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON, | 538 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON, |
539 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); | 539 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); |
540 | 540 |
541 zoom_label_ = new Label( | 541 zoom_label_ = new Label(base::FormatPercent(100)); |
542 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); | |
543 zoom_label_->SetAutoColorReadabilityEnabled(false); | 542 zoom_label_->SetAutoColorReadabilityEnabled(false); |
544 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 543 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
545 | 544 |
546 InMenuButtonBackground* center_bg = | 545 InMenuButtonBackground* center_bg = |
547 new InMenuButtonBackground(InMenuButtonBackground::RIGHT_BUTTON); | 546 new InMenuButtonBackground(InMenuButtonBackground::RIGHT_BUTTON); |
548 zoom_label_->set_background(center_bg); | 547 zoom_label_->set_background(center_bg); |
549 | 548 |
550 AddChildView(zoom_label_); | 549 AddChildView(zoom_label_); |
551 zoom_label_max_width_valid_ = false; | 550 zoom_label_max_width_valid_ = false; |
552 | 551 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 if (selected_tab) { | 676 if (selected_tab) { |
678 auto zoom_controller = | 677 auto zoom_controller = |
679 ui_zoom::ZoomController::FromWebContents(selected_tab); | 678 ui_zoom::ZoomController::FromWebContents(selected_tab); |
680 if (zoom_controller) | 679 if (zoom_controller) |
681 zoom = zoom_controller->GetZoomPercent(); | 680 zoom = zoom_controller->GetZoomPercent(); |
682 increment_button_->SetEnabled(zoom < | 681 increment_button_->SetEnabled(zoom < |
683 selected_tab->GetMaximumZoomPercent()); | 682 selected_tab->GetMaximumZoomPercent()); |
684 decrement_button_->SetEnabled(zoom > | 683 decrement_button_->SetEnabled(zoom > |
685 selected_tab->GetMinimumZoomPercent()); | 684 selected_tab->GetMinimumZoomPercent()); |
686 } | 685 } |
687 zoom_label_->SetText( | 686 zoom_label_->SetText(base::FormatPercent(zoom)); |
688 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); | |
689 | |
690 zoom_label_max_width_valid_ = false; | 687 zoom_label_max_width_valid_ = false; |
691 } | 688 } |
692 | 689 |
693 // Returns the max width the zoom string can be. | 690 // Returns the max width the zoom string can be. |
694 int ZoomLabelMaxWidth() const { | 691 int ZoomLabelMaxWidth() const { |
695 if (!zoom_label_max_width_valid_) { | 692 if (!zoom_label_max_width_valid_) { |
696 const gfx::FontList& font_list = zoom_label_->font_list(); | 693 const gfx::FontList& font_list = zoom_label_->font_list(); |
697 int border_width = zoom_label_->border() | 694 int border_width = zoom_label_->border() |
698 ? zoom_label_->border()->GetInsets().width() | 695 ? zoom_label_->border()->GetInsets().width() |
699 : 0; | 696 : 0; |
700 | 697 |
701 int max_w = 0; | 698 int max_w = 0; |
702 | 699 |
703 WebContents* selected_tab = GetActiveWebContents(); | 700 WebContents* selected_tab = GetActiveWebContents(); |
704 if (selected_tab) { | 701 if (selected_tab) { |
705 auto zoom_controller = | 702 auto zoom_controller = |
706 ui_zoom::ZoomController::FromWebContents(selected_tab); | 703 ui_zoom::ZoomController::FromWebContents(selected_tab); |
707 DCHECK(zoom_controller); | 704 DCHECK(zoom_controller); |
708 // Enumerate all zoom factors that can be used in PageZoom::Zoom. | 705 // Enumerate all zoom factors that can be used in PageZoom::Zoom. |
709 std::vector<double> zoom_factors = ui_zoom::PageZoom::PresetZoomFactors( | 706 std::vector<double> zoom_factors = ui_zoom::PageZoom::PresetZoomFactors( |
710 zoom_controller->GetZoomPercent()); | 707 zoom_controller->GetZoomPercent()); |
711 for (auto zoom : zoom_factors) { | 708 for (auto zoom : zoom_factors) { |
712 int w = gfx::GetStringWidth( | 709 int w = gfx::GetStringWidth( |
713 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, | 710 base::FormatPercent(static_cast<int>(std::round(zoom * 100))), |
714 static_cast<int>(zoom * 100 + 0.5)), | |
715 font_list); | 711 font_list); |
716 max_w = std::max(w, max_w); | 712 max_w = std::max(w, max_w); |
717 } | 713 } |
718 } else { | 714 } else { |
719 max_w = gfx::GetStringWidth( | 715 max_w = gfx::GetStringWidth(base::FormatPercent(100), font_list); |
720 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100), font_list); | |
721 } | 716 } |
722 zoom_label_max_width_ = max_w + border_width; | 717 zoom_label_max_width_ = max_w + border_width; |
723 | 718 |
724 zoom_label_max_width_valid_ = true; | 719 zoom_label_max_width_valid_ = true; |
725 } | 720 } |
726 return zoom_label_max_width_; | 721 return zoom_label_max_width_; |
727 } | 722 } |
728 | 723 |
729 // Index of the fullscreen menu item in the model. | 724 // Index of the fullscreen menu item in the model. |
730 const int fullscreen_index_; | 725 const int fullscreen_index_; |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 0, | 1297 0, |
1303 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1298 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1304 BOOKMARK_LAUNCH_LOCATION_APP_MENU); | 1299 BOOKMARK_LAUNCH_LOCATION_APP_MENU); |
1305 } | 1300 } |
1306 | 1301 |
1307 int AppMenu::ModelIndexFromCommandId(int command_id) const { | 1302 int AppMenu::ModelIndexFromCommandId(int command_id) const { |
1308 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); | 1303 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); |
1309 DCHECK(ix != command_id_to_entry_.end()); | 1304 DCHECK(ix != command_id_to_entry_.end()); |
1310 return ix->second.second; | 1305 return ix->second.second; |
1311 } | 1306 } |
OLD | NEW |