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/. */
6 #ifndef nsRangeFrame_h___
7 #define nsRangeFrame_h___
9 #include "mozilla/Attributes.h"
10 #include "nsContainerFrame.h"
11 #include "nsIAnonymousContentCreator.h"
14 class nsBaseContentList
;
17 class nsRangeFrame
: public nsContainerFrame
,
18 public nsIAnonymousContentCreator
21 NS_NewRangeFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
23 nsRangeFrame(nsStyleContext
* aContext
);
24 virtual ~nsRangeFrame();
27 NS_DECL_QUERYFRAME_TARGET(nsRangeFrame
)
29 NS_DECL_FRAMEARENA_HELPERS
32 virtual void DestroyFrom(nsIFrame
* aDestructRoot
) MOZ_OVERRIDE
;
34 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
35 const nsRect
& aDirtyRect
,
36 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
38 NS_IMETHOD
Reflow(nsPresContext
* aPresContext
,
39 nsHTMLReflowMetrics
& aDesiredSize
,
40 const nsHTMLReflowState
& aReflowState
,
41 nsReflowStatus
& aStatus
) MOZ_OVERRIDE
;
44 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
{
45 return MakeFrameName(NS_LITERAL_STRING("Range"), aResult
);
49 virtual bool IsLeaf() const MOZ_OVERRIDE
{ return true; }
51 // nsIAnonymousContentCreator
52 virtual nsresult
CreateAnonymousContent(nsTArray
<ContentInfo
>& aElements
) MOZ_OVERRIDE
;
53 virtual void AppendAnonymousContentTo(nsBaseContentList
& aElements
,
54 uint32_t aFilter
) MOZ_OVERRIDE
;
56 NS_IMETHOD
AttributeChanged(int32_t aNameSpaceID
,
58 int32_t aModType
) MOZ_OVERRIDE
;
60 virtual nsSize
ComputeAutoSize(nsRenderingContext
*aRenderingContext
,
61 nsSize aCBSize
, nscoord aAvailableWidth
,
62 nsSize aMargin
, nsSize aBorder
,
63 nsSize aPadding
, bool aShrinkWrap
) MOZ_OVERRIDE
;
65 virtual nscoord
GetMinWidth(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
66 virtual nscoord
GetPrefWidth(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
68 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
70 virtual bool IsFrameOfType(uint32_t aFlags
) const MOZ_OVERRIDE
72 return nsContainerFrame::IsFrameOfType(aFlags
&
73 ~(nsIFrame::eReplaced
| nsIFrame::eReplacedContainsBlock
));
77 * Returns true if the slider's thumb moves horizontally, or else false if it
80 * aOverrideFrameSize If specified, this will be used instead of the size of
81 * the frame's rect (i.e. the frame's border-box size) if the frame's
82 * rect would have otherwise been examined. This should only be specified
83 * during reflow when the frame's [new] border-box size has not yet been
84 * stored in its mRect.
86 bool IsHorizontal(const nsSize
*aFrameSizeOverride
= nullptr) const;
88 double GetMin() const;
89 double GetMax() const;
90 double GetValue() const;
93 * Returns whether the frame and its child should use the native style.
95 bool ShouldUseNativeStyle() const;
97 double GetValueAtEventPoint(nsGUIEvent
* aEvent
);
100 * Helper to reposition the thumb and schedule a repaint when the value of
101 * the range changes. (This does not reflow, since the position and size of
102 * the thumb do not affect the position or size of any other frames.)
104 void UpdateThumbPositionForValueChange();
108 // Helper function which reflows the anonymous div frames.
109 nsresult
ReflowAnonymousContent(nsPresContext
* aPresContext
,
110 nsHTMLReflowMetrics
& aDesiredSize
,
111 const nsHTMLReflowState
& aReflowState
);
113 void DoUpdateThumbPosition(nsIFrame
* aThumbFrame
,
114 const nsSize
& aRangeSize
);
117 * Returns the input element's value as a fraction of the difference between
118 * the input's minimum and its maximum (i.e. returns 0.0 when the value is
119 * the same as the minimum, and returns 1.0 when the value is the same as the
122 double GetValueAsFractionOfRange();
125 * The div used to show the track.
126 * @see nsRangeFrame::CreateAnonymousContent
128 nsCOMPtr
<nsIContent
> mTrackDiv
;
131 * The div used to show the thumb.
132 * @see nsRangeFrame::CreateAnonymousContent
134 nsCOMPtr
<nsIContent
> mThumbDiv
;