diff --git a/accessible/src/generic/HyperTextAccessible.cpp b/accessible/src/generic/HyperTextAccessible.cpp index f651f254684c..5382a6b44c86 100644 --- a/accessible/src/generic/HyperTextAccessible.cpp +++ b/accessible/src/generic/HyperTextAccessible.cpp @@ -1824,7 +1824,7 @@ HyperTextAccessible::SetSelectionBounds(int32_t aSelectionNum, nsRefPtr range; if (aSelectionNum == rangeCount) - range = new nsRange(mContent); + range = new nsRange(); else range = domSel->GetRangeAt(aSelectionNum); @@ -1886,7 +1886,7 @@ HyperTextAccessible::ScrollSubstringTo(int32_t aStartIndex, int32_t aEndIndex, if (IsDefunct()) return NS_ERROR_FAILURE; - nsRefPtr range = new nsRange(mContent); + nsRefPtr range = new nsRange(); nsresult rv = HypertextOffsetsToDOMRange(aStartIndex, aEndIndex, range); NS_ENSURE_SUCCESS(rv, rv); @@ -1910,7 +1910,7 @@ HyperTextAccessible::ScrollSubstringToPoint(int32_t aStartIndex, nsIntPoint coords = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordinateType, this); - nsRefPtr range = new nsRange(mContent); + nsRefPtr range = new nsRange(); nsresult rv = HypertextOffsetsToDOMRange(aStartIndex, aEndIndex, range); NS_ENSURE_SUCCESS(rv, rv); diff --git a/accessible/src/msaa/TextLeafAccessibleWrap.cpp b/accessible/src/msaa/TextLeafAccessibleWrap.cpp index 8c0786a27897..eac78d1b3cd6 100644 --- a/accessible/src/msaa/TextLeafAccessibleWrap.cpp +++ b/accessible/src/msaa/TextLeafAccessibleWrap.cpp @@ -158,7 +158,7 @@ TextLeafAccessibleWrap::scrollToSubstring( if (IsDefunct()) return E_FAIL; - nsRefPtr range = new nsRange(mContent); + nsRefPtr range = new nsRange(); if (NS_FAILED(range->SetStart(mContent, aStartIndex))) return E_FAIL; diff --git a/browser/devtools/framework/Toolbox.jsm b/browser/devtools/framework/Toolbox.jsm index bcf51c8c24e6..13951cc9c727 100644 --- a/browser/devtools/framework/Toolbox.jsm +++ b/browser/devtools/framework/Toolbox.jsm @@ -465,7 +465,6 @@ Toolbox.prototype = { iframe.className = "toolbox-panel-iframe"; iframe.id = "toolbox-panel-iframe-" + id; iframe.setAttribute("flex", 1); - iframe.setAttribute("forceOwnRefreshDriver", ""); let vbox = this.doc.getElementById("toolbox-panel-" + id); vbox.appendChild(iframe); diff --git a/browser/devtools/framework/toolbox-window.xul b/browser/devtools/framework/toolbox-window.xul index 881d1f1ce733..d0eb1acc522a 100644 --- a/browser/devtools/framework/toolbox-window.xul +++ b/browser/devtools/framework/toolbox-window.xul @@ -29,5 +29,5 @@ modifiers="accel"/> - + diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 3264c176efbd..db1a4518c69d 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -112,7 +112,6 @@ namespace layers { } // namespace layers namespace dom { -class DocumentFragment; class Element; } // namespace dom @@ -367,7 +366,6 @@ public: // Check if the (JS) caller can access aNode. static bool CanCallerAccess(nsIDOMNode *aNode); - static bool CanCallerAccess(nsINode* aNode); // Check if the (JS) caller can access aWindow. // aWindow can be either outer or inner window. @@ -1086,10 +1084,6 @@ public: const nsAString& aFragment, bool aPreventScriptExecution, nsIDOMDocumentFragment** aReturn); - static already_AddRefed - CreateContextualFragment(nsINode* aContextNode, const nsAString& aFragment, - bool aPreventScriptExecution, - mozilla::ErrorResult& aRv); /** * Invoke the fragment parsing algorithm (innerHTML) using the HTML parser. diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 7a0d95490a83..91141453e029 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -1939,10 +1939,6 @@ public: void ReleaseCapture() const; virtual void MozSetImageElement(const nsAString& aImageElementId, Element* aElement) = 0; - nsIURI* GetDocumentURIObject() - { - return GetDocumentURI(); - } // Not const because all the full-screen goop is not const virtual bool MozFullScreenEnabled() = 0; virtual Element* GetMozFullScreenElement(mozilla::ErrorResult& rv) = 0; @@ -2412,10 +2408,6 @@ nsresult NS_NewVideoDocument(nsIDocument** aInstancePtrResult); #endif -already_AddRefed -NS_NewDocumentFragment(nsNodeInfoManager* aNodeInfoManager, - mozilla::ErrorResult& aRv); - nsresult NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult, nsNodeInfoManager *aNodeInfoManager); diff --git a/content/base/src/DocumentFragment.cpp b/content/base/src/DocumentFragment.cpp index 360fe25e7c7e..01bca88a6564 100644 --- a/content/base/src/DocumentFragment.cpp +++ b/content/base/src/DocumentFragment.cpp @@ -21,34 +21,21 @@ nsresult NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult, nsNodeInfoManager *aNodeInfoManager) -{ - mozilla::ErrorResult rv; - *aInstancePtrResult = NS_NewDocumentFragment(aNodeInfoManager, rv).get(); - return rv.ErrorCode(); -} - -already_AddRefed -NS_NewDocumentFragment(nsNodeInfoManager* aNodeInfoManager, - mozilla::ErrorResult& aRv) { using namespace mozilla::dom; - if (!aNodeInfoManager) { - aRv.Throw(NS_ERROR_INVALID_ARG); - return nullptr; - } + NS_ENSURE_ARG(aNodeInfoManager); - nsCOMPtr nodeInfo = - aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentFragmentNodeName, - nullptr, kNameSpaceID_None, - nsIDOMNode::DOCUMENT_FRAGMENT_NODE); - if (!nodeInfo) { - aRv.Throw(NS_ERROR_OUT_OF_MEMORY); - return nullptr; - } + nsCOMPtr nodeInfo; + nodeInfo = aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentFragmentNodeName, + nullptr, kNameSpaceID_None, + nsIDOMNode::DOCUMENT_FRAGMENT_NODE); + NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); - nsRefPtr it = new DocumentFragment(nodeInfo.forget()); - return it.forget(); + DocumentFragment *it = new DocumentFragment(nodeInfo.forget()); + NS_ADDREF(*aInstancePtrResult = it); + + return NS_OK; } DOMCI_NODE_DATA(DocumentFragment, mozilla::dom::DocumentFragment) diff --git a/content/base/src/Makefile.in b/content/base/src/Makefile.in index 9456cf22fd8e..b13d0d8ecb82 100644 --- a/content/base/src/Makefile.in +++ b/content/base/src/Makefile.in @@ -51,7 +51,6 @@ EXPORTS_mozilla/dom = \ DOMImplementation.h \ EventSource.h \ Link.h \ - Text.h \ $(NULL) CPPSRCS = \ @@ -121,7 +120,6 @@ CPPSRCS = \ nsStyledElement.cpp \ nsStyleLinkElement.cpp \ nsSyncLoadService.cpp \ - Text.cpp \ nsTextFragment.cpp \ nsTextNode.cpp \ nsTraversal.cpp \ diff --git a/content/base/src/Text.cpp b/content/base/src/Text.cpp deleted file mode 100644 index 783c29fa34c1..000000000000 --- a/content/base/src/Text.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "mozilla/dom/Text.h" - -namespace mozilla { -namespace dom { - -already_AddRefed -Text::SplitText(uint32_t aOffset, ErrorResult& rv) -{ - nsCOMPtr newChild; - rv = SplitData(aOffset, getter_AddRefs(newChild)); - if (rv.Failed()) { - return nullptr; - } - return static_cast(newChild.forget().get()); -} - -} // namespace dom -} // namespace mozilla diff --git a/content/base/src/Text.h b/content/base/src/Text.h deleted file mode 100644 index ee2c5aba5921..000000000000 --- a/content/base/src/Text.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_dom_Text_h -#define mozilla_dom_Text_h - -#include "nsGenericDOMDataNode.h" -#include "mozilla/ErrorResult.h" - -namespace mozilla { -namespace dom { - -class Text : public nsGenericDOMDataNode -{ -public: - Text(already_AddRefed aNodeInfo) - : nsGenericDOMDataNode(aNodeInfo) - {} - - using nsGenericDOMDataNode::GetWholeText; - - // WebIDL API - already_AddRefed SplitText(uint32_t aOffset, ErrorResult& rv); - void GetWholeText(nsAString& aWholeText, ErrorResult& rv) - { - rv = GetWholeText(aWholeText); - } -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_Text_h diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 8b2c94bc04f6..36bd3c5ade10 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -168,7 +168,6 @@ #include "nsSVGFeatures.h" #include "MediaDecoder.h" #include "DecoderTraits.h" -#include "mozilla/dom/DocumentFragment.h" #include "nsWrapperCacheInlines.h" #include "nsViewportInfo.h" @@ -1582,15 +1581,6 @@ nsContentUtils::CanCallerAccess(nsIPrincipal* aSubjectPrincipal, // static bool nsContentUtils::CanCallerAccess(nsIDOMNode *aNode) -{ - nsCOMPtr node = do_QueryInterface(aNode); - NS_ENSURE_TRUE(node, false); - return CanCallerAccess(node); -} - -// static -bool -nsContentUtils::CanCallerAccess(nsINode* aNode) { // XXXbz why not check the IsCapabilityEnabled thing up front, and not bother // with the system principal games? But really, there should be a simpler @@ -1605,7 +1595,10 @@ nsContentUtils::CanCallerAccess(nsINode* aNode) return true; } - return CanCallerAccess(subjectPrincipal, aNode->NodePrincipal()); + nsCOMPtr node = do_QueryInterface(aNode); + NS_ENSURE_TRUE(node, false); + + return CanCallerAccess(subjectPrincipal, node->NodePrincipal()); } // static @@ -4062,22 +4055,8 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode, bool aPreventScriptExecution, nsIDOMDocumentFragment** aReturn) { - ErrorResult rv; - *aReturn = CreateContextualFragment(aContextNode, aFragment, - aPreventScriptExecution, rv).get(); - return rv.ErrorCode(); -} - -already_AddRefed -nsContentUtils::CreateContextualFragment(nsINode* aContextNode, - const nsAString& aFragment, - bool aPreventScriptExecution, - ErrorResult& aRv) -{ - if (!aContextNode) { - aRv.Throw(NS_ERROR_INVALID_ARG); - return nullptr; - } + *aReturn = nullptr; + NS_ENSURE_ARG(aContextNode); // If we don't have a document here, we can't get the right security context // for compiling event handlers... so just bail out. @@ -4089,8 +4068,8 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode, #endif if (isHTML) { - nsRefPtr frag = - NS_NewDocumentFragment(document->NodeInfoManager(), aRv); + nsCOMPtr frag; + NS_NewDocumentFragment(getter_AddRefs(frag), document->NodeInfoManager()); nsCOMPtr contextAsContent = do_QueryInterface(aContextNode); if (contextAsContent && !contextAsContent->IsElement()) { @@ -4101,23 +4080,28 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode, } } + nsresult rv; + nsCOMPtr fragment = do_QueryInterface(frag); if (contextAsContent && !contextAsContent->IsHTML(nsGkAtoms::html)) { - aRv = ParseFragmentHTML(aFragment, frag, - contextAsContent->Tag(), - contextAsContent->GetNameSpaceID(), - (document->GetCompatibilityMode() == + rv = ParseFragmentHTML(aFragment, + fragment, + contextAsContent->Tag(), + contextAsContent->GetNameSpaceID(), + (document->GetCompatibilityMode() == eCompatibility_NavQuirks), - aPreventScriptExecution); + aPreventScriptExecution); } else { - aRv = ParseFragmentHTML(aFragment, frag, - nsGkAtoms::body, - kNameSpaceID_XHTML, - (document->GetCompatibilityMode() == + rv = ParseFragmentHTML(aFragment, + fragment, + nsGkAtoms::body, + kNameSpaceID_XHTML, + (document->GetCompatibilityMode() == eCompatibility_NavQuirks), - aPreventScriptExecution); + aPreventScriptExecution); } - return frag.forget(); + frag.forget(aReturn); + return rv; } nsAutoTArray tagStack; @@ -4129,10 +4113,7 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode, while (content && content->IsElement()) { nsString& tagName = *tagStack.AppendElement(); - if (!&tagName) { - aRv.Throw(NS_ERROR_OUT_OF_MEMORY); - return nullptr; - } + NS_ENSURE_TRUE(&tagName, NS_ERROR_OUT_OF_MEMORY); tagName = content->NodeInfo()->QualifiedName(); @@ -4178,10 +4159,11 @@ nsContentUtils::CreateContextualFragment(nsINode* aContextNode, content = content->GetParent(); } - nsCOMPtr frag; - aRv = ParseFragmentXML(aFragment, document, tagStack, - aPreventScriptExecution, getter_AddRefs(frag)); - return static_cast(frag.forget().get()); + return ParseFragmentXML(aFragment, + document, + tagStack, + aPreventScriptExecution, + aReturn); } /* static */ diff --git a/content/base/src/nsCopySupport.cpp b/content/base/src/nsCopySupport.cpp index 36d8a315bc8a..6073f90ca478 100644 --- a/content/base/src/nsCopySupport.cpp +++ b/content/base/src/nsCopySupport.cpp @@ -293,7 +293,7 @@ nsCopySupport::GetTransferableForNode(nsINode* aNode, NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr node = do_QueryInterface(aNode); NS_ENSURE_TRUE(node, NS_ERROR_FAILURE); - nsRefPtr range = new nsRange(aNode); + nsRefPtr range = new nsRange(); rv = range->SelectNode(node); NS_ENSURE_SUCCESS(rv, rv); rv = selection->AddRange(range); diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 7057681c8c2e..70ad5912c542 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -5341,7 +5341,7 @@ nsDocument::CreateRange(nsIDOMRange** aReturn) already_AddRefed nsIDocument::CreateRange(ErrorResult& rv) { - nsRefPtr range = new nsRange(this); + nsRefPtr range = new nsRange(); nsresult res = range->Set(this, 0, this, 0); if (NS_FAILED(res)) { rv.Throw(res); diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index 4b0e389b9429..512be5123a50 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -372,7 +372,6 @@ GK_ATOM(fontpicker, "fontpicker") GK_ATOM(footer, "footer") GK_ATOM(_for, "for") GK_ATOM(forEach, "for-each") -GK_ATOM(forceOwnRefreshDriver, "forceOwnRefreshDriver") GK_ATOM(form, "form") GK_ATOM(formaction, "formaction") GK_ATOM(format, "format") diff --git a/content/base/src/nsRange.cpp b/content/base/src/nsRange.cpp index cf0690da49c0..99c7a7e1b668 100644 --- a/content/base/src/nsRange.cpp +++ b/content/base/src/nsRange.cpp @@ -29,23 +29,27 @@ #include "nsLayoutUtils.h" #include "nsTextFrame.h" #include "nsFontFaceList.h" -#include "mozilla/dom/DocumentFragment.h" -#include "mozilla/dom/RangeBinding.h" #include "mozilla/Telemetry.h" #include "mozilla/Likely.h" using namespace mozilla; -JSObject* -nsRange::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap) -{ - return dom::RangeBinding::Wrap(aCx, aScope, this, aTriedToWrap); -} - /****************************************************** * stack based utilty class for managing monitor ******************************************************/ +// NS_ERROR_DOM_NOT_OBJECT_ERR is not the correct one to throw, but spec doesn't say +// what is +#define VALIDATE_ACCESS(node_) \ + PR_BEGIN_MACRO \ + if (!node_) { \ + return NS_ERROR_DOM_NOT_OBJECT_ERR; \ + } \ + if (!nsContentUtils::CanCallerAccess(node_)) { \ + return NS_ERROR_DOM_SECURITY_ERR; \ + } \ + PR_END_MACRO + static void InvalidateAllFrames(nsINode* aNode) { NS_PRECONDITION(aNode, "bad arg"); @@ -220,12 +224,9 @@ nsRange::CreateRange(nsIDOMNode* aStartParent, int32_t aStartOffset, MOZ_ASSERT(aRange); *aRange = NULL; - nsCOMPtr startParent = do_QueryInterface(aStartParent); - NS_ENSURE_ARG_POINTER(startParent); + nsRefPtr range = new nsRange(); - nsRefPtr range = new nsRange(startParent); - - nsresult rv = range->SetStart(startParent, aStartOffset); + nsresult rv = range->SetStart(aStartParent, aStartOffset); NS_ENSURE_SUCCESS(rv, rv); rv = range->SetEnd(aEndParent, aEndOffset); @@ -259,7 +260,6 @@ DOMCI_DATA(Range, nsRange) // QueryInterface implementation for nsRange NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsRange) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsIDOMRange) NS_INTERFACE_MAP_ENTRY(nsIMutationObserver) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMRange) @@ -267,24 +267,15 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsRange) NS_INTERFACE_MAP_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsRange) - NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER - NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner); tmp->Reset(); NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsRange) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStartParent) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEndParent) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsRange) - NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER -NS_IMPL_CYCLE_COLLECTION_TRACE_END - - static void RangeHashTableDtor(void* aObject, nsIAtom* aPropertyName, void* aPropertyValue, void* aData) @@ -685,78 +676,58 @@ nsRange::ParentChainChanged(nsIContent *aContent) NS_IMETHODIMP nsRange::IsPointInRange(nsIDOMNode* aParent, int32_t aOffset, bool* aResult) { - nsCOMPtr parent = do_QueryInterface(aParent); - if (!parent) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; - } - - ErrorResult rv; - *aResult = IsPointInRange(*parent, aOffset, rv); - return rv.ErrorCode(); -} - -bool -nsRange::IsPointInRange(nsINode& aParent, uint32_t aOffset, ErrorResult& aRv) -{ - uint16_t compareResult = ComparePoint(aParent, aOffset, aRv); + int16_t compareResult = 0; + nsresult rv = ComparePoint(aParent, aOffset, &compareResult); // If the node isn't in the range's document, it clearly isn't in the range. - if (aRv.ErrorCode() == NS_ERROR_DOM_WRONG_DOCUMENT_ERR) { - aRv = NS_OK; - return false; + if (rv == NS_ERROR_DOM_WRONG_DOCUMENT_ERR) { + *aResult = false; + return NS_OK; } - return compareResult == 0; -} + *aResult = compareResult == 0; + return rv; +} + // returns -1 if point is before range, 0 if point is in range, // 1 if point is after range. NS_IMETHODIMP nsRange::ComparePoint(nsIDOMNode* aParent, int32_t aOffset, int16_t* aResult) { + // our range is in a good state? + if (!mIsPositioned) + return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr parent = do_QueryInterface(aParent); NS_ENSURE_TRUE(parent, NS_ERROR_DOM_HIERARCHY_REQUEST_ERR); - ErrorResult rv; - *aResult = ComparePoint(*parent, aOffset, rv); - return rv.ErrorCode(); -} - -int16_t -nsRange::ComparePoint(nsINode& aParent, uint32_t aOffset, ErrorResult& aRv) -{ - // our range is in a good state? - if (!mIsPositioned) { - aRv.Throw(NS_ERROR_NOT_INITIALIZED); - return 0; + if (!nsContentUtils::ContentIsDescendantOf(parent, mRoot)) { + return NS_ERROR_DOM_WRONG_DOCUMENT_ERR; + } + + if (parent->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE) { + return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR; } - if (!nsContentUtils::ContentIsDescendantOf(&aParent, mRoot)) { - aRv.Throw(NS_ERROR_DOM_WRONG_DOCUMENT_ERR); - return 0; + if (aOffset < 0 || uint32_t(aOffset) > parent->Length()) { + return NS_ERROR_DOM_INDEX_SIZE_ERR; } - - if (aParent.NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE) { - aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR); - return 0; - } - - if (aOffset > aParent.Length()) { - aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); - return 0; - } - + int32_t cmp; - if ((cmp = nsContentUtils::ComparePoints(&aParent, aOffset, + if ((cmp = nsContentUtils::ComparePoints(parent, aOffset, mStartParent, mStartOffset)) <= 0) { - - return cmp; + + *aResult = cmp; } - if (nsContentUtils::ComparePoints(mEndParent, mEndOffset, - &aParent, aOffset) == -1) { - return 1; + else if (nsContentUtils::ComparePoints(mEndParent, mEndOffset, + parent, aOffset) == -1) { + *aResult = 1; } - - return 0; + else { + *aResult = 0; + } + + return NS_OK; } NS_IMETHODIMP @@ -768,45 +739,35 @@ nsRange::IntersectsNode(nsIDOMNode* aNode, bool* aResult) // TODO: This should throw a TypeError. NS_ENSURE_ARG(node); - ErrorResult rv; - *aResult = IntersectsNode(*node, rv); - return rv.ErrorCode(); -} - -bool -nsRange::IntersectsNode(nsINode& aNode, ErrorResult& aRv) -{ - if (!mIsPositioned) { - aRv.Throw(NS_ERROR_NOT_INITIALIZED); - return false; - } + NS_ENSURE_TRUE(mIsPositioned, NS_ERROR_NOT_INITIALIZED); // Step 3. - nsINode* parent = aNode.GetParentNode(); + nsINode* parent = node->GetParentNode(); if (!parent) { // Steps 2 and 4. // |parent| is null, so |node|'s root is |node| itself. - return GetRoot() == &aNode; + *aResult = (GetRoot() == node); + return NS_OK; } // Step 5. - int32_t nodeIndex = parent->IndexOf(&aNode); + int32_t nodeIndex = parent->IndexOf(node); // Steps 6-7. // Note: if disconnected is true, ComparePoints returns 1. bool disconnected = false; - bool result = nsContentUtils::ComparePoints(mStartParent, mStartOffset, - parent, nodeIndex + 1, - &disconnected) < 0 && - nsContentUtils::ComparePoints(parent, nodeIndex, - mEndParent, mEndOffset, - &disconnected) < 0; + *aResult = nsContentUtils::ComparePoints(mStartParent, mStartOffset, + parent, nodeIndex + 1, + &disconnected) < 0 && + nsContentUtils::ComparePoints(parent, nodeIndex, + mEndParent, mEndOffset, + &disconnected) < 0; // Step 2. if (disconnected) { - result = false; + *aResult = false; } - return result; + return NS_OK; } /****************************************************** @@ -883,14 +844,6 @@ nsRange::DoSetRange(nsINode* aStartN, int32_t aStartOffset, mRoot = aRoot; } -static int32_t -IndexOf(nsINode* aChild) -{ - nsINode* parent = aChild->GetParentNode(); - - return parent ? parent->IndexOf(aChild) : -1; -} - static int32_t IndexOf(nsIDOMNode* aChildNode) { @@ -900,7 +853,11 @@ IndexOf(nsIDOMNode* aChildNode) if (!child) { return -1; } - return IndexOf(child); + + nsINode *parent = child->GetParentNode(); + + // finally we get the index + return parent ? parent->IndexOf(child) : -1; } nsINode* @@ -930,17 +887,6 @@ nsRange::GetStartContainer(nsIDOMNode** aStartParent) return CallQueryInterface(mStartParent, aStartParent); } -nsINode* -nsRange::GetStartContainer(ErrorResult& aRv) const -{ - if (!mIsPositioned) { - aRv.Throw(NS_ERROR_NOT_INITIALIZED); - return nullptr; - } - - return mStartParent; -} - NS_IMETHODIMP nsRange::GetStartOffset(int32_t* aStartOffset) { @@ -952,17 +898,6 @@ nsRange::GetStartOffset(int32_t* aStartOffset) return NS_OK; } -uint32_t -nsRange::GetStartOffset(ErrorResult& aRv) const -{ - if (!mIsPositioned) { - aRv.Throw(NS_ERROR_NOT_INITIALIZED); - return 0; - } - - return mStartOffset; -} - NS_IMETHODIMP nsRange::GetEndContainer(nsIDOMNode** aEndParent) { @@ -972,17 +907,6 @@ nsRange::GetEndContainer(nsIDOMNode** aEndParent) return CallQueryInterface(mEndParent, aEndParent); } -nsINode* -nsRange::GetEndContainer(ErrorResult& aRv) const -{ - if (!mIsPositioned) { - aRv.Throw(NS_ERROR_NOT_INITIALIZED); - return nullptr; - } - - return mEndParent; -} - NS_IMETHODIMP nsRange::GetEndOffset(int32_t* aEndOffset) { @@ -994,17 +918,6 @@ nsRange::GetEndOffset(int32_t* aEndOffset) return NS_OK; } -uint32_t -nsRange::GetEndOffset(ErrorResult& aRv) const -{ - if (!mIsPositioned) { - aRv.Throw(NS_ERROR_NOT_INITIALIZED); - return 0; - } - - return mEndOffset; -} - NS_IMETHODIMP nsRange::GetCollapsed(bool* aIsCollapsed) { @@ -1016,29 +929,19 @@ nsRange::GetCollapsed(bool* aIsCollapsed) return NS_OK; } -nsINode* -nsRange::GetCommonAncestorContainer(ErrorResult& aRv) const -{ - if (!mIsPositioned) { - aRv.Throw(NS_ERROR_NOT_INITIALIZED); - return nullptr; - } - - return nsContentUtils::GetCommonAncestor(mStartParent, mEndParent); -} - NS_IMETHODIMP nsRange::GetCommonAncestorContainer(nsIDOMNode** aCommonParent) { - ErrorResult rv; - nsINode* commonAncestor = GetCommonAncestorContainer(rv); - if (commonAncestor) { - NS_ADDREF(*aCommonParent = commonAncestor->AsDOMNode()); - } else { - *aCommonParent = nullptr; + *aCommonParent = nullptr; + if (!mIsPositioned) + return NS_ERROR_NOT_INITIALIZED; + + nsINode* container = nsContentUtils::GetCommonAncestor(mStartParent, mEndParent); + if (container) { + return CallQueryInterface(container, aCommonParent); } - return rv.ErrorCode(); + return NS_ERROR_NOT_INITIALIZED; } nsINode* @@ -1089,29 +992,14 @@ nsRange::IsValidBoundary(nsINode* aNode) return root; } -void -nsRange::SetStart(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNode)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - AutoInvalidateSelection atEndOfBlock(this); - aRv = SetStart(&aNode, aOffset); -} - NS_IMETHODIMP nsRange::SetStart(nsIDOMNode* aParent, int32_t aOffset) { - nsCOMPtr parent = do_QueryInterface(aParent); - if (!parent) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; - } + VALIDATE_ACCESS(aParent); - ErrorResult rv; - SetStart(*parent, aOffset, rv); - return rv.ErrorCode(); + nsCOMPtr parent = do_QueryInterface(aParent); + AutoInvalidateSelection atEndOfBlock(this); + return SetStart(parent, aOffset); } /* virtual */ nsresult @@ -1139,80 +1027,45 @@ nsRange::SetStart(nsINode* aParent, int32_t aOffset) return NS_OK; } -void -nsRange::SetStartBefore(nsINode& aNode, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNode)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - AutoInvalidateSelection atEndOfBlock(this); - aRv = SetStart(aNode.GetParentNode(), IndexOf(&aNode)); -} - NS_IMETHODIMP nsRange::SetStartBefore(nsIDOMNode* aSibling) { - nsCOMPtr sibling = do_QueryInterface(aSibling); - if (!sibling) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; + VALIDATE_ACCESS(aSibling); + + nsCOMPtr parent; + nsresult rv = aSibling->GetParentNode(getter_AddRefs(parent)); + if (NS_FAILED(rv) || !parent) { + return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR; } - ErrorResult rv; - SetStartBefore(*sibling, rv); - return rv.ErrorCode(); -} - -void -nsRange::SetStartAfter(nsINode& aNode, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNode)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - AutoInvalidateSelection atEndOfBlock(this); - aRv = SetStart(aNode.GetParentNode(), IndexOf(&aNode) + 1); + return SetStart(parent, IndexOf(aSibling)); } NS_IMETHODIMP nsRange::SetStartAfter(nsIDOMNode* aSibling) { - nsCOMPtr sibling = do_QueryInterface(aSibling); - if (!sibling) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; + VALIDATE_ACCESS(aSibling); + + nsCOMPtr nParent; + nsresult res = aSibling->GetParentNode(getter_AddRefs(nParent)); + if (NS_FAILED(res) || !nParent) { + return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR; } - ErrorResult rv; - SetStartAfter(*sibling, rv); - return rv.ErrorCode(); -} - -void -nsRange::SetEnd(nsINode& aNode, uint32_t aOffset, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNode)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - AutoInvalidateSelection atEndOfBlock(this); - aRv = SetEnd(&aNode, aOffset); + return SetStart(nParent, IndexOf(aSibling) + 1); } NS_IMETHODIMP nsRange::SetEnd(nsIDOMNode* aParent, int32_t aOffset) { - nsCOMPtr parent = do_QueryInterface(aParent); - if (!parent) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; - } + VALIDATE_ACCESS(aParent); - ErrorResult rv; - SetEnd(*parent, aOffset, rv); - return rv.ErrorCode(); + AutoInvalidateSelection atEndOfBlock(this); + nsCOMPtr parent = do_QueryInterface(aParent); + return SetEnd(parent, aOffset); } + /* virtual */ nsresult nsRange::SetEnd(nsINode* aParent, int32_t aOffset) { @@ -1238,54 +1091,32 @@ nsRange::SetEnd(nsINode* aParent, int32_t aOffset) return NS_OK; } -void -nsRange::SetEndBefore(nsINode& aNode, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNode)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - AutoInvalidateSelection atEndOfBlock(this); - aRv = SetEnd(aNode.GetParentNode(), IndexOf(&aNode)); -} - NS_IMETHODIMP nsRange::SetEndBefore(nsIDOMNode* aSibling) { - nsCOMPtr sibling = do_QueryInterface(aSibling); - if (!sibling) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; + VALIDATE_ACCESS(aSibling); + + nsCOMPtr nParent; + nsresult rv = aSibling->GetParentNode(getter_AddRefs(nParent)); + if (NS_FAILED(rv) || !nParent) { + return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR; } - ErrorResult rv; - SetEndBefore(*sibling, rv); - return rv.ErrorCode(); -} - -void -nsRange::SetEndAfter(nsINode& aNode, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNode)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - AutoInvalidateSelection atEndOfBlock(this); - aRv = SetEnd(aNode.GetParentNode(), IndexOf(&aNode) + 1); + return SetEnd(nParent, IndexOf(aSibling)); } NS_IMETHODIMP nsRange::SetEndAfter(nsIDOMNode* aSibling) { - nsCOMPtr sibling = do_QueryInterface(aSibling); - if (!sibling) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; + VALIDATE_ACCESS(aSibling); + + nsCOMPtr nParent; + nsresult res = aSibling->GetParentNode(getter_AddRefs(nParent)); + if (NS_FAILED(res) || !nParent) { + return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR; } - ErrorResult rv; - SetEndAfter(*sibling, rv); - return rv.ErrorCode(); + return SetEnd(nParent, IndexOf(aSibling) + 1); } NS_IMETHODIMP @@ -1306,66 +1137,39 @@ nsRange::Collapse(bool aToStart) NS_IMETHODIMP nsRange::SelectNode(nsIDOMNode* aN) { + VALIDATE_ACCESS(aN); + nsCOMPtr node = do_QueryInterface(aN); NS_ENSURE_TRUE(node, NS_ERROR_DOM_INVALID_NODE_TYPE_ERR); - ErrorResult rv; - SelectNode(*node, rv); - return rv.ErrorCode(); -} - -void -nsRange::SelectNode(nsINode& aNode, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNode)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - nsINode* parent = aNode.GetParentNode(); + nsINode* parent = node->GetParentNode(); nsINode* newRoot = IsValidBoundary(parent); - if (!newRoot) { - aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR); - return; - } + NS_ENSURE_TRUE(newRoot, NS_ERROR_DOM_INVALID_NODE_TYPE_ERR); - int32_t index = parent->IndexOf(&aNode); + int32_t index = parent->IndexOf(node); if (index < 0) { - aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR); - return; + return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR; } AutoInvalidateSelection atEndOfBlock(this); DoSetRange(parent, index, parent, index + 1, newRoot); + + return NS_OK; } NS_IMETHODIMP nsRange::SelectNodeContents(nsIDOMNode* aN) { + VALIDATE_ACCESS(aN); + nsCOMPtr node = do_QueryInterface(aN); - NS_ENSURE_TRUE(node, NS_ERROR_DOM_INVALID_NODE_TYPE_ERR); - - ErrorResult rv; - SelectNodeContents(*node, rv); - return rv.ErrorCode(); -} - -void -nsRange::SelectNodeContents(nsINode& aNode, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNode)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - nsINode* newRoot = IsValidBoundary(&aNode); - if (!newRoot) { - aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR); - return; - } - + nsINode* newRoot = IsValidBoundary(node); + NS_ENSURE_TRUE(newRoot, NS_ERROR_DOM_INVALID_NODE_TYPE_ERR); + AutoInvalidateSelection atEndOfBlock(this); - DoSetRange(&aNode, 0, &aNode, aNode.Length(), newRoot); + DoSetRange(node, 0, node, node->Length(), newRoot); + + return NS_OK; } // The Subtree Content Iterator only returns subtrees that are @@ -1769,27 +1573,28 @@ ValidateCurrentNode(nsRange* aRange, RangeSubtreeIterator& aIter) return NS_SUCCEEDED(res) && !before && !after; } -nsresult -nsRange::CutContents(dom::DocumentFragment** aFragment) +nsresult nsRange::CutContents(nsIDOMDocumentFragment** aFragment) { if (aFragment) { *aFragment = nullptr; } + nsresult rv; + nsCOMPtr doc = mStartParent->OwnerDoc(); nsCOMPtr commonAncestor; - nsresult rv = GetCommonAncestorContainer(getter_AddRefs(commonAncestor)); + rv = GetCommonAncestorContainer(getter_AddRefs(commonAncestor)); NS_ENSURE_SUCCESS(rv, rv); // If aFragment isn't null, create a temporary fragment to hold our return. - nsRefPtr retval; + nsCOMPtr retval; if (aFragment) { - ErrorResult error; - retval = NS_NewDocumentFragment(doc->NodeInfoManager(), error); - NS_ENSURE_SUCCESS(error.ErrorCode(), error.ErrorCode()); + rv = NS_NewDocumentFragment(getter_AddRefs(retval), + doc->NodeInfoManager()); + NS_ENSURE_SUCCESS(rv, rv); } - nsCOMPtr commonCloneAncestor = retval.get(); + nsCOMPtr commonCloneAncestor(do_QueryInterface(retval)); // Batch possible DOMSubtreeModified events. mozAutoSubtreeModified subtree(mRoot ? mRoot->OwnerDoc(): nullptr, nullptr); @@ -2059,28 +1864,11 @@ nsRange::DeleteContents() return CutContents(nullptr); } -void -nsRange::DeleteContents(ErrorResult& aRv) -{ - aRv = CutContents(nullptr); -} - NS_IMETHODIMP nsRange::ExtractContents(nsIDOMDocumentFragment** aReturn) { NS_ENSURE_ARG_POINTER(aReturn); - nsRefPtr fragment; - nsresult rv = CutContents(getter_AddRefs(fragment)); - fragment.forget(aReturn); - return rv; -} - -already_AddRefed -nsRange::ExtractContents(ErrorResult& rv) -{ - nsRefPtr fragment; - rv = CutContents(getter_AddRefs(fragment)); - return fragment.forget(); + return CutContents(aReturn); } NS_IMETHODIMP @@ -2090,19 +1878,8 @@ nsRange::CompareBoundaryPoints(uint16_t aHow, nsIDOMRange* aOtherRange, nsRange* otherRange = static_cast(aOtherRange); NS_ENSURE_TRUE(otherRange, NS_ERROR_NULL_POINTER); - ErrorResult rv; - *aCmpRet = CompareBoundaryPoints(aHow, *otherRange, rv); - return rv.ErrorCode(); -} - -int16_t -nsRange::CompareBoundaryPoints(uint16_t aHow, nsRange& aOtherRange, - ErrorResult& rv) -{ - if (!mIsPositioned || !aOtherRange.IsPositioned()) { - rv.Throw(NS_ERROR_NOT_INITIALIZED); - return 0; - } + if (!mIsPositioned || !otherRange->IsPositioned()) + return NS_ERROR_NOT_INITIALIZED; nsINode *ourNode, *otherNode; int32_t ourOffset, otherOffset; @@ -2111,40 +1888,39 @@ nsRange::CompareBoundaryPoints(uint16_t aHow, nsRange& aOtherRange, case nsIDOMRange::START_TO_START: ourNode = mStartParent; ourOffset = mStartOffset; - otherNode = aOtherRange.GetStartParent(); - otherOffset = aOtherRange.StartOffset(); + otherNode = otherRange->GetStartParent(); + otherOffset = otherRange->StartOffset(); break; case nsIDOMRange::START_TO_END: ourNode = mEndParent; ourOffset = mEndOffset; - otherNode = aOtherRange.GetStartParent(); - otherOffset = aOtherRange.StartOffset(); + otherNode = otherRange->GetStartParent(); + otherOffset = otherRange->StartOffset(); break; case nsIDOMRange::END_TO_START: ourNode = mStartParent; ourOffset = mStartOffset; - otherNode = aOtherRange.GetEndParent(); - otherOffset = aOtherRange.EndOffset(); + otherNode = otherRange->GetEndParent(); + otherOffset = otherRange->EndOffset(); break; case nsIDOMRange::END_TO_END: ourNode = mEndParent; ourOffset = mEndOffset; - otherNode = aOtherRange.GetEndParent(); - otherOffset = aOtherRange.EndOffset(); + otherNode = otherRange->GetEndParent(); + otherOffset = otherRange->EndOffset(); break; default: // We were passed an illegal value - rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return 0; + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; } - if (mRoot != aOtherRange.GetRoot()) { - rv.Throw(NS_ERROR_DOM_WRONG_DOCUMENT_ERR); - return 0; - } + if (mRoot != otherRange->GetRoot()) + return NS_ERROR_DOM_WRONG_DOCUMENT_ERR; - return nsContentUtils::ComparePoints(ourNode, ourOffset, - otherNode, otherOffset); + *aCmpRet = nsContentUtils::ComparePoints(ourNode, ourOffset, + otherNode, otherOffset); + + return NS_OK; } /* static */ nsresult @@ -2201,58 +1977,45 @@ nsRange::CloneParentsBetween(nsIDOMNode *aAncestor, NS_IMETHODIMP nsRange::CloneContents(nsIDOMDocumentFragment** aReturn) { - ErrorResult rv; - *aReturn = CloneContents(rv).get(); - return rv.ErrorCode(); -} - -already_AddRefed -nsRange::CloneContents(ErrorResult& aRv) -{ + nsresult res; nsCOMPtr commonAncestor; - aRv = GetCommonAncestorContainer(getter_AddRefs(commonAncestor)); - MOZ_ASSERT(!aRv.Failed(), "GetCommonAncestorContainer() shouldn't fail!"); + res = GetCommonAncestorContainer(getter_AddRefs(commonAncestor)); + if (NS_FAILED(res)) return res; nsCOMPtr document = do_QueryInterface(mStartParent->OwnerDoc()); NS_ASSERTION(document, "CloneContents needs a document to continue."); - if (!document) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } + if (!document) return NS_ERROR_FAILURE; // Create a new document fragment in the context of this document, // which might be null + nsCOMPtr clonedFrag; nsCOMPtr doc(do_QueryInterface(document)); - nsRefPtr clonedFrag = - NS_NewDocumentFragment(doc->NodeInfoManager(), aRv); - if (aRv.Failed()) { - return nullptr; - } + res = NS_NewDocumentFragment(getter_AddRefs(clonedFrag), + doc->NodeInfoManager()); + if (NS_FAILED(res)) return res; - nsCOMPtr commonCloneAncestor = clonedFrag.get(); - if (!commonCloneAncestor) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } + nsCOMPtr commonCloneAncestor(do_QueryInterface(clonedFrag)); + if (!commonCloneAncestor) return NS_ERROR_FAILURE; // Create and initialize a subtree iterator that will give // us all the subtrees within the range. RangeSubtreeIterator iter; - aRv = iter.Init(this); - if (aRv.Failed()) { - return nullptr; - } + res = iter.Init(this); + if (NS_FAILED(res)) return res; if (iter.IsDone()) { // There's nothing to add to the doc frag, we must be done! - return clonedFrag.forget(); + + *aReturn = clonedFrag; + NS_IF_ADDREF(*aReturn); + return NS_OK; } iter.First(); @@ -2280,10 +2043,8 @@ nsRange::CloneContents(ErrorResult& aRv) // Clone the current subtree! nsCOMPtr clone; - aRv = node->CloneNode(deepClone, 1, getter_AddRefs(clone)); - if (aRv.Failed()) { - return nullptr; - } + res = node->CloneNode(deepClone, 1, getter_AddRefs(clone)); + if (NS_FAILED(res)) return res; // If it's CharacterData, make sure we only clone what // is in the range. @@ -2301,17 +2062,13 @@ nsRange::CloneContents(ErrorResult& aRv) // data after it. uint32_t dataLength = 0; - aRv = charData->GetLength(&dataLength); - if (aRv.Failed()) { - return nullptr; - } + res = charData->GetLength(&dataLength); + if (NS_FAILED(res)) return res; if (dataLength > (uint32_t)mEndOffset) { - aRv = charData->DeleteData(mEndOffset, dataLength - mEndOffset); - if (aRv.Failed()) { - return nullptr; - } + res = charData->DeleteData(mEndOffset, dataLength - mEndOffset); + if (NS_FAILED(res)) return res; } } @@ -2322,10 +2079,8 @@ nsRange::CloneContents(ErrorResult& aRv) if (mStartOffset > 0) { - aRv = charData->DeleteData(0, mStartOffset); - if (aRv.Failed()) { - return nullptr; - } + res = charData->DeleteData(0, mStartOffset); + if (NS_FAILED(res)) return res; } } } @@ -2334,13 +2089,11 @@ nsRange::CloneContents(ErrorResult& aRv) nsCOMPtr closestAncestor, farthestAncestor; - aRv = CloneParentsBetween(commonAncestor, node, + res = CloneParentsBetween(commonAncestor, node, getter_AddRefs(closestAncestor), getter_AddRefs(farthestAncestor)); - if (aRv.Failed()) { - return nullptr; - } + if (NS_FAILED(res)) return res; // Hook the parent hierarchy/context of the subtree into the clone tree. @@ -2348,12 +2101,10 @@ nsRange::CloneContents(ErrorResult& aRv) if (farthestAncestor) { - aRv = commonCloneAncestor->AppendChild(farthestAncestor, + res = commonCloneAncestor->AppendChild(farthestAncestor, getter_AddRefs(tmpNode)); - if (aRv.Failed()) { - return nullptr; - } + if (NS_FAILED(res)) return res; } // Place the cloned subtree into the cloned doc frag tree! @@ -2363,18 +2114,16 @@ nsRange::CloneContents(ErrorResult& aRv) // Append the subtree under closestAncestor since it is the // immediate parent of the subtree. - aRv = closestAncestor->AppendChild(clone, getter_AddRefs(tmpNode)); + res = closestAncestor->AppendChild(clone, getter_AddRefs(tmpNode)); } else { // If we get here, there is no missing parent hierarchy between // commonAncestor and node, so just append clone to commonCloneAncestor. - aRv = commonCloneAncestor->AppendChild(clone, getter_AddRefs(tmpNode)); - } - if (aRv.Failed()) { - return nullptr; + res = commonCloneAncestor->AppendChild(clone, getter_AddRefs(tmpNode)); } + if (NS_FAILED(res)) return res; // Get the next subtree to be processed. The idea here is to setup // the parameters for the next iteration of the loop. @@ -2385,56 +2134,42 @@ nsRange::CloneContents(ErrorResult& aRv) break; // We must be done! nsCOMPtr nextNode(iter.GetCurrentNode()); - if (!nextNode) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } + if (!nextNode) return NS_ERROR_FAILURE; // Get node and nextNode's common parent. nsContentUtils::GetCommonAncestor(node, nextNode, getter_AddRefs(commonAncestor)); - if (!commonAncestor) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } + if (!commonAncestor) + return NS_ERROR_FAILURE; // Find the equivalent of commonAncestor in the cloned tree! while (node && node != commonAncestor) { tmpNode = node; - aRv = tmpNode->GetParentNode(getter_AddRefs(node)); - if (aRv.Failed()) { - return nullptr; - } - - if (!node) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } + res = tmpNode->GetParentNode(getter_AddRefs(node)); + if (NS_FAILED(res)) return res; + if (!node) return NS_ERROR_FAILURE; tmpNode = clone; - aRv = tmpNode->GetParentNode(getter_AddRefs(clone)); - if (aRv.Failed()) { - return nullptr; - } - - if (!clone) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } + res = tmpNode->GetParentNode(getter_AddRefs(clone)); + if (NS_FAILED(res)) return res; + if (!clone) return NS_ERROR_FAILURE; } commonCloneAncestor = clone; } - return clonedFrag.forget(); + *aReturn = clonedFrag; + NS_IF_ADDREF(*aReturn); + + return NS_OK; } already_AddRefed nsRange::CloneRange() const { - nsRefPtr range = new nsRange(mOwner); + nsRefPtr range = new nsRange(); range->SetMaySpanAnonymousSubtrees(mMaySpanAnonymousSubtrees); @@ -2453,31 +2188,15 @@ nsRange::CloneRange(nsIDOMRange** aReturn) NS_IMETHODIMP nsRange::InsertNode(nsIDOMNode* aNode) { - nsCOMPtr node = do_QueryInterface(aNode); - if (!node) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; - } - - ErrorResult rv; - InsertNode(*node, rv); - return rv.ErrorCode(); -} - -void -nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNode)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - int32_t tStartOffset = StartOffset(); + VALIDATE_ACCESS(aNode); + + nsresult res; + int32_t tStartOffset; + this->GetStartOffset(&tStartOffset); nsCOMPtr tStartContainer; - aRv = this->GetStartContainer(getter_AddRefs(tStartContainer)); - if (aRv.Failed()) { - return; - } + res = this->GetStartContainer(getter_AddRefs(tStartContainer)); + NS_ENSURE_SUCCESS(res, res); // This is the node we'll be inserting before, and its parent nsCOMPtr referenceNode; @@ -2486,34 +2205,22 @@ nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv) nsCOMPtr startTextNode(do_QueryInterface(tStartContainer)); nsCOMPtr tChildList; if (startTextNode) { - aRv = tStartContainer->GetParentNode(getter_AddRefs(referenceParentNode)); - if (aRv.Failed()) { - return; - } - - if (!referenceParentNode) { - aRv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR); - return; - } + res = tStartContainer->GetParentNode(getter_AddRefs(referenceParentNode)); + NS_ENSURE_SUCCESS(res, res); + NS_ENSURE_TRUE(referenceParentNode, NS_ERROR_DOM_HIERARCHY_REQUEST_ERR); nsCOMPtr secondPart; - aRv = startTextNode->SplitText(tStartOffset, getter_AddRefs(secondPart)); - if (aRv.Failed()) { - return; - } + res = startTextNode->SplitText(tStartOffset, getter_AddRefs(secondPart)); + NS_ENSURE_SUCCESS(res, res); referenceNode = secondPart; } else { - aRv = tStartContainer->GetChildNodes(getter_AddRefs(tChildList)); - if (aRv.Failed()) { - return; - } + res = tStartContainer->GetChildNodes(getter_AddRefs(tChildList)); + NS_ENSURE_SUCCESS(res, res); // find the insertion point in the DOM and insert the Node - aRv = tChildList->Item(tStartOffset, getter_AddRefs(referenceNode)); - if (aRv.Failed()) { - return; - } + res = tChildList->Item(tStartOffset, getter_AddRefs(referenceNode)); + NS_ENSURE_SUCCESS(res, res); } // We might need to update the end to include the new node (bug 433662). @@ -2525,61 +2232,36 @@ nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv) newOffset = IndexOf(referenceNode); } else { uint32_t length; - aRv = tChildList->GetLength(&length); - if (aRv.Failed()) { - return; - } - + res = tChildList->GetLength(&length); + NS_ENSURE_SUCCESS(res, res); newOffset = length; } - if (aNode.NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) { - newOffset += aNode.GetChildCount(); + nsCOMPtr node = do_QueryInterface(aNode); + NS_ENSURE_STATE(node); + if (node->NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) { + newOffset += node->GetChildCount(); } else { newOffset++; } // Now actually insert the node nsCOMPtr tResultNode; - nsCOMPtr node = aNode.AsDOMNode(); - if (!node) { - aRv.Throw(NS_ERROR_DOM_NOT_OBJECT_ERR); - return; - } - aRv = referenceParentNode->InsertBefore(node, referenceNode, getter_AddRefs(tResultNode)); - if (aRv.Failed()) { - return; - } + res = referenceParentNode->InsertBefore(aNode, referenceNode, getter_AddRefs(tResultNode)); + NS_ENSURE_SUCCESS(res, res); if (Collapsed()) { - aRv = SetEnd(referenceParentNode, newOffset); + return SetEnd(referenceParentNode, newOffset); } + return NS_OK; } NS_IMETHODIMP nsRange::SurroundContents(nsIDOMNode* aNewParent) { - nsCOMPtr node = do_QueryInterface(aNewParent); - if (!node) { - return NS_ERROR_DOM_NOT_OBJECT_ERR; - } - ErrorResult rv; - SurroundContents(*node, rv); - return rv.ErrorCode(); -} + VALIDATE_ACCESS(aNewParent); -void -nsRange::SurroundContents(nsINode& aNewParent, ErrorResult& aRv) -{ - if (!nsContentUtils::CanCallerAccess(&aNewParent)) { - aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - if (!mRoot) { - aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); - return; - } + NS_ENSURE_TRUE(mRoot, NS_ERROR_DOM_INVALID_STATE_ERR); // INVALID_STATE_ERROR: Raised if the Range partially selects a non-text // node. if (mStartParent != mEndParent) { @@ -2587,88 +2269,78 @@ nsRange::SurroundContents(nsINode& aNewParent, ErrorResult& aRv) bool endIsText = mEndParent->IsNodeOfType(nsINode::eTEXT); nsINode* startGrandParent = mStartParent->GetParentNode(); nsINode* endGrandParent = mEndParent->GetParentNode(); - if (!((startIsText && endIsText && - startGrandParent && - startGrandParent == endGrandParent) || - (startIsText && - startGrandParent && - startGrandParent == mEndParent) || - (endIsText && - endGrandParent && - endGrandParent == mStartParent))) { - aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); - return; - } + NS_ENSURE_TRUE((startIsText && endIsText && + startGrandParent && + startGrandParent == endGrandParent) || + (startIsText && + startGrandParent && + startGrandParent == mEndParent) || + (endIsText && + endGrandParent && + endGrandParent == mStartParent), + NS_ERROR_DOM_INVALID_STATE_ERR); } // INVALID_NODE_TYPE_ERROR if aNewParent is something that can't be inserted // (Document, DocumentType, DocumentFragment) - uint16_t nodeType = aNewParent.NodeType(); + uint16_t nodeType; + nsresult res = aNewParent->GetNodeType(&nodeType); + if (NS_FAILED(res)) return res; if (nodeType == nsIDOMNode::DOCUMENT_NODE || nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE || nodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) { - aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR); - return; + return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR; } // Extract the contents within the range. nsCOMPtr docFrag; - aRv = ExtractContents(getter_AddRefs(docFrag)); + res = ExtractContents(getter_AddRefs(docFrag)); - if (aRv.Failed()) { - return; - } - - if (!docFrag) { - aRv.Throw(NS_ERROR_FAILURE); - return; - } + if (NS_FAILED(res)) return res; + if (!docFrag) return NS_ERROR_FAILURE; // Spec says we need to remove all of aNewParent's // children prior to insertion. - nsCOMPtr children = aNewParent.ChildNodes(); - if (!children) { - aRv.Throw(NS_ERROR_FAILURE); - return; - } + nsCOMPtr children; + res = aNewParent->GetChildNodes(getter_AddRefs(children)); - uint32_t numChildren = children->Length(); + if (NS_FAILED(res)) return res; + if (!children) return NS_ERROR_FAILURE; + + uint32_t numChildren = 0; + res = children->GetLength(&numChildren); + if (NS_FAILED(res)) return res; nsCOMPtr tmpNode; while (numChildren) { - nsCOMPtr child = children->Item(--numChildren); - if (!child) { - aRv.Throw(NS_ERROR_FAILURE); - return; - } + nsCOMPtr child; + res = children->Item(--numChildren, getter_AddRefs(child)); - aNewParent.RemoveChild(*child, aRv); - if (aRv.Failed()) { - return; - } + if (NS_FAILED(res)) return res; + if (!child) return NS_ERROR_FAILURE; + + res = aNewParent->RemoveChild(child, getter_AddRefs(tmpNode)); + if (NS_FAILED(res)) return res; } // Insert aNewParent at the range's start point. - InsertNode(aNewParent, aRv); - if (aRv.Failed()) { - return; - } + res = InsertNode(aNewParent); + if (NS_FAILED(res)) return res; // Append the content we extracted under aNewParent. - aRv = aNewParent.AsDOMNode()->AppendChild(docFrag, getter_AddRefs(tmpNode)); - if (aRv.Failed()) { - return; - } + + res = aNewParent->AppendChild(docFrag, getter_AddRefs(tmpNode)); + if (NS_FAILED(res)) return res; // Select aNewParent, and its contents. - SelectNode(aNewParent, aRv); + return SelectNode(aNewParent); } NS_IMETHODIMP @@ -2779,18 +2451,6 @@ nsRange::CreateContextualFragment(const nsAString& aFragment, return NS_ERROR_FAILURE; } -already_AddRefed -nsRange::CreateContextualFragment(const nsAString& aFragment, ErrorResult& aRv) -{ - if (!mIsPositioned) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } - - return nsContentUtils::CreateContextualFragment(mStartParent, aFragment, - false, aRv); -} - static void ExtractRectFromOffset(nsIFrame* aFrame, const nsIFrame* aRelativeTo, const int32_t aOffset, nsRect* aR, bool aKeepLeft) @@ -2923,54 +2583,51 @@ static void CollectClientRects(nsLayoutUtils::RectCallback* aCollector, NS_IMETHODIMP nsRange::GetBoundingClientRect(nsIDOMClientRect** aResult) { - *aResult = GetBoundingClientRect().get(); - return NS_OK; -} + *aResult = nullptr; + + // Weak ref, since we addref it below + nsClientRect* rect = new nsClientRect(); + if (!rect) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*aResult = rect); -already_AddRefed -nsRange::GetBoundingClientRect() -{ - nsRefPtr rect = new nsClientRect(); if (!mStartParent) - return rect.forget(); + return NS_OK; nsLayoutUtils::RectAccumulator accumulator; + CollectClientRects(&accumulator, this, mStartParent, mStartOffset, mEndParent, mEndOffset); nsRect r = accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect : accumulator.mResultRect; rect->SetLayoutRect(r); - return rect.forget(); + return NS_OK; } NS_IMETHODIMP nsRange::GetClientRects(nsIDOMClientRectList** aResult) { - ErrorResult rv; - *aResult = GetClientRects(rv).get(); - return rv.ErrorCode(); -} + *aResult = nullptr; -already_AddRefed -nsRange::GetClientRects(ErrorResult& rv) -{ if (!mStartParent) - return nullptr; + return NS_OK; nsRefPtr rectList = new nsClientRectList(static_cast(this)); + if (!rectList) + return NS_ERROR_OUT_OF_MEMORY; nsLayoutUtils::RectListBuilder builder(rectList); CollectClientRects(&builder, this, mStartParent, mStartOffset, mEndParent, mEndOffset); - if (NS_FAILED(builder.mRV)) { - rv.Throw(builder.mRV); - return nullptr; - } - return rectList.forget(); + if (NS_FAILED(builder.mRV)) + return builder.mRV; + rectList.forget(aResult); + return NS_OK; } NS_IMETHODIMP diff --git a/content/base/src/nsRange.h b/content/base/src/nsRange.h index afc27dcd4710..7a84e41c5abf 100644 --- a/content/base/src/nsRange.h +++ b/content/base/src/nsRange.h @@ -12,32 +12,17 @@ #include "nsIDOMRange.h" #include "nsCOMPtr.h" +#include "nsIDOMDocumentFragment.h" #include "nsINode.h" -#include "nsIDocument.h" #include "nsIDOMNode.h" #include "prmon.h" #include "nsStubMutationObserver.h" -#include "nsWrapperCache.h" -#include "mozilla/Attributes.h" -class nsClientRectList; -class nsIDOMDocumentFragment; - -namespace mozilla { -class ErrorResult; -namespace dom { -class DocumentFragment; -} -} - -class nsRange MOZ_FINAL : public nsIDOMRange, - public nsStubMutationObserver, - public nsWrapperCache +class nsRange : public nsIDOMRange, + public nsStubMutationObserver { - typedef mozilla::ErrorResult ErrorResult; - public: - nsRange(nsINode* aNode) + nsRange() : mRoot(nullptr) , mStartOffset(0) , mEndOffset(0) @@ -51,11 +36,7 @@ public: , mAssertNextInsertOrAppendIndex(-1) , mAssertNextInsertOrAppendNode(nullptr) #endif - { - SetIsDOMBinding(); - MOZ_ASSERT(aNode, "range isn't in a document!"); - mOwner = aNode->OwnerDoc(); - } + {} virtual ~nsRange(); static nsresult CreateRange(nsIDOMNode* aStartParent, int32_t aStartOffset, @@ -66,7 +47,7 @@ public: nsIDOMRange** aRange); NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsRange, nsIDOMRange) + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsRange, nsIDOMRange) // nsIDOMRange interface NS_DECL_NSIDOMRANGE @@ -101,6 +82,12 @@ public: return mIsPositioned; } + bool Collapsed() const + { + return mIsPositioned && mStartParent == mEndParent && + mStartOffset == mEndOffset; + } + void SetMaySpanAnonymousSubtrees(bool aMaySpanAnonymousSubtrees) { mMaySpanAnonymousSubtrees = aMaySpanAnonymousSubtrees; @@ -159,46 +146,6 @@ public: NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED - // WebIDL - bool Collapsed() const - { - return mIsPositioned && mStartParent == mEndParent && - mStartOffset == mEndOffset; - } - already_AddRefed - CreateContextualFragment(const nsAString& aString, ErrorResult& aError); - already_AddRefed - CloneContents(ErrorResult& aErr); - int16_t CompareBoundaryPoints(uint16_t aHow, nsRange& aOther, - ErrorResult& aErr); - int16_t ComparePoint(nsINode& aParent, uint32_t aOffset, ErrorResult& aErr); - void DeleteContents(ErrorResult& aRv); - already_AddRefed - ExtractContents(ErrorResult& aErr); - nsINode* GetCommonAncestorContainer(ErrorResult& aRv) const; - nsINode* GetStartContainer(ErrorResult& aRv) const; - uint32_t GetStartOffset(ErrorResult& aRv) const; - nsINode* GetEndContainer(ErrorResult& aRv) const; - uint32_t GetEndOffset(ErrorResult& aRv) const; - void InsertNode(nsINode& aNode, ErrorResult& aErr); - bool IntersectsNode(nsINode& aNode, ErrorResult& aRv); - bool IsPointInRange(nsINode& aParent, uint32_t aOffset, ErrorResult& aErr); - void SelectNode(nsINode& aNode, ErrorResult& aErr); - void SelectNodeContents(nsINode& aNode, ErrorResult& aErr); - void SetEnd(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr); - void SetEndAfter(nsINode& aNode, ErrorResult& aErr); - void SetEndBefore(nsINode& aNode, ErrorResult& aErr); - void SetStart(nsINode& aNode, uint32_t aOffset, ErrorResult& aErr); - void SetStartAfter(nsINode& aNode, ErrorResult& aErr); - void SetStartBefore(nsINode& aNode, ErrorResult& aErr); - void SurroundContents(nsINode& aNode, ErrorResult& aErr); - already_AddRefed GetBoundingClientRect(); - already_AddRefed GetClientRects(ErrorResult& aErr); - - nsINode* GetParentObject() const { return mOwner; } - virtual JSObject* WrapObject(JSContext* cx, JSObject* scope, bool* tried) - MOZ_OVERRIDE MOZ_FINAL; - private: // no copy's or assigns nsRange(const nsRange&); @@ -210,7 +157,7 @@ private: * @param aFragment nsIDOMDocumentFragment containing the nodes. * May be null to indicate the caller doesn't want a fragment. */ - nsresult CutContents(mozilla::dom::DocumentFragment** frag); + nsresult CutContents(nsIDOMDocumentFragment** frag); static nsresult CloneParentsBetween(nsIDOMNode *aAncestor, nsIDOMNode *aNode, @@ -277,8 +224,7 @@ protected: #endif static bool mIsNested; }; - - nsCOMPtr mOwner; + nsCOMPtr mRoot; nsCOMPtr mStartParent; nsCOMPtr mEndParent; diff --git a/content/base/src/nsTextNode.cpp b/content/base/src/nsTextNode.cpp index e1f95e8bcf3d..6d13f47fd643 100644 --- a/content/base/src/nsTextNode.cpp +++ b/content/base/src/nsTextNode.cpp @@ -185,6 +185,17 @@ void nsTextNode::UnbindFromTree(bool aDeep, bool aNullParent) nsGenericDOMDataNode::UnbindFromTree(aDeep, aNullParent); } +already_AddRefed +nsTextNode::SplitText(uint32_t aOffset, ErrorResult& rv) +{ + nsCOMPtr newChild; + rv = SplitData(aOffset, getter_AddRefs(newChild)); + if (rv.Failed()) { + return nullptr; + } + return static_cast(newChild.forget().get()); +} + #ifdef DEBUG void nsTextNode::List(FILE* out, int32_t aIndent) const diff --git a/content/base/src/nsTextNode.h b/content/base/src/nsTextNode.h index 1d4fdf6f6aeb..525cc7543d04 100644 --- a/content/base/src/nsTextNode.h +++ b/content/base/src/nsTextNode.h @@ -10,19 +10,19 @@ * Implementation of DOM Core's nsIDOMText node. */ -#include "mozilla/dom/Text.h" +#include "nsGenericDOMDataNode.h" #include "nsIDOMText.h" #include "nsDebug.h" /** * Class used to implement DOM text nodes */ -class nsTextNode : public mozilla::dom::Text, +class nsTextNode : public nsGenericDOMDataNode, public nsIDOMText { public: nsTextNode(already_AddRefed aNodeInfo) - : mozilla::dom::Text(aNodeInfo) + : nsGenericDOMDataNode(aNodeInfo) { NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE, "Bad NodeType in aNodeInfo"); @@ -62,6 +62,14 @@ public: virtual nsIDOMNode* AsDOMNode() { return this; } + // WebIDL API + already_AddRefed SplitText(uint32_t aOffset, + mozilla::ErrorResult& rv); + void GetWholeText(nsAString& aWholeText, mozilla::ErrorResult& rv) + { + rv = GetWholeText(aWholeText); + } + #ifdef DEBUG virtual void List(FILE* out, int32_t aIndent) const; virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const; diff --git a/content/base/test/test_bug166235.html b/content/base/test/test_bug166235.html index 460bdf644a94..33b138099add 100644 --- a/content/base/test/test_bug166235.html +++ b/content/base/test/test_bug166235.html @@ -40,7 +40,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=816298 var clipboard = Cc["@mozilla.org/widget/clipboard;1"] .getService(SpecialPowers.Ci.nsIClipboard); - var textarea = SpecialPowers.wrap(document.getElementById('input')); + var textarea = SpecialPowers.wrap(document).getElementById('input'); function getLoadContext() { return SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor) @@ -78,7 +78,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=816298 function testPasteText(expected, test) { textarea.value=""; textarea.focus(); - textarea.editor.paste(1); + textarea.QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement) + .editor.paste(1); is(textarea.value, expected, test + ": textarea paste"); } function testInnerHTML(id, expected) { diff --git a/content/base/test/test_copypaste.html b/content/base/test/test_copypaste.html index c6d5061d546e..dbdf2cc1b176 100644 --- a/content/base/test/test_copypaste.html +++ b/content/base/test/test_copypaste.html @@ -56,7 +56,7 @@ function testCopyPaste () { var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"] .getService(Components.interfaces.nsIClipboard); - var textarea = SpecialPowers.wrap(document.getElementById('input')); + var textarea = document.getElementById('input'); function copySelectionToClipboard() { documentViewer.copySelection(); @@ -111,7 +111,8 @@ function testCopyPaste () { function testPasteText(expected) { textarea.value=""; textarea.focus(); - textarea.editor.paste(1); + textarea.QueryInterface(Components.interfaces.nsIDOMNSEditableElement) + .editor.paste(1); is(textarea.value, expected, "value of the textarea after the paste"); } function testSelectionToString(expected) { diff --git a/content/events/src/nsContentEventHandler.cpp b/content/events/src/nsContentEventHandler.cpp index de978925bf4c..45011d852200 100644 --- a/content/events/src/nsContentEventHandler.cpp +++ b/content/events/src/nsContentEventHandler.cpp @@ -515,7 +515,7 @@ nsContentEventHandler::OnQueryTextContent(nsQueryContentEvent* aEvent) NS_ASSERTION(aEvent->mReply.mString.IsEmpty(), "The reply string must be empty"); - nsRefPtr range = new nsRange(mRootContent); + nsRefPtr range = new nsRange(); rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset, aEvent->mInput.mLength, false); NS_ENSURE_SUCCESS(rv, rv); @@ -572,7 +572,7 @@ nsContentEventHandler::OnQueryTextRect(nsQueryContentEvent* aEvent) if (NS_FAILED(rv)) return rv; - nsRefPtr range = new nsRange(mRootContent); + nsRefPtr range = new nsRange(); rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset, aEvent->mInput.mLength, true); NS_ENSURE_SUCCESS(rv, rv); @@ -716,7 +716,7 @@ nsContentEventHandler::OnQueryCaretRect(nsQueryContentEvent* aEvent) } // Otherwise, we should set the guessed caret rect. - nsRefPtr range = new nsRange(mRootContent); + nsRefPtr range = new nsRange(); rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset, 0, true); NS_ENSURE_SUCCESS(rv, rv); @@ -899,10 +899,9 @@ nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent, int32_t aNodeOffset, uint32_t* aNativeOffset) { - NS_ENSURE_STATE(aRootContent); NS_ASSERTION(aNativeOffset, "param is invalid"); - nsRefPtr prev = new nsRange(aRootContent); + nsRefPtr prev = new nsRange(); nsCOMPtr rootDOMNode(do_QueryInterface(aRootContent)); prev->SetStart(rootDOMNode, 0); @@ -1034,7 +1033,7 @@ nsContentEventHandler::OnSelectionEvent(nsSelectionEvent* aEvent) } // Get range from offset and length - nsRefPtr range = new nsRange(mRootContent); + nsRefPtr range = new nsRange(); NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY); rv = SetRangeFromFlatTextOffset(range, aEvent->mOffset, aEvent->mLength, aEvent->mExpandToClusterBoundary); diff --git a/content/html/content/src/HTMLTextAreaElement.cpp b/content/html/content/src/HTMLTextAreaElement.cpp index 820071285292..efa13a55ab1a 100644 --- a/content/html/content/src/HTMLTextAreaElement.cpp +++ b/content/html/content/src/HTMLTextAreaElement.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/HTMLTextAreaElement.h" -#include "mozilla/dom/HTMLTextAreaElementBinding.h" #include "mozilla/Util.h" #include "nsIControllers.h" @@ -19,6 +18,7 @@ #include "nsFormSubmission.h" #include "nsIDOMEventTarget.h" #include "nsAttrValueInlines.h" +#include "nsGkAtoms.h" #include "nsStyleConsts.h" #include "nsPresContext.h" #include "nsMappedAttributes.h" @@ -73,8 +73,6 @@ HTMLTextAreaElement::HTMLTextAreaElement(already_AddRefed aNodeInfo AddStatesSilently(NS_EVENT_STATE_ENABLED | NS_EVENT_STATE_OPTIONAL | NS_EVENT_STATE_VALID); - - SetIsDOMBinding(); } @@ -238,7 +236,7 @@ HTMLTextAreaElement::GetValueInternal(nsAString& aValue, bool aIgnoreWrap) const NS_IMETHODIMP_(nsIEditor*) HTMLTextAreaElement::GetTextEditor() { - return GetEditor(); + return mState.GetEditor(); } NS_IMETHODIMP_(nsISelectionController*) @@ -372,22 +370,12 @@ HTMLTextAreaElement::GetDefaultValue(nsAString& aDefaultValue) NS_IMETHODIMP HTMLTextAreaElement::SetDefaultValue(const nsAString& aDefaultValue) -{ - ErrorResult error; - SetDefaultValue(aDefaultValue, error); - return error.ErrorCode(); -} - -void -HTMLTextAreaElement::SetDefaultValue(const nsAString& aDefaultValue, ErrorResult& aError) { nsresult rv = nsContentUtils::SetNodeTextContent(this, aDefaultValue, true); if (NS_SUCCEEDED(rv) && !mValueChanged) { Reset(); } - if (NS_FAILED(rv)) { - aError.Throw(rv); - } + return rv; } bool @@ -575,65 +563,45 @@ HTMLTextAreaElement::IsDoneAddingChildren() // Controllers Methods -nsIControllers* -HTMLTextAreaElement::GetControllers(ErrorResult& aError) -{ - if (!mControllers) - { - nsresult rv; - mControllers = do_CreateInstance(kXULControllersCID, &rv); - if (NS_FAILED(rv)) { - aError.Throw(rv); - return nullptr; - } - - nsCOMPtr controller = do_CreateInstance("@mozilla.org/editor/editorcontroller;1", &rv); - if (NS_FAILED(rv)) { - aError.Throw(rv); - return nullptr; - } - - mControllers->AppendController(controller); - - controller = do_CreateInstance("@mozilla.org/editor/editingcontroller;1", &rv); - if (NS_FAILED(rv)) { - aError.Throw(rv); - return nullptr; - } - - mControllers->AppendController(controller); - } - - return mControllers; -} - NS_IMETHODIMP HTMLTextAreaElement::GetControllers(nsIControllers** aResult) { NS_ENSURE_ARG_POINTER(aResult); - ErrorResult error; - *aResult = GetControllers(error); + if (!mControllers) + { + nsresult rv; + mControllers = do_CreateInstance(kXULControllersCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr controller = do_CreateInstance("@mozilla.org/editor/editorcontroller;1", &rv); + if (NS_FAILED(rv)) + return rv; + + mControllers->AppendController(controller); + + controller = do_CreateInstance("@mozilla.org/editor/editingcontroller;1", &rv); + if (NS_FAILED(rv)) + return rv; + + mControllers->AppendController(controller); + } + + *aResult = mControllers; NS_IF_ADDREF(*aResult); - return error.ErrorCode(); -} - -uint32_t -HTMLTextAreaElement::GetTextLength() -{ - nsAutoString val; - GetValue(val); - return val.Length(); + return NS_OK; } NS_IMETHODIMP HTMLTextAreaElement::GetTextLength(int32_t *aTextLength) { NS_ENSURE_ARG_POINTER(aTextLength); - *aTextLength = GetTextLength(); + nsAutoString val; + nsresult rv = GetValue(val); + *aTextLength = val.Length(); - return NS_OK; + return rv; } NS_IMETHODIMP @@ -641,62 +609,35 @@ HTMLTextAreaElement::GetSelectionStart(int32_t *aSelectionStart) { NS_ENSURE_ARG_POINTER(aSelectionStart); - ErrorResult error; - *aSelectionStart = GetSelectionStart(error); - return error.ErrorCode(); -} - -uint32_t -HTMLTextAreaElement::GetSelectionStart(ErrorResult& aError) -{ - int32_t selStart, selEnd; - nsresult rv = GetSelectionRange(&selStart, &selEnd); + int32_t selEnd; + nsresult rv = GetSelectionRange(aSelectionStart, &selEnd); if (NS_FAILED(rv) && mState.IsSelectionCached()) { - return mState.GetSelectionProperties().mStart; + *aSelectionStart = mState.GetSelectionProperties().mStart; + return NS_OK; } - if (NS_FAILED(rv)) { - aError.Throw(rv); - } - return selStart; + return rv; } NS_IMETHODIMP HTMLTextAreaElement::SetSelectionStart(int32_t aSelectionStart) -{ - ErrorResult error; - SetSelectionStart(aSelectionStart, error); - return error.ErrorCode(); -} - -void -HTMLTextAreaElement::SetSelectionStart(uint32_t aSelectionStart, ErrorResult& aError) { if (mState.IsSelectionCached()) { mState.GetSelectionProperties().mStart = aSelectionStart; - return; + return NS_OK; } nsAutoString direction; nsresult rv = GetSelectionDirection(direction); - if (NS_FAILED(rv)) { - aError.Throw(rv); - return; - } + NS_ENSURE_SUCCESS(rv, rv); int32_t start, end; rv = GetSelectionRange(&start, &end); - if (NS_FAILED(rv)) { - aError.Throw(rv); - return; - } + NS_ENSURE_SUCCESS(rv, rv); start = aSelectionStart; if (end < start) { end = start; } - rv = SetSelectionRange(start, end, direction); - if (NS_FAILED(rv)) { - aError.Throw(rv); - } + return SetSelectionRange(start, end, direction); } NS_IMETHODIMP @@ -704,62 +645,35 @@ HTMLTextAreaElement::GetSelectionEnd(int32_t *aSelectionEnd) { NS_ENSURE_ARG_POINTER(aSelectionEnd); - ErrorResult error; - *aSelectionEnd = GetSelectionEnd(error); - return error.ErrorCode(); -} - -uint32_t -HTMLTextAreaElement::GetSelectionEnd(ErrorResult& aError) -{ - int32_t selStart, selEnd; - nsresult rv = GetSelectionRange(&selStart, &selEnd); + int32_t selStart; + nsresult rv = GetSelectionRange(&selStart, aSelectionEnd); if (NS_FAILED(rv) && mState.IsSelectionCached()) { - return mState.GetSelectionProperties().mEnd; + *aSelectionEnd = mState.GetSelectionProperties().mEnd; + return NS_OK; } - if (NS_FAILED(rv)) { - aError.Throw(rv); - } - return selEnd; + return rv; } NS_IMETHODIMP HTMLTextAreaElement::SetSelectionEnd(int32_t aSelectionEnd) -{ - ErrorResult error; - SetSelectionEnd(aSelectionEnd, error); - return error.ErrorCode(); -} - -void -HTMLTextAreaElement::SetSelectionEnd(uint32_t aSelectionEnd, ErrorResult& aError) { if (mState.IsSelectionCached()) { mState.GetSelectionProperties().mEnd = aSelectionEnd; - return; + return NS_OK; } nsAutoString direction; nsresult rv = GetSelectionDirection(direction); - if (NS_FAILED(rv)) { - aError.Throw(rv); - return; - } + NS_ENSURE_SUCCESS(rv, rv); int32_t start, end; rv = GetSelectionRange(&start, &end); - if (NS_FAILED(rv)) { - aError.Throw(rv); - return; - } + NS_ENSURE_SUCCESS(rv, rv); end = aSelectionEnd; if (start > end) { start = end; } - rv = SetSelectionRange(start, end, direction); - if (NS_FAILED(rv)) { - aError.Throw(rv); - } + return SetSelectionRange(start, end, direction); } nsresult @@ -794,14 +708,6 @@ DirectionToName(nsITextControlFrame::SelectionDirection dir, nsAString& aDirecti nsresult HTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection) -{ - ErrorResult error; - GetSelectionDirection(aDirection, error); - return error.ErrorCode(); -} - -void -HTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection, ErrorResult& aError) { nsresult rv = NS_ERROR_FAILURE; nsIFormControlFrame* formControlFrame = GetFormControlFrame(true); @@ -820,23 +726,15 @@ HTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection, ErrorResult& a if (NS_FAILED(rv)) { if (mState.IsSelectionCached()) { DirectionToName(mState.GetSelectionProperties().mDirection, aDirection); - return; + return NS_OK; } - aError.Throw(rv); } + + return rv; } NS_IMETHODIMP -HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection) -{ - ErrorResult error; - SetSelectionDirection(aDirection, error); - return error.ErrorCode(); -} - -void -HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection, ErrorResult& aError) -{ +HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection) { if (mState.IsSelectionCached()) { nsITextControlFrame::SelectionDirection dir = nsITextControlFrame::eNone; if (aDirection.EqualsLiteral("forward")) { @@ -845,7 +743,7 @@ HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection, ErrorRes dir = nsITextControlFrame::eBackward; } mState.GetSelectionProperties().mDirection = dir; - return; + return NS_OK; } int32_t start, end; @@ -853,29 +751,15 @@ HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection, ErrorRes if (NS_SUCCEEDED(rv)) { rv = SetSelectionRange(start, end, aDirection); } - if (NS_FAILED(rv)) { - aError.Throw(rv); - } + + return rv; } NS_IMETHODIMP HTMLTextAreaElement::SetSelectionRange(int32_t aSelectionStart, int32_t aSelectionEnd, const nsAString& aDirection) -{ - ErrorResult error; - Optional dir; - dir = &aDirection; - SetSelectionRange(aSelectionStart, aSelectionEnd, dir, error); - return error.ErrorCode(); -} - -void -HTMLTextAreaElement::SetSelectionRange(uint32_t aSelectionStart, - uint32_t aSelectionEnd, - const Optional& aDirection, - ErrorResult& aError) -{ +{ nsresult rv = NS_ERROR_FAILURE; nsIFormControlFrame* formControlFrame = GetFormControlFrame(true); @@ -886,7 +770,7 @@ HTMLTextAreaElement::SetSelectionRange(uint32_t aSelectionStart, // Note that we don't currently support directionless selections, so // "none" is treated like "forward". nsITextControlFrame::SelectionDirection dir = nsITextControlFrame::eForward; - if (aDirection.WasPassed() && aDirection.Value().EqualsLiteral("backward")) { + if (aDirection.EqualsLiteral("backward")) { dir = nsITextControlFrame::eBackward; } @@ -897,10 +781,8 @@ HTMLTextAreaElement::SetSelectionRange(uint32_t aSelectionStart, } } - if (NS_FAILED(rv)) { - aError.Throw(rv); - } -} + return rv; +} nsresult HTMLTextAreaElement::Reset() @@ -1428,12 +1310,5 @@ HTMLTextAreaElement::FieldSetDisabledChanged(bool aNotify) nsGenericHTMLFormElement::FieldSetDisabledChanged(aNotify); } -JSObject* -HTMLTextAreaElement::WrapNode(JSContext* aCx, JSObject* aScope, - bool* aTriedToWrap) -{ - return HTMLTextAreaElementBinding::Wrap(aCx, aScope, this, aTriedToWrap); -} - } // namespace dom } // namespace mozilla diff --git a/content/html/content/src/HTMLTextAreaElement.h b/content/html/content/src/HTMLTextAreaElement.h index d73a9f80ff05..9436484cce05 100644 --- a/content/html/content/src/HTMLTextAreaElement.h +++ b/content/html/content/src/HTMLTextAreaElement.h @@ -16,7 +16,6 @@ #include "nsStubMutationObserver.h" #include "nsIConstraintValidation.h" #include "nsHTMLFormElement.h" -#include "nsGkAtoms.h" #include "nsTextEditorState.h" @@ -160,123 +159,9 @@ public: nsresult GetValidationMessage(nsAString& aValidationMessage, ValidityStateType aType); - // Web IDL binding methods - bool Autofocus() - { - return GetBoolAttr(nsGkAtoms::autofocus); - } - void SetAutofocus(bool aAutoFocus, ErrorResult& aError) - { - SetHTMLBoolAttr(nsGkAtoms::autofocus, aAutoFocus, aError); - } - uint32_t Cols() - { - return GetIntAttr(nsGkAtoms::cols, DEFAULT_COLS); - } - void SetCols(uint32_t aCols, ErrorResult& aError) - { - if (aCols == 0) { - aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); - } else { - SetHTMLUnsignedIntAttr(nsGkAtoms::cols, aCols, aError); - } - } - bool Disabled() - { - return GetBoolAttr(nsGkAtoms::disabled); - } - void SetDisabled(bool aDisabled, ErrorResult& aError) - { - SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aError); - } - // nsGenericHTMLFormElement::GetForm is fine - using nsGenericHTMLFormElement::GetForm; - int32_t MaxLength() - { - return GetIntAttr(nsGkAtoms::maxlength, -1); - } - void SetMaxLength(int32_t aMaxLength, ErrorResult& aError) - { - if (aMaxLength < 0) { - aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); - } else { - SetHTMLIntAttr(nsGkAtoms::maxlength, aMaxLength, aError); - } - } - // XPCOM GetName is fine - void SetName(const nsAString& aName, ErrorResult& aError) - { - SetHTMLAttr(nsGkAtoms::name, aName, aError); - } - // XPCOM GetPlaceholder is fine - void SetPlaceholder(const nsAString& aPlaceholder, ErrorResult& aError) - { - SetHTMLAttr(nsGkAtoms::placeholder, aPlaceholder, aError); - } - bool ReadOnly() - { - return GetBoolAttr(nsGkAtoms::readonly); - } - void SetReadOnly(bool aReadOnly, ErrorResult& aError) - { - SetHTMLBoolAttr(nsGkAtoms::readonly, aReadOnly, aError); - } - bool Required() - { - return GetBoolAttr(nsGkAtoms::required); - } - void SetRequired(bool aRequired, ErrorResult& aError) - { - SetHTMLBoolAttr(nsGkAtoms::required, aRequired, aError); - } - uint32_t Rows() - { - return GetIntAttr(nsGkAtoms::rows, DEFAULT_ROWS_TEXTAREA); - } - void SetRows(uint32_t aRows, ErrorResult& aError) - { - if (aRows == 0) { - aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); - } else { - SetHTMLUnsignedIntAttr(nsGkAtoms::rows, aRows, aError); - } - } - // XPCOM GetWrap is fine - void SetWrap(const nsAString& aWrap, ErrorResult& aError) - { - SetHTMLAttr(nsGkAtoms::wrap, aWrap, aError); - } - // XPCOM GetType is fine - // XPCOM GetDefaultValue is fine - void SetDefaultValue(const nsAString& aDefaultValue, ErrorResult& aError); - // XPCOM GetValue/SetValue are fine - uint32_t GetTextLength(); - // nsIConstraintValidation::WillValidate is fine. - // nsIConstraintValidation::Validity() is fine. - // nsIConstraintValidation::GetValidationMessage() is fine. - // nsIConstraintValidation::CheckValidity() is fine. - using nsIConstraintValidation::CheckValidity; - // nsIConstraintValidation::SetCustomValidity() is fine. - // XPCOM Select is fine - uint32_t GetSelectionStart(ErrorResult& aError); - void SetSelectionStart(uint32_t aSelectionStart, ErrorResult& aError); - uint32_t GetSelectionEnd(ErrorResult& aError); - void SetSelectionEnd(uint32_t aSelectionEnd, ErrorResult& aError); - void GetSelectionDirection(nsAString& aDirection, ErrorResult& aError); - void SetSelectionDirection(const nsAString& aDirection, ErrorResult& aError); - void SetSelectionRange(uint32_t aSelectionStart, uint32_t aSelectionEnd, const Optional& aDirecton, ErrorResult& aError); - nsIControllers* GetControllers(ErrorResult& aError); - nsIEditor* GetEditor() - { - return mState.GetEditor(); - } - protected: using nsGenericHTMLFormElement::IsSingleLineTextControl; // get rid of the compiler warning - virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope, - bool *aTriedToWrap) MOZ_OVERRIDE; - nsCOMPtr mControllers; /** Whether or not the value has changed since its default value was given. */ bool mValueChanged; diff --git a/content/html/content/src/HTMLTimeElement.cpp b/content/html/content/src/HTMLTimeElement.cpp deleted file mode 100644 index 28a24186a808..000000000000 --- a/content/html/content/src/HTMLTimeElement.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "HTMLTimeElement.h" -#include "mozilla/dom/HTMLTimeElementBinding.h" -#include "nsContentUtils.h" -#include "nsGenericHTMLElement.h" -#include "nsVariant.h" -#include "nsGkAtoms.h" - -NS_IMPL_NS_NEW_HTML_ELEMENT(Time) - -namespace mozilla { -namespace dom { - -HTMLTimeElement::HTMLTimeElement(already_AddRefed aNodeInfo) - : nsGenericHTMLElement(aNodeInfo) -{ - SetIsDOMBinding(); -} - -HTMLTimeElement::~HTMLTimeElement() -{ -} - -NS_IMPL_ADDREF_INHERITED(HTMLTimeElement, Element) -NS_IMPL_RELEASE_INHERITED(HTMLTimeElement, Element) - -NS_INTERFACE_TABLE_HEAD(HTMLTimeElement) - NS_HTML_CONTENT_INTERFACE_TABLE0(HTMLTimeElement) - NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(HTMLTimeElement, - nsGenericHTMLElement) -NS_HTML_CONTENT_INTERFACE_MAP_END - -NS_IMPL_ELEMENT_CLONE(HTMLTimeElement) - -JSObject* -HTMLTimeElement::WrapNode(JSContext* cx, JSObject* scope, bool* triedToWrap) -{ - return HTMLTimeElementBinding::Wrap(cx, scope, this, triedToWrap); -} - -void -HTMLTimeElement::GetItemValueText(nsAString& text) -{ - if (HasAttr(kNameSpaceID_None, nsGkAtoms::datetime)) { - GetDateTime(text); - } else { - GetTextContentInternal(text); - } -} - -void -HTMLTimeElement::SetItemValueText(const nsAString& text) -{ - ErrorResult rv; - SetDateTime(text, rv); -} - -} // namespace dom -} // namespace mozilla diff --git a/content/html/content/src/HTMLTimeElement.h b/content/html/content/src/HTMLTimeElement.h deleted file mode 100644 index f6ff70e3ca5f..000000000000 --- a/content/html/content/src/HTMLTimeElement.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_dom_HTMLTimeElement_h -#define mozilla_dom_HTMLTimeElement_h - -#include "nsIDOMHTMLElement.h" -#include "nsGenericHTMLElement.h" -#include "nsGkAtoms.h" - -namespace mozilla { -namespace dom { - -class HTMLTimeElement MOZ_FINAL : public nsGenericHTMLElement, - public nsIDOMHTMLElement -{ -public: - HTMLTimeElement(already_AddRefed aNodeInfo); - virtual ~HTMLTimeElement(); - - // nsISupports - NS_DECL_ISUPPORTS_INHERITED - - // nsIDOMNode - NS_FORWARD_NSIDOMNODE_TO_NSINODE - - // nsIDOMElement - NS_FORWARD_NSIDOMELEMENT_TO_GENERIC - - // nsIDOMHTMLElement - NS_FORWARD_NSIDOMHTMLELEMENT_TO_GENERIC - - // HTMLTimeElement WebIDL - void GetDateTime(nsAString& aDateTime) - { - GetHTMLAttr(nsGkAtoms::datetime, aDateTime); - } - - void SetDateTime(const nsAString& aDateTime, ErrorResult& aError) - { - SetHTMLAttr(nsGkAtoms::datetime, aDateTime, aError); - } - - virtual void GetItemValueText(nsAString& text); - virtual void SetItemValueText(const nsAString& text); - virtual nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const; - virtual nsIDOMNode* AsDOMNode() { return this; } - -protected: - virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope, - bool* aTriedToWrap) MOZ_OVERRIDE; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_HTMLTimeElement_h diff --git a/content/html/content/src/Makefile.in b/content/html/content/src/Makefile.in index 433fef732da6..cbd25cd098ec 100644 --- a/content/html/content/src/Makefile.in +++ b/content/html/content/src/Makefile.in @@ -72,7 +72,6 @@ EXPORTS_mozilla/dom = \ HTMLTableRowElement.h \ HTMLTableSectionElement.h \ HTMLTextAreaElement.h \ - HTMLTimeElement.h \ HTMLTitleElement.h \ HTMLUnknownElement.h \ UndoManager.h \ @@ -137,7 +136,6 @@ CPPSRCS = \ HTMLTableRowElement.cpp \ HTMLTableSectionElement.cpp \ HTMLTextAreaElement.cpp \ - HTMLTimeElement.cpp \ HTMLTitleElement.cpp \ HTMLUnknownElement.cpp \ ValidityState.cpp \ diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 3bae9173f6ef..64b28ec5a2d7 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -1962,7 +1962,6 @@ NS_DECLARE_NS_NEW_HTML_ELEMENT(Tbody) NS_DECLARE_NS_NEW_HTML_ELEMENT(TextArea) NS_DECLARE_NS_NEW_HTML_ELEMENT(Tfoot) NS_DECLARE_NS_NEW_HTML_ELEMENT(Thead) -NS_DECLARE_NS_NEW_HTML_ELEMENT(Time) NS_DECLARE_NS_NEW_HTML_ELEMENT(Title) NS_DECLARE_NS_NEW_HTML_ELEMENT(Unknown) #if defined(MOZ_MEDIA) diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index 1bdf63dc1630..1551722a41e3 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -3291,7 +3291,7 @@ nsIContent* nsHTMLMediaElement::GetNextSource() nsresult rv = NS_OK; if (!mSourcePointer) { // First time this has been run, create a selection to cover children. - mSourcePointer = new nsRange(this); + mSourcePointer = new nsRange(); rv = mSourcePointer->SelectNodeContents(thisDomNode); if (NS_FAILED(rv)) return nullptr; diff --git a/content/html/content/test/Makefile.in b/content/html/content/test/Makefile.in index 1709bdc65fe3..b43c60020fec 100644 --- a/content/html/content/test/Makefile.in +++ b/content/html/content/test/Makefile.in @@ -279,7 +279,6 @@ MOCHITEST_FILES = \ test_bug803677.html \ test_bug827126.html \ test_bug827426.html \ - test_bug838582.html \ test_bug841466.html \ test_iframe_sandbox_inheritance.html \ file_iframe_sandbox_a_if1.html \ @@ -350,7 +349,6 @@ MOCHITEST_FILES = \ test_mod_attributes_reflection.html \ test_mozaudiochannel.html \ test_style_attributes_reflection.html \ - test_bug629801.html \ $(NULL) diff --git a/content/html/content/test/reflect.js b/content/html/content/test/reflect.js index 68cd3f15874d..a6cbe80ec9dd 100644 --- a/content/html/content/test/reflect.js +++ b/content/html/content/test/reflect.js @@ -58,7 +58,8 @@ function reflectString(aParameters) // TODO: remove this ugly hack when null stringification will work as expected. var todoAttrs = { form: [ "acceptCharset", "name", "target" ], - input: [ "accept", "alt", "formTarget", "max", "min", "name", "pattern", "placeholder", "step", "defaultValue" ] + input: [ "accept", "alt", "formTarget", "max", "min", "name", "pattern", "placeholder", "step", "defaultValue" ], + textarea: [ "name", "placeholder" ] }; if (!(element.localName in todoAttrs) || todoAttrs[element.localName].indexOf(idlAttr) == -1) { is(element.getAttribute(contentAttr), "null", diff --git a/content/html/content/test/test_bug388558.html b/content/html/content/test/test_bug388558.html index 1a3417bbcf7f..eea045cd209a 100644 --- a/content/html/content/test/test_bug388558.html +++ b/content/html/content/test/test_bug388558.html @@ -25,7 +25,7 @@ var textareaChange = 0; function testUserInput() { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var input = document.getElementById("input"); - var textarea = SpecialPowers.wrap(document.getElementById("textarea")); + var textarea = document.getElementById("textarea"); input.focus(); input.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).setUserInput("foo"); @@ -47,7 +47,7 @@ function testUserInput() { "Change event dispatched when input element doesn't have focus."); textarea.focus(); - textarea.setUserInput("foo"); + textarea.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).setUserInput("foo"); textarea.blur(); is(textareaChange, 1, "Textarea element should have got one change event."); @@ -61,7 +61,7 @@ function testUserInput() { is(textareaChange, 1, "Change event dispatched when setting the value of the textarea element (2)."); - textarea.setUserInput("foo"); + textarea.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).setUserInput("foo"); is(textareaChange, 1, "Change event dispatched when textarea element doesn't have focus."); } diff --git a/content/html/content/test/test_bug389797.html b/content/html/content/test/test_bug389797.html index 08c21607ee02..6d658fda4af5 100644 --- a/content/html/content/test/test_bug389797.html +++ b/content/html/content/test/test_bug389797.html @@ -213,7 +213,6 @@ HTML_TAG("textarea", "TextArea", [], [ "nsIDOMNSEditableElement" ]); HTML_TAG("tfoot", "TableSection"); HTML_TAG("th", "TableCell"); HTML_TAG("thead", "TableSection"); -HTML_TAG("time", "Time"); HTML_TAG("title", "Title"); HTML_TAG("tr", "TableRow"); HTML_TAG("tt", ""); @@ -255,6 +254,28 @@ for (var tag of allTags) { is(node instanceof SpecialPowers.Ci[iface], true, tagName(tag) + " does not QI to " + iface); } + + // Now see what classinfo reports + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var nodeClassInfo = SpecialPowers.wrap(node).QueryInterface(SpecialPowers.Ci.nsIClassInfo); + var count = {}; + var classInfoInterfaces = + nodeClassInfo.getInterfaces(count). + map(function(id) { return SpecialPowers.Components.interfacesByID[id].toString(); }); + + // Make sure that we know about all the things classinfo claims + for (var classInfoInterface of classInfoInterfaces) { + isnot(interfaces[tag].indexOf(classInfoInterface), -1, + "Should know about " + tagName(tag) + " implementing " + + classInfoInterface); + } + + // And make sure classinfo claims all the things we know about + for (iface of interfaces[tag]) { + isnot(classInfoInterfaces.indexOf(iface), -1, + "Classinfo for " + tagName(tag) + " should claim to implement " + + iface); + } } diff --git a/content/html/content/test/test_bug629801.html b/content/html/content/test/test_bug629801.html deleted file mode 100644 index cca974df64cc..000000000000 --- a/content/html/content/test/test_bug629801.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - - Test for Bug 629801 - - - - - -Mozilla Bug 629801 -

- -
-
-
- - diff --git a/content/html/content/test/test_bug838582.html b/content/html/content/test/test_bug838582.html deleted file mode 100644 index 5c227c2bdb7b..000000000000 --- a/content/html/content/test/test_bug838582.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - Test for Bug 838582 - - - - - -Mozilla Bug 838582 -

- -
-
-
-
- - diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index ae06bdfb6b76..2f60cd91530c 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -2612,7 +2612,7 @@ nsHTMLDocument::DeferredContentEditableCountChange(nsIContent *aElement) nsCOMPtr editor; docshell->GetEditor(getter_AddRefs(editor)); if (editor) { - nsRefPtr range = new nsRange(aElement); + nsRefPtr range = new nsRange(); rv = range->SelectNode(node); if (NS_FAILED(rv)) { // The node might be detached from the document at this point, diff --git a/content/test/unit/test_range.js b/content/test/unit/test_range.js index f5c5a669e9f4..9cfa647151a0 100644 --- a/content/test/unit/test_range.js +++ b/content/test/unit/test_range.js @@ -363,7 +363,7 @@ function run_miscellaneous_tests() { baseRange.setStart(null, 0); do_throw("Should have thrown NOT_OBJECT_ERR!"); } catch (e) { - do_check_eq(e instanceof TypeError, true); + do_check_eq(e.name, "NS_ERROR_DOM_NOT_OBJECT_ERR"); } // Invalid start node @@ -371,7 +371,7 @@ function run_miscellaneous_tests() { baseRange.setStart({}, 0); do_throw("Should have thrown SecurityError!"); } catch (e) { - do_check_true(e instanceof TypeError); + do_check_eq(e.name, "SecurityError"); } // Invalid index diff --git a/content/xml/content/src/CDATASection.h b/content/xml/content/src/CDATASection.h index f3f005937749..e726b6504bd2 100644 --- a/content/xml/content/src/CDATASection.h +++ b/content/xml/content/src/CDATASection.h @@ -7,17 +7,17 @@ #define mozilla_dom_CDATASection_h #include "nsIDOMCDATASection.h" -#include "mozilla/dom/Text.h" +#include "nsGenericDOMDataNode.h" namespace mozilla { namespace dom { -class CDATASection : public Text, +class CDATASection : public nsGenericDOMDataNode, public nsIDOMCDATASection { public: CDATASection(already_AddRefed aNodeInfo) - : Text(aNodeInfo) + : nsGenericDOMDataNode(aNodeInfo) { NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE, "Bad NodeType in aNodeInfo"); diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 816a49a891e7..e54982d55511 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -6667,6 +6667,19 @@ nsNavigatorSH::PreCreate(nsISupports *nativeObj, JSContext *cx, // DOM Node helper +template +static JSBool +GetterShim(JSContext *cx, JSHandleObject obj, JSHandleId /* unused */, JSMutableHandleValue vp) +{ + nsresult rv = (*func)(cx, obj, vp.address()); + if (NS_FAILED(rv)) { + xpc::Throw(cx, rv); + return JS_FALSE; + } + + return JS_TRUE; +} + NS_IMETHODIMP nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, JSObject **parentObj) @@ -7379,6 +7392,42 @@ nsNamedNodeMapSH::GetNamedItem(nsISupports *aNative, const nsAString& aName, return attr; } +// Can't be static so GetterShim will compile +nsresult +DocumentURIObjectGetter(JSContext *cx, JSObject *obj, jsval *vp) +{ + // This function duplicates some of the logic in XPC_WN_HelperGetProperty + XPCWrappedNative *wrapper = + XPCWrappedNative::GetWrappedNativeOfJSObject(cx, obj); + + // The error checks duplicate code in THROW_AND_RETURN_IF_BAD_WRAPPER + NS_ENSURE_TRUE(!wrapper || wrapper->IsValid(), NS_ERROR_XPC_HAS_BEEN_SHUTDOWN); + + nsCOMPtr doc = do_QueryWrappedNative(wrapper, obj); + NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); + + return WrapNative(cx, JS_GetGlobalForScopeChain(cx), doc->GetDocumentURI(), + &NS_GET_IID(nsIURI), true, vp); +} + +NS_IMETHODIMP +nsDocumentSH::PostCreatePrototype(JSContext * cx, JSObject * proto) +{ + // XXXbz when this goes away, kill GetterShim as well. + // set up our proto first + nsresult rv = nsNodeSH::PostCreatePrototype(cx, proto); + + if (xpc::AccessCheck::isChrome(js::GetObjectCompartment(proto))) { + // Stick a documentURIObject property on there + JS_DefinePropertyById(cx, proto, sDocumentURIObject_id, + JSVAL_VOID, GetterShim, + nullptr, + JSPROP_READONLY | JSPROP_SHARED); + } + + return rv; +} + NS_IMETHODIMP nsDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsid id, uint32_t flags, diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index f98b0bed49dc..cb8e5c62ff4d 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -634,6 +634,7 @@ public: } public: + NS_IMETHOD PostCreatePrototype(JSContext * cx, JSObject * proto); NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsid id, uint32_t flags, JSObject **objp, bool *_retval); diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 4362aaec1205..e29b7591eb13 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -430,15 +430,6 @@ DOMInterfaces = { ] }, -'HTMLTextAreaElement': { - 'resultNotAddRefed': [ - 'form', 'controllers', 'editor' - ], - 'binaryNames': { - 'textLength': 'getTextLength' - } -}, - 'HTMLStyleElement': { 'resultNotAddRefed': [ 'sheet' @@ -582,14 +573,6 @@ DOMInterfaces = { 'resultNotAddRefed': [ 'item' ] }, -'Range': { - 'nativeType': 'nsRange', - 'resultNotAddRefed': [ 'startContainer', 'endContainer', 'commonAncestorContainer' ], - 'binaryNames': { - '__stringifier': 'ToString' - } -}, - 'Rect': { "nativeType": "nsDOMCSSRect", 'resultNotAddRefed': [ "top", "right", "bottom", "left" ] @@ -833,9 +816,7 @@ DOMInterfaces = { }, 'Text': { - # Total hack to allow binding code to realize that nsTextNode can - # in fact be cast to Text. - 'headerFile': 'nsTextNode.h', + 'nativeType': 'nsTextNode', }, 'TextDecoder': [ @@ -1223,11 +1204,11 @@ addExternalIface('NamedNodeMap') addExternalIface('NodeIterator') addExternalIface('nsIStreamListener', nativeType='nsIStreamListener', notflattened=True) addExternalIface('nsISupports', nativeType='nsISupports') -addExternalIface('nsIEditor', nativeType='nsIEditor', notflattened=True) addExternalIface('OutputStream', nativeType='nsIOutputStream', notflattened=True) addExternalIface('Principal', nativeType='nsIPrincipal', headerFile='nsIPrincipal.h', notflattened=True) +addExternalIface('Range', nativeType='nsRange') addExternalIface('Selection', nativeType='nsISelection') addExternalIface('StyleSheet', nativeType='nsIStyleSheet') addExternalIface('StyleSheetList') diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index bd446138adc4..20a504e529d2 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -1819,18 +1819,6 @@ def InitUnforgeableProperties(descriptor, properties): "// finalizer trying to drop its ownership of the C++ object.\n"), post="\n")).define() if len(unforgeables) > 0 else "" -def AssertInheritanceChain(descriptor): - asserts = "" - iface = descriptor.interface - while iface: - desc = descriptor.getDescriptor(iface.identifier.name) - asserts += ( - " MOZ_ASSERT(static_cast<%s*>(aObject) == \n" - " reinterpret_cast<%s*>(aObject));\n" % - (desc.nativeType, desc.nativeType)) - iface = iface.parent - return asserts - class CGWrapWithCacheMethod(CGAbstractMethod): """ Create a wrapper JSObject for a given native that implements nsWrapperCache. @@ -1851,8 +1839,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod): return """ *aTriedToWrap = true; return aObject->GetJSObject();""" - return """%s - *aTriedToWrap = true; + return """ *aTriedToWrap = true; JSObject* parent = WrapNativeParent(aCx, aScope, aObject->GetParentObject()); if (!parent) { @@ -1881,8 +1868,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod): %s aCache->SetWrapper(obj); - return obj;""" % (AssertInheritanceChain(self.descriptor), - CheckPref(self.descriptor, "global", "*aTriedToWrap", "NULL", "aCache"), + return obj;""" % (CheckPref(self.descriptor, "global", "*aTriedToWrap", "NULL", "aCache"), CreateBindingJSObject(self.descriptor, "parent"), InitUnforgeableProperties(self.descriptor, self.properties)) @@ -1913,7 +1899,7 @@ class CGWrapNonWrapperCacheMethod(CGAbstractMethod): self.properties = properties def definition_body(self): - return """%s + return """ JSObject* global = JS_GetGlobalForObject(aCx, aScope); JSObject* proto = GetProtoObject(aCx, global); if (!proto) { @@ -1922,8 +1908,7 @@ class CGWrapNonWrapperCacheMethod(CGAbstractMethod): %s %s - return obj;""" % (AssertInheritanceChain(self.descriptor), - CreateBindingJSObject(self.descriptor, "global"), + return obj;""" % (CreateBindingJSObject(self.descriptor, "global"), InitUnforgeableProperties(self.descriptor, self.properties)) builtinNames = { diff --git a/dom/imptests/failures/html/old-tests/submission/Opera/microdata/test_001.html.json b/dom/imptests/failures/html/old-tests/submission/Opera/microdata/test_001.html.json index 1cee5fb2bbc3..dd4c63403d68 100644 --- a/dom/imptests/failures/html/old-tests/submission/Opera/microdata/test_001.html.json +++ b/dom/imptests/failures/html/old-tests/submission/Opera/microdata/test_001.html.json @@ -1,3 +1,5 @@ { - "itemValue must reflect the src attribute on track elements": true + "itemValue must reflect the src attribute on track elements": true, + "itemValue must reflect the dateTime attribute of time elements with no datetime attribute": true, + "itemValue must reflect the datetime attribute of time elements with a datetime attribute": true } diff --git a/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json b/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json index 991047f70cb9..43dc2efd5c86 100644 --- a/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json +++ b/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json @@ -92,6 +92,45 @@ "CharacterData interface: document.createTextNode(\"abc\") must inherit property \"remove\" with the proper type (7)": true, "CharacterData interface: xmlDoc.createProcessingInstruction(\"abc\", \"def\") must inherit property \"remove\" with the proper type (7)": true, "CharacterData interface: document.createComment(\"abc\") must inherit property \"remove\" with the proper type (7)": true, + "Range interface: existence and properties of interface object": true, + "Range interface: existence and properties of interface prototype object": true, + "Range interface: existence and properties of interface prototype object's \"constructor\" property": true, + "Range interface: attribute startContainer": true, + "Range interface: attribute startOffset": true, + "Range interface: attribute endContainer": true, + "Range interface: attribute endOffset": true, + "Range interface: attribute collapsed": true, + "Range interface: attribute commonAncestorContainer": true, + "Range interface: calling setStart(Node,unsigned long) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling setEnd(Node,unsigned long) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling setStartBefore(Node) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling setStartAfter(Node) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling setEndBefore(Node) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling setEndAfter(Node) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling collapse(boolean) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling selectNode(Node) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling selectNodeContents(Node) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling compareBoundaryPoints(unsigned short,Range) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling insertNode(Node) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling surroundContents(Node) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling isPointInRange(Node,unsigned long) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling comparePoint(Node,unsigned long) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling intersectsNode(Node) on document.createRange() with too few arguments must throw TypeError": true, + "Range interface: calling setStart(Node,unsigned long) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling setEnd(Node,unsigned long) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling setStartBefore(Node) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling setStartAfter(Node) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling setEndBefore(Node) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling setEndAfter(Node) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling collapse(boolean) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling selectNode(Node) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling selectNodeContents(Node) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling compareBoundaryPoints(unsigned short,Range) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling insertNode(Node) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling surroundContents(Node) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling isPointInRange(Node,unsigned long) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling comparePoint(Node,unsigned long) on detachedRange with too few arguments must throw TypeError": true, + "Range interface: calling intersectsNode(Node) on detachedRange with too few arguments must throw TypeError": true, "NodeIterator interface: existence and properties of interface object": true, "NodeIterator interface: existence and properties of interface prototype object": true, "NodeIterator interface: existence and properties of interface prototype object's \"constructor\" property": true, diff --git a/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/Makefile.in b/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/Makefile.in index 840112e07906..99612af5a7bc 100644 --- a/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/Makefile.in +++ b/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/Makefile.in @@ -29,6 +29,7 @@ MOCHITEST_FILES := \ test_Range-commonAncestorContainer.html.json \ test_Range-comparePoint.html.json \ test_Range-detach.html.json \ + test_Range-intersectsNode-binding.html.json \ test_attributes.html.json \ test_case.html.json \ test_historical.html.json \ diff --git a/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/test_Range-comparePoint.html.json b/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/test_Range-comparePoint.html.json index d7d8b443a70e..456283f7ac70 100644 --- a/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/test_Range-comparePoint.html.json +++ b/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/test_Range-comparePoint.html.json @@ -1,3 +1,4 @@ { - "Range.comparePoint": true + "Range.comparePoint": true, + "Range.comparePoint 1": true } diff --git a/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/test_Range-intersectsNode-binding.html.json b/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/test_Range-intersectsNode-binding.html.json new file mode 100644 index 000000000000..fdfba98df306 --- /dev/null +++ b/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/test_Range-intersectsNode-binding.html.json @@ -0,0 +1,3 @@ +{ + "Calling intersectsNode without an argument or with an invalid argument should throw a TypeError.": true +} diff --git a/dom/interfaces/core/nsIDOMDocumentFragment.idl b/dom/interfaces/core/nsIDOMDocumentFragment.idl index d9d9cca4c65f..4b51c7bde842 100644 --- a/dom/interfaces/core/nsIDOMDocumentFragment.idl +++ b/dom/interfaces/core/nsIDOMDocumentFragment.idl @@ -14,7 +14,7 @@ * http://www.w3.org/TR/DOM-Level-2-Core/ */ -[scriptable, builtinclass, uuid(4a15eb0c-d5bc-4902-9d50-21b12cab47e7)] +[scriptable, uuid(4a15eb0c-d5bc-4902-9d50-21b12cab47e7)] interface nsIDOMDocumentFragment : nsIDOMNode { }; diff --git a/dom/interfaces/core/nsIDOMNSEditableElement.idl b/dom/interfaces/core/nsIDOMNSEditableElement.idl index 91aad0853d4c..cd244741986d 100644 --- a/dom/interfaces/core/nsIDOMNSEditableElement.idl +++ b/dom/interfaces/core/nsIDOMNSEditableElement.idl @@ -9,11 +9,8 @@ interface nsIEditor; /** * This interface is implemented by elements which have inner editable content, - * such as HTML input and textarea. - * - * Please make sure to update the HTMLTextAreaElement Web IDL interface to - * mirror this interface when changing it. - */ + * such as HTML input and textarea. +*/ [scriptable, uuid(b33eb56c-3120-418c-892b-774b00c7dde8)] interface nsIDOMNSEditableElement : nsISupports diff --git a/dom/interfaces/html/nsIDOMHTMLTextAreaElement.idl b/dom/interfaces/html/nsIDOMHTMLTextAreaElement.idl index 56cb4add443a..cedceaff7d72 100644 --- a/dom/interfaces/html/nsIDOMHTMLTextAreaElement.idl +++ b/dom/interfaces/html/nsIDOMHTMLTextAreaElement.idl @@ -60,7 +60,5 @@ interface nsIDOMHTMLTextAreaElement : nsIDOMHTMLElement // Mozilla extensions - // Please make sure to update the HTMLTextAreaElement Web IDL interface to - // mirror the list of Mozilla extensions here when changing it. readonly attribute nsIControllers controllers; }; diff --git a/dom/plugins/test/mochitest/test_copyText.html b/dom/plugins/test/mochitest/test_copyText.html index 032c94c27f31..55f2a6a0da4f 100644 --- a/dom/plugins/test/mochitest/test_copyText.html +++ b/dom/plugins/test/mochitest/test_copyText.html @@ -15,7 +15,8 @@ function runTests() { textElt.focus(); textElt.value = text; textElt.select(); - SpecialPowers.wrap(textElt).editor.copy(); + textElt.QueryInterface(Components.interfaces.nsIDOMNSEditableElement) + .editor.copy(); is(plugin.getClipboardText(), text); diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index 5f23a0e1a9bc..003ef1d0c17e 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -18,6 +18,7 @@ interface Attr; interface Comment; interface NodeIterator; +interface Range; interface StyleSheetList; interface Touch; interface TouchList; @@ -203,9 +204,6 @@ partial interface Document { void mozSetImageElement(DOMString aImageElementId, Element? aImageElement); - [ChromeOnly] - readonly attribute URI? documentURIObject; - }; // http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html#api diff --git a/dom/webidl/HTMLTextAreaElement.webidl b/dom/webidl/HTMLTextAreaElement.webidl deleted file mode 100644 index 2a87589016ae..000000000000 --- a/dom/webidl/HTMLTextAreaElement.webidl +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * The origin of this IDL file is - * http://www.whatwg.org/specs/web-apps/current-work/#the-textarea-element - * http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis - * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and - * Opera Software ASA. You are granted a license to use, reproduce - * and create derivative works of this document. - */ - -interface nsIEditor; -interface MozControllers; - -interface HTMLTextAreaElement : HTMLElement { - // attribute DOMString autocomplete; - [SetterThrows, Pure] - attribute boolean autofocus; - [SetterThrows, Pure] - attribute unsigned long cols; - // attribute DOMString dirName; - [SetterThrows, Pure] - attribute boolean disabled; - [Pure] - readonly attribute HTMLFormElement? form; - // attribute DOMString inputMode; - [SetterThrows, Pure] - attribute long maxLength; - [SetterThrows, Pure] - attribute DOMString name; - [SetterThrows, Pure] - attribute DOMString placeholder; - [SetterThrows, Pure] - attribute boolean readOnly; - [SetterThrows, Pure] - attribute boolean required; - [SetterThrows, Pure] - attribute unsigned long rows; - [SetterThrows, Pure] - attribute DOMString wrap; - - [Constant] - readonly attribute DOMString type; - [SetterThrows, Pure] - attribute DOMString defaultValue; - [TreatNullAs=EmptyString] attribute DOMString value; - readonly attribute unsigned long textLength; - - readonly attribute boolean willValidate; - readonly attribute ValidityState validity; - readonly attribute DOMString validationMessage; - boolean checkValidity(); - void setCustomValidity(DOMString error); - - // readonly attribute NodeList labels; - - void select(); - [Throws] - attribute unsigned long selectionStart; - [Throws] - attribute unsigned long selectionEnd; - [Throws] - attribute DOMString selectionDirection; - // void setRangeText(DOMString replacement); - // void setRangeText(DOMString replacement, unsigned long start, unsigned long end, optional SelectionMode selectionMode); - [Throws] - void setSelectionRange(unsigned long start, unsigned long end, optional DOMString direction); -}; - -partial interface HTMLTextAreaElement { - // Mirrored chrome-only Mozilla extensions to nsIDOMHTMLTextAreaElement. - // Please make sure to update this list of nsIDOMHTMLTextAreaElement changes. - - [Throws, ChromeOnly] - readonly attribute MozControllers controllers; -}; - -partial interface HTMLTextAreaElement { - // Mirrored chrome-only nsIDOMNSEditableElement methods. Please make sure - // to update this list if nsIDOMNSEditableElement changes. - - [ChromeOnly] - readonly attribute nsIEditor? editor; - - // This is similar to set .value on nsIDOMInput/TextAreaElements, but - // handling of the value change is closer to the normal user input, so - // 'change' event for example will be dispatched when focusing out the - // element. - [ChromeOnly] - void setUserInput(DOMString input); -}; diff --git a/dom/webidl/HTMLTimeElement.webidl b/dom/webidl/HTMLTimeElement.webidl deleted file mode 100644 index 517ca9981eeb..000000000000 --- a/dom/webidl/HTMLTimeElement.webidl +++ /dev/null @@ -1,13 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. - * - * The origin of this IDL file is - * http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-time-element - */ - -interface HTMLTimeElement : HTMLElement { - [SetterThrows] - attribute DOMString dateTime; -}; diff --git a/dom/webidl/Range.webidl b/dom/webidl/Range.webidl index 6db93d70aca0..9df9468117ad 100644 --- a/dom/webidl/Range.webidl +++ b/dom/webidl/Range.webidl @@ -4,87 +4,49 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. * * The origin of this IDL file is - * http://dom.spec.whatwg.org/#range - * http://domparsing.spec.whatwg.org/#dom-range-createcontextualfragment - * http://dvcs.w3.org/hg/csswg/raw-file/tip/cssom-view/Overview.html#extensions-to-the-range-interface + * http://www.w3.org/TR/2012/WD-dom-20120105/ * * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C * liability, trademark and document use rules apply. */ -interface ClientRect; - interface Range { - [Throws] readonly attribute Node startContainer; - [Throws] readonly attribute unsigned long startOffset; - [Throws] readonly attribute Node endContainer; - [Throws] readonly attribute unsigned long endOffset; readonly attribute boolean collapsed; - [Throws] readonly attribute Node commonAncestorContainer; - [Throws] void setStart(Node refNode, unsigned long offset); - [Throws] void setEnd(Node refNode, unsigned long offset); - [Throws] void setStartBefore(Node refNode); - [Throws] void setStartAfter(Node refNode); - [Throws] void setEndBefore(Node refNode); - [Throws] void setEndAfter(Node refNode); void collapse(boolean toStart); - [Throws] void selectNode(Node refNode); - [Throws] void selectNodeContents(Node refNode); const unsigned short START_TO_START = 0; const unsigned short START_TO_END = 1; const unsigned short END_TO_END = 2; const unsigned short END_TO_START = 3; - [Throws] short compareBoundaryPoints(unsigned short how, Range sourceRange); - [Throws] + void deleteContents(); - [Throws] DocumentFragment extractContents(); - [Throws] DocumentFragment cloneContents(); - [Throws] void insertNode(Node node); - [Throws] void surroundContents(Node newParent); Range cloneRange(); void detach(); - [Throws] boolean isPointInRange(Node node, unsigned long offset); - [Throws] short comparePoint(Node node, unsigned long offset); - [Throws] boolean intersectsNode(Node node); stringifier; }; - -// http://domparsing.spec.whatwg.org/#dom-range-createcontextualfragment -partial interface Range { - [Throws] - DocumentFragment createContextualFragment(DOMString fragment); -}; - -// http://dvcs.w3.org/hg/csswg/raw-file/tip/cssom-view/Overview.html#extensions-to-the-range-interface -partial interface Range { - [Throws] - ClientRectList getClientRects(); - ClientRect getBoundingClientRect(); -}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index ea40ea4282d8..12f18a20ced0 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -108,8 +108,6 @@ webidl_files = \ HTMLTableElement.webidl \ HTMLTableRowElement.webidl \ HTMLTableSectionElement.webidl \ - HTMLTextAreaElement.webidl \ - HTMLTimeElement.webidl \ HTMLTitleElement.webidl \ HTMLUListElement.webidl \ ImageData.webidl \ @@ -128,7 +126,6 @@ webidl_files = \ PerformanceNavigation.webidl \ PerformanceTiming.webidl \ ProcessingInstruction.webidl \ - Range.webidl \ Rect.webidl \ RGBColor.webidl \ RTCConfiguration.webidl \ diff --git a/editor/composer/test/test_bug338427.html b/editor/composer/test/test_bug338427.html index f31ef23f04f6..ccd647bb0afe 100644 --- a/editor/composer/test/test_bug338427.html +++ b/editor/composer/test/test_bug338427.html @@ -21,7 +21,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338427 /** Test for Bug 338427 **/ function init() { var textarea = document.getElementById("editor"); - var editor = textarea.editor; + var editor = textarea.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor; var spellchecker = editor.getInlineSpellChecker(true); spellchecker.enableRealTimeSpell = true; diff --git a/editor/libeditor/base/IMETextTxn.cpp b/editor/libeditor/base/IMETextTxn.cpp index b8398233c920..d229c0d45192 100644 --- a/editor/libeditor/base/IMETextTxn.cpp +++ b/editor/libeditor/base/IMETextTxn.cpp @@ -314,13 +314,8 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) if(NS_FAILED(result)) break; - nsCOMPtr content = do_QueryInterface(mElement); - if (!content) { - break; - } - - nsRefPtr newRange = new nsRange(content); - result = newRange->SetStart(content, mOffset+selectionStart); + nsRefPtr newRange = new nsRange(); + result = newRange->SetStart(mElement,mOffset+selectionStart); NS_ASSERTION(NS_SUCCEEDED(result), "Cannot SetStart"); if(NS_FAILED(result)) break; diff --git a/editor/libeditor/base/nsEditPropertyAtomList.h b/editor/libeditor/base/nsEditPropertyAtomList.h index 6d45f5a407db..eb9a6f132f88 100644 --- a/editor/libeditor/base/nsEditPropertyAtomList.h +++ b/editor/libeditor/base/nsEditPropertyAtomList.h @@ -150,7 +150,6 @@ EDITOR_ATOM(textarea, "textarea") EDITOR_ATOM(tfoot, "tfoot") EDITOR_ATOM(thead, "thead") EDITOR_ATOM(th, "th") -EDITOR_ATOM(time, "time") EDITOR_ATOM(tr, "tr") EDITOR_ATOM(tt, "tt") EDITOR_ATOM(ul, "ul") diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index c2768b58cb5e..71bf07da6b50 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -248,26 +248,20 @@ nsHTMLEditRules::Init(nsPlaintextEditor *aEditor) mReturnInEmptyLIKillsList = !returnInEmptyLIKillsList.EqualsLiteral("false"); // make a utility range for use by the listenter - nsCOMPtr node = mHTMLEditor->GetRoot(); - if (!node) { - node = mHTMLEditor->GetDocument(); - } - - NS_ENSURE_STATE(node); - - mUtilRange = new nsRange(node); + mUtilRange = new nsRange(); // set up mDocChangeRange to be whole doc - // temporarily turn off rules sniffing - nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this); - if (!mDocChangeRange) { - mDocChangeRange = new nsRange(node); - } - - if (node->IsElement()) { - ErrorResult rv; - mDocChangeRange->SelectNode(*node, rv); - res = AdjustSpecialBreaks(node); + nsCOMPtr rootElem = do_QueryInterface(mHTMLEditor->GetRoot()); + if (rootElem) + { + // temporarily turn off rules sniffing + nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this); + if (!mDocChangeRange) + { + mDocChangeRange = new nsRange(); + } + mDocChangeRange->SelectNode(rootElem); + res = AdjustSpecialBreaks(); NS_ENSURE_SUCCESS(res, res); } @@ -1447,9 +1441,7 @@ nsHTMLEditRules::WillInsertText(EditAction aAction, // the correct portion of the document. if (!mDocChangeRange) { - nsCOMPtr node = do_QueryInterface(selNode); - NS_ENSURE_STATE(node); - mDocChangeRange = new nsRange(node); + mDocChangeRange = new nsRange(); } res = mDocChangeRange->SetStart(selNode, selOffset); NS_ENSURE_SUCCESS(res, res); @@ -5078,9 +5070,7 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection) bool nodeBefore=false, nodeAfter=false; // create a range that represents expanded selection - nsCOMPtr node = do_QueryInterface(selStartNode); - NS_ENSURE_STATE(node); - nsRefPtr range = new nsRange(node); + nsRefPtr range = new nsRange(); res = range->SetStart(selStartNode, selStartOffset); NS_ENSURE_SUCCESS(res, res); res = range->SetEnd(selEndNode, selEndOffset); @@ -6127,9 +6117,7 @@ nsHTMLEditRules::GetNodesFromPoint(DOMPoint point, point.GetPoint(node, offset); // use it to make a range - nsCOMPtr nativeNode = do_QueryInterface(node); - NS_ENSURE_STATE(nativeNode); - nsRefPtr range = new nsRange(nativeNode); + nsRefPtr range = new nsRange(); res = range->SetStart(node, offset); NS_ENSURE_SUCCESS(res, res); /* SetStart() will also set the end for this new range @@ -7309,9 +7297,7 @@ nsHTMLEditRules::PinSelectionToNewBlock(nsISelection *aSelection) temp = selNode; // use ranges and sRangeHelper to compare sel point to new block - nsCOMPtr node = do_QueryInterface(selNode); - NS_ENSURE_STATE(node); - nsRefPtr range = new nsRange(node); + nsRefPtr range = new nsRange(); res = range->SetStart(selNode, selOffset); NS_ENSURE_SUCCESS(res, res); res = range->SetEnd(selNode, selOffset); diff --git a/editor/libeditor/html/nsHTMLEditUtils.cpp b/editor/libeditor/html/nsHTMLEditUtils.cpp index add644cd8847..854eb5031f49 100644 --- a/editor/libeditor/html/nsHTMLEditUtils.cpp +++ b/editor/libeditor/html/nsHTMLEditUtils.cpp @@ -750,7 +750,6 @@ static const nsElementInfo kElements[eHTMLTag_userdefined] = { ELEM(tfoot, true, false, GROUP_NONE, GROUP_TBODY_CONTENT), ELEM(th, true, false, GROUP_TR_CONTENT, GROUP_FLOW_ELEMENT), ELEM(thead, true, false, GROUP_NONE, GROUP_TBODY_CONTENT), - ELEM(time, true, false, GROUP_PHRASE, GROUP_INLINE_ELEMENT), ELEM(title, true, false, GROUP_HEAD_CONTENT, GROUP_LEAF), ELEM(tr, true, false, GROUP_TBODY_CONTENT, GROUP_TR_CONTENT), ELEM(tt, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT), diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 1f9060b796f3..dfcf318fa8ac 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -3254,7 +3254,7 @@ nsHTMLEditor::ContentInserted(nsIDocument *aDocument, nsIContent* aContainer, // Update spellcheck for only the newly-inserted node (bug 743819) if (mInlineSpellChecker) { - nsRefPtr range = new nsRange(aChild); + nsRefPtr range = new nsRange(); nsresult res = range->Set(aContainer, aIndexInContainer, aContainer, aIndexInContainer + 1); if (NS_SUCCEEDED(res)) { diff --git a/editor/libeditor/html/nsWSRunObject.cpp b/editor/libeditor/html/nsWSRunObject.cpp index 2e5265c0bf41..f42c469bcc67 100644 --- a/editor/libeditor/html/nsWSRunObject.cpp +++ b/editor/libeditor/html/nsWSRunObject.cpp @@ -1484,10 +1484,8 @@ nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, int32_t aStartOffset, { if (!range) { - nsCOMPtr startNode = do_QueryInterface(aStartNode); - NS_ENSURE_STATE(startNode); - range = new nsRange(startNode); - res = range->SetStart(startNode, aStartOffset); + range = new nsRange(); + res = range->SetStart(aStartNode, aStartOffset); NS_ENSURE_SUCCESS(res, res); res = range->SetEnd(aEndNode, aEndOffset); NS_ENSURE_SUCCESS(res, res); diff --git a/editor/libeditor/html/tests/test_bug629845.html b/editor/libeditor/html/tests/test_bug629845.html index 9eb24f904a60..49c902b88be9 100644 --- a/editor/libeditor/html/tests/test_bug629845.html +++ b/editor/libeditor/html/tests/test_bug629845.html @@ -26,12 +26,10 @@ function command(aName) { var frame = document.getElementsByTagName('iframe')[0]; - is(frame.contentDocument.designMode, "on", "design mode should be on!"); var caught = false; try { frame.contentDocument.execCommand(aName, false, null); } catch (e) { - ok(false, "exception " + e + " was thrown"); caught = true; } diff --git a/editor/libeditor/text/tests/test_bug596333.html b/editor/libeditor/text/tests/test_bug596333.html index 8b0833597807..908aab08882b 100644 --- a/editor/libeditor/text/tests/test_bug596333.html +++ b/editor/libeditor/text/tests/test_bug596333.html @@ -27,7 +27,9 @@ addLoadEvent(function() SimpleTest.executeSoon(runTest)); var gMisspeltWords; function getEditor() { - return SpecialPowers.wrap(document.getElementById("edit")).editor; + return document.getElementById("edit") + .QueryInterface(Ci.nsIDOMNSEditableElement) + .editor; } function getSpellCheckSelection() { diff --git a/editor/libeditor/text/tests/test_texteditor_keyevent_handling.html b/editor/libeditor/text/tests/test_texteditor_keyevent_handling.html index 400273e5c9b0..3de76db4a3da 100644 --- a/editor/libeditor/text/tests/test_texteditor_keyevent_handling.html +++ b/editor/libeditor/text/tests/test_texteditor_keyevent_handling.html @@ -427,7 +427,7 @@ function runTests() textarea.removeAttribute("readonly"); const nsIPlaintextEditor = Components.interfaces.nsIPlaintextEditor; const nsIDOMNSEditableElement = Components.interfaces.nsIDOMNSEditableElement; - var editor = SpecialPowers.wrap(textarea).editor; + var editor = textarea.QueryInterface(nsIDOMNSEditableElement).editor; var flags = editor.flags; editor.flags = flags & ~(nsIPlaintextEditor.eEditorWidgetMask | nsIPlaintextEditor.eEditorAllowInteraction); diff --git a/editor/txtsvc/src/nsFilteredContentIterator.cpp b/editor/txtsvc/src/nsFilteredContentIterator.cpp index ed8ab35e955e..95c9218f5cdb 100644 --- a/editor/txtsvc/src/nsFilteredContentIterator.cpp +++ b/editor/txtsvc/src/nsFilteredContentIterator.cpp @@ -57,14 +57,13 @@ NS_IMPL_CYCLE_COLLECTION_5(nsFilteredContentIterator, nsresult nsFilteredContentIterator::Init(nsINode* aRoot) { - NS_ENSURE_ARG_POINTER(aRoot); NS_ENSURE_TRUE(mPreIterator, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE); mIsOutOfRange = false; mDirection = eForward; mCurrentIterator = mPreIterator; - mRange = new nsRange(aRoot); + mRange = new nsRange(); nsCOMPtr domNode(do_QueryInterface(aRoot)); if (domNode) { mRange->SelectNode(domNode); diff --git a/editor/txtsvc/src/nsTextServicesDocument.cpp b/editor/txtsvc/src/nsTextServicesDocument.cpp index 343c57e75060..a7a636e648f0 100644 --- a/editor/txtsvc/src/nsTextServicesDocument.cpp +++ b/editor/txtsvc/src/nsTextServicesDocument.cpp @@ -2070,10 +2070,7 @@ nsTextServicesDocument::CreateDocumentContentRange(nsIDOMRange **aRange) NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER); - nsCOMPtr nativeNode = do_QueryInterface(node); - NS_ENSURE_STATE(nativeNode); - - nsRefPtr range = new nsRange(nativeNode); + nsRefPtr range = new nsRange(); rv = range->SelectNodeContents(node); NS_ENSURE_SUCCESS(rv, rv); diff --git a/embedding/components/find/src/nsFind.cpp b/embedding/components/find/src/nsFind.cpp index 0c550ed6bea3..47152786c761 100644 --- a/embedding/components/find/src/nsFind.cpp +++ b/embedding/components/find/src/nsFind.cpp @@ -147,8 +147,6 @@ nsresult nsFindContentIterator::Init(nsIDOMNode* aStartNode, int32_t aStartOffset, nsIDOMNode* aEndNode, int32_t aEndOffset) { - NS_ENSURE_ARG_POINTER(aStartNode); - NS_ENSURE_ARG_POINTER(aEndNode); if (!mOuterIterator) { if (mFindBackward) { // Use post-order in the reverse case, so we get parents @@ -276,10 +274,7 @@ nsFindContentIterator::Reset() // Note: OK to just set up the outer iterator here; if our range has a native // anonymous endpoint we'll end up setting up an inner iterator, and // reset the outer one in the process. - nsCOMPtr node = do_QueryInterface(mStartNode); - NS_ENSURE_TRUE_VOID(node); - - nsCOMPtr range = nsFind::CreateRange(node); + nsCOMPtr range = nsFind::CreateRange(); range->SetStart(mStartNode, mStartOffset); range->SetEnd(mEndNode, mEndOffset); mOuterIterator->Init(range); @@ -371,9 +366,10 @@ nsFindContentIterator::SetupInnerIterator(nsIContent* aContent) nsCOMPtr rootElement; editor->GetRootElement(getter_AddRefs(rootElement)); + nsCOMPtr rootContent(do_QueryInterface(rootElement)); - nsCOMPtr innerRange = nsFind::CreateRange(aContent); - nsCOMPtr outerRange = nsFind::CreateRange(aContent); + nsCOMPtr innerRange = nsFind::CreateRange(); + nsCOMPtr outerRange = nsFind::CreateRange(); if (!innerRange || !outerRange) { return; } @@ -1145,7 +1141,7 @@ nsFind::Find(const PRUnichar *aPatText, nsIDOMRange* aSearchRange, // Make the range: nsCOMPtr startParent; nsCOMPtr endParent; - nsCOMPtr range = CreateRange(tc); + nsCOMPtr range = CreateRange(); if (range) { int32_t matchStartOffset, matchEndOffset; @@ -1259,9 +1255,9 @@ nsFind::Find(const PRUnichar *aPatText, nsIDOMRange* aSearchRange, /* static */ already_AddRefed -nsFind::CreateRange(nsINode* aNode) +nsFind::CreateRange() { - nsRefPtr range = new nsRange(aNode); + nsRefPtr range = new nsRange(); range->SetMaySpanAnonymousSubtrees(true); return range.forget(); } diff --git a/embedding/components/find/src/nsFind.h b/embedding/components/find/src/nsFind.h index 8f3f43de73f6..3626cc8f2079 100644 --- a/embedding/components/find/src/nsFind.h +++ b/embedding/components/find/src/nsFind.h @@ -35,7 +35,7 @@ public: nsFind(); virtual ~nsFind(); - static already_AddRefed CreateRange(nsINode* aNode); + static already_AddRefed CreateRange(); protected: // Parameters set from the interface: diff --git a/embedding/components/find/src/nsWebBrowserFind.cpp b/embedding/components/find/src/nsWebBrowserFind.cpp index d5b6f175d6d6..98570050f1b4 100644 --- a/embedding/components/find/src/nsWebBrowserFind.cpp +++ b/embedding/components/find/src/nsWebBrowserFind.cpp @@ -727,11 +727,11 @@ nsresult nsWebBrowserFind::SearchInFrame(nsIDOMWindow* aWindow, GetFrameSelection(aWindow, getter_AddRefs(sel)); NS_ENSURE_ARG_POINTER(sel); - nsCOMPtr searchRange = nsFind::CreateRange(theDoc); + nsCOMPtr searchRange = nsFind::CreateRange(); NS_ENSURE_ARG_POINTER(searchRange); - nsCOMPtr startPt = nsFind::CreateRange(theDoc); + nsCOMPtr startPt = nsFind::CreateRange(); NS_ENSURE_ARG_POINTER(startPt); - nsCOMPtr endPt = nsFind::CreateRange(theDoc); + nsCOMPtr endPt = nsFind::CreateRange(); NS_ENSURE_ARG_POINTER(endPt); nsCOMPtr foundRange; diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.cpp b/extensions/spellcheck/src/mozInlineSpellChecker.cpp index c7c88344202a..885be2b516c9 100644 --- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp +++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp @@ -132,10 +132,7 @@ mozInlineSpellStatus::InitForEditorChange( mOp = eOpChange; // range to check - nsCOMPtr prevNode = do_QueryInterface(aPreviousNode); - NS_ENSURE_STATE(prevNode); - - mRange = new nsRange(prevNode); + mRange = new nsRange(); // ...we need to put the start and end in the correct order int16_t cmpResult; diff --git a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp index a7e73f333e33..cc90e6aea697 100644 --- a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp +++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp @@ -317,11 +317,10 @@ nsresult mozInlineSpellWordUtil::MakeRange(NodeOffset aBegin, NodeOffset aEnd, nsRange** aRange) { - NS_ENSURE_ARG_POINTER(aBegin.mNode); if (!mDOMDocument) return NS_ERROR_NOT_INITIALIZED; - nsRefPtr range = new nsRange(aBegin.mNode); + nsRefPtr range = new nsRange(); nsresult rv = range->Set(aBegin.mNode, aBegin.mOffset, aEnd.mNode, aEnd.mOffset); NS_ENSURE_SUCCESS(rv, rv); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 525c4d87ee83..ff2edbb31522 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -948,14 +948,7 @@ nsPresContext::Init(nsDeviceContext* aDeviceContext) nsCOMPtr parentItem; ourItem->GetSameTypeParent(getter_AddRefs(parentItem)); if (parentItem) { - Element* containingElement = - parent->FindContentForSubDocument(mDocument); - if (!containingElement->IsXUL() || - !containingElement-> - HasAttr(kNameSpaceID_None, - nsGkAtoms::forceOwnRefreshDriver)) { - mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver(); - } + mRefreshDriver = parent->GetShell()->GetPresContext()->RefreshDriver(); } } } diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 7658d5d7e712..c9ba6ce93600 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -2903,7 +2903,7 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll) // Even if select anchor pref is false, we must still move the // caret there. That way tabbing will start from the new // location - nsRefPtr jumpToRange = new nsRange(mDocument); + nsRefPtr jumpToRange = new nsRange(); while (content && content->GetFirstChild()) { content = content->GetFirstChild(); } @@ -4804,7 +4804,7 @@ PresShell::RenderNode(nsIDOMNode* aNode, if (!node->IsInDoc()) return nullptr; - nsRefPtr range = new nsRange(node); + nsRefPtr range = new nsRange(); if (NS_FAILED(range->SelectNode(aNode))) return nullptr; diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 69d8505b91e6..df30bc2b13a9 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -778,7 +778,7 @@ nsTextControlFrame::SetSelectionInternal(nsIDOMNode *aStartNode, // Note that we use a new range to avoid having to do // isIncreasing checks to avoid possible errors. - nsRefPtr range = new nsRange(mContent); + nsRefPtr range = new nsRange(); nsresult rv = range->SetStart(aStartNode, aStartOffset); NS_ENSURE_SUCCESS(rv, rv); diff --git a/layout/forms/test/test_bug595310.html b/layout/forms/test/test_bug595310.html index 2491c367d69f..73ccfd251e32 100644 --- a/layout/forms/test/test_bug595310.html +++ b/layout/forms/test/test_bug595310.html @@ -30,7 +30,7 @@ addLoadEvent(function() { var content = document.getElementById('content'); var i = document.getElementById('i'); - var t = SpecialPowers.wrap(document.getElementById('t')); + var t = document.getElementById('t'); i.value = ""; i.placeholder = "foo"; t.value = ""; t.placeholder = "foo"; diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index 6dd3aaf6a69d..def526467164 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -1469,7 +1469,7 @@ nsFrameSelection::TakeFocus(nsIContent *aNewFocus, // non-anchor/focus collapsed ranges. mDomSelections[index]->RemoveCollapsedRanges(); - nsRefPtr newRange = new nsRange(aNewFocus); + nsRefPtr newRange = new nsRange(); newRange->SetStart(aNewFocus, aContentOffset); newRange->SetEnd(aNewFocus, aContentOffset); @@ -2869,7 +2869,7 @@ nsFrameSelection::CreateAndAddRange(nsINode *aParentNode, int32_t aOffset) { if (!aParentNode) return NS_ERROR_NULL_POINTER; - nsRefPtr range = new nsRange(aParentNode); + nsRefPtr range = new nsRange(); // Set range around child at given offset nsresult result = range->SetStart(aParentNode, aOffset); @@ -3279,7 +3279,7 @@ Selection::SubtractRange(RangeData* aRange, nsRange* aSubtract, if (cmp2 > 0) { // We need to add a new RangeData to the output, running from // the end of aSubtract to the end of range - nsRefPtr postOverlap = new nsRange(aSubtract->GetEndParent()); + nsRefPtr postOverlap = new nsRange(); rv = postOverlap->SetStart(aSubtract->GetEndParent(), aSubtract->EndOffset()); @@ -3297,7 +3297,7 @@ Selection::SubtractRange(RangeData* aRange, nsRange* aSubtract, if (cmp < 0) { // We need to add a new RangeData to the output, running from // the start of the range to the start of aSubtract - nsRefPtr preOverlap = new nsRange(range->GetStartParent()); + nsRefPtr preOverlap = new nsRange(); nsresult rv = preOverlap->SetStart(range->GetStartParent(), range->StartOffset()); @@ -4409,7 +4409,7 @@ Selection::Collapse(nsINode* aParentNode, int32_t aOffset) // Turn off signal for table selection mFrameSelection->ClearTableCellSelection(); - nsRefPtr range = new nsRange(aParentNode); + nsRefPtr range = new nsRange(); result = range->SetEnd(aParentNode, aOffset); if (NS_FAILED(result)) return result; @@ -4665,7 +4665,7 @@ Selection::Extend(nsINode* aParentNode, int32_t aOffset) &disconnected); nsRefPtr presContext = GetPresContext(); - nsRefPtr difRange = new nsRange(aParentNode); + nsRefPtr difRange = new nsRange(); if ((result1 == 0 && result3 < 0) || (result1 <= 0 && result2 < 0)){//a1,2 a,1,2 //select from 1 to 2 unless they are collapsed res = range->SetEnd(aParentNode, aOffset); diff --git a/layout/generic/test/test_selection_expanding.html b/layout/generic/test/test_selection_expanding.html index 553ce0d98762..fc17d527bfb6 100644 --- a/layout/generic/test/test_selection_expanding.html +++ b/layout/generic/test/test_selection_expanding.html @@ -75,7 +75,7 @@ var fixedDiv1 = document.getElementById("fixedDiv1"); var fixedDiv2 = document.getElementById("fixedDiv2"); var iframe = document.getElementById("iframe"); var input = document.getElementById("input"); -var textarea = SpecialPowers.wrap(document.getElementById("textarea")); +var textarea = document.getElementById("textarea"); function test() { @@ -409,4 +409,4 @@ SimpleTest.waitForExplicitFinish(); - + \ No newline at end of file diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 1369fd4b2970..38ab6afa5c42 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -2441,11 +2441,8 @@ CloneRangeToSelection(nsRange* aRange, nsIDocument* aDoc, nsCOMPtr newEnd = GetEqualNodeInCloneTree(endContainer, aDoc); NS_ENSURE_TRUE_VOID(newStart && newEnd); - nsCOMPtr newStartNode = do_QueryInterface(newStart); - NS_ENSURE_TRUE_VOID(newStartNode); - - nsRefPtr range = new nsRange(newStartNode); - nsresult rv = range->SetStart(newStartNode, startOffset); + nsRefPtr range = new nsRange(); + nsresult rv = range->SetStart(newStart, startOffset); NS_ENSURE_SUCCESS_VOID(rv); rv = range->SetEnd(newEnd, endOffset); NS_ENSURE_SUCCESS_VOID(rv); diff --git a/parser/htmlparser/public/nsHTMLTagList.h b/parser/htmlparser/public/nsHTMLTagList.h index 0426f88e7ec4..d180f253765c 100644 --- a/parser/htmlparser/public/nsHTMLTagList.h +++ b/parser/htmlparser/public/nsHTMLTagList.h @@ -153,7 +153,6 @@ HTML_TAG(textarea, TextArea) HTML_TAG(tfoot, TableSection) HTML_TAG(th, TableCell) HTML_TAG(thead, TableSection) -HTML_TAG(time, Time) HTML_TAG(title, Title) HTML_TAG(tr, TableRow) HTML_HTMLELEMENT_TAG(tt) diff --git a/parser/htmlparser/src/nsElementTable.cpp b/parser/htmlparser/src/nsElementTable.cpp index 790e56667767..3502ff61d2f7 100644 --- a/parser/htmlparser/src/nsElementTable.cpp +++ b/parser/htmlparser/src/nsElementTable.cpp @@ -1201,15 +1201,6 @@ const nsHTMLElement gHTMLElements[] = { /*special props, prop-range*/ (kNoPropagate|kBadContentWatch|kNoStyleLeaksIn|kNoStyleLeaksOut), kNoPropRange, /*special parents,kids*/ &gInTable,&gTableElemKids, }, - { - /*tag*/ eHTMLTag_time, - /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, - /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, - /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kPhrase, (kSelf|kInlineEntity), kNone, - /*special props, prop-range*/ 0, kDefaultPropRange, - /*special parents,kids*/ 0,0, - }, { /*tag*/ eHTMLTag_title, /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, diff --git a/parser/htmlparser/src/nsHTMLTags.cpp b/parser/htmlparser/src/nsHTMLTags.cpp index 8af5659ee2b3..e2fd669b3045 100644 --- a/parser/htmlparser/src/nsHTMLTags.cpp +++ b/parser/htmlparser/src/nsHTMLTags.cpp @@ -255,8 +255,6 @@ static const PRUnichar sHTMLTagUnicodeName_th[] = {'t', 'h', '\0'}; static const PRUnichar sHTMLTagUnicodeName_thead[] = {'t', 'h', 'e', 'a', 'd', '\0'}; -static const PRUnichar sHTMLTagUnicodeName_time[] = - {'t', 'i', 'm', 'e', '\0'}; static const PRUnichar sHTMLTagUnicodeName_title[] = {'t', 'i', 't', 'l', 'e', '\0'}; static const PRUnichar sHTMLTagUnicodeName_tr[] = diff --git a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp index 25d2451f6288..824aaf6227aa 100644 --- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp +++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp @@ -94,12 +94,9 @@ nsresult nsTypeAheadFind::Init(nsIDocShell* aDocShell) { nsCOMPtr prefInternal(do_GetService(NS_PREFSERVICE_CONTRACTID)); - nsIPresShell* presShell = aDocShell->GetPresShell(); - NS_ENSURE_STATE(presShell); - - mSearchRange = nullptr; - mStartPointRange = nullptr; - mEndPointRange = nullptr; + mSearchRange = new nsRange(); + mStartPointRange = new nsRange(); + mEndPointRange = new nsRange(); if (!prefInternal || !EnsureFind()) return NS_ERROR_FAILURE; @@ -169,12 +166,12 @@ nsTypeAheadFind::SetDocShell(nsIDocShell* aDocShell) nsCOMPtr presShell; presShell = aDocShell->GetPresShell(); - mPresShell = do_GetWeakReference(presShell); + mPresShell = do_GetWeakReference(presShell); mStartFindRange = nullptr; - mStartPointRange = nullptr; - mSearchRange = nullptr; - mEndPointRange = nullptr; + mStartPointRange = new nsRange(); + mSearchRange = new nsRange(); + mEndPointRange = new nsRange(); mFoundLink = nullptr; mFoundEditable = nullptr; @@ -364,10 +361,6 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly, } int16_t rangeCompareResult = 0; - if (!mStartPointRange) { - mStartPointRange = new nsRange(presShell->GetDocument()); - } - mStartPointRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, mSearchRange, &rangeCompareResult); // No need to wrap find in doc if starting at beginning bool hasWrapped = (rangeCompareResult < 0); @@ -628,10 +621,6 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly, // at end of document and go to beginning nsCOMPtr tempRange; mStartPointRange->CloneRange(getter_AddRefs(tempRange)); - if (!mEndPointRange) { - mEndPointRange = new nsRange(presShell->GetDocument()); - } - mStartPointRange = mEndPointRange; mEndPointRange = tempRange; } @@ -730,14 +719,6 @@ nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer, uint32_t childCount = rootContent->GetChildCount(); - if (!mSearchRange) { - mSearchRange = new nsRange(rootContent); - } - - if (!mEndPointRange) { - mEndPointRange = new nsRange(rootContent); - } - mSearchRange->SelectNodeContents(rootNode); mEndPointRange->SetEnd(rootNode, childCount); @@ -755,10 +736,6 @@ nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer, selection->GetRangeAt(0, getter_AddRefs(currentSelectionRange)); } - if (!mStartPointRange) { - mStartPointRange = new nsRange(doc); - } - if (!currentSelectionRange) { // Ensure visible range, move forward if necessary // This uses ignores the return value, but usese the side effect of