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/views/extensions/browser_action_drag_data.h" | 13 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
13 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 14 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
14 #include "extensions/common/feature_switch.h" | 15 #include "extensions/common/feature_switch.h" |
15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
17 #include "ui/base/resource/material_design/material_design_controller.h" | |
16 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/base/theme_provider.h" | 19 #include "ui/base/theme_provider.h" |
18 #include "ui/views/controls/button/label_button_border.h" | 20 #include "ui/views/controls/button/label_button_border.h" |
19 #include "ui/views/metrics.h" | 21 #include "ui/views/metrics.h" |
20 #include "ui/views/painter.h" | 22 #include "ui/views/painter.h" |
21 | 23 |
22 // static | 24 // static |
23 bool WrenchToolbarButton::g_open_wrench_immediately_for_testing = false; | 25 bool WrenchToolbarButton::g_open_wrench_immediately_for_testing = false; |
24 | 26 |
25 WrenchToolbarButton::WrenchToolbarButton(ToolbarView* toolbar_view) | 27 WrenchToolbarButton::WrenchToolbarButton(ToolbarView* toolbar_view) |
26 : views::MenuButton(NULL, base::string16(), toolbar_view, false), | 28 : views::MenuButton(NULL, base::string16(), toolbar_view, false), |
27 wrench_icon_painter_(new WrenchIconPainter(this)), | 29 wrench_icon_painter_(nullptr), |
28 toolbar_view_(toolbar_view), | 30 toolbar_view_(toolbar_view), |
29 allow_extension_dragging_( | 31 allow_extension_dragging_( |
30 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()), | 32 extensions::FeatureSwitch::extension_action_redesign() |
33 ->IsEnabled()), | |
31 weak_factory_(this) { | 34 weak_factory_(this) { |
35 if (!ui::MaterialDesignController::IsModeMaterial()) | |
36 wrench_icon_painter_.reset(new WrenchIconPainter(this)); | |
32 } | 37 } |
33 | 38 |
34 WrenchToolbarButton::~WrenchToolbarButton() { | 39 WrenchToolbarButton::~WrenchToolbarButton() { |
35 } | 40 } |
36 | 41 |
37 void WrenchToolbarButton::SetSeverity(WrenchIconPainter::Severity severity, | 42 void WrenchToolbarButton::SetSeverity(WrenchIconPainter::Severity severity, |
38 bool animate) { | 43 bool animate) { |
44 if (!wrench_icon_painter_) | |
bruthig
2015/08/07 16:43:15
Consider using "if (ui::MaterialDesignController::
jonross
2015/08/07 17:33:46
Done.
| |
45 return; | |
46 | |
39 wrench_icon_painter_->SetSeverity(severity, animate); | 47 wrench_icon_painter_->SetSeverity(severity, animate); |
40 SchedulePaint(); | 48 SchedulePaint(); |
41 } | 49 } |
42 | 50 |
43 gfx::Size WrenchToolbarButton::GetPreferredSize() const { | 51 gfx::Size WrenchToolbarButton::GetPreferredSize() const { |
52 if (ui::MaterialDesignController::IsModeMaterial()) { | |
53 gfx::Size size(image()->GetPreferredSize()); | |
54 ui::ThemeProvider* provider = GetThemeProvider(); | |
55 if (provider && provider->UsingSystemTheme()) { | |
56 int inset = provider->GetDisplayProperty( | |
57 ThemeProperties::PROPERTY_TOOLBAR_BUTTON_BORDER_INSET); | |
58 size.Enlarge(2 * inset, 2 * inset); | |
59 } | |
60 return size; | |
61 } | |
62 | |
44 return ResourceBundle::GetSharedInstance(). | 63 return ResourceBundle::GetSharedInstance(). |
45 GetImageSkiaNamed(IDR_TOOLBAR_BEZEL_HOVER)->size(); | 64 GetImageSkiaNamed(IDR_TOOLBAR_BEZEL_HOVER)->size(); |
46 } | 65 } |
47 | 66 |
48 void WrenchToolbarButton::ScheduleWrenchIconPaint() { | 67 void WrenchToolbarButton::ScheduleWrenchIconPaint() { |
49 SchedulePaint(); | 68 SchedulePaint(); |
50 } | 69 } |
51 | 70 |
52 const char* WrenchToolbarButton::GetClassName() const { | 71 const char* WrenchToolbarButton::GetClassName() const { |
53 return "WrenchToolbarButton"; | 72 return "WrenchToolbarButton"; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 weak_factory_.InvalidateWeakPtrs(); | 113 weak_factory_.InvalidateWeakPtrs(); |
95 } | 114 } |
96 | 115 |
97 int WrenchToolbarButton::OnPerformDrop(const ui::DropTargetEvent& event) { | 116 int WrenchToolbarButton::OnPerformDrop(const ui::DropTargetEvent& event) { |
98 DCHECK(allow_extension_dragging_); | 117 DCHECK(allow_extension_dragging_); |
99 return ui::DragDropTypes::DRAG_MOVE; | 118 return ui::DragDropTypes::DRAG_MOVE; |
100 } | 119 } |
101 | 120 |
102 void WrenchToolbarButton::OnPaint(gfx::Canvas* canvas) { | 121 void WrenchToolbarButton::OnPaint(gfx::Canvas* canvas) { |
103 views::MenuButton::OnPaint(canvas); | 122 views::MenuButton::OnPaint(canvas); |
123 if (!wrench_icon_painter_) | |
124 return; | |
104 wrench_icon_painter_->Paint(canvas, | 125 wrench_icon_painter_->Paint(canvas, |
105 GetThemeProvider(), | 126 GetThemeProvider(), |
106 gfx::Rect(size()), | 127 gfx::Rect(size()), |
107 WrenchIconPainter::BEZEL_NONE); | 128 WrenchIconPainter::BEZEL_NONE); |
108 } | 129 } |
109 | 130 |
110 void WrenchToolbarButton::ShowOverflowMenu() { | 131 void WrenchToolbarButton::ShowOverflowMenu() { |
111 toolbar_view_->ShowAppMenu(true); // For drop. | 132 toolbar_view_->ShowAppMenu(true); // For drop. |
112 } | 133 } |
OLD | NEW |