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

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

Issue 62873007: [Toolbar] Base toolbar button class with background images for button states (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: overriding Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_view.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | 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/toolbar_view.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/i18n/number_formatting.h" 9 #include "base/i18n/number_formatting.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 15 matching lines...) Expand all
26 #include "chrome/browser/ui/omnibox/omnibox_view.h" 26 #include "chrome/browser/ui/omnibox/omnibox_view.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" 28 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
29 #include "chrome/browser/ui/view_ids.h" 29 #include "chrome/browser/ui/view_ids.h"
30 #include "chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h" 30 #include "chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h"
31 #include "chrome/browser/ui/views/frame/browser_view.h" 31 #include "chrome/browser/ui/views/frame/browser_view.h"
32 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 32 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
33 #include "chrome/browser/ui/views/location_bar/star_view.h" 33 #include "chrome/browser/ui/views/location_bar/star_view.h"
34 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" 34 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
35 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" 35 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
36 #include "chrome/browser/ui/views/toolbar/back_button.h"
36 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" 37 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
37 #include "chrome/browser/ui/views/toolbar/button_dropdown.h"
38 #include "chrome/browser/ui/views/toolbar/home_button.h" 38 #include "chrome/browser/ui/views/toolbar/home_button.h"
39 #include "chrome/browser/ui/views/toolbar/reload_button.h" 39 #include "chrome/browser/ui/views/toolbar/reload_button.h"
40 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
40 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" 41 #include "chrome/browser/ui/views/toolbar/wrench_menu.h"
41 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" 42 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
42 #include "chrome/browser/upgrade_detector.h" 43 #include "chrome/browser/upgrade_detector.h"
43 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/pref_names.h" 45 #include "chrome/common/pref_names.h"
45 #include "content/public/browser/browser_accessibility_state.h" 46 #include "content/public/browser/browser_accessibility_state.h"
46 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/render_view_host.h" 48 #include "content/public/browser/render_view_host.h"
48 #include "content/public/browser/user_metrics.h" 49 #include "content/public/browser/user_metrics.h"
49 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 160
160 ToolbarView::~ToolbarView() { 161 ToolbarView::~ToolbarView() {
161 // NOTE: Don't remove the command observers here. This object gets destroyed 162 // NOTE: Don't remove the command observers here. This object gets destroyed
162 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is 163 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is
163 // already gone. 164 // already gone.
164 } 165 }
165 166
166 void ToolbarView::Init() { 167 void ToolbarView::Init() {
167 GetWidget()->AddObserver(this); 168 GetWidget()->AddObserver(this);
168 169
169 back_ = new ButtonDropDown(this, new BackForwardMenuModel( 170 back_ = new BackButton(this, new BackForwardMenuModel(
170 browser_, BackForwardMenuModel::BACKWARD_MENU)); 171 browser_, BackForwardMenuModel::BACKWARD_MENU));
171 back_->set_triggerable_event_flags( 172 back_->set_triggerable_event_flags(
172 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 173 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
173 back_->set_tag(IDC_BACK); 174 back_->set_tag(IDC_BACK);
174 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT,
175 views::ImageButton::ALIGN_TOP);
176 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)); 175 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK));
177 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); 176 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK));
178 back_->set_id(VIEW_ID_BACK_BUTTON); 177 back_->set_id(VIEW_ID_BACK_BUTTON);
179 178
180 forward_ = new ButtonDropDown(this, new BackForwardMenuModel( 179 forward_ = new ToolbarButton(this, new BackForwardMenuModel(
181 browser_, BackForwardMenuModel::FORWARD_MENU)); 180 browser_, BackForwardMenuModel::FORWARD_MENU));
182 forward_->set_triggerable_event_flags( 181 forward_->set_triggerable_event_flags(
183 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 182 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
184 forward_->set_tag(IDC_FORWARD); 183 forward_->set_tag(IDC_FORWARD);
185 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)); 184 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD));
186 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); 185 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD));
187 forward_->set_id(VIEW_ID_FORWARD_BUTTON); 186 forward_->set_id(VIEW_ID_FORWARD_BUTTON);
188 187
189 // Have to create this before |reload_| as |reload_|'s constructor needs it. 188 // Have to create this before |reload_| as |reload_|'s constructor needs it.
190 location_bar_ = new LocationBarView( 189 location_bar_ = new LocationBarView(
191 browser_, browser_->profile(), 190 browser_, browser_->profile(),
192 browser_->command_controller()->command_updater(), this, 191 browser_->command_controller()->command_updater(), this,
193 display_mode_ == DISPLAYMODE_LOCATION || 192 display_mode_ == DISPLAYMODE_LOCATION ||
194 (browser_->is_app() && IsStreamlinedHostedAppsEnabled())); 193 (browser_->is_app() && IsStreamlinedHostedAppsEnabled()));
195 194
196 reload_ = new ReloadButton(location_bar_, 195 reload_ = new ReloadButton(location_bar_,
197 browser_->command_controller()->command_updater()); 196 browser_->command_controller()->command_updater());
198 reload_->set_triggerable_event_flags( 197 reload_->set_triggerable_event_flags(
199 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 198 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
200 reload_->set_tag(IDC_RELOAD); 199 reload_->set_tag(IDC_RELOAD);
201 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); 200 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD));
202 reload_->set_id(VIEW_ID_RELOAD_BUTTON); 201 reload_->set_id(VIEW_ID_RELOAD_BUTTON);
203 202
204 home_ = new HomeImageButton(this, browser_); 203 home_ = new HomeButton(this, browser_);
205 home_->set_triggerable_event_flags( 204 home_->set_triggerable_event_flags(
206 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 205 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
207 home_->set_tag(IDC_HOME); 206 home_->set_tag(IDC_HOME);
208 home_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_HOME)); 207 home_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_HOME));
209 home_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME)); 208 home_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME));
210 home_->set_id(VIEW_ID_HOME_BUTTON); 209 home_->set_id(VIEW_ID_HOME_BUTTON);
211 210
212 browser_actions_ = new BrowserActionsContainer(browser_, this); 211 browser_actions_ = new BrowserActionsContainer(browser_, this);
213 212
214 #if defined(OS_WIN) && !defined(USE_AURA) 213 #if defined(OS_WIN) && !defined(USE_AURA)
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 524
526 // If the window is maximized, we extend the back button to the left so that 525 // If the window is maximized, we extend the back button to the left so that
527 // clicking on the left-most pixel will activate the back button. 526 // clicking on the left-most pixel will activate the back button.
528 // TODO(abarth): If the window becomes maximized but is not resized, 527 // TODO(abarth): If the window becomes maximized but is not resized,
529 // then Layout() might not be called and the back button 528 // then Layout() might not be called and the back button
530 // will be slightly the wrong size. We should force a 529 // will be slightly the wrong size. We should force a
531 // Layout() in this case. 530 // Layout() in this case.
532 // http://crbug.com/5540 531 // http://crbug.com/5540
533 bool maximized = browser_->window() && browser_->window()->IsMaximized(); 532 bool maximized = browser_->window() && browser_->window()->IsMaximized();
534 int back_width = back_->GetPreferredSize().width(); 533 int back_width = back_->GetPreferredSize().width();
535 if (maximized) 534 if (maximized) {
536 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); 535 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height);
537 else 536 back_->SetLeadingMargin(kLeftEdgeSpacing);
537 } else {
538 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); 538 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height);
539 back_->SetLeadingMargin(0);
540 }
539 541
540 int button_spacing = GetButtonSpacing(); 542 int button_spacing = GetButtonSpacing();
541 forward_->SetBounds(back_->x() + back_->width() + button_spacing, 543 forward_->SetBounds(back_->x() + back_->width() + button_spacing,
542 child_y, forward_->GetPreferredSize().width(), child_height); 544 child_y, forward_->GetPreferredSize().width(), child_height);
543 545
544 reload_->SetBounds(forward_->x() + forward_->width() + button_spacing, 546 reload_->SetBounds(forward_->x() + forward_->width() + button_spacing,
545 child_y, reload_->GetPreferredSize().width(), child_height); 547 child_y, reload_->GetPreferredSize().width(), child_height);
546 548
547 if (show_home_button_.GetValue()) { 549 if (show_home_button_.GetValue()) {
548 home_->SetVisible(true); 550 home_->SetVisible(true);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 } 708 }
707 709
708 int ToolbarView::PopupTopSpacing() const { 710 int ToolbarView::PopupTopSpacing() const {
709 const int kPopupTopSpacingNonGlass = 3; 711 const int kPopupTopSpacingNonGlass = 3;
710 return GetWidget()->ShouldUseNativeFrame() ? 0 : kPopupTopSpacingNonGlass; 712 return GetWidget()->ShouldUseNativeFrame() ? 0 : kPopupTopSpacingNonGlass;
711 } 713 }
712 714
713 void ToolbarView::LoadImages() { 715 void ToolbarView::LoadImages() {
714 ui::ThemeProvider* tp = GetThemeProvider(); 716 ui::ThemeProvider* tp = GetThemeProvider();
715 717
716 back_->SetImage(views::CustomButton::STATE_NORMAL, 718 back_->SetImage(views::Button::STATE_NORMAL,
717 tp->GetImageSkiaNamed(IDR_BACK)); 719 *(tp->GetImageSkiaNamed(IDR_BACK)));
718 back_->SetImage(views::CustomButton::STATE_HOVERED, 720 back_->SetImage(views::Button::STATE_DISABLED,
719 tp->GetImageSkiaNamed(IDR_BACK_H)); 721 *(tp->GetImageSkiaNamed(IDR_BACK_D)));
720 back_->SetImage(views::CustomButton::STATE_PRESSED,
721 tp->GetImageSkiaNamed(IDR_BACK_P));
722 back_->SetImage(views::CustomButton::STATE_DISABLED,
723 tp->GetImageSkiaNamed(IDR_BACK_D));
724 722
725 forward_->SetImage(views::CustomButton::STATE_NORMAL, 723 forward_->SetImage(views::Button::STATE_NORMAL,
726 tp->GetImageSkiaNamed(IDR_FORWARD)); 724 *(tp->GetImageSkiaNamed(IDR_FORWARD)));
727 forward_->SetImage(views::CustomButton::STATE_HOVERED, 725 forward_->SetImage(views::Button::STATE_DISABLED,
728 tp->GetImageSkiaNamed(IDR_FORWARD_H)); 726 *(tp->GetImageSkiaNamed(IDR_FORWARD_D)));
729 forward_->SetImage(views::CustomButton::STATE_PRESSED,
730 tp->GetImageSkiaNamed(IDR_FORWARD_P));
731 forward_->SetImage(views::CustomButton::STATE_DISABLED,
732 tp->GetImageSkiaNamed(IDR_FORWARD_D));
733 727
734 reload_->LoadImages(); 728 reload_->LoadImages();
735 729
736 home_->SetImage(views::CustomButton::STATE_NORMAL, 730 home_->SetImage(views::Button::STATE_NORMAL,
737 tp->GetImageSkiaNamed(IDR_HOME)); 731 *(tp->GetImageSkiaNamed(IDR_HOME)));
738 home_->SetImage(views::CustomButton::STATE_HOVERED,
739 tp->GetImageSkiaNamed(IDR_HOME_H));
740 home_->SetImage(views::CustomButton::STATE_PRESSED,
741 tp->GetImageSkiaNamed(IDR_HOME_P));
742 } 732 }
743 733
744 void ToolbarView::ShowCriticalNotification() { 734 void ToolbarView::ShowCriticalNotification() {
745 #if defined(OS_WIN) 735 #if defined(OS_WIN)
746 CriticalNotificationBubbleView* bubble_delegate = 736 CriticalNotificationBubbleView* bubble_delegate =
747 new CriticalNotificationBubbleView(app_menu_); 737 new CriticalNotificationBubbleView(app_menu_);
748 views::BubbleDelegateView::CreateBubble(bubble_delegate); 738 views::BubbleDelegateView::CreateBubble(bubble_delegate);
749 bubble_delegate->StartFade(true); 739 bubble_delegate->StartFade(true);
750 #endif 740 #endif
751 } 741 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 803
814 void ToolbarView::OnShowHomeButtonChanged() { 804 void ToolbarView::OnShowHomeButtonChanged() {
815 Layout(); 805 Layout();
816 SchedulePaint(); 806 SchedulePaint();
817 } 807 }
818 808
819 int ToolbarView::content_shadow_height() const { 809 int ToolbarView::content_shadow_height() const {
820 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? 810 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ?
821 kContentShadowHeightAsh : kContentShadowHeight; 811 kContentShadowHeightAsh : kContentShadowHeight;
822 } 812 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_view.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698