From 688cb6d061d1ecdbbf26ea0d020d55271c8687aa Mon Sep 17 00:00:00 2001 From: "peterv@propagandism.org" Date: Sun, 20 Jan 2008 08:53:08 -0800 Subject: [PATCH] Fix for bug 390278 (Shift+tab no longer navigates out of MIDAS area). r/sr=jst. --- .../html/content/src/nsGenericHTMLElement.cpp | 2 +- .../libeditor/text/nsEditorEventListeners.cpp | 48 ++++++++++++------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index e2bacb4d0c20..d357e586b11d 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -3752,7 +3752,7 @@ nsGenericHTMLElement::IsEditableRoot() const } if (document->HasFlag(NODE_IS_EDITABLE)) { - return this == document->GetRootContent(); + return PR_FALSE; } if (GetContentEditableValue() != eTrue) { diff --git a/editor/libeditor/text/nsEditorEventListeners.cpp b/editor/libeditor/text/nsEditorEventListeners.cpp index 522e6c5b191a..5c66a26efffd 100644 --- a/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/editor/libeditor/text/nsEditorEventListeners.cpp @@ -1065,11 +1065,8 @@ FindSelectionRoot(nsIEditor *aEditor, nsIContent *aContent) CallQueryInterface(rootElement, &root); - if (!root) { - nsIDocument *document = aContent->GetCurrentDoc(); - if (document) { - NS_IF_ADDREF(root = document->GetRootContent()); - } + if (!root && document) { + NS_IF_ADDREF(root = document->GetRootContent()); } return root; @@ -1119,26 +1116,33 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent) { // only enable caret and selection if the editor is not disabled nsCOMPtr content = do_QueryInterface(target); - nsCOMPtr editableRoot = - content ? FindSelectionRoot(mEditor, content) : nsnull; + PRBool targetIsEditableDoc = PR_FALSE; + nsCOMPtr editableRoot; + if (content) { + editableRoot = FindSelectionRoot(mEditor, content); + } + else { + nsCOMPtr document = do_QueryInterface(target); + targetIsEditableDoc = document && document->HasFlag(NODE_IS_EDITABLE); + } nsCOMPtr selCon; mEditor->GetSelectionController(getter_AddRefs(selCon)); - if (selCon) + if (selCon && (targetIsEditableDoc || editableRoot)) { nsCOMPtr selection; selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); nsCOMPtr presShell = do_QueryReferent(mPresShell); - if (presShell) { - nsCOMPtr caret; - presShell->GetCaret(getter_AddRefs(caret)); - if (caret) { - caret->SetIgnoreUserModify(PR_FALSE); - if (selection) { - caret->SetCaretDOMSelection(selection); - } + if (presShell) { + nsCOMPtr caret; + presShell->GetCaret(getter_AddRefs(caret)); + if (caret) { + caret->SetIgnoreUserModify(PR_FALSE); + if (selection) { + caret->SetCaretDOMSelection(selection); + } } } @@ -1203,6 +1207,18 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent) } nsCOMPtr presShell = do_QueryReferent(mPresShell); + nsCOMPtr presSelCon = + do_QueryInterface(presShell); + if (presSelCon == selCon && selection) { + nsCOMPtr target; + aEvent->GetTarget(getter_AddRefs(target)); + nsCOMPtr node = do_QueryInterface(target); + nsIDocument* doc = node ? node->GetOwnerDoc() : nsnull; + if (doc && !doc->HasFlag(NODE_IS_EDITABLE)) { + selection->RemoveAllRanges(); + } + } + if (presShell) { nsCOMPtr caret; presShell->GetCaret(getter_AddRefs(caret));