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"
21 class CrossShadowBoundaryRange final
: public StaticRange
,
22 public nsStubMutationObserver
{
24 NS_DECL_ISUPPORTS_INHERITED
25 NS_IMETHODIMP_(void) DeleteCycleCollectable(void) override
;
26 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
27 CrossShadowBoundaryRange
, StaticRange
)
29 CrossShadowBoundaryRange() = delete;
30 explicit CrossShadowBoundaryRange(const StaticRange
& aOther
) = delete;
32 template <typename SPT
, typename SRT
, typename EPT
, typename ERT
>
33 static already_AddRefed
<CrossShadowBoundaryRange
> Create(
34 const RangeBoundaryBase
<SPT
, SRT
>& aStartBoundary
,
35 const RangeBoundaryBase
<EPT
, ERT
>& aEndBoundary
, nsRange
* aOwner
);
37 void NotifyNodeBecomesShadowHost(nsINode
* aNode
) {
38 if (aNode
== mStart
.Container()) {
39 mStart
.NotifyParentBecomesShadowHost();
42 if (aNode
== mEnd
.Container()) {
43 mEnd
.NotifyParentBecomesShadowHost();
47 nsINode
* GetCommonAncestor() const { return mCommonAncestor
; }
49 // CrossShadowBoundaryRange should have a very limited usage.
50 nsresult
SetStartAndEnd(nsINode
* aStartContainer
, uint32_t aStartOffset
,
51 nsINode
* aEndContainer
, uint32_t aEndOffset
) = delete;
53 template <typename SPT
, typename SRT
, typename EPT
, typename ERT
>
54 nsresult
SetStartAndEnd(const RangeBoundaryBase
<SPT
, SRT
>& aStartBoundary
,
55 const RangeBoundaryBase
<EPT
, ERT
>& aEndBoundary
) {
56 return StaticRange::SetStartAndEnd(aStartBoundary
, aEndBoundary
);
59 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
60 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
61 NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED
64 explicit CrossShadowBoundaryRange(nsINode
* aNode
, nsRange
* aOwner
)
65 : StaticRange(aNode
, RangeBoundaryIsMutationObserved::Yes
),
67 virtual ~CrossShadowBoundaryRange() = default;
70 * DoSetRange() is called when `AbstractRange::SetStartAndEndInternal()` sets
73 * @param aStartBoundary Computed start point. This must equals or be before
74 * aEndBoundary in the DOM tree order.
75 * @param aEndBoundary Computed end point.
76 * @param aRootNode The root node of aStartBoundary or aEndBoundary.
77 * It's useless to CrossShadowBoundaryRange.
78 * @param aOwner The nsRange that owns this CrossShadowBoundaryRange.
80 template <typename SPT
, typename SRT
, typename EPT
, typename ERT
>
81 void DoSetRange(const RangeBoundaryBase
<SPT
, SRT
>& aStartBoundary
,
82 const RangeBoundaryBase
<EPT
, ERT
>& aEndBoundary
,
83 nsINode
* aRootNode
, nsRange
* aOwner
);
85 // This is either NULL if this CrossShadowBoundaryRange has been
86 // reset by Release() or the closest common shadow-including ancestor
87 // of mStart and mEnd.
88 nsCOMPtr
<nsINode
> mCommonAncestor
;
90 static nsTArray
<RefPtr
<CrossShadowBoundaryRange
>>* sCachedRanges
;
92 friend class AbstractRange
;
94 // nsRange owns CrossShadowBoundaryRange; it always outlives
95 // CrossShadowBoundaryRange, so it's safe to use raw pointer here.
99 } // namespace mozilla
101 #endif // #ifndef mozilla_dom_CrossShadowBoundaryRange_h