Last Comment Bug 768503 - Allow moving cursor to overflowed text in selectable content
: Allow moving cursor to overflowed text in selectable content
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: Selection (show other bugs)
: unspecified
: All All
: P2 normal (vote)
: mozilla17
Assigned To: :Ehsan Akhgari
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-26 09:35 PDT by Chris Jones [:cjones] inactive; ni?/f?/r? if you need me
Modified: 2012-08-21 14:10 PDT (History)
20 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
+
+


Attachments
Patch (v1) (976 bytes, patch)
2012-08-16 09:02 PDT, :Ehsan Akhgari
roc: review+
cjones.bugs: feedback+
Details | Diff | Splinter Review

Description Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-06-26 09:35:08 PDT
The problem to be solved here is that on touch devices, the user's finger adjusts the caret position.  But fingers are much fatter than the caret and text around the caret, so the finger can obscure where the caret position is.

To help avoid this problem, UX has proposed implementing a "caret handle".  The proposed behavior of the handle is
 * The caret is always visible
 * Tap anywhere on the text to instantly position the caret on the spot (approximately, I know) and show the handle for a couple of seconds to allow for fine tuning.
 * Start dragging from the handle to move the caret, and be free to move away from the handle while still dragging (so you can prevent your hand/finger for not seeing where you're moving the caret to)
 * Swipe anywhere over the text anytime to scroll.
 * The handle disappears when not used for a couple of seconds or activity elsewhere (kbd, scroll, etc.)

CC'ing jcarpenter for clarification (can't find cyee in bugzilla).  Also see https://github.com/mozilla-b2g/gaia/issues/1685 .
Comment 1 :Ehsan Akhgari 2012-06-26 10:12:04 PDT
Do we have precise mockups on what the user interaction would look like?  Do we want the implementation to live in core (which is where the current caret's implementation lives) or do we want to implement this in JS?
Comment 2 Mark Finkle (:mfinkle) (use needinfo?) 2012-06-26 12:00:35 PDT
This is related to bug 695173 (selection in web content) and bug 765079 (selection in text boxes) and probably a dupe of bug 652168.

I am fine with closing out bug 652168 since it's old and was filed for XUL Fennec.

Margaret is currently using XBL and some JS to control the text selection / caret placement. We are open to other approaches too.
Comment 3 Wesley Johnston (:wesj) 2012-06-26 12:14:01 PDT
(In reply to Ehsan Akhgari [:ehsan] from comment #1)
> Do we have precise mockups on what the user interaction would look like?  Do
> we want the implementation to live in core (which is where the current
> caret's implementation lives) or do we want to implement this in JS?

I'd love to see this in platform tied to drawing the blinking cursor. On Android, the system method of doing this is something like this:

http://www.xiaomiapp.com/wp-content/uploads/2011/04/Android-design-trend-analysis003.jpg
(see image on right).

i.e. a small Frame below the cursor that would be draggable via touch events. The handle should follow the caret (not necessarily at the same point as the user's finger), when it is dragged. We don't have access to this image from Android (not sure if that's possible or not), so the ability to style it with CSS or by some other means would be nice.

Not sure if the B2G team wants something different.
Comment 4 :Ehsan Akhgari 2012-06-26 20:00:14 PDT
I don't think what native fennec does is the correct approach (even for Fennec).  Adding stuff into the page's DOM is messy, and there might be any number of bugs which would cause Gecko's notion of the selection to get out of sync with that of the front-end.

I don't know much about the platform integration side of things, and how the icon can be customizable from content, but I presume that it should be possible with some hackery in the widget code (which is where we get our other platform dependent images from.)
Comment 5 Robert O'Callahan (:roc) (Exited; email my personal email if necessary) 2012-06-26 21:44:56 PDT
One question is how the caret handle should behave when the text is contained in an element subject to various CSS effects --- e.g., opacity, clipping, transforms, being covered by other content, etc. Currently we allow the regular caret to be subject to those effects. Is that what you want for the caret handle? I suspect not.
Comment 6 JP Rosevear [:jpr] 2012-06-27 02:09:54 PDT
(In reply to Ehsan Akhgari [:ehsan] from comment #1)
> Do we have precise mockups on what the user interaction would look like? 

More details here:
https://wiki.mozilla.org/Gaia/System/CursorManagement

and in the PDF there.
Comment 7 Mark Finkle (:mfinkle) (use needinfo?) 2012-06-27 06:04:00 PDT
(In reply to Ehsan Akhgari [:ehsan] from comment #4)
> I don't think what native fennec does is the correct approach (even for
> Fennec).  Adding stuff into the page's DOM is messy, and there might be any
> number of bugs which would cause Gecko's notion of the selection to get out
> of sync with that of the front-end.

The intent in Fennec is to create caret and selection handles using anonymous XBL content, like the video controls. We do not want to inject elements into the DOM in a non-anonymous way.

> I don't know much about the platform integration side of things, and how the
> icon can be customizable from content, but I presume that it should be
> possible with some hackery in the widget code (which is where we get our
> other platform dependent images from.)

For Fennec, we might have a need to dynamically style (using CSS or images) the appearance of the handles depending on the version of Android.
Comment 8 :Ehsan Akhgari 2012-06-27 09:48:18 PDT
(In reply to JP Rosevear [:jpr] from comment #6)
> (In reply to Ehsan Akhgari [:ehsan] from comment #1)
> > Do we have precise mockups on what the user interaction would look like? 
> 
> More details here:
> https://wiki.mozilla.org/Gaia/System/CursorManagement
> 
> and in the PDF there.

How is "moving the finger away while dragging" supposed to work in cases where, for example, the entire document is editable?  Shouldn't the handle follow the finger in that case?
Comment 9 :Ehsan Akhgari 2012-06-27 09:50:23 PDT
(In reply to Mark Finkle (:mfinkle) from comment #7)
> (In reply to Ehsan Akhgari [:ehsan] from comment #4)
> > I don't think what native fennec does is the correct approach (even for
> > Fennec).  Adding stuff into the page's DOM is messy, and there might be any
> > number of bugs which would cause Gecko's notion of the selection to get out
> > of sync with that of the front-end.
> 
> The intent in Fennec is to create caret and selection handles using
> anonymous XBL content, like the video controls. We do not want to inject
> elements into the DOM in a non-anonymous way.

Yeah, I understand.

> > I don't know much about the platform integration side of things, and how the
> > icon can be customizable from content, but I presume that it should be
> > possible with some hackery in the widget code (which is where we get our
> > other platform dependent images from.)
> 
> For Fennec, we might have a need to dynamically style (using CSS or images)
> the appearance of the handles depending on the version of Android.

I think with the current implementation in Fennec that is possible, but that's outside of the scope of this bug.  This bug is hopefully about doing this appropriately in the core code, as opposed to hack a selection mechanism in the front-end for it.  :-)
Comment 10 Wesley Johnston (:wesj) 2012-06-27 09:53:12 PDT
(In reply to Ehsan Akhgari [:ehsan] from comment #8)
> How is "moving the finger away while dragging" supposed to work in cases
> where, for example, the entire document is editable?  Shouldn't the handle
> follow the finger in that case?

The cursor can still only be in certain positions (next to images, not in the middle of them, at the end of lines not way out in white space, at the bottom of a line of text, not in the middle of a letter). In those cases, the caret should stay where the cursor can be and not necessarily where the users finger is.
Comment 11 :Ehsan Akhgari 2012-06-27 09:57:39 PDT
(In reply to Wesley Johnston (:wesj) from comment #10)
> (In reply to Ehsan Akhgari [:ehsan] from comment #8)
> > How is "moving the finger away while dragging" supposed to work in cases
> > where, for example, the entire document is editable?  Shouldn't the handle
> > follow the finger in that case?
> 
> The cursor can still only be in certain positions (next to images, not in
> the middle of them, at the end of lines not way out in white space, at the
> bottom of a line of text, not in the middle of a letter). In those cases,
> the caret should stay where the cursor can be and not necessarily where the
> users finger is.

Yeah but I don't read the wiki page that way.  It talks about making it possible for the user to move their finger away while dragging to see the handle, as if the cursor is locked into either horizontal (or vertical) movement.
Comment 12 Casey Yee 2012-06-27 10:28:53 PDT
(In reply to Ehsan Akhgari [:ehsan] from comment #11)
> (In reply to Wesley Johnston (:wesj) from comment #10)
> > (In reply to Ehsan Akhgari [:ehsan] from comment #8)
> > > How is "moving the finger away while dragging" supposed to work in cases
> > > where, for example, the entire document is editable?  Shouldn't the handle
> > > follow the finger in that case?
> > 
> > The cursor can still only be in certain positions (next to images, not in
> > the middle of them, at the end of lines not way out in white space, at the
> > bottom of a line of text, not in the middle of a letter). In those cases,
> > the caret should stay where the cursor can be and not necessarily where the
> > users finger is.
> 
> Yeah but I don't read the wiki page that way.  It talks about making it
> possible for the user to move their finger away while dragging to see the
> handle, as if the cursor is locked into either horizontal (or vertical)
> movement.

Ehsan described the behavior correctly, though your right, in a multi-line scenario, the cursor wouldn't be locked in a vertical or horizontal movement but should be able to traverse multiple lines.   When you encounter a situation where you at text boundaries (as per Ehan's examples), your finger would be able to move from the handle.   

We (UX) will update the wiki with more details reflective of this conversation.




 we (UX) will update the doc to reflect
Comment 13 :Ehsan Akhgari 2012-06-27 10:40:26 PDT
OK, would you mind also updating this bug when you clarify this on the wiki, please?  Thanks!
Comment 14 Andreas Gal :gal 2012-08-08 15:22:57 PDT
Renom if you think we can't ship a v1 without this.
Comment 15 Jason Smith [:jsmith] 2012-08-08 16:19:45 PDT
Per IRC conversations with a few other folks, I think the best course of action if there is disagreement on whether this blocks or not is to do the following:

- Move the blocking-basecamp flag to ? for re-evaluation
- Indicate a rationale for why you disagree
Comment 16 Andrew Overholt [:overholt] 2012-08-13 11:05:15 PDT
Chris Lee/Josh:  do either of you have thoughts on this from a UX/product standpoint?
Comment 17 Josh Carpenter [:jcarpenter] 2012-08-13 23:02:07 PDT
Casey can better speak to this once he's back from PTO (returns Tuesday 8/13 after a 6 day stretch), but in the interim:

blocking-basecamp? I haven't read the full thread, but I've encountered this problem already in my device usage. I'd entered a long URL into the Browser, IIRC, and needed to edit "HTTP" to "HTTPS". Without caret management I had no way to drag the cursor back to start of the text. Annoying as hell.

This is less pressing if we can enable users to scroll freely within contents of text field. In the example above, I could have scrolled to left, for example, to reveal start of text, and tapped where I wanted to insert cursor. If we had that, it would be easier to defer full caret management to v2.
Comment 18 Jonas Sicking (:sicking) PTO Until July 5th 2012-08-14 13:58:43 PDT
I'm going to make a call here and minus this. This hasn't been listed as an explicit product requirement and we just won't be able to match all the features of competing OSs in v1.
Comment 19 Josh Carpenter [:jcarpenter] 2012-08-14 14:10:31 PDT
We're also discussing this here: https://github.com/mozilla-b2g/gaia/issues/3270

In absence of caret, we at minimum need way for users to traverse the contents of a text field whose cup runneth over.
Comment 20 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-08-14 14:43:13 PDT
IOW, shipping a phone without a way to move the caret in text fields is flat-out unacceptable.
Comment 21 Andreas Gal :gal 2012-08-14 14:46:35 PDT
We need an owner here.
Comment 22 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-08-14 15:03:25 PDT
This bug doesn't necessarily block, but if it doesn't, then we need to make overflowed text areas pannable.
Comment 23 Chris Lee [:clee] 2012-08-15 00:40:10 PDT
This is a *must* have or we'll have tons of customer care calls.

Once additional criteria to consider when deciding if a bug is blocking is the number of customer support calls we believe we would receive.  

Already marked blocking, but we should keep this blocking unless we have an alternative solution per comment 22.
Comment 24 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-08-15 10:54:32 PDT
Ehsan, last I heard you were investigating this --- will you be able to take it through?
Comment 25 :Ehsan Akhgari 2012-08-15 12:50:31 PDT
I was not really investigating anything closely, I was just looking to find out information about what kind of user experience we must support and whether we need to expose something to the web in order to make this possible to implement in HTML/CSS/JS.

The short answer is that for the text selection, I think what Gecko already does is enough here.  For caret movement, the selection.modify API should provide you with what you need.  For rendering the caret at the right position, we need to know the location of the selection end points, and I don't think we have any web-exposed APIs for retrieving that information.

Also, the solution for <input type=text> and <textarea> needs to be specialized, since both those elements put their text inside a native anonymous subtree which is not exposed to the web.

Please let me know if I can provide more information here.
Comment 26 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-08-15 13:41:34 PDT
Oh dear, there's been a considerable amount of miscommunication about this work.

STR the badness here
 (1) Load browser app
 (2) Go to google.com
 (3) Click link to "Privacy"
 (4) Click URL bar to try to edit URL text

If you try to move the caret within the <input>, it's clunky but it works.  Note that the URL text overflows the input box --- if you try to move the caret to the overflowed text, it doesn't work at all.

The goal with this specific bug is to kill two birds with one stone, using a (touch-aware?) caret handle to fix the clunkiness and inability to move the caret.  And do this within gecko instead of with fragile frontend hacks as has been the past m.o.

JP or roc, is there someone who can take over this work?

If not, frontend hackery, I guess ... :(
Comment 27 :Ehsan Akhgari 2012-08-15 14:18:32 PDT
(In reply to comment #26)
> Oh dear, there's been a considerable amount of miscommunication about this
> work.
> 
> STR the badness here
>  (1) Load browser app
>  (2) Go to google.com
>  (3) Click link to "Privacy"
>  (4) Click URL bar to try to edit URL text
> 
> If you try to move the caret within the <input>, it's clunky but it works. 
> Note that the URL text overflows the input box --- if you try to move the caret
> to the overflowed text, it doesn't work at all.

Huh, OK, I had no idea this bug is filed about this STR.  I found a b2g device at the office which I'm charging right now in order to test what's happening here.  It apparently has a ROM which is a couple of weeks old.  Is that good enough to reproduce the bug?

About what happens inside Gecko, we listen for mousedown, mousemove and mouseup.  If the touch events are translated to those events properly, then everything _should_ work the same way it does in desktop Firefox.

Let me test on the device here to figure out what the exact problem is.

> The goal with this specific bug is to kill two birds with one stone, using a
> (touch-aware?) caret handle to fix the clunkiness and inability to move the
> caret.  And do this within gecko instead of with fragile frontend hacks as has
> been the past m.o.

That is also different from what I had heard from b2g folks in the past!  It is definitely possible to do a caret handle inside Gecko, and I think overall it should be easier than doing it in the front-end (and getting it right of course).  But I was under the impression that an implementation living in Gecko is not interesting to b2g.
Comment 28 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-08-15 15:21:25 PDT
(In reply to Ehsan Akhgari [:ehsan] from comment #27)
> (In reply to comment #26)
> > Oh dear, there's been a considerable amount of miscommunication about this
> > work.
> > 
> > STR the badness here
> >  (1) Load browser app
> >  (2) Go to google.com
> >  (3) Click link to "Privacy"
> >  (4) Click URL bar to try to edit URL text
> > 
> > If you try to move the caret within the <input>, it's clunky but it works. 
> > Note that the URL text overflows the input box --- if you try to move the caret
> > to the overflowed text, it doesn't work at all.
> 
> Huh, OK, I had no idea this bug is filed about this STR.  I found a b2g
> device at the office which I'm charging right now in order to test what's
> happening here.  It apparently has a ROM which is a couple of weeks old.  Is
> that good enough to reproduce the bug?
> 

Should.  bjacob also has a recent b2g build.
Comment 29 :Ehsan Akhgari 2012-08-15 16:00:24 PDT
So I tested the device using the latest nightly.  What I see is that it is completely impossible to scroll the caret, and it doesn't matter at all whether you want to scroll to the parts of the text that are visible in the input box or not.  In fact, what happens is that the browser UI itself is scrolled up and down (which is probably its own bug.)

As a quick update, I chatted with cjones about this on IRC.  The behavior added in bug 707734 is not entirely correct for editable content.  I may have a simple patch to fix it -- I'm planning to test it locally first.
Comment 30 :Ehsan Akhgari 2012-08-16 09:02:11 PDT
Created attachment 652467 [details] [diff] [review]
Patch (v1)

This patch restores Gecko's text selection support for editable content.  It doesn't regress what bug 707734 tried to fix as far as I can tell.

Here is the behavior that I get with this patch:
* In the browser's address bar, I can now tap and hold and move my finger to select text, and I can also scroll past the overflow section.  I can use the IME keyboard to delete the selected text or replace it with something, as one would expect.
* In the browser's content area, tapping on an input, textarea or a contenteditable brings up the keyboard, and tapping again to move my finger to select text makes the IME keyboard disappear and therefore the caret goes away.  This seems to be a bug in the IME keyboard.  I think making the IME keyboard stay on the screen would fix that, since in that case those elements would effectively be treated the same way as the browser's address bar.
* In the browser's content area, the keyboard appears with a lag, so if you tap to activate an input, textarea or contenteditable and don't lift your finger, wait for the IME keybaord to show up and then move your finger, you can do selection, but that is not pleasant at all.
* There seems to be rendering bugs where you select and scroll text in a textarea, so we should probably fix those as part of a follow-up bug as well.

Asking feedback from cjones mostly because I want him to test this patch as well.
Comment 31 :Ehsan Akhgari 2012-08-16 09:24:42 PDT
Comment on attachment 652467 [details] [diff] [review]
Patch (v1)

Ah, the comment needs to be adjusted as well.  I'll do that when landing.
Comment 32 Mark Finkle (:mfinkle) (use needinfo?) 2012-08-16 10:30:39 PDT
Ehsan - Can you test this on Firefox for Android too? I just want to be sure we don't regress text selection there.
Comment 33 :Ehsan Akhgari 2012-08-16 12:01:47 PDT
(In reply to comment #32)
> Ehsan - Can you test this on Firefox for Android too? I just want to be sure we
> don't regress text selection there.

Hrm, the pref in question is not set on Android, is it?
Comment 34 Mark Finkle (:mfinkle) (use needinfo?) 2012-08-16 13:50:02 PDT
(In reply to Ehsan Akhgari [:ehsan] from comment #33)
> (In reply to comment #32)
> > Ehsan - Can you test this on Firefox for Android too? I just want to be sure we
> > don't regress text selection there.
> 
> Hrm, the pref in question is not set on Android, is it?

Checked out the patch. Right, not currently used on Fennec.
Comment 35 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-08-16 18:19:57 PDT
Comment on attachment 652467 [details] [diff] [review]
Patch (v1)

Works like a charm!  Nice fix :).
Comment 36 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-08-16 18:30:36 PDT
https://tbpl.mozilla.org/?tree=Try&rev=c7ae5d5c5bfa
Comment 37 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-08-17 00:56:57 PDT
https://hg.mozilla.org/integration/mozilla-inbound/rev/fc8dc06d7592
Comment 38 Chris Jones [:cjones] inactive; ni?/f?/r? if you need me 2012-08-17 01:05:27 PDT
Morphing to what was fixed here.
Comment 39 Ryan VanderMeulen [:RyanVM] 2012-08-17 19:23:56 PDT
https://hg.mozilla.org/mozilla-central/rev/fc8dc06d7592
Comment 40 :Ehsan Akhgari 2012-08-21 14:10:01 PDT
Thanks for landing the patch!  I fixed the comment around this code as promised: https://hg.mozilla.org/mozilla-central/rev/9315dc9bb36f

Note You need to log in before you can comment on or make changes to this bug.