| 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/native_theme_gtk2.h" | 10 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" |
| 11 #include "third_party/skia/include/effects/SkLerpXfermode.h" | 11 #include "third_party/skia/include/effects/SkLerpXfermode.h" |
| 12 #include "ui/base/theme_provider.h" | 12 #include "ui/base/theme_provider.h" |
| 13 #include "ui/gfx/animation/animation.h" | 13 #include "ui/gfx/animation/animation.h" |
| 14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/image/image_skia_source.h" | 15 #include "ui/gfx/image/image_skia_source.h" |
| 16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
| 18 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
| 19 #include "ui/views/controls/button/label_button_border.h" |
| 19 #include "ui/views/native_theme_delegate.h" | 20 #include "ui/views/native_theme_delegate.h" |
| 20 | 21 |
| 21 using views::Button; | 22 using views::Button; |
| 22 using views::NativeThemeDelegate; | 23 using views::NativeThemeDelegate; |
| 23 | 24 |
| 24 namespace libgtk2ui { | 25 namespace libgtk2ui { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const int kNumberOfFocusedStates = 2; | 29 const int kNumberOfFocusedStates = 2; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 const bool focused_; | 67 const bool focused_; |
| 67 const gfx::Size size_; | 68 const gfx::Size size_; |
| 68 | 69 |
| 69 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); | 70 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 } // namespace | 73 } // namespace |
| 73 | 74 |
| 74 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, | 75 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, |
| 75 views::LabelButton* owning_button, | 76 views::LabelButton* owning_button, |
| 76 scoped_ptr<views::Border> border) | 77 scoped_ptr<views::LabelButtonBorder> border) |
| 77 : gtk2_ui_(gtk2_ui), | 78 : gtk2_ui_(gtk2_ui), |
| 78 owning_button_(owning_button), | 79 owning_button_(owning_button), |
| 79 border_(border.Pass()), | 80 border_(border.Pass()), |
| 80 observer_manager_(this) { | 81 observer_manager_(this) { |
| 81 observer_manager_.Add(NativeThemeGtk2::instance()); | 82 observer_manager_.Add(NativeThemeGtk2::instance()); |
| 82 } | 83 } |
| 83 | 84 |
| 84 Gtk2Border::~Gtk2Border() { | 85 Gtk2Border::~Gtk2Border() { |
| 85 } | 86 } |
| 86 | 87 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 owning_button_->InvalidateLayout(); | 136 owning_button_->InvalidateLayout(); |
| 136 } | 137 } |
| 137 | 138 |
| 138 void Gtk2Border::PaintState(const ui::NativeTheme::State state, | 139 void Gtk2Border::PaintState(const ui::NativeTheme::State state, |
| 139 const ui::NativeTheme::ExtraParams& extra, | 140 const ui::NativeTheme::ExtraParams& extra, |
| 140 const gfx::Rect& rect, | 141 const gfx::Rect& rect, |
| 141 gfx::Canvas* canvas) { | 142 gfx::Canvas* canvas) { |
| 142 bool focused = extra.button.is_focused; | 143 bool focused = extra.button.is_focused; |
| 143 Button::ButtonState views_state = Button::GetButtonStateFrom(state); | 144 Button::ButtonState views_state = Button::GetButtonStateFrom(state); |
| 144 | 145 |
| 145 if (ShouldDrawBorder(focused, views_state)) { | 146 if (border_->GetPainter(focused, views_state) || |
| 147 (focused && border_->GetPainter(false, views_state))) { |
| 146 gfx::ImageSkia* image = &button_images_[focused][views_state]; | 148 gfx::ImageSkia* image = &button_images_[focused][views_state]; |
| 147 | 149 |
| 148 if (image->isNull() || image->size() != rect.size()) { | 150 if (image->isNull() || image->size() != rect.size()) { |
| 149 GtkStateType gtk_state = GetGtkState(state); | 151 GtkStateType gtk_state = GetGtkState(state); |
| 150 *image = gfx::ImageSkia( | 152 *image = gfx::ImageSkia( |
| 151 new ButtonImageSkiaSource(gtk2_ui_, gtk_state, focused, rect.size()), | 153 new ButtonImageSkiaSource(gtk2_ui_, gtk_state, focused, rect.size()), |
| 152 rect.size()); | 154 rect.size()); |
| 153 } | 155 } |
| 154 canvas->DrawImageInt(*image, rect.x(), rect.y()); | 156 canvas->DrawImageInt(*image, rect.x(), rect.y()); |
| 155 } | 157 } |
| 156 } | 158 } |
| 157 | 159 |
| 158 bool Gtk2Border::ShouldDrawBorder(bool focused, | |
| 159 views::Button::ButtonState state) { | |
| 160 // This logic should be kept in sync with the LabelButtonBorder constructor. | |
| 161 if (owning_button_->style() == Button::STYLE_BUTTON) { | |
| 162 return true; | |
| 163 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { | |
| 164 return focused == false && (state == Button::STATE_HOVERED || | |
| 165 state == Button::STATE_PRESSED); | |
| 166 } | |
| 167 | |
| 168 return false; | |
| 169 } | |
| 170 | |
| 171 } // namespace libgtk2ui | 160 } // namespace libgtk2ui |
| OLD | NEW |