2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-02-16 21:57:21 +04:00
|
|
|
/* 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-06 03:23:18 +04:00
|
|
|
#include "mozilla/Decimal.h"
|
2013-09-24 14:04:14 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
2013-02-16 21:57:21 +04:00
|
|
|
#include "nsContainerFrame.h"
|
|
|
|
#include "nsIAnonymousContentCreator.h"
|
2015-01-13 17:06:37 +03:00
|
|
|
#include "nsIDOMEventListener.h"
|
2013-02-16 21:57:21 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2014-02-19 03:35:07 +04:00
|
|
|
class nsDisplayRangeFocusRing;
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2018-04-20 07:49:29 +03:00
|
|
|
namespace mozilla {
|
2019-04-16 10:24:49 +03:00
|
|
|
class PresShell;
|
2018-04-20 07:49:29 +03:00
|
|
|
namespace dom {
|
|
|
|
class Event;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
class nsRangeFrame final : public nsContainerFrame,
|
|
|
|
public nsIAnonymousContentCreator {
|
2019-04-16 10:24:49 +03:00
|
|
|
friend nsIFrame* NS_NewRangeFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2014-02-19 03:35:07 +04:00
|
|
|
friend class nsDisplayRangeFocusRing;
|
|
|
|
|
2019-02-05 19:45:54 +03:00
|
|
|
explicit nsRangeFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
|
2013-02-16 21:57:21 +04:00
|
|
|
virtual ~nsRangeFrame();
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
typedef mozilla::PseudoStyleType PseudoStyleType;
|
2013-12-03 08:49:03 +04:00
|
|
|
typedef mozilla::dom::Element Element;
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_QUERYFRAME
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsRangeFrame)
|
2013-02-16 21:57:21 +04:00
|
|
|
|
|
|
|
// nsIFrame overrides
|
2014-05-25 02:20:40 +04:00
|
|
|
virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2013-04-11 13:11:54 +04:00
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) override;
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsReflowStatus& aStatus) override;
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override {
|
2013-02-16 21:57:21 +04:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Range"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-28 04:54:54 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual mozilla::a11y::AccType AccessibleType() override;
|
2013-04-28 04:54:54 +04:00
|
|
|
#endif
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
// nsIAnonymousContentCreator
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult CreateAnonymousContent(
|
|
|
|
nsTArray<ContentInfo>& aElements) override;
|
2014-07-16 22:41:57 +04:00
|
|
|
virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aFilter) override;
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t aModType) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-24 18:34:51 +04:00
|
|
|
virtual mozilla::LogicalSize ComputeAutoSize(
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aRenderingContext, mozilla::WritingMode aWM,
|
2014-08-24 18:34:51 +04:00
|
|
|
const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
|
|
|
|
const mozilla::LogicalSize& aMargin, const mozilla::LogicalSize& aBorder,
|
|
|
|
const mozilla::LogicalSize& aPadding, ComputeSizeFlags aFlags) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
|
|
|
|
virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override {
|
2013-02-16 21:57:21 +04:00
|
|
|
return nsContainerFrame::IsFrameOfType(
|
|
|
|
aFlags & ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
|
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* GetAdditionalComputedStyle(int32_t aIndex) const override;
|
|
|
|
void SetAdditionalComputedStyle(int32_t aIndex,
|
|
|
|
ComputedStyle* aComputedStyle) override;
|
2014-02-19 03:35:07 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the slider's thumb moves horizontally, or else false if it
|
|
|
|
* moves vertically.
|
|
|
|
*/
|
2015-04-29 10:18:54 +03: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 21:57:21 +04:00
|
|
|
|
2013-03-16 09:40:15 +04:00
|
|
|
double GetMin() const;
|
|
|
|
double GetMax() const;
|
|
|
|
double GetValue() const;
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
/**
|
2013-04-17 03:50:26 +04: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
|
2017-07-06 15:00:35 +03:00
|
|
|
* the same as the minimum, and returns 1.0 when the value is the same as the
|
2013-04-17 03:50:26 +04:00
|
|
|
* maximum).
|
2017-07-06 15:00:35 +03:00
|
|
|
*/
|
2013-04-17 03:50:26 +04:00
|
|
|
double GetValueAsFractionOfRange();
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
/**
|
|
|
|
* Returns whether the frame and its child should use the native style.
|
|
|
|
*/
|
|
|
|
bool ShouldUseNativeStyle() const;
|
|
|
|
|
2013-10-02 07:46:03 +04:00
|
|
|
mozilla::Decimal GetValueAtEventPoint(mozilla::WidgetGUIEvent* aEvent);
|
2013-03-08 13:40:12 +04:00
|
|
|
|
2013-03-13 15:48:27 +04:00
|
|
|
/**
|
2013-03-27 03:04:41 +04: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 15:48:27 +04:00
|
|
|
*/
|
2013-03-27 03:04:41 +04:00
|
|
|
void UpdateForValueChange();
|
2013-03-13 15:48:27 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
private:
|
2019-02-15 03:53:23 +03:00
|
|
|
// Return our preferred size in the cross-axis (the axis perpendicular
|
|
|
|
// to the direction of movement of the thumb).
|
|
|
|
nscoord AutoCrossSize(nscoord aEm);
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
nsresult MakeAnonymousDiv(Element** aResult, PseudoStyleType aPseudoType,
|
2013-03-27 03:04:41 +04:00
|
|
|
nsTArray<ContentInfo>& aElements);
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
// Helper function which reflows the anonymous div frames.
|
2014-05-13 04:47:52 +04:00
|
|
|
void ReflowAnonymousContent(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-15 13:04:54 +04:00
|
|
|
void DoUpdateThumbPosition(nsIFrame* aThumbFrame, const nsSize& aRangeSize);
|
|
|
|
|
2013-03-27 03:04:41 +04:00
|
|
|
void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame,
|
|
|
|
const nsSize& aRangeSize);
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
/**
|
2013-03-27 03:04:41 +04:00
|
|
|
* The div used to show the ::-moz-range-track pseudo-element.
|
2013-02-16 21:57:21 +04:00
|
|
|
* @see nsRangeFrame::CreateAnonymousContent
|
|
|
|
*/
|
2013-12-03 08:49:03 +04:00
|
|
|
nsCOMPtr<Element> mTrackDiv;
|
2013-02-16 21:57:21 +04:00
|
|
|
|
|
|
|
/**
|
2013-03-27 03:04:41 +04: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 08:49:03 +04:00
|
|
|
nsCOMPtr<Element> mProgressDiv;
|
2013-03-27 03:04:41 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The div used to show the ::-moz-range-thumb pseudo-element.
|
2013-02-16 21:57:21 +04:00
|
|
|
* @see nsRangeFrame::CreateAnonymousContent
|
|
|
|
*/
|
2013-12-03 08:49:03 +04:00
|
|
|
nsCOMPtr<Element> mThumbDiv;
|
2014-02-19 03:35:07 +04:00
|
|
|
|
|
|
|
/**
|
2018-03-23 16:49:21 +03:00
|
|
|
* Cached ComputedStyle for -moz-focus-outer CSS pseudo-element style.
|
2014-02-19 03:35:07 +04:00
|
|
|
*/
|
2018-03-22 21:20:41 +03:00
|
|
|
RefPtr<ComputedStyle> mOuterFocusStyle;
|
2015-01-13 17:06:37 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DummyTouchListener final : public nsIDOMEventListener {
|
2015-01-13 17:06:37 +03:00
|
|
|
private:
|
|
|
|
~DummyTouchListener() {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2018-04-20 07:49:29 +03:00
|
|
|
NS_IMETHOD HandleEvent(mozilla::dom::Event* aEvent) override {
|
2015-01-13 17:06:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A no-op touch-listener used for APZ purposes (see nsRangeFrame::Init).
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DummyTouchListener> mDummyTouchListener;
|
2013-02-16 21:57:21 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|