Chromium Code Reviews| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 NativeThemeGtk2::instance()->AddObserver(this); |
|
Evan Stade
2014/04/24 01:14:52
nit: ScopedObserver
msw
2014/04/24 18:32:00
Done.
| |
| 80 } | 81 } |
| 81 | 82 |
| 82 Gtk2Border::~Gtk2Border() { | 83 Gtk2Border::~Gtk2Border() { |
| 83 gtk2_ui_->RemoveNativeThemeChangeObserver(this); | 84 NativeThemeGtk2::instance()->RemoveObserver(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() { |
| 148 for (int i = 0; i < kNumberOfFocusedStates; ++i) { | 149 for (int i = 0; i < kNumberOfFocusedStates; ++i) { |
| 149 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { | 150 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { |
| 150 button_images_[i][j] = gfx::ImageSkia(); | 151 button_images_[i][j] = gfx::ImageSkia(); |
| 151 } | 152 } |
| 152 } | 153 } |
| 153 | 154 |
| 154 // Our owning view must have its layout invalidated because the insets could | 155 // Our owning view must have its layout invalidated because the insets could |
| 155 // have changed. | 156 // have changed. |
| 156 owning_button_->InvalidateLayout(); | 157 owning_button_->InvalidateLayout(); |
| 157 } | 158 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 183 return true; | 184 return true; |
| 184 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { | 185 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { |
| 185 return focused == false && (state == Button::STATE_HOVERED || | 186 return focused == false && (state == Button::STATE_HOVERED || |
| 186 state == Button::STATE_PRESSED); | 187 state == Button::STATE_PRESSED); |
| 187 } | 188 } |
| 188 | 189 |
| 189 return false; | 190 return false; |
| 190 } | 191 } |
| 191 | 192 |
| 192 } // namespace libgtk2ui | 193 } // namespace libgtk2ui |
| OLD | NEW |