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" |
| 24 #include "ui/gfx/color_palette.h" | 25 #include "ui/gfx/color_palette.h" |
| 25 #include "ui/gfx/paint_vector_icon.h" | 26 #include "ui/gfx/paint_vector_icon.h" |
| 26 #include "ui/gfx/vector_icons_public.h" | 27 #include "ui/gfx/vector_icons_public.h" |
| 27 #include "ui/keyboard/keyboard_controller.h" | 28 #include "ui/keyboard/keyboard_controller.h" |
| 28 #include "ui/views/animation/button_ink_drop_delegate.h" | 29 #include "ui/views/animation/button_ink_drop_delegate.h" |
| 29 #include "ui/views/controls/button/label_button_border.h" | 30 #include "ui/views/controls/button/label_button_border.h" |
| 30 #include "ui/views/controls/menu/menu_listener.h" | 31 #include "ui/views/controls/menu/menu_listener.h" |
| 31 #include "ui/views/metrics.h" | 32 #include "ui/views/metrics.h" |
| 32 #include "ui/views/painter.h" | 33 #include "ui/views/painter.h" |
| 33 | 34 |
| 34 // static | 35 // static |
| 35 bool AppMenuButton::g_open_app_immediately_for_testing = false; | 36 bool AppMenuButton::g_open_app_immediately_for_testing = false; |
| 36 | 37 |
| 37 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view) | 38 AppMenuButton::AppMenuButton(ToolbarView* toolbar_view) |
| 38 : views::MenuButton(base::string16(), toolbar_view, false), | 39 : views::MenuButton(base::string16(), toolbar_view, false), |
| 39 severity_(AppMenuIconPainter::SEVERITY_NONE), | 40 severity_(AppMenuIconPainter::SEVERITY_NONE), |
| 41 type_(AppMenuBadgeController::BadgeType::NONE), | |
|
kylix_rd
2016/06/06 17:46:55
Oops... failed to properly initialize the type_ fi
| |
| 40 toolbar_view_(toolbar_view), | 42 toolbar_view_(toolbar_view), |
| 41 allow_extension_dragging_( | 43 allow_extension_dragging_( |
| 42 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()), | 44 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()), |
| 43 margin_trailing_(0), | 45 margin_trailing_(0), |
| 44 weak_factory_(this) { | 46 weak_factory_(this) { |
| 45 set_ink_drop_delegate( | 47 set_ink_drop_delegate( |
| 46 base::WrapUnique(new views::ButtonInkDropDelegate(this, this))); | 48 base::WrapUnique(new views::ButtonInkDropDelegate(this, this))); |
| 47 if (!ui::MaterialDesignController::IsModeMaterial()) | 49 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 48 icon_painter_.reset(new AppMenuIconPainter(this)); | 50 icon_painter_.reset(new AppMenuIconPainter(this)); |
| 49 } | 51 } |
| 50 | 52 |
| 51 AppMenuButton::~AppMenuButton() {} | 53 AppMenuButton::~AppMenuButton() {} |
| 52 | 54 |
| 53 void AppMenuButton::SetSeverity(AppMenuIconPainter::Severity severity, | 55 void AppMenuButton::SetSeverity(AppMenuBadgeController::BadgeType type, |
| 56 AppMenuIconPainter::Severity severity, | |
| 54 bool animate) { | 57 bool animate) { |
| 55 if (ui::MaterialDesignController::IsModeMaterial()) { | 58 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 56 severity_ = severity; | 59 severity_ = severity; |
| 60 type_ = type; | |
| 57 UpdateIcon(); | 61 UpdateIcon(); |
| 58 return; | 62 return; |
| 59 } | 63 } |
| 60 | 64 |
| 61 icon_painter_->SetSeverity(severity, animate); | 65 icon_painter_->SetSeverity(severity, animate); |
| 62 SchedulePaint(); | 66 SchedulePaint(); |
| 63 } | 67 } |
| 64 | 68 |
| 65 void AppMenuButton::ShowMenu(bool for_drop) { | 69 void AppMenuButton::ShowMenu(bool for_drop) { |
| 66 if (menu_ && menu_->IsShowing()) | 70 if (menu_ && menu_->IsShowing()) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 color = gfx::kGoogleGreen700; | 148 color = gfx::kGoogleGreen700; |
| 145 break; | 149 break; |
| 146 case AppMenuIconPainter::SEVERITY_MEDIUM: | 150 case AppMenuIconPainter::SEVERITY_MEDIUM: |
| 147 color = gfx::kGoogleYellow700; | 151 color = gfx::kGoogleYellow700; |
| 148 break; | 152 break; |
| 149 case AppMenuIconPainter::SEVERITY_HIGH: | 153 case AppMenuIconPainter::SEVERITY_HIGH: |
| 150 color = gfx::kGoogleRed700; | 154 color = gfx::kGoogleRed700; |
| 151 break; | 155 break; |
| 152 } | 156 } |
| 153 | 157 |
| 154 SetImage(views::Button::STATE_NORMAL, | 158 gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; |
| 155 gfx::CreateVectorIcon(gfx::VectorIconId::BROWSER_TOOLS, color)); | 159 switch (type_) { |
| 160 case AppMenuBadgeController::BadgeType::NONE: | |
| 161 icon_id = gfx::VectorIconId::BROWSER_TOOLS; | |
| 162 DCHECK_EQ(severity_, AppMenuIconPainter::SEVERITY_NONE); | |
| 163 break; | |
| 164 case AppMenuBadgeController::BadgeType::UPGRADE_NOTIFICATION: | |
| 165 icon_id = gfx::VectorIconId::BROWSER_TOOLS_UPDATE; | |
| 166 break; | |
| 167 case AppMenuBadgeController::BadgeType::GLOBAL_ERROR: | |
| 168 icon_id = gfx::VectorIconId::BROWSER_TOOLS_ERROR; | |
| 169 break; | |
| 170 case AppMenuBadgeController::BadgeType::INCOMPATIBILITY_WARNING: | |
| 171 icon_id = gfx::VectorIconId::BROWSER_TOOLS_WARNING; | |
| 172 break; | |
| 173 } | |
| 174 | |
| 175 SetImage(views::Button::STATE_NORMAL, gfx::CreateVectorIcon(icon_id, 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 |