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
{
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
);
59 explicit CrossShadowBoundaryRange(nsINode
* aNode
) : StaticRange(aNode
) {}
60 virtual ~CrossShadowBoundaryRange() = default;
63 * DoSetRange() is called when `AbstractRange::SetStartAndEndInternal()` sets
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
,
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
;
87 } // namespace mozilla
89 #endif // #ifndef mozilla_dom_CrossShadowBoundaryRange_h