1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/forms/nsRangeFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,179 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsRangeFrame_h___ 1.10 +#define nsRangeFrame_h___ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "mozilla/Decimal.h" 1.14 +#include "mozilla/EventForwards.h" 1.15 +#include "nsContainerFrame.h" 1.16 +#include "nsIAnonymousContentCreator.h" 1.17 +#include "nsCOMPtr.h" 1.18 + 1.19 +class nsBaseContentList; 1.20 +class nsDisplayRangeFocusRing; 1.21 + 1.22 +class nsRangeFrame : public nsContainerFrame, 1.23 + public nsIAnonymousContentCreator 1.24 +{ 1.25 + friend nsIFrame* 1.26 + NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); 1.27 + 1.28 + friend class nsDisplayRangeFocusRing; 1.29 + 1.30 + nsRangeFrame(nsStyleContext* aContext); 1.31 + virtual ~nsRangeFrame(); 1.32 + 1.33 + typedef mozilla::dom::Element Element; 1.34 + 1.35 +public: 1.36 + NS_DECL_QUERYFRAME_TARGET(nsRangeFrame) 1.37 + NS_DECL_QUERYFRAME 1.38 + NS_DECL_FRAMEARENA_HELPERS 1.39 + 1.40 + // nsIFrame overrides 1.41 + virtual void Init(nsIContent* aContent, 1.42 + nsIFrame* aParent, 1.43 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.44 + 1.45 + virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; 1.46 + 1.47 + void BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.48 + const nsRect& aDirtyRect, 1.49 + const nsDisplayListSet& aLists) MOZ_OVERRIDE; 1.50 + 1.51 + virtual nsresult Reflow(nsPresContext* aPresContext, 1.52 + nsHTMLReflowMetrics& aDesiredSize, 1.53 + const nsHTMLReflowState& aReflowState, 1.54 + nsReflowStatus& aStatus) MOZ_OVERRIDE; 1.55 + 1.56 +#ifdef DEBUG_FRAME_DUMP 1.57 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { 1.58 + return MakeFrameName(NS_LITERAL_STRING("Range"), aResult); 1.59 + } 1.60 +#endif 1.61 + 1.62 + virtual bool IsLeaf() const MOZ_OVERRIDE { return true; } 1.63 + 1.64 +#ifdef ACCESSIBILITY 1.65 + virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; 1.66 +#endif 1.67 + 1.68 + // nsIAnonymousContentCreator 1.69 + virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE; 1.70 + virtual void AppendAnonymousContentTo(nsBaseContentList& aElements, 1.71 + uint32_t aFilter) MOZ_OVERRIDE; 1.72 + 1.73 + virtual nsresult AttributeChanged(int32_t aNameSpaceID, 1.74 + nsIAtom* aAttribute, 1.75 + int32_t aModType) MOZ_OVERRIDE; 1.76 + 1.77 + virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext, 1.78 + nsSize aCBSize, nscoord aAvailableWidth, 1.79 + nsSize aMargin, nsSize aBorder, 1.80 + nsSize aPadding, bool aShrinkWrap) MOZ_OVERRIDE; 1.81 + 1.82 + virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; 1.83 + virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; 1.84 + 1.85 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.86 + 1.87 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.88 + { 1.89 + return nsContainerFrame::IsFrameOfType(aFlags & 1.90 + ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock)); 1.91 + } 1.92 + 1.93 + nsStyleContext* GetAdditionalStyleContext(int32_t aIndex) const MOZ_OVERRIDE; 1.94 + void SetAdditionalStyleContext(int32_t aIndex, 1.95 + nsStyleContext* aStyleContext) MOZ_OVERRIDE; 1.96 + 1.97 + /** 1.98 + * Returns true if the slider's thumb moves horizontally, or else false if it 1.99 + * moves vertically. 1.100 + * 1.101 + * aOverrideFrameSize If specified, this will be used instead of the size of 1.102 + * the frame's rect (i.e. the frame's border-box size) if the frame's 1.103 + * rect would have otherwise been examined. This should only be specified 1.104 + * during reflow when the frame's [new] border-box size has not yet been 1.105 + * stored in its mRect. 1.106 + */ 1.107 + bool IsHorizontal(const nsSize *aFrameSizeOverride = nullptr) const; 1.108 + 1.109 + double GetMin() const; 1.110 + double GetMax() const; 1.111 + double GetValue() const; 1.112 + 1.113 + /** 1.114 + * Returns the input element's value as a fraction of the difference between 1.115 + * the input's minimum and its maximum (i.e. returns 0.0 when the value is 1.116 + * the same as the minimum, and returns 1.0 when the value is the same as the 1.117 + * maximum). 1.118 + */ 1.119 + double GetValueAsFractionOfRange(); 1.120 + 1.121 + /** 1.122 + * Returns whether the frame and its child should use the native style. 1.123 + */ 1.124 + bool ShouldUseNativeStyle() const; 1.125 + 1.126 + mozilla::Decimal GetValueAtEventPoint(mozilla::WidgetGUIEvent* aEvent); 1.127 + 1.128 + /** 1.129 + * Helper that's used when the value of the range changes to reposition the 1.130 + * thumb, resize the range-progress element, and schedule a repaint. (This 1.131 + * does not reflow, since the position and size of the thumb and 1.132 + * range-progress element do not affect the position or size of any other 1.133 + * frames.) 1.134 + */ 1.135 + void UpdateForValueChange(); 1.136 + 1.137 + virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE; 1.138 + 1.139 +private: 1.140 + 1.141 + nsresult MakeAnonymousDiv(Element** aResult, 1.142 + nsCSSPseudoElements::Type aPseudoType, 1.143 + nsTArray<ContentInfo>& aElements); 1.144 + 1.145 + // Helper function which reflows the anonymous div frames. 1.146 + nsresult ReflowAnonymousContent(nsPresContext* aPresContext, 1.147 + nsHTMLReflowMetrics& aDesiredSize, 1.148 + const nsHTMLReflowState& aReflowState); 1.149 + 1.150 + void DoUpdateThumbPosition(nsIFrame* aThumbFrame, 1.151 + const nsSize& aRangeSize); 1.152 + 1.153 + void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame, 1.154 + const nsSize& aRangeSize); 1.155 + 1.156 + /** 1.157 + * The div used to show the ::-moz-range-track pseudo-element. 1.158 + * @see nsRangeFrame::CreateAnonymousContent 1.159 + */ 1.160 + nsCOMPtr<Element> mTrackDiv; 1.161 + 1.162 + /** 1.163 + * The div used to show the ::-moz-range-progress pseudo-element, which is 1.164 + * used to (optionally) style the specific chunk of track leading up to the 1.165 + * thumb's current position. 1.166 + * @see nsRangeFrame::CreateAnonymousContent 1.167 + */ 1.168 + nsCOMPtr<Element> mProgressDiv; 1.169 + 1.170 + /** 1.171 + * The div used to show the ::-moz-range-thumb pseudo-element. 1.172 + * @see nsRangeFrame::CreateAnonymousContent 1.173 + */ 1.174 + nsCOMPtr<Element> mThumbDiv; 1.175 + 1.176 + /** 1.177 + * Cached style context for -moz-focus-outer CSS pseudo-element style. 1.178 + */ 1.179 + nsRefPtr<nsStyleContext> mOuterFocusStyle; 1.180 +}; 1.181 + 1.182 +#endif