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

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/app_toolbar_button.mm

Issue 2859903003: [Mac] App Menu Animated Icon (Closed)
Patch Set: Fixes for rsesek, created a bridge 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h" 5 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h"
6 6
7 #include "base/command_line.h"
7 #include "base/macros.h" 8 #include "base/macros.h"
8 #include "chrome/app/vector_icons/vector_icons.h" 9 #include "chrome/app/vector_icons/vector_icons.h"
9 #import "chrome/browser/ui/cocoa/themed_window.h" 10 #import "chrome/browser/ui/cocoa/themed_window.h"
10 #import "chrome/browser/ui/cocoa/view_id_util.h" 11 #import "chrome/browser/ui/cocoa/view_id_util.h"
12 #include "chrome/browser/ui/toolbar/app_menu_animation.h"
13 #include "chrome/common/chrome_switches.h"
11 #include "chrome/grit/chromium_strings.h" 14 #include "chrome/grit/chromium_strings.h"
15 #include "skia/ext/skia_utils_mac.h"
12 #include "ui/base/l10n/l10n_util_mac.h" 16 #include "ui/base/l10n/l10n_util_mac.h"
13 #include "ui/base/material_design/material_design_controller.h" 17 #include "ui/base/material_design/material_design_controller.h"
14 #include "ui/base/theme_provider.h" 18 #include "ui/base/theme_provider.h"
15 #include "ui/gfx/color_palette.h" 19 #include "ui/gfx/color_palette.h"
20 #include "ui/gfx/skia_util.h"
21
22 namespace {
23
24 // The radius of each dot.
25 constexpr float kDotRadius = 8.0f;
26
27 // The size of the icon.
28 constexpr float kIconSize = 16.0f;
29
30 } // namespace
31
32 class AppMenuBridgeCocoa : public AppMenuAnimationDelegate {
33 public:
34 AppMenuBridgeCocoa(AppToolbarButton* owner);
35
36 // AppMenuAnimationDelegate:
37 void PaintDot(const gfx::PointF point,
38 SkColor color,
39 gfx::SizeF size,
40 gfx::Canvas* canvas) override;
41
42 void AppMenuAnimationStarted() override;
43 void AppMenuAnimationEnded() override;
44 void InvalidateIcon() override;
45
46 private:
47 AppToolbarButton* owner_;
48 };
49
50 AppMenuBridgeCocoa::AppMenuBridgeCocoa(AppToolbarButton* owner)
51 : owner_(owner) {}
52
53 void AppMenuBridgeCocoa::PaintDot(const gfx::PointF point,
54 SkColor color,
55 gfx::SizeF size,
56 gfx::Canvas* canvas) {
57 NSRect rect = NSMakeRect(point.x(), point.y(), size.width(), size.height());
58
59 [skia::SkColorToSRGBNSColor(color) set];
60 [[NSBezierPath bezierPathWithRoundedRect:rect
61 xRadius:kDotRadius
62 yRadius:kDotRadius] fill];
63 }
64
65 void AppMenuBridgeCocoa::AppMenuAnimationStarted() {}
66
67 void AppMenuBridgeCocoa::AppMenuAnimationEnded() {}
68
69 void AppMenuBridgeCocoa::InvalidateIcon() {
70 [owner_ setNeedsDisplay:YES];
71 }
16 72
17 @interface AppToolbarButton () 73 @interface AppToolbarButton ()
18 - (void)commonInit; 74 - (void)commonInit;
19 @end 75 @end
20 76
21 @implementation AppToolbarButton 77 @implementation AppToolbarButton
22 78
23 - (instancetype)initWithFrame:(NSRect)frame { 79 - (instancetype)initWithFrame:(NSRect)frame {
24 if ((self = [super initWithFrame:frame])) { 80 if ((self = [super initWithFrame:frame])) {
25 [self commonInit]; 81 [self commonInit];
82
83 base::CommandLine* commandLine = base::CommandLine::ForCurrentProcess();
84 if (commandLine->HasSwitch(switches::kEnableNewAppMenuIcon)) {
85 appMenuBridge_.reset(new AppMenuBridgeCocoa(self));
86 appMenuAnimation_.reset(new AppMenuAnimation(
87 appMenuBridge_.get(),
88 [self vectorIconColor:[[self window] hasDarkTheme]]));
89 }
26 } 90 }
27 return self; 91 return self;
28 } 92 }
29 93
30 - (void)awakeFromNib { 94 - (void)awakeFromNib {
31 [self commonInit]; 95 [self commonInit];
32 } 96 }
33 97
98 - (void)drawRect:(NSRect)frame {
99 [super drawRect:frame];
100
101 if (appMenuAnimation_) {
102 NSRect imageFrame = NSInsetRect(frame, (NSWidth(frame) - kIconSize) / 2,
103 (NSHeight(frame) - kIconSize) / 2);
104 appMenuAnimation_->PaintAppMenu(nullptr, gfx::Rect(imageFrame));
105 }
106 }
107
34 - (void)commonInit { 108 - (void)commonInit {
35 view_id_util::SetID(self, VIEW_ID_APP_MENU); 109 view_id_util::SetID(self, VIEW_ID_APP_MENU);
36 severity_ = AppMenuIconController::Severity::NONE; 110 severity_ = AppMenuIconController::Severity::NONE;
37 type_ = AppMenuIconController::IconType::NONE; 111 type_ = AppMenuIconController::IconType::NONE;
38 [self setToolTip:l10n_util::GetNSString(IDS_APPMENU_TOOLTIP)]; 112 [self setToolTip:l10n_util::GetNSString(IDS_APPMENU_TOOLTIP)];
39 } 113 }
40 114
41 - (const gfx::VectorIcon*)vectorIcon { 115 - (const gfx::VectorIcon*)vectorIcon {
116 // The new app menu icon doesn't use vectors.
117 if (appMenuAnimation_)
118 return nullptr;
119
42 switch (type_) { 120 switch (type_) {
43 case AppMenuIconController::IconType::NONE: 121 case AppMenuIconController::IconType::NONE:
44 DCHECK_EQ(severity_, AppMenuIconController::Severity::NONE); 122 DCHECK_EQ(severity_, AppMenuIconController::Severity::NONE);
45 return &kBrowserToolsIcon; 123 return &kBrowserToolsIcon;
46 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION: 124 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION:
47 return &kBrowserToolsUpdateIcon; 125 return &kBrowserToolsUpdateIcon;
48 case AppMenuIconController::IconType::GLOBAL_ERROR: 126 case AppMenuIconController::IconType::GLOBAL_ERROR:
49 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING: 127 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING:
50 return &kBrowserToolsErrorIcon; 128 return &kBrowserToolsErrorIcon;
51 } 129 }
(...skipping 27 matching lines...) Expand all
79 break; 157 break;
80 } 158 }
81 } 159 }
82 160
83 - (void)setSeverity:(AppMenuIconController::Severity)severity 161 - (void)setSeverity:(AppMenuIconController::Severity)severity
84 iconType:(AppMenuIconController::IconType)type 162 iconType:(AppMenuIconController::IconType)type
85 shouldAnimate:(BOOL)shouldAnimate { 163 shouldAnimate:(BOOL)shouldAnimate {
86 if (severity != severity_ || type != type_) { 164 if (severity != severity_ || type != type_) {
87 severity_ = severity; 165 severity_ = severity;
88 type_ = type; 166 type_ = type;
89 // Update the button state images with the new severity color or icon type. 167
90 [self resetButtonStateImages]; 168 if (appMenuAnimation_) {
169 appMenuAnimation_->set_target_color(
170 [self vectorIconColor:[[self window] hasDarkTheme]]);
171 appMenuAnimation_->StartAnimation();
172 } else {
173 // Update the button state images with the new severity color or icon
174 // type.
175 [self resetButtonStateImages];
176 }
91 } 177 }
92 } 178 }
93 179
180 - (void)onTabInsertedInForeground {
181 if (appMenuAnimation_ && severity_ != AppMenuIconController::Severity::NONE)
182 appMenuAnimation_->StartAnimation();
183 }
184
185 - (void)willShowMenu {
186 if (appMenuAnimation_ && severity_ != AppMenuIconController::Severity::NONE)
187 appMenuAnimation_->StartAnimation();
188 }
189
94 @end 190 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h ('k') | chrome/browser/ui/toolbar/app_menu_animation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698