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

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

Issue 2843413003: [Views] App Menu Icon Update (Closed)
Patch Set: Fixes for msw Created 3 years, 7 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
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_button.h" 5 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 29 matching lines...) Expand all
40 } // namespace 40 } // namespace
41 41
42 // static 42 // static
43 bool AppMenuButton::g_open_app_immediately_for_testing = false; 43 bool AppMenuButton::g_open_app_immediately_for_testing = false;
44 44
45 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view) 45 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view)
46 : views::MenuButton(base::string16(), toolbar_view, false), 46 : views::MenuButton(base::string16(), toolbar_view, false),
47 severity_(AppMenuIconController::Severity::NONE), 47 severity_(AppMenuIconController::Severity::NONE),
48 type_(AppMenuIconController::IconType::NONE), 48 type_(AppMenuIconController::IconType::NONE),
49 toolbar_view_(toolbar_view), 49 toolbar_view_(toolbar_view),
50 should_use_new_icon_(false),
50 margin_trailing_(0), 51 margin_trailing_(0),
51 weak_factory_(this) { 52 weak_factory_(this) {
52 SetInkDropMode(InkDropMode::ON); 53 SetInkDropMode(InkDropMode::ON);
53 SetFocusPainter(nullptr); 54 SetFocusPainter(nullptr);
54 55
55 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 56 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
56 if (command_line->HasSwitch(switches::kAppMenuIcon)) { 57 if (command_line->HasSwitch(switches::kEnableNewAppMenuIcon)) {
57 std::string flag = 58 toolbar_view_->browser()->tab_strip_model()->AddObserver(this);
58 command_line->GetSwitchValueASCII(switches::kAppMenuIcon); 59 should_use_new_icon_ = true;
59 if (flag == switches::kAppMenuIconPersistentClosedState) {
60 Browser* browser = toolbar_view_->browser();
61 browser->tab_strip_model()->AddObserver(this);
62 animation_ = base::MakeUnique<AppMenuAnimation>(this, true);
63 } else if (flag == switches::kAppMenuIconPersistentOpenedState) {
64 animation_ = base::MakeUnique<AppMenuAnimation>(this, false);
65 }
66 } 60 }
67 } 61 }
68 62
69 AppMenuButton::~AppMenuButton() {} 63 AppMenuButton::~AppMenuButton() {}
70 64
71 void AppMenuButton::SetSeverity(AppMenuIconController::IconType type, 65 void AppMenuButton::SetSeverity(AppMenuIconController::IconType type,
72 AppMenuIconController::Severity severity, 66 AppMenuIconController::Severity severity,
73 bool animate) { 67 bool animate) {
74 type_ = type; 68 type_ = type;
75 severity_ = severity; 69 severity_ = severity;
(...skipping 26 matching lines...) Expand all
102 menu_->RunMenu(this); 96 menu_->RunMenu(this);
103 97
104 if (!for_drop) { 98 if (!for_drop) {
105 // Record the time-to-action for the menu. We don't record in the case of a 99 // Record the time-to-action for the menu. We don't record in the case of a
106 // drag-and-drop command because menus opened for drag-and-drop don't block 100 // drag-and-drop command because menus opened for drag-and-drop don't block
107 // the message loop. 101 // the message loop.
108 UMA_HISTOGRAM_TIMES("Toolbar.AppMenuTimeToAction", 102 UMA_HISTOGRAM_TIMES("Toolbar.AppMenuTimeToAction",
109 base::TimeTicks::Now() - menu_open_time); 103 base::TimeTicks::Now() - menu_open_time);
110 } 104 }
111 105
112 if (animation_ && severity_ != AppMenuIconController::Severity::NONE) 106 AnimateIconIfPossible();
113 animation_->StartAnimation();
114 } 107 }
115 108
116 void AppMenuButton::CloseMenu() { 109 void AppMenuButton::CloseMenu() {
117 if (menu_) 110 if (menu_)
118 menu_->CloseMenu(); 111 menu_->CloseMenu();
119 menu_.reset(); 112 menu_.reset();
120 } 113 }
121 114
122 bool AppMenuButton::IsMenuShowing() const { 115 bool AppMenuButton::IsMenuShowing() const {
123 return menu_ && menu_->IsShowing(); 116 return menu_ && menu_->IsShowing();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 148
156 gfx::Rect bounds = GetLocalBounds(); 149 gfx::Rect bounds = GetLocalBounds();
157 bounds.Inset(gfx::Insets(ToolbarButton::kInteriorPadding)); 150 bounds.Inset(gfx::Insets(ToolbarButton::kInteriorPadding));
158 animation_->PaintAppMenu(canvas, bounds); 151 animation_->PaintAppMenu(canvas, bounds);
159 } 152 }
160 153
161 void AppMenuButton::TabInsertedAt(TabStripModel* tab_strip_model, 154 void AppMenuButton::TabInsertedAt(TabStripModel* tab_strip_model,
162 content::WebContents* contents, 155 content::WebContents* contents,
163 int index, 156 int index,
164 bool foreground) { 157 bool foreground) {
165 if (severity_ != AppMenuIconController::Severity::NONE) 158 AnimateIconIfPossible();
166 animation_->StartAnimation();
167 } 159 }
168 160
169 void AppMenuButton::UpdateIcon(bool should_animate) { 161 void AppMenuButton::UpdateIcon(bool should_animate) {
170 SkColor severity_color = gfx::kPlaceholderColor; 162 SkColor severity_color = gfx::kPlaceholderColor;
171 SkColor toolbar_icon_color = 163 SkColor toolbar_icon_color =
172 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); 164 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
173 const ui::NativeTheme* native_theme = GetNativeTheme(); 165 const ui::NativeTheme* native_theme = GetNativeTheme();
174 switch (severity_) { 166 switch (severity_) {
175 case AppMenuIconController::Severity::NONE: 167 case AppMenuIconController::Severity::NONE:
176 severity_color = toolbar_icon_color; 168 severity_color = toolbar_icon_color;
177 break; 169 break;
178 case AppMenuIconController::Severity::LOW: 170 case AppMenuIconController::Severity::LOW:
179 severity_color = native_theme->GetSystemColor( 171 severity_color = native_theme->GetSystemColor(
180 ui::NativeTheme::kColorId_AlertSeverityLow); 172 ui::NativeTheme::kColorId_AlertSeverityLow);
181 break; 173 break;
182 case AppMenuIconController::Severity::MEDIUM: 174 case AppMenuIconController::Severity::MEDIUM:
183 severity_color = native_theme->GetSystemColor( 175 severity_color = native_theme->GetSystemColor(
184 ui::NativeTheme::kColorId_AlertSeverityMedium); 176 ui::NativeTheme::kColorId_AlertSeverityMedium);
185 break; 177 break;
186 case AppMenuIconController::Severity::HIGH: 178 case AppMenuIconController::Severity::HIGH:
187 severity_color = native_theme->GetSystemColor( 179 severity_color = native_theme->GetSystemColor(
188 ui::NativeTheme::kColorId_AlertSeverityHigh); 180 ui::NativeTheme::kColorId_AlertSeverityHigh);
189 break; 181 break;
190 } 182 }
191 183
192 if (animation_) { 184 if (should_use_new_icon_) {
193 animation_->SetIconColors(toolbar_icon_color, severity_color); 185 // |animation_| is created here instead of the constructor because the
msw 2017/04/29 00:55:05 optional nit: I think it's okay to remove this com
spqchan 2017/04/29 02:34:42 Done.
186 // theme provider is necessary to provide the correct initial toolbar
187 // icon color.
188 if (!animation_)
189 animation_ = base::MakeUnique<AppMenuAnimation>(this, toolbar_icon_color);
190
191 animation_->set_severity_color(severity_color);
194 if (should_animate) 192 if (should_animate)
195 animation_->StartAnimation(); 193 AnimateIconIfPossible();
194
196 return; 195 return;
197 } 196 }
198 197
199 const gfx::VectorIcon* icon_id = nullptr; 198 const gfx::VectorIcon* icon_id = nullptr;
200 switch (type_) { 199 switch (type_) {
201 case AppMenuIconController::IconType::NONE: 200 case AppMenuIconController::IconType::NONE:
202 icon_id = &kBrowserToolsIcon; 201 icon_id = &kBrowserToolsIcon;
203 DCHECK_EQ(AppMenuIconController::Severity::NONE, severity_); 202 DCHECK_EQ(AppMenuIconController::Severity::NONE, severity_);
204 break; 203 break;
205 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION: 204 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION:
206 icon_id = &kBrowserToolsUpdateIcon; 205 icon_id = &kBrowserToolsUpdateIcon;
207 break; 206 break;
208 case AppMenuIconController::IconType::GLOBAL_ERROR: 207 case AppMenuIconController::IconType::GLOBAL_ERROR:
209 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING: 208 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING:
210 icon_id = &kBrowserToolsErrorIcon; 209 icon_id = &kBrowserToolsErrorIcon;
211 break; 210 break;
212 } 211 }
213 212
214 SetImage(views::Button::STATE_NORMAL, 213 SetImage(views::Button::STATE_NORMAL,
215 gfx::CreateVectorIcon(*icon_id, severity_color)); 214 gfx::CreateVectorIcon(*icon_id, severity_color));
216 } 215 }
217 216
218 void AppMenuButton::SetTrailingMargin(int margin) { 217 void AppMenuButton::SetTrailingMargin(int margin) {
219 margin_trailing_ = margin; 218 margin_trailing_ = margin;
220 UpdateThemedBorder(); 219 UpdateThemedBorder();
221 InvalidateLayout(); 220 InvalidateLayout();
222 } 221 }
223 222
223 void AppMenuButton::AnimateIconIfPossible() {
224 if (!should_use_new_icon_ ||
225 severity_ == AppMenuIconController::Severity::NONE || !animation_) {
msw 2017/04/29 00:55:05 optional nit: reorder to check animation earlier:
spqchan 2017/04/29 02:34:42 Done.
226 return;
227 }
228
229 animation_->StartAnimation();
230 }
231
224 void AppMenuButton::AppMenuAnimationStarted() { 232 void AppMenuButton::AppMenuAnimationStarted() {
225 SetPaintToLayer(); 233 SetPaintToLayer();
226 layer()->SetFillsBoundsOpaquely(false); 234 layer()->SetFillsBoundsOpaquely(false);
227 } 235 }
228 236
229 void AppMenuButton::AppMenuAnimationEnded() { 237 void AppMenuButton::AppMenuAnimationEnded() {
230 DestroyLayer(); 238 DestroyLayer();
231 } 239 }
232 240
233 const char* AppMenuButton::GetClassName() const { 241 const char* AppMenuButton::GetClassName() const {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return ui::DragDropTypes::DRAG_MOVE; 295 return ui::DragDropTypes::DRAG_MOVE;
288 } 296 }
289 297
290 void AppMenuButton::OnDragExited() { 298 void AppMenuButton::OnDragExited() {
291 weak_factory_.InvalidateWeakPtrs(); 299 weak_factory_.InvalidateWeakPtrs();
292 } 300 }
293 301
294 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) { 302 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) {
295 return ui::DragDropTypes::DRAG_MOVE; 303 return ui::DragDropTypes::DRAG_MOVE;
296 } 304 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698