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

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: tweaks 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
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 16 matching lines...) Expand all
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/browser_actions_container.h" 36 #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" 37 #include "chrome/browser/ui/views/toolbar/home_button.h"
39 #include "chrome/browser/ui/views/toolbar/reload_button.h" 38 #include "chrome/browser/ui/views/toolbar/reload_button.h"
39 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
40 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" 40 #include "chrome/browser/ui/views/toolbar/wrench_menu.h"
41 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" 41 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
42 #include "chrome/browser/upgrade_detector.h" 42 #include "chrome/browser/upgrade_detector.h"
43 #include "chrome/common/chrome_switches.h" 43 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/pref_names.h" 44 #include "chrome/common/pref_names.h"
45 #include "content/public/browser/browser_accessibility_state.h" 45 #include "content/public/browser/browser_accessibility_state.h"
46 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/render_view_host.h" 47 #include "content/public/browser/render_view_host.h"
48 #include "content/public/browser/user_metrics.h" 48 #include "content/public/browser/user_metrics.h"
49 #include "content/public/browser/web_contents.h" 49 #include "content/public/browser/web_contents.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 ToolbarView::~ToolbarView() { 160 ToolbarView::~ToolbarView() {
161 // NOTE: Don't remove the command observers here. This object gets destroyed 161 // NOTE: Don't remove the command observers here. This object gets destroyed
162 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is 162 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is
163 // already gone. 163 // already gone.
164 } 164 }
165 165
166 void ToolbarView::Init() { 166 void ToolbarView::Init() {
167 GetWidget()->AddObserver(this); 167 GetWidget()->AddObserver(this);
168 168
169 back_ = new ButtonDropDown(this, new BackForwardMenuModel( 169 back_ = new ToolbarButton(this, new BackForwardMenuModel(
170 browser_, BackForwardMenuModel::BACKWARD_MENU)); 170 browser_, BackForwardMenuModel::BACKWARD_MENU));
171 back_->set_triggerable_event_flags( 171 back_->set_triggerable_event_flags(
172 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 172 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
173 back_->set_tag(IDC_BACK); 173 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)); 174 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK));
177 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); 175 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK));
178 back_->set_id(VIEW_ID_BACK_BUTTON); 176 back_->set_id(VIEW_ID_BACK_BUTTON);
179 177
180 forward_ = new ButtonDropDown(this, new BackForwardMenuModel( 178 forward_ = new ToolbarButton(this, new BackForwardMenuModel(
181 browser_, BackForwardMenuModel::FORWARD_MENU)); 179 browser_, BackForwardMenuModel::FORWARD_MENU));
182 forward_->set_triggerable_event_flags( 180 forward_->set_triggerable_event_flags(
183 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 181 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
184 forward_->set_tag(IDC_FORWARD); 182 forward_->set_tag(IDC_FORWARD);
185 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD)); 183 forward_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_FORWARD));
186 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); 184 forward_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD));
187 forward_->set_id(VIEW_ID_FORWARD_BUTTON); 185 forward_->set_id(VIEW_ID_FORWARD_BUTTON);
188 186
189 // Have to create this before |reload_| as |reload_|'s constructor needs it. 187 // Have to create this before |reload_| as |reload_|'s constructor needs it.
190 location_bar_ = new LocationBarView( 188 location_bar_ = new LocationBarView(
191 browser_, browser_->profile(), 189 browser_, browser_->profile(),
192 browser_->command_controller()->command_updater(), this, 190 browser_->command_controller()->command_updater(), this,
193 display_mode_ == DISPLAYMODE_LOCATION || 191 display_mode_ == DISPLAYMODE_LOCATION ||
194 (browser_->is_app() && IsStreamlinedHostedAppsEnabled())); 192 (browser_->is_app() && IsStreamlinedHostedAppsEnabled()));
195 193
196 reload_ = new ReloadButton(location_bar_, 194 reload_ = new ReloadButton(location_bar_,
197 browser_->command_controller()->command_updater()); 195 browser_->command_controller()->command_updater());
198 reload_->set_triggerable_event_flags( 196 reload_->set_triggerable_event_flags(
199 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 197 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
200 reload_->set_tag(IDC_RELOAD); 198 reload_->set_tag(IDC_RELOAD);
201 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); 199 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD));
202 reload_->set_id(VIEW_ID_RELOAD_BUTTON); 200 reload_->set_id(VIEW_ID_RELOAD_BUTTON);
203 201
204 home_ = new HomeImageButton(this, browser_); 202 home_ = new HomeButton(this, browser_);
205 home_->set_triggerable_event_flags( 203 home_->set_triggerable_event_flags(
206 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 204 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
207 home_->set_tag(IDC_HOME); 205 home_->set_tag(IDC_HOME);
208 home_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_HOME)); 206 home_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_HOME));
209 home_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME)); 207 home_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME));
210 home_->set_id(VIEW_ID_HOME_BUTTON); 208 home_->set_id(VIEW_ID_HOME_BUTTON);
211 209
212 browser_actions_ = new BrowserActionsContainer(browser_, this); 210 browser_actions_ = new BrowserActionsContainer(browser_, this);
213 211
214 #if defined(OS_WIN) && !defined(USE_AURA) 212 #if defined(OS_WIN) && !defined(USE_AURA)
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 523
526 // If the window is maximized, we extend the back button to the left so that 524 // 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. 525 // clicking on the left-most pixel will activate the back button.
528 // TODO(abarth): If the window becomes maximized but is not resized, 526 // TODO(abarth): If the window becomes maximized but is not resized,
529 // then Layout() might not be called and the back button 527 // then Layout() might not be called and the back button
530 // will be slightly the wrong size. We should force a 528 // will be slightly the wrong size. We should force a
531 // Layout() in this case. 529 // Layout() in this case.
532 // http://crbug.com/5540 530 // http://crbug.com/5540
533 bool maximized = browser_->window() && browser_->window()->IsMaximized(); 531 bool maximized = browser_->window() && browser_->window()->IsMaximized();
534 int back_width = back_->GetPreferredSize().width(); 532 int back_width = back_->GetPreferredSize().width();
535 if (maximized) 533 if (maximized) {
536 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); 534 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height);
537 else 535 back_->SetLeftMargin(kLeftEdgeSpacing);
536 } else {
538 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); 537 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height);
538 back_->SetLeftMargin(0);
539 }
539 540
540 int button_spacing = GetButtonSpacing(); 541 int button_spacing = GetButtonSpacing();
541 forward_->SetBounds(back_->x() + back_->width() + button_spacing, 542 forward_->SetBounds(back_->x() + back_->width() + button_spacing,
542 child_y, forward_->GetPreferredSize().width(), child_height); 543 child_y, forward_->GetPreferredSize().width(), child_height);
543 544
544 reload_->SetBounds(forward_->x() + forward_->width() + button_spacing, 545 reload_->SetBounds(forward_->x() + forward_->width() + button_spacing,
545 child_y, reload_->GetPreferredSize().width(), child_height); 546 child_y, reload_->GetPreferredSize().width(), child_height);
546 547
547 if (show_home_button_.GetValue()) { 548 if (show_home_button_.GetValue()) {
548 home_->SetVisible(true); 549 home_->SetVisible(true);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 } 707 }
707 708
708 int ToolbarView::PopupTopSpacing() const { 709 int ToolbarView::PopupTopSpacing() const {
709 const int kPopupTopSpacingNonGlass = 3; 710 const int kPopupTopSpacingNonGlass = 3;
710 return GetWidget()->ShouldUseNativeFrame() ? 0 : kPopupTopSpacingNonGlass; 711 return GetWidget()->ShouldUseNativeFrame() ? 0 : kPopupTopSpacingNonGlass;
711 } 712 }
712 713
713 void ToolbarView::LoadImages() { 714 void ToolbarView::LoadImages() {
714 ui::ThemeProvider* tp = GetThemeProvider(); 715 ui::ThemeProvider* tp = GetThemeProvider();
715 716
716 back_->SetImage(views::CustomButton::STATE_NORMAL, 717 back_->SetImage(views::Button::STATE_NORMAL,
717 tp->GetImageSkiaNamed(IDR_BACK)); 718 *(tp->GetImageSkiaNamed(IDR_BACK)));
718 back_->SetImage(views::CustomButton::STATE_HOVERED, 719 back_->SetImage(views::Button::STATE_DISABLED,
719 tp->GetImageSkiaNamed(IDR_BACK_H)); 720 *(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 721
725 forward_->SetImage(views::CustomButton::STATE_NORMAL, 722 forward_->SetImage(views::Button::STATE_NORMAL,
726 tp->GetImageSkiaNamed(IDR_FORWARD)); 723 *(tp->GetImageSkiaNamed(IDR_FORWARD)));
727 forward_->SetImage(views::CustomButton::STATE_HOVERED, 724 forward_->SetImage(views::Button::STATE_DISABLED,
728 tp->GetImageSkiaNamed(IDR_FORWARD_H)); 725 *(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 726
734 reload_->LoadImages(); 727 reload_->LoadImages();
735 728
736 home_->SetImage(views::CustomButton::STATE_NORMAL, 729 home_->SetImage(views::Button::STATE_NORMAL,
737 tp->GetImageSkiaNamed(IDR_HOME)); 730 *(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 } 731 }
743 732
744 void ToolbarView::ShowCriticalNotification() { 733 void ToolbarView::ShowCriticalNotification() {
745 #if defined(OS_WIN) 734 #if defined(OS_WIN)
746 CriticalNotificationBubbleView* bubble_delegate = 735 CriticalNotificationBubbleView* bubble_delegate =
747 new CriticalNotificationBubbleView(app_menu_); 736 new CriticalNotificationBubbleView(app_menu_);
748 views::BubbleDelegateView::CreateBubble(bubble_delegate); 737 views::BubbleDelegateView::CreateBubble(bubble_delegate);
749 bubble_delegate->StartFade(true); 738 bubble_delegate->StartFade(true);
750 #endif 739 #endif
751 } 740 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 802
814 void ToolbarView::OnShowHomeButtonChanged() { 803 void ToolbarView::OnShowHomeButtonChanged() {
815 Layout(); 804 Layout();
816 SchedulePaint(); 805 SchedulePaint();
817 } 806 }
818 807
819 int ToolbarView::content_shadow_height() const { 808 int ToolbarView::content_shadow_height() const {
820 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? 809 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ?
821 kContentShadowHeightAsh : kContentShadowHeight; 810 kContentShadowHeightAsh : kContentShadowHeight;
822 } 811 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698