Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef nsRangeFrame_h___
7 : #define nsRangeFrame_h___
8 :
9 : #include "mozilla/Attributes.h"
10 : #include "mozilla/Decimal.h"
11 : #include "mozilla/EventForwards.h"
12 : #include "nsContainerFrame.h"
13 : #include "nsIAnonymousContentCreator.h"
14 : #include "nsIDOMEventListener.h"
15 : #include "nsCOMPtr.h"
16 :
17 : class nsDisplayRangeFocusRing;
18 :
19 : class nsRangeFrame final : public nsContainerFrame,
20 : public nsIAnonymousContentCreator
21 : {
22 : friend nsIFrame*
23 : NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
24 :
25 : friend class nsDisplayRangeFocusRing;
26 :
27 : explicit nsRangeFrame(nsStyleContext* aContext);
28 : virtual ~nsRangeFrame();
29 :
30 : typedef mozilla::CSSPseudoElementType CSSPseudoElementType;
31 : typedef mozilla::dom::Element Element;
32 :
33 : public:
34 : NS_DECL_QUERYFRAME
35 0 : NS_DECL_FRAMEARENA_HELPERS(nsRangeFrame)
36 :
37 : // nsIFrame overrides
38 : virtual void Init(nsIContent* aContent,
39 : nsContainerFrame* aParent,
40 : nsIFrame* aPrevInFlow) override;
41 :
42 : virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
43 :
44 : void BuildDisplayList(nsDisplayListBuilder* aBuilder,
45 : const nsRect& aDirtyRect,
46 : const nsDisplayListSet& aLists) override;
47 :
48 : virtual void Reflow(nsPresContext* aPresContext,
49 : ReflowOutput& aDesiredSize,
50 : const ReflowInput& aReflowInput,
51 : nsReflowStatus& aStatus) override;
52 :
53 : #ifdef DEBUG_FRAME_DUMP
54 0 : virtual nsresult GetFrameName(nsAString& aResult) const override {
55 0 : return MakeFrameName(NS_LITERAL_STRING("Range"), aResult);
56 : }
57 : #endif
58 :
59 : #ifdef ACCESSIBILITY
60 : virtual mozilla::a11y::AccType AccessibleType() override;
61 : #endif
62 :
63 : // nsIAnonymousContentCreator
64 : virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
65 : virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
66 : uint32_t aFilter) override;
67 :
68 : virtual nsresult AttributeChanged(int32_t aNameSpaceID,
69 : nsIAtom* aAttribute,
70 : int32_t aModType) override;
71 :
72 : virtual mozilla::LogicalSize
73 : ComputeAutoSize(gfxContext* aRenderingContext,
74 : mozilla::WritingMode aWM,
75 : const mozilla::LogicalSize& aCBSize,
76 : nscoord aAvailableISize,
77 : const mozilla::LogicalSize& aMargin,
78 : const mozilla::LogicalSize& aBorder,
79 : const mozilla::LogicalSize& aPadding,
80 : ComputeSizeFlags aFlags) override;
81 :
82 : virtual nscoord GetMinISize(gfxContext *aRenderingContext) override;
83 : virtual nscoord GetPrefISize(gfxContext *aRenderingContext) override;
84 :
85 0 : virtual bool IsFrameOfType(uint32_t aFlags) const override
86 : {
87 0 : return nsContainerFrame::IsFrameOfType(aFlags &
88 0 : ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
89 : }
90 :
91 : nsStyleContext* GetAdditionalStyleContext(int32_t aIndex) const override;
92 : void SetAdditionalStyleContext(int32_t aIndex,
93 : nsStyleContext* aStyleContext) override;
94 :
95 : /**
96 : * Returns true if the slider's thumb moves horizontally, or else false if it
97 : * moves vertically.
98 : */
99 : bool IsHorizontal() const;
100 :
101 : /**
102 : * Returns true if the slider is oriented along the inline axis.
103 : */
104 0 : bool IsInlineOriented() const {
105 0 : return IsHorizontal() != GetWritingMode().IsVertical();
106 : }
107 :
108 : /**
109 : * Returns true if the slider's thumb moves right-to-left for increasing
110 : * values; only relevant when IsHorizontal() is true.
111 : */
112 0 : bool IsRightToLeft() const {
113 0 : MOZ_ASSERT(IsHorizontal());
114 0 : mozilla::WritingMode wm = GetWritingMode();
115 0 : return wm.IsVertical() ? wm.IsVerticalRL() : !wm.IsBidiLTR();
116 : }
117 :
118 : double GetMin() const;
119 : double GetMax() const;
120 : double GetValue() const;
121 :
122 : /**
123 : * Returns the input element's value as a fraction of the difference between
124 : * the input's minimum and its maximum (i.e. returns 0.0 when the value is
125 : * the same as the minimum, and returns 1.0 when the value is the same as the
126 : * maximum).
127 : */
128 : double GetValueAsFractionOfRange();
129 :
130 : /**
131 : * Returns whether the frame and its child should use the native style.
132 : */
133 : bool ShouldUseNativeStyle() const;
134 :
135 : mozilla::Decimal GetValueAtEventPoint(mozilla::WidgetGUIEvent* aEvent);
136 :
137 : /**
138 : * Helper that's used when the value of the range changes to reposition the
139 : * thumb, resize the range-progress element, and schedule a repaint. (This
140 : * does not reflow, since the position and size of the thumb and
141 : * range-progress element do not affect the position or size of any other
142 : * frames.)
143 : */
144 : void UpdateForValueChange();
145 :
146 : virtual Element* GetPseudoElement(CSSPseudoElementType aType) override;
147 :
148 : private:
149 :
150 : nsresult MakeAnonymousDiv(Element** aResult,
151 : CSSPseudoElementType aPseudoType,
152 : nsTArray<ContentInfo>& aElements);
153 :
154 : // Helper function which reflows the anonymous div frames.
155 : void ReflowAnonymousContent(nsPresContext* aPresContext,
156 : ReflowOutput& aDesiredSize,
157 : const ReflowInput& aReflowInput);
158 :
159 : void DoUpdateThumbPosition(nsIFrame* aThumbFrame,
160 : const nsSize& aRangeSize);
161 :
162 : void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame,
163 : const nsSize& aRangeSize);
164 :
165 : /**
166 : * The div used to show the ::-moz-range-track pseudo-element.
167 : * @see nsRangeFrame::CreateAnonymousContent
168 : */
169 : nsCOMPtr<Element> mTrackDiv;
170 :
171 : /**
172 : * The div used to show the ::-moz-range-progress pseudo-element, which is
173 : * used to (optionally) style the specific chunk of track leading up to the
174 : * thumb's current position.
175 : * @see nsRangeFrame::CreateAnonymousContent
176 : */
177 : nsCOMPtr<Element> mProgressDiv;
178 :
179 : /**
180 : * The div used to show the ::-moz-range-thumb pseudo-element.
181 : * @see nsRangeFrame::CreateAnonymousContent
182 : */
183 : nsCOMPtr<Element> mThumbDiv;
184 :
185 : /**
186 : * Cached style context for -moz-focus-outer CSS pseudo-element style.
187 : */
188 : RefPtr<nsStyleContext> mOuterFocusStyle;
189 :
190 0 : class DummyTouchListener final : public nsIDOMEventListener
191 : {
192 : private:
193 0 : ~DummyTouchListener() {}
194 :
195 : public:
196 : NS_DECL_ISUPPORTS
197 :
198 0 : NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) override
199 : {
200 0 : return NS_OK;
201 : }
202 : };
203 :
204 : /**
205 : * A no-op touch-listener used for APZ purposes (see nsRangeFrame::Init).
206 : */
207 : RefPtr<DummyTouchListener> mDummyTouchListener;
208 : };
209 :
210 : #endif
|