From c64aea7200d90f14d50cc3c34ba05c5db392f056 Mon Sep 17 00:00:00 2001 From: Martin Stransky Date: Wed, 27 Apr 2016 01:07:00 +0200 Subject: [PATCH] Bug 1263145 - Render multiline input text entries as GtkTextView, r=karlt --- widget/gtk/gtk3drawing.cpp | 52 +++++++++++++++++++++++++++++++++ widget/gtk/gtkdrawing.h | 2 ++ widget/gtk/nsNativeThemeGTK.cpp | 8 ++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/widget/gtk/gtk3drawing.cpp b/widget/gtk/gtk3drawing.cpp index 309e2bffefc0..066e8a026c43 100644 --- a/widget/gtk/gtk3drawing.cpp +++ b/widget/gtk/gtk3drawing.cpp @@ -1510,6 +1510,54 @@ moz_gtk_entry_paint(cairo_t *cr, GdkRectangle* rect, return MOZ_GTK_SUCCESS; } +static gint +moz_gtk_text_view_paint(cairo_t *cr, GdkRectangle* rect, + GtkWidgetState* state, + GtkTextDirection direction) +{ + ensure_text_view_widget(); + ensure_scrolled_window_widget(); + + gtk_widget_set_direction(gTextViewWidget, direction); + gtk_widget_set_direction(gScrolledWindowWidget, direction); + + GtkStyleContext* style = gtk_widget_get_style_context(gTextViewWidget); + gtk_style_context_save(style); + gtk_style_context_add_class(style, GTK_STYLE_CLASS_VIEW); + + GtkStyleContext* style_frame = gtk_widget_get_style_context(gScrolledWindowWidget); + gtk_style_context_save(style_frame); + gtk_style_context_add_class(style_frame, GTK_STYLE_CLASS_FRAME); + + if (state->focused && !state->disabled) { + gtk_style_context_set_state(style, GTK_STATE_FLAG_FOCUSED); + } + + if (state->disabled) { + gtk_style_context_set_state(style, GTK_STATE_FLAG_INSENSITIVE); + gtk_style_context_set_state(style_frame, GTK_STATE_FLAG_INSENSITIVE); + } + gtk_render_frame(style_frame, cr, rect->x, rect->y, rect->width, rect->height); + + GtkBorder border, padding; + GtkStateFlags state_flags = gtk_style_context_get_state(style); + gtk_style_context_get_border(style_frame, state_flags, &border); + gtk_style_context_get_padding(style_frame, state_flags, &padding); + + gint xthickness = border.left + padding.left; + gint ythickness = border.top + padding.top; + + gtk_render_background(style, cr, + rect->x + xthickness, rect->y + ythickness, + rect->width - 2 * xthickness, + rect->height - 2 * ythickness); + + gtk_style_context_restore(style); + gtk_style_context_restore(style_frame); + + return MOZ_GTK_SUCCESS; +} + static gint moz_gtk_treeview_paint(cairo_t *cr, GdkRectangle* rect, GtkWidgetState* state, @@ -2736,6 +2784,7 @@ moz_gtk_get_widget_border(GtkThemeWidgetType widget, gint* left, gint* top, return MOZ_GTK_SUCCESS; } + case MOZ_GTK_TEXT_VIEW: case MOZ_GTK_TREEVIEW: { ensure_scrolled_window_widget(); @@ -3300,6 +3349,9 @@ moz_gtk_widget_paint(GtkThemeWidgetType widget, cairo_t *cr, return moz_gtk_entry_paint(cr, rect, state, gEntryWidget, direction); break; + case MOZ_GTK_TEXT_VIEW: + return moz_gtk_text_view_paint(cr, rect, state, direction); + break; case MOZ_GTK_DROPDOWN: return moz_gtk_combo_box_paint(cr, rect, state, direction); break; diff --git a/widget/gtk/gtkdrawing.h b/widget/gtk/gtkdrawing.h index 5bd8878c8db6..9b39cc0ee5e2 100644 --- a/widget/gtk/gtkdrawing.h +++ b/widget/gtk/gtkdrawing.h @@ -123,6 +123,8 @@ typedef enum { MOZ_GTK_GRIPPER, /* Paints a GtkEntry. */ MOZ_GTK_ENTRY, + /* Paints a GtkTextView. */ + MOZ_GTK_TEXT_VIEW, /* Paints a GtkOptionMenu. */ MOZ_GTK_DROPDOWN, /* Paints a dropdown arrow (a GtkButton containing a down GtkArrow). */ diff --git a/widget/gtk/nsNativeThemeGTK.cpp b/widget/gtk/nsNativeThemeGTK.cpp index 8ee8ba98b1e5..5045d13ece15 100644 --- a/widget/gtk/nsNativeThemeGTK.cpp +++ b/widget/gtk/nsNativeThemeGTK.cpp @@ -510,9 +510,15 @@ nsNativeThemeGTK::GetGtkWidgetAndState(uint8_t aWidgetType, nsIFrame* aFrame, break; case NS_THEME_NUMBER_INPUT: case NS_THEME_TEXTFIELD: - case NS_THEME_TEXTFIELD_MULTILINE: aGtkWidgetType = MOZ_GTK_ENTRY; break; + case NS_THEME_TEXTFIELD_MULTILINE: +#if (MOZ_WIDGET_GTK == 3) + aGtkWidgetType = MOZ_GTK_TEXT_VIEW; +#else + aGtkWidgetType = MOZ_GTK_ENTRY; +#endif + break; case NS_THEME_LISTBOX: case NS_THEME_TREEVIEW: aGtkWidgetType = MOZ_GTK_TREEVIEW;