michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsRangeFrame_h___ michael@0: #define nsRangeFrame_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/Decimal.h" michael@0: #include "mozilla/EventForwards.h" michael@0: #include "nsContainerFrame.h" michael@0: #include "nsIAnonymousContentCreator.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: class nsBaseContentList; michael@0: class nsDisplayRangeFocusRing; michael@0: michael@0: class nsRangeFrame : public nsContainerFrame, michael@0: public nsIAnonymousContentCreator michael@0: { michael@0: friend nsIFrame* michael@0: NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: michael@0: friend class nsDisplayRangeFocusRing; michael@0: michael@0: nsRangeFrame(nsStyleContext* aContext); michael@0: virtual ~nsRangeFrame(); michael@0: michael@0: typedef mozilla::dom::Element Element; michael@0: michael@0: public: michael@0: NS_DECL_QUERYFRAME_TARGET(nsRangeFrame) michael@0: NS_DECL_QUERYFRAME michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: // nsIFrame overrides michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) MOZ_OVERRIDE; michael@0: michael@0: virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; michael@0: michael@0: void BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult Reflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aDesiredSize, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) MOZ_OVERRIDE; michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { michael@0: return MakeFrameName(NS_LITERAL_STRING("Range"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: virtual bool IsLeaf() const MOZ_OVERRIDE { return true; } michael@0: michael@0: #ifdef ACCESSIBILITY michael@0: virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: // nsIAnonymousContentCreator michael@0: virtual nsresult CreateAnonymousContent(nsTArray& aElements) MOZ_OVERRIDE; michael@0: virtual void AppendAnonymousContentTo(nsBaseContentList& aElements, michael@0: uint32_t aFilter) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) MOZ_OVERRIDE; michael@0: michael@0: virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext, michael@0: nsSize aCBSize, nscoord aAvailableWidth, michael@0: nsSize aMargin, nsSize aBorder, michael@0: nsSize aPadding, bool aShrinkWrap) MOZ_OVERRIDE; michael@0: michael@0: virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; michael@0: virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; michael@0: michael@0: virtual nsIAtom* GetType() const MOZ_OVERRIDE; michael@0: michael@0: virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE michael@0: { michael@0: return nsContainerFrame::IsFrameOfType(aFlags & michael@0: ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock)); michael@0: } michael@0: michael@0: nsStyleContext* GetAdditionalStyleContext(int32_t aIndex) const MOZ_OVERRIDE; michael@0: void SetAdditionalStyleContext(int32_t aIndex, michael@0: nsStyleContext* aStyleContext) MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Returns true if the slider's thumb moves horizontally, or else false if it michael@0: * moves vertically. michael@0: * michael@0: * aOverrideFrameSize If specified, this will be used instead of the size of michael@0: * the frame's rect (i.e. the frame's border-box size) if the frame's michael@0: * rect would have otherwise been examined. This should only be specified michael@0: * during reflow when the frame's [new] border-box size has not yet been michael@0: * stored in its mRect. michael@0: */ michael@0: bool IsHorizontal(const nsSize *aFrameSizeOverride = nullptr) const; michael@0: michael@0: double GetMin() const; michael@0: double GetMax() const; michael@0: double GetValue() const; michael@0: michael@0: /** michael@0: * Returns the input element's value as a fraction of the difference between michael@0: * the input's minimum and its maximum (i.e. returns 0.0 when the value is michael@0: * the same as the minimum, and returns 1.0 when the value is the same as the michael@0: * maximum). michael@0: */ michael@0: double GetValueAsFractionOfRange(); michael@0: michael@0: /** michael@0: * Returns whether the frame and its child should use the native style. michael@0: */ michael@0: bool ShouldUseNativeStyle() const; michael@0: michael@0: mozilla::Decimal GetValueAtEventPoint(mozilla::WidgetGUIEvent* aEvent); michael@0: michael@0: /** michael@0: * Helper that's used when the value of the range changes to reposition the michael@0: * thumb, resize the range-progress element, and schedule a repaint. (This michael@0: * does not reflow, since the position and size of the thumb and michael@0: * range-progress element do not affect the position or size of any other michael@0: * frames.) michael@0: */ michael@0: void UpdateForValueChange(); michael@0: michael@0: virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: michael@0: nsresult MakeAnonymousDiv(Element** aResult, michael@0: nsCSSPseudoElements::Type aPseudoType, michael@0: nsTArray& aElements); michael@0: michael@0: // Helper function which reflows the anonymous div frames. michael@0: nsresult ReflowAnonymousContent(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aDesiredSize, michael@0: const nsHTMLReflowState& aReflowState); michael@0: michael@0: void DoUpdateThumbPosition(nsIFrame* aThumbFrame, michael@0: const nsSize& aRangeSize); michael@0: michael@0: void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame, michael@0: const nsSize& aRangeSize); michael@0: michael@0: /** michael@0: * The div used to show the ::-moz-range-track pseudo-element. michael@0: * @see nsRangeFrame::CreateAnonymousContent michael@0: */ michael@0: nsCOMPtr mTrackDiv; michael@0: michael@0: /** michael@0: * The div used to show the ::-moz-range-progress pseudo-element, which is michael@0: * used to (optionally) style the specific chunk of track leading up to the michael@0: * thumb's current position. michael@0: * @see nsRangeFrame::CreateAnonymousContent michael@0: */ michael@0: nsCOMPtr mProgressDiv; michael@0: michael@0: /** michael@0: * The div used to show the ::-moz-range-thumb pseudo-element. michael@0: * @see nsRangeFrame::CreateAnonymousContent michael@0: */ michael@0: nsCOMPtr mThumbDiv; michael@0: michael@0: /** michael@0: * Cached style context for -moz-focus-outer CSS pseudo-element style. michael@0: */ michael@0: nsRefPtr mOuterFocusStyle; michael@0: }; michael@0: michael@0: #endif