| 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 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_GTK2_BORDER_H_ | 5 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_GTK2_BORDER_H_ |
| 6 #define CHROME_BROWSER_UI_LIBGTK2UI_GTK2_BORDER_H_ | 6 #define CHROME_BROWSER_UI_LIBGTK2UI_GTK2_BORDER_H_ |
| 7 | 7 |
| 8 #include "base/scoped_observer.h" |
| 8 #include "ui/gfx/image/image_skia.h" | 9 #include "ui/gfx/image/image_skia.h" |
| 9 #include "ui/native_theme/native_theme.h" | 10 #include "ui/native_theme/native_theme.h" |
| 10 #include "ui/views/border.h" | 11 #include "ui/views/border.h" |
| 11 #include "ui/views/controls/button/button.h" | 12 #include "ui/views/controls/button/button.h" |
| 12 #include "ui/views/linux_ui/native_theme_change_observer.h" | |
| 13 | 13 |
| 14 namespace gfx { | 14 namespace gfx { |
| 15 class Canvas; | 15 class Canvas; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| 19 class LabelButton; | 19 class LabelButton; |
| 20 class Border; | 20 class Border; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace libgtk2ui { | 23 namespace libgtk2ui { |
| 24 class Gtk2UI; | 24 class Gtk2UI; |
| 25 | 25 |
| 26 // Draws a gtk button border, and manages the memory of the resulting pixbufs. | 26 // Draws a gtk button border, and manages the memory of the resulting pixbufs. |
| 27 class Gtk2Border : public views::Border, | 27 class Gtk2Border : public views::Border, public ui::NativeThemeObserver { |
| 28 public views::NativeThemeChangeObserver { | |
| 29 public: | 28 public: |
| 30 Gtk2Border(Gtk2UI* gtk2_ui, | 29 Gtk2Border(Gtk2UI* gtk2_ui, |
| 31 views::LabelButton* owning_button, | 30 views::LabelButton* owning_button, |
| 32 scoped_ptr<views::Border> border); | 31 scoped_ptr<views::Border> border); |
| 33 virtual ~Gtk2Border(); | 32 virtual ~Gtk2Border(); |
| 34 | 33 |
| 35 // Overridden from views::Border: | 34 // Overridden from views::Border: |
| 36 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; | 35 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; |
| 37 virtual gfx::Insets GetInsets() const OVERRIDE; | 36 virtual gfx::Insets GetInsets() const OVERRIDE; |
| 38 virtual gfx::Size GetMinimumSize() const OVERRIDE; | 37 virtual gfx::Size GetMinimumSize() const OVERRIDE; |
| 39 | 38 |
| 40 // Overridden from views::NativeThemeChangeObserver: | 39 // Overridden from views::NativeThemeChangeObserver: |
| 41 virtual void OnNativeThemeChanged() OVERRIDE; | 40 virtual void OnNativeThemeUpdate(ui::NativeTheme* observed_theme) OVERRIDE; |
| 42 | 41 |
| 43 private: | 42 private: |
| 44 void PaintState(const ui::NativeTheme::State state, | 43 void PaintState(const ui::NativeTheme::State state, |
| 45 const ui::NativeTheme::ExtraParams& extra, | 44 const ui::NativeTheme::ExtraParams& extra, |
| 46 const gfx::Rect& rect, | 45 const gfx::Rect& rect, |
| 47 gfx::Canvas* canvas); | 46 gfx::Canvas* canvas); |
| 48 | 47 |
| 49 bool ShouldDrawBorder(bool focused, views::Button::ButtonState state); | 48 bool ShouldDrawBorder(bool focused, views::Button::ButtonState state); |
| 50 | 49 |
| 51 Gtk2UI* gtk2_ui_; | 50 Gtk2UI* gtk2_ui_; |
| 52 | 51 |
| 53 gfx::ImageSkia button_images_[2][views::Button::STATE_COUNT]; | 52 gfx::ImageSkia button_images_[2][views::Button::STATE_COUNT]; |
| 54 | 53 |
| 55 // The view to which we are a border. We keep track of this so that we can | 54 // The view to which we are a border. We keep track of this so that we can |
| 56 // force invalidate the layout on theme changes. | 55 // force invalidate the layout on theme changes. |
| 57 views::LabelButton* owning_button_; | 56 views::LabelButton* owning_button_; |
| 58 | 57 |
| 59 // Since we don't want to expose the concept of whether we're using a GTK | 58 // Since we don't want to expose the concept of whether we're using a GTK |
| 60 // theme down to the cross platform views layer, we keep a normal Border and | 59 // theme down to the cross platform views layer, we keep a normal Border and |
| 61 // delegate to it whenever we aren't in GTK theme mode. | 60 // delegate to it whenever we aren't in GTK theme mode. |
| 62 scoped_ptr<views::Border> border_; | 61 scoped_ptr<views::Border> border_; |
| 63 | 62 |
| 63 ScopedObserver<ui::NativeTheme, ui::NativeThemeObserver> observer_manager_; |
| 64 |
| 64 DISALLOW_COPY_AND_ASSIGN(Gtk2Border); | 65 DISALLOW_COPY_AND_ASSIGN(Gtk2Border); |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 } // namespace libgtk2ui | 68 } // namespace libgtk2ui |
| 68 | 69 |
| 69 #endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_BORDER_H_ | 70 #endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_BORDER_H_ |
| OLD | NEW |