|
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 "nsCOMPtr.h" |
|
15 |
|
16 class nsBaseContentList; |
|
17 class nsDisplayRangeFocusRing; |
|
18 |
|
19 class nsRangeFrame : public nsContainerFrame, |
|
20 public nsIAnonymousContentCreator |
|
21 { |
|
22 friend nsIFrame* |
|
23 NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
24 |
|
25 friend class nsDisplayRangeFocusRing; |
|
26 |
|
27 nsRangeFrame(nsStyleContext* aContext); |
|
28 virtual ~nsRangeFrame(); |
|
29 |
|
30 typedef mozilla::dom::Element Element; |
|
31 |
|
32 public: |
|
33 NS_DECL_QUERYFRAME_TARGET(nsRangeFrame) |
|
34 NS_DECL_QUERYFRAME |
|
35 NS_DECL_FRAMEARENA_HELPERS |
|
36 |
|
37 // nsIFrame overrides |
|
38 virtual void Init(nsIContent* aContent, |
|
39 nsIFrame* aParent, |
|
40 nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
|
41 |
|
42 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
|
43 |
|
44 void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
45 const nsRect& aDirtyRect, |
|
46 const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
|
47 |
|
48 virtual nsresult Reflow(nsPresContext* aPresContext, |
|
49 nsHTMLReflowMetrics& aDesiredSize, |
|
50 const nsHTMLReflowState& aReflowState, |
|
51 nsReflowStatus& aStatus) MOZ_OVERRIDE; |
|
52 |
|
53 #ifdef DEBUG_FRAME_DUMP |
|
54 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { |
|
55 return MakeFrameName(NS_LITERAL_STRING("Range"), aResult); |
|
56 } |
|
57 #endif |
|
58 |
|
59 virtual bool IsLeaf() const MOZ_OVERRIDE { return true; } |
|
60 |
|
61 #ifdef ACCESSIBILITY |
|
62 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; |
|
63 #endif |
|
64 |
|
65 // nsIAnonymousContentCreator |
|
66 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE; |
|
67 virtual void AppendAnonymousContentTo(nsBaseContentList& aElements, |
|
68 uint32_t aFilter) MOZ_OVERRIDE; |
|
69 |
|
70 virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
|
71 nsIAtom* aAttribute, |
|
72 int32_t aModType) MOZ_OVERRIDE; |
|
73 |
|
74 virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext, |
|
75 nsSize aCBSize, nscoord aAvailableWidth, |
|
76 nsSize aMargin, nsSize aBorder, |
|
77 nsSize aPadding, bool aShrinkWrap) MOZ_OVERRIDE; |
|
78 |
|
79 virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; |
|
80 virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; |
|
81 |
|
82 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
83 |
|
84 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
85 { |
|
86 return nsContainerFrame::IsFrameOfType(aFlags & |
|
87 ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock)); |
|
88 } |
|
89 |
|
90 nsStyleContext* GetAdditionalStyleContext(int32_t aIndex) const MOZ_OVERRIDE; |
|
91 void SetAdditionalStyleContext(int32_t aIndex, |
|
92 nsStyleContext* aStyleContext) MOZ_OVERRIDE; |
|
93 |
|
94 /** |
|
95 * Returns true if the slider's thumb moves horizontally, or else false if it |
|
96 * moves vertically. |
|
97 * |
|
98 * aOverrideFrameSize If specified, this will be used instead of the size of |
|
99 * the frame's rect (i.e. the frame's border-box size) if the frame's |
|
100 * rect would have otherwise been examined. This should only be specified |
|
101 * during reflow when the frame's [new] border-box size has not yet been |
|
102 * stored in its mRect. |
|
103 */ |
|
104 bool IsHorizontal(const nsSize *aFrameSizeOverride = nullptr) const; |
|
105 |
|
106 double GetMin() const; |
|
107 double GetMax() const; |
|
108 double GetValue() const; |
|
109 |
|
110 /** |
|
111 * Returns the input element's value as a fraction of the difference between |
|
112 * the input's minimum and its maximum (i.e. returns 0.0 when the value is |
|
113 * the same as the minimum, and returns 1.0 when the value is the same as the |
|
114 * maximum). |
|
115 */ |
|
116 double GetValueAsFractionOfRange(); |
|
117 |
|
118 /** |
|
119 * Returns whether the frame and its child should use the native style. |
|
120 */ |
|
121 bool ShouldUseNativeStyle() const; |
|
122 |
|
123 mozilla::Decimal GetValueAtEventPoint(mozilla::WidgetGUIEvent* aEvent); |
|
124 |
|
125 /** |
|
126 * Helper that's used when the value of the range changes to reposition the |
|
127 * thumb, resize the range-progress element, and schedule a repaint. (This |
|
128 * does not reflow, since the position and size of the thumb and |
|
129 * range-progress element do not affect the position or size of any other |
|
130 * frames.) |
|
131 */ |
|
132 void UpdateForValueChange(); |
|
133 |
|
134 virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE; |
|
135 |
|
136 private: |
|
137 |
|
138 nsresult MakeAnonymousDiv(Element** aResult, |
|
139 nsCSSPseudoElements::Type aPseudoType, |
|
140 nsTArray<ContentInfo>& aElements); |
|
141 |
|
142 // Helper function which reflows the anonymous div frames. |
|
143 nsresult ReflowAnonymousContent(nsPresContext* aPresContext, |
|
144 nsHTMLReflowMetrics& aDesiredSize, |
|
145 const nsHTMLReflowState& aReflowState); |
|
146 |
|
147 void DoUpdateThumbPosition(nsIFrame* aThumbFrame, |
|
148 const nsSize& aRangeSize); |
|
149 |
|
150 void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame, |
|
151 const nsSize& aRangeSize); |
|
152 |
|
153 /** |
|
154 * The div used to show the ::-moz-range-track pseudo-element. |
|
155 * @see nsRangeFrame::CreateAnonymousContent |
|
156 */ |
|
157 nsCOMPtr<Element> mTrackDiv; |
|
158 |
|
159 /** |
|
160 * The div used to show the ::-moz-range-progress pseudo-element, which is |
|
161 * used to (optionally) style the specific chunk of track leading up to the |
|
162 * thumb's current position. |
|
163 * @see nsRangeFrame::CreateAnonymousContent |
|
164 */ |
|
165 nsCOMPtr<Element> mProgressDiv; |
|
166 |
|
167 /** |
|
168 * The div used to show the ::-moz-range-thumb pseudo-element. |
|
169 * @see nsRangeFrame::CreateAnonymousContent |
|
170 */ |
|
171 nsCOMPtr<Element> mThumbDiv; |
|
172 |
|
173 /** |
|
174 * Cached style context for -moz-focus-outer CSS pseudo-element style. |
|
175 */ |
|
176 nsRefPtr<nsStyleContext> mOuterFocusStyle; |
|
177 }; |
|
178 |
|
179 #endif |