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/wrench_toolbar_button.h" | 5 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "chrome/browser/themes/theme_properties.h" | |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 13 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
13 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 14 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
14 #include "chrome/browser/ui/views/layout_constants.h" | 15 #include "chrome/browser/ui/views/layout_constants.h" |
15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
16 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" | 17 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" |
17 #include "extensions/common/feature_switch.h" | 18 #include "extensions/common/feature_switch.h" |
18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
19 #include "ui/base/resource/material_design/material_design_controller.h" | 20 #include "ui/base/resource/material_design/material_design_controller.h" |
20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/base/theme_provider.h" | 22 #include "ui/base/theme_provider.h" |
23 #include "ui/gfx/color_palette.h" | |
24 #include "ui/gfx/paint_vector_icon.h" | |
25 #include "ui/gfx/vector_icons_public.h" | |
22 #include "ui/keyboard/keyboard_controller.h" | 26 #include "ui/keyboard/keyboard_controller.h" |
23 #include "ui/views/controls/button/label_button_border.h" | 27 #include "ui/views/controls/button/label_button_border.h" |
24 #include "ui/views/controls/menu/menu_listener.h" | 28 #include "ui/views/controls/menu/menu_listener.h" |
25 #include "ui/views/metrics.h" | 29 #include "ui/views/metrics.h" |
26 #include "ui/views/painter.h" | 30 #include "ui/views/painter.h" |
27 | 31 |
28 // static | 32 // static |
29 bool WrenchToolbarButton::g_open_app_immediately_for_testing = false; | 33 bool WrenchToolbarButton::g_open_app_immediately_for_testing = false; |
30 | 34 |
31 WrenchToolbarButton::WrenchToolbarButton(ToolbarView* toolbar_view) | 35 WrenchToolbarButton::WrenchToolbarButton(ToolbarView* toolbar_view) |
32 : views::MenuButton(NULL, base::string16(), toolbar_view, false), | 36 : views::MenuButton(NULL, base::string16(), toolbar_view, false), |
33 wrench_icon_painter_(nullptr), | 37 severity_(WrenchIconPainter::SEVERITY_NONE), |
34 toolbar_view_(toolbar_view), | 38 toolbar_view_(toolbar_view), |
35 allow_extension_dragging_( | 39 allow_extension_dragging_( |
36 extensions::FeatureSwitch::extension_action_redesign() | 40 extensions::FeatureSwitch::extension_action_redesign() |
37 ->IsEnabled()), | 41 ->IsEnabled()), |
38 weak_factory_(this) { | 42 weak_factory_(this) { |
39 if (!ui::MaterialDesignController::IsModeMaterial()) | 43 if (!ui::MaterialDesignController::IsModeMaterial()) |
40 wrench_icon_painter_.reset(new WrenchIconPainter(this)); | 44 wrench_icon_painter_.reset(new WrenchIconPainter(this)); |
41 } | 45 } |
42 | 46 |
43 WrenchToolbarButton::~WrenchToolbarButton() { | 47 WrenchToolbarButton::~WrenchToolbarButton() { |
44 } | 48 } |
45 | 49 |
46 void WrenchToolbarButton::SetSeverity(WrenchIconPainter::Severity severity, | 50 void WrenchToolbarButton::SetSeverity(WrenchIconPainter::Severity severity, |
47 bool animate) { | 51 bool animate) { |
48 if (ui::MaterialDesignController::IsModeMaterial()) | 52 if (ui::MaterialDesignController::IsModeMaterial()) { |
53 severity_ = severity; | |
54 UpdateIcon(); | |
49 return; | 55 return; |
56 } | |
50 | 57 |
51 wrench_icon_painter_->SetSeverity(severity, animate); | 58 wrench_icon_painter_->SetSeverity(severity, animate); |
52 SchedulePaint(); | 59 SchedulePaint(); |
53 } | 60 } |
54 | 61 |
55 void WrenchToolbarButton::ShowMenu(bool for_drop) { | 62 void WrenchToolbarButton::ShowMenu(bool for_drop) { |
56 if (menu_ && menu_->IsShowing()) | 63 if (menu_ && menu_->IsShowing()) |
57 return; | 64 return; |
58 | 65 |
59 #if defined(USE_AURA) | 66 #if defined(USE_AURA) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 } | 113 } |
107 | 114 |
108 return ResourceBundle::GetSharedInstance(). | 115 return ResourceBundle::GetSharedInstance(). |
109 GetImageSkiaNamed(IDR_TOOLBAR_BEZEL_HOVER)->size(); | 116 GetImageSkiaNamed(IDR_TOOLBAR_BEZEL_HOVER)->size(); |
110 } | 117 } |
111 | 118 |
112 void WrenchToolbarButton::ScheduleWrenchIconPaint() { | 119 void WrenchToolbarButton::ScheduleWrenchIconPaint() { |
113 SchedulePaint(); | 120 SchedulePaint(); |
114 } | 121 } |
115 | 122 |
123 void WrenchToolbarButton::UpdateIcon() { | |
124 DCHECK(ui::MaterialDesignController::IsModeMaterial()); | |
125 SkColor color = SK_ColorRED; | |
126 switch (severity_) { | |
127 case WrenchIconPainter::SEVERITY_NONE: | |
128 color = GetThemeProvider()->GetColor( | |
129 ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); | |
130 break; | |
131 case WrenchIconPainter::SEVERITY_LOW: | |
132 color = gfx::kGoogleGreen700; | |
133 break; | |
134 case WrenchIconPainter::SEVERITY_MEDIUM: | |
135 color = gfx::kGoogleYellow700; | |
136 break; | |
137 case WrenchIconPainter::SEVERITY_HIGH: | |
138 color = gfx::kGoogleRed700; | |
139 break; | |
140 } | |
141 | |
142 const int kButtonSize = 16; | |
Evan Stade
2015/10/07 21:59:17
(in the future this should move to layout_constant
sky
2015/10/07 23:41:52
How about a TODO then?
Evan Stade
2015/10/08 00:03:31
Done.
| |
143 SetImage(views::Button::STATE_NORMAL, | |
144 gfx::CreateVectorIcon(gfx::VectorIconId::BROWSER_TOOLS, kButtonSize, | |
145 color)); | |
146 } | |
147 | |
116 const char* WrenchToolbarButton::GetClassName() const { | 148 const char* WrenchToolbarButton::GetClassName() const { |
117 return "WrenchToolbarButton"; | 149 return "WrenchToolbarButton"; |
118 } | 150 } |
119 | 151 |
120 bool WrenchToolbarButton::GetDropFormats( | 152 bool WrenchToolbarButton::GetDropFormats( |
121 int* formats, | 153 int* formats, |
122 std::set<ui::Clipboard::FormatType>* format_types) { | 154 std::set<ui::Clipboard::FormatType>* format_types) { |
123 return allow_extension_dragging_ ? | 155 return allow_extension_dragging_ ? |
124 BrowserActionDragData::GetDropFormats(format_types) : | 156 BrowserActionDragData::GetDropFormats(format_types) : |
125 views::View::GetDropFormats(formats, format_types); | 157 views::View::GetDropFormats(formats, format_types); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 | 198 |
167 void WrenchToolbarButton::OnPaint(gfx::Canvas* canvas) { | 199 void WrenchToolbarButton::OnPaint(gfx::Canvas* canvas) { |
168 views::MenuButton::OnPaint(canvas); | 200 views::MenuButton::OnPaint(canvas); |
169 if (ui::MaterialDesignController::IsModeMaterial()) | 201 if (ui::MaterialDesignController::IsModeMaterial()) |
170 return; | 202 return; |
171 wrench_icon_painter_->Paint(canvas, | 203 wrench_icon_painter_->Paint(canvas, |
172 GetThemeProvider(), | 204 GetThemeProvider(), |
173 gfx::Rect(size()), | 205 gfx::Rect(size()), |
174 WrenchIconPainter::BEZEL_NONE); | 206 WrenchIconPainter::BEZEL_NONE); |
175 } | 207 } |
OLD | NEW |