Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / base / CrossShadowBoundaryRange.h
blob3ad4fa17937146db7d530acf7109f7be1bb9fa4f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_CrossShadowBoundaryRange_h
8 #define mozilla_dom_CrossShadowBoundaryRange_h
10 #include "mozilla/RangeBoundary.h"
11 #include "mozilla/RangeUtils.h"
12 #include "mozilla/dom/AbstractRange.h"
13 #include "mozilla/dom/StaticRange.h"
14 #include "nsTArray.h"
16 namespace mozilla {
17 class ErrorResult;
19 namespace dom {
21 class CrossShadowBoundaryRange final : public StaticRange {
22 public:
23 NS_DECL_ISUPPORTS_INHERITED
24 NS_IMETHODIMP_(void) DeleteCycleCollectable(void) override;
25 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
26 CrossShadowBoundaryRange, StaticRange)
28 CrossShadowBoundaryRange() = delete;
29 explicit CrossShadowBoundaryRange(const StaticRange& aOther) = delete;
31 template <typename SPT, typename SRT, typename EPT, typename ERT>
32 static already_AddRefed<CrossShadowBoundaryRange> Create(
33 const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
34 const RangeBoundaryBase<EPT, ERT>& aEndBoundary);
36 void NotifyNodeBecomesShadowHost(nsINode* aNode) {
37 if (aNode == mStart.Container()) {
38 mStart.NotifyParentBecomesShadowHost();
41 if (aNode == mEnd.Container()) {
42 mEnd.NotifyParentBecomesShadowHost();
46 nsINode* GetCommonAncestor() const { return mCommonAncestor; }
48 // CrossShadowBoundaryRange should have a very limited usage.
49 nsresult SetStartAndEnd(nsINode* aStartContainer, uint32_t aStartOffset,
50 nsINode* aEndContainer, uint32_t aEndOffset) = delete;
52 template <typename SPT, typename SRT, typename EPT, typename ERT>
53 nsresult SetStartAndEnd(const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
54 const RangeBoundaryBase<EPT, ERT>& aEndBoundary) {
55 return StaticRange::SetStartAndEnd(aStartBoundary, aEndBoundary);
58 private:
59 explicit CrossShadowBoundaryRange(nsINode* aNode) : StaticRange(aNode) {}
60 virtual ~CrossShadowBoundaryRange() = default;
62 /**
63 * DoSetRange() is called when `AbstractRange::SetStartAndEndInternal()` sets
64 * mStart and mEnd.
66 * @param aStartBoundary Computed start point. This must equals or be before
67 * aEndBoundary in the DOM tree order.
68 * @param aEndBoundary Computed end point.
69 * @param aRootNode The root node of aStartBoundary or aEndBoundary.
70 * It's useless to CrossShadowBoundaryRange.
72 template <typename SPT, typename SRT, typename EPT, typename ERT>
73 void DoSetRange(const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
74 const RangeBoundaryBase<EPT, ERT>& aEndBoundary,
75 nsINode* aRootNode);
77 // This is either NULL if this CrossShadowBoundaryRange has been
78 // reset by Release() or the closest common shadow-including ancestor
79 // of mStart and mEnd.
80 nsCOMPtr<nsINode> mCommonAncestor;
82 static nsTArray<RefPtr<CrossShadowBoundaryRange>>* sCachedRanges;
84 friend class AbstractRange;
86 } // namespace dom
87 } // namespace mozilla
89 #endif // #ifndef mozilla_dom_CrossShadowBoundaryRange_h