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/. */
|
|
|
|
|
|
|
|
#include "nsRangeFrame.h"
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-09-25 15:21:16 +04:00
|
|
|
#include "mozilla/TouchEvents.h"
|
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
#include "gfxContext.h"
|
2013-02-16 21:57:21 +04:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
2016-02-17 23:37:00 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2014-02-19 03:35:07 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2017-09-27 15:12:00 +03:00
|
|
|
#include "nsCheckboxRadioFrame.h"
|
2013-02-16 21:57:21 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2013-02-16 21:57:21 +04:00
|
|
|
#include "nsIPresShell.h"
|
2013-02-16 21:57:21 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2013-03-28 23:41:32 +04:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
2013-02-16 21:57:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2013-02-16 21:57:21 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
2018-03-29 14:15:46 +03:00
|
|
|
#include "mozilla/ServoStyleSet.h"
|
2018-07-25 16:03:45 +03:00
|
|
|
#include "nsStyleConsts.h"
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-04-28 04:54:54 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
#define LONG_SIDE_TO_SHORT_SIDE_RATIO 10
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-28 23:41:32 +04:00
|
|
|
using namespace mozilla;
|
2013-12-03 08:49:03 +04:00
|
|
|
using namespace mozilla::dom;
|
2015-10-23 05:54:49 +03:00
|
|
|
using namespace mozilla::image;
|
2013-03-28 23:41:32 +04:00
|
|
|
|
2015-01-13 17:06:37 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsRangeFrame::DummyTouchListener, nsIDOMEventListener)
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
nsIFrame*
|
2018-03-22 21:20:41 +03:00
|
|
|
NS_NewRangeFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2018-03-22 21:20:41 +03:00
|
|
|
return new (aPresShell) nsRangeFrame(aStyle);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
nsRangeFrame::nsRangeFrame(ComputedStyle* aStyle)
|
|
|
|
: nsContainerFrame(aStyle, kClassID)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRangeFrame::~nsRangeFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRangeFrame)
|
|
|
|
|
|
|
|
NS_QUERYFRAME_HEAD(nsRangeFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsRangeFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
|
|
|
|
2013-04-11 13:11:54 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsRangeFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2013-04-11 13:11:54 +04:00
|
|
|
{
|
2015-01-13 17:06:37 +03:00
|
|
|
// With APZ enabled, touch events may be handled directly by the APZC code
|
|
|
|
// if the APZ knows that there is no content interested in the touch event.
|
|
|
|
// The range input element *is* interested in touch events, but doesn't use
|
|
|
|
// the usual mechanism (i.e. registering an event listener) to handle touch
|
|
|
|
// input. Instead, we do it here so that the APZ finds out about it, and
|
|
|
|
// makes sure to wait for content to run handlers before handling the touch
|
|
|
|
// input itself.
|
|
|
|
if (!mDummyTouchListener) {
|
|
|
|
mDummyTouchListener = new DummyTouchListener();
|
2013-04-11 13:11:54 +04:00
|
|
|
}
|
2015-01-13 17:06:37 +03:00
|
|
|
aContent->AddEventListener(NS_LITERAL_STRING("touchstart"), mDummyTouchListener, false);
|
2014-02-19 03:35:07 +04:00
|
|
|
|
2018-03-29 14:15:46 +03:00
|
|
|
ServoStyleSet* styleSet = PresContext()->StyleSet();
|
2014-02-19 03:35:07 +04:00
|
|
|
|
|
|
|
mOuterFocusStyle =
|
2018-07-24 19:15:01 +03:00
|
|
|
styleSet->ProbePseudoElementStyle(*aContent->AsElement(),
|
2016-02-17 01:07:00 +03:00
|
|
|
CSSPseudoElementType::mozFocusOuter,
|
2018-03-22 21:20:41 +03:00
|
|
|
Style());
|
2014-02-19 03:35:07 +04:00
|
|
|
|
2013-04-11 13:11:54 +04:00
|
|
|
return nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
void
|
2017-11-07 03:20:33 +03:00
|
|
|
nsRangeFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2013-02-16 21:57:21 +04:00
|
|
|
NS_ASSERTION(!GetPrevContinuation() && !GetNextContinuation(),
|
2013-02-16 21:57:21 +04:00
|
|
|
"nsRangeFrame should not have continuations; if it does we "
|
|
|
|
"need to call RegUnregAccessKey only for the first.");
|
2015-01-13 17:06:37 +03:00
|
|
|
|
|
|
|
mContent->RemoveEventListener(NS_LITERAL_STRING("touchstart"), mDummyTouchListener, false);
|
|
|
|
|
2017-09-27 15:12:00 +03:00
|
|
|
nsCheckboxRadioFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
2017-11-07 03:20:33 +03:00
|
|
|
aPostDestroyData.AddAnonymousContent(mTrackDiv.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mProgressDiv.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mThumbDiv.forget());
|
|
|
|
nsContainerFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-12-03 08:49:03 +04:00
|
|
|
nsRangeFrame::MakeAnonymousDiv(Element** aResult,
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
2013-03-27 03:04:41 +04:00
|
|
|
nsTArray<ContentInfo>& aElements)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2014-07-31 00:15:44 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetComposedDoc();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Element> resultElement = doc->CreateHTMLElement(nsGkAtoms::div);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-27 03:04:41 +04:00
|
|
|
// Associate the pseudo-element with the anonymous child.
|
2017-01-13 06:21:11 +03:00
|
|
|
resultElement->SetPseudoElementType(aPseudoType);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2017-01-13 06:21:11 +03:00
|
|
|
if (!aElements.AppendElement(resultElement)) {
|
2013-02-16 21:57:21 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2013-12-03 08:49:03 +04:00
|
|
|
|
|
|
|
resultElement.forget(aResult);
|
2013-03-27 03:04:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-27 03:04:41 +04:00
|
|
|
|
2013-03-27 03:04:41 +04:00
|
|
|
nsresult
|
|
|
|
nsRangeFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Create the ::-moz-range-track pseuto-element (a div):
|
|
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mTrackDiv),
|
2016-02-17 01:07:00 +03:00
|
|
|
CSSPseudoElementType::mozRangeTrack,
|
2013-03-27 03:04:41 +04:00
|
|
|
aElements);
|
2013-02-16 21:57:21 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-03-27 03:04:41 +04:00
|
|
|
// Create the ::-moz-range-progress pseudo-element (a div):
|
|
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mProgressDiv),
|
2016-02-17 01:07:00 +03:00
|
|
|
CSSPseudoElementType::mozRangeProgress,
|
2013-03-27 03:04:41 +04:00
|
|
|
aElements);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-27 03:04:41 +04:00
|
|
|
// Create the ::-moz-range-thumb pseudo-element (a div):
|
|
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mThumbDiv),
|
2016-02-17 01:07:00 +03:00
|
|
|
CSSPseudoElementType::mozRangeThumb,
|
2013-03-27 03:04:41 +04:00
|
|
|
aElements);
|
|
|
|
return rv;
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-16 22:41:57 +04:00
|
|
|
nsRangeFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
2013-02-16 21:57:21 +04:00
|
|
|
uint32_t aFilter)
|
|
|
|
{
|
2014-07-16 22:41:57 +04:00
|
|
|
if (mTrackDiv) {
|
|
|
|
aElements.AppendElement(mTrackDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mProgressDiv) {
|
|
|
|
aElements.AppendElement(mProgressDiv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mThumbDiv) {
|
|
|
|
aElements.AppendElement(mThumbDiv);
|
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2013-04-22 13:11:56 +04:00
|
|
|
class nsDisplayRangeFocusRing : public nsDisplayItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDisplayRangeFocusRing(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayRangeFocusRing);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayRangeFocusRing() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayRangeFocusRing);
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-19 03:35:07 +04:00
|
|
|
|
2015-10-23 05:54:49 +03:00
|
|
|
nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override;
|
|
|
|
void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
2017-08-24 18:09:44 +03:00
|
|
|
nsRegion *aInvalidRegion) const override;
|
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) const override;
|
2017-06-09 22:14:53 +03:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
|
2016-08-27 02:02:49 +03:00
|
|
|
NS_DISPLAY_DECL_NAME("RangeFocusRing", TYPE_RANGE_FOCUS_RING)
|
2013-04-22 13:11:56 +04:00
|
|
|
};
|
|
|
|
|
2015-10-23 05:54:49 +03:00
|
|
|
nsDisplayItemGeometry*
|
|
|
|
nsDisplayRangeFocusRing::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return new nsDisplayItemGenericImageGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-24 18:09:44 +03:00
|
|
|
nsDisplayRangeFocusRing::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion) const
|
2015-10-23 05:54:49 +03:00
|
|
|
{
|
|
|
|
auto geometry =
|
|
|
|
static_cast<const nsDisplayItemGenericImageGeometry*>(aGeometry);
|
|
|
|
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages() &&
|
|
|
|
geometry->ShouldInvalidateToSyncDecodeImages()) {
|
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
}
|
|
|
|
|
2014-02-19 03:35:07 +04:00
|
|
|
nsRect
|
2017-08-24 18:09:44 +03:00
|
|
|
nsDisplayRangeFocusRing::GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) const
|
2014-02-19 03:35:07 +04:00
|
|
|
{
|
|
|
|
*aSnap = false;
|
|
|
|
nsRect rect(ToReferenceFrame(), Frame()->GetSize());
|
|
|
|
|
|
|
|
// We want to paint as if specifying a border for ::-moz-focus-outer
|
|
|
|
// specifies an outline for our frame, so inflate by the border widths:
|
2018-03-22 16:49:21 +03:00
|
|
|
ComputedStyle* computedStyle =
|
2014-02-19 03:35:07 +04:00
|
|
|
static_cast<nsRangeFrame*>(mFrame)->mOuterFocusStyle;
|
2018-03-22 16:49:21 +03:00
|
|
|
MOZ_ASSERT(computedStyle, "We only exist if mOuterFocusStyle is non-null");
|
|
|
|
rect.Inflate(computedStyle->StyleBorder()->GetComputedBorder());
|
2014-02-19 03:35:07 +04:00
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2013-04-22 13:11:56 +04:00
|
|
|
void
|
|
|
|
nsDisplayRangeFocusRing::Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx)
|
2013-04-22 13:11:56 +04:00
|
|
|
{
|
2014-02-19 03:35:07 +04:00
|
|
|
bool unused;
|
2018-03-22 16:49:21 +03:00
|
|
|
ComputedStyle* computedStyle =
|
2014-02-19 03:35:07 +04:00
|
|
|
static_cast<nsRangeFrame*>(mFrame)->mOuterFocusStyle;
|
2018-03-22 16:49:21 +03:00
|
|
|
MOZ_ASSERT(computedStyle, "We only exist if mOuterFocusStyle is non-null");
|
2015-10-23 05:54:49 +03:00
|
|
|
|
|
|
|
PaintBorderFlags flags = aBuilder->ShouldSyncDecodeImages()
|
|
|
|
? PaintBorderFlags::SYNC_DECODE_IMAGES
|
|
|
|
: PaintBorderFlags();
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result =
|
2015-10-23 05:54:49 +03:00
|
|
|
nsCSSRendering::PaintBorder(mFrame->PresContext(), *aCtx, mFrame,
|
2018-05-16 06:56:32 +03:00
|
|
|
GetPaintRect(), GetBounds(aBuilder, &unused),
|
2018-03-22 16:49:21 +03:00
|
|
|
computedStyle, flags);
|
2015-10-23 05:54:49 +03:00
|
|
|
|
|
|
|
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
|
2013-04-22 13:11:56 +04:00
|
|
|
}
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
void
|
2013-02-16 21:57:21 +04:00
|
|
|
nsRangeFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2013-02-16 21:57:21 +04:00
|
|
|
const nsDisplayListSet& aLists)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2017-05-02 04:16:20 +03:00
|
|
|
const nsStyleDisplay* disp = StyleDisplay();
|
|
|
|
if (IsThemed(disp)) {
|
2013-04-03 14:07:12 +04:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
// Only create items for the thumb. Specifically, we do not want
|
|
|
|
// the track to paint, since *our* background is used to paint
|
|
|
|
// the track, and we don't want the unthemed track painting over
|
|
|
|
// the top of the themed track.
|
|
|
|
// This logic is copied from
|
|
|
|
// nsContainerFrame::BuildDisplayListForNonBlockChildren as
|
|
|
|
// called by BuildDisplayListForInline.
|
|
|
|
nsIFrame* thumb = mThumbDiv->GetPrimaryFrame();
|
|
|
|
if (thumb) {
|
|
|
|
nsDisplayListSet set(aLists, aLists.Content());
|
2017-08-07 05:23:35 +03:00
|
|
|
BuildDisplayListForChild(aBuilder, thumb, set, DISPLAY_CHILD_INLINE);
|
2013-04-03 14:07:12 +04:00
|
|
|
}
|
|
|
|
} else {
|
2017-08-07 05:23:35 +03:00
|
|
|
BuildDisplayListForInline(aBuilder, aLists);
|
2013-04-03 14:07:12 +04:00
|
|
|
}
|
2013-04-22 13:11:56 +04:00
|
|
|
|
|
|
|
// Draw a focus outline if appropriate:
|
2014-02-19 03:35:07 +04:00
|
|
|
|
|
|
|
if (!aBuilder->IsForPainting() ||
|
|
|
|
!IsVisibleForPainting(aBuilder)) {
|
|
|
|
// we don't want the focus ring item for hit-testing or if the item isn't
|
|
|
|
// in the area being [re]painted
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates eventStates = mContent->AsElement()->State();
|
2014-02-19 03:35:07 +04:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED) ||
|
|
|
|
!eventStates.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
|
|
|
return; // can't have focus or doesn't match :-moz-focusring
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mOuterFocusStyle ||
|
|
|
|
!mOuterFocusStyle->StyleBorder()->HasBorder()) {
|
|
|
|
// no ::-moz-focus-outer specified border (how style specifies a focus ring
|
|
|
|
// for range)
|
2013-04-22 13:11:56 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-02-19 03:35:07 +04:00
|
|
|
|
|
|
|
if (IsThemed(disp) &&
|
2017-05-21 12:15:00 +03:00
|
|
|
PresContext()->GetTheme()->ThemeDrawsFocusForWidget(disp->mAppearance)) {
|
2014-02-19 03:35:07 +04:00
|
|
|
return; // the native theme displays its own visual indication of focus
|
2013-04-22 13:11:56 +04:00
|
|
|
}
|
2014-02-19 03:35:07 +04:00
|
|
|
|
2017-12-13 20:23:04 +03:00
|
|
|
aLists.Content()->AppendToTop(
|
2018-02-13 03:43:28 +03:00
|
|
|
MakeDisplayItem<nsDisplayRangeFocusRing>(aBuilder, this));
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2013-02-16 21:57:21 +04:00
|
|
|
nsRangeFrame::Reflow(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
|
|
|
nsReflowStatus& aStatus)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
2013-02-16 21:57:21 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsRangeFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-27 03:04:41 +04:00
|
|
|
NS_ASSERTION(mTrackDiv, "::-moz-range-track div must exist!");
|
|
|
|
NS_ASSERTION(mProgressDiv, "::-moz-range-progress div must exist!");
|
|
|
|
NS_ASSERTION(mThumbDiv, "::-moz-range-thumb div must exist!");
|
2013-02-16 21:57:21 +04:00
|
|
|
NS_ASSERTION(!GetPrevContinuation() && !GetNextContinuation(),
|
2013-02-16 21:57:21 +04:00
|
|
|
"nsRangeFrame should not have continuations; if it does we "
|
|
|
|
"need to call RegUnregAccessKey only for the first.");
|
|
|
|
|
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
2017-09-27 15:12:00 +03:00
|
|
|
nsCheckboxRadioFrame::RegUnRegAccessKey(this, true);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = aReflowInput.GetWritingMode();
|
|
|
|
nscoord computedBSize = aReflowInput.ComputedBSize();
|
2014-07-24 12:30:07 +04:00
|
|
|
if (computedBSize == NS_AUTOHEIGHT) {
|
|
|
|
computedBSize = 0;
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
2014-07-24 12:30:07 +04:00
|
|
|
LogicalSize
|
|
|
|
finalSize(wm,
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.ComputedISize() +
|
|
|
|
aReflowInput.ComputedLogicalBorderPadding().IStartEnd(wm),
|
2014-07-24 12:30:07 +04:00
|
|
|
computedBSize +
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.ComputedLogicalBorderPadding().BStartEnd(wm));
|
2014-07-24 12:30:07 +04:00
|
|
|
aDesiredSize.SetSize(wm, finalSize);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowAnonymousContent(aPresContext, aDesiredSize, aReflowInput);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
nsIFrame* trackFrame = mTrackDiv->GetPrimaryFrame();
|
|
|
|
if (trackFrame) {
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, trackFrame);
|
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-27 03:04:41 +04:00
|
|
|
nsIFrame* rangeProgressFrame = mProgressDiv->GetPrimaryFrame();
|
|
|
|
if (rangeProgressFrame) {
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, rangeProgressFrame);
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
|
|
if (thumbFrame) {
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, thumbFrame);
|
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "This type of frame can't be split.");
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2013-02-16 21:57:21 +04:00
|
|
|
nsRangeFrame::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-02-16 21:57:21 +04:00
|
|
|
// The width/height of our content box, which is the available width/height
|
|
|
|
// for our anonymous content:
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord rangeFrameContentBoxWidth = aReflowInput.ComputedWidth();
|
|
|
|
nscoord rangeFrameContentBoxHeight = aReflowInput.ComputedHeight();
|
2013-02-16 21:57:21 +04:00
|
|
|
if (rangeFrameContentBoxHeight == NS_AUTOHEIGHT) {
|
|
|
|
rangeFrameContentBoxHeight = 0;
|
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
nsIFrame* trackFrame = mTrackDiv->GetPrimaryFrame();
|
|
|
|
|
|
|
|
if (trackFrame) { // display:none?
|
|
|
|
|
|
|
|
// Position the track:
|
|
|
|
// The idea here is that we allow content authors to style the width,
|
|
|
|
// height, border and padding of the track, but we ignore margin and
|
|
|
|
// positioning properties and do the positioning ourself to keep the center
|
|
|
|
// of the track's border box on the center of the nsRangeFrame's content
|
|
|
|
// box.
|
|
|
|
|
2014-07-24 12:28:46 +04:00
|
|
|
WritingMode wm = trackFrame->GetWritingMode();
|
2016-07-21 13:36:39 +03:00
|
|
|
LogicalSize availSize = aReflowInput.ComputedSize(wm);
|
2014-07-24 12:28:46 +04:00
|
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput trackReflowInput(aPresContext, aReflowInput,
|
2014-07-24 12:28:46 +04:00
|
|
|
trackFrame, availSize);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
|
|
|
// Find the x/y position of the track frame such that it will be positioned
|
|
|
|
// as described above. These coordinates are with respect to the
|
|
|
|
// nsRangeFrame's border-box.
|
|
|
|
nscoord trackX = rangeFrameContentBoxWidth / 2;
|
|
|
|
nscoord trackY = rangeFrameContentBoxHeight / 2;
|
|
|
|
|
|
|
|
// Account for the track's border and padding (we ignore its margin):
|
2016-07-21 13:36:39 +03:00
|
|
|
trackX -= trackReflowInput.ComputedPhysicalBorderPadding().left +
|
|
|
|
trackReflowInput.ComputedWidth() / 2;
|
|
|
|
trackY -= trackReflowInput.ComputedPhysicalBorderPadding().top +
|
|
|
|
trackReflowInput.ComputedHeight() / 2;
|
2013-02-16 21:57:21 +04:00
|
|
|
|
|
|
|
// Make relative to our border box instead of our content box:
|
2016-07-21 13:36:39 +03:00
|
|
|
trackX += aReflowInput.ComputedPhysicalBorderPadding().left;
|
|
|
|
trackY += aReflowInput.ComputedPhysicalBorderPadding().top;
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-29 13:49:53 +04:00
|
|
|
nsReflowStatus frameStatus;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput trackDesiredSize(aReflowInput);
|
2014-05-13 04:47:52 +04:00
|
|
|
ReflowChild(trackFrame, aPresContext, trackDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
trackReflowInput, trackX, trackY, 0, frameStatus);
|
2017-02-11 17:38:48 +03:00
|
|
|
MOZ_ASSERT(frameStatus.IsFullyComplete(),
|
2013-02-16 21:57:21 +04:00
|
|
|
"We gave our child unconstrained height, so it should be complete");
|
2014-05-13 04:47:52 +04:00
|
|
|
FinishReflowChild(trackFrame, aPresContext, trackDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
&trackReflowInput, trackX, trackY, 0);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
if (thumbFrame) { // display:none?
|
2014-07-24 12:28:46 +04:00
|
|
|
WritingMode wm = thumbFrame->GetWritingMode();
|
2016-07-21 13:36:39 +03:00
|
|
|
LogicalSize availSize = aReflowInput.ComputedSize(wm);
|
2014-07-24 12:28:46 +04:00
|
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput thumbReflowInput(aPresContext, aReflowInput,
|
2014-07-24 12:28:46 +04:00
|
|
|
thumbFrame, availSize);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-21 10:41:32 +04:00
|
|
|
// Where we position the thumb depends on its size, so we first reflow
|
2013-03-15 13:04:54 +04:00
|
|
|
// the thumb at {0,0} to obtain its size, then position it afterwards.
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-29 13:49:53 +04:00
|
|
|
nsReflowStatus frameStatus;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput thumbDesiredSize(aReflowInput);
|
2014-05-13 04:47:52 +04:00
|
|
|
ReflowChild(thumbFrame, aPresContext, thumbDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
thumbReflowInput, 0, 0, 0, frameStatus);
|
2017-02-11 17:38:48 +03:00
|
|
|
MOZ_ASSERT(frameStatus.IsFullyComplete(),
|
2013-02-16 21:57:21 +04:00
|
|
|
"We gave our child unconstrained height, so it should be complete");
|
2014-05-13 04:47:52 +04:00
|
|
|
FinishReflowChild(thumbFrame, aPresContext, thumbDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
&thumbReflowInput, 0, 0, 0);
|
2013-12-27 21:59:52 +04:00
|
|
|
DoUpdateThumbPosition(thumbFrame, nsSize(aDesiredSize.Width(),
|
|
|
|
aDesiredSize.Height()));
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2013-03-27 03:04:41 +04:00
|
|
|
nsIFrame* rangeProgressFrame = mProgressDiv->GetPrimaryFrame();
|
|
|
|
|
|
|
|
if (rangeProgressFrame) { // display:none?
|
2014-07-24 12:28:46 +04:00
|
|
|
WritingMode wm = rangeProgressFrame->GetWritingMode();
|
2016-07-21 13:36:39 +03:00
|
|
|
LogicalSize availSize = aReflowInput.ComputedSize(wm);
|
2014-07-24 12:28:46 +04:00
|
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput progressReflowInput(aPresContext, aReflowInput,
|
2014-07-24 12:28:46 +04:00
|
|
|
rangeProgressFrame, availSize);
|
2013-03-27 03:04:41 +04:00
|
|
|
|
|
|
|
// We first reflow the range-progress frame at {0,0} to obtain its
|
|
|
|
// unadjusted dimensions, then we adjust it to so that the appropriate edge
|
|
|
|
// ends at the thumb.
|
|
|
|
|
2013-03-29 13:49:53 +04:00
|
|
|
nsReflowStatus frameStatus;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput progressDesiredSize(aReflowInput);
|
2014-05-13 04:47:52 +04:00
|
|
|
ReflowChild(rangeProgressFrame, aPresContext,
|
2016-07-21 13:36:39 +03:00
|
|
|
progressDesiredSize, progressReflowInput, 0, 0,
|
2014-05-13 04:47:52 +04:00
|
|
|
0, frameStatus);
|
2017-02-11 17:38:48 +03:00
|
|
|
MOZ_ASSERT(frameStatus.IsFullyComplete(),
|
2013-03-27 03:04:41 +04:00
|
|
|
"We gave our child unconstrained height, so it should be complete");
|
2014-05-13 04:47:52 +04:00
|
|
|
FinishReflowChild(rangeProgressFrame, aPresContext,
|
2016-07-21 13:36:39 +03:00
|
|
|
progressDesiredSize, &progressReflowInput, 0, 0, 0);
|
2013-12-27 21:59:52 +04:00
|
|
|
DoUpdateRangeProgressFrame(rangeProgressFrame, nsSize(aDesiredSize.Width(),
|
|
|
|
aDesiredSize.Height()));
|
2013-03-27 03:04:41 +04:00
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-04-28 04:54:54 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
a11y::AccType
|
|
|
|
nsRangeFrame::AccessibleType()
|
|
|
|
{
|
|
|
|
return a11y::eHTMLRangeType;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
double
|
|
|
|
nsRangeFrame::GetValueAsFractionOfRange()
|
|
|
|
{
|
2015-03-03 14:08:59 +03:00
|
|
|
MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast");
|
2017-08-27 01:58:38 +03:00
|
|
|
dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(GetContent());
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2017-04-01 05:49:00 +03:00
|
|
|
MOZ_ASSERT(input->ControlType() == NS_FORM_INPUT_RANGE);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-05-06 03:23:18 +04:00
|
|
|
Decimal value = input->GetValueAsDecimal();
|
|
|
|
Decimal minimum = input->GetMinimum();
|
|
|
|
Decimal maximum = input->GetMaximum();
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-05-06 03:23:18 +04:00
|
|
|
MOZ_ASSERT(value.isFinite() && minimum.isFinite() && maximum.isFinite(),
|
2013-02-16 21:57:21 +04:00
|
|
|
"type=range should have a default maximum/minimum");
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
if (maximum <= minimum) {
|
|
|
|
MOZ_ASSERT(value == minimum, "Unsanitized value");
|
|
|
|
return 0.0;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
MOZ_ASSERT(value >= minimum && value <= maximum, "Unsanitized value");
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2013-05-06 03:23:18 +04:00
|
|
|
return ((value - minimum) / (maximum - minimum)).toDouble();
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-05-06 03:23:18 +04:00
|
|
|
Decimal
|
2013-10-02 07:46:03 +04:00
|
|
|
nsRangeFrame::GetValueAtEventPoint(WidgetGUIEvent* aEvent)
|
2013-03-08 13:40:12 +04:00
|
|
|
{
|
2014-08-04 09:28:50 +04:00
|
|
|
MOZ_ASSERT(aEvent->mClass == eMouseEventClass ||
|
2014-08-04 09:28:53 +04:00
|
|
|
aEvent->mClass == eTouchEventClass,
|
2016-04-18 17:09:02 +03:00
|
|
|
"Unexpected event type - aEvent->mRefPoint may be meaningless");
|
2013-03-08 13:40:12 +04:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast");
|
2017-08-27 01:58:38 +03:00
|
|
|
dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(GetContent());
|
2013-03-08 13:40:12 +04:00
|
|
|
|
2017-04-01 05:49:00 +03:00
|
|
|
MOZ_ASSERT(input->ControlType() == NS_FORM_INPUT_RANGE);
|
2013-03-08 13:40:12 +04:00
|
|
|
|
2013-05-06 03:23:18 +04:00
|
|
|
Decimal minimum = input->GetMinimum();
|
|
|
|
Decimal maximum = input->GetMaximum();
|
|
|
|
MOZ_ASSERT(minimum.isFinite() && maximum.isFinite(),
|
2013-03-08 13:40:12 +04:00
|
|
|
"type=range should have a default maximum/minimum");
|
2013-03-15 13:04:54 +04:00
|
|
|
if (maximum <= minimum) {
|
2013-03-08 13:40:12 +04:00
|
|
|
return minimum;
|
|
|
|
}
|
2013-05-06 03:23:18 +04:00
|
|
|
Decimal range = maximum - minimum;
|
2013-03-08 13:40:12 +04:00
|
|
|
|
2013-08-02 11:05:16 +04:00
|
|
|
LayoutDeviceIntPoint absPoint;
|
2014-08-04 09:28:53 +04:00
|
|
|
if (aEvent->mClass == eTouchEventClass) {
|
2016-03-30 12:44:28 +03:00
|
|
|
MOZ_ASSERT(aEvent->AsTouchEvent()->mTouches.Length() == 1,
|
|
|
|
"Unexpected number of mTouches");
|
|
|
|
absPoint = aEvent->AsTouchEvent()->mTouches[0]->mRefPoint;
|
2013-03-08 13:40:12 +04:00
|
|
|
} else {
|
2016-04-18 17:09:02 +03:00
|
|
|
absPoint = aEvent->mRefPoint;
|
2013-03-08 13:40:12 +04:00
|
|
|
}
|
2013-03-15 13:04:54 +04:00
|
|
|
nsPoint point =
|
2015-02-02 01:27:31 +03:00
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, absPoint, this);
|
2013-03-08 13:40:12 +04:00
|
|
|
|
2013-04-15 09:01:38 +04:00
|
|
|
if (point == nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)) {
|
|
|
|
// We don't want to change the current value for this error state.
|
2017-08-27 01:58:38 +03:00
|
|
|
return static_cast<dom::HTMLInputElement*>(GetContent())->GetValueAsDecimal();
|
2013-04-15 09:01:38 +04:00
|
|
|
}
|
|
|
|
|
2013-03-15 13:04:54 +04:00
|
|
|
nsRect rangeContentRect = GetContentRectRelativeToSelf();
|
|
|
|
nsSize thumbSize;
|
2013-03-16 09:40:15 +04:00
|
|
|
|
|
|
|
if (IsThemed()) {
|
|
|
|
// We need to get the size of the thumb from the theme.
|
|
|
|
nsPresContext *presContext = PresContext();
|
|
|
|
bool notUsedCanOverride;
|
2015-03-30 18:36:14 +03:00
|
|
|
LayoutDeviceIntSize size;
|
2013-03-16 09:40:15 +04:00
|
|
|
presContext->GetTheme()->
|
2018-07-25 16:03:45 +03:00
|
|
|
GetMinimumWidgetSize(presContext, this, StyleAppearance::RangeThumb, &size,
|
2013-03-16 09:40:15 +04:00
|
|
|
¬UsedCanOverride);
|
|
|
|
thumbSize.width = presContext->DevPixelsToAppUnits(size.width);
|
|
|
|
thumbSize.height = presContext->DevPixelsToAppUnits(size.height);
|
2017-01-17 22:20:37 +03:00
|
|
|
// For GTK, GetMinimumWidgetSize returns zero for the thumb dimension
|
|
|
|
// perpendicular to the orientation of the slider. That's okay since we
|
|
|
|
// only care about the dimension in the direction of the slider when using
|
|
|
|
// |thumbSize| below, but it means this assertion need to check
|
|
|
|
// IsHorizontal().
|
|
|
|
MOZ_ASSERT((IsHorizontal() && thumbSize.width > 0) ||
|
|
|
|
(!IsHorizontal() && thumbSize.height > 0),
|
|
|
|
"The thumb is expected to take up some slider space");
|
2013-03-16 09:40:15 +04:00
|
|
|
} else {
|
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
|
|
if (thumbFrame) { // diplay:none?
|
|
|
|
thumbSize = thumbFrame->GetSize();
|
|
|
|
}
|
2013-03-08 13:40:12 +04:00
|
|
|
}
|
2013-03-15 13:04:54 +04:00
|
|
|
|
2013-05-06 03:23:18 +04:00
|
|
|
Decimal fraction;
|
2013-03-15 13:04:54 +04:00
|
|
|
if (IsHorizontal()) {
|
|
|
|
nscoord traversableDistance = rangeContentRect.width - thumbSize.width;
|
|
|
|
if (traversableDistance <= 0) {
|
|
|
|
return minimum;
|
|
|
|
}
|
|
|
|
nscoord posAtStart = rangeContentRect.x + thumbSize.width/2;
|
|
|
|
nscoord posAtEnd = posAtStart + traversableDistance;
|
|
|
|
nscoord posOfPoint = mozilla::clamped(point.x, posAtStart, posAtEnd);
|
2014-06-07 07:17:06 +04:00
|
|
|
fraction = Decimal(posOfPoint - posAtStart) / Decimal(traversableDistance);
|
2015-04-29 10:18:54 +03:00
|
|
|
if (IsRightToLeft()) {
|
2013-05-06 03:23:18 +04:00
|
|
|
fraction = Decimal(1) - fraction;
|
2013-03-15 13:04:54 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nscoord traversableDistance = rangeContentRect.height - thumbSize.height;
|
|
|
|
if (traversableDistance <= 0) {
|
|
|
|
return minimum;
|
|
|
|
}
|
|
|
|
nscoord posAtStart = rangeContentRect.y + thumbSize.height/2;
|
|
|
|
nscoord posAtEnd = posAtStart + traversableDistance;
|
|
|
|
nscoord posOfPoint = mozilla::clamped(point.y, posAtStart, posAtEnd);
|
|
|
|
// For a vertical range, the top (posAtStart) is the highest value, so we
|
|
|
|
// subtract the fraction from 1.0 to get that polarity correct.
|
2014-06-07 07:17:06 +04:00
|
|
|
fraction = Decimal(1) - Decimal(posOfPoint - posAtStart) / Decimal(traversableDistance);
|
2013-03-15 13:04:54 +04:00
|
|
|
}
|
|
|
|
|
2014-06-07 07:17:06 +04:00
|
|
|
MOZ_ASSERT(fraction >= Decimal(0) && fraction <= Decimal(1));
|
2013-03-15 13:04:54 +04:00
|
|
|
return minimum + fraction * range;
|
2013-03-08 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2013-03-13 15:48:27 +04:00
|
|
|
void
|
2013-03-27 03:04:41 +04:00
|
|
|
nsRangeFrame::UpdateForValueChange()
|
2013-03-13 15:48:27 +04:00
|
|
|
{
|
|
|
|
if (NS_SUBTREE_DIRTY(this)) {
|
|
|
|
return; // we're going to be updated when we reflow
|
|
|
|
}
|
2013-03-27 03:04:41 +04:00
|
|
|
nsIFrame* rangeProgressFrame = mProgressDiv->GetPrimaryFrame();
|
2013-03-13 15:48:27 +04:00
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
2013-03-27 03:04:41 +04:00
|
|
|
if (!rangeProgressFrame && !thumbFrame) {
|
2013-03-13 15:48:27 +04:00
|
|
|
return; // diplay:none?
|
|
|
|
}
|
2013-03-27 03:04:41 +04:00
|
|
|
if (rangeProgressFrame) {
|
|
|
|
DoUpdateRangeProgressFrame(rangeProgressFrame, GetSize());
|
|
|
|
}
|
|
|
|
if (thumbFrame) {
|
|
|
|
DoUpdateThumbPosition(thumbFrame, GetSize());
|
|
|
|
}
|
2013-03-16 09:40:15 +04:00
|
|
|
if (IsThemed()) {
|
|
|
|
// We don't know the exact dimensions or location of the thumb when native
|
|
|
|
// theming is applied, so we just repaint the entire range.
|
|
|
|
InvalidateFrame();
|
|
|
|
}
|
2013-04-28 04:54:54 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
nsAccessibilityService* accService = nsIPresShell::AccService();
|
|
|
|
if (accService) {
|
2017-11-09 05:00:48 +03:00
|
|
|
accService->RangeValueChanged(PresShell(), mContent);
|
2013-04-28 04:54:54 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-15 13:04:54 +04:00
|
|
|
SchedulePaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRangeFrame::DoUpdateThumbPosition(nsIFrame* aThumbFrame,
|
|
|
|
const nsSize& aRangeSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aThumbFrame);
|
|
|
|
|
|
|
|
// The idea here is that we want to position the thumb so that the center
|
|
|
|
// of the thumb is on an imaginary line drawn from the middle of one edge
|
|
|
|
// of the range frame's content box to the middle of the opposite edge of
|
|
|
|
// its content box (the opposite edges being the left/right edge if the
|
|
|
|
// range is horizontal, or else the top/bottom edges if the range is
|
|
|
|
// vertical). How far along this line the center of the thumb is placed
|
|
|
|
// depends on the value of the range.
|
|
|
|
|
2013-03-13 15:48:27 +04:00
|
|
|
nsMargin borderAndPadding = GetUsedBorderAndPadding();
|
|
|
|
nsPoint newPosition(borderAndPadding.left, borderAndPadding.top);
|
2013-03-15 13:04:54 +04:00
|
|
|
|
|
|
|
nsSize rangeContentBoxSize(aRangeSize);
|
|
|
|
rangeContentBoxSize.width -= borderAndPadding.LeftRight();
|
|
|
|
rangeContentBoxSize.height -= borderAndPadding.TopBottom();
|
|
|
|
|
|
|
|
nsSize thumbSize = aThumbFrame->GetSize();
|
|
|
|
double fraction = GetValueAsFractionOfRange();
|
|
|
|
MOZ_ASSERT(fraction >= 0.0 && fraction <= 1.0);
|
|
|
|
|
2015-04-29 10:18:54 +03:00
|
|
|
if (IsHorizontal()) {
|
2013-03-15 13:04:54 +04:00
|
|
|
if (thumbSize.width < rangeContentBoxSize.width) {
|
|
|
|
nscoord traversableDistance =
|
|
|
|
rangeContentBoxSize.width - thumbSize.width;
|
2015-04-29 10:18:54 +03:00
|
|
|
if (IsRightToLeft()) {
|
2013-03-15 13:04:54 +04:00
|
|
|
newPosition.x += NSToCoordRound((1.0 - fraction) * traversableDistance);
|
|
|
|
} else {
|
|
|
|
newPosition.x += NSToCoordRound(fraction * traversableDistance);
|
|
|
|
}
|
|
|
|
newPosition.y += (rangeContentBoxSize.height - thumbSize.height)/2;
|
|
|
|
}
|
2013-03-13 15:48:27 +04:00
|
|
|
} else {
|
2013-03-15 13:04:54 +04:00
|
|
|
if (thumbSize.height < rangeContentBoxSize.height) {
|
|
|
|
nscoord traversableDistance =
|
|
|
|
rangeContentBoxSize.height - thumbSize.height;
|
|
|
|
newPosition.x += (rangeContentBoxSize.width - thumbSize.width)/2;
|
|
|
|
newPosition.y += NSToCoordRound((1.0 - fraction) * traversableDistance);
|
|
|
|
}
|
2013-03-13 15:48:27 +04:00
|
|
|
}
|
2013-03-15 13:04:54 +04:00
|
|
|
aThumbFrame->SetPosition(newPosition);
|
2013-03-13 15:48:27 +04:00
|
|
|
}
|
2013-03-08 13:40:12 +04:00
|
|
|
|
2013-03-27 03:04:41 +04:00
|
|
|
void
|
|
|
|
nsRangeFrame::DoUpdateRangeProgressFrame(nsIFrame* aRangeProgressFrame,
|
|
|
|
const nsSize& aRangeSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRangeProgressFrame);
|
|
|
|
|
|
|
|
// The idea here is that we want to position the ::-moz-range-progress
|
|
|
|
// pseudo-element so that the center line running along its length is on the
|
|
|
|
// corresponding center line of the nsRangeFrame's content box. In the other
|
|
|
|
// dimension, we align the "start" edge of the ::-moz-range-progress
|
|
|
|
// pseudo-element's border-box with the corresponding edge of the
|
|
|
|
// nsRangeFrame's content box, and we size the progress element's border-box
|
|
|
|
// to have a length of GetValueAsFractionOfRange() times the nsRangeFrame's
|
|
|
|
// content-box size.
|
|
|
|
|
|
|
|
nsMargin borderAndPadding = GetUsedBorderAndPadding();
|
|
|
|
nsSize progSize = aRangeProgressFrame->GetSize();
|
|
|
|
nsRect progRect(borderAndPadding.left, borderAndPadding.top,
|
|
|
|
progSize.width, progSize.height);
|
|
|
|
|
|
|
|
nsSize rangeContentBoxSize(aRangeSize);
|
|
|
|
rangeContentBoxSize.width -= borderAndPadding.LeftRight();
|
|
|
|
rangeContentBoxSize.height -= borderAndPadding.TopBottom();
|
|
|
|
|
|
|
|
double fraction = GetValueAsFractionOfRange();
|
|
|
|
MOZ_ASSERT(fraction >= 0.0 && fraction <= 1.0);
|
|
|
|
|
2015-04-29 10:18:54 +03:00
|
|
|
if (IsHorizontal()) {
|
2013-03-27 03:04:41 +04:00
|
|
|
nscoord progLength = NSToCoordRound(fraction * rangeContentBoxSize.width);
|
2015-04-29 10:18:54 +03:00
|
|
|
if (IsRightToLeft()) {
|
2013-03-27 03:04:41 +04:00
|
|
|
progRect.x += rangeContentBoxSize.width - progLength;
|
|
|
|
}
|
|
|
|
progRect.y += (rangeContentBoxSize.height - progSize.height)/2;
|
|
|
|
progRect.width = progLength;
|
|
|
|
} else {
|
|
|
|
nscoord progLength = NSToCoordRound(fraction * rangeContentBoxSize.height);
|
|
|
|
progRect.x += (rangeContentBoxSize.width - progSize.width)/2;
|
|
|
|
progRect.y += rangeContentBoxSize.height - progLength;
|
|
|
|
progRect.height = progLength;
|
|
|
|
}
|
|
|
|
aRangeProgressFrame->SetRect(progRect);
|
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2013-02-16 21:57:21 +04:00
|
|
|
nsRangeFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2013-02-16 21:57:21 +04:00
|
|
|
int32_t aModType)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2013-02-16 21:57:21 +04:00
|
|
|
NS_ASSERTION(mTrackDiv, "The track div must exist!");
|
|
|
|
NS_ASSERTION(mThumbDiv, "The thumb div must exist!");
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-03-26 17:54:05 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::value ||
|
|
|
|
aAttribute == nsGkAtoms::min ||
|
|
|
|
aAttribute == nsGkAtoms::max ||
|
|
|
|
aAttribute == nsGkAtoms::step) {
|
|
|
|
// We want to update the position of the thumb, except in one special
|
|
|
|
// case: If the value attribute is being set, it is possible that we are
|
|
|
|
// in the middle of a type change away from type=range, under the
|
2013-03-28 23:41:32 +04:00
|
|
|
// SetAttr(..., nsGkAtoms::value, ...) call in HTMLInputElement::
|
|
|
|
// HandleTypeChange. In that case the HTMLInputElement's type will
|
2013-03-27 03:04:41 +04:00
|
|
|
// already have changed, and if we call UpdateForValueChange()
|
2013-03-26 17:54:05 +04:00
|
|
|
// we'll fail the asserts under that call that check the type of our
|
2013-03-28 23:41:32 +04:00
|
|
|
// HTMLInputElement. Given that we're changing away from being a range
|
2013-03-26 17:54:05 +04:00
|
|
|
// and this frame will shortly be destroyed, there's no point in calling
|
2013-03-27 03:04:41 +04:00
|
|
|
// UpdateForValueChange() anyway.
|
2015-03-03 14:08:59 +03:00
|
|
|
MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast");
|
2017-04-01 05:49:00 +03:00
|
|
|
bool typeIsRange =
|
2017-08-27 01:58:38 +03:00
|
|
|
static_cast<dom::HTMLInputElement*>(GetContent())->ControlType() ==
|
2013-03-26 17:54:05 +04:00
|
|
|
NS_FORM_INPUT_RANGE;
|
2013-09-25 00:29:31 +04:00
|
|
|
// If script changed the <input>'s type before setting these attributes
|
|
|
|
// then we don't need to do anything since we are going to be reframed.
|
2013-03-26 17:54:05 +04:00
|
|
|
if (typeIsRange) {
|
2013-03-27 03:04:41 +04:00
|
|
|
UpdateForValueChange();
|
2013-03-26 17:54:05 +04:00
|
|
|
}
|
|
|
|
} else if (aAttribute == nsGkAtoms::orient) {
|
2017-11-09 05:00:48 +03:00
|
|
|
PresShell()->FrameNeedsReflow(this, nsIPresShell::eResize,
|
2017-11-09 05:00:48 +03:00
|
|
|
NS_FRAME_IS_DIRTY);
|
2013-03-13 17:59:11 +04:00
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
2014-08-24 18:34:51 +04:00
|
|
|
LogicalSize
|
2017-06-09 22:14:53 +03:00
|
|
|
nsRangeFrame::ComputeAutoSize(gfxContext* aRenderingContext,
|
2016-11-05 04:57:06 +03:00
|
|
|
WritingMode aWM,
|
|
|
|
const LogicalSize& aCBSize,
|
|
|
|
nscoord aAvailableISize,
|
|
|
|
const LogicalSize& aMargin,
|
|
|
|
const LogicalSize& aBorder,
|
|
|
|
const LogicalSize& aPadding,
|
|
|
|
ComputeSizeFlags aFlags)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
nscoord oneEm = NSToCoordRound(StyleFont()->mFont.size *
|
2013-02-16 21:57:21 +04:00
|
|
|
nsLayoutUtils::FontSizeInflationFor(this)); // 1em
|
|
|
|
|
2015-04-29 10:18:54 +03:00
|
|
|
bool isInlineOriented = IsInlineOriented();
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2014-08-24 18:34:51 +04:00
|
|
|
const WritingMode wm = GetWritingMode();
|
|
|
|
LogicalSize autoSize(wm);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
// nsFrame::ComputeSize calls GetMinimumWidgetSize to prevent us from being
|
|
|
|
// given too small a size when we're natively themed. If we're themed, we set
|
|
|
|
// our "thickness" dimension to zero below and rely on that
|
|
|
|
// GetMinimumWidgetSize check to correct that dimension to the natural
|
|
|
|
// thickness of a slider in the current theme.
|
|
|
|
|
2014-08-24 18:34:51 +04:00
|
|
|
if (isInlineOriented) {
|
|
|
|
autoSize.ISize(wm) = LONG_SIDE_TO_SHORT_SIDE_RATIO * oneEm;
|
|
|
|
autoSize.BSize(wm) = IsThemed() ? 0 : oneEm;
|
2013-02-16 21:57:21 +04:00
|
|
|
} else {
|
2014-08-24 18:34:51 +04:00
|
|
|
autoSize.ISize(wm) = IsThemed() ? 0 : oneEm;
|
|
|
|
autoSize.BSize(wm) = LONG_SIDE_TO_SHORT_SIDE_RATIO * oneEm;
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2014-08-24 18:34:51 +04:00
|
|
|
return autoSize.ConvertTo(aWM, wm);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2017-06-09 22:14:53 +03:00
|
|
|
nsRangeFrame::GetMinISize(gfxContext *aRenderingContext)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2013-02-16 21:57:21 +04:00
|
|
|
// nsFrame::ComputeSize calls GetMinimumWidgetSize to prevent us from being
|
|
|
|
// given too small a size when we're natively themed. If we aren't native
|
|
|
|
// themed, we don't mind how small we're sized.
|
|
|
|
return nscoord(0);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2017-06-09 22:14:53 +03:00
|
|
|
nsRangeFrame::GetPrefISize(gfxContext *aRenderingContext)
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2015-04-29 10:18:54 +03:00
|
|
|
bool isInline = IsInlineOriented();
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2015-04-29 10:18:54 +03:00
|
|
|
if (!isInline && IsThemed()) {
|
2013-02-16 21:57:21 +04:00
|
|
|
// nsFrame::ComputeSize calls GetMinimumWidgetSize to prevent us from being
|
|
|
|
// given too small a size when we're natively themed. We return zero and
|
2015-04-29 10:18:54 +03:00
|
|
|
// depend on that correction to get our "natural" width when we're a
|
2013-02-16 21:57:21 +04:00
|
|
|
// vertical slider.
|
|
|
|
return 0;
|
|
|
|
}
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2015-04-29 10:18:54 +03:00
|
|
|
nscoord prefISize = NSToCoordRound(StyleFont()->mFont.size *
|
2013-02-16 21:57:21 +04:00
|
|
|
nsLayoutUtils::FontSizeInflationFor(this)); // 1em
|
|
|
|
|
2015-04-29 10:18:54 +03:00
|
|
|
if (isInline) {
|
|
|
|
prefISize *= LONG_SIDE_TO_SHORT_SIDE_RATIO;
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2015-04-29 10:18:54 +03:00
|
|
|
return prefISize;
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
bool
|
2015-04-29 10:18:54 +03:00
|
|
|
nsRangeFrame::IsHorizontal() const
|
2013-02-16 21:57:21 +04:00
|
|
|
{
|
2015-04-29 10:18:54 +03:00
|
|
|
dom::HTMLInputElement* element =
|
2017-08-27 01:58:38 +03:00
|
|
|
static_cast<dom::HTMLInputElement*>(GetContent());
|
2015-04-29 10:18:54 +03:00
|
|
|
return element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::orient,
|
|
|
|
nsGkAtoms::horizontal, eCaseMatters) ||
|
|
|
|
(!element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::orient,
|
|
|
|
nsGkAtoms::vertical, eCaseMatters) &&
|
|
|
|
GetWritingMode().IsVertical() ==
|
|
|
|
element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::orient,
|
|
|
|
nsGkAtoms::block, eCaseMatters));
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2013-03-16 09:40:15 +04:00
|
|
|
double
|
|
|
|
nsRangeFrame::GetMin() const
|
|
|
|
{
|
2017-08-27 01:58:38 +03:00
|
|
|
return static_cast<dom::HTMLInputElement*>(GetContent())->GetMinimum().toDouble();
|
2013-03-16 09:40:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
nsRangeFrame::GetMax() const
|
|
|
|
{
|
2017-08-27 01:58:38 +03:00
|
|
|
return static_cast<dom::HTMLInputElement*>(GetContent())->GetMaximum().toDouble();
|
2013-03-16 09:40:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
nsRangeFrame::GetValue() const
|
|
|
|
{
|
2017-08-27 01:58:38 +03:00
|
|
|
return static_cast<dom::HTMLInputElement*>(GetContent())->GetValueAsDecimal().toDouble();
|
2013-03-16 09:40:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define STYLES_DISABLING_NATIVE_THEMING \
|
|
|
|
NS_AUTHOR_SPECIFIED_BACKGROUND | \
|
|
|
|
NS_AUTHOR_SPECIFIED_PADDING | \
|
|
|
|
NS_AUTHOR_SPECIFIED_BORDER
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
bool
|
|
|
|
nsRangeFrame::ShouldUseNativeStyle() const
|
|
|
|
{
|
2015-08-03 14:08:32 +03:00
|
|
|
nsIFrame* trackFrame = mTrackDiv->GetPrimaryFrame();
|
|
|
|
nsIFrame* progressFrame = mProgressDiv->GetPrimaryFrame();
|
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
|
|
|
2018-07-25 16:03:45 +03:00
|
|
|
return (StyleDisplay()->mAppearance == StyleAppearance::Range) &&
|
2015-08-19 01:41:24 +03:00
|
|
|
!PresContext()->HasAuthorSpecifiedRules(this,
|
2013-04-15 09:03:57 +04:00
|
|
|
(NS_AUTHOR_SPECIFIED_BORDER |
|
|
|
|
NS_AUTHOR_SPECIFIED_BACKGROUND)) &&
|
2015-08-03 14:08:32 +03:00
|
|
|
trackFrame &&
|
|
|
|
!PresContext()->HasAuthorSpecifiedRules(trackFrame,
|
2013-03-16 09:40:15 +04:00
|
|
|
STYLES_DISABLING_NATIVE_THEMING) &&
|
2015-08-03 14:08:32 +03:00
|
|
|
progressFrame &&
|
|
|
|
!PresContext()->HasAuthorSpecifiedRules(progressFrame,
|
2013-03-27 03:04:41 +04:00
|
|
|
STYLES_DISABLING_NATIVE_THEMING) &&
|
2015-08-03 14:08:32 +03:00
|
|
|
thumbFrame &&
|
|
|
|
!PresContext()->HasAuthorSpecifiedRules(thumbFrame,
|
2013-03-16 09:40:15 +04:00
|
|
|
STYLES_DISABLING_NATIVE_THEMING);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
2013-12-03 03:57:50 +04:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle*
|
|
|
|
nsRangeFrame::GetAdditionalComputedStyle(int32_t aIndex) const
|
2014-02-19 03:35:07 +04:00
|
|
|
{
|
2018-03-22 21:20:41 +03:00
|
|
|
// We only implement this so that SetAdditionalComputedStyle will be
|
2014-02-19 03:35:07 +04:00
|
|
|
// called if style changes that would change the -moz-focus-outer
|
|
|
|
// pseudo-element have occurred.
|
2015-08-13 15:22:48 +03:00
|
|
|
if (aIndex != 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mOuterFocusStyle;
|
2014-02-19 03:35:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-22 21:20:41 +03:00
|
|
|
nsRangeFrame::SetAdditionalComputedStyle(int32_t aIndex,
|
|
|
|
ComputedStyle* aComputedStyle)
|
2014-02-19 03:35:07 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIndex == 0,
|
2018-03-22 21:20:41 +03:00
|
|
|
"GetAdditionalComputedStyle is handling other indexes?");
|
2015-02-18 01:28:53 +03:00
|
|
|
|
2014-02-19 03:35:07 +04:00
|
|
|
// The -moz-focus-outer pseudo-element's style has changed.
|
2018-03-22 21:20:41 +03:00
|
|
|
mOuterFocusStyle = aComputedStyle;
|
2014-02-19 03:35:07 +04:00
|
|
|
}
|