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

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

Issue 171413002: linux_aura: Keep GTK state from leaking between profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac compile. Created 6 years, 10 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 "third_party/skia/include/effects/SkLerpXfermode.h" 10 #include "third_party/skia/include/effects/SkLerpXfermode.h"
11 #include "ui/base/theme_provider.h"
11 #include "ui/gfx/animation/animation.h" 12 #include "ui/gfx/animation/animation.h"
12 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/image/image_skia_source.h" 14 #include "ui/gfx/image/image_skia_source.h"
14 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
15 #include "ui/gfx/skia_util.h" 16 #include "ui/gfx/skia_util.h"
16 #include "ui/views/controls/button/label_button.h" 17 #include "ui/views/controls/button/label_button.h"
17 #include "ui/views/native_theme_delegate.h" 18 #include "ui/views/native_theme_delegate.h"
18 19
19 using views::Button; 20 using views::Button;
20 using views::NativeThemeDelegate; 21 using views::NativeThemeDelegate;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 67
67 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource); 68 DISALLOW_COPY_AND_ASSIGN(ButtonImageSkiaSource);
68 }; 69 };
69 70
70 } // namespace 71 } // namespace
71 72
72 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, 73 Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui,
73 views::LabelButton* owning_button, 74 views::LabelButton* owning_button,
74 scoped_ptr<views::Border> border) 75 scoped_ptr<views::Border> border)
75 : gtk2_ui_(gtk2_ui), 76 : gtk2_ui_(gtk2_ui),
76 use_gtk_(gtk2_ui_->GetUseSystemTheme()),
77 owning_button_(owning_button), 77 owning_button_(owning_button),
78 border_(border.Pass()) { 78 border_(border.Pass()) {
79 gtk2_ui_->AddGtkBorder(this); 79 gtk2_ui_->AddGtkBorder(this);
80 } 80 }
81 81
82 Gtk2Border::~Gtk2Border() { 82 Gtk2Border::~Gtk2Border() {
83 gtk2_ui_->RemoveGtkBorder(this); 83 gtk2_ui_->RemoveGtkBorder(this);
84 } 84 }
85 85
86 void Gtk2Border::InvalidateAndSetUsesGtk(bool use_gtk) { 86 void Gtk2Border::InvalidateGtkImages() {
87 for (int i = 0; i < kNumberOfFocusedStates; ++i) { 87 for (int i = 0; i < kNumberOfFocusedStates; ++i) {
88 for (int j = 0; j < views::Button::STATE_COUNT; ++j) { 88 for (int j = 0; j < views::Button::STATE_COUNT; ++j) {
89 button_images_[i][j] = gfx::ImageSkia(); 89 button_images_[i][j] = gfx::ImageSkia();
90 } 90 }
91 } 91 }
92 92
93 // Our owning view must have its layout invalidated because the insets could 93 // Our owning view must have its layout invalidated because the insets could
94 // have changed. 94 // have changed.
95 owning_button_->InvalidateLayout(); 95 owning_button_->InvalidateLayout();
96
97 use_gtk_ = use_gtk;
98 } 96 }
99 97
100 void Gtk2Border::Paint(const views::View& view, gfx::Canvas* canvas) { 98 void Gtk2Border::Paint(const views::View& view, gfx::Canvas* canvas) {
101 if (!use_gtk_) { 99 ui::ThemeProvider* provider = owning_button_->GetThemeProvider();
100 if (!provider || !provider->UsingNativeTheme()) {
102 border_->Paint(view, canvas); 101 border_->Paint(view, canvas);
103 return; 102 return;
104 } 103 }
105 104
106 DCHECK_EQ(&view, owning_button_); 105 DCHECK_EQ(&view, owning_button_);
107 const NativeThemeDelegate* native_theme_delegate = owning_button_; 106 const NativeThemeDelegate* native_theme_delegate = owning_button_;
108 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); 107 gfx::Rect rect(native_theme_delegate->GetThemePaintRect());
109 ui::NativeTheme::ExtraParams extra; 108 ui::NativeTheme::ExtraParams extra;
110 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); 109 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra);
111 110
(...skipping 14 matching lines...) Expand all
126 PaintState(state, extra, rect, canvas); 125 PaintState(state, extra, rect, canvas);
127 canvas->sk_canvas()->restore(); 126 canvas->sk_canvas()->restore();
128 127
129 canvas->sk_canvas()->restore(); 128 canvas->sk_canvas()->restore();
130 } else { 129 } else {
131 PaintState(state, extra, rect, canvas); 130 PaintState(state, extra, rect, canvas);
132 } 131 }
133 } 132 }
134 133
135 gfx::Insets Gtk2Border::GetInsets() const { 134 gfx::Insets Gtk2Border::GetInsets() const {
136 if (!use_gtk_) 135 ui::ThemeProvider* provider = owning_button_->GetThemeProvider();
136 if (!provider || !provider->UsingNativeTheme())
137 return border_->GetInsets(); 137 return border_->GetInsets();
138 138
139 return gtk2_ui_->GetButtonInsets(); 139 return gtk2_ui_->GetButtonInsets();
140 } 140 }
141 141
142 gfx::Size Gtk2Border::GetMinimumSize() const { 142 gfx::Size Gtk2Border::GetMinimumSize() const {
143 if (!use_gtk_) 143 ui::ThemeProvider* provider = owning_button_->GetThemeProvider();
144 if (!provider || !provider->UsingNativeTheme())
144 return border_->GetMinimumSize(); 145 return border_->GetMinimumSize();
145 146
146 gfx::Insets insets = GetInsets(); 147 gfx::Insets insets = GetInsets();
147 return gfx::Size(insets.width(), insets.height()); 148 return gfx::Size(insets.width(), insets.height());
148 } 149 }
149 150
150 void Gtk2Border::PaintState(const ui::NativeTheme::State state, 151 void Gtk2Border::PaintState(const ui::NativeTheme::State state,
151 const ui::NativeTheme::ExtraParams& extra, 152 const ui::NativeTheme::ExtraParams& extra,
152 const gfx::Rect& rect, 153 const gfx::Rect& rect,
153 gfx::Canvas* canvas) { 154 gfx::Canvas* canvas) {
(...skipping 20 matching lines...) Expand all
174 return true; 175 return true;
175 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { 176 } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) {
176 return focused == false && (state == Button::STATE_HOVERED || 177 return focused == false && (state == Button::STATE_HOVERED ||
177 state == Button::STATE_PRESSED); 178 state == Button::STATE_PRESSED);
178 } 179 }
179 180
180 return false; 181 return false;
181 } 182 }
182 183
183 } // namespace libgtk2ui 184 } // 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