Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 5 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "chrome/browser/themes/theme_properties.h" | 12 #include "chrome/browser/themes/theme_properties.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_otr_state.h" | |
| 14 #include "chrome/browser/ui/layout_constants.h" | 15 #include "chrome/browser/ui/layout_constants.h" |
| 15 #include "chrome/browser/ui/toolbar/app_menu_model.h" | 16 #include "chrome/browser/ui/toolbar/app_menu_model.h" |
| 16 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 17 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 17 #include "chrome/browser/ui/views/toolbar/app_menu.h" | 18 #include "chrome/browser/ui/views/toolbar/app_menu.h" |
| 18 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 19 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 19 #include "extensions/common/feature_switch.h" | 20 #include "extensions/common/feature_switch.h" |
| 20 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 21 #include "ui/base/material_design/material_design_controller.h" | 22 #include "ui/base/material_design/material_design_controller.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/base/theme_provider.h" | 24 #include "ui/base/theme_provider.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 43 margin_trailing_(0), | 44 margin_trailing_(0), |
| 44 weak_factory_(this) { | 45 weak_factory_(this) { |
| 45 set_ink_drop_delegate( | 46 set_ink_drop_delegate( |
| 46 base::WrapUnique(new views::ButtonInkDropDelegate(this, this))); | 47 base::WrapUnique(new views::ButtonInkDropDelegate(this, this))); |
| 47 if (!ui::MaterialDesignController::IsModeMaterial()) | 48 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 48 icon_painter_.reset(new AppMenuIconPainter(this)); | 49 icon_painter_.reset(new AppMenuIconPainter(this)); |
| 49 } | 50 } |
| 50 | 51 |
| 51 AppMenuButton::~AppMenuButton() {} | 52 AppMenuButton::~AppMenuButton() {} |
| 52 | 53 |
| 53 void AppMenuButton::SetSeverity(AppMenuIconPainter::Severity severity, | 54 void AppMenuButton::SetSeverity(AppMenuBadgeController::BadgeType type, |
| 55 AppMenuIconPainter::Severity severity, | |
| 54 bool animate) { | 56 bool animate) { |
| 55 if (ui::MaterialDesignController::IsModeMaterial()) { | 57 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 56 severity_ = severity; | 58 severity_ = severity; |
| 59 type_ = type; | |
| 57 UpdateIcon(); | 60 UpdateIcon(); |
| 58 return; | 61 return; |
| 59 } | 62 } |
| 60 | 63 |
| 61 icon_painter_->SetSeverity(severity, animate); | 64 icon_painter_->SetSeverity(severity, animate); |
| 62 SchedulePaint(); | 65 SchedulePaint(); |
| 63 } | 66 } |
| 64 | 67 |
| 65 void AppMenuButton::ShowMenu(bool for_drop) { | 68 void AppMenuButton::ShowMenu(bool for_drop) { |
| 66 if (menu_ && menu_->IsShowing()) | 69 if (menu_ && menu_->IsShowing()) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 color = gfx::kGoogleGreen700; | 147 color = gfx::kGoogleGreen700; |
| 145 break; | 148 break; |
| 146 case AppMenuIconPainter::SEVERITY_MEDIUM: | 149 case AppMenuIconPainter::SEVERITY_MEDIUM: |
| 147 color = gfx::kGoogleYellow700; | 150 color = gfx::kGoogleYellow700; |
| 148 break; | 151 break; |
| 149 case AppMenuIconPainter::SEVERITY_HIGH: | 152 case AppMenuIconPainter::SEVERITY_HIGH: |
| 150 color = gfx::kGoogleRed700; | 153 color = gfx::kGoogleRed700; |
| 151 break; | 154 break; |
| 152 } | 155 } |
| 153 | 156 |
| 157 gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 158 switch (type_) { | |
| 159 case AppMenuBadgeController::BadgeType::NONE: | |
| 160 icon_id = gfx::VectorIconId::BROWSER_TOOLS; | |
|
Evan Stade
2016/06/03 22:06:20
nit: indent off
kylix_rd
2016/06/03 22:20:04
Done.
| |
| 161 DCHECK(severity_ == AppMenuIconPainter::SEVERITY_NONE); | |
| 162 break; | |
| 163 case AppMenuBadgeController::BadgeType::UPGRADE_NOTIFICATION: | |
| 164 icon_id = gfx::VectorIconId::UPDATE_MENU_SEVERITY_LOW_MEDIUM_HIGH; | |
| 165 break; | |
| 166 case AppMenuBadgeController::BadgeType::GLOBAL_ERROR: | |
| 167 icon_id = gfx::VectorIconId::UPDATE_MENU_FAILED; | |
| 168 break; | |
| 169 case AppMenuBadgeController::BadgeType::INCOMPATIBILITY_WARNING: | |
| 170 icon_id = gfx::VectorIconId::UPDATE_MENU_SEVERITY_WARNING; | |
| 171 break; | |
| 172 } | |
| 173 | |
| 154 SetImage(views::Button::STATE_NORMAL, | 174 SetImage(views::Button::STATE_NORMAL, |
| 155 gfx::CreateVectorIcon(gfx::VectorIconId::BROWSER_TOOLS, color)); | 175 gfx::CreateVectorIcon(icon_id, 16, color)); |
| 156 } | 176 } |
| 157 | 177 |
| 158 void AppMenuButton::SetTrailingMargin(int margin) { | 178 void AppMenuButton::SetTrailingMargin(int margin) { |
| 159 margin_trailing_ = margin; | 179 margin_trailing_ = margin; |
| 160 | 180 |
| 161 UpdateThemedBorder(); | 181 UpdateThemedBorder(); |
| 162 | 182 |
| 163 if (!ui::MaterialDesignController::IsModeMaterial()) { | 183 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 164 const int inset = LabelButton::kFocusRectInset; | 184 const int inset = LabelButton::kFocusRectInset; |
| 165 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets( | 185 SetFocusPainter(views::Painter::CreateDashedFocusPainterWithInsets( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 views::MenuButton::OnPaint(canvas); | 267 views::MenuButton::OnPaint(canvas); |
| 248 if (ui::MaterialDesignController::IsModeMaterial()) | 268 if (ui::MaterialDesignController::IsModeMaterial()) |
| 249 return; | 269 return; |
| 250 // Use GetPreferredSize() to center the icon inside the visible bounds rather | 270 // Use GetPreferredSize() to center the icon inside the visible bounds rather |
| 251 // than the whole size() (which may refer to hit test region extended to the | 271 // than the whole size() (which may refer to hit test region extended to the |
| 252 // end of the toolbar in maximized mode). | 272 // end of the toolbar in maximized mode). |
| 253 icon_painter_->Paint(canvas, GetThemeProvider(), | 273 icon_painter_->Paint(canvas, GetThemeProvider(), |
| 254 gfx::Rect(GetPreferredSize()), | 274 gfx::Rect(GetPreferredSize()), |
| 255 AppMenuIconPainter::BEZEL_NONE); | 275 AppMenuIconPainter::BEZEL_NONE); |
| 256 } | 276 } |
| OLD | NEW |