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

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

Issue 1803003003: [UI Views] Check menu() in ZoomView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 // Overridden from ButtonListener. 640 // Overridden from ButtonListener.
641 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 641 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
642 if (sender->tag() == fullscreen_index_) { 642 if (sender->tag() == fullscreen_index_) {
643 menu()->CancelAndEvaluate(menu_model(), sender->tag()); 643 menu()->CancelAndEvaluate(menu_model(), sender->tag());
644 } else { 644 } else {
645 // Zoom buttons don't close the menu. 645 // Zoom buttons don't close the menu.
646 menu_model()->ActivatedAt(sender->tag()); 646 menu_model()->ActivatedAt(sender->tag());
647 } 647 }
648 } 648 }
649 649
650 // Overridden from AppMenuObserver. 650 private:
651 void AppMenuDestroyed() override { AppMenuView::AppMenuDestroyed(); } 651 content::WebContents* GetActiveWebContents() const {
Devlin 2016/03/15 21:39:22 Drive-by: this was a bit silly.
652 return menu() ?
653 menu()->browser_->tab_strip_model()->GetActiveWebContents() :
654 nullptr;
655 }
652 656
653 private:
654 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change) { 657 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change) {
655 UpdateZoomControls(); 658 UpdateZoomControls();
656 } 659 }
657 660
658 void UpdateZoomControls() { 661 void UpdateZoomControls() {
659 WebContents* selected_tab = 662 WebContents* selected_tab = GetActiveWebContents();
660 menu()->browser_->tab_strip_model()->GetActiveWebContents();
661 int zoom = 100; 663 int zoom = 100;
662 if (selected_tab) { 664 if (selected_tab) {
663 auto zoom_controller = 665 auto zoom_controller =
664 ui_zoom::ZoomController::FromWebContents(selected_tab); 666 ui_zoom::ZoomController::FromWebContents(selected_tab);
665 if (zoom_controller) 667 if (zoom_controller)
666 zoom = zoom_controller->GetZoomPercent(); 668 zoom = zoom_controller->GetZoomPercent();
667 increment_button_->SetEnabled(zoom < 669 increment_button_->SetEnabled(zoom <
668 selected_tab->GetMaximumZoomPercent()); 670 selected_tab->GetMaximumZoomPercent());
669 decrement_button_->SetEnabled(zoom > 671 decrement_button_->SetEnabled(zoom >
670 selected_tab->GetMinimumZoomPercent()); 672 selected_tab->GetMinimumZoomPercent());
671 } 673 }
672 zoom_label_->SetText( 674 zoom_label_->SetText(
673 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); 675 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom));
674 676
675 zoom_label_max_width_valid_ = false; 677 zoom_label_max_width_valid_ = false;
676 } 678 }
677 679
678 // Returns the max width the zoom string can be. 680 // Returns the max width the zoom string can be.
679 int ZoomLabelMaxWidth() const { 681 int ZoomLabelMaxWidth() const {
680 if (!zoom_label_max_width_valid_) { 682 if (!zoom_label_max_width_valid_) {
681 const gfx::FontList& font_list = zoom_label_->font_list(); 683 const gfx::FontList& font_list = zoom_label_->font_list();
682 int border_width = zoom_label_->border() 684 int border_width = zoom_label_->border()
683 ? zoom_label_->border()->GetInsets().width() 685 ? zoom_label_->border()->GetInsets().width()
684 : 0; 686 : 0;
685 687
686 int max_w = 0; 688 int max_w = 0;
687 689
688 WebContents* selected_tab = 690 WebContents* selected_tab = GetActiveWebContents();
689 menu()->browser_->tab_strip_model()->GetActiveWebContents();
690 if (selected_tab) { 691 if (selected_tab) {
691 auto zoom_controller = 692 auto zoom_controller =
692 ui_zoom::ZoomController::FromWebContents(selected_tab); 693 ui_zoom::ZoomController::FromWebContents(selected_tab);
693 DCHECK(zoom_controller); 694 DCHECK(zoom_controller);
694 // Enumerate all zoom factors that can be used in PageZoom::Zoom. 695 // Enumerate all zoom factors that can be used in PageZoom::Zoom.
695 std::vector<double> zoom_factors = ui_zoom::PageZoom::PresetZoomFactors( 696 std::vector<double> zoom_factors = ui_zoom::PageZoom::PresetZoomFactors(
696 zoom_controller->GetZoomPercent()); 697 zoom_controller->GetZoomPercent());
697 for (auto zoom : zoom_factors) { 698 for (auto zoom : zoom_factors) {
698 int w = gfx::GetStringWidth( 699 int w = gfx::GetStringWidth(
699 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 700 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT,
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 0, 1288 0,
1288 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, 1289 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS,
1289 BOOKMARK_LAUNCH_LOCATION_APP_MENU); 1290 BOOKMARK_LAUNCH_LOCATION_APP_MENU);
1290 } 1291 }
1291 1292
1292 int AppMenu::ModelIndexFromCommandId(int command_id) const { 1293 int AppMenu::ModelIndexFromCommandId(int command_id) const {
1293 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id); 1294 CommandIDToEntry::const_iterator ix = command_id_to_entry_.find(command_id);
1294 DCHECK(ix != command_id_to_entry_.end()); 1295 DCHECK(ix != command_id_to_entry_.end());
1295 return ix->second.second; 1296 return ix->second.second;
1296 } 1297 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698