| 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 "third_party/skia/include/effects/SkLerpXfermode.h" | 11 #include "third_party/skia/include/effects/SkLerpXfermode.h" |
| 11 #include "ui/base/theme_provider.h" | 12 #include "ui/base/theme_provider.h" |
| 12 #include "ui/gfx/animation/animation.h" | 13 #include "ui/gfx/animation/animation.h" |
| 13 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/image/image_skia_source.h" | 15 #include "ui/gfx/image/image_skia_source.h" |
| 15 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 16 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
| 17 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
| 18 #include "ui/views/native_theme_delegate.h" | 19 #include "ui/views/native_theme_delegate.h" |
| 19 | 20 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); | 69 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 } // namespace | 72 } // namespace |
| 72 | 73 |
| 73 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, | 74 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, |
| 74 views::LabelButton* owning_button, | 75 views::LabelButton* owning_button, |
| 75 scoped_ptr<views::Border> border) | 76 scoped_ptr<views::Border> border) |
| 76 : gtk2_ui_(gtk2_ui), | 77 : gtk2_ui_(gtk2_ui), |
| 77 owning_button_(owning_button), | 78 owning_button_(owning_button), |
| 78 border_(border.Pass()) { | 79 border_(border.Pass()), |
| 79 gtk2_ui_->AddNativeThemeChangeObserver(this); | 80 observer_manager_(this) { |
| 81 observer_manager_.Add(NativeThemeGtk2::instance()); |
| 80 } | 82 } |
| 81 | 83 |
| 82 Gtk2Border::~Gtk2Border() { | 84 Gtk2Border::~Gtk2Border() { |
| 83 gtk2_ui_->RemoveNativeThemeChangeObserver(this); | |
| 84 } | 85 } |
| 85 | 86 |
| 86 void Gtk2Border::Paint(const views::View& view, gfx::Canvas* canvas) { | 87 void Gtk2Border::Paint(const views::View& view, gfx::Canvas* canvas) { |
| 87 ui::ThemeProvider* provider = owning_button_->GetThemeProvider(); | 88 ui::ThemeProvider* provider = owning_button_->GetThemeProvider(); |
| 88 if (!provider || !provider->UsingNativeTheme()) { | 89 if (!provider || !provider->UsingNativeTheme()) { |
| 89 border_->Paint(view, canvas); | 90 border_->Paint(view, canvas); |
| 90 return; | 91 return; |
| 91 } | 92 } |
| 92 | 93 |
| 93 DCHECK_EQ(&view, owning_button_); | 94 DCHECK_EQ(&view, owning_button_); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 138 |
| 138 gfx::Size Gtk2Border::GetMinimumSize() const { | 139 gfx::Size Gtk2Border::GetMinimumSize() const { |
| 139 ui::ThemeProvider* provider = owning_button_->GetThemeProvider(); | 140 ui::ThemeProvider* provider = owning_button_->GetThemeProvider(); |
| 140 if (!provider || !provider->UsingNativeTheme()) | 141 if (!provider || !provider->UsingNativeTheme()) |
| 141 return border_->GetMinimumSize(); | 142 return border_->GetMinimumSize(); |
| 142 | 143 |
| 143 gfx::Insets insets = GetInsets(); | 144 gfx::Insets insets = GetInsets(); |
| 144 return gfx::Size(insets.width(), insets.height()); | 145 return gfx::Size(insets.width(), insets.height()); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void Gtk2Border::OnNativeThemeChanged() { | 148 void Gtk2Border::OnNativeThemeUpdate(ui::NativeTheme* observed_theme) { |
| 149 DCHECK_EQ(observed_theme, NativeThemeGtk2::instance()); |
| 148 for (int i = 0; i < kNumberOfFocusedStates; ++i) { | 150 for (int i = 0; i < kNumberOfFocusedStates; ++i) { |
| 149 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { | 151 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { |
| 150 button_images_[i][j] = gfx::ImageSkia(); | 152 button_images_[i][j] = gfx::ImageSkia(); |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 | 155 |
| 154 // Our owning view must have its layout invalidated because the insets could | 156 // Our owning view must have its layout invalidated because the insets could |
| 155 // have changed. | 157 // have changed. |
| 156 owning_button_->InvalidateLayout(); | 158 owning_button_->InvalidateLayout(); |
| 157 } | 159 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 183 return true; | 185 return true; |
| 184 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { | 186 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { |
| 185 return focused == false && (state == Button::STATE_HOVERED || | 187 return focused == false && (state == Button::STATE_HOVERED || |
| 186 state == Button::STATE_PRESSED); | 188 state == Button::STATE_PRESSED); |
| 187 } | 189 } |
| 188 | 190 |
| 189 return false; | 191 return false; |
| 190 } | 192 } |
| 191 | 193 |
| 192 } // namespace libgtk2ui | 194 } // namespace libgtk2ui |
| OLD | NEW |