From a54b2183fedee89c1cfcfd896482058e92668936 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Sat, 18 May 2013 09:07:46 +0900 Subject: [PATCH] Bug 824080 HTML editor shouldn't set selection state as inactive at losing focus but the document has focus r=ehsan --- editor/libeditor/base/nsEditor.cpp | 57 +++++++++++++++++++ editor/libeditor/base/nsEditor.h | 8 +++ .../libeditor/base/nsEditorEventListener.cpp | 40 +------------ editor/reftests/824080-1-ref.html | 17 ++++++ editor/reftests/824080-1.html | 19 +++++++ editor/reftests/824080-2-ref.html | 22 +++++++ editor/reftests/824080-2.html | 22 +++++++ editor/reftests/824080-3-ref.html | 21 +++++++ editor/reftests/824080-3.html | 21 +++++++ editor/reftests/824080-4-ref.html | 21 +++++++ editor/reftests/824080-4.html | 26 +++++++++ editor/reftests/824080-5-ref.html | 22 +++++++ editor/reftests/824080-5.html | 25 ++++++++ editor/reftests/824080-6-ref.html | 18 ++++++ editor/reftests/824080-6.html | 20 +++++++ editor/reftests/824080-7-ref.html | 19 +++++++ editor/reftests/824080-7.html | 22 +++++++ editor/reftests/reftest.list | 10 ++++ 18 files changed, 371 insertions(+), 39 deletions(-) create mode 100644 editor/reftests/824080-1-ref.html create mode 100644 editor/reftests/824080-1.html create mode 100644 editor/reftests/824080-2-ref.html create mode 100644 editor/reftests/824080-2.html create mode 100644 editor/reftests/824080-3-ref.html create mode 100644 editor/reftests/824080-3.html create mode 100644 editor/reftests/824080-4-ref.html create mode 100644 editor/reftests/824080-4.html create mode 100644 editor/reftests/824080-5-ref.html create mode 100644 editor/reftests/824080-5.html create mode 100644 editor/reftests/824080-6-ref.html create mode 100644 editor/reftests/824080-6.html create mode 100644 editor/reftests/824080-7-ref.html create mode 100644 editor/reftests/824080-7.html diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 0e51641ba901..d25c1e422cc4 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -4957,6 +4957,63 @@ nsEditor::InitializeSelection(nsIDOMEventTarget* aFocusEventTarget) return NS_OK; } +void +nsEditor::FinalizeSelection() +{ + nsCOMPtr selCon; + nsresult rv = GetSelectionController(getter_AddRefs(selCon)); + NS_ENSURE_SUCCESS_VOID(rv); + + nsCOMPtr selection; + rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, + getter_AddRefs(selection)); + NS_ENSURE_SUCCESS_VOID(rv); + + nsCOMPtr selectionPrivate = do_QueryInterface(selection); + NS_ENSURE_TRUE_VOID(selectionPrivate); + + selectionPrivate->SetAncestorLimiter(nullptr); + + nsCOMPtr presShell = GetPresShell(); + NS_ENSURE_TRUE_VOID(presShell); + + nsRefPtr caret = presShell->GetCaret(); + if (caret) { + caret->SetIgnoreUserModify(true); + } + + selCon->SetCaretEnabled(false); + + if (!HasIndependentSelection()) { + // If this editor doesn't have an independent selection, i.e., it must + // mean that it is an HTML editor, the selection controller is shared with + // presShell. So, even this editor loses focus, other part of the document + // may still have focus. + nsCOMPtr doc = GetDocument(); + ErrorResult ret; + if (!doc || !doc->HasFocus(ret)) { + // If the document already lost focus, mark the selection as disabled. + selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED); + } else { + // Otherwise, mark selection as normal because outside of a + // contenteditable element should be selected with normal selection + // color after here. + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); + } + } else if (IsFormWidget() || IsPasswordEditor() || + IsReadonly() || IsDisabled() || IsInputFiltered()) { + // In or + + + diff --git a/editor/reftests/824080-6.html b/editor/reftests/824080-6.html new file mode 100644 index 000000000000..54bafd68099b --- /dev/null +++ b/editor/reftests/824080-6.html @@ -0,0 +1,20 @@ + + + + + + +

normal text

+ + + + diff --git a/editor/reftests/824080-7-ref.html b/editor/reftests/824080-7-ref.html new file mode 100644 index 000000000000..10162cb1f3d6 --- /dev/null +++ b/editor/reftests/824080-7-ref.html @@ -0,0 +1,19 @@ + + + + + + +

normal text

+ + + + diff --git a/editor/reftests/824080-7.html b/editor/reftests/824080-7.html new file mode 100644 index 000000000000..d09e1b5bad3e --- /dev/null +++ b/editor/reftests/824080-7.html @@ -0,0 +1,22 @@ + + + + + + +

normal text

+ + + + diff --git a/editor/reftests/reftest.list b/editor/reftests/reftest.list index 6486a3adec61..b4e83e59220c 100644 --- a/editor/reftests/reftest.list +++ b/editor/reftests/reftest.list @@ -98,3 +98,13 @@ skip-if(Android||B2G) needs-focus == 462758-grabbers-resizers.html 462758-grabbe == 388980-1.html 388980-1-ref.html needs-focus == spellcheck-superscript-1.html spellcheck-superscript-1-ref.html skip-if(B2G) fails-if(Android) needs-focus != spellcheck-superscript-2.html spellcheck-superscript-2-ref.html # bug 783658 +== 824080-1.html 824080-1-ref.html +== 824080-2.html 824080-2-ref.html +== 824080-3.html 824080-3-ref.html +!= 824080-2.html 824080-3.html +== 824080-4.html 824080-4-ref.html +== 824080-5.html 824080-5-ref.html +!= 824080-4.html 824080-5.html +== 824080-6.html 824080-6-ref.html +== 824080-7.html 824080-7-ref.html +!= 824080-6.html 824080-7.html