зеркало из https://github.com/mozilla/gecko-dev.git
Bug 550434 - Clicking in an empty contenteditable element that has focus causes the caret to disappear; r=roc
This commit is contained in:
Родитель
39a886795d
Коммит
11c5dd5c2b
|
@ -371,6 +371,8 @@ nsEditorEventListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
|||
return rv;
|
||||
}
|
||||
|
||||
EnsureSelectionInEditor(aMouseEvent, PR_FALSE);
|
||||
|
||||
// If we got a mouse down inside the editing area, we should force the
|
||||
// IME to commit before we change the cursor position
|
||||
mEditor->ForceCompositionEnd();
|
||||
|
@ -855,14 +857,21 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
|
|||
NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_AVAILABLE);
|
||||
NS_ENSURE_ARG(aEvent);
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
aEvent->GetTarget(getter_AddRefs(target));
|
||||
|
||||
// turn on selection and caret
|
||||
if (mEditor->IsDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EnsureSelectionInEditor(aEvent, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsEditorEventListener::EnsureSelectionInEditor(nsIDOMEvent* aEvent, PRBool aOnFocus)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
aEvent->GetTarget(getter_AddRefs(target));
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(target);
|
||||
|
||||
PRBool targetIsEditableDoc = PR_FALSE;
|
||||
|
@ -880,12 +889,12 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
|
|||
// listener in the chain changed the focus.
|
||||
if (editableRoot) {
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
NS_ENSURE_TRUE(fm, NS_OK);
|
||||
NS_ENSURE_TRUE(fm, );
|
||||
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
fm->GetFocusedElement(getter_AddRefs(element));
|
||||
if (!SameCOMIdentity(element, target))
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -901,21 +910,23 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
|
|||
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
getter_AddRefs(selection));
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
||||
if (presShell) {
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (caret) {
|
||||
caret->SetIgnoreUserModify(PR_FALSE);
|
||||
if (selection) {
|
||||
caret->SetCaretDOMSelection(selection);
|
||||
if (aOnFocus) {
|
||||
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
||||
if (presShell) {
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (caret) {
|
||||
caret->SetIgnoreUserModify(PR_FALSE);
|
||||
if (selection) {
|
||||
caret->SetCaretDOMSelection(selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selCon->SetCaretReadOnly(mEditor->IsReadonly());
|
||||
selCon->SetCaretEnabled(PR_TRUE);
|
||||
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
||||
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
selCon->SetCaretReadOnly(mEditor->IsReadonly());
|
||||
selCon->SetCaretEnabled(PR_TRUE);
|
||||
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
||||
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISelectionPrivate> selectionPrivate =
|
||||
do_QueryInterface(selection);
|
||||
|
@ -924,7 +935,7 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
|
|||
selectionPrivate->SetAncestorLimiter(editableRoot);
|
||||
}
|
||||
|
||||
if (selection && !editableRoot) {
|
||||
if (aOnFocus && selection && !editableRoot) {
|
||||
PRInt32 rangeCount;
|
||||
selection->GetRangeCount(&rangeCount);
|
||||
if (rangeCount == 0) {
|
||||
|
@ -932,7 +943,6 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
|
|||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -107,6 +107,8 @@ protected:
|
|||
nsresult DragGesture(nsIDOMDragEvent* aDragEvent);
|
||||
already_AddRefed<nsIPresShell> GetPresShell();
|
||||
|
||||
void EnsureSelectionInEditor(nsIDOMEvent* aEvent, PRBool aOnFocus);
|
||||
|
||||
protected:
|
||||
nsEditor* mEditor; // weak
|
||||
nsRefPtr<nsCaret> mCaret;
|
||||
|
|
|
@ -57,6 +57,7 @@ _TEST_FILES = \
|
|||
test_bug487524.html \
|
||||
test_bug525389.html \
|
||||
test_bug537046.html \
|
||||
test_bug550434.html \
|
||||
test_contenteditable_focus.html \
|
||||
test_htmleditor_keyevent_handling.html \
|
||||
test_select_all_without_body.html \
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=550434
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 550434</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=550434">Mozilla Bug 550434</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<div id="editor" contenteditable="true"
|
||||
style="height: 250px; height: 200px; border: 4px solid red; outline: none;"></div>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 550434 **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.waitForFocus(function() {
|
||||
var ed = document.getElementById("editor");
|
||||
|
||||
// Simulate click twice
|
||||
synthesizeMouse(ed, 10, 10, {});
|
||||
synthesizeMouse(ed, 50, 50, {});
|
||||
setTimeout(function() {
|
||||
synthesizeKey("x", {});
|
||||
|
||||
is(ed.innerHTML, "x", "Editor should work after being clicked twice");
|
||||
SimpleTest.finish();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче