Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar/app_menu_button.cc |
| diff --git a/chrome/browser/ui/views/toolbar/app_menu_button.cc b/chrome/browser/ui/views/toolbar/app_menu_button.cc |
| index 448dcc6ad1826d569b5f82c85087983805e65dfb..f8750591f60bbde841fab41ce6ba31e979d0fddb 100644 |
| --- a/chrome/browser/ui/views/toolbar/app_menu_button.cc |
| +++ b/chrome/browser/ui/views/toolbar/app_menu_button.cc |
| @@ -4,21 +4,26 @@ |
| #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| +#include "base/command_line.h" |
| #include "base/location.h" |
| #include "base/metrics/histogram_macros.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| +#include "cc/paint/paint_flags.h" |
| #include "chrome/app/vector_icons/vector_icons.h" |
| #include "chrome/browser/themes/theme_properties.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_otr_state.h" |
| #include "chrome/browser/ui/layout_constants.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/browser/ui/toolbar/app_menu_model.h" |
| #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| #include "chrome/browser/ui/views/toolbar/app_menu.h" |
| +#include "chrome/browser/ui/views/toolbar/app_menu_animation.h" |
| #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
| #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| +#include "chrome/common/chrome_switches.h" |
| #include "chrome/grit/theme_resources.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/base/theme_provider.h" |
| @@ -29,6 +34,10 @@ |
| #include "ui/views/controls/menu/menu_listener.h" |
| #include "ui/views/metrics.h" |
| +namespace { |
| +const float kIconSize = 16; |
| +} // namespace |
| + |
| // static |
| bool AppMenuButton::g_open_app_immediately_for_testing = false; |
| @@ -41,6 +50,21 @@ AppMenuButton::AppMenuButton(ToolbarView* toolbar_view) |
| weak_factory_(this) { |
| SetInkDropMode(InkDropMode::ON); |
| SetFocusPainter(nullptr); |
| + |
| + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kGlobalErrorMenuIcon)) { |
| + std::string flag = |
| + command_line->GetSwitchValueASCII(switches::kGlobalErrorMenuIcon); |
| + if (flag != switches::kGlobalErrorMenuIconOldBehavior) { |
| + if (flag == switches::kGlobalErrorMenuIconPersistentClosedState) { |
| + Browser* browser = toolbar_view_->browser(); |
| + browser->tab_strip_model()->AddObserver(this); |
| + animation_.reset(new AppMenuAnimation(this, true)); |
|
msw
2017/04/11 17:34:14
nit: = base::MakeUnique here and below
spqchan
2017/04/12 19:42:10
Done.
|
| + } else { |
| + animation_.reset(new AppMenuAnimation(this, false)); |
| + } |
| + } |
| + } |
| } |
| AppMenuButton::~AppMenuButton() {} |
| @@ -50,7 +74,7 @@ void AppMenuButton::SetSeverity(AppMenuIconController::IconType type, |
| bool animate) { |
| type_ = type; |
| severity_ = severity; |
| - UpdateIcon(); |
| + UpdateIcon(animate); |
| } |
| void AppMenuButton::ShowMenu(bool for_drop) { |
| @@ -85,6 +109,9 @@ void AppMenuButton::ShowMenu(bool for_drop) { |
| UMA_HISTOGRAM_TIMES("Toolbar.AppMenuTimeToAction", |
| base::TimeTicks::Now() - menu_open_time); |
| } |
| + |
| + if (severity_ != AppMenuIconController::Severity::NONE) |
| + animation_->StartAnimation(); |
| } |
| void AppMenuButton::CloseMenu() { |
| @@ -106,33 +133,70 @@ void AppMenuButton::RemoveMenuListener(views::MenuListener* listener) { |
| } |
| gfx::Size AppMenuButton::GetPreferredSize() const { |
| - gfx::Rect rect(image()->GetPreferredSize()); |
| + gfx::Rect rect(gfx::Size(kIconSize, kIconSize)); |
| rect.Inset(gfx::Insets(-ToolbarButton::kInteriorPadding)); |
| return rect.size(); |
| } |
| -void AppMenuButton::UpdateIcon() { |
| - SkColor color = gfx::kPlaceholderColor; |
| +void AppMenuButton::Layout() { |
| + if (animation_.get()) { |
|
msw
2017/04/11 17:34:14
nit: remove |.get()|, you can just check |if (anim
spqchan
2017/04/12 19:42:10
Done.
|
| + ink_drop_container()->SetBoundsRect(GetLocalBounds()); |
| + image()->SetBoundsRect(GetLocalBounds()); |
| + return; |
| + } |
| + |
| + views::MenuButton::Layout(); |
| +} |
| + |
| +void AppMenuButton::OnPaint(gfx::Canvas* canvas) { |
| + if (!animation_.get()) { |
| + views::MenuButton::OnPaint(canvas); |
| + return; |
| + } |
| + |
| + gfx::Rect bounds = GetLocalBounds(); |
| + bounds.Inset(gfx::Insets(ToolbarButton::kInteriorPadding)); |
| + animation_->PaintAppMenu(canvas, bounds); |
| +} |
| + |
| +void AppMenuButton::TabInsertedAt(TabStripModel* tab_strip_model, |
| + content::WebContents* contents, |
| + int index, |
| + bool foreground) { |
| + if (severity_ != AppMenuIconController::Severity::NONE) |
| + animation_->StartAnimation(); |
| +} |
| + |
| +void AppMenuButton::UpdateIcon(bool should_animate) { |
| + SkColor severity_color = gfx::kPlaceholderColor; |
| + SkColor toolbar_icon_color = |
| + GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); |
| const ui::NativeTheme* native_theme = GetNativeTheme(); |
| switch (severity_) { |
| case AppMenuIconController::Severity::NONE: |
| - color = GetThemeProvider()->GetColor( |
| - ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); |
| + severity_color = toolbar_icon_color; |
| break; |
| case AppMenuIconController::Severity::LOW: |
| - color = native_theme->GetSystemColor( |
| + severity_color = native_theme->GetSystemColor( |
| ui::NativeTheme::kColorId_AlertSeverityLow); |
| break; |
| case AppMenuIconController::Severity::MEDIUM: |
| - color = native_theme->GetSystemColor( |
| + severity_color = native_theme->GetSystemColor( |
| ui::NativeTheme::kColorId_AlertSeverityMedium); |
| break; |
| case AppMenuIconController::Severity::HIGH: |
| - color = native_theme->GetSystemColor( |
| + severity_color = native_theme->GetSystemColor( |
| ui::NativeTheme::kColorId_AlertSeverityHigh); |
| break; |
| } |
| + if (animation_.get()) { |
| + animation_->UpdateIconColor(toolbar_icon_color, severity_color); |
| + if (should_animate) |
| + animation_->StartAnimation(); |
| + return; |
| + } |
| + |
| const gfx::VectorIcon* icon_id = nullptr; |
| switch (type_) { |
| case AppMenuIconController::IconType::NONE: |
| @@ -148,7 +212,8 @@ void AppMenuButton::UpdateIcon() { |
| break; |
| } |
| - SetImage(views::Button::STATE_NORMAL, gfx::CreateVectorIcon(*icon_id, color)); |
| + SetImage(views::Button::STATE_NORMAL, |
| + gfx::CreateVectorIcon(*icon_id, severity_color)); |
| } |
| void AppMenuButton::SetTrailingMargin(int margin) { |