diff --git a/content/html/content/src/nsTextEditorState.cpp b/content/html/content/src/nsTextEditorState.cpp index a0be3a92fda..a1f5daa48d6 100644 --- a/content/html/content/src/nsTextEditorState.cpp +++ b/content/html/content/src/nsTextEditorState.cpp @@ -82,11 +82,13 @@ struct SelectionState { class RestoreSelectionState : public nsRunnable { public: - RestoreSelectionState(nsTextControlFrame *aFrame, PRInt32 aStart, PRInt32 aEnd) + RestoreSelectionState(nsTextEditorState *aState, nsTextControlFrame *aFrame, + PRInt32 aStart, PRInt32 aEnd) : mFrame(aFrame), mWeakFrame(aFrame), mStart(aStart), - mEnd(aEnd) + mEnd(aEnd), + mTextEditorState(aState) { } @@ -96,6 +98,7 @@ public: // need to block script to avoid nested PrepareEditor calls (bug 642800). nsAutoScriptBlocker scriptBlocker; mFrame->SetSelectionRange(mStart, mEnd); + mTextEditorState->HideSelectionIfBlurred(); } return NS_OK; } @@ -105,6 +108,7 @@ private: nsWeakFrame mWeakFrame; PRInt32 mStart; PRInt32 mEnd; + nsTextEditorState* mTextEditorState; }; /*static*/ @@ -1385,7 +1389,7 @@ nsTextEditorState::PrepareEditor(const nsAString *aValue) // Restore our selection after being bound to a new frame if (mSelState) { - nsContentUtils::AddScriptRunner(new RestoreSelectionState(mBoundFrame, mSelState->mStart, mSelState->mEnd)); + nsContentUtils::AddScriptRunner(new RestoreSelectionState(this, mBoundFrame, mSelState->mStart, mSelState->mEnd)); mSelState = nsnull; } @@ -2011,6 +2015,16 @@ nsTextEditorState::SetPlaceholderClass(PRBool aVisible, classValue, aNotify); } +void +nsTextEditorState::HideSelectionIfBlurred() +{ + NS_ABORT_IF_FALSE(mSelCon, "Should have a selection controller if we have a frame!"); + nsCOMPtr content = do_QueryInterface(mTextCtrlElement); + if (!nsContentUtils::IsFocusedContent(content)) { + mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_HIDDEN); + } +} + NS_IMPL_ISUPPORTS1(nsAnonDivObserver, nsIMutationObserver) void diff --git a/content/html/content/src/nsTextEditorState.h b/content/html/content/src/nsTextEditorState.h index e97154c5f7f..ec707dae03e 100644 --- a/content/html/content/src/nsTextEditorState.h +++ b/content/html/content/src/nsTextEditorState.h @@ -210,6 +210,8 @@ public: void ClearValueCache() { mCachedValue.Truncate(); } + void HideSelectionIfBlurred(); + private: // not copy constructible nsTextEditorState(const nsTextEditorState&); diff --git a/layout/reftests/editor/reftest.list b/layout/reftests/editor/reftest.list index 69f7d2e4f33..9ac99591f85 100644 --- a/layout/reftests/editor/reftest.list +++ b/layout/reftests/editor/reftest.list @@ -60,3 +60,5 @@ fails-if(Android) != spellcheck-hyphen-multiple-invalid.html spellcheck-hyphen-m == caret_on_presshell_reinit.html caret_on_presshell_reinit-ref.html == caret_on_presshell_reinit-2.html caret_on_presshell_reinit-ref.html == 642800.html 642800-ref.html +== selection_visibility_after_reframe.html selection_visibility_after_reframe-ref.html +!= selection_visibility_after_reframe-2.html selection_visibility_after_reframe-ref.html diff --git a/layout/reftests/editor/selection_visibility_after_reframe-2.html b/layout/reftests/editor/selection_visibility_after_reframe-2.html new file mode 100644 index 00000000000..fb705cc3692 --- /dev/null +++ b/layout/reftests/editor/selection_visibility_after_reframe-2.html @@ -0,0 +1,11 @@ + + + + + + + diff --git a/layout/reftests/editor/selection_visibility_after_reframe-ref.html b/layout/reftests/editor/selection_visibility_after_reframe-ref.html new file mode 100644 index 00000000000..c227b39c8f7 --- /dev/null +++ b/layout/reftests/editor/selection_visibility_after_reframe-ref.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/layout/reftests/editor/selection_visibility_after_reframe.html b/layout/reftests/editor/selection_visibility_after_reframe.html new file mode 100644 index 00000000000..b05f130a137 --- /dev/null +++ b/layout/reftests/editor/selection_visibility_after_reframe.html @@ -0,0 +1,14 @@ + + + + + + +