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/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/gfx/image/image_skia_source.h" | 17 #include "ui/gfx/image/image_skia_source.h" |
18 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
19 #include "ui/views/controls/button/blue_button.h" | |
20 #include "ui/views/controls/button/label_button.h" | 19 #include "ui/views/controls/button/label_button.h" |
21 #include "ui/views/controls/button/label_button_border.h" | 20 #include "ui/views/controls/button/label_button_border.h" |
22 #include "ui/views/native_theme_delegate.h" | 21 #include "ui/views/native_theme_delegate.h" |
23 | 22 |
24 using views::Button; | 23 using views::Button; |
25 using views::NativeThemeDelegate; | 24 using views::NativeThemeDelegate; |
26 | 25 |
27 namespace libgtk2ui { | 26 namespace libgtk2ui { |
28 | 27 |
29 namespace { | |
30 | |
31 const int kNumberOfFocusedStates = 2; | |
32 | |
33 class ButtonImageSkiaSource : public gfx::ImageSkiaSource { | |
34 public: | |
35 ButtonImageSkiaSource(const Gtk2UI* gtk2_ui, | |
36 const GtkStateType state, | |
37 const bool focused, | |
38 const bool call_to_action, | |
39 const gfx::Size& size) | |
40 : gtk2_ui_(gtk2_ui), | |
41 state_(state), | |
42 focused_(focused), | |
43 call_to_action_(call_to_action), | |
44 size_(size) { | |
45 } | |
46 | |
47 ~ButtonImageSkiaSource() override {} | |
48 | |
49 gfx::ImageSkiaRep GetImageForScale(float scale) override { | |
50 int w = size_.width() * scale; | |
51 int h = size_.height() * scale; | |
52 return gfx::ImageSkiaRep( | |
53 gtk2_ui_->DrawGtkButtonBorder(state_, focused_, call_to_action_, w, h), | |
54 scale); | |
55 } | |
56 | |
57 private: | |
58 const Gtk2UI* gtk2_ui_; | |
59 const GtkStateType state_; | |
60 const bool focused_; | |
61 const bool call_to_action_; | |
62 const gfx::Size size_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); | |
65 }; | |
66 | |
67 } // namespace | |
68 | |
69 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, | 28 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, |
70 views::LabelButton* owning_button, | 29 views::LabelButton* owning_button, |
71 scoped_ptr<views::LabelButtonBorder> border) | 30 scoped_ptr<views::LabelButtonBorder> border) |
72 : gtk2_ui_(gtk2_ui), | 31 : gtk2_ui_(gtk2_ui), |
73 owning_button_(owning_button), | 32 owning_button_(owning_button), |
74 border_(border.Pass()), | 33 border_(border.Pass()), |
75 observer_manager_(this) { | 34 observer_manager_(this) { |
76 observer_manager_.Add(NativeThemeGtk2::instance()); | 35 observer_manager_.Add(NativeThemeGtk2::instance()); |
77 } | 36 } |
78 | 37 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 gfx::Insets Gtk2Border::GetInsets() const { | 71 gfx::Insets Gtk2Border::GetInsets() const { |
113 return border_->GetInsets(); | 72 return border_->GetInsets(); |
114 } | 73 } |
115 | 74 |
116 gfx::Size Gtk2Border::GetMinimumSize() const { | 75 gfx::Size Gtk2Border::GetMinimumSize() const { |
117 return border_->GetMinimumSize(); | 76 return border_->GetMinimumSize(); |
118 } | 77 } |
119 | 78 |
120 void Gtk2Border::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) { | 79 void Gtk2Border::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) { |
121 DCHECK_EQ(observed_theme, NativeThemeGtk2::instance()); | 80 DCHECK_EQ(observed_theme, NativeThemeGtk2::instance()); |
122 for (int i = 0; i < kNumberOfFocusedStates; ++i) { | 81 for (int i = 0; i < 2; ++i) { |
Elliot Glaysher
2015/09/01 22:43:58
Probably want to keep the constant.
knthzh
2015/09/02 05:48:29
I did it to match the declaration in gtk2_border.h
Elliot Glaysher
2015/09/03 19:28:00
Macros are highly, highly discouraged. (You'll sti
| |
123 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { | 82 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { |
124 button_images_[i][j] = gfx::ImageSkia(); | 83 button_images_[i][j] = gfx::ImageSkia(); |
125 } | 84 } |
126 } | 85 } |
127 | 86 |
128 // Our owning view must have its layout invalidated because the insets could | 87 // Our owning view must have its layout invalidated because the insets could |
129 // have changed. | 88 // have changed. |
130 owning_button_->InvalidateLayout(); | 89 owning_button_->InvalidateLayout(); |
131 } | 90 } |
132 | 91 |
133 void Gtk2Border::PaintState(const ui::NativeTheme::State state, | 92 void Gtk2Border::PaintState(const ui::NativeTheme::State state, |
134 const ui::NativeTheme::ExtraParams& extra, | 93 const ui::NativeTheme::ExtraParams& extra, |
135 const gfx::Rect& rect, | 94 const gfx::Rect& rect, |
136 gfx::Canvas* canvas) { | 95 gfx::Canvas* canvas) { |
137 bool focused = extra.button.is_focused; | 96 bool focused = extra.button.is_focused; |
138 Button::ButtonState views_state = Button::GetButtonStateFrom(state); | 97 Button::ButtonState views_state = Button::GetButtonStateFrom(state); |
139 | 98 |
140 if (border_->PaintsButtonState(focused, views_state)) { | 99 if (border_->PaintsButtonState(focused, views_state)) { |
141 gfx::ImageSkia* image = &button_images_[focused][views_state]; | 100 gfx::ImageSkia* image = &button_images_[focused][views_state]; |
142 | 101 |
143 if (image->isNull() || image->size() != rect.size()) { | 102 if (image->isNull() || image->size() != rect.size()) { |
144 bool call_to_action = owning_button_->GetClassName() == | 103 *image = gfx::ImageSkia::CreateFrom1xBitmap( |
145 views::BlueButton::kViewClassName; | 104 gtk2_ui_->DrawGtkButtonBorder(owning_button_->GetClassName(), |
146 GtkStateType gtk_state = GetGtkState(state); | 105 state, |
147 *image = gfx::ImageSkia( | 106 rect.width(), |
148 new ButtonImageSkiaSource(gtk2_ui_, | 107 rect.height())); |
Elliot Glaysher
2015/09/01 22:43:58
So what's the motivation for this change here? The
knthzh
2015/09/02 05:48:29
Oops, misunderstood the original code. I definitel
| |
149 gtk_state, | |
150 focused, | |
151 call_to_action, | |
152 rect.size()), | |
153 rect.size()); | |
154 } | 108 } |
155 canvas->DrawImageInt(*image, rect.x(), rect.y()); | 109 canvas->DrawImageInt(*image, rect.x(), rect.y()); |
156 } | 110 } |
157 } | 111 } |
158 | 112 |
159 } // namespace libgtk2ui | 113 } // namespace libgtk2ui |
OLD | NEW |