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

Unified Diff: views/controls/textfield/gtk_views_entry.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/controls/textfield/gtk_views_entry.h ('k') | views/controls/textfield/native_textfield_gtk.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/textfield/gtk_views_entry.cc
diff --git a/views/controls/textfield/gtk_views_entry.cc b/views/controls/textfield/gtk_views_entry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dbb0be4e8bf83dcfe4dfd04bc57c706e8363727f
--- /dev/null
+++ b/views/controls/textfield/gtk_views_entry.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "views/controls/textfield/gtk_views_entry.h"
+
+#include "app/gfx/canvas_paint.h"
+#include "base/utf_string_conversions.h"
+#include "gfx/insets.h"
+#include "gfx/skia_utils_gtk.h"
+#include "views/controls/textfield/native_textfield_gtk.h"
+#include "views/controls/textfield/textfield.h"
+
+G_BEGIN_DECLS
+
+G_DEFINE_TYPE(GtkViewsEntry, gtk_views_entry, GTK_TYPE_ENTRY)
+
+static gint gtk_views_entry_expose_event(GtkWidget *widget,
+ GdkEventExpose *event) {
+ gint result = GTK_WIDGET_CLASS(gtk_views_entry_parent_class)->expose_event(
+ widget, event);
+
+ GtkEntry* entry = GTK_ENTRY(widget);
+ views::NativeTextfieldGtk* host = GTK_VIEWS_ENTRY(widget)->host;
+
+ // Internally GtkEntry creates an additional window (text_area) that the
+ // text is drawn to. We only need paint after that window has painted.
+ if (host && event->window == entry->text_area &&
+ !host->textfield()->text_to_display_when_empty().empty() &&
+ g_utf8_strlen(gtk_entry_get_text(entry), -1) == 0) {
+ gfx::CanvasPaint canvas(event);
+ if (!canvas.is_empty()) {
+ gfx::Insets insets =
+ views::NativeTextfieldGtk::GetEntryInnerBorder(entry);
+ gfx::Font font = host->textfield()->font();
+ const string16 text = host->textfield()->text_to_display_when_empty();
+ canvas.DrawStringInt(
+ UTF16ToWide(text), font,
+ gfx::GdkColorToSkColor(widget->style->text[GTK_STATE_INSENSITIVE]),
+ insets.left(), insets.top(),
+ widget->allocation.width - insets.width(), font.height());
+ }
+ }
+
+ return result;
+}
+
+static void gtk_views_entry_class_init(GtkViewsEntryClass* views_entry_class) {
+ GtkWidgetClass* widget_class =
+ reinterpret_cast<GtkWidgetClass*>(views_entry_class);
+ widget_class->expose_event = gtk_views_entry_expose_event;
+}
+
+static void gtk_views_entry_init(GtkViewsEntry* entry) {
+ entry->host = NULL;
+}
+
+GtkWidget* gtk_views_entry_new(views::NativeTextfieldGtk* host) {
+ gpointer entry = g_object_new(GTK_TYPE_VIEWS_ENTRY, NULL);
+ GTK_VIEWS_ENTRY(entry)->host = host;
+ return GTK_WIDGET(entry);
+}
+
+G_END_DECLS
« no previous file with comments | « views/controls/textfield/gtk_views_entry.h ('k') | views/controls/textfield/native_textfield_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698