After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 440963 - Add hinting to GtkEntry
Add hinting to GtkEntry
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkEntry
2.90.x
Other All
: Normal enhancement
: 3.2
Assigned To: gtk-bugs
gtk-bugs
: 566741 602090 625919 (view as bug list)
Depends on:
Blocks: 348933
 
 
Reported: 2007-05-24 15:18 UTC by Ross Burton
Modified: 2011-03-21 09:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Initial rough patch (7.71 KB, patch)
2007-05-24 20:47 UTC, Ross Burton
none Details | Review
maemo patch rebased against master (9.52 KB, patch)
2010-05-27 17:24 UTC, Claudio Saavedra
none Details | Review
Patch against master using tooltip-markup for the text (12.46 KB, patch)
2010-10-20 18:57 UTC, Alberto Garcia
none Details | Review
Test case (1.34 KB, text/plain)
2010-10-20 19:12 UTC, Alberto Garcia
  Details
gtkentry: Add hinting to GtkEntry (13.08 KB, patch)
2011-02-24 12:36 UTC, Carlos Garcia Campos
none Details | Review
gtkentry: Add hinting to GtkEntry (13.36 KB, patch)
2011-03-01 16:47 UTC, Carlos Garcia Campos
none Details | Review
gail: Implement AtkObject::get_description() in GailEntry (5.97 KB, patch)
2011-03-02 17:24 UTC, Carlos Garcia Campos
none Details | Review
gtkentry: Add hinting to GtkEntry (12.11 KB, patch)
2011-03-09 08:56 UTC, Carlos Garcia Campos
accepted-commit_now Details | Review
gail: Implement AtkObject::get_attributes() in GailEntry (6.25 KB, patch)
2011-03-09 08:59 UTC, Carlos Garcia Campos
accepted-commit_now Details | Review

Description Ross Burton 2007-05-24 15:18:06 UTC
Many applications in GNOME and OS X use a hint inside text entries when they are not focused.  For example, the search bar in Evolution.

Basically, when an entry is unfocused and empty, it should display a different string in faded colour.  When it is focused, that string disappears and the entry behaves as usual.  When the entry is unfocused and the text is set to "" again, the hint is shown again.

I think this should be added to GtkEntry as a "hint" property.  I'll try and come up with a patch shortly.
Comment 1 Ross Burton 2007-05-24 20:47:01 UTC
Created attachment 88772 [details] [review]
Initial rough patch

Attaching an initial prod at integrating this into GtkEntry.  This is just to make sure I'm not going totally insane with how I'm manipulating the entry field.

To do:
- api documentation
- handle hinting in GtkEditable:get_characters implementation (cf gtk_entry_get_text)
- check that I don't need handle ->hinting in any more places

The patch also contains a test application which shows a "normal" entry and a "hinted" entry, with labels which are updated when the entries change to check that the hint cannot be obtained except via _get_hint().
Comment 2 Matthias Clasen 2007-05-25 02:35:12 UTC
I know that this kind of "hint" has become more popular recently, but I have some reservations about the design:

- it sends a mixed message: the insensitive appearance says "not editable", while
  the text says "edit me!"

- it shows text that looks like the "content" of the entry, but doesn't behave
  like it, e.g. can't be copied and pasted

In most cases, a clear label and/or a tooltip would probably work just as well without these drawbacks.
Comment 3 Ross Burton 2007-05-25 07:39:42 UTC
Rationale for hinting includes to add extra context (see the Evolution search bar), or for explaining what an entry is for (like a label would) without taking up the extra space (for small screens or compact interfaces).
Comment 4 Peter Clifton 2007-05-25 10:16:13 UTC
I like the idea, its one of the UI concepts I've considered for showing properties inherited from a parent object. The parent's property text would be displayed in a hint like text, and could be over-ridden by typing in the entry.

Un-setting a parent property isn't immediately covered by this case, and I'm not sure how discoverable putting that option in a sexy icon is (E.g. The Evolution icon which sets the find options.)

Will the hint support markup to make the text italic, for example? This makes it look less like text which could be copy-pasted.
Comment 5 Ross Burton 2007-05-25 10:25:09 UTC
The current patch doesn't support markup, but always showing the hint in italic could be a good idea.
Comment 6 Matthias Clasen 2007-05-25 17:45:53 UTC
- too many font styles make for a messy ui appearance

- italic is not meaningful in certain typographies
Comment 7 Ross Burton 2007-05-25 18:28:58 UTC
That convinced me. :)
Comment 8 Peter Clifton 2007-05-30 13:11:40 UTC
Ok, but I think italic may work in English. (I've not mocked it up to see how it looks though). If we allow markup, then the translators can add/remove what is meaningful for their typography. Does that seem a good compromise?
Comment 9 Matthias Clasen 2007-05-30 13:14:51 UTC
I'd really like to see this discussed with some usability/interface designer people, before committing to anything.
Comment 10 Ross Burton 2007-05-30 14:08:12 UTC
I think that recommending that the hints imply further action such as "New Task..." would be a better solution to markup.
Comment 11 Matthias Clasen 2007-05-30 14:16:56 UTC
one problematic aspect of the whole "conserve space by putting informative text in the empty entry" approach that I failed to mention so far:

Once the entry is not empty anymore, the informative text is gone. 
How is a user that comes to the scene at this point going to infer 
what the entry is about ? 
Comment 12 Ross Burton 2007-05-30 14:22:57 UTC
I don't think users would type into entries randomly.  Before it is focused, they'll see the message.  If they have no idea what the entry does they can delete the text and when they focus away, the hint will return.  They only need to use the entry once to understand what it is for.

Obviously this means that people replacing a table of label and entries with a table of hinted entries should be shot.  Hinted entries should be used sparingly, with obvious uses (such as Evolution search bar, Tasks new task bar).
Comment 13 Emmanuele Bassi (:ebassi) 2007-05-30 14:25:57 UTC
an interesting twist would be using the "tooltip-markup" property to fill the hint for GtkEntry; this would make the hinting useful on touchscreen devices which do not have tooltip support.

so:

  g_object_set (entry, "tooltip-markup", "Write foo here", NULL);
  gtk_entry_set_enable_hint (GTK_ENTRY (entry), TRUE);

would show the value of "tooltip-markup" inside the entry (stripped of any real markup), with the text using the colour for the disabled state (it wouldn't look like a disabled entry, because the background colour would not change).
Comment 14 Matthias Clasen 2007-05-30 14:32:07 UTC
> I don't think users would type into entries randomly.  Before it is focused,
> they'll see the message.  If they have no idea what the entry does they can
> delete the text and when they focus away, the hint will return.  They only need
> to use the entry once to understand what it is for.

That is what you are saying now, but soon enough, people will forget about that
and just prefill the entry with the saved value from last time around - which is 
generally a good thing, but in this case, makes the hint useless.

Also, it doesn't help the user who typed something in the entry, switched to a different workspace, and comes back half a day later...
Comment 15 Behdad Esfahbod 2007-05-30 15:34:17 UTC
I second Matthias's concerns.  Evo moved to use such hints for the search target and it's not usable.

Emmanuele's suggestion on the other hand sounds good.
Comment 16 Tuomas Kuosmanen 2007-06-01 09:37:19 UTC
The widget set should be a useful toolkit, the "sense" and elegance of an UI comes from the design, how it is done.

I think this kind of functionality would be good idea, because it helps consistency - currently everyone seems to do this their own way which can lead into inconsistent implementations, being a lot worse.

I think this is especially helpful in handheld devices with small screen, but also for desktop to avoid unnecessary clutter. This would give yet another tool to use when needed.

I do see the problem of this looking "disabled" - but whether this is a real problem, or something we just think in our own heads is hard to say - if the hint text in an entry says "Add new entry..." it's still pretty obvious. I think this would need to be tested whether people really assume the widget is not active. Keep in mind the disabled entry *widget* itself has a different style nevertheless - the hint text is just a label inside otherwise active looking entry.
Comment 17 Matthias Clasen 2009-01-06 14:36:14 UTC
*** Bug 566741 has been marked as a duplicate of this bug. ***
Comment 18 Murray Cumming 2009-06-12 08:52:58 UTC
I understand Mathias Clasen's reservations about this UI technique in general. But there are situations where there just isn't enough space to show the hint anywhere else, so it would be overall better to have the hint in the GtkEntry itself. That's particularly true in embedded UIs that have very large widgets.

Because this bug was unresolved, the Hildon API in Maemo 5 has awkward custom widgets (HildonEntry and HildonTextView) to add this functionality. It would be nice to deprecate them in favour of upstream GTK+ widgets in a future Maemo version. 
Comment 19 Claudio Saavedra 2009-08-28 16:17:47 UTC
Maemo 5's GTK+ has now this implemented in GtkEntry and GtkTextView. I'll try to rebase the patches for GTK+'s master in the next days..
Comment 20 Matthew Paul Thomas (mpt) 2009-09-29 13:45:15 UTC
I campaigned against an equivalent attribute being included for text fields in HTML5 last year, on the grounds that making bad design more difficult to implement would discourage developers from doing it.
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-November/017441.html>
I lost the argument in that case.
<http://www.w3.org/TR/html5/forms.html#the-placeholder-attribute>

Even if GTK+ makes it easy, I hope the Human Interface Guidelines will say "don't do that".
Comment 21 Matthias Clasen 2009-11-23 14:30:05 UTC
*** Bug 602090 has been marked as a duplicate of this bug. ***
Comment 22 Claudio Saavedra 2010-05-27 17:24:10 UTC
Created attachment 162125 [details] [review]
maemo patch rebased against master

This is a cleaner version of the patch in Maemo 5, rebased against master, looking forward to 3.0..
Comment 23 Claudio Saavedra 2010-06-23 21:03:12 UTC
Are there any chances to get this or similar merged into GTK+ or are you so diametrically opposed to it?
Comment 24 Javier Jardón (IRC: jjardon) 2010-08-03 10:17:22 UTC
*** Bug 625919 has been marked as a duplicate of this bug. ***
Comment 25 Adam [:hobophobe] 2010-10-05 20:32:49 UTC
At the very least, shouldn't the color of hints be other than INSENSITIVE?  

Otherwise it's entirely possible for unacceptably low contrast between the input box and the hinting text.  This is especially true as the Theme Manager allows for the Input box color to be set by a user without any indication of how it will affect the display of hinted input boxes.
Comment 26 Alberto Garcia 2010-10-20 18:57:45 UTC
Created attachment 172869 [details] [review]
Patch against master using tooltip-markup for the text

(In reply to comment #13)
> an interesting twist would be using the "tooltip-markup" property to
> fill the hint for GtkEntry

I like this idea, so I've taken the existing patch and updated it to
compile against master and use "tooltip-markup" instead.

I've tested it and it appears to work fine, but comments are of course
appreciated.
Comment 27 Alberto Garcia 2010-10-20 19:12:09 UTC
Created attachment 172870 [details]
Test case

And here's a test case
Comment 28 Carlos Garcia Campos 2011-02-24 12:36:29 UTC
Created attachment 181822 [details] [review]
gtkentry: Add hinting to GtkEntry

This is alberto's patch updated to current git master, ported to GtkStyleContext and connecting to tooltip-text notify signals only when hint is enabled.
Comment 29 Carlos Garcia Campos 2011-02-24 12:42:02 UTC
btw, to test it I used test/testentryicons using the props editor.
Comment 30 Matthias Clasen 2011-02-25 21:51:29 UTC
Quick comments:

- I don't like reusing the tooltip for this. It took me 10 seconds to spot the firefox search entry which has a hint text of 'Google' and a tooltip of 'Search using Google'. So better keep this separate.

- I don't think just blanket doing fg-color / 2 is going to work. Better to have a separate color for this that themes can set independently.
Comment 31 Matthias Clasen 2011-02-25 21:52:38 UTC
Another question that I have not seen discussed before is the a11y implications of displaying text that goes away on focus-in, since focusing a control is usually the way to get the screen reader to read the text to you...
Comment 32 Carlos Garcia Campos 2011-03-01 16:47:50 UTC
Created attachment 182189 [details] [review]
gtkentry: Add hinting to GtkEntry

Updated patch according to comments:

 - Use gtk_entry_set_hint_text() instead of enable_hint() and use the tooltip text
 - Add hint_text_color to default css theme
Comment 33 Joanmarie Diggs (IRC: joanie) 2011-03-01 17:16:50 UTC
(In reply to comment #31)
> Another question that I have not seen discussed before is the a11y implications
> of displaying text that goes away on focus-in, since focusing a control is
> usually the way to get the screen reader to read the text to you...

Could the hint text be exposed to ATs as the accessible description?
Comment 34 Matthias Clasen 2011-03-01 17:19:28 UTC
(In reply to comment #33)
> (In reply to comment #31)
> > Another question that I have not seen discussed before is the a11y implications
> > of displaying text that goes away on focus-in, since focusing a control is
> > usually the way to get the screen reader to read the text to you...
> 
> Could the hint text be exposed to ATs as the accessible description?

No reason it couldn't. I think we normally use the tooltip text for that if no description has been explicitly set.
Comment 35 Alejandro Piñeiro Iglesias (IRC: infapi00) 2011-03-01 17:24:29 UTC
(In reply to comment #34)
> (In reply to comment #33)
> > (In reply to comment #31)
> > > Another question that I have not seen discussed before is the a11y implications
> > > of displaying text that goes away on focus-in, since focusing a control is
> > > usually the way to get the screen reader to read the text to you...
> > 
> > Could the hint text be exposed to ATs as the accessible description?
> 
> No reason it couldn't. I think we normally use the tooltip text for that if no
> description has been explicitly set.

Yes, AFAIR, tooltip is the default description. So it would be just reimplement ->get_description on gailentry. And in the case of having both, I think that the more sensible option would be use the tooltip (so use hint text as the fallback option, when no tooltip or custom accessible description available)
Comment 36 Carlos Garcia Campos 2011-03-02 17:24:38 UTC
Created attachment 182276 [details] [review]
gail: Implement AtkObject::get_description() in GailEntry

Patch for GailEntry. As suggested by API, the hint text is only used as description when GailWidget::get_description() returns NULL.
Comment 37 Joanmarie Diggs (IRC: joanie) 2011-03-05 19:26:09 UTC
(In reply to comment #36)
> Created an attachment (id=182276) [details] [review]
> gail: Implement AtkObject::get_description() in GailEntry
> 

Thanks for doing this Carlos!

> Patch for GailEntry. As suggested by API, the hint text is only used as
> description when GailWidget::get_description() returns NULL.

From the perspective of Orca and its users, my question is: How do we get the hint text the rest of the time, i.e. when GailWidget::get_description() does not return NULL?

I personally think that what is most desirable is consistency. In other words, an assistive technology needs a reliable means by which it can get the hint text (for the purpose of presenting it to the user) and get the tooltip text (for the purpose of presenting it to the user). The presence or absence or one should not impact the other, IMHO.

FWIW, the way Orca users currently get the tooltip text from a Gtk+ widget is by pressing Ctrl+F1 to toggle the tooltip's appearance. When the appearance changes to showing/visible we get the appropriate events and are able to present the tooltip to the user from those events (i.e. we present the tooltip itself and NOT the description associated with the widget).

What I was suggesting in comment 33 is that the hint text always be exposed via the description. Mind you, I had forgotten that tooltip text comes to us this way as well. I completely understand if it is not desirable to change what is currently done with tooltip text. But then I would propose a different solution. For instance, what about always exposing the hint text as an AtkObject Attribute (e.g. 'hint':'bla bla bla')?

(Sorry....)
Comment 38 Benjamin Otte (Company) 2011-03-07 11:40:50 UTC
(In reply to comment #32)
> Created an attachment (id=182189) [details] [review]
> gtkentry: Add hinting to GtkEntry
> 
+  *
+  * The text taht will be displayed in the #GtkEntry when it is empty and unfocused.
+  *
Typo in there.

Question: Why do you keep an extra PangoLayout around for the hint text? I'd much prefer it if we just kept one layout around, namely the layout that is actually displayed. I suspect that's a bit more code to write, but it makes the code cleaner in that priv->cached_layout is the actual layout that is displayed at all times.

Last but not least, I don't like the name "hint", as that is not really correct.
HTML5 names it "placeholder" - see http://dev.w3.org/html5/spec/Overview.html#attr-input-placeholder - I think that's a much better name as it more accurately describes what that string is for.
Comment 39 Alberto Garcia 2011-03-07 14:13:41 UTC
(In reply to comment #38)
> Last but not least, I don't like the name "hint", as that is not
> really correct.  HTML5 names it "placeholder"

That's actually how we named it in Maemo-GTK as well.
Comment 40 Carlos Garcia Campos 2011-03-08 11:24:44 UTC
I've reworked the patch to use one pango layout, and fix the typo mentioned by Company, and I'm about to rename hint_text as placeholder_text but I want to make sure we all agree before doing it.
Comment 41 Alejandro Piñeiro Iglesias (IRC: infapi00) 2011-03-08 12:44:35 UTC
Just to comment that I agree with Joanmarie (see comment 37) after a long discussion (that I think that lead her to write that comment).

In summary:

  * Although the tooltip can be accessed using Ctrl+F1, lets maintain the default accessible description as the tooltip
  * But, as it could be interesting to get the hint (or placeholder) *always*, expose it always, for example using attributes [1]


You can see as a example of this on gailwidget, as it exposes the toolkit. As with the method ref_state_set this should be done incrementally (so gailentry will call the parent get_attributes to get the attributes from the parent, and then add this new attribute).

This is somewhat more complex that just redefine the description, but have the advantage that we could always get the hint, and not just conditionally of having or not a tooltip.

[1] http://library.gnome.org/devel/atk/stable/AtkObject.html#atk-object-get-attributes
Comment 42 Carlos Garcia Campos 2011-03-09 08:56:32 UTC
Created attachment 182937 [details] [review]
gtkentry: Add hinting to GtkEntry

Updated patch:

 - Using only one pango layout
 - Fixed the typo
 - Renamed to placeholder_text
Comment 43 Carlos Garcia Campos 2011-03-09 08:59:32 UTC
Created attachment 182938 [details] [review]
gail: Implement AtkObject::get_attributes() in GailEntry

Use AtkObject::get_attributes() instead of AtkObject::get_description(). It still renames get/set_description to get/set_action_description becuase it's confusing.
Comment 44 Johannes Schmid 2011-03-11 18:18:39 UTC
While we are on it - the same should be done for GtkCellRendererText because it is used in the same way as GtkEntry regarding this matter. One example is the signal-editor for glade.
Comment 45 Matthias Clasen 2011-03-13 02:07:40 UTC
Review of attachment 182937 [details] [review]:

Seems to address all the points raised in review, looks good to me now.

Once thing that would be nice to have is an example for this in gtk3-demo. Maybe add some placeholder text to the 'Search Entry' example ?

::: gtk/gtkentry.c
@@ +5601,1 @@
 

This looks like an unrelated change, should be left out.
Comment 46 Matthias Clasen 2011-03-13 02:08:49 UTC
Review of attachment 182938 [details] [review]:

Looks ok to me.
Comment 47 Carlos Garcia Campos 2011-03-21 09:06:41 UTC
(In reply to comment #45)
> Review of attachment 182937 [details] [review]:
> 
> Seems to address all the points raised in review, looks good to me now.
> 
> Once thing that would be nice to have is an example for this in gtk3-demo.
> Maybe add some placeholder text to the 'Search Entry' example ?

The problem with the search entry example is that the entry is always focused, so you don't see the placeholder text unless you move the focus to another widget. I'll add a new entry demo showing several entries with different placeholder texts

> ::: gtk/gtkentry.c
> @@ +5601,1 @@
> 
> 
> This looks like an unrelated change, should be left out.

Pushed to git master.