зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1444847 - part 4: Implement `mozilla::dom::StaticRange` and static factory methods r=smaug
This patch is based on Makoto Kato-san's patch. This patch implements `mozilla::dom::StaticRange` class and creating some static factory methods. Then, makes `AbstractRange` has a utility method of `SetStartAndEnd()` method of `nsRange` and `StaticRange` for sharing same logic in one place. However, there are some additional work is required only in `nsRange`, e.g., `nsRange` needs to start observing mutation of the range, but `StaticRange` does not it. Therefore, it's implemented as a template method which takes `nsRange*` or `StaticRange*` as a parameter. Then, each `DoSetRange()` method of them can do different things without virtual calls. Note that `StaticRange` does not have any properties, methods nor constructor. Therefore, we need additional API to test it. Differential Revision: https://phabricator.services.mozilla.com/D35143 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
da61ea3112
Коммит
c2694625b5
|
@ -6,13 +6,43 @@
|
|||
|
||||
#include "mozilla/dom/AbstractRange.h"
|
||||
#include "mozilla/dom/AbstractRangeBinding.h"
|
||||
|
||||
#include "mozilla/RangeUtils.h"
|
||||
#include "mozilla/dom/StaticRange.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsINode.h"
|
||||
#include "nsRange.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
template nsresult AbstractRange::SetStartAndEndInternal(
|
||||
const RangeBoundary& aStartBoundary, const RangeBoundary& aEndBoundary,
|
||||
nsRange* aRange);
|
||||
template nsresult AbstractRange::SetStartAndEndInternal(
|
||||
const RangeBoundary& aStartBoundary, const RawRangeBoundary& aEndBoundary,
|
||||
nsRange* aRange);
|
||||
template nsresult AbstractRange::SetStartAndEndInternal(
|
||||
const RawRangeBoundary& aStartBoundary, const RangeBoundary& aEndBoundary,
|
||||
nsRange* aRange);
|
||||
template nsresult AbstractRange::SetStartAndEndInternal(
|
||||
const RawRangeBoundary& aStartBoundary,
|
||||
const RawRangeBoundary& aEndBoundary, nsRange* aRange);
|
||||
template nsresult AbstractRange::SetStartAndEndInternal(
|
||||
const RangeBoundary& aStartBoundary, const RangeBoundary& aEndBoundary,
|
||||
StaticRange* aRange);
|
||||
template nsresult AbstractRange::SetStartAndEndInternal(
|
||||
const RangeBoundary& aStartBoundary, const RawRangeBoundary& aEndBoundary,
|
||||
StaticRange* aRange);
|
||||
template nsresult AbstractRange::SetStartAndEndInternal(
|
||||
const RawRangeBoundary& aStartBoundary, const RangeBoundary& aEndBoundary,
|
||||
StaticRange* aRange);
|
||||
template nsresult AbstractRange::SetStartAndEndInternal(
|
||||
const RawRangeBoundary& aStartBoundary,
|
||||
const RawRangeBoundary& aEndBoundary, StaticRange* aRange);
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(AbstractRange)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(AbstractRange)
|
||||
|
||||
|
@ -50,6 +80,67 @@ nsINode* AbstractRange::GetCommonAncestor() const {
|
|||
: nullptr;
|
||||
}
|
||||
|
||||
// static
|
||||
template <typename SPT, typename SRT, typename EPT, typename ERT,
|
||||
typename RangeType>
|
||||
nsresult AbstractRange::SetStartAndEndInternal(
|
||||
const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
const RangeBoundaryBase<EPT, ERT>& aEndBoundary, RangeType* aRange) {
|
||||
if (NS_WARN_IF(!aStartBoundary.IsSet()) ||
|
||||
NS_WARN_IF(!aEndBoundary.IsSet())) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsINode* newStartRoot =
|
||||
RangeUtils::ComputeRootNode(aStartBoundary.Container());
|
||||
if (!newStartRoot) {
|
||||
return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR;
|
||||
}
|
||||
if (!aStartBoundary.IsSetAndValid()) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
if (aStartBoundary.Container() == aEndBoundary.Container()) {
|
||||
if (!aEndBoundary.IsSetAndValid()) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
// XXX: Offsets - handle this more efficiently.
|
||||
// If the end offset is less than the start offset, this should be
|
||||
// collapsed at the end offset.
|
||||
if (aStartBoundary.Offset() > aEndBoundary.Offset()) {
|
||||
aRange->DoSetRange(aEndBoundary, aEndBoundary, newStartRoot);
|
||||
} else {
|
||||
aRange->DoSetRange(aStartBoundary, aEndBoundary, newStartRoot);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsINode* newEndRoot = RangeUtils::ComputeRootNode(aEndBoundary.Container());
|
||||
if (!newEndRoot) {
|
||||
return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR;
|
||||
}
|
||||
if (!aEndBoundary.IsSetAndValid()) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
// If they have different root, this should be collapsed at the end point.
|
||||
if (newStartRoot != newEndRoot) {
|
||||
aRange->DoSetRange(aEndBoundary, aEndBoundary, newEndRoot);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If the end point is before the start point, this should be collapsed at
|
||||
// the end point.
|
||||
if (nsContentUtils::ComparePoints(aStartBoundary, aEndBoundary) == 1) {
|
||||
aRange->DoSetRange(aEndBoundary, aEndBoundary, newEndRoot);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Otherwise, set the range as specified.
|
||||
aRange->DoSetRange(aStartBoundary, aEndBoundary, newStartRoot);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
JSObject* AbstractRange::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
MOZ_CRASH("Must be overridden");
|
||||
|
|
|
@ -68,6 +68,12 @@ class AbstractRange : public nsISupports, public nsWrapperCache {
|
|||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
protected:
|
||||
template <typename SPT, typename SRT, typename EPT, typename ERT,
|
||||
typename RangeType>
|
||||
static nsresult SetStartAndEndInternal(
|
||||
const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
const RangeBoundaryBase<EPT, ERT>& aEndBoundary, RangeType* aRange);
|
||||
|
||||
RefPtr<Document> mOwner;
|
||||
RangeBoundary mStart;
|
||||
RangeBoundary mEnd;
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/StaticRange.h"
|
||||
#include "mozilla/dom/StaticRangeBinding.h"
|
||||
#include "nsINode.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
template already_AddRefed<StaticRange> StaticRange::Create(
|
||||
const RangeBoundary& aStartBoundary, const RangeBoundary& aEndBoundary,
|
||||
ErrorResult& aRv);
|
||||
template already_AddRefed<StaticRange> StaticRange::Create(
|
||||
const RangeBoundary& aStartBoundary, const RawRangeBoundary& aEndBoundary,
|
||||
ErrorResult& aRv);
|
||||
template already_AddRefed<StaticRange> StaticRange::Create(
|
||||
const RawRangeBoundary& aStartBoundary, const RangeBoundary& aEndBoundary,
|
||||
ErrorResult& aRv);
|
||||
template already_AddRefed<StaticRange> StaticRange::Create(
|
||||
const RawRangeBoundary& aStartBoundary,
|
||||
const RawRangeBoundary& aEndBoundary, ErrorResult& aRv);
|
||||
template nsresult StaticRange::SetStartAndEnd(
|
||||
const RangeBoundary& aStartBoundary, const RangeBoundary& aEndBoundary);
|
||||
template nsresult StaticRange::SetStartAndEnd(
|
||||
const RangeBoundary& aStartBoundary, const RawRangeBoundary& aEndBoundary);
|
||||
template nsresult StaticRange::SetStartAndEnd(
|
||||
const RawRangeBoundary& aStartBoundary, const RangeBoundary& aEndBoundary);
|
||||
template nsresult StaticRange::SetStartAndEnd(
|
||||
const RawRangeBoundary& aStartBoundary,
|
||||
const RawRangeBoundary& aEndBoundary);
|
||||
template void StaticRange::DoSetRange(const RangeBoundary& aStartBoundary,
|
||||
const RangeBoundary& aEndBoundary,
|
||||
nsINode* aRootNode);
|
||||
template void StaticRange::DoSetRange(const RangeBoundary& aStartBoundary,
|
||||
const RawRangeBoundary& aEndBoundary,
|
||||
nsINode* aRootNode);
|
||||
template void StaticRange::DoSetRange(const RawRangeBoundary& aStartBoundary,
|
||||
const RangeBoundary& aEndBoundary,
|
||||
nsINode* aRootNode);
|
||||
template void StaticRange::DoSetRange(const RawRangeBoundary& aStartBoundary,
|
||||
const RawRangeBoundary& aEndBoundary,
|
||||
nsINode* aRootNode);
|
||||
|
||||
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(StaticRange)
|
||||
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(
|
||||
StaticRange, DoSetRange(RawRangeBoundary(), RawRangeBoundary(), nullptr))
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StaticRange)
|
||||
NS_INTERFACE_MAP_END_INHERITING(AbstractRange)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(StaticRange)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(StaticRange, AbstractRange)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStart)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEnd)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(StaticRange, AbstractRange)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(StaticRange, AbstractRange)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
// static
|
||||
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
||||
already_AddRefed<StaticRange> StaticRange::Create(
|
||||
const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
const RangeBoundaryBase<EPT, ERT>& aEndBoundary, ErrorResult& aRv) {
|
||||
RefPtr<StaticRange> staticRange = new StaticRange(aStartBoundary.Container());
|
||||
aRv = staticRange->SetStartAndEnd(aStartBoundary, aEndBoundary);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
return staticRange.forget();
|
||||
}
|
||||
|
||||
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
||||
void StaticRange::DoSetRange(const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
const RangeBoundaryBase<EPT, ERT>& aEndBoundary,
|
||||
nsINode* aRootNode) {
|
||||
mStart = aStartBoundary;
|
||||
mEnd = aEndBoundary;
|
||||
mIsPositioned = mStart.IsSet();
|
||||
}
|
||||
|
||||
JSObject* StaticRange::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return StaticRange_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,105 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_StaticRange_h
|
||||
#define mozilla_dom_StaticRange_h
|
||||
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/RangeBoundary.h"
|
||||
#include "mozilla/dom/AbstractRange.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class StaticRange final : public AbstractRange {
|
||||
public:
|
||||
explicit StaticRange(nsINode* aNode) : AbstractRange(aNode) {}
|
||||
StaticRange() = delete;
|
||||
explicit StaticRange(const StaticRange& aOther) = delete;
|
||||
|
||||
/**
|
||||
* Create() may return `StaticRange` instance which is initialized with
|
||||
* given range or points. If it fails initializing new range with the
|
||||
* arguments, returns `nullptr`. `ErrorResult` is set to an error only
|
||||
* when this returns `nullptr`. The error code indicates the reason why
|
||||
* it couldn't initialize the instance.
|
||||
*/
|
||||
static already_AddRefed<StaticRange> Create(
|
||||
const AbstractRange* aAbstractRange, ErrorResult& aRv) {
|
||||
MOZ_ASSERT(aAbstractRange);
|
||||
return StaticRange::Create(aAbstractRange->StartRef(),
|
||||
aAbstractRange->EndRef(), aRv);
|
||||
}
|
||||
static already_AddRefed<StaticRange> Create(nsINode* aStartContainer,
|
||||
uint32_t aStartOffset,
|
||||
nsINode* aEndContainer,
|
||||
uint32_t aEndOffset,
|
||||
ErrorResult& aRv) {
|
||||
return StaticRange::Create(RawRangeBoundary(aStartContainer, aStartOffset),
|
||||
RawRangeBoundary(aEndContainer, aEndOffset),
|
||||
aRv);
|
||||
}
|
||||
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
||||
static already_AddRefed<StaticRange> Create(
|
||||
const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
const RangeBoundaryBase<EPT, ERT>& aEndBoundary, ErrorResult& aRv);
|
||||
|
||||
protected:
|
||||
virtual ~StaticRange() = default;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
// Need to override this for calling `DoSetRange()` from
|
||||
// `NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE()`.
|
||||
NS_IMETHODIMP_(void) DeleteCycleCollectable(void) override;
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(StaticRange,
|
||||
AbstractRange)
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
|
||||
|
||||
/**
|
||||
* SetStartAndEnd() works similar to call both SetStart() and SetEnd().
|
||||
* Different from calls them separately, this does nothing if either
|
||||
* the start point or the end point is invalid point.
|
||||
* If the specified start point is after the end point, the range will be
|
||||
* collapsed at the end point. Similarly, if they are in different root,
|
||||
* the range will be collapsed at the end point.
|
||||
*/
|
||||
nsresult SetStartAndEnd(nsINode* aStartContainer, uint32_t aStartOffset,
|
||||
nsINode* aEndContainer, uint32_t aEndOffset) {
|
||||
return SetStartAndEnd(RawRangeBoundary(aStartContainer, aStartOffset),
|
||||
RawRangeBoundary(aEndContainer, aEndOffset));
|
||||
}
|
||||
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
||||
nsresult SetStartAndEnd(const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
const RangeBoundaryBase<EPT, ERT>& aEndBoundary) {
|
||||
return AbstractRange::SetStartAndEndInternal(aStartBoundary, aEndBoundary,
|
||||
this);
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* DoSetRange() is called when `AbstractRange::SetStartAndEndInternal()` sets
|
||||
* mStart and mEnd.
|
||||
*
|
||||
* @param aStartBoundary Computed start point. This must equals or be before
|
||||
* aEndBoundary in the DOM tree order.
|
||||
* @param aEndBoundary Computed end point.
|
||||
* @param aRootNode The root node.
|
||||
*/
|
||||
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
||||
void DoSetRange(const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
const RangeBoundaryBase<EPT, ERT>& aEndBoundary,
|
||||
nsINode* aRootNode);
|
||||
|
||||
friend class AbstractRange;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // #ifndef mozilla_dom_StaticRange_h
|
|
@ -5,6 +5,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ThirdPartyUtil.h"
|
||||
#include "nsGlobalWindowOuter.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIChannel.h"
|
||||
|
@ -23,7 +24,6 @@
|
|||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsGlobalWindowOuter.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS(ThirdPartyUtil, mozIThirdPartyUtil)
|
||||
|
||||
|
|
|
@ -7,11 +7,13 @@
|
|||
#ifndef ThirdPartyUtil_h__
|
||||
#define ThirdPartyUtil_h__
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "mozIThirdPartyUtil.h"
|
||||
#include "nsEffectiveTLDService.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsEffectiveTLDService.h"
|
||||
#include "nsString.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
class nsIURI;
|
||||
class nsPIDOMWindowOuter;
|
||||
|
|
|
@ -226,6 +226,7 @@ EXPORTS.mozilla.dom += [
|
|||
'SerializedStackHolder.h',
|
||||
'ShadowIncludingTreeIterator.h',
|
||||
'ShadowRoot.h',
|
||||
'StaticRange.h',
|
||||
'StructuredCloneBlob.h',
|
||||
'StructuredCloneHolder.h',
|
||||
'StructuredCloneTags.h',
|
||||
|
@ -396,6 +397,7 @@ UNIFIED_SOURCES += [
|
|||
'SelectionChangeEventDispatcher.cpp',
|
||||
'SerializedStackHolder.cpp',
|
||||
'ShadowRoot.cpp',
|
||||
'StaticRange.cpp',
|
||||
'StorageAccessPermissionRequest.cpp',
|
||||
'StructuredCloneBlob.cpp',
|
||||
'StructuredCloneHolder.cpp',
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* via XMLHttpRequest).
|
||||
*/
|
||||
|
||||
#include "nsContentPolicyUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsContentPolicyUtils.h"
|
||||
#include "nsDataDocumentContentPolicy.h"
|
||||
|
@ -22,6 +23,8 @@
|
|||
#include "nsIDOMWindow.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsDataDocumentContentPolicy, nsIContentPolicy)
|
||||
|
||||
// Helper method for ShouldLoad()
|
||||
|
|
|
@ -1144,65 +1144,6 @@ void nsRange::SelectNodesInContainer(nsINode* aContainer,
|
|||
DoSetRange(start, end, newRoot);
|
||||
}
|
||||
|
||||
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
||||
nsresult nsRange::SetStartAndEnd(
|
||||
const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
const RangeBoundaryBase<EPT, ERT>& aEndBoundary) {
|
||||
if (NS_WARN_IF(!aStartBoundary.IsSet()) ||
|
||||
NS_WARN_IF(!aEndBoundary.IsSet())) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsINode* newStartRoot =
|
||||
RangeUtils::ComputeRootNode(aStartBoundary.Container());
|
||||
if (!newStartRoot) {
|
||||
return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR;
|
||||
}
|
||||
if (!aStartBoundary.IsSetAndValid()) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
if (aStartBoundary.Container() == aEndBoundary.Container()) {
|
||||
if (!aEndBoundary.IsSetAndValid()) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
// XXX: Offsets - handle this more efficiently.
|
||||
// If the end offset is less than the start offset, this should be
|
||||
// collapsed at the end offset.
|
||||
if (aStartBoundary.Offset() > aEndBoundary.Offset()) {
|
||||
DoSetRange(aEndBoundary, aEndBoundary, newStartRoot);
|
||||
} else {
|
||||
DoSetRange(aStartBoundary, aEndBoundary, newStartRoot);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsINode* newEndRoot = RangeUtils::ComputeRootNode(aEndBoundary.Container());
|
||||
if (!newEndRoot) {
|
||||
return NS_ERROR_DOM_INVALID_NODE_TYPE_ERR;
|
||||
}
|
||||
if (!aEndBoundary.IsSetAndValid()) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
// If they have different root, this should be collapsed at the end point.
|
||||
if (newStartRoot != newEndRoot) {
|
||||
DoSetRange(aEndBoundary, aEndBoundary, newEndRoot);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If the end point is before the start point, this should be collapsed at
|
||||
// the end point.
|
||||
if (nsContentUtils::ComparePoints(aStartBoundary, aEndBoundary) == 1) {
|
||||
DoSetRange(aEndBoundary, aEndBoundary, newEndRoot);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Otherwise, set the range as specified.
|
||||
DoSetRange(aStartBoundary, aEndBoundary, newStartRoot);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsRange::SetEndBeforeJS(nsINode& aNode, ErrorResult& aErr) {
|
||||
AutoCalledByJSRestore calledByJSRestorer(*this);
|
||||
mCalledByJS = true;
|
||||
|
|
|
@ -164,7 +164,10 @@ class nsRange final : public mozilla::dom::AbstractRange,
|
|||
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
||||
nsresult SetStartAndEnd(
|
||||
const mozilla::RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
const mozilla::RangeBoundaryBase<EPT, ERT>& aEndBoundary);
|
||||
const mozilla::RangeBoundaryBase<EPT, ERT>& aEndBoundary) {
|
||||
return AbstractRange::SetStartAndEndInternal(aStartBoundary, aEndBoundary,
|
||||
this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all nodes between |aStartContent| and |aEndContent| to the range.
|
||||
|
@ -349,10 +352,22 @@ class nsRange final : public mozilla::dom::AbstractRange,
|
|||
void RegisterCommonAncestor(nsINode* aNode);
|
||||
void UnregisterCommonAncestor(nsINode* aNode, bool aIsUnlinking);
|
||||
|
||||
// CharacterDataChanged set aNotInsertedYet to true to disable an assertion
|
||||
// and suppress re-registering a range common ancestor node since
|
||||
// the new text node of a splitText hasn't been inserted yet.
|
||||
// CharacterDataChanged does the re-registering when needed.
|
||||
/**
|
||||
* DoSetRange() is called when `AbstractRange::SetStartAndEndInternal()` sets
|
||||
* mStart and mEnd, or some other internal methods modify `mStart` and/or
|
||||
* `mEnd`. Therefore, this shouldn't be a virtual method.
|
||||
*
|
||||
* @param aStartBoundary Computed start point. This must equals or be
|
||||
* before aEndBoundary in the DOM tree order.
|
||||
* @param aEndBoundary Computed end point.
|
||||
* @param aRootNode The root node.
|
||||
* @param aNotInsertedYet true if this is called by CharacterDataChanged()
|
||||
* to disable assertion and suppress re-registering
|
||||
* a range common ancestor node since the new text
|
||||
* node of a splitText hasn't been inserted yet.
|
||||
* CharacterDataChanged() does the re-registering
|
||||
* when needed. Otherwise, false.
|
||||
*/
|
||||
template <typename SPT, typename SRT, typename EPT, typename ERT>
|
||||
MOZ_CAN_RUN_SCRIPT_BOUNDARY void DoSetRange(
|
||||
const mozilla::RangeBoundaryBase<SPT, SRT>& aStartBoundary,
|
||||
|
@ -422,6 +437,8 @@ class nsRange final : public mozilla::dom::AbstractRange,
|
|||
// notifications while holding a strong reference to the new child.
|
||||
nsIContent* MOZ_NON_OWNING_REF mNextStartRef;
|
||||
nsIContent* MOZ_NON_OWNING_REF mNextEndRef;
|
||||
|
||||
friend class mozilla::dom::AbstractRange;
|
||||
};
|
||||
|
||||
#endif /* nsRange_h___ */
|
||||
|
|
|
@ -921,6 +921,8 @@ var interfaceNamesInGlobalScope =
|
|||
{name: "SpeechSynthesisVoice", insecureContext: true},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "SpecialPowers", insecureContext: true},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "StaticRange", insecureContext: true},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{name: "StereoPannerNode", insecureContext: true},
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/* -*- 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
|
||||
* https://dom.spec.whatwg.org/#staticrange
|
||||
*
|
||||
* Copyright 2012 W3C (MIT, ERCIM, Keio), All Rights Reserved. W3C
|
||||
* liability, trademark and document use rules apply.
|
||||
*/
|
||||
|
||||
// Currently, StaticRange cannot be created from web apps.
|
||||
interface StaticRange : AbstractRange {
|
||||
// And no additional functions/properties.
|
||||
};
|
|
@ -769,6 +769,7 @@ WEBIDL_FILES = [
|
|||
'SocketCommon.webidl',
|
||||
'SourceBuffer.webidl',
|
||||
'SourceBufferList.webidl',
|
||||
'StaticRange.webidl',
|
||||
'StereoPannerNode.webidl',
|
||||
'Storage.webidl',
|
||||
'StorageEvent.webidl',
|
||||
|
|
|
@ -181,24 +181,5 @@
|
|||
[Document interface: xmlDoc must inherit property "origin" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[StaticRange interface: existence and properties of interface object]
|
||||
expected: FAIL
|
||||
|
||||
[StaticRange interface object length]
|
||||
expected: FAIL
|
||||
|
||||
[StaticRange interface object name]
|
||||
expected: FAIL
|
||||
|
||||
[StaticRange interface: existence and properties of interface prototype object]
|
||||
expected: FAIL
|
||||
|
||||
[StaticRange interface: existence and properties of interface prototype object's "constructor" property]
|
||||
expected: FAIL
|
||||
|
||||
[StaticRange interface: existence and properties of interface prototype object's @@unscopables property]
|
||||
expected: FAIL
|
||||
|
||||
[Document interface: existence and properties of interface prototype object's @@unscopables property]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче