2013-02-16 17:57:21 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef nsRangeFrame_h___
|
|
|
|
#define nsRangeFrame_h___
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2013-05-05 23:23:18 +00:00
|
|
|
#include "mozilla/Decimal.h"
|
2013-09-24 10:04:14 +00:00
|
|
|
#include "mozilla/EventForwards.h"
|
2013-02-16 17:57:21 +00:00
|
|
|
#include "nsContainerFrame.h"
|
|
|
|
#include "nsIAnonymousContentCreator.h"
|
2015-01-13 14:06:37 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
2013-02-16 17:57:21 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2014-02-18 23:35:07 +00:00
|
|
|
class nsDisplayRangeFocusRing;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
|
|
|
class nsRangeFrame : public nsContainerFrame,
|
|
|
|
public nsIAnonymousContentCreator
|
|
|
|
{
|
2013-02-16 17:57:21 +00:00
|
|
|
friend nsIFrame*
|
|
|
|
NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|
|
|
|
2014-02-18 23:35:07 +00:00
|
|
|
friend class nsDisplayRangeFocusRing;
|
|
|
|
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit nsRangeFrame(nsStyleContext* aContext);
|
2013-02-16 17:57:21 +00:00
|
|
|
virtual ~nsRangeFrame();
|
|
|
|
|
2016-02-17 20:37:00 +00:00
|
|
|
typedef mozilla::CSSPseudoElementType CSSPseudoElementType;
|
2013-12-03 04:49:03 +00:00
|
|
|
typedef mozilla::dom::Element Element;
|
|
|
|
|
2013-02-16 17:57:21 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsRangeFrame)
|
|
|
|
NS_DECL_QUERYFRAME
|
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
|
|
|
// nsIFrame overrides
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2013-04-11 09:11:54 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2013-02-16 17:57:21 +00:00
|
|
|
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
2015-03-21 16:28:04 +00:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2014-05-13 00:47:52 +00:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsReflowStatus& aStatus) override;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override {
|
2013-02-16 17:57:21 +00:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Range"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool IsLeaf() const override { return true; }
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2013-04-28 00:54:54 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual mozilla::a11y::AccType AccessibleType() override;
|
2013-04-28 00:54:54 +00:00
|
|
|
#endif
|
|
|
|
|
2013-02-16 17:57:21 +00:00
|
|
|
// nsIAnonymousContentCreator
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
|
2014-07-16 18:41:57 +00:00
|
|
|
virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
2015-03-21 16:28:04 +00:00
|
|
|
uint32_t aFilter) override;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 08:36:33 +00:00
|
|
|
nsIAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
int32_t aModType) override;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2014-08-24 14:34:51 +00:00
|
|
|
virtual mozilla::LogicalSize
|
|
|
|
ComputeAutoSize(nsRenderingContext *aRenderingContext,
|
|
|
|
mozilla::WritingMode aWritingMode,
|
|
|
|
const mozilla::LogicalSize& aCBSize,
|
|
|
|
nscoord aAvailableISize,
|
|
|
|
const mozilla::LogicalSize& aMargin,
|
|
|
|
const mozilla::LogicalSize& aBorder,
|
|
|
|
const mozilla::LogicalSize& aPadding,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aShrinkWrap) override;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override;
|
|
|
|
virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) override;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsIAtom* GetType() const override;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override
|
2013-02-16 17:57:21 +00:00
|
|
|
{
|
|
|
|
return nsContainerFrame::IsFrameOfType(aFlags &
|
|
|
|
~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
nsStyleContext* GetAdditionalStyleContext(int32_t aIndex) const override;
|
2014-02-18 23:35:07 +00:00
|
|
|
void SetAdditionalStyleContext(int32_t aIndex,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsStyleContext* aStyleContext) override;
|
2014-02-18 23:35:07 +00:00
|
|
|
|
2013-02-16 17:57:21 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the slider's thumb moves horizontally, or else false if it
|
|
|
|
* moves vertically.
|
|
|
|
*/
|
2015-04-29 07:18:54 +00:00
|
|
|
bool IsHorizontal() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the slider is oriented along the inline axis.
|
|
|
|
*/
|
|
|
|
bool IsInlineOriented() const {
|
|
|
|
return IsHorizontal() != GetWritingMode().IsVertical();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the slider's thumb moves right-to-left for increasing
|
|
|
|
* values; only relevant when IsHorizontal() is true.
|
|
|
|
*/
|
|
|
|
bool IsRightToLeft() const {
|
|
|
|
MOZ_ASSERT(IsHorizontal());
|
|
|
|
mozilla::WritingMode wm = GetWritingMode();
|
|
|
|
return wm.IsVertical() ? wm.IsVerticalRL() : !wm.IsBidiLTR();
|
|
|
|
}
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2013-03-16 05:40:15 +00:00
|
|
|
double GetMin() const;
|
|
|
|
double GetMax() const;
|
|
|
|
double GetValue() const;
|
|
|
|
|
2013-04-16 23:50:26 +00:00
|
|
|
/**
|
|
|
|
* Returns the input element's value as a fraction of the difference between
|
|
|
|
* the input's minimum and its maximum (i.e. returns 0.0 when the value is
|
|
|
|
* the same as the minimum, and returns 1.0 when the value is the same as the
|
|
|
|
* maximum).
|
|
|
|
*/
|
|
|
|
double GetValueAsFractionOfRange();
|
|
|
|
|
2013-02-16 17:57:21 +00:00
|
|
|
/**
|
|
|
|
* Returns whether the frame and its child should use the native style.
|
|
|
|
*/
|
|
|
|
bool ShouldUseNativeStyle() const;
|
|
|
|
|
2013-10-02 03:46:03 +00:00
|
|
|
mozilla::Decimal GetValueAtEventPoint(mozilla::WidgetGUIEvent* aEvent);
|
2013-03-08 09:40:12 +00:00
|
|
|
|
2013-03-13 11:48:27 +00:00
|
|
|
/**
|
2013-03-26 23:04:41 +00:00
|
|
|
* Helper that's used when the value of the range changes to reposition the
|
|
|
|
* thumb, resize the range-progress element, and schedule a repaint. (This
|
|
|
|
* does not reflow, since the position and size of the thumb and
|
|
|
|
* range-progress element do not affect the position or size of any other
|
|
|
|
* frames.)
|
2013-03-13 11:48:27 +00:00
|
|
|
*/
|
2013-03-26 23:04:41 +00:00
|
|
|
void UpdateForValueChange();
|
2013-03-13 11:48:27 +00:00
|
|
|
|
2016-02-17 20:37:00 +00:00
|
|
|
virtual Element* GetPseudoElement(CSSPseudoElementType aType) override;
|
2013-12-02 23:57:50 +00:00
|
|
|
|
2013-02-16 17:57:21 +00:00
|
|
|
private:
|
|
|
|
|
2013-12-03 04:49:03 +00:00
|
|
|
nsresult MakeAnonymousDiv(Element** aResult,
|
2016-02-17 20:37:00 +00:00
|
|
|
CSSPseudoElementType aPseudoType,
|
2013-03-26 23:04:41 +00:00
|
|
|
nsTArray<ContentInfo>& aElements);
|
|
|
|
|
2013-02-16 17:57:21 +00:00
|
|
|
// Helper function which reflows the anonymous div frames.
|
2014-05-13 00:47:52 +00:00
|
|
|
void ReflowAnonymousContent(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState);
|
2013-02-16 17:57:21 +00:00
|
|
|
|
2013-03-15 09:04:54 +00:00
|
|
|
void DoUpdateThumbPosition(nsIFrame* aThumbFrame,
|
|
|
|
const nsSize& aRangeSize);
|
|
|
|
|
2013-03-26 23:04:41 +00:00
|
|
|
void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame,
|
|
|
|
const nsSize& aRangeSize);
|
|
|
|
|
2013-02-16 17:57:21 +00:00
|
|
|
/**
|
2013-03-26 23:04:41 +00:00
|
|
|
* The div used to show the ::-moz-range-track pseudo-element.
|
2013-02-16 17:57:21 +00:00
|
|
|
* @see nsRangeFrame::CreateAnonymousContent
|
|
|
|
*/
|
2013-12-03 04:49:03 +00:00
|
|
|
nsCOMPtr<Element> mTrackDiv;
|
2013-02-16 17:57:21 +00:00
|
|
|
|
|
|
|
/**
|
2013-03-26 23:04:41 +00:00
|
|
|
* The div used to show the ::-moz-range-progress pseudo-element, which is
|
|
|
|
* used to (optionally) style the specific chunk of track leading up to the
|
|
|
|
* thumb's current position.
|
|
|
|
* @see nsRangeFrame::CreateAnonymousContent
|
|
|
|
*/
|
2013-12-03 04:49:03 +00:00
|
|
|
nsCOMPtr<Element> mProgressDiv;
|
2013-03-26 23:04:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The div used to show the ::-moz-range-thumb pseudo-element.
|
2013-02-16 17:57:21 +00:00
|
|
|
* @see nsRangeFrame::CreateAnonymousContent
|
|
|
|
*/
|
2013-12-03 04:49:03 +00:00
|
|
|
nsCOMPtr<Element> mThumbDiv;
|
2014-02-18 23:35:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cached style context for -moz-focus-outer CSS pseudo-element style.
|
|
|
|
*/
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsStyleContext> mOuterFocusStyle;
|
2015-01-13 14:06:37 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class DummyTouchListener final : public nsIDOMEventListener
|
2015-01-13 14:06:37 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
~DummyTouchListener() {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) override
|
2015-01-13 14:06:37 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A no-op touch-listener used for APZ purposes (see nsRangeFrame::Init).
|
|
|
|
*/
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DummyTouchListener> mDummyTouchListener;
|
2013-02-16 17:57:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|