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

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
« no previous file with comments | « chrome/browser/ui/views/toolbar/app_menu_button.h ('k') | chrome/common/chrome_switches.h » ('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/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 if (!animation_)
186 animation_ = base::MakeUnique<AppMenuAnimation>(this, toolbar_icon_color);
187
188 animation_->set_target_color(severity_color);
194 if (should_animate) 189 if (should_animate)
195 animation_->StartAnimation(); 190 AnimateIconIfPossible();
191
196 return; 192 return;
197 } 193 }
198 194
199 const gfx::VectorIcon* icon_id = nullptr; 195 const gfx::VectorIcon* icon_id = nullptr;
200 switch (type_) { 196 switch (type_) {
201 case AppMenuIconController::IconType::NONE: 197 case AppMenuIconController::IconType::NONE:
202 icon_id = &kBrowserToolsIcon; 198 icon_id = &kBrowserToolsIcon;
203 DCHECK_EQ(AppMenuIconController::Severity::NONE, severity_); 199 DCHECK_EQ(AppMenuIconController::Severity::NONE, severity_);
204 break; 200 break;
205 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION: 201 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION:
206 icon_id = &kBrowserToolsUpdateIcon; 202 icon_id = &kBrowserToolsUpdateIcon;
207 break; 203 break;
208 case AppMenuIconController::IconType::GLOBAL_ERROR: 204 case AppMenuIconController::IconType::GLOBAL_ERROR:
209 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING: 205 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING:
210 icon_id = &kBrowserToolsErrorIcon; 206 icon_id = &kBrowserToolsErrorIcon;
211 break; 207 break;
212 } 208 }
213 209
214 SetImage(views::Button::STATE_NORMAL, 210 SetImage(views::Button::STATE_NORMAL,
215 gfx::CreateVectorIcon(*icon_id, severity_color)); 211 gfx::CreateVectorIcon(*icon_id, severity_color));
216 } 212 }
217 213
218 void AppMenuButton::SetTrailingMargin(int margin) { 214 void AppMenuButton::SetTrailingMargin(int margin) {
219 margin_trailing_ = margin; 215 margin_trailing_ = margin;
220 UpdateThemedBorder(); 216 UpdateThemedBorder();
221 InvalidateLayout(); 217 InvalidateLayout();
222 } 218 }
223 219
220 void AppMenuButton::AnimateIconIfPossible() {
221 if (!animation_ || !should_use_new_icon_ ||
222 severity_ == AppMenuIconController::Severity::NONE) {
223 return;
224 }
225
226 animation_->StartAnimation();
227 }
228
224 void AppMenuButton::AppMenuAnimationStarted() { 229 void AppMenuButton::AppMenuAnimationStarted() {
225 SetPaintToLayer(); 230 SetPaintToLayer();
226 layer()->SetFillsBoundsOpaquely(false); 231 layer()->SetFillsBoundsOpaquely(false);
227 } 232 }
228 233
229 void AppMenuButton::AppMenuAnimationEnded() { 234 void AppMenuButton::AppMenuAnimationEnded() {
230 DestroyLayer(); 235 DestroyLayer();
231 } 236 }
232 237
233 const char* AppMenuButton::GetClassName() const { 238 const char* AppMenuButton::GetClassName() const {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return ui::DragDropTypes::DRAG_MOVE; 292 return ui::DragDropTypes::DRAG_MOVE;
288 } 293 }
289 294
290 void AppMenuButton::OnDragExited() { 295 void AppMenuButton::OnDragExited() {
291 weak_factory_.InvalidateWeakPtrs(); 296 weak_factory_.InvalidateWeakPtrs();
292 } 297 }
293 298
294 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) { 299 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) {
295 return ui::DragDropTypes::DRAG_MOVE; 300 return ui::DragDropTypes::DRAG_MOVE;
296 } 301 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/app_menu_button.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698