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 #include "mozilla/dom/CrossShadowBoundaryRange.h"
8 #include "nsContentUtils.h"
11 namespace mozilla::dom
{
12 template already_AddRefed
<CrossShadowBoundaryRange
>
13 CrossShadowBoundaryRange::Create(const RangeBoundary
& aStartBoundary
,
14 const RangeBoundary
& aEndBoundary
);
15 template already_AddRefed
<CrossShadowBoundaryRange
>
16 CrossShadowBoundaryRange::Create(const RangeBoundary
& aStartBoundary
,
17 const RawRangeBoundary
& aEndBoundary
);
18 template already_AddRefed
<CrossShadowBoundaryRange
>
19 CrossShadowBoundaryRange::Create(const RawRangeBoundary
& aStartBoundary
,
20 const RangeBoundary
& aEndBoundary
);
21 template already_AddRefed
<CrossShadowBoundaryRange
>
22 CrossShadowBoundaryRange::Create(const RawRangeBoundary
& aStartBoundary
,
23 const RawRangeBoundary
& aEndBoundary
);
25 template void CrossShadowBoundaryRange::DoSetRange(
26 const RangeBoundary
& aStartBoundary
, const RangeBoundary
& aEndBoundary
,
28 template void CrossShadowBoundaryRange::DoSetRange(
29 const RangeBoundary
& aStartBoundary
, const RawRangeBoundary
& aEndBoundary
,
31 template void CrossShadowBoundaryRange::DoSetRange(
32 const RawRangeBoundary
& aStartBoundary
, const RangeBoundary
& aEndBoundary
,
34 template void CrossShadowBoundaryRange::DoSetRange(
35 const RawRangeBoundary
& aStartBoundary
,
36 const RawRangeBoundary
& aEndBoundary
, nsINode
* aRootNode
);
38 template nsresult
CrossShadowBoundaryRange::SetStartAndEnd(
39 const RangeBoundary
& aStartBoundary
, const RangeBoundary
& aEndBoundary
);
40 template nsresult
CrossShadowBoundaryRange::SetStartAndEnd(
41 const RangeBoundary
& aStartBoundary
, const RawRangeBoundary
& aEndBoundary
);
42 template nsresult
CrossShadowBoundaryRange::SetStartAndEnd(
43 const RawRangeBoundary
& aStartBoundary
, const RangeBoundary
& aEndBoundary
);
44 template nsresult
CrossShadowBoundaryRange::SetStartAndEnd(
45 const RawRangeBoundary
& aStartBoundary
,
46 const RawRangeBoundary
& aEndBoundary
);
48 nsTArray
<RefPtr
<CrossShadowBoundaryRange
>>*
49 CrossShadowBoundaryRange::sCachedRanges
= nullptr;
51 NS_IMPL_CYCLE_COLLECTING_ADDREF(CrossShadowBoundaryRange
)
53 NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_INTERRUPTABLE_LAST_RELEASE(
54 CrossShadowBoundaryRange
,
55 DoSetRange(RawRangeBoundary(), RawRangeBoundary(), nullptr),
56 AbstractRange::MaybeCacheToReuse(*this))
58 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CrossShadowBoundaryRange
)
59 NS_INTERFACE_MAP_END_INHERITING(CrossShadowBoundaryRange
)
61 NS_IMPL_CYCLE_COLLECTION_CLASS(CrossShadowBoundaryRange
)
63 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CrossShadowBoundaryRange
,
65 NS_IMPL_CYCLE_COLLECTION_UNLINK(mCommonAncestor
)
66 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
68 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CrossShadowBoundaryRange
,
70 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCommonAncestor
)
71 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
73 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CrossShadowBoundaryRange
,
75 NS_IMPL_CYCLE_COLLECTION_TRACE_END
78 template <typename SPT
, typename SRT
, typename EPT
, typename ERT
>
79 already_AddRefed
<CrossShadowBoundaryRange
> CrossShadowBoundaryRange::Create(
80 const RangeBoundaryBase
<SPT
, SRT
>& aStartBoundary
,
81 const RangeBoundaryBase
<EPT
, ERT
>& aEndBoundary
) {
82 RefPtr
<CrossShadowBoundaryRange
> range
;
83 if (!sCachedRanges
|| sCachedRanges
->IsEmpty()) {
84 range
= new CrossShadowBoundaryRange(aStartBoundary
.Container());
86 range
= sCachedRanges
->PopLastElement().forget();
89 range
->Init(aStartBoundary
.Container());
90 range
->DoSetRange(aStartBoundary
, aEndBoundary
, nullptr);
91 return range
.forget();
94 template <typename SPT
, typename SRT
, typename EPT
, typename ERT
>
95 void CrossShadowBoundaryRange::DoSetRange(
96 const RangeBoundaryBase
<SPT
, SRT
>& aStartBoundary
,
97 const RangeBoundaryBase
<EPT
, ERT
>& aEndBoundary
, nsINode
* aRootNode
) {
98 // aRootNode is useless to CrossShadowBoundaryRange because aStartBoundary
99 // and aEndBoundary could have different roots.
100 StaticRange::DoSetRange(aStartBoundary
, aEndBoundary
, nullptr);
102 nsINode
* startRoot
= RangeUtils::ComputeRootNode(mStart
.Container());
103 nsINode
* endRoot
= RangeUtils::ComputeRootNode(mEnd
.Container());
105 if (startRoot
== endRoot
) {
106 // This should be the case when Release() is called.
107 MOZ_ASSERT(!startRoot
&& !endRoot
);
108 mCommonAncestor
= startRoot
;
111 nsContentUtils::GetClosestCommonShadowIncludingInclusiveAncestor(
112 mStart
.Container(), mEnd
.Container());
115 } // namespace mozilla::dom