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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const GtkStateType state_; | 65 const GtkStateType state_; |
66 const bool focused_; | 66 const bool focused_; |
67 const gfx::Size size_; | 67 const gfx::Size size_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); | 69 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); |
70 }; | 70 }; |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, | 74 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, |
75 views::LabelButton* owning_button) | 75 views::LabelButton* owning_button, |
| 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), |
| 79 border_(border.Pass()), |
78 observer_manager_(this) { | 80 observer_manager_(this) { |
79 observer_manager_.Add(NativeThemeGtk2::instance()); | 81 observer_manager_.Add(NativeThemeGtk2::instance()); |
80 } | 82 } |
81 | 83 |
82 Gtk2Border::~Gtk2Border() { | 84 Gtk2Border::~Gtk2Border() { |
83 } | 85 } |
84 | 86 |
85 void Gtk2Border::Paint(const views::View& view, gfx::Canvas* canvas) { | 87 void Gtk2Border::Paint(const views::View& view, gfx::Canvas* canvas) { |
86 DCHECK_EQ(&view, owning_button_); | 88 DCHECK_EQ(&view, owning_button_); |
87 const NativeThemeDelegate* native_theme_delegate = owning_button_; | 89 const NativeThemeDelegate* native_theme_delegate = owning_button_; |
(...skipping 18 matching lines...) Expand all Loading... |
106 PaintState(state, extra, rect, canvas); | 108 PaintState(state, extra, rect, canvas); |
107 canvas->sk_canvas()->restore(); | 109 canvas->sk_canvas()->restore(); |
108 | 110 |
109 canvas->sk_canvas()->restore(); | 111 canvas->sk_canvas()->restore(); |
110 } else { | 112 } else { |
111 PaintState(state, extra, rect, canvas); | 113 PaintState(state, extra, rect, canvas); |
112 } | 114 } |
113 } | 115 } |
114 | 116 |
115 gfx::Insets Gtk2Border::GetInsets() const { | 117 gfx::Insets Gtk2Border::GetInsets() const { |
116 // On STYLE_TEXTUBTTON, we want the smaller insets so we can fit the GTK icon | 118 return border_->GetInsets(); |
117 // in the toolbar without cutting off the edges of the GTK image. | |
118 return gtk2_ui_->GetButtonInsets(); | |
119 } | 119 } |
120 | 120 |
121 gfx::Size Gtk2Border::GetMinimumSize() const { | 121 gfx::Size Gtk2Border::GetMinimumSize() const { |
122 gfx::Insets insets = GetInsets(); | 122 return border_->GetMinimumSize(); |
123 return gfx::Size(insets.width(), insets.height()); | |
124 } | 123 } |
125 | 124 |
126 void Gtk2Border::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) { | 125 void Gtk2Border::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) { |
127 DCHECK_EQ(observed_theme, NativeThemeGtk2::instance()); | 126 DCHECK_EQ(observed_theme, NativeThemeGtk2::instance()); |
128 for (int i = 0; i < kNumberOfFocusedStates; ++i) { | 127 for (int i = 0; i < kNumberOfFocusedStates; ++i) { |
129 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { | 128 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { |
130 button_images_[i][j] = gfx::ImageSkia(); | 129 button_images_[i][j] = gfx::ImageSkia(); |
131 } | 130 } |
132 } | 131 } |
133 | 132 |
(...skipping 29 matching lines...) Expand all Loading... |
163 return true; | 162 return true; |
164 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { | 163 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { |
165 return focused == false && (state == Button::STATE_HOVERED || | 164 return focused == false && (state == Button::STATE_HOVERED || |
166 state == Button::STATE_PRESSED); | 165 state == Button::STATE_PRESSED); |
167 } | 166 } |
168 | 167 |
169 return false; | 168 return false; |
170 } | 169 } |
171 | 170 |
172 } // namespace libgtk2ui | 171 } // namespace libgtk2ui |
OLD | NEW |