From 0e562f96b975bb11356dd1964ae01a1162e7cfe2 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Wed, 10 Sep 2014 12:21:58 -0400 Subject: [PATCH] Backed out 3 changesets (bug 739396) for Mulet perma-fail on a CLOSED TREE. Backed out changeset 299911e6983b (bug 739396) Backed out changeset de11af3e0964 (bug 739396) Backed out changeset e274cb276cc5 (bug 739396) --- content/base/src/nsRange.cpp | 92 --------- content/base/src/nsRange.h | 13 -- content/base/test/mochitest.ini | 2 - content/base/test/test_user_select.html | 259 ------------------------ layout/base/nsDocumentViewer.cpp | 61 +++--- layout/generic/Selection.h | 36 +--- layout/generic/nsFrameSelection.h | 12 +- layout/generic/nsSelection.cpp | 87 +------- 8 files changed, 43 insertions(+), 519 deletions(-) delete mode 100644 content/base/test/test_user_select.html diff --git a/content/base/src/nsRange.cpp b/content/base/src/nsRange.cpp index 2c94d44b7c4b..2fc2ca4db8d9 100644 --- a/content/base/src/nsRange.cpp +++ b/content/base/src/nsRange.cpp @@ -3039,95 +3039,3 @@ nsRange::Constructor(const GlobalObject& aGlobal, return window->GetDoc()->CreateRange(aRv); } - -void -nsRange::ExcludeNonSelectableNodes(nsTArray>* aOutRanges) -{ - MOZ_ASSERT(mIsPositioned); - MOZ_ASSERT(mEndParent); - MOZ_ASSERT(mStartParent); - - nsRange* range = this; - nsRefPtr newRange; - while (range) { - nsCOMPtr iter = NS_NewPreContentIterator(); - nsresult rv = iter->Init(range); - if (NS_FAILED(rv)) { - return; - } - - bool added = false; - bool seenSelectable = false; - nsIContent* firstNonSelectableContent = nullptr; - while (true) { - ErrorResult err; - nsINode* node = iter->GetCurrentNode(); - iter->Next(); - bool selectable = true; - nsIContent* content = - node && node->IsContent() ? node->AsContent() : nullptr; - if (content) { - nsIFrame* frame = content->GetPrimaryFrame(); - for (nsIContent* p = content; !frame && (p = p->GetParent()); ) { - frame = p->GetPrimaryFrame(); - } - if (frame) { - frame->IsSelectable(&selectable, nullptr); - } - } - - if (!selectable) { - if (!firstNonSelectableContent) { - firstNonSelectableContent = content; - } - if (iter->IsDone() && seenSelectable) { - // The tail end of the initial range is non-selectable - truncate the - // current range before the first non-selectable node. - range->SetEndBefore(*firstNonSelectableContent, err); - } - } else if (firstNonSelectableContent) { - if (range == this && !seenSelectable) { - // This is the initial range and all its nodes until now are - // non-selectable so just trim them from the start. - range->SetStartBefore(*node, err); - if (err.Failed()) { - return; - } - break; // restart the same range with a new iterator - } else { - // Save the end point before truncating the range. - nsINode* endParent = range->mEndParent; - int32_t endOffset = range->mEndOffset; - - // Truncate the current range before the first non-selectable node. - range->SetEndBefore(*firstNonSelectableContent, err); - - // Store it in the result (strong ref) - do this before creating - // a new range in |newRange| below so we don't drop the last ref - // to the range created in the previous iteration. - if (!added && !err.Failed()) { - aOutRanges->AppendElement(range); - } - - // Create a new range for the remainder. - rv = CreateRange(node, 0, endParent, endOffset, - getter_AddRefs(newRange)); - if (NS_FAILED(rv) || newRange->Collapsed()) { - newRange = nullptr; - } - range = newRange; - break; // create a new iterator for the new range, if any - } - } else { - seenSelectable = true; - if (!added) { - added = true; - aOutRanges->AppendElement(range); - } - } - if (iter->IsDone()) { - return; - } - } - } -} diff --git a/content/base/src/nsRange.h b/content/base/src/nsRange.h index c93a9217bd6b..5e4c9f92f1e4 100644 --- a/content/base/src/nsRange.h +++ b/content/base/src/nsRange.h @@ -264,19 +264,6 @@ public: nsINode* aEndParent, int32_t aEndOffset, bool aClampToEdge, bool aFlushLayout); - /** - * Scan this range for -moz-user-select:none nodes and split it up into - * multiple ranges to exclude those nodes. The resulting ranges are put - * in aOutRanges. If no -moz-user-select:none node is found in the range - * then |this| is unmodified and is the only range in aOutRanges. - * Otherwise, |this| will be modified so that it ends before the first - * -moz-user-select:none node and additional ranges may also be created. - * If all nodes in the range are -moz-user-select:none then aOutRanges - * will be empty. - * @param aOutRanges the resulting set of ranges - */ - void ExcludeNonSelectableNodes(nsTArray>* aOutRanges); - typedef nsTHashtable > RangeHashTable; protected: void RegisterCommonAncestor(nsINode* aNode); diff --git a/content/base/test/mochitest.ini b/content/base/test/mochitest.ini index ed49cf27aa49..1c5ecbda74a8 100644 --- a/content/base/test/mochitest.ini +++ b/content/base/test/mochitest.ini @@ -656,5 +656,3 @@ skip-if = buildapp == 'b2g' || e10s support-files = file_bug1011748_redirect.sjs file_bug1011748_OK.sjs [test_bug1025933.html] [test_element.matches.html] -[test_user_select.html] -skip-if = buildapp == 'b2g' diff --git a/content/base/test/test_user_select.html b/content/base/test/test_user_select.html deleted file mode 100644 index e31526418695..000000000000 --- a/content/base/test/test_user_select.html +++ /dev/null @@ -1,259 +0,0 @@ - - - --moz-user-select selection tests - - - - - - - - - -
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
-
aaaaaaabbbbbbbbccccccc
- - - -
-
-
- - diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 1047d3a3efa0..6c5e595d4a47 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -28,7 +28,7 @@ #include "nsILinkHandler.h" #include "nsIDOMDocument.h" #include "nsISelectionListener.h" -#include "mozilla/dom/Selection.h" +#include "nsISelectionPrivate.h" #include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLElement.h" #include "nsContentUtils.h" @@ -316,7 +316,7 @@ private: nsresult SyncParentSubDocMap(); - mozilla::dom::Selection* GetDocumentSelection(); + nsresult GetDocumentSelection(nsISelection **aSelection); void DestroyPresShell(); void DestroyPresContext(); @@ -704,12 +704,12 @@ nsDocumentViewer::InitPresentationStuff(bool aDoInitialReflow) mSelectionListener = selectionListener; } - nsRefPtr selection = GetDocumentSelection(); - if (!selection) { - return NS_ERROR_FAILURE; - } + nsCOMPtr selection; + rv = GetDocumentSelection(getter_AddRefs(selection)); + NS_ENSURE_SUCCESS(rv, rv); - rv = selection->AddSelectionListener(mSelectionListener); + nsCOMPtr selPrivate(do_QueryInterface(selection)); + rv = selPrivate->AddSelectionListener(mSelectionListener); if (NS_FAILED(rv)) return rv; @@ -2562,14 +2562,19 @@ nsDocumentViewer::CreateDeviceContext(nsView* aContainerView) // Return the selection for the document. Note that text fields have their // own selection, which cannot be accessed with this method. -mozilla::dom::Selection* -nsDocumentViewer::GetDocumentSelection() +nsresult nsDocumentViewer::GetDocumentSelection(nsISelection **aSelection) { + NS_ENSURE_ARG_POINTER(aSelection); if (!mPresShell) { - return nullptr; + return NS_ERROR_NOT_INITIALIZED; } - return mPresShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL); + nsCOMPtr selcon; + selcon = do_QueryInterface(mPresShell); + if (selcon) + return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, + aSelection); + return NS_ERROR_FAILURE; } /* ======================================================================================== @@ -2578,11 +2583,12 @@ nsDocumentViewer::GetDocumentSelection() NS_IMETHODIMP nsDocumentViewer::ClearSelection() { + nsresult rv; + nsCOMPtr selection; + // use nsCopySupport::GetSelectionForCopy() ? - nsRefPtr selection = GetDocumentSelection(); - if (!selection) { - return NS_ERROR_FAILURE; - } + rv = GetDocumentSelection(getter_AddRefs(selection)); + if (NS_FAILED(rv)) return rv; return selection->CollapseToStart(); } @@ -2592,17 +2598,16 @@ NS_IMETHODIMP nsDocumentViewer::SelectAll() // XXX this is a temporary implementation copied from nsWebShell // for now. I think nsDocument and friends should have some helper // functions to make this easier. + nsCOMPtr selection; + nsresult rv; // use nsCopySupport::GetSelectionForCopy() ? - nsRefPtr selection = GetDocumentSelection(); - if (!selection) { - return NS_ERROR_FAILURE; - } + rv = GetDocumentSelection(getter_AddRefs(selection)); + if (NS_FAILED(rv)) return rv; nsCOMPtr htmldoc = do_QueryInterface(mDocument); nsCOMPtr bodyNode; - nsresult rv; if (htmldoc) { nsCOMPtrbodyElement; @@ -2620,7 +2625,6 @@ NS_IMETHODIMP nsDocumentViewer::SelectAll() rv = selection->RemoveAllRanges(); if (NS_FAILED(rv)) return rv; - mozilla::dom::Selection::AutoApplyUserSelectStyle userSelection(selection); rv = selection->SelectAllChildren(bodyNode); return rv; } @@ -3544,10 +3548,9 @@ NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocumen NS_ASSERTION(mDocViewer, "Should have doc viewer!"); // get the selection state - nsRefPtr selection = mDocViewer->GetDocumentSelection(); - if (!selection) { - return NS_ERROR_FAILURE; - } + nsCOMPtr selection; + nsresult rv = mDocViewer->GetDocumentSelection(getter_AddRefs(selection)); + if (NS_FAILED(rv)) return rv; nsIDocument* theDoc = mDocViewer->GetDocument(); if (!theDoc) return NS_ERROR_FAILURE; @@ -4429,9 +4432,11 @@ nsDocumentViewer::DestroyPresShell() // Break circular reference (or something) mPresShell->EndObservingDocument(); - nsRefPtr selection = GetDocumentSelection(); - if (selection && mSelectionListener) - selection->RemoveSelectionListener(mSelectionListener); + nsCOMPtr selection; + GetDocumentSelection(getter_AddRefs(selection)); + nsCOMPtr selPrivate = do_QueryInterface(selection); + if (selPrivate && mSelectionListener) + selPrivate->RemoveSelectionListener(mSelectionListener); nsRefPtr selectionCaret = mPresShell->GetSelectionCarets(); if (selectionCaret) { diff --git a/layout/generic/Selection.h b/layout/generic/Selection.h index 1ac35bd55039..12d63624a90d 100644 --- a/layout/generic/Selection.h +++ b/layout/generic/Selection.h @@ -9,13 +9,12 @@ #include "nsIWeakReference.h" -#include "mozilla/AutoRestore.h" -#include "mozilla/TextRange.h" #include "nsISelection.h" #include "nsISelectionController.h" #include "nsISelectionPrivate.h" #include "nsRange.h" #include "nsThreadUtils.h" +#include "mozilla/TextRange.h" #include "nsWrapperCache.h" struct CachedOffsetForFrame; @@ -101,14 +100,8 @@ public: int32_t aFlags = 0); nsresult SubtractRange(RangeData* aRange, nsRange* aSubtract, nsTArray* aOutput); - /** - * AddItem adds aRange to this Selection. If mApplyUserSelectStyle is true, - * then aRange is first scanned for -moz-user-select:none nodes and split up - * into multiple ranges to exclude those before adding the resulting ranges - * to this Selection. - */ - nsresult AddItem(nsRange* aRange, int32_t* aOutIndex); - nsresult RemoveItem(nsRange* aRange); + nsresult AddItem(nsRange *aRange, int32_t* aOutIndex); + nsresult RemoveItem(nsRange *aRange); nsresult RemoveCollapsedRanges(); nsresult Clear(nsPresContext* aPresContext); nsresult Collapse(nsINode* aParentNode, int32_t aOffset); @@ -212,19 +205,6 @@ public: nsresult NotifySelectionListeners(); - friend struct AutoApplyUserSelectStyle; - struct MOZ_STACK_CLASS AutoApplyUserSelectStyle - { - AutoApplyUserSelectStyle(Selection* aSelection - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : mSavedValue(aSelection->mApplyUserSelectStyle) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - aSelection->mApplyUserSelectStyle = true; - } - AutoRestore mSavedValue; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER - }; private: class ScrollSelectionIntoViewEvent; @@ -278,11 +258,6 @@ private: int32_t* aStartIndex, int32_t* aEndIndex); RangeData* FindRangeData(nsIDOMRange* aRange); - /** - * Helper method for AddItem. - */ - nsresult AddItemInternal(nsRange* aRange, int32_t* aOutIndex); - // These are the ranges inside this selection. They are kept sorted in order // of DOM start position. // @@ -306,11 +281,6 @@ private: CachedOffsetForFrame *mCachedOffsetForFrame; nsDirection mDirection; SelectionType mType; - /** - * True if the current selection operation was initiated by user action. - * It determines whether we exclude -moz-user-select:none nodes or not. - */ - bool mApplyUserSelectStyle; }; } // namespace dom diff --git a/layout/generic/nsFrameSelection.h b/layout/generic/nsFrameSelection.h index a7e823de6c96..1822dc7dd8f4 100644 --- a/layout/generic/nsFrameSelection.h +++ b/layout/generic/nsFrameSelection.h @@ -12,7 +12,6 @@ #include "nsIFrame.h" #include "nsIContent.h" #include "nsISelectionController.h" -#include "nsISelectionListener.h" #include "nsITableCellLayout.h" #include "nsIDOMElement.h" #include "WordMovementType.h" @@ -614,18 +613,9 @@ private: int16_t PopReason() { int16_t retval = mSelectionChangeReason; - mSelectionChangeReason = nsISelectionListener::NO_REASON; + mSelectionChangeReason = 0; return retval; } - bool IsUserSelectionReason() const - { - return (mSelectionChangeReason & - (nsISelectionListener::DRAG_REASON | - nsISelectionListener::MOUSEDOWN_REASON | - nsISelectionListener::MOUSEUP_REASON | - nsISelectionListener::KEYPRESS_REASON)) != - nsISelectionListener::NO_REASON; - } friend class mozilla::dom::Selection; #ifdef DEBUG diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index 251a9ea6b63a..bfe39dcc77d7 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -1548,11 +1548,6 @@ nsFrameSelection::TakeFocus(nsIContent* aNewFocus, if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER; - Maybe userSelect; - if (IsUserSelectionReason()) { - userSelect.emplace(mDomSelections[index]); - } - //traverse through document and unselect crap here if (!aContinueSelection) {//single click? setting cursor down uint32_t batching = mBatching;//hack to use the collapse code. @@ -3108,7 +3103,6 @@ Selection::Selection() : mCachedOffsetForFrame(nullptr) , mDirection(eDirNext) , mType(nsISelectionController::SELECTION_NORMAL) - , mApplyUserSelectStyle(false) { SetIsDOMBinding(); } @@ -3118,7 +3112,6 @@ Selection::Selection(nsFrameSelection* aList) , mCachedOffsetForFrame(nullptr) , mDirection(eDirNext) , mType(nsISelectionController::SELECTION_NORMAL) - , mApplyUserSelectStyle(false) { SetIsDOMBinding(); } @@ -3461,25 +3454,6 @@ Selection::AddItem(nsRange* aItem, int32_t* aOutIndex) NS_ASSERTION(aOutIndex, "aOutIndex can't be null"); - if (mApplyUserSelectStyle) { - nsAutoTArray, 4> rangesToAdd; - aItem->ExcludeNonSelectableNodes(&rangesToAdd); - for (size_t i = 0; i < rangesToAdd.Length(); ++i) { - nsresult rv = AddItemInternal(rangesToAdd[i], aOutIndex); - NS_ENSURE_SUCCESS(rv, rv); - } - return NS_OK; - } - return AddItemInternal(aItem, aOutIndex); -} - -nsresult -Selection::AddItemInternal(nsRange* aItem, int32_t* aOutIndex) -{ - MOZ_ASSERT(aItem); - MOZ_ASSERT(aItem->IsPositioned()); - MOZ_ASSERT(aOutIndex); - *aOutIndex = -1; // a common case is that we have no ranges yet @@ -4469,7 +4443,8 @@ Selection::AddRange(nsRange& aRange, ErrorResult& aRv) return; } - if (!didAddRange) { + if (!didAddRange) + { result = AddItem(&aRange, &rangeIndex); if (NS_FAILED(result)) { aRv.Throw(result); @@ -4477,10 +4452,7 @@ Selection::AddRange(nsRange& aRange, ErrorResult& aRv) } } - if (rangeIndex < 0) { - return; - } - + NS_ASSERTION(rangeIndex >= 0, "Range index not returned"); setAnchorFocusRange(rangeIndex); // Make sure the caret appears on the next line, if at a newline @@ -4949,48 +4921,7 @@ Selection::Extend(nsINode& aParentNode, uint32_t aOffset, ErrorResult& aRv) return; } - nsDirection dir = GetDirection(); - - // If aParentNode is inside a range in a multi-range selection we need - // to remove the ranges that follows in the selection direction and - // make that range the mAnchorFocusRange. - if (mRanges.Length() > 1) { - for (size_t i = 0; i < mRanges.Length(); ++i) { - nsRange* range = mRanges[i].mRange; - bool disconnected1 = false; - bool disconnected2 = false; - const bool isBeforeStart = - nsContentUtils::ComparePoints(range->GetStartParent(), - range->StartOffset(), - &aParentNode, aOffset, - &disconnected1) > 0; - const bool isAfterEnd = - nsContentUtils::ComparePoints(range->GetEndParent(), - range->EndOffset(), - &aParentNode, aOffset, - &disconnected2) < 0; - if (!isBeforeStart && !isAfterEnd && !disconnected1 && !disconnected2) { - // aParentNode/aOffset is inside 'range'. - mAnchorFocusRange = range; - if (dir == eDirNext) { - for (size_t j = i + 1; j < mRanges.Length(); ++j) { - nsRange* r = mRanges[j].mRange; - r->SetInSelection(false); - selectFrames(presContext, r, false); - } - mRanges.TruncateLength(i + 1); - } else { - for (size_t j = 0; j < i; ++j) { - nsRange* r = mRanges[j].mRange; - r->SetInSelection(false); - selectFrames(presContext, r, false); - } - mRanges.RemoveElementsAt(0, i); - } - break; - } - } - } + //mFrameSelection->InvalidateDesiredX(); nsINode* anchorNode = GetAnchorNode(); nsINode* focusNode = GetFocusNode(); @@ -5004,6 +4935,8 @@ Selection::Extend(nsINode& aParentNode, uint32_t aOffset, ErrorResult& aRv) int32_t startOffset = range->StartOffset(); int32_t endOffset = range->EndOffset(); + nsDirection dir = GetDirection(); + //compare anchor to old cursor. // We pass |disconnected| to the following ComparePoints calls in order @@ -5229,14 +5162,6 @@ Selection::Extend(nsINode& aParentNode, uint32_t aOffset, ErrorResult& aRv) } } - if (mRanges.Length() > 1) { - for (size_t i = 0; i < mRanges.Length(); ++i) { - nsRange* range = mRanges[i].mRange; - MOZ_ASSERT(range->IsInSelection()); - selectFrames(presContext, range, range->IsInSelection()); - } - } - DEBUG_OUT_RANGE(range); #ifdef DEBUG_SELECTION if (eDirNext == mDirection)