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

Unified Diff: chrome/browser/ui/cocoa/toolbar/app_toolbar_button.mm

Issue 2859903003: [Mac] App Menu Animated Icon (Closed)
Patch Set: Switch to CanvasSkiaPaint 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/toolbar/app_toolbar_button.mm
diff --git a/chrome/browser/ui/cocoa/toolbar/app_toolbar_button.mm b/chrome/browser/ui/cocoa/toolbar/app_toolbar_button.mm
index 14396d582c0f2605a439307f4fe5e65d31eb6eff..f758388a470997fe80554ca7257c04ee64306f64 100644
--- a/chrome/browser/ui/cocoa/toolbar/app_toolbar_button.mm
+++ b/chrome/browser/ui/cocoa/toolbar/app_toolbar_button.mm
@@ -4,15 +4,51 @@
#import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h"
+#include "base/command_line.h"
#include "base/macros.h"
#include "chrome/app/vector_icons/vector_icons.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
+#include "chrome/browser/ui/toolbar/app_menu_animation.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/grit/chromium_strings.h"
+#include "skia/ext/skia_utils_mac.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/theme_provider.h"
+#include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/color_palette.h"
+#include "ui/gfx/skia_util.h"
+
+namespace {
+
+// The size of the icon.
+constexpr float kIconSize = 16.0f;
+
+} // namespace
+
+class AppMenuBridgeCocoa : public AppMenuAnimationDelegate {
+ public:
+ AppMenuBridgeCocoa(AppToolbarButton* owner);
+
+ void AppMenuAnimationStarted() override;
+ void AppMenuAnimationEnded() override;
+ void InvalidateIcon() override;
+
+ private:
+ AppToolbarButton* owner_;
+};
+
+AppMenuBridgeCocoa::AppMenuBridgeCocoa(AppToolbarButton* owner)
+ : owner_(owner) {}
+
+void AppMenuBridgeCocoa::AppMenuAnimationStarted() {}
+
+void AppMenuBridgeCocoa::AppMenuAnimationEnded() {}
+
+void AppMenuBridgeCocoa::InvalidateIcon() {
+ [owner_ setNeedsDisplay:YES];
+}
@interface AppToolbarButton ()
- (void)commonInit;
@@ -23,6 +59,14 @@
- (instancetype)initWithFrame:(NSRect)frame {
if ((self = [super initWithFrame:frame])) {
[self commonInit];
+
+ base::CommandLine* commandLine = base::CommandLine::ForCurrentProcess();
+ if (commandLine->HasSwitch(switches::kEnableNewAppMenuIcon)) {
+ appMenuBridge_.reset(new AppMenuBridgeCocoa(self));
+ appMenuAnimation_.reset(new AppMenuAnimation(
+ appMenuBridge_.get(),
+ [self vectorIconColor:[[self window] hasDarkTheme]]));
+ }
}
return self;
}
@@ -31,6 +75,19 @@
[self commonInit];
}
+- (void)drawRect:(NSRect)frame {
+ [super drawRect:frame];
+
+ if (appMenuAnimation_) {
+ NSRect imageFrame = NSInsetRect(frame, (NSWidth(frame) - kIconSize) / 2,
+ (NSHeight(frame) - kIconSize) / 2);
+ gfx::CanvasSkiaPaint canvas(imageFrame, false);
+ canvas.set_composite_alpha(true);
+ appMenuAnimation_->PaintAppMenu(&canvas, gfx::Rect(imageFrame));
+ canvas.Restore();
+ }
+}
+
- (void)commonInit {
view_id_util::SetID(self, VIEW_ID_APP_MENU);
severity_ = AppMenuIconController::Severity::NONE;
@@ -39,6 +96,10 @@
}
- (const gfx::VectorIcon*)vectorIcon {
+ // The new app menu icon doesn't use vectors.
+ if (appMenuAnimation_)
+ return nullptr;
+
switch (type_) {
case AppMenuIconController::IconType::NONE:
DCHECK_EQ(severity_, AppMenuIconController::Severity::NONE);
@@ -86,9 +147,27 @@
if (severity != severity_ || type != type_) {
severity_ = severity;
type_ = type;
- // Update the button state images with the new severity color or icon type.
- [self resetButtonStateImages];
+
+ if (appMenuAnimation_) {
+ appMenuAnimation_->set_target_color(
+ [self vectorIconColor:[[self window] hasDarkTheme]]);
+ appMenuAnimation_->StartAnimation();
+ } else {
+ // Update the button state images with the new severity color or icon
+ // type.
+ [self resetButtonStateImages];
+ }
}
}
+- (void)onTabInsertedInForeground {
+ if (appMenuAnimation_ && severity_ != AppMenuIconController::Severity::NONE)
+ appMenuAnimation_->StartAnimation();
+}
+
+- (void)willShowMenu {
+ if (appMenuAnimation_ && severity_ != AppMenuIconController::Severity::NONE)
+ appMenuAnimation_->StartAnimation();
+}
+
@end
« 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