Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/ui/views/toolbar/app_menu.cc

Issue 1989563002: i18n of Zoom % to use locally correct numeric glyphs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 ui_zoom::ZoomEventManager::GetForBrowserContext( 519 ui_zoom::ZoomEventManager::GetForBrowserContext(
520 menu->browser_->profile()) 520 menu->browser_->profile())
521 ->AddZoomLevelChangedCallback( 521 ->AddZoomLevelChangedCallback(
522 base::Bind(&AppMenu::ZoomView::OnZoomLevelChanged, 522 base::Bind(&AppMenu::ZoomView::OnZoomLevelChanged,
523 base::Unretained(this))); 523 base::Unretained(this)));
524 524
525 decrement_button_ = CreateButtonWithAccName( 525 decrement_button_ = CreateButtonWithAccName(
526 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON, 526 IDS_ZOOM_MINUS2, InMenuButtonBackground::LEFT_BUTTON,
527 decrement_index, IDS_ACCNAME_ZOOM_MINUS2); 527 decrement_index, IDS_ACCNAME_ZOOM_MINUS2);
528 528
529 zoom_label_ = new Label( 529 zoom_label_ = new Label(base::FormatPercent(100));
530 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100));
jungshik at Google 2016/05/17 23:58:43 Please, drop IDS_ZOOM_PERCENT from a grd file.
Greg Levin 2016/05/18 21:33:44 Done.
531 zoom_label_->SetAutoColorReadabilityEnabled(false); 530 zoom_label_->SetAutoColorReadabilityEnabled(false);
532 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 531 zoom_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
533 532
534 InMenuButtonBackground* center_bg = 533 InMenuButtonBackground* center_bg =
535 new InMenuButtonBackground(InMenuButtonBackground::RIGHT_BUTTON); 534 new InMenuButtonBackground(InMenuButtonBackground::RIGHT_BUTTON);
536 zoom_label_->set_background(center_bg); 535 zoom_label_->set_background(center_bg);
537 536
538 AddChildView(zoom_label_); 537 AddChildView(zoom_label_);
539 zoom_label_max_width_valid_ = false; 538 zoom_label_max_width_valid_ = false;
540 539
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 if (selected_tab) { 663 if (selected_tab) {
665 auto zoom_controller = 664 auto zoom_controller =
666 ui_zoom::ZoomController::FromWebContents(selected_tab); 665 ui_zoom::ZoomController::FromWebContents(selected_tab);
667 if (zoom_controller) 666 if (zoom_controller)
668 zoom = zoom_controller->GetZoomPercent(); 667 zoom = zoom_controller->GetZoomPercent();
669 increment_button_->SetEnabled(zoom < 668 increment_button_->SetEnabled(zoom <
670 selected_tab->GetMaximumZoomPercent()); 669 selected_tab->GetMaximumZoomPercent());
671 decrement_button_->SetEnabled(zoom > 670 decrement_button_->SetEnabled(zoom >
672 selected_tab->GetMinimumZoomPercent()); 671 selected_tab->GetMinimumZoomPercent());
673 } 672 }
674 zoom_label_->SetText( 673 zoom_label_->SetText(base::FormatPercent(zoom));
675 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom));
676
677 zoom_label_max_width_valid_ = false; 674 zoom_label_max_width_valid_ = false;
678 } 675 }
679 676
680 // Returns the max width the zoom string can be. 677 // Returns the max width the zoom string can be.
681 int ZoomLabelMaxWidth() const { 678 int ZoomLabelMaxWidth() const {
682 if (!zoom_label_max_width_valid_) { 679 if (!zoom_label_max_width_valid_) {
683 const gfx::FontList& font_list = zoom_label_->font_list(); 680 const gfx::FontList& font_list = zoom_label_->font_list();
684 int border_width = zoom_label_->border() 681 int border_width = zoom_label_->border()
685 ? zoom_label_->border()->GetInsets().width() 682 ? zoom_label_->border()->GetInsets().width()
686 : 0; 683 : 0;
687 684
688 int max_w = 0; 685 int max_w = 0;
689 686
690 WebContents* selected_tab = GetActiveWebContents(); 687 WebContents* selected_tab = GetActiveWebContents();
691 if (selected_tab) { 688 if (selected_tab) {
692 auto zoom_controller = 689 auto zoom_controller =
693 ui_zoom::ZoomController::FromWebContents(selected_tab); 690 ui_zoom::ZoomController::FromWebContents(selected_tab);
694 DCHECK(zoom_controller); 691 DCHECK(zoom_controller);
695 // Enumerate all zoom factors that can be used in PageZoom::Zoom. 692 // Enumerate all zoom factors that can be used in PageZoom::Zoom.
696 std::vector<double> zoom_factors = ui_zoom::PageZoom::PresetZoomFactors( 693 std::vector<double> zoom_factors = ui_zoom::PageZoom::PresetZoomFactors(
697 zoom_controller->GetZoomPercent()); 694 zoom_controller->GetZoomPercent());
698 for (auto zoom : zoom_factors) { 695 for (auto zoom : zoom_factors) {
699 int w = gfx::GetStringWidth( 696 int w = gfx::GetStringWidth(
700 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 697 base::FormatPercent(static_cast<int>(zoom * 100 + 0.5)),
Peter Kasting 2016/05/18 02:37:25 Use std::round().
Greg Levin 2016/05/18 21:33:44 Done.
701 static_cast<int>(zoom * 100 + 0.5)),
702 font_list); 698 font_list);
703 max_w = std::max(w, max_w); 699 max_w = std::max(w, max_w);
704 } 700 }
705 } else { 701 } else {
706 max_w = gfx::GetStringWidth( 702 max_w = gfx::GetStringWidth(base::FormatPercent(100), font_list);
707 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100), font_list);
708 } 703 }
709 zoom_label_max_width_ = max_w + border_width; 704 zoom_label_max_width_ = max_w + border_width;
710 705
711 zoom_label_max_width_valid_ = true; 706 zoom_label_max_width_valid_ = true;
712 } 707 }
713 return zoom_label_max_width_; 708 return zoom_label_max_width_;
714 } 709 }
715 710
716 // Index of the fullscreen menu item in the model. 711 // Index of the fullscreen menu item in the model.
717 const int fullscreen_index_; 712 const int fullscreen_index_;
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 0, 1284 0,
1290 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1285 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1291 BOOKMARK_LAUNCH_LOCATION_APP_MENU); 1286 BOOKMARK_LAUNCH_LOCATION_APP_MENU);
1292 } 1287 }
1293 1288
1294 int AppMenu::ModelIndexFromCommandId(int command_id) const { 1289 int AppMenu::ModelIndexFromCommandId(int command_id) const {
1295 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1290 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1296 DCHECK(ix != command_id_to_entry_.end()); 1291 DCHECK(ix != command_id_to_entry_.end());
1297 return ix->second.second; 1292 return ix->second.second;
1298 } 1293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698