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

Side by Side Diff: chrome/browser/ui/views/toolbar/reload_button.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: Graphics from UI. Created 7 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/reload_button.h" 5 #include "chrome/browser/ui/views/toolbar/reload_button.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/command_updater.h" 9 #include "chrome/browser/command_updater.h"
10 #include "chrome/browser/search/search.h" 10 #include "chrome/browser/search/search.h"
11 #include "chrome/browser/ui/search/search_model.h" 11 #include "chrome/browser/ui/search/search_model.h"
12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
13 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/models/simple_menu_model.h" 16 #include "ui/base/models/simple_menu_model.h"
17 #include "ui/base/theme_provider.h" 17 #include "ui/base/theme_provider.h"
18 #include "ui/base/window_open_disposition.h" 18 #include "ui/base/window_open_disposition.h"
19 #include "ui/views/metrics.h" 19 #include "ui/views/metrics.h"
20 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
21 21
22 22
23 namespace { 23 namespace {
24 24
25 const int kReloadImages[] = 25 const int kReloadImages[] =
26 { IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, IDR_RELOAD_D }; 26 { IDR_RELOAD_INNER, IDR_RELOAD_INNER, IDR_RELOAD_INNER,
27 IDR_RELOAD_INNER_DIMMED };
27 28
28 const int kStopImages[] = { IDR_STOP, IDR_STOP_H, IDR_STOP_P, IDR_STOP_D }; 29 const int kStopImages[] = { IDR_STOP_INNER, IDR_STOP_INNER, IDR_STOP_INNER,
30 IDR_STOP_INNER_D };
29 31
30 // Contents of the Reload drop-down menu. 32 // Contents of the Reload drop-down menu.
31 const int kReloadMenuItems[] = { 33 const int kReloadMenuItems[] = {
32 IDS_RELOAD_MENU_NORMAL_RELOAD_ITEM, 34 IDS_RELOAD_MENU_NORMAL_RELOAD_ITEM,
33 IDS_RELOAD_MENU_HARD_RELOAD_ITEM, 35 IDS_RELOAD_MENU_HARD_RELOAD_ITEM,
34 IDS_RELOAD_MENU_EMPTY_AND_HARD_RELOAD_ITEM, 36 IDS_RELOAD_MENU_EMPTY_AND_HARD_RELOAD_ITEM,
35 }; 37 };
36 38
37 } // namespace 39 } // namespace
38 40
39 41
40 // ReloadButton --------------------------------------------------------------- 42 // ReloadButton ---------------------------------------------------------------
41 43
42 // static 44 // static
43 const char ReloadButton::kViewClassName[] = "ReloadButton"; 45 const char ReloadButton::kViewClassName[] = "ReloadButton";
44 46
45 ReloadButton::ReloadButton(LocationBarView* location_bar, 47 ReloadButton::ReloadButton(LocationBarView* location_bar,
46 CommandUpdater* command_updater) 48 CommandUpdater* command_updater)
47 : ButtonDropDown(this, CreateMenuModel()), 49 : ToolbarButton(CreateMenuModel()),
48 location_bar_(location_bar), 50 location_bar_(location_bar),
49 command_updater_(command_updater), 51 command_updater_(command_updater),
50 intended_mode_(MODE_RELOAD), 52 intended_mode_(MODE_RELOAD),
51 visible_mode_(MODE_RELOAD), 53 visible_mode_(MODE_RELOAD),
52 double_click_timer_delay_( 54 double_click_timer_delay_(
53 base::TimeDelta::FromMilliseconds(views::GetDoubleClickInterval())), 55 base::TimeDelta::FromMilliseconds(views::GetDoubleClickInterval())),
54 stop_to_reload_timer_delay_(base::TimeDelta::FromMilliseconds(1350)), 56 stop_to_reload_timer_delay_(base::TimeDelta::FromMilliseconds(1350)),
55 menu_enabled_(false), 57 menu_enabled_(false),
56 testing_mouse_hovered_(false), 58 testing_mouse_hovered_(false),
57 testing_reload_count_(0) { 59 testing_reload_count_(0) {
58 } 60 }
59 61
60 ReloadButton::~ReloadButton() { 62 ReloadButton::~ReloadButton() {
61 } 63 };
64
Peter Kasting 2013/11/15 03:28:58 Nit: Extra semicolon and newline
Greg Billock 2013/11/15 19:36:50 Done.
62 65
63 void ReloadButton::ChangeMode(Mode mode, bool force) { 66 void ReloadButton::ChangeMode(Mode mode, bool force) {
64 intended_mode_ = mode; 67 intended_mode_ = mode;
65 68
66 // If the change is forced, or the user isn't hovering the icon, or it's safe 69 // If the change is forced, or the user isn't hovering the icon, or it's safe
67 // to change it to the other image type, make the change immediately; 70 // to change it to the other image type, make the change immediately;
68 // otherwise we'll let it happen later. 71 // otherwise we'll let it happen later.
69 if (force || (!IsMouseHovered() && !testing_mouse_hovered_) || 72 if (force || (!IsMouseHovered() && !testing_mouse_hovered_) ||
70 ((mode == MODE_STOP) ? 73 ((mode == MODE_STOP) ?
71 !double_click_timer_.IsRunning() : (visible_mode_ != MODE_STOP))) { 74 !double_click_timer_.IsRunning() : (visible_mode_ != MODE_STOP))) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 for (int i = 0; i < STATE_COUNT; i++) { 106 for (int i = 0; i < STATE_COUNT; i++) {
104 reload_images[i] = *(tp->GetImageSkiaNamed(kReloadImages[i])); 107 reload_images[i] = *(tp->GetImageSkiaNamed(kReloadImages[i]));
105 stop_images[i] = *(tp->GetImageSkiaNamed(kStopImages[i])); 108 stop_images[i] = *(tp->GetImageSkiaNamed(kStopImages[i]));
106 } 109 }
107 110
108 SchedulePaint(); 111 SchedulePaint();
109 PreferredSizeChanged(); 112 PreferredSizeChanged();
110 } 113 }
111 114
112 void ReloadButton::OnMouseExited(const ui::MouseEvent& event) { 115 void ReloadButton::OnMouseExited(const ui::MouseEvent& event) {
113 ButtonDropDown::OnMouseExited(event); 116 ToolbarButton::OnMouseExited(event);
114 if (!IsMenuShowing()) 117 if (!IsMenuShowing())
115 ChangeMode(intended_mode_, true); 118 ChangeMode(intended_mode_, true);
116 } 119 }
117 120
118 bool ReloadButton::GetTooltipText(const gfx::Point& p, 121 bool ReloadButton::GetTooltipText(const gfx::Point& p,
119 string16* tooltip) const { 122 string16* tooltip) const {
120 int reload_tooltip = menu_enabled_ ? 123 int reload_tooltip = menu_enabled_ ?
121 IDS_TOOLTIP_RELOAD_WITH_MENU : IDS_TOOLTIP_RELOAD; 124 IDS_TOOLTIP_RELOAD_WITH_MENU : IDS_TOOLTIP_RELOAD;
122 int text_id = (visible_mode_ == MODE_RELOAD) ? 125 int text_id = (visible_mode_ == MODE_RELOAD) ?
123 reload_tooltip : IDS_TOOLTIP_STOP; 126 reload_tooltip : IDS_TOOLTIP_STOP;
124 tooltip->assign(l10n_util::GetStringUTF16(text_id)); 127 tooltip->assign(l10n_util::GetStringUTF16(text_id));
125 return true; 128 return true;
126 } 129 }
127 130
128 const char* ReloadButton::GetClassName() const { 131 const char* ReloadButton::GetClassName() const {
129 return kViewClassName; 132 return kViewClassName;
130 } 133 }
131 134
132 void ReloadButton::GetAccessibleState(ui::AccessibleViewState* state) { 135 void ReloadButton::GetAccessibleState(ui::AccessibleViewState* state) {
133 if (menu_enabled_) 136 if (menu_enabled_)
134 ButtonDropDown::GetAccessibleState(state); 137 ToolbarButton::GetAccessibleState(state);
135 else 138 else
136 CustomButton::GetAccessibleState(state); 139 CustomButton::GetAccessibleState(state);
137 } 140 }
138 141
139 bool ReloadButton::ShouldShowMenu() { 142 bool ReloadButton::ShouldShowMenu() {
140 return menu_enabled_ && (visible_mode_ == MODE_RELOAD); 143 return menu_enabled_ && (visible_mode_ == MODE_RELOAD);
141 } 144 }
142 145
143 void ReloadButton::ShowDropDownMenu(ui::MenuSourceType source_type) { 146 void ReloadButton::ShowDropDownMenu(ui::MenuSourceType source_type) {
144 ButtonDropDown::ShowDropDownMenu(source_type); // Blocks. 147 ToolbarButton::ShowDropDownMenu(source_type); // Blocks.
145 ChangeMode(intended_mode_, true); 148 ChangeMode(intended_mode_, true);
146 } 149 }
147 150
148 void ReloadButton::ButtonPressed(views::Button* /* button */, 151 void ReloadButton::ButtonPressed(views::Button* /* button */,
149 const ui::Event& event) { 152 const ui::Event& event) {
150 ClearPendingMenu(); 153 ClearPendingMenu();
151 154
152 if (visible_mode_ == MODE_STOP) { 155 if (visible_mode_ == MODE_STOP) {
153 if (command_updater_) 156 if (command_updater_)
154 command_updater_->ExecuteCommandWithDisposition(IDC_STOP, CURRENT_TAB); 157 command_updater_->ExecuteCommandWithDisposition(IDC_STOP, CURRENT_TAB);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // action. 247 // action.
245 location_bar_->Revert(); 248 location_bar_->Revert();
246 } 249 }
247 command_updater_->ExecuteCommandWithDisposition(command, disposition); 250 command_updater_->ExecuteCommandWithDisposition(command, disposition);
248 } 251 }
249 252
250 void ReloadButton::ChangeModeInternal(Mode mode) { 253 void ReloadButton::ChangeModeInternal(Mode mode) {
251 if (visible_mode_ == mode) 254 if (visible_mode_ == mode)
252 return; 255 return;
253 256
254 for (size_t i = 0; i < STATE_COUNT; ++i) 257 for (size_t i = 0; i < STATE_COUNT; ++i) {
255 std::swap(images_[i], alternate_images_[i]); 258 std::swap(images_[i], alternate_images_[i]);
Peter Kasting 2013/11/15 03:28:58 Nit: It seems like at the least we could name thes
Greg Billock 2013/11/15 19:36:50 It's in the guts of ButtonDropDown > ImageButton,
259 SetImage((views::Button::ButtonState)i, images_[i]);
Peter Kasting 2013/11/15 03:28:58 Nit: Don't use C-style casts
Greg Billock 2013/11/15 19:36:50 Done.
260 }
261
256 visible_mode_ = mode; 262 visible_mode_ = mode;
257 SchedulePaint(); 263 SchedulePaint();
258 } 264 }
259 265
260 void ReloadButton::OnDoubleClickTimer() { 266 void ReloadButton::OnDoubleClickTimer() {
261 if (!IsMenuShowing()) 267 if (!IsMenuShowing())
262 ChangeMode(intended_mode_, false); 268 ChangeMode(intended_mode_, false);
263 } 269 }
264 270
265 void ReloadButton::OnStopToReloadTimer() { 271 void ReloadButton::OnStopToReloadTimer() {
266 DCHECK(!IsMenuShowing()); 272 DCHECK(!IsMenuShowing());
267 ChangeMode(intended_mode_, true); 273 ChangeMode(intended_mode_, true);
268 } 274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698