Closed Bug 563865 Opened 15 years ago Closed 12 years ago

When pressing tab key on a page which has one or more contenteditable editor, focus is moved to the editor, not first focusable element

Categories

(Core :: DOM: Editor, defect)

defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: masayuki, Unassigned)

References

(Blocks 1 open bug, )

Details

Load the URI: > data:text/html,<a href="about:blank">anchor #1</a><br><span contenteditable="true">here is contenteditable</span><br><a href="about:blank">anchor #2</a> And press tab key, then, you can see the focus is moved to the editor. But the first <a> should be focused. In nsEditor::BeginningOfDocument() which is called by nsIEditor::init(), it sets selection (caret position) to the first editable node, but it's wrong with contenteditable and the editable element isn't <html> or <body>. http://mxr.mozilla.org/mozilla-central/source/editor/libeditor/base/nsEditor.cpp#994 > 1011 // find first editable thingy > 1012 nsCOMPtr<nsIDOMNode> firstNode; > 1013 result = GetFirstEditableNode(rootElement, address_of(firstNode)); > 1014 if (firstNode) > 1015 { > 1016 // if firstNode is text, set selection to beginning of the text node > 1017 if (IsTextNode(firstNode)) > 1018 { > 1019 result = selection->Collapse(firstNode, 0); > 1020 } > 1021 else > 1022 { // otherwise, it's a leaf node and we set the selection just in front of it > 1023 nsCOMPtr<nsIDOMNode> parentNode; > 1024 result = firstNode->GetParentNode(getter_AddRefs(parentNode)); > 1025 if (NS_FAILED(result)) { return result; } > 1026 if (!parentNode) { return NS_ERROR_NULL_POINTER; } > 1027 PRInt32 offsetInParent; > 1028 result = nsEditor::GetChildOffset(firstNode, parentNode, offsetInParent); > 1029 if (NS_FAILED(result)) return result; > 1030 result = selection->Collapse(parentNode, offsetInParent); > 1031 } > 1032 } > 1033 else > 1034 { > 1035 // just the root node, set selection to inside the root > 1036 result = selection->Collapse(rootElement, 0); > 1037 } I think that this is only needed when the editor is focused at first time. However, there is bug 389372. If we move the code from there, we can see many assertions until fixing bug 389372.
Hmm, now, this works fine after page load.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.