Chromium Code Reviews| 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/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" |
| 11 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button_icon.h" | |
| 10 #import "chrome/browser/ui/cocoa/view_id_util.h" | 12 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 13 #include "chrome/common/chrome_switches.h" | |
| 11 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
| 12 #include "ui/base/l10n/l10n_util_mac.h" | 15 #include "ui/base/l10n/l10n_util_mac.h" |
| 13 #include "ui/base/material_design/material_design_controller.h" | 16 #include "ui/base/material_design/material_design_controller.h" |
| 14 #include "ui/base/theme_provider.h" | 17 #include "ui/base/theme_provider.h" |
| 15 #include "ui/gfx/color_palette.h" | 18 #include "ui/gfx/color_palette.h" |
| 16 | 19 |
| 17 @interface AppToolbarButton () | 20 @interface AppToolbarButton () |
| 18 - (void)commonInit; | 21 - (void)commonInit; |
| 19 @end | 22 @end |
| 20 | 23 |
| 21 @implementation AppToolbarButton | 24 @implementation AppToolbarButton |
| 22 | 25 |
| 23 - (instancetype)initWithFrame:(NSRect)frame { | 26 - (instancetype)initWithFrame:(NSRect)frame { |
| 24 if ((self = [super initWithFrame:frame])) { | 27 if ((self = [super initWithFrame:frame])) { |
| 25 [self commonInit]; | 28 [self commonInit]; |
| 29 | |
| 30 base::CommandLine* commandLine = base::CommandLine::ForCurrentProcess(); | |
| 31 if (commandLine->HasSwitch(switches::kEnableNewAppMenuIcon)) { | |
| 32 app_icon_.reset(new AppToolbarButtonIcon( | |
| 33 self, [self vectorIconColor:[[self window] hasDarkTheme]])); | |
| 34 } | |
| 26 } | 35 } |
| 27 return self; | 36 return self; |
| 28 } | 37 } |
| 29 | 38 |
| 30 - (void)awakeFromNib { | 39 - (void)awakeFromNib { |
| 31 [self commonInit]; | 40 [self commonInit]; |
| 32 } | 41 } |
| 33 | 42 |
| 43 - (void)drawRect:(NSRect)frame { | |
| 44 [super drawRect:frame]; | |
| 45 | |
| 46 if (app_icon_) | |
| 47 app_icon_->DrawIcon(frame); | |
| 48 } | |
| 49 | |
| 34 - (void)commonInit { | 50 - (void)commonInit { |
| 35 view_id_util::SetID(self, VIEW_ID_APP_MENU); | 51 view_id_util::SetID(self, VIEW_ID_APP_MENU); |
| 36 severity_ = AppMenuIconController::Severity::NONE; | 52 severity_ = AppMenuIconController::Severity::NONE; |
| 37 type_ = AppMenuIconController::IconType::NONE; | 53 type_ = AppMenuIconController::IconType::NONE; |
| 38 [self setToolTip:l10n_util::GetNSString(IDS_APPMENU_TOOLTIP)]; | 54 [self setToolTip:l10n_util::GetNSString(IDS_APPMENU_TOOLTIP)]; |
| 39 } | 55 } |
| 40 | 56 |
| 41 - (const gfx::VectorIcon*)vectorIcon { | 57 - (const gfx::VectorIcon*)vectorIcon { |
| 58 // The new app menu icon doesn't use vectors. | |
| 59 if (app_icon_) | |
| 60 return nullptr; | |
| 61 | |
| 42 switch (type_) { | 62 switch (type_) { |
| 43 case AppMenuIconController::IconType::NONE: | 63 case AppMenuIconController::IconType::NONE: |
| 44 DCHECK_EQ(severity_, AppMenuIconController::Severity::NONE); | 64 DCHECK_EQ(severity_, AppMenuIconController::Severity::NONE); |
| 45 return &kBrowserToolsIcon; | 65 return &kBrowserToolsIcon; |
| 46 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION: | 66 case AppMenuIconController::IconType::UPGRADE_NOTIFICATION: |
| 47 return &kBrowserToolsUpdateIcon; | 67 return &kBrowserToolsUpdateIcon; |
| 48 case AppMenuIconController::IconType::GLOBAL_ERROR: | 68 case AppMenuIconController::IconType::GLOBAL_ERROR: |
| 49 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING: | 69 case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING: |
| 50 return &kBrowserToolsErrorIcon; | 70 return &kBrowserToolsErrorIcon; |
| 51 } | 71 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 79 break; | 99 break; |
| 80 } | 100 } |
| 81 } | 101 } |
| 82 | 102 |
| 83 - (void)setSeverity:(AppMenuIconController::Severity)severity | 103 - (void)setSeverity:(AppMenuIconController::Severity)severity |
| 84 iconType:(AppMenuIconController::IconType)type | 104 iconType:(AppMenuIconController::IconType)type |
| 85 shouldAnimate:(BOOL)shouldAnimate { | 105 shouldAnimate:(BOOL)shouldAnimate { |
| 86 if (severity != severity_ || type != type_) { | 106 if (severity != severity_ || type != type_) { |
| 87 severity_ = severity; | 107 severity_ = severity; |
| 88 type_ = type; | 108 type_ = type; |
| 89 // Update the button state images with the new severity color or icon type. | 109 |
| 90 [self resetButtonStateImages]; | 110 if (app_icon_) { |
| 111 app_icon_->set_target_color( | |
| 112 [self vectorIconColor:[[self window] hasDarkTheme]]); | |
| 113 app_icon_->StartAnimation(); | |
| 114 } else { | |
| 115 // Update the button state images with the new severity color or icon | |
| 116 // type. | |
| 117 [self resetButtonStateImages]; | |
| 118 } | |
| 91 } | 119 } |
| 92 } | 120 } |
| 93 | 121 |
| 122 - (void)onTabInsertedInForeground { | |
|
Robert Sesek
2017/05/03 22:44:29
What do you think of this?
Rename this -maybeStar
| |
| 123 if (app_icon_ && severity_ != AppMenuIconController::Severity::NONE) | |
| 124 app_icon_->StartAnimation(); | |
| 125 } | |
| 126 | |
| 127 - (void)willShowMenu { | |
| 128 if (app_icon_ && severity_ != AppMenuIconController::Severity::NONE) | |
| 129 app_icon_->StartAnimation(); | |
| 130 } | |
| 131 | |
| 94 @end | 132 @end |
| OLD | NEW |