OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/libgtk2ui/gtk2_border.h" | 5 #include "chrome/browser/ui/libgtk2ui/gtk2_border.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" | 9 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" |
10 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" | 10 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" |
11 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" | 11 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" |
12 #include "third_party/skia/include/effects/SkLerpXfermode.h" | 12 #include "third_party/skia/include/effects/SkLerpXfermode.h" |
13 #include "ui/base/theme_provider.h" | 13 #include "ui/base/theme_provider.h" |
14 #include "ui/gfx/animation/animation.h" | 14 #include "ui/gfx/animation/animation.h" |
15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/image/image_skia_source.h" | 16 #include "ui/gfx/image/image_skia_source.h" |
17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
18 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
19 #include "ui/views/controls/button/label_button.h" | 19 #include "ui/views/controls/button/label_button.h" |
| 20 #include "ui/views/controls/button/label_button_border.h" |
20 #include "ui/views/native_theme_delegate.h" | 21 #include "ui/views/native_theme_delegate.h" |
21 | 22 |
22 using views::Button; | 23 using views::Button; |
23 using views::NativeThemeDelegate; | 24 using views::NativeThemeDelegate; |
24 | 25 |
25 namespace libgtk2ui { | 26 namespace libgtk2ui { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 const int kNumberOfFocusedStates = 2; | 30 const int kNumberOfFocusedStates = 2; |
(...skipping 26 matching lines...) Expand all Loading... |
56 const bool focused_; | 57 const bool focused_; |
57 const gfx::Size size_; | 58 const gfx::Size size_; |
58 | 59 |
59 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); | 60 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); |
60 }; | 61 }; |
61 | 62 |
62 } // namespace | 63 } // namespace |
63 | 64 |
64 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, | 65 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, |
65 views::LabelButton* owning_button, | 66 views::LabelButton* owning_button, |
66 scoped_ptr<views::Border> border) | 67 scoped_ptr<views::LabelButtonBorder> border) |
67 : gtk2_ui_(gtk2_ui), | 68 : gtk2_ui_(gtk2_ui), |
68 owning_button_(owning_button), | 69 owning_button_(owning_button), |
69 border_(border.Pass()), | 70 border_(border.Pass()), |
70 observer_manager_(this) { | 71 observer_manager_(this) { |
71 observer_manager_.Add(NativeThemeGtk2::instance()); | 72 observer_manager_.Add(NativeThemeGtk2::instance()); |
72 } | 73 } |
73 | 74 |
74 Gtk2Border::~Gtk2Border() { | 75 Gtk2Border::~Gtk2Border() { |
75 } | 76 } |
76 | 77 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 owning_button_->InvalidateLayout(); | 126 owning_button_->InvalidateLayout(); |
126 } | 127 } |
127 | 128 |
128 void Gtk2Border::PaintState(const ui::NativeTheme::State state, | 129 void Gtk2Border::PaintState(const ui::NativeTheme::State state, |
129 const ui::NativeTheme::ExtraParams& extra, | 130 const ui::NativeTheme::ExtraParams& extra, |
130 const gfx::Rect& rect, | 131 const gfx::Rect& rect, |
131 gfx::Canvas* canvas) { | 132 gfx::Canvas* canvas) { |
132 bool focused = extra.button.is_focused; | 133 bool focused = extra.button.is_focused; |
133 Button::ButtonState views_state = Button::GetButtonStateFrom(state); | 134 Button::ButtonState views_state = Button::GetButtonStateFrom(state); |
134 | 135 |
135 if (ShouldDrawBorder(focused, views_state)) { | 136 if (border_->GetPainter(focused, views_state) || |
| 137 (focused && border_->GetPainter(false, views_state))) { |
136 gfx::ImageSkia* image = &button_images_[focused][views_state]; | 138 gfx::ImageSkia* image = &button_images_[focused][views_state]; |
137 | 139 |
138 if (image->isNull() || image->size() != rect.size()) { | 140 if (image->isNull() || image->size() != rect.size()) { |
139 GtkStateType gtk_state = GetGtkState(state); | 141 GtkStateType gtk_state = GetGtkState(state); |
140 *image = gfx::ImageSkia( | 142 *image = gfx::ImageSkia( |
141 new ButtonImageSkiaSource(gtk2_ui_, gtk_state, focused, rect.size()), | 143 new ButtonImageSkiaSource(gtk2_ui_, gtk_state, focused, rect.size()), |
142 rect.size()); | 144 rect.size()); |
143 } | 145 } |
144 canvas->DrawImageInt(*image, rect.x(), rect.y()); | 146 canvas->DrawImageInt(*image, rect.x(), rect.y()); |
145 } | 147 } |
146 } | 148 } |
147 | 149 |
148 bool Gtk2Border::ShouldDrawBorder(bool focused, | |
149 views::Button::ButtonState state) { | |
150 // This logic should be kept in sync with the LabelButtonBorder constructor. | |
151 if (owning_button_->style() == Button::STYLE_BUTTON) { | |
152 return true; | |
153 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { | |
154 return focused == false && (state == Button::STATE_HOVERED || | |
155 state == Button::STATE_PRESSED); | |
156 } | |
157 | |
158 return false; | |
159 } | |
160 | |
161 } // namespace libgtk2ui | 150 } // namespace libgtk2ui |
OLD | NEW |