| OLD | NEW |
| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #import "chrome/browser/ui/cocoa/themed_window.h" | 8 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 9 #import "chrome/browser/ui/cocoa/view_id_util.h" | 9 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 10 #include "ui/base/material_design/material_design_controller.h" | 10 #include "ui/base/material_design/material_design_controller.h" |
| 11 #include "ui/gfx/color_palette.h" | 11 #include "ui/gfx/color_palette.h" |
| 12 | 12 |
| 13 class AppMenuButtonIconPainterDelegateMac : | |
| 14 public AppMenuIconPainter::Delegate { | |
| 15 public: | |
| 16 explicit AppMenuButtonIconPainterDelegateMac(NSButton* button) : | |
| 17 button_(button) {} | |
| 18 ~AppMenuButtonIconPainterDelegateMac() override {} | |
| 19 | |
| 20 void ScheduleAppMenuIconPaint() override { | |
| 21 [button_ setNeedsDisplay:YES]; | |
| 22 } | |
| 23 | |
| 24 private: | |
| 25 NSButton* button_; | |
| 26 | |
| 27 DISALLOW_COPY_AND_ASSIGN(AppMenuButtonIconPainterDelegateMac); | |
| 28 }; | |
| 29 | |
| 30 @interface AppToolbarButton () | 13 @interface AppToolbarButton () |
| 31 - (void)commonInit; | 14 - (void)commonInit; |
| 32 @end | 15 @end |
| 33 | 16 |
| 34 @implementation AppToolbarButton | 17 @implementation AppToolbarButton |
| 35 | 18 |
| 36 - (instancetype)initWithFrame:(NSRect)frame { | 19 - (instancetype)initWithFrame:(NSRect)frame { |
| 37 if ((self = [super initWithFrame:frame])) { | 20 if ((self = [super initWithFrame:frame])) { |
| 38 [self commonInit]; | 21 [self commonInit]; |
| 39 } | 22 } |
| 40 return self; | 23 return self; |
| 41 } | 24 } |
| 42 | 25 |
| 43 - (void)awakeFromNib { | 26 - (void)awakeFromNib { |
| 44 [self commonInit]; | 27 [self commonInit]; |
| 45 } | 28 } |
| 46 | 29 |
| 47 - (void)commonInit { | 30 - (void)commonInit { |
| 48 view_id_util::SetID(self, VIEW_ID_APP_MENU); | 31 view_id_util::SetID(self, VIEW_ID_APP_MENU); |
| 49 delegate_.reset(new AppMenuButtonIconPainterDelegateMac(self)); | 32 severity_ = AppMenuIconController::Severity::NONE; |
| 50 severity_ = AppMenuIconPainter::Severity::SEVERITY_NONE; | |
| 51 type_ = AppMenuIconController::IconType::NONE; | 33 type_ = AppMenuIconController::IconType::NONE; |
| 52 } | 34 } |
| 53 | 35 |
| 54 - (gfx::VectorIconId)vectorIconId { | 36 - (gfx::VectorIconId)vectorIconId { |
| 55 switch (type_) { | 37 switch (type_) { |
| 56 case AppMenuIconController::IconType::NONE: | 38 case AppMenuIconController::IconType::NONE: |
| 57 DCHECK_EQ(severity_, AppMenuIconPainter::SEVERITY_NONE); | 39 DCHECK_EQ(severity_, AppMenuIconController::Severity::NONE); |
| 58 return gfx::VectorIconId::BROWSER_TOOLS; | 40 return gfx::VectorIconId::BROWSER_TOOLS; |
| 59 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION: | 41 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION: |
| 60 return gfx::VectorIconId::BROWSER_TOOLS_UPDATE; | 42 return gfx::VectorIconId::BROWSER_TOOLS_UPDATE; |
| 61 case AppMenuIconController::IconType::GLOBAL_ERROR: | 43 case AppMenuIconController::IconType::GLOBAL_ERROR: |
| 62 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING: | 44 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING: |
| 63 return gfx::VectorIconId::BROWSER_TOOLS_ERROR; | 45 return gfx::VectorIconId::BROWSER_TOOLS_ERROR; |
| 64 } | 46 } |
| 65 | 47 |
| 66 return gfx::VectorIconId::VECTOR_ICON_NONE; | 48 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 67 } | 49 } |
| 68 | 50 |
| 69 - (SkColor)vectorIconColor:(BOOL)themeIsDark { | 51 - (SkColor)vectorIconColor:(BOOL)themeIsDark { |
| 70 switch (severity_) { | 52 switch (severity_) { |
| 71 case AppMenuIconPainter::Severity::SEVERITY_NONE: | 53 case AppMenuIconController::Severity::NONE: |
| 72 return themeIsDark ? SK_ColorWHITE : gfx::kChromeIconGrey; | 54 return themeIsDark ? SK_ColorWHITE : gfx::kChromeIconGrey; |
| 73 break; | 55 break; |
| 74 | 56 |
| 75 case AppMenuIconPainter::Severity::SEVERITY_LOW: | 57 case AppMenuIconController::Severity::LOW: |
| 76 return themeIsDark ? gfx::kGoogleGreen300 : gfx::kGoogleGreen700; | 58 return themeIsDark ? gfx::kGoogleGreen300 : gfx::kGoogleGreen700; |
| 77 break; | 59 break; |
| 78 | 60 |
| 79 case AppMenuIconPainter::Severity::SEVERITY_MEDIUM: | 61 case AppMenuIconController::Severity::MEDIUM: |
| 80 return themeIsDark ? gfx::kGoogleYellow300 : gfx::kGoogleYellow700; | 62 return themeIsDark ? gfx::kGoogleYellow300 : gfx::kGoogleYellow700; |
| 81 break; | 63 break; |
| 82 | 64 |
| 83 case AppMenuIconPainter::Severity::SEVERITY_HIGH: | 65 case AppMenuIconController::Severity::HIGH: |
| 84 return themeIsDark ? gfx::kGoogleRed300 : gfx::kGoogleRed700; | 66 return themeIsDark ? gfx::kGoogleRed300 : gfx::kGoogleRed700; |
| 85 break; | 67 break; |
| 86 | 68 |
| 87 default: | 69 default: |
| 88 break; | 70 break; |
| 89 } | 71 } |
| 90 } | 72 } |
| 91 | 73 |
| 92 - (void)setSeverity:(AppMenuIconPainter::Severity)severity | 74 - (void)setSeverity:(AppMenuIconController::Severity)severity |
| 93 iconType:(AppMenuIconController::IconType)type | 75 iconType:(AppMenuIconController::IconType)type |
| 94 shouldAnimate:(BOOL)shouldAnimate { | 76 shouldAnimate:(BOOL)shouldAnimate { |
| 95 if (severity != severity_ || type != type_) { | 77 if (severity != severity_ || type != type_) { |
| 96 severity_ = severity; | 78 severity_ = severity; |
| 97 type_ = type; | 79 type_ = type; |
| 98 // Update the button state images with the new severity color or icon type. | 80 // Update the button state images with the new severity color or icon type. |
| 99 [self resetButtonStateImages]; | 81 [self resetButtonStateImages]; |
| 100 } | 82 } |
| 101 } | 83 } |
| 102 | 84 |
| 103 @end | 85 @end |
| OLD | NEW |