Closed Bug 669026 Opened 13 years ago Closed 13 years ago

Scrolling with arrow keys is broken if any element on the page has contenteditable=true

Categories

(Core :: DOM: Editor, defect)

x86_64
All
defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
firefox6 - ---

People

(Reporter: jruderman, Assigned: neil)

References

(Depends on 2 open bugs)

Details

(Keywords: testcase)

Attachments

(2 files, 4 obsolete files)

Split from bug 549262.

1. Load the testcase, https://bugzilla.mozilla.org/attachment.cgi?id=459420
2. Press the down arrow key several times.

Result: scrolls to the top of the pink div and stops.
Happens on Windows too => OS = All.
OS: Mac OS X → All
Possibly even a dupe of bug 549262...
Depends on: 549262
(In reply to comment #2)
> Possibly even a dupe of bug 549262...

Oh, forget this comment, I was totally confused.

Boris, is it possible to specify a "fallback" action for the arrow keys?
No longer depends on: 549262
I'm on fire today!  Boris, see comment 3.  :-)
I don't know offhand.... Neil might.
(In reply to comment #5)
> I don't know offhand.... Neil might.
I don't understand the question...
So, here is the problem.  In platformHTMLBindings.xml, we define a VK_DOWN handler for caret navigation command so that you can go to the next line in editor by pressing down for example.  If there is no editable element focused, we need the default behavior of scrolling the page down to take place, so we need some kind of a fallback event handler being bound to VK_DOWN.  Is there any way to do that?
(In reply to comment #7)
> So, here is the problem.  In platformHTMLBindings.xml, we define a VK_DOWN
> handler for caret navigation command so that you can go to the next line in
> editor by pressing down for example.  If there is no editable element
> focused, we need the default behavior of scrolling the page down to take
> place, so we need some kind of a fallback event handler being bound to
> VK_DOWN.  Is there any way to do that?
There is a way to do that, but you have to bind your handlers and attach your controllers to the focused element rather than the window root as you currently do.

The second approach is to fix the editor's command controller to work with editable regions.

The third approach is to stop editor from handling the up and down arrow keys. If you look at the global window controller you'll see that if it thinks there's a caret then it will try to do caret movement instead of scrolling. I think the test detects design mode but not contentEditable regions, so it still tries to do scrolling in that case.
(In reply to comment #8)
> The third approach is to stop editor from handling the up and down arrow
> keys. If you look at the global window controller you'll see that if it
> thinks there's a caret then it will try to do caret movement instead of
> scrolling. I think the test detects design mode but not contentEditable
> regions, so it still tries to do scrolling in that case.
It does detect contentEditable regions. But some focus code to make link focusing work in caret browsing mode blurs the region :-( See nsSelectMoveScrollCommand::DoCommandBrowseWithCaretOn()
Attached patch Patch (v1) (obsolete) — Splinter Review
Assignee: nobody → ehsan
Status: NEW → ASSIGNED
Attachment #548924 - Flags: review?(roc)
Attached patch Proof of concept (obsolete) — Splinter Review
The editor-base.inc change remaps VK_UP to cmd_scrollLineUp because that was easier to prototype, but ideally it would be renamed back to cmd_linePrevious throughout the codebase. The editor command handler is ruled out of the equation, and that code should be removed. The nsGlobalWindowCommands already knows how to move a caret, so that doesn't change, but the focus manager has to be told not to blur a contenteditable region.

Note that even with caret browsing on, this code doesn't move focus in to a contenteditable region either. I don't know whether this is reasonable.
I don't understand why the focus manager change there is OK...
Why don't you make nsEditor::IsActiveInDOMWindow() an insterface method of nsIEditor?

And, PageUp, PageDown, Home, End keys need to be handled too. (I'm not sure about Shift+Arrow or them)
Comment on attachment 548949 [details] [diff] [review]
Proof of concept

Well, I might as well ask for review on the nsFocusManager change, just in case... the point here is that we don't normally get here because the editor command handlers are active in contenteditable mode, but I want to be able to remove the editor motion command handlers because the global ones work anyway, except for the issue that they blur contenteditable regions, which is unwanted.
Attachment #548949 - Flags: review?(enndeakin)
Ehsan, does Neil's approach sound better to you? It does to me.
Is this a regression in 6? How widespread is this likely to be? We're just a few days from the final Beta of 6.
(In reply to comment #19)
> Is this a regression in 6? How widespread is this likely to be? We're just a
> few days from the final Beta of 6.

This is not a regression in 6, from what Ehsan said on IRC, but e.g. planet.m.o is unusable using keys for several days now, due to this bug.
(In reply to comment #20)
> (In reply to comment #19)
> > Is this a regression in 6? How widespread is this likely to be? We're just a
> > few days from the final Beta of 6.
> 
> This is not a regression in 6, from what Ehsan said on IRC, but e.g.
> planet.m.o is unusable using keys for several days now, due to this bug.

While that is true, this bug has existed for ages (I think from Firefox 3+) and there is no good reason why we should track it for Firefox 6...
(In reply to comment #18)
> Ehsan, does Neil's approach sound better to you? It does to me.

As I've said before, I don't understand the focus manager code, so if Neil (Deakin) vouches on that, I'd be fine with Neil's approach.  I'm assuming that he's going to address the todo items in comment 13 once Neil reviews the focus manager change.  Also, Neil, can you check to see if my test case passes successfully with your patch?

(In reply to comment #13)
> Note that even with caret browsing on, this code doesn't move focus in to a
> contenteditable region either. I don't know whether this is reasonable.

That's definitely not desired, but I tested it and we are doing the same thing right now even without this patch, so I don't think we need to worry about this problem here.
Comment on attachment 548949 [details] [diff] [review]
Proof of concept

The focus manager change looks ok, but the editor-base.inc change is not.

The former fixes an issue where there is a selection within the editable area, but the editable area is not focusable, then tab is pressed. (The removed code from nsFocusManager is only called when there is nothing focused).

The editor-base.inc change though makes scrolling occur in a number of situations where it shouldn't, for example, scrolling should not occur while caret browsing is on, nor while the caret is within the focused editable area.

Is the editor attaching it's command controller to the document and not the editable area?
(In reply to comment #23)
> The former fixes an issue where there is a selection within the editable
> area, but the editable area is not focusable, then tab is pressed. (The
> removed code from nsFocusManager is only called when there is nothing
> focused).
I could only get that code to be hit when there was a caret. I'm not sure how to make an unfocusable editable area, but I guess it won't have a caret.

> The editor-base.inc change though makes scrolling occur in a number of
> situations where it shouldn't, for example, scrolling should not occur while
> caret browsing is on, nor while the caret is within the focused editable
> area.
The global window commands already know about caret browsing. (If you look at the browser-base.inc then you'll see the bindings are the same. At some point we may want to rename them back to reduce confusion.) And, except for the code block in the focus manager, its idea of a caret also applies to editable areas, which was why I wanted to remove the code block!

> Is the editor attaching it's command controller to the document and not the
> editable area?
Correct. There was some issue with attaching the commands to the editable area which ehsan has pointed me towards several times but I still forget the bug #.
(In reply to neil@parkwaycc.co.uk from comment #24)
> > Is the editor attaching it's command controller to the document and not the
> > editable area?
> Correct. There was some issue with attaching the commands to the editable
> area which ehsan has pointed me towards several times but I still forget the
> bug #.

I tried very hard in bug 289384 to do that, but I failed miserably...  Maybe because I didn't have a good idea what I'm doing. :/
Attachment #548924 - Attachment is obsolete: true
Attachment #548924 - Flags: review?(roc)
Comment on attachment 548949 [details] [diff] [review]
Proof of concept

I'm not sure if something else is being asked of me here.

With this patch:
 1. Click in the editable area
 2. Press cursor up/down

Expected:
  The caret moves up/down a line
Actual:
  Page scrolls, so keyboard users cannot edit other lines.
Attachment #548949 - Flags: review?(enndeakin) → review-
(In reply to Neil Deakin from comment #26)
> Expected:
>   The caret moves up/down a line
Well, that's what I get locally. Does caret browsing work in your build?
I get the same whether caret browsing is enabled or not.
(In reply to Neil Deakin from comment #28)
> (In reply to neil@parkwaycc.co.uk from comment #27)
> > (In reply to Neil Deakin from comment #26)
> > > Expected:
> > >   The caret moves up/down a line
> > Well, that's what I get locally. Does caret browsing work in your build?
> I get the same whether caret browsing is enabled or not.
Sorry, I wasn't clear, I meant caret browsing in general, not just in editable areas.
Ping?
just in case, HOME/END key is breaks too...
There seems to be some expectation that I respond here but I have nothing else to add. The patch creates an issue as described in comment 26. The same issue occurs with caret browsing enabled or disabled.
Caret browsing doesn't work with this patch. The page scrolls when I try to move the caret up and down.
Attached patch Fixed proof of concept (obsolete) — Splinter Review
Attachment #548949 - Attachment is obsolete: true
Attachment #565950 - Flags: review?(enndeakin)
Comment on attachment 565950 [details] [diff] [review]
Fixed proof of concept

Testing and debugging shows that this seems to work.
Attachment #565950 - Flags: review?(enndeakin) → review+
Neil, does your patch make the test part of attachment 548924 [details] [diff] [review] pass?  If so, we can get them landed.  :-)
(In reply to Ehsan Akhgari from comment #37)
> If so, we can get them landed.  :-)

Except it's very much proof of concept (although I wouldn't mind landing the nsFocusManager.cpp change which would be necessary anyway).

In particular, I'm not sure a) which keys need to be changed b) whether those keys should map to the same commands in textareas and browsers/editors c) how native Linux key bindings fit in.
Attached patch Proposed patch (obsolete) — Splinter Review
The names of the commands are configured in three places:
* GTK2 Native keybindings
* Editor bindings (editor-base.inc and libeditor)
* Browser bindings (browser-base.inc and nsGlobalWindowCommands)
The browser bindings have six differences to the other two sets of bindings,
all cmd_scroll* names, which I have renamed for consistency.
The browser bindings were missing implementations for selecting by page.
The stubs also used the wrong command names, so I corrected that too.
This then allowed me to remove the editor implementation.
Assignee: ehsan → neil
Attachment #565950 - Attachment is obsolete: true
Attachment #569554 - Flags: review?(ehsan)
Comment on attachment 569554 [details] [diff] [review]
Proposed patch

Review of attachment 569554 [details] [diff] [review]:
-----------------------------------------------------------------

Looks very good!

Does my test case pass with this patch?
Attachment #569554 - Flags: review?(ehsan) → review+
(In reply to Ehsan Akhgari from comment #40)
> Does my test case pass with this patch?
Yes, it does.
So, things didn't go quite as well as I'd hoped.

Text areas and input fields need to have the editor behaviour.
Design mode and contenteditable windows need to have the global behaviour.
Attached patch Fixed patchSplinter Review
So, I ended up having to separate the cursor movement commands into their own command table so that I could append that controller for textareas and inputs.
Attachment #569554 - Attachment is obsolete: true
Attachment #570250 - Flags: review?(ehsan)
Neil, any news about this bug?
It affects Fx9+(current beta), if we don't fix it in Fx11, then user have to wait at least 3*6=18 weeks before thay can copy text in those page again...
Sorry, I mistaken this bug for bug 692153.
(In reply to dindog from comment #44)
> Neil, any news about this bug?
ehsan, should I be asking someone else for review?

> It affects Fx9+(current beta), if we don't fix it in Fx11, then user have to
> wait at least 3*6=18 weeks before thay can copy text in those page again...

(In reply to dindog from comment #45)
> Sorry, I mistaken this bug for bug 692153.
Actually it turned out to be fairly straightforward to adapt this patch to apply to Copy, but it won't help with the Select All case.
Comment on attachment 570250 [details] [diff] [review]
Fixed patch

Review of attachment 570250 [details] [diff] [review]:
-----------------------------------------------------------------

I'm not crazy about "editor" vs. "editing" controllers, but I couldn't really think of anything better, so r=me.

Thanks a lot for your work on this, Neil, and sorry that I did a very bad job at responding to the review request in time.
Attachment #570250 - Flags: review?(ehsan) → review+
Try run for e3859a3ea446 is complete.
Detailed breakdown of the results available here:
    https://tbpl.mozilla.org/?tree=Try&rev=e3859a3ea446
Results (out of 208 total builds):
    success: 144
    warnings: 50
    failure: 14
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/neil@parkwaycc.co.uk-e3859a3ea446
test_showcaret.xul: uses cmd_scrollBottom, got renamed to cmd_moveBottom
test_selection_move_commands.xul: many renames...
test_movement_by_characters/word.html: rely on the buggy behaviour!
test_selection_move_commands actually tests for the broken commands. Sigh...
test_movement_by_characters.html's reliance on this bug is due to it failing to focus the content before performing the navigation.

test_movement_by_words.html has the above bug but did also find a real bug; with this patch, you can't move by words to the very end of a contenteditable area, because it tries to move right out of the contenteditable area...
Try run for 8c5b9300caf0 is complete.
Detailed breakdown of the results available here:
    https://tbpl.mozilla.org/?tree=Try&rev=8c5b9300caf0
Results (out of 208 total builds):
    exception: 1
    success: 137
    warnings: 56
    failure: 14
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/neil@parkwaycc.co.uk-8c5b9300caf0
Try run for f0084cbf3b9d is complete.
Detailed breakdown of the results available here:
    https://tbpl.mozilla.org/?tree=Try&rev=f0084cbf3b9d
Results (out of 206 total builds):
    success: 167
    warnings: 24
    failure: 15
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/neil@parkwaycc.co.uk-f0084cbf3b9d
>     warnings: 24
>     failure: 15
Most of these are hidden; 3 randomorange show up on tbpl by default.
More oranges and the reds show up with noignore or via self-serve but they're all Lion, Tegra and/or Jetpack so nobody cares about them.
Attachment #584062 - Flags: review+
This bug is fixed in 20121224 nightly. Neil, would you please look into the copy menuitem too?

Ehsan, sorry again for the other day urge you to review this bug in IRC. I got a reason to worried. Two major sites in China use contenteditable element in part of there service, (In fact, they rank No.1 & No.2 in China and No.5 & No.10 all over the world in Alexa), both are popular things, try imagining as they are Chinese Facebook and Google group, you'll got the picture.

I heard complaint about unable to copy and scroll after Fx9.0 was released. I don't want Firefox losing users. I'll would be better have it fixed not only in nightly, but also beta, even release.
*It* 'll would be better have it fixed not only in nightly, but also beta, even release. 

sorry for the misspell
Pushed changeset 4d0391866459 to mozilla-central.

(In reply to dindog from comment #56)
> Neil, would you please look into the copy menuitem too?
Yes, I'll do copy (but not select all, because it's harder) in bug 692153.
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
"Dude, where's my commands?!" This change removed commands that have been around for many years, breaking add-ons: bug 714164.
Depends on: 714164
Neil, I think you need to add those commands back, and just make us not use them... :(
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Fair enough, and I can put the test back too, but I might as well use bug 714164.
Status: REOPENED → RESOLVED
Closed: 13 years ago13 years ago
Resolution: --- → FIXED
Blocks: 702064
Bug 696020 appears to have exacerbated this problem in 10 (see bug 702064). The attached patch appears to be higher risk than we're comfortable for Beta (please correct me if I'm wrong), but I'm wondering if this is a good candidate for Aurora 11.
(In reply to Alex Keybl [:akeybl] from comment #63)
> Bug 696020 appears to have exacerbated this problem in 10 (see bug 702064).
> The attached patch appears to be higher risk than we're comfortable for Beta
> (please correct me if I'm wrong), but I'm wondering if this is a good
> candidate for Aurora 11.

I'd be much more comfortable if we could back out bug 696020 from Aurora.  smaug, can we do that?
No. We were thinking to release 9.0.2 with bug 696020 fixed.
Or if we do that, we need to backout all
bug 696020, bug 689564 and bug 659350.
If I could request a summary of the status, where are we on this bug now? dindog@163's saying that it's fixed in 20121224 nightly? How about in release? When is this going to be seen in a release, and when?
If I've done my sums right, you should find that it's currently available in Firefox Aurora, will become available in Beta on the 13th, and then released on the 24th of April. (If you think 17 weeks is a long time to wait, don't forget that Firefox 4 came out 14 months after Firefox 3.6!)
Woot, I see this now in Firefox 12. (This is the main reason we're still using a designMode iframe in G+)
(In reply to garryb from comment #70)
> Woot, I see this now in Firefox 12. (This is the main reason we're still
> using a designMode iframe in G+)

Great!  Please file new bugs if you see more problems blocking you from moving to contenteditable elements.
Depends on: 757368
As of 13.0.1 this still hasn't been fixed. Please see attached example:
http://pastebin.com/WTiitrQy
(In reply to Jakub Ondrusek from comment #72)

Please file a new Report in the Core/Editor Component with your Testcase attached. Thanks!
Depends on: 1248186
Depends on: 1250321
Depends on: 1260840
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: