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 "third_party/skia/include/effects/SkLerpXfermode.h" | 10 #include "third_party/skia/include/effects/SkLerpXfermode.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const GtkStateType state_; | 64 const GtkStateType state_; |
65 const bool focused_; | 65 const bool focused_; |
66 const gfx::Size size_; | 66 const gfx::Size size_; |
67 | 67 |
68 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); | 68 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); |
69 }; | 69 }; |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, | 73 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, |
74 views::LabelButton* owning_button, | 74 views::LabelButton* owning_button) |
75 scoped_ptr<views::Border> border) | |
76 : gtk2_ui_(gtk2_ui), | 75 : gtk2_ui_(gtk2_ui), |
77 owning_button_(owning_button), | 76 owning_button_(owning_button) { |
78 border_(border.Pass()) { | |
79 gtk2_ui_->AddNativeThemeChangeObserver(this); | 77 gtk2_ui_->AddNativeThemeChangeObserver(this); |
80 } | 78 } |
81 | 79 |
82 Gtk2Border::~Gtk2Border() { | 80 Gtk2Border::~Gtk2Border() { |
83 gtk2_ui_->RemoveNativeThemeChangeObserver(this); | 81 gtk2_ui_->RemoveNativeThemeChangeObserver(this); |
84 } | 82 } |
85 | 83 |
86 void Gtk2Border::Paint(const views::View& view, gfx::Canvas* canvas) { | 84 void Gtk2Border::Paint(const views::View& view, gfx::Canvas* canvas) { |
87 ui::ThemeProvider* provider = owning_button_->GetThemeProvider(); | |
88 if (!provider || !provider->UsingNativeTheme()) { | |
89 border_->Paint(view, canvas); | |
90 return; | |
91 } | |
92 | |
93 DCHECK_EQ(&view, owning_button_); | 85 DCHECK_EQ(&view, owning_button_); |
94 const NativeThemeDelegate* native_theme_delegate = owning_button_; | 86 const NativeThemeDelegate* native_theme_delegate = owning_button_; |
95 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); | 87 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); |
96 ui::NativeTheme::ExtraParams extra; | 88 ui::NativeTheme::ExtraParams extra; |
97 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); | 89 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); |
98 | 90 |
99 const gfx::Animation* animation = native_theme_delegate->GetThemeAnimation(); | 91 const gfx::Animation* animation = native_theme_delegate->GetThemeAnimation(); |
100 if (animation && animation->is_animating()) { | 92 if (animation && animation->is_animating()) { |
101 // Linearly interpolate background and foreground painters during animation. | 93 // Linearly interpolate background and foreground painters during animation. |
102 const SkRect sk_rect = gfx::RectToSkRect(rect); | 94 const SkRect sk_rect = gfx::RectToSkRect(rect); |
(...skipping 10 matching lines...) Expand all Loading... |
113 PaintState(state, extra, rect, canvas); | 105 PaintState(state, extra, rect, canvas); |
114 canvas->sk_canvas()->restore(); | 106 canvas->sk_canvas()->restore(); |
115 | 107 |
116 canvas->sk_canvas()->restore(); | 108 canvas->sk_canvas()->restore(); |
117 } else { | 109 } else { |
118 PaintState(state, extra, rect, canvas); | 110 PaintState(state, extra, rect, canvas); |
119 } | 111 } |
120 } | 112 } |
121 | 113 |
122 gfx::Insets Gtk2Border::GetInsets() const { | 114 gfx::Insets Gtk2Border::GetInsets() const { |
123 // TODO(erg): We want to differentiate between buttons on the toolbar and | |
124 // buttons everywhere else. Right now, the only way to do this is to check | |
125 // the style. STYLE_BUTTON is the button style used in dialogs, and | |
126 // STYLE_TEXTUBTTON is the button style used in the toolbar, including all | |
127 // the buttons which are just toolbar images. | |
128 ui::ThemeProvider* provider = owning_button_->GetThemeProvider(); | |
129 if (owning_button_->style() == views::Button::STYLE_BUTTON || | |
130 (!provider || !provider->UsingNativeTheme())) | |
131 return border_->GetInsets(); | |
132 | |
133 // On STYLE_TEXTUBTTON, we want the smaller insets so we can fit the GTK icon | 115 // On STYLE_TEXTUBTTON, we want the smaller insets so we can fit the GTK icon |
134 // in the toolbar without cutting off the edges of the GTK image. | 116 // in the toolbar without cutting off the edges of the GTK image. |
135 return gtk2_ui_->GetButtonInsets(); | 117 return gtk2_ui_->GetButtonInsets(); |
136 } | 118 } |
137 | 119 |
138 gfx::Size Gtk2Border::GetMinimumSize() const { | 120 gfx::Size Gtk2Border::GetMinimumSize() const { |
139 ui::ThemeProvider* provider = owning_button_->GetThemeProvider(); | |
140 if (!provider || !provider->UsingNativeTheme()) | |
141 return border_->GetMinimumSize(); | |
142 | |
143 gfx::Insets insets = GetInsets(); | 121 gfx::Insets insets = GetInsets(); |
144 return gfx::Size(insets.width(), insets.height()); | 122 return gfx::Size(insets.width(), insets.height()); |
145 } | 123 } |
146 | 124 |
147 void Gtk2Border::OnNativeThemeChanged() { | 125 void Gtk2Border::OnNativeThemeChanged() { |
148 for (int i = 0; i < kNumberOfFocusedStates; ++i) { | 126 for (int i = 0; i < kNumberOfFocusedStates; ++i) { |
149 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { | 127 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { |
150 button_images_[i][j] = gfx::ImageSkia(); | 128 button_images_[i][j] = gfx::ImageSkia(); |
151 } | 129 } |
152 } | 130 } |
(...skipping 30 matching lines...) Expand all Loading... |
183 return true; | 161 return true; |
184 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { | 162 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { |
185 return focused == false && (state == Button::STATE_HOVERED || | 163 return focused == false && (state == Button::STATE_HOVERED || |
186 state == Button::STATE_PRESSED); | 164 state == Button::STATE_PRESSED); |
187 } | 165 } |
188 | 166 |
189 return false; | 167 return false; |
190 } | 168 } |
191 | 169 |
192 } // namespace libgtk2ui | 170 } // namespace libgtk2ui |
OLD | NEW |