OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/wrench_menu.h" | 5 #include "chrome/browser/ui/views/wrench_menu.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "ui/views/controls/button/text_button.h" | 38 #include "ui/views/controls/button/text_button.h" |
39 #include "ui/views/controls/label.h" | 39 #include "ui/views/controls/label.h" |
40 #include "ui/views/controls/menu/menu_config.h" | 40 #include "ui/views/controls/menu/menu_config.h" |
41 #include "ui/views/controls/menu/menu_item_view.h" | 41 #include "ui/views/controls/menu/menu_item_view.h" |
42 #include "ui/views/controls/menu/menu_runner.h" | 42 #include "ui/views/controls/menu/menu_runner.h" |
43 #include "ui/views/controls/menu/menu_scroll_view_container.h" | 43 #include "ui/views/controls/menu/menu_scroll_view_container.h" |
44 #include "ui/views/controls/menu/submenu_view.h" | 44 #include "ui/views/controls/menu/submenu_view.h" |
45 #include "ui/views/widget/widget.h" | 45 #include "ui/views/widget/widget.h" |
46 | 46 |
47 using content::UserMetricsAction; | 47 using content::UserMetricsAction; |
| 48 using content::WebContents; |
48 using ui::MenuModel; | 49 using ui::MenuModel; |
49 using views::CustomButton; | 50 using views::CustomButton; |
50 using views::ImageButton; | 51 using views::ImageButton; |
51 using views::Label; | 52 using views::Label; |
52 using views::MenuConfig; | 53 using views::MenuConfig; |
53 using views::MenuItemView; | 54 using views::MenuItemView; |
54 using views::TextButton; | 55 using views::TextButton; |
55 using views::View; | 56 using views::View; |
56 | 57 |
57 namespace { | 58 namespace { |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 const content::NotificationSource& source, | 499 const content::NotificationSource& source, |
499 const content::NotificationDetails& details) { | 500 const content::NotificationDetails& details) { |
500 DCHECK_EQ(content::NOTIFICATION_ZOOM_LEVEL_CHANGED, type); | 501 DCHECK_EQ(content::NOTIFICATION_ZOOM_LEVEL_CHANGED, type); |
501 UpdateZoomControls(); | 502 UpdateZoomControls(); |
502 } | 503 } |
503 | 504 |
504 private: | 505 private: |
505 void UpdateZoomControls() { | 506 void UpdateZoomControls() { |
506 bool enable_increment = false; | 507 bool enable_increment = false; |
507 bool enable_decrement = false; | 508 bool enable_decrement = false; |
508 TabContents* selected_tab = menu_->browser_->GetSelectedTabContents(); | 509 WebContents* selected_tab = menu_->browser_->GetSelectedWebContents(); |
509 int zoom = 100; | 510 int zoom = 100; |
510 if (selected_tab) | 511 if (selected_tab) |
511 zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement); | 512 zoom = selected_tab->GetZoomPercent(&enable_increment, &enable_decrement); |
512 increment_button_->SetEnabled(enable_increment); | 513 increment_button_->SetEnabled(enable_increment); |
513 decrement_button_->SetEnabled(enable_decrement); | 514 decrement_button_->SetEnabled(enable_decrement); |
514 zoom_label_->SetText( | 515 zoom_label_->SetText( |
515 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); | 516 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom)); |
516 | 517 |
517 zoom_label_width_ = MaxWidthForZoomLabel(); | 518 zoom_label_width_ = MaxWidthForZoomLabel(); |
518 } | 519 } |
519 | 520 |
520 // Calculates the max width the zoom string can be. | 521 // Calculates the max width the zoom string can be. |
521 int MaxWidthForZoomLabel() { | 522 int MaxWidthForZoomLabel() { |
522 gfx::Font font = zoom_label_->font(); | 523 gfx::Font font = zoom_label_->font(); |
523 gfx::Insets insets; | 524 gfx::Insets insets; |
524 if (zoom_label_->border()) | 525 if (zoom_label_->border()) |
525 zoom_label_->border()->GetInsets(&insets); | 526 zoom_label_->border()->GetInsets(&insets); |
526 | 527 |
527 int max_w = 0; | 528 int max_w = 0; |
528 | 529 |
529 TabContents* selected_tab = menu_->browser_->GetSelectedTabContents(); | 530 WebContents* selected_tab = menu_->browser_->GetSelectedWebContents(); |
530 if (selected_tab) { | 531 if (selected_tab) { |
531 int min_percent = selected_tab->GetMinimumZoomPercent(); | 532 int min_percent = selected_tab->GetMinimumZoomPercent(); |
532 int max_percent = selected_tab->GetMaximumZoomPercent(); | 533 int max_percent = selected_tab->GetMaximumZoomPercent(); |
533 | 534 |
534 int step = (max_percent - min_percent) / 10; | 535 int step = (max_percent - min_percent) / 10; |
535 for (int i = min_percent; i <= max_percent; i += step) { | 536 for (int i = min_percent; i <= max_percent; i += step) { |
536 int w = font.GetStringWidth( | 537 int w = font.GetStringWidth( |
537 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, i)); | 538 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, i)); |
538 max_w = std::max(w, max_w); | 539 max_w = std::max(w, max_w); |
539 } | 540 } |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 bookmark_menu_delegate_.reset( | 893 bookmark_menu_delegate_.reset( |
893 new BookmarkMenuDelegate(browser_->profile(), | 894 new BookmarkMenuDelegate(browser_->profile(), |
894 NULL, | 895 NULL, |
895 parent, | 896 parent, |
896 first_bookmark_command_id_)); | 897 first_bookmark_command_id_)); |
897 bookmark_menu_delegate_->Init( | 898 bookmark_menu_delegate_->Init( |
898 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 899 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
899 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 900 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
900 bookmark_utils::LAUNCH_WRENCH_MENU); | 901 bookmark_utils::LAUNCH_WRENCH_MENU); |
901 } | 902 } |
OLD | NEW |