Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: chrome/browser/ui/libgtk2ui/gtk2_border.cc

Issue 340003002: Revert of views: Move MenuButton from TextButton to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_border.h ('k') | chrome/browser/ui/libgtk2ui/gtk2_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gtk2_util.h" 10 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h"
11 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" 11 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h"
12 #include "third_party/skia/include/effects/SkLerpXfermode.h" 12 #include "third_party/skia/include/effects/SkLerpXfermode.h"
13 #include "ui/base/theme_provider.h" 13 #include "ui/base/theme_provider.h"
14 #include "ui/gfx/animation/animation.h" 14 #include "ui/gfx/animation/animation.h"
15 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/image/image_skia_source.h" 16 #include "ui/gfx/image/image_skia_source.h"
17 #include "ui/gfx/rect.h" 17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/skia_util.h" 18 #include "ui/gfx/skia_util.h"
19 #include "ui/views/controls/button/label_button.h" 19 #include "ui/views/controls/button/label_button.h"
20 #include "ui/views/controls/button/label_button_border.h"
21 #include "ui/views/native_theme_delegate.h" 20 #include "ui/views/native_theme_delegate.h"
22 21
23 using views::Button; 22 using views::Button;
24 using views::NativeThemeDelegate; 23 using views::NativeThemeDelegate;
25 24
26 namespace libgtk2ui { 25 namespace libgtk2ui {
27 26
28 namespace { 27 namespace {
29 28
30 const int kNumberOfFocusedStates = 2; 29 const int kNumberOfFocusedStates = 2;
(...skipping 26 matching lines...) Expand all
57 const bool focused_; 56 const bool focused_;
58 const gfx::Size size_; 57 const gfx::Size size_;
59 58
60 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); 59 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource);
61 }; 60 };
62 61
63 } // namespace 62 } // namespace
64 63
65 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, 64 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui,
66 views::LabelButton* owning_button, 65 views::LabelButton* owning_button,
67 scoped_ptr<views::LabelButtonBorder> border) 66 scoped_ptr<views::Border> border)
68 : gtk2_ui_(gtk2_ui), 67 : gtk2_ui_(gtk2_ui),
69 owning_button_(owning_button), 68 owning_button_(owning_button),
70 border_(border.Pass()), 69 border_(border.Pass()),
71 observer_manager_(this) { 70 observer_manager_(this) {
72 observer_manager_.Add(NativeThemeGtk2::instance()); 71 observer_manager_.Add(NativeThemeGtk2::instance());
73 } 72 }
74 73
75 Gtk2Border::~Gtk2Border() { 74 Gtk2Border::~Gtk2Border() {
76 } 75 }
77 76
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 owning_button_->InvalidateLayout(); 125 owning_button_->InvalidateLayout();
127 } 126 }
128 127
129 void Gtk2Border::PaintState(const ui::NativeTheme::State state, 128 void Gtk2Border::PaintState(const ui::NativeTheme::State state,
130 const ui::NativeTheme::ExtraParams& extra, 129 const ui::NativeTheme::ExtraParams& extra,
131 const gfx::Rect& rect, 130 const gfx::Rect& rect,
132 gfx::Canvas* canvas) { 131 gfx::Canvas* canvas) {
133 bool focused = extra.button.is_focused; 132 bool focused = extra.button.is_focused;
134 Button::ButtonState views_state = Button::GetButtonStateFrom(state); 133 Button::ButtonState views_state = Button::GetButtonStateFrom(state);
135 134
136 if (border_->GetPainter(focused, views_state) || 135 if (ShouldDrawBorder(focused, views_state)) {
137 (focused && border_->GetPainter(false, views_state))) {
138 gfx::ImageSkia* image = &button_images_[focused][views_state]; 136 gfx::ImageSkia* image = &button_images_[focused][views_state];
139 137
140 if (image->isNull() || image->size() != rect.size()) { 138 if (image->isNull() || image->size() != rect.size()) {
141 GtkStateType gtk_state = GetGtkState(state); 139 GtkStateType gtk_state = GetGtkState(state);
142 *image = gfx::ImageSkia( 140 *image = gfx::ImageSkia(
143 new ButtonImageSkiaSource(gtk2_ui_, gtk_state, focused, rect.size()), 141 new ButtonImageSkiaSource(gtk2_ui_, gtk_state, focused, rect.size()),
144 rect.size()); 142 rect.size());
145 } 143 }
146 canvas->DrawImageInt(*image, rect.x(), rect.y()); 144 canvas->DrawImageInt(*image, rect.x(), rect.y());
147 } 145 }
148 } 146 }
149 147
148 bool Gtk2Border::ShouldDrawBorder(bool focused,
149 views::Button::ButtonState state) {
150 // This logic should be kept in sync with the LabelButtonBorder constructor.
151 if (owning_button_->style() == Button::STYLE_BUTTON) {
152 return true;
153 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) {
154 return focused == false && (state == Button::STATE_HOVERED ||
155 state == Button::STATE_PRESSED);
156 }
157
158 return false;
159 }
160
150 } // namespace libgtk2ui 161 } // namespace libgtk2ui
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_border.h ('k') | chrome/browser/ui/libgtk2ui/gtk2_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698