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"
|
2019-04-06 09:02:28 +03:00
|
|
|
#include "mozilla/PresShell.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"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.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"
|
2019-03-29 18:11:22 +03:00
|
|
|
#include "nsPresContextInlines.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
|
|
|
|
|
2018-11-15 22:47:33 +03:00
|
|
|
// Our intrinsic size is 12em in the main-axis and 1.3em in the cross-axis.
|
|
|
|
#define MAIN_AXIS_EM_SIZE 12
|
|
|
|
#define CROSS_AXIS_EM_SIZE 1.3f
|
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)
|
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsIFrame* NS_NewRangeFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell) nsRangeFrame(aStyle, aPresShell->GetPresContext());
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2019-02-05 19:45:54 +03:00
|
|
|
nsRangeFrame::nsRangeFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
|
|
|
|
: nsContainerFrame(aStyle, aPresContext, kClassID) {}
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2020-03-17 12:38:32 +03:00
|
|
|
nsRangeFrame::~nsRangeFrame() = default;
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsRangeFrame)
|
|
|
|
|
|
|
|
NS_QUERYFRAME_HEAD(nsRangeFrame)
|
2018-12-07 23:00:18 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsRangeFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
2013-02-16 21:57:21 +04:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsRangeFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
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
|
|
|
|
2018-07-24 19:15:01 +03:00
|
|
|
mOuterFocusStyle = styleSet->ProbePseudoElementStyle(
|
2019-02-19 16:44:33 +03:00
|
|
|
*aContent->AsElement(), PseudoStyleType::mozFocusOuter, Style());
|
2014-02-19 03:35:07 +04:00
|
|
|
|
2013-04-11 13:11:54 +04:00
|
|
|
return nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
void nsRangeFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) {
|
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
|
|
|
}
|
|
|
|
|
2013-12-03 08:49:03 +04:00
|
|
|
nsresult nsRangeFrame::MakeAnonymousDiv(Element** aResult,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType,
|
2013-03-27 03:04:41 +04:00
|
|
|
nsTArray<ContentInfo>& aElements) {
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> 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;
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
// Create the ::-moz-range-track pseudo-element (a div):
|
2013-03-27 03:04:41 +04:00
|
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mTrackDiv),
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType::mozRangeTrack, 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),
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType::mozRangeProgress, aElements);
|
2013-03-27 03:04:41 +04:00
|
|
|
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),
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType::mozRangeThumb, aElements);
|
2013-03-27 03:04:41 +04:00
|
|
|
return rv;
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2014-07-16 22:41:57 +04:00
|
|
|
void 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
|
|
|
}
|
|
|
|
|
2019-05-08 16:49:56 +03:00
|
|
|
class nsDisplayRangeFocusRing final : public nsPaintedDisplayItem {
|
2013-04-22 13:11:56 +04:00
|
|
|
public:
|
|
|
|
nsDisplayRangeFocusRing(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
2019-05-08 16:49:56 +03:00
|
|
|
: nsPaintedDisplayItem(aBuilder, aFrame) {
|
2013-04-22 13:11:56 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayRangeFocusRing);
|
|
|
|
}
|
2020-02-20 14:40:14 +03:00
|
|
|
MOZ_COUNTED_DTOR_OVERRIDE(nsDisplayRangeFocusRing)
|
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);
|
|
|
|
}
|
|
|
|
|
2017-08-24 18:09:44 +03:00
|
|
|
void 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);
|
|
|
|
}
|
|
|
|
|
2017-08-24 18:09:44 +03:00
|
|
|
nsRect 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) {
|
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()
|
2019-04-26 02:03:04 +03:00
|
|
|
? PaintBorderFlags::SyncDecodeImages
|
2015-10-23 05:54:49 +03:00
|
|
|
: PaintBorderFlags();
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result = nsCSSRendering::PaintBorder(
|
2015-10-23 05:54:49 +03:00
|
|
|
mFrame->PresContext(), *aCtx, mFrame, GetPaintRect(),
|
2018-05-16 06:56:32 +03:00
|
|
|
GetBounds(aBuilder, &unused), 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 nsRangeFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2013-02-16 21:57:21 +04:00
|
|
|
const nsDisplayListSet& aLists) {
|
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
|
|
|
|
2018-12-06 22:40:50 +03:00
|
|
|
if (!aBuilder->IsForPainting() || !IsVisibleForPainting()) {
|
2014-02-19 03:35:07 +04:00
|
|
|
// 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) &&
|
2020-03-04 04:58:30 +03:00
|
|
|
PresContext()->Theme()->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
|
|
|
|
2019-04-01 19:53:11 +03:00
|
|
|
aLists.Content()->AppendNewToTop<nsDisplayRangeFocusRing>(aBuilder, this);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
void 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) {
|
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();
|
2019-06-05 02:41:20 +03:00
|
|
|
if (computedBSize == NS_UNCONSTRAINEDSIZE) {
|
2014-07-24 12:30:07 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
void 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
|
|
|
// 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();
|
2019-06-05 02:41:20 +03:00
|
|
|
if (rangeFrameContentBoxHeight == NS_UNCONSTRAINEDSIZE) {
|
2013-02-16 21:57:21 +04:00
|
|
|
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, trackFrame,
|
2014-07-24 12:28:46 +04:00
|
|
|
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, trackReflowInput,
|
2019-08-08 22:48:19 +03:00
|
|
|
trackX, trackY, ReflowChildFlags::Default, 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,
|
2019-08-08 22:48:19 +03:00
|
|
|
&trackReflowInput, trackX, trackY,
|
|
|
|
ReflowChildFlags::Default);
|
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, thumbFrame,
|
2014-07-24 12:28:46 +04:00
|
|
|
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, thumbReflowInput, 0,
|
2019-08-08 22:48:19 +03:00
|
|
|
0, ReflowChildFlags::Default, 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,
|
2019-08-08 22:48:19 +03:00
|
|
|
&thumbReflowInput, 0, 0, ReflowChildFlags::Default);
|
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, progressDesiredSize,
|
2019-08-08 22:48:19 +03:00
|
|
|
progressReflowInput, 0, 0, ReflowChildFlags::Default,
|
|
|
|
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, progressDesiredSize,
|
2019-08-08 22:48:19 +03:00
|
|
|
&progressReflowInput, 0, 0, ReflowChildFlags::Default);
|
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) {
|
2018-11-03 00:30:49 +03:00
|
|
|
// Avoid rounding triggering the assert by checking against an epsilon.
|
|
|
|
MOZ_ASSERT((value - minimum).abs().toDouble() <
|
|
|
|
std::numeric_limits<float>::epsilon(),
|
|
|
|
"Unsanitized value");
|
2013-02-16 21:57:21 +04:00
|
|
|
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-10-02 07:46:03 +04:00
|
|
|
Decimal nsRangeFrame::GetValueAtEventPoint(WidgetGUIEvent* aEvent) {
|
2014-08-04 09:28:50 +04:00
|
|
|
MOZ_ASSERT(
|
|
|
|
aEvent->mClass == eMouseEventClass || 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;
|
2020-03-04 04:58:30 +03:00
|
|
|
presContext->Theme()->GetMinimumWidgetSize(presContext, this,
|
|
|
|
StyleAppearance::RangeThumb,
|
|
|
|
&size, ¬UsedCanOverride);
|
2013-03-16 09:40:15 +04:00
|
|
|
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-27 03:04:41 +04:00
|
|
|
void 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
|
2019-04-30 10:53:20 +03:00
|
|
|
if (nsAccessibilityService* accService =
|
|
|
|
PresShell::GetAccessibilityService()) {
|
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);
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:57:21 +04:00
|
|
|
nsresult nsRangeFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute, int32_t aModType) {
|
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) {
|
2019-04-25 08:04:15 +03:00
|
|
|
PresShell()->FrameNeedsReflow(this, IntrinsicDirty::Resize,
|
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);
|
|
|
|
}
|
|
|
|
|
2019-02-15 03:53:23 +03:00
|
|
|
nscoord nsRangeFrame::AutoCrossSize(nscoord aEm) {
|
|
|
|
nscoord minCrossSize(0);
|
|
|
|
if (IsThemed()) {
|
|
|
|
bool unused;
|
|
|
|
LayoutDeviceIntSize size;
|
|
|
|
nsPresContext* pc = PresContext();
|
2020-03-04 04:58:30 +03:00
|
|
|
pc->Theme()->GetMinimumWidgetSize(pc, this, StyleAppearance::RangeThumb,
|
|
|
|
&size, &unused);
|
2019-02-15 03:53:23 +03:00
|
|
|
minCrossSize =
|
|
|
|
pc->DevPixelsToAppUnits(IsHorizontal() ? size.height : size.width);
|
|
|
|
}
|
|
|
|
return std::max(minCrossSize, NSToCoordRound(CROSS_AXIS_EM_SIZE * aEm));
|
|
|
|
}
|
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
LogicalSize nsRangeFrame::ComputeAutoSize(
|
|
|
|
gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
|
2016-11-05 04:57:06 +03:00
|
|
|
nscoord aAvailableISize, const LogicalSize& aMargin,
|
|
|
|
const LogicalSize& aBorder, const LogicalSize& aPadding,
|
|
|
|
ComputeSizeFlags aFlags) {
|
2015-04-29 10:18:54 +03:00
|
|
|
bool isInlineOriented = IsInlineOriented();
|
2018-11-15 22:47:33 +03:00
|
|
|
auto em = StyleFont()->mFont.size * nsLayoutUtils::FontSizeInflationFor(this);
|
2013-02-16 21:57:21 +04:00
|
|
|
|
2014-08-24 18:34:51 +04:00
|
|
|
const WritingMode wm = GetWritingMode();
|
|
|
|
LogicalSize autoSize(wm);
|
|
|
|
if (isInlineOriented) {
|
2018-11-15 22:47:33 +03:00
|
|
|
autoSize.ISize(wm) = NSToCoordRound(MAIN_AXIS_EM_SIZE * em);
|
2019-02-15 03:53:23 +03:00
|
|
|
autoSize.BSize(wm) = AutoCrossSize(em);
|
2013-02-16 21:57:21 +04:00
|
|
|
} else {
|
2019-02-15 03:53:23 +03:00
|
|
|
autoSize.ISize(wm) = AutoCrossSize(em);
|
2018-11-15 22:47:33 +03:00
|
|
|
autoSize.BSize(wm) = NSToCoordRound(MAIN_AXIS_EM_SIZE * em);
|
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
|
|
|
}
|
|
|
|
|
2018-11-15 22:47:33 +03:00
|
|
|
nscoord nsRangeFrame::GetMinISize(gfxContext* aRenderingContext) {
|
2018-12-20 04:01:01 +03:00
|
|
|
auto pos = StylePosition();
|
|
|
|
auto wm = GetWritingMode();
|
|
|
|
if (pos->ISize(wm).HasPercent()) {
|
|
|
|
// https://drafts.csswg.org/css-sizing-3/#percentage-sizing
|
|
|
|
// https://drafts.csswg.org/css-sizing-3/#min-content-zero
|
2019-02-10 15:55:16 +03:00
|
|
|
return nsLayoutUtils::ResolveToLength<true>(
|
|
|
|
pos->ISize(wm).AsLengthPercentage(), nscoord(0));
|
2018-12-20 04:01:01 +03:00
|
|
|
}
|
2018-12-12 00:56:00 +03:00
|
|
|
return GetPrefISize(aRenderingContext);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2018-11-15 22:47:33 +03:00
|
|
|
nscoord nsRangeFrame::GetPrefISize(gfxContext* aRenderingContext) {
|
2015-04-29 10:18:54 +03:00
|
|
|
bool isInline = IsInlineOriented();
|
2018-11-15 22:47:33 +03:00
|
|
|
auto em = StyleFont()->mFont.size * nsLayoutUtils::FontSizeInflationFor(this);
|
2019-02-15 03:53:23 +03:00
|
|
|
return isInline ? NSToCoordRound(em * MAIN_AXIS_EM_SIZE) : AutoCrossSize(em);
|
2013-02-16 21:57:21 +04:00
|
|
|
}
|
|
|
|
|
2015-04-29 10:18:54 +03:00
|
|
|
bool nsRangeFrame::IsHorizontal() const {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-03-26 19:48:01 +03:00
|
|
|
#define STYLES_DISABLING_NATIVE_THEMING \
|
|
|
|
NS_AUTHOR_SPECIFIED_BORDER_OR_BACKGROUND | NS_AUTHOR_SPECIFIED_PADDING
|
2013-03-16 09:40:15 +04:00
|
|
|
|
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();
|
|
|
|
|
2020-03-26 19:48:01 +03:00
|
|
|
return StyleDisplay()->mAppearance == StyleAppearance::Range && trackFrame &&
|
2015-08-03 14:08:32 +03:00
|
|
|
!PresContext()->HasAuthorSpecifiedRules(
|
2013-03-16 09:40:15 +04:00
|
|
|
trackFrame, STYLES_DISABLING_NATIVE_THEMING) &&
|
2015-08-03 14:08:32 +03:00
|
|
|
progressFrame &&
|
|
|
|
!PresContext()->HasAuthorSpecifiedRules(
|
2013-03-27 03:04:41 +04:00
|
|
|
progressFrame, STYLES_DISABLING_NATIVE_THEMING) &&
|
2015-08-03 14:08:32 +03:00
|
|
|
thumbFrame &&
|
|
|
|
!PresContext()->HasAuthorSpecifiedRules(
|
2013-03-16 09:40:15 +04:00
|
|
|
thumbFrame, 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 {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
void 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
|
|
|
}
|