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

Side by Side Diff: views/controls/textfield/native_textfield_gtk.cc

Issue 1155008: Adds the ability to display text in a textfield when the text is (Closed)
Patch Set: Updates Created 10 years, 9 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
« no previous file with comments | « views/controls/textfield/native_textfield_gtk.h ('k') | views/controls/textfield/textfield.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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <gtk/gtk.h> 5 #include <gtk/gtk.h>
6 6
7 #include "views/controls/textfield/native_textfield_gtk.h" 7 #include "views/controls/textfield/native_textfield_gtk.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "gfx/gtk_util.h" 11 #include "gfx/gtk_util.h"
12 #include "gfx/insets.h" 12 #include "gfx/insets.h"
13 #include "gfx/skia_utils_gtk.h" 13 #include "gfx/skia_utils_gtk.h"
14 #include "views/controls/textfield/gtk_views_entry.h"
14 #include "views/controls/textfield/textfield.h" 15 #include "views/controls/textfield/textfield.h"
15 16
16 namespace views { 17 namespace views {
18
17 // A character used to hide a text in password mode. 19 // A character used to hide a text in password mode.
18 const char kPasswordChar = '*'; 20 static const char kPasswordChar = '*';
19 21
20 //////////////////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////////////////
21 // NativeTextfieldGtk, public: 23 // NativeTextfieldGtk, public:
22 24
23 NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield) 25 NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield)
24 : textfield_(textfield) { 26 : textfield_(textfield) {
25 if (textfield_->style() & Textfield::STYLE_MULTILINE) 27 if (textfield_->style() & Textfield::STYLE_MULTILINE)
26 NOTIMPLEMENTED(); // We don't support multiline yet. 28 NOTIMPLEMENTED(); // We don't support multiline yet.
27 // Make |textfield| the focused view, so that when we get focused the focus 29 // Make |textfield| the focused view, so that when we get focused the focus
28 // manager sees |textfield| as the focused view (since we are just a wrapper 30 // manager sees |textfield| as the focused view (since we are just a wrapper
29 // view). 31 // view).
30 set_focus_view(textfield); 32 set_focus_view(textfield);
31 } 33 }
32 34
33 NativeTextfieldGtk::~NativeTextfieldGtk() { 35 NativeTextfieldGtk::~NativeTextfieldGtk() {
34 } 36 }
35 37
38 // Returns the inner border of an entry.
39 // static
40 gfx::Insets NativeTextfieldGtk::GetEntryInnerBorder(GtkEntry* entry) {
41 const GtkBorder* inner_border = gtk_entry_get_inner_border(entry);
42 if (inner_border)
43 return gfx::Insets(*inner_border);
44
45 // No explicit border set, try the style.
46 GtkBorder* style_border;
47 gtk_widget_style_get(GTK_WIDGET(entry), "inner-border", &style_border, NULL);
48 if (style_border) {
49 gfx::Insets insets = gfx::Insets(*style_border);
50 gtk_border_free(style_border);
51 return insets;
52 }
53
54 // If border is null, Gtk uses 2 on all sides.
55 return gfx::Insets(2, 2, 2, 2);
56 }
57
36 //////////////////////////////////////////////////////////////////////////////// 58 ////////////////////////////////////////////////////////////////////////////////
37 // NativeTextfieldGtk, NativeTextfieldWrapper implementation: 59 // NativeTextfieldGtk, NativeTextfieldWrapper implementation:
38 60
39 string16 NativeTextfieldGtk::GetText() const { 61 string16 NativeTextfieldGtk::GetText() const {
40 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(native_view()))); 62 return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(native_view())));
41 } 63 }
42 64
43 void NativeTextfieldGtk::UpdateText() { 65 void NativeTextfieldGtk::UpdateText() {
44 if (!native_view()) 66 if (!native_view())
45 return; 67 return;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 165 }
144 166
145 gfx::Insets NativeTextfieldGtk::CalculateInsets() { 167 gfx::Insets NativeTextfieldGtk::CalculateInsets() {
146 if (!native_view()) 168 if (!native_view())
147 return gfx::Insets(); 169 return gfx::Insets();
148 170
149 GtkWidget* widget = native_view(); 171 GtkWidget* widget = native_view();
150 GtkEntry* entry = GTK_ENTRY(widget); 172 GtkEntry* entry = GTK_ENTRY(widget);
151 gfx::Insets insets; 173 gfx::Insets insets;
152 174
153 const GtkBorder* inner_border = gtk_entry_get_inner_border(entry); 175 insets += GetEntryInnerBorder(entry);
154 if (inner_border) {
155 insets += gfx::Insets(*inner_border);
156 } else {
157 // No explicit border set, try the style.
158 GtkBorder* style_border;
159 gtk_widget_style_get(widget, "inner-border", &style_border, NULL);
160 if (style_border) {
161 insets += gfx::Insets(*style_border);
162 gtk_border_free(style_border);
163 } else {
164 // If border is null, Gtk uses 2 on all sides.
165 insets += gfx::Insets(2, 2, 2, 2);
166 }
167 }
168 176
169 if (entry->has_frame) { 177 if (entry->has_frame) {
170 insets += gfx::Insets(widget->style->ythickness, 178 insets += gfx::Insets(widget->style->ythickness,
171 widget->style->xthickness, 179 widget->style->xthickness,
172 widget->style->ythickness, 180 widget->style->ythickness,
173 widget->style->xthickness); 181 widget->style->xthickness);
174 } 182 }
175 183
176 gboolean interior_focus; 184 gboolean interior_focus;
177 gint focus_width; 185 gint focus_width;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 Textfield::Controller* controller = textfield_->GetController(); 241 Textfield::Controller* controller = textfield_->GetController();
234 if (controller) 242 if (controller)
235 controller->ContentsChanged(textfield_, GetText()); 243 controller->ContentsChanged(textfield_, GetText());
236 return false; 244 return false;
237 } 245 }
238 246
239 //////////////////////////////////////////////////////////////////////////////// 247 ////////////////////////////////////////////////////////////////////////////////
240 // NativeTextfieldGtk, NativeControlGtk overrides: 248 // NativeTextfieldGtk, NativeControlGtk overrides:
241 249
242 void NativeTextfieldGtk::CreateNativeControl() { 250 void NativeTextfieldGtk::CreateNativeControl() {
243 NativeControlCreated(gtk_entry_new()); 251 NativeControlCreated(gtk_views_entry_new(this));
244 gtk_entry_set_invisible_char(GTK_ENTRY(native_view()), 252 gtk_entry_set_invisible_char(GTK_ENTRY(native_view()),
245 static_cast<gunichar>(kPasswordChar)); 253 static_cast<gunichar>(kPasswordChar));
246 textfield_->UpdateAllProperties(); 254 textfield_->UpdateAllProperties();
247 } 255 }
248 256
249 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { 257 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) {
250 NativeControlGtk::NativeControlCreated(widget); 258 NativeControlGtk::NativeControlCreated(widget);
251 g_signal_connect(widget, "changed", 259 g_signal_connect(widget, "changed",
252 G_CALLBACK(OnChangedHandler), this); 260 G_CALLBACK(OnChangedHandler), this);
253 g_signal_connect(widget, "key-press-event", 261 g_signal_connect(widget, "key-press-event",
254 G_CALLBACK(OnKeyPressEventHandler), this); 262 G_CALLBACK(OnKeyPressEventHandler), this);
255 } 263 }
256 264
257 //////////////////////////////////////////////////////////////////////////////// 265 ////////////////////////////////////////////////////////////////////////////////
258 // NativeTextfieldWrapper, public: 266 // NativeTextfieldWrapper, public:
259 267
260 // static 268 // static
261 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( 269 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
262 Textfield* field) { 270 Textfield* field) {
263 return new NativeTextfieldGtk(field); 271 return new NativeTextfieldGtk(field);
264 } 272 }
265 273
266 } // namespace views 274 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/native_textfield_gtk.h ('k') | views/controls/textfield/textfield.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698