Closed
Bug 567213
Opened 15 years ago
Closed 15 years ago
selecting editable text and the clicking on an a focusable element does weird things
Categories
(Core :: DOM: Editor, defect)
Core
DOM: Editor
Tracking
()
RESOLVED
FIXED
mozilla1.9.3a5
People
(Reporter: ojan, Assigned: ehsan.akhgari)
Details
Attachments
(3 files)
See the test cases. Also, the similar webkit bug: https://bugs.webkit.org/show_bug.cgi?id=38696.
Reporter | ||
Comment 1•15 years ago
|
||
Assignee | ||
Comment 2•15 years ago
|
||
(In reply to comment #1)
> Created an attachment (id=446568) [details]
> typing test case
In this test case, the actual focus is not lost (you can verify this by typing something, and then enter javascript:alert(document.activeElement) in the location bar). It just happens that the keydown event handler doesn't check if the element is focused, and if typing should actually modify it.
Reporter | ||
Comment 3•15 years ago
|
||
(In reply to comment #2)
> (In reply to comment #1)
> > Created an attachment (id=446568) [details] [details]
> > typing test case
>
> In this test case, the actual focus is not lost (you can verify this by typing
> something, and then enter javascript:alert(document.activeElement) in the
> location bar). It just happens that the keydown event handler doesn't check if
> the element is focused, and if typing should actually modify it.
I don't follow. Here's the output I see in firebug after each of the three steps in the testcase:
>>> document.activeElement
<p contenteditable="" onkeydown="fail()">
>>> document.activeElement
<button>
>>> document.activeElement
<button>
So, even though typing is going into the contentEditable element, the activeElement is still the button. Note that you need to do this in Firebug in a new window for the test to be valid.
Clicking in the location bar messes up your focus in the document (activeElement returns the body), which itself seems like a bug.
Assignee | ||
Comment 4•15 years ago
|
||
(In reply to comment #3)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > Created an attachment (id=446568) [details] [details] [details]
> > > typing test case
> >
> > In this test case, the actual focus is not lost (you can verify this by typing
> > something, and then enter javascript:alert(document.activeElement) in the
> > location bar). It just happens that the keydown event handler doesn't check if
> > the element is focused, and if typing should actually modify it.
>
> I don't follow. Here's the output I see in firebug after each of the three
> steps in the testcase:
> >>> document.activeElement
> <p contenteditable="" onkeydown="fail()">
> >>> document.activeElement
> <button>
> >>> document.activeElement
> <button>
>
> So, even though typing is going into the contentEditable element, the
> activeElement is still the button. Note that you need to do this in Firebug in
> a new window for the test to be valid.
Oh, sure. That's what I meant. After clicking on the button, it gets focused. The problem here is that the keys entered when the button is focused end up modifying the contenteditable section, and the onkeypress event handler has no chance of canceling them because the dispatched event never reaches that element.
> Clicking in the location bar messes up your focus in the document
> (activeElement returns the body), which itself seems like a bug.
I can't reproduce this...
Assignee | ||
Updated•15 years ago
|
OS: Mac OS X → All
Hardware: x86 → All
Version: unspecified → Trunk
Assignee | ||
Comment 5•15 years ago
|
||
The reason behind this bug is that the HTML editor is attached to the document, and typically installs its event listeners on the body element (if available, otherwise on the documentElement). Later on, it decides whether something like a keypress should modify the editable areas based on the NODE_IS_EDITABLE flag on document selection's start node (which is set for contenteditbale nodes and all their descendants, as well as the document node for designMode="on" documents), or on the document itself (for the designMode scenario).
This generally means that keypress events do not follow the node chain they're dispatched to, which is the root of the problems in the attached test cases.
Perhaps the least disruptive fix is to check the editable status on the event target and ignore those events targeted to other nodes in the document.
I have a patch which does this.
Assignee: nobody → ehsan
Status: NEW → ASSIGNED
Assignee | ||
Comment 6•15 years ago
|
||
Attachment #446862 -
Flags: review?(roc)
Attachment #446862 -
Flags: review?(roc) → review+
Assignee | ||
Comment 7•15 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a5
You need to log in
before you can comment on or make changes to this bug.
Description
•