2013-02-16 09:57:21 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "nsRangeFrame.h"
|
|
|
|
|
2013-09-25 04:21:16 -07:00
|
|
|
#include "mozilla/TouchEvents.h"
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
#include "nsContentCreatorFunctions.h"
|
|
|
|
#include "nsContentList.h"
|
|
|
|
#include "nsContentUtils.h"
|
2014-02-18 15:35:07 -08:00
|
|
|
#include "nsCSSRendering.h"
|
2013-02-16 09:57:21 -08:00
|
|
|
#include "nsFormControlFrame.h"
|
2013-02-16 09:57:21 -08:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2013-02-16 09:57:21 -08:00
|
|
|
#include "nsINodeInfo.h"
|
2013-02-16 09:57:21 -08:00
|
|
|
#include "nsIPresShell.h"
|
2013-02-16 09:57:21 -08:00
|
|
|
#include "nsGkAtoms.h"
|
2013-03-28 12:41:32 -07:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
2013-02-16 09:57:21 -08:00
|
|
|
#include "nsPresContext.h"
|
2013-02-16 09:57:21 -08:00
|
|
|
#include "nsNodeInfoManager.h"
|
2013-03-15 22:40:15 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2013-02-16 09:57:21 -08:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsThemeConstants.h"
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-04-27 17:54:54 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
#define LONG_SIDE_TO_SHORT_SIDE_RATIO 10
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-03-28 12:41:32 -07:00
|
|
|
using namespace mozilla;
|
2013-12-02 20:49:03 -08:00
|
|
|
using namespace mozilla::dom;
|
2013-03-28 12:41:32 -07:00
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
nsIFrame*
|
|
|
|
NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsRangeFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRangeFrame::nsRangeFrame(nsStyleContext* aContext)
|
|
|
|
: nsContainerFrame(aContext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRangeFrame::~nsRangeFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-16 09:57:21 -08: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 02:11:54 -07:00
|
|
|
void
|
|
|
|
nsRangeFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
// B2G's AsyncPanZoomController::ReceiveInputEvent handles touch events
|
|
|
|
// without checking whether the out-of-process document that it controls
|
|
|
|
// will handle them, unless it has been told that the document might do so.
|
|
|
|
// This is for perf reasons, otherwise it has to wait for the event to be
|
|
|
|
// round-tripped to the other process and back, delaying panning, etc.
|
|
|
|
// We must call SetHasTouchEventListeners() in order to get APZC to wait
|
|
|
|
// until the event has been round-tripped and check whether it has been
|
|
|
|
// handled, otherwise B2G will end up panning the document when the user
|
|
|
|
// tries to drag our thumb.
|
|
|
|
//
|
|
|
|
nsIPresShell* presShell = PresContext()->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
nsIDocument* document = presShell->GetDocument();
|
|
|
|
if (document) {
|
|
|
|
nsPIDOMWindow* innerWin = document->GetInnerWindow();
|
|
|
|
if (innerWin) {
|
|
|
|
innerWin->SetHasTouchEventListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-18 15:35:07 -08:00
|
|
|
|
|
|
|
nsStyleSet *styleSet = PresContext()->StyleSet();
|
|
|
|
|
|
|
|
mOuterFocusStyle =
|
|
|
|
styleSet->ProbePseudoElementStyle(aContent->AsElement(),
|
|
|
|
nsCSSPseudoElements::ePseudo_mozFocusOuter,
|
|
|
|
StyleContext());
|
|
|
|
|
2013-04-11 02:11:54 -07:00
|
|
|
return nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
void
|
|
|
|
nsRangeFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
|
|
{
|
2013-02-16 09:57:21 -08:00
|
|
|
NS_ASSERTION(!GetPrevContinuation() && !GetNextContinuation(),
|
2013-02-16 09:57:21 -08:00
|
|
|
"nsRangeFrame should not have continuations; if it does we "
|
|
|
|
"need to call RegUnregAccessKey only for the first.");
|
|
|
|
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
2013-02-16 09:57:21 -08:00
|
|
|
nsContentUtils::DestroyAnonymousContent(&mTrackDiv);
|
2013-03-26 16:04:41 -07:00
|
|
|
nsContentUtils::DestroyAnonymousContent(&mProgressDiv);
|
2013-02-16 09:57:21 -08:00
|
|
|
nsContentUtils::DestroyAnonymousContent(&mThumbDiv);
|
|
|
|
nsContainerFrame::DestroyFrom(aDestructRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-12-02 20:49:03 -08:00
|
|
|
nsRangeFrame::MakeAnonymousDiv(Element** aResult,
|
2013-03-26 16:04:41 -07:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
|
|
|
nsTArray<ContentInfo>& aElements)
|
2013-02-16 09:57:21 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
|
2013-12-02 20:49:03 -08:00
|
|
|
nsRefPtr<Element> resultElement = doc->CreateHTMLElement(nsGkAtoms::div);
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-03-26 16:04:41 -07:00
|
|
|
// Associate the pseudo-element with the anonymous child.
|
2013-02-16 09:57:21 -08:00
|
|
|
nsRefPtr<nsStyleContext> newStyleContext =
|
|
|
|
PresContext()->StyleSet()->ResolvePseudoElementStyle(mContent->AsElement(),
|
2013-03-26 16:04:41 -07:00
|
|
|
aPseudoType,
|
2013-11-27 22:46:38 -08:00
|
|
|
StyleContext(),
|
2013-12-02 20:49:03 -08:00
|
|
|
resultElement);
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-12-02 20:49:03 -08:00
|
|
|
if (!aElements.AppendElement(ContentInfo(resultElement, newStyleContext))) {
|
2013-02-16 09:57:21 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2013-12-02 20:49:03 -08:00
|
|
|
|
|
|
|
resultElement.forget(aResult);
|
2013-03-26 16:04:41 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-26 16:04:41 -07:00
|
|
|
|
2013-03-26 16:04:41 -07:00
|
|
|
nsresult
|
|
|
|
nsRangeFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Create the ::-moz-range-track pseuto-element (a div):
|
|
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mTrackDiv),
|
|
|
|
nsCSSPseudoElements::ePseudo_mozRangeTrack,
|
|
|
|
aElements);
|
2013-02-16 09:57:21 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-03-26 16:04:41 -07:00
|
|
|
// Create the ::-moz-range-progress pseudo-element (a div):
|
|
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mProgressDiv),
|
|
|
|
nsCSSPseudoElements::ePseudo_mozRangeProgress,
|
|
|
|
aElements);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-03-26 16:04:41 -07:00
|
|
|
// Create the ::-moz-range-thumb pseudo-element (a div):
|
|
|
|
rv = MakeAnonymousDiv(getter_AddRefs(mThumbDiv),
|
|
|
|
nsCSSPseudoElements::ePseudo_mozRangeThumb,
|
|
|
|
aElements);
|
|
|
|
return rv;
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRangeFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
|
|
|
|
uint32_t aFilter)
|
|
|
|
{
|
2013-02-16 09:57:21 -08:00
|
|
|
aElements.MaybeAppendElement(mTrackDiv);
|
2013-03-26 16:04:41 -07:00
|
|
|
aElements.MaybeAppendElement(mProgressDiv);
|
2013-02-16 09:57:21 -08:00
|
|
|
aElements.MaybeAppendElement(mThumbDiv);
|
|
|
|
}
|
|
|
|
|
2013-04-22 02:11:56 -07: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-18 15:35:07 -08:00
|
|
|
|
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE;
|
2013-04-22 02:11:56 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
|
|
|
|
NS_DISPLAY_DECL_NAME("RangeFocusRing", TYPE_OUTLINE)
|
|
|
|
};
|
|
|
|
|
2014-02-18 15:35:07 -08:00
|
|
|
nsRect
|
|
|
|
nsDisplayRangeFocusRing::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
|
|
|
{
|
|
|
|
*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:
|
|
|
|
nsStyleContext* styleContext =
|
|
|
|
static_cast<nsRangeFrame*>(mFrame)->mOuterFocusStyle;
|
|
|
|
MOZ_ASSERT(styleContext, "We only exist if mOuterFocusStyle is non-null");
|
|
|
|
rect.Inflate(styleContext->StyleBorder()->GetComputedBorder());
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2013-04-22 02:11:56 -07:00
|
|
|
void
|
|
|
|
nsDisplayRangeFocusRing::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
|
|
|
{
|
2014-02-18 15:35:07 -08:00
|
|
|
bool unused;
|
|
|
|
nsStyleContext* styleContext =
|
|
|
|
static_cast<nsRangeFrame*>(mFrame)->mOuterFocusStyle;
|
|
|
|
MOZ_ASSERT(styleContext, "We only exist if mOuterFocusStyle is non-null");
|
|
|
|
nsCSSRendering::PaintBorder(mFrame->PresContext(), *aCtx, mFrame,
|
|
|
|
mVisibleRect, GetBounds(aBuilder, &unused),
|
|
|
|
styleContext);
|
2013-04-22 02:11:56 -07:00
|
|
|
}
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
void
|
2013-02-16 09:57:21 -08:00
|
|
|
nsRangeFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2013-02-16 09:57:21 -08:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
2013-02-16 09:57:21 -08:00
|
|
|
{
|
2013-04-03 03:07:12 -07:00
|
|
|
if (IsThemed()) {
|
|
|
|
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());
|
|
|
|
BuildDisplayListForChild(aBuilder, thumb, aDirtyRect, set, DISPLAY_CHILD_INLINE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BuildDisplayListForInline(aBuilder, aDirtyRect, aLists);
|
|
|
|
}
|
2013-04-22 02:11:56 -07:00
|
|
|
|
|
|
|
// Draw a focus outline if appropriate:
|
2014-02-18 15:35:07 -08: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;
|
|
|
|
}
|
|
|
|
|
2013-04-22 02:11:56 -07:00
|
|
|
nsEventStates eventStates = mContent->AsElement()->State();
|
2014-02-18 15:35:07 -08: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 02:11:56 -07:00
|
|
|
return;
|
|
|
|
}
|
2014-02-18 15:35:07 -08:00
|
|
|
|
2013-04-22 02:11:56 -07:00
|
|
|
const nsStyleDisplay *disp = StyleDisplay();
|
2014-02-18 15:35:07 -08:00
|
|
|
if (IsThemed(disp) &&
|
|
|
|
PresContext()->GetTheme()->ThemeDrawsFocusForWidget(disp->mAppearance)) {
|
|
|
|
return; // the native theme displays its own visual indication of focus
|
2013-04-22 02:11:56 -07:00
|
|
|
}
|
2014-02-18 15:35:07 -08:00
|
|
|
|
|
|
|
aLists.Content()->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayRangeFocusRing(aBuilder, this));
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2013-02-16 09:57:21 -08:00
|
|
|
nsRangeFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
2013-02-16 09:57:21 -08:00
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsRangeFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
|
2013-03-26 16:04:41 -07: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 09:57:21 -08:00
|
|
|
NS_ASSERTION(!GetPrevContinuation() && !GetNextContinuation(),
|
2013-02-16 09:57:21 -08:00
|
|
|
"nsRangeFrame should not have continuations; if it does we "
|
|
|
|
"need to call RegUnregAccessKey only for the first.");
|
|
|
|
|
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, true);
|
|
|
|
}
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
nscoord computedHeight = aReflowState.ComputedHeight();
|
|
|
|
if (computedHeight == NS_AUTOHEIGHT) {
|
|
|
|
computedHeight = 0;
|
|
|
|
}
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Width() = aReflowState.ComputedWidth() +
|
2013-12-27 09:59:21 -08:00
|
|
|
aReflowState.ComputedPhysicalBorderPadding().LeftRight();
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Height() = computedHeight +
|
2013-12-27 09:59:21 -08:00
|
|
|
aReflowState.ComputedPhysicalBorderPadding().TopBottom();
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
nsresult rv =
|
|
|
|
ReflowAnonymousContent(aPresContext, aDesiredSize, aReflowState);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
nsIFrame* trackFrame = mTrackDiv->GetPrimaryFrame();
|
|
|
|
if (trackFrame) {
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, trackFrame);
|
|
|
|
}
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-03-26 16:04:41 -07:00
|
|
|
nsIFrame* rangeProgressFrame = mProgressDiv->GetPrimaryFrame();
|
|
|
|
if (rangeProgressFrame) {
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, rangeProgressFrame);
|
|
|
|
}
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
|
|
if (thumbFrame) {
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, thumbFrame);
|
|
|
|
}
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
2013-02-16 09:57:21 -08:00
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
nsresult
|
|
|
|
nsRangeFrame::ReflowAnonymousContent(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState)
|
2013-02-16 09:57:21 -08:00
|
|
|
{
|
2013-02-16 09:57:21 -08:00
|
|
|
// The width/height of our content box, which is the available width/height
|
|
|
|
// for our anonymous content:
|
|
|
|
nscoord rangeFrameContentBoxWidth = aReflowState.ComputedWidth();
|
|
|
|
nscoord rangeFrameContentBoxHeight = aReflowState.ComputedHeight();
|
|
|
|
if (rangeFrameContentBoxHeight == NS_AUTOHEIGHT) {
|
|
|
|
rangeFrameContentBoxHeight = 0;
|
|
|
|
}
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-02-16 09:57:21 -08: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.
|
|
|
|
|
|
|
|
nsHTMLReflowState trackReflowState(aPresContext, aReflowState, trackFrame,
|
|
|
|
nsSize(aReflowState.ComputedWidth(),
|
|
|
|
NS_UNCONSTRAINEDSIZE));
|
|
|
|
|
|
|
|
// 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):
|
2013-12-27 09:59:21 -08:00
|
|
|
trackX -= trackReflowState.ComputedPhysicalBorderPadding().left +
|
2013-02-16 09:57:21 -08:00
|
|
|
trackReflowState.ComputedWidth() / 2;
|
2013-12-27 09:59:21 -08:00
|
|
|
trackY -= trackReflowState.ComputedPhysicalBorderPadding().top +
|
2013-02-16 09:57:21 -08:00
|
|
|
trackReflowState.ComputedHeight() / 2;
|
|
|
|
|
|
|
|
// Make relative to our border box instead of our content box:
|
2013-12-27 09:59:21 -08:00
|
|
|
trackX += aReflowState.ComputedPhysicalBorderPadding().left;
|
|
|
|
trackY += aReflowState.ComputedPhysicalBorderPadding().top;
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-03-29 02:49:53 -07:00
|
|
|
nsReflowStatus frameStatus;
|
2013-12-31 05:50:31 -08:00
|
|
|
nsHTMLReflowMetrics trackDesiredSize(aReflowState);
|
2013-02-16 09:57:21 -08:00
|
|
|
nsresult rv = ReflowChild(trackFrame, aPresContext, trackDesiredSize,
|
|
|
|
trackReflowState, trackX, trackY, 0, frameStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
MOZ_ASSERT(NS_FRAME_IS_FULLY_COMPLETE(frameStatus),
|
|
|
|
"We gave our child unconstrained height, so it should be complete");
|
2014-01-16 17:34:44 -08:00
|
|
|
rv = FinishReflowChild(trackFrame, aPresContext, trackDesiredSize,
|
|
|
|
&trackReflowState, trackX, trackY, 0);
|
2013-02-16 09:57:21 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
if (thumbFrame) { // display:none?
|
|
|
|
nsHTMLReflowState thumbReflowState(aPresContext, aReflowState, thumbFrame,
|
|
|
|
nsSize(aReflowState.ComputedWidth(),
|
|
|
|
NS_UNCONSTRAINEDSIZE));
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-03-20 23:41:32 -07:00
|
|
|
// Where we position the thumb depends on its size, so we first reflow
|
2013-03-15 02:04:54 -07:00
|
|
|
// the thumb at {0,0} to obtain its size, then position it afterwards.
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-03-29 02:49:53 -07:00
|
|
|
nsReflowStatus frameStatus;
|
2013-12-31 05:50:31 -08:00
|
|
|
nsHTMLReflowMetrics thumbDesiredSize(aReflowState);
|
2013-02-16 09:57:21 -08:00
|
|
|
nsresult rv = ReflowChild(thumbFrame, aPresContext, thumbDesiredSize,
|
2013-03-15 02:04:54 -07:00
|
|
|
thumbReflowState, 0, 0, 0, frameStatus);
|
2013-02-16 09:57:21 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
MOZ_ASSERT(NS_FRAME_IS_FULLY_COMPLETE(frameStatus),
|
|
|
|
"We gave our child unconstrained height, so it should be complete");
|
2014-01-16 17:34:44 -08:00
|
|
|
rv = FinishReflowChild(thumbFrame, aPresContext, thumbDesiredSize,
|
|
|
|
&thumbReflowState, 0, 0, 0);
|
2013-02-16 09:57:21 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-03-15 02:04:54 -07:00
|
|
|
|
2013-12-27 09:59:52 -08:00
|
|
|
DoUpdateThumbPosition(thumbFrame, nsSize(aDesiredSize.Width(),
|
|
|
|
aDesiredSize.Height()));
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
|
|
|
|
2013-03-26 16:04:41 -07:00
|
|
|
nsIFrame* rangeProgressFrame = mProgressDiv->GetPrimaryFrame();
|
|
|
|
|
|
|
|
if (rangeProgressFrame) { // display:none?
|
|
|
|
nsHTMLReflowState progressReflowState(aPresContext, aReflowState,
|
|
|
|
rangeProgressFrame,
|
|
|
|
nsSize(aReflowState.ComputedWidth(),
|
|
|
|
NS_UNCONSTRAINEDSIZE));
|
|
|
|
|
|
|
|
// 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 02:49:53 -07:00
|
|
|
nsReflowStatus frameStatus;
|
2013-12-31 05:50:31 -08:00
|
|
|
nsHTMLReflowMetrics progressDesiredSize(aReflowState);
|
2013-03-26 16:04:41 -07:00
|
|
|
nsresult rv = ReflowChild(rangeProgressFrame, aPresContext,
|
|
|
|
progressDesiredSize, progressReflowState, 0, 0,
|
|
|
|
0, frameStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
MOZ_ASSERT(NS_FRAME_IS_FULLY_COMPLETE(frameStatus),
|
|
|
|
"We gave our child unconstrained height, so it should be complete");
|
|
|
|
rv = FinishReflowChild(rangeProgressFrame, aPresContext,
|
2014-01-16 17:34:44 -08:00
|
|
|
progressDesiredSize, &progressReflowState, 0, 0, 0);
|
2013-03-26 16:04:41 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-12-27 09:59:52 -08:00
|
|
|
DoUpdateRangeProgressFrame(rangeProgressFrame, nsSize(aDesiredSize.Width(),
|
|
|
|
aDesiredSize.Height()));
|
2013-03-26 16:04:41 -07:00
|
|
|
}
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-04-27 17:54:54 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
a11y::AccType
|
|
|
|
nsRangeFrame::AccessibleType()
|
|
|
|
{
|
|
|
|
return a11y::eHTMLRangeType;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
double
|
|
|
|
nsRangeFrame::GetValueAsFractionOfRange()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mContent->IsHTML(nsGkAtoms::input), "bad cast");
|
2013-03-28 12:41:32 -07:00
|
|
|
dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(mContent);
|
2013-02-16 09:57:21 -08:00
|
|
|
|
|
|
|
MOZ_ASSERT(input->GetType() == NS_FORM_INPUT_RANGE);
|
|
|
|
|
2013-05-05 16:23:18 -07:00
|
|
|
Decimal value = input->GetValueAsDecimal();
|
|
|
|
Decimal minimum = input->GetMinimum();
|
|
|
|
Decimal maximum = input->GetMaximum();
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-05-05 16:23:18 -07:00
|
|
|
MOZ_ASSERT(value.isFinite() && minimum.isFinite() && maximum.isFinite(),
|
2013-02-16 09:57:21 -08:00
|
|
|
"type=range should have a default maximum/minimum");
|
|
|
|
|
|
|
|
if (maximum <= minimum) {
|
|
|
|
MOZ_ASSERT(value == minimum, "Unsanitized value");
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(value >= minimum && value <= maximum, "Unsanitized value");
|
|
|
|
|
2013-05-05 16:23:18 -07:00
|
|
|
return ((value - minimum) / (maximum - minimum)).toDouble();
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-05-05 16:23:18 -07:00
|
|
|
Decimal
|
2013-10-01 20:46:03 -07:00
|
|
|
nsRangeFrame::GetValueAtEventPoint(WidgetGUIEvent* aEvent)
|
2013-03-08 01:40:12 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aEvent->eventStructType == NS_MOUSE_EVENT ||
|
|
|
|
aEvent->eventStructType == NS_TOUCH_EVENT,
|
|
|
|
"Unexpected event type - aEvent->refPoint may be meaningless");
|
|
|
|
|
|
|
|
MOZ_ASSERT(mContent->IsHTML(nsGkAtoms::input), "bad cast");
|
2013-03-28 12:41:32 -07:00
|
|
|
dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(mContent);
|
2013-03-08 01:40:12 -08:00
|
|
|
|
|
|
|
MOZ_ASSERT(input->GetType() == NS_FORM_INPUT_RANGE);
|
|
|
|
|
2013-05-05 16:23:18 -07:00
|
|
|
Decimal minimum = input->GetMinimum();
|
|
|
|
Decimal maximum = input->GetMaximum();
|
|
|
|
MOZ_ASSERT(minimum.isFinite() && maximum.isFinite(),
|
2013-03-08 01:40:12 -08:00
|
|
|
"type=range should have a default maximum/minimum");
|
2013-03-15 02:04:54 -07:00
|
|
|
if (maximum <= minimum) {
|
2013-03-08 01:40:12 -08:00
|
|
|
return minimum;
|
|
|
|
}
|
2013-05-05 16:23:18 -07:00
|
|
|
Decimal range = maximum - minimum;
|
2013-03-08 01:40:12 -08:00
|
|
|
|
2013-08-02 00:05:16 -07:00
|
|
|
LayoutDeviceIntPoint absPoint;
|
2013-03-08 01:40:12 -08:00
|
|
|
if (aEvent->eventStructType == NS_TOUCH_EVENT) {
|
2013-10-17 23:10:23 -07:00
|
|
|
MOZ_ASSERT(aEvent->AsTouchEvent()->touches.Length() == 1,
|
2013-03-08 01:40:12 -08:00
|
|
|
"Unexpected number of touches");
|
2013-08-02 00:05:16 -07:00
|
|
|
absPoint = LayoutDeviceIntPoint::FromUntyped(
|
2013-10-17 23:10:23 -07:00
|
|
|
aEvent->AsTouchEvent()->touches[0]->mRefPoint);
|
2013-03-08 01:40:12 -08:00
|
|
|
} else {
|
2013-03-15 02:04:54 -07:00
|
|
|
absPoint = aEvent->refPoint;
|
2013-03-08 01:40:12 -08:00
|
|
|
}
|
2013-03-15 02:04:54 -07:00
|
|
|
nsPoint point =
|
2013-08-02 00:05:16 -07:00
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,
|
|
|
|
LayoutDeviceIntPoint::ToUntyped(absPoint), this);
|
2013-03-08 01:40:12 -08:00
|
|
|
|
2013-04-14 22:01:38 -07:00
|
|
|
if (point == nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)) {
|
|
|
|
// We don't want to change the current value for this error state.
|
2013-05-05 16:23:18 -07:00
|
|
|
return static_cast<dom::HTMLInputElement*>(mContent)->GetValueAsDecimal();
|
2013-04-14 22:01:38 -07:00
|
|
|
}
|
|
|
|
|
2013-03-15 02:04:54 -07:00
|
|
|
nsRect rangeContentRect = GetContentRectRelativeToSelf();
|
|
|
|
nsSize thumbSize;
|
2013-03-15 22:40:15 -07:00
|
|
|
|
|
|
|
if (IsThemed()) {
|
|
|
|
// We need to get the size of the thumb from the theme.
|
|
|
|
nsPresContext *presContext = PresContext();
|
|
|
|
nsRefPtr<nsRenderingContext> tmpCtx =
|
|
|
|
presContext->PresShell()->GetReferenceRenderingContext();
|
|
|
|
bool notUsedCanOverride;
|
|
|
|
nsIntSize size;
|
|
|
|
presContext->GetTheme()->
|
|
|
|
GetMinimumWidgetSize(tmpCtx.get(), this, NS_THEME_RANGE_THUMB, &size,
|
|
|
|
¬UsedCanOverride);
|
|
|
|
thumbSize.width = presContext->DevPixelsToAppUnits(size.width);
|
|
|
|
thumbSize.height = presContext->DevPixelsToAppUnits(size.height);
|
|
|
|
MOZ_ASSERT(thumbSize.width > 0 && thumbSize.height > 0);
|
|
|
|
} else {
|
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
|
|
|
if (thumbFrame) { // diplay:none?
|
|
|
|
thumbSize = thumbFrame->GetSize();
|
|
|
|
}
|
2013-03-08 01:40:12 -08:00
|
|
|
}
|
2013-03-15 02:04:54 -07:00
|
|
|
|
2013-05-05 16:23:18 -07:00
|
|
|
Decimal fraction;
|
2013-03-15 02:04:54 -07: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);
|
2013-05-05 16:23:18 -07:00
|
|
|
fraction = Decimal(posOfPoint - posAtStart) / traversableDistance;
|
2013-03-15 02:04:54 -07:00
|
|
|
if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
2013-05-05 16:23:18 -07:00
|
|
|
fraction = Decimal(1) - fraction;
|
2013-03-15 02:04:54 -07: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.
|
2013-05-05 16:23:18 -07:00
|
|
|
fraction = Decimal(1) - Decimal(posOfPoint - posAtStart) / traversableDistance;
|
2013-03-15 02:04:54 -07:00
|
|
|
}
|
|
|
|
|
2013-05-05 16:23:18 -07:00
|
|
|
MOZ_ASSERT(fraction >= 0 && fraction <= 1);
|
2013-03-15 02:04:54 -07:00
|
|
|
return minimum + fraction * range;
|
2013-03-08 01:40:12 -08:00
|
|
|
}
|
|
|
|
|
2013-03-13 04:48:27 -07:00
|
|
|
void
|
2013-03-26 16:04:41 -07:00
|
|
|
nsRangeFrame::UpdateForValueChange()
|
2013-03-13 04:48:27 -07:00
|
|
|
{
|
|
|
|
if (NS_SUBTREE_DIRTY(this)) {
|
|
|
|
return; // we're going to be updated when we reflow
|
|
|
|
}
|
2013-03-26 16:04:41 -07:00
|
|
|
nsIFrame* rangeProgressFrame = mProgressDiv->GetPrimaryFrame();
|
2013-03-13 04:48:27 -07:00
|
|
|
nsIFrame* thumbFrame = mThumbDiv->GetPrimaryFrame();
|
2013-03-26 16:04:41 -07:00
|
|
|
if (!rangeProgressFrame && !thumbFrame) {
|
2013-03-13 04:48:27 -07:00
|
|
|
return; // diplay:none?
|
|
|
|
}
|
2013-03-26 16:04:41 -07:00
|
|
|
if (rangeProgressFrame) {
|
|
|
|
DoUpdateRangeProgressFrame(rangeProgressFrame, GetSize());
|
|
|
|
}
|
|
|
|
if (thumbFrame) {
|
|
|
|
DoUpdateThumbPosition(thumbFrame, GetSize());
|
|
|
|
}
|
2013-03-15 22:40:15 -07: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-27 17:54:54 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
nsAccessibilityService* accService = nsIPresShell::AccService();
|
|
|
|
if (accService) {
|
|
|
|
accService->RangeValueChanged(PresContext()->PresShell(), mContent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-15 02:04:54 -07: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 04:48:27 -07:00
|
|
|
nsMargin borderAndPadding = GetUsedBorderAndPadding();
|
|
|
|
nsPoint newPosition(borderAndPadding.left, borderAndPadding.top);
|
2013-03-15 02:04:54 -07: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);
|
|
|
|
|
|
|
|
// We are called under Reflow, so we need to pass IsHorizontal a valid rect.
|
|
|
|
nsSize frameSizeOverride(aRangeSize.width, aRangeSize.height);
|
|
|
|
if (IsHorizontal(&frameSizeOverride)) {
|
|
|
|
if (thumbSize.width < rangeContentBoxSize.width) {
|
|
|
|
nscoord traversableDistance =
|
|
|
|
rangeContentBoxSize.width - thumbSize.width;
|
|
|
|
if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
|
|
|
newPosition.x += NSToCoordRound((1.0 - fraction) * traversableDistance);
|
|
|
|
} else {
|
|
|
|
newPosition.x += NSToCoordRound(fraction * traversableDistance);
|
|
|
|
}
|
|
|
|
newPosition.y += (rangeContentBoxSize.height - thumbSize.height)/2;
|
|
|
|
}
|
2013-03-13 04:48:27 -07:00
|
|
|
} else {
|
2013-03-15 02:04:54 -07: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 04:48:27 -07:00
|
|
|
}
|
2013-03-15 02:04:54 -07:00
|
|
|
aThumbFrame->SetPosition(newPosition);
|
2013-03-13 04:48:27 -07:00
|
|
|
}
|
2013-03-08 01:40:12 -08:00
|
|
|
|
2013-03-26 16:04:41 -07: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);
|
|
|
|
|
|
|
|
// We are called under Reflow, so we need to pass IsHorizontal a valid rect.
|
|
|
|
nsSize frameSizeOverride(aRangeSize.width, aRangeSize.height);
|
|
|
|
if (IsHorizontal(&frameSizeOverride)) {
|
|
|
|
nscoord progLength = NSToCoordRound(fraction * rangeContentBoxSize.width);
|
|
|
|
if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
|
|
|
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-17 23:47:48 -08:00
|
|
|
nsresult
|
2013-02-16 09:57:21 -08:00
|
|
|
nsRangeFrame::AttributeChanged(int32_t aNameSpaceID,
|
2013-02-16 09:57:21 -08:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType)
|
2013-02-16 09:57:21 -08:00
|
|
|
{
|
2013-02-16 09:57:21 -08:00
|
|
|
NS_ASSERTION(mTrackDiv, "The track div must exist!");
|
|
|
|
NS_ASSERTION(mThumbDiv, "The thumb div must exist!");
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-03-26 06:54:05 -07: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 12:41:32 -07:00
|
|
|
// SetAttr(..., nsGkAtoms::value, ...) call in HTMLInputElement::
|
|
|
|
// HandleTypeChange. In that case the HTMLInputElement's type will
|
2013-03-26 16:04:41 -07:00
|
|
|
// already have changed, and if we call UpdateForValueChange()
|
2013-03-26 06:54:05 -07:00
|
|
|
// we'll fail the asserts under that call that check the type of our
|
2013-03-28 12:41:32 -07:00
|
|
|
// HTMLInputElement. Given that we're changing away from being a range
|
2013-03-26 06:54:05 -07:00
|
|
|
// and this frame will shortly be destroyed, there's no point in calling
|
2013-03-26 16:04:41 -07:00
|
|
|
// UpdateForValueChange() anyway.
|
2013-03-26 06:54:05 -07:00
|
|
|
MOZ_ASSERT(mContent->IsHTML(nsGkAtoms::input), "bad cast");
|
2013-03-28 12:41:32 -07:00
|
|
|
bool typeIsRange = static_cast<dom::HTMLInputElement*>(mContent)->GetType() ==
|
2013-03-26 06:54:05 -07:00
|
|
|
NS_FORM_INPUT_RANGE;
|
2013-09-24 13:29:31 -07: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 06:54:05 -07:00
|
|
|
if (typeIsRange) {
|
2013-03-26 16:04:41 -07:00
|
|
|
UpdateForValueChange();
|
2013-03-26 06:54:05 -07:00
|
|
|
}
|
|
|
|
} else if (aAttribute == nsGkAtoms::orient) {
|
|
|
|
PresContext()->PresShell()->FrameNeedsReflow(this, nsIPresShell::eResize,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2013-03-13 06:59:11 -07:00
|
|
|
}
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsRangeFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
|
2013-02-16 09:57:21 -08:00
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder,
|
|
|
|
nsSize aPadding, bool aShrinkWrap)
|
2013-02-16 09:57:21 -08:00
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
nscoord oneEm = NSToCoordRound(StyleFont()->mFont.size *
|
2013-02-16 09:57:21 -08:00
|
|
|
nsLayoutUtils::FontSizeInflationFor(this)); // 1em
|
|
|
|
|
|
|
|
// frameSizeOverride values just gets us to fall back to being horizontal
|
|
|
|
// (the actual values are irrelevant, as long as width > height):
|
|
|
|
nsSize frameSizeOverride(10,1);
|
|
|
|
bool isHorizontal = IsHorizontal(&frameSizeOverride);
|
2013-02-16 09:57:21 -08:00
|
|
|
|
|
|
|
nsSize autoSize;
|
|
|
|
|
2013-02-16 09:57:21 -08: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.
|
|
|
|
|
|
|
|
if (isHorizontal) {
|
|
|
|
autoSize.width = LONG_SIDE_TO_SHORT_SIDE_RATIO * oneEm;
|
|
|
|
autoSize.height = IsThemed() ? 0 : oneEm;
|
2013-02-16 09:57:21 -08:00
|
|
|
} else {
|
2013-02-16 09:57:21 -08:00
|
|
|
autoSize.width = IsThemed() ? 0 : oneEm;
|
|
|
|
autoSize.height = LONG_SIDE_TO_SHORT_SIDE_RATIO * oneEm;
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return autoSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsRangeFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
|
|
|
{
|
2013-02-16 09:57:21 -08: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 09:57:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsRangeFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
|
|
|
{
|
2013-02-16 09:57:21 -08:00
|
|
|
// frameSizeOverride values just gets us to fall back to being horizontal:
|
|
|
|
nsSize frameSizeOverride(10,1);
|
|
|
|
bool isHorizontal = IsHorizontal(&frameSizeOverride);
|
|
|
|
|
|
|
|
if (!isHorizontal && IsThemed()) {
|
|
|
|
// nsFrame::ComputeSize calls GetMinimumWidgetSize to prevent us from being
|
|
|
|
// given too small a size when we're natively themed. We return zero and
|
|
|
|
// depend on that correction to get our "natuaral" width when we're a
|
|
|
|
// vertical slider.
|
|
|
|
return 0;
|
|
|
|
}
|
2013-02-16 09:57:21 -08:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
nscoord prefWidth = NSToCoordRound(StyleFont()->mFont.size *
|
2013-02-16 09:57:21 -08:00
|
|
|
nsLayoutUtils::FontSizeInflationFor(this)); // 1em
|
|
|
|
|
|
|
|
if (isHorizontal) {
|
|
|
|
prefWidth *= LONG_SIDE_TO_SHORT_SIDE_RATIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prefWidth;
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
bool
|
|
|
|
nsRangeFrame::IsHorizontal(const nsSize *aFrameSizeOverride) const
|
2013-02-16 09:57:21 -08:00
|
|
|
{
|
2013-03-28 12:41:32 -07:00
|
|
|
dom::HTMLInputElement* element = static_cast<dom::HTMLInputElement*>(mContent);
|
2013-03-26 06:54:05 -07:00
|
|
|
return !element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::orient,
|
|
|
|
nsGkAtoms::vertical, eCaseMatters);
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
|
|
|
|
2013-03-15 22:40:15 -07:00
|
|
|
double
|
|
|
|
nsRangeFrame::GetMin() const
|
|
|
|
{
|
2013-05-05 16:23:18 -07:00
|
|
|
return static_cast<dom::HTMLInputElement*>(mContent)->GetMinimum().toDouble();
|
2013-03-15 22:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
nsRangeFrame::GetMax() const
|
|
|
|
{
|
2013-05-05 16:23:18 -07:00
|
|
|
return static_cast<dom::HTMLInputElement*>(mContent)->GetMaximum().toDouble();
|
2013-03-15 22:40:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
nsRangeFrame::GetValue() const
|
|
|
|
{
|
2013-05-05 16:23:18 -07:00
|
|
|
return static_cast<dom::HTMLInputElement*>(mContent)->GetValueAsDecimal().toDouble();
|
2013-03-15 22:40:15 -07:00
|
|
|
}
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
nsIAtom*
|
|
|
|
nsRangeFrame::GetType() const
|
2013-02-16 09:57:21 -08:00
|
|
|
{
|
2013-02-16 09:57:21 -08:00
|
|
|
return nsGkAtoms::rangeFrame;
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
|
|
|
|
2013-03-15 22:40:15 -07:00
|
|
|
#define STYLES_DISABLING_NATIVE_THEMING \
|
|
|
|
NS_AUTHOR_SPECIFIED_BACKGROUND | \
|
|
|
|
NS_AUTHOR_SPECIFIED_PADDING | \
|
|
|
|
NS_AUTHOR_SPECIFIED_BORDER
|
|
|
|
|
2013-02-16 09:57:21 -08:00
|
|
|
bool
|
|
|
|
nsRangeFrame::ShouldUseNativeStyle() const
|
|
|
|
{
|
2013-03-15 22:40:15 -07:00
|
|
|
return (StyleDisplay()->mAppearance == NS_THEME_RANGE) &&
|
|
|
|
!PresContext()->HasAuthorSpecifiedRules(const_cast<nsRangeFrame*>(this),
|
2013-04-14 22:03:57 -07:00
|
|
|
(NS_AUTHOR_SPECIFIED_BORDER |
|
|
|
|
NS_AUTHOR_SPECIFIED_BACKGROUND)) &&
|
2013-03-15 22:40:15 -07:00
|
|
|
!PresContext()->HasAuthorSpecifiedRules(mTrackDiv->GetPrimaryFrame(),
|
|
|
|
STYLES_DISABLING_NATIVE_THEMING) &&
|
2013-03-26 16:04:41 -07:00
|
|
|
!PresContext()->HasAuthorSpecifiedRules(mProgressDiv->GetPrimaryFrame(),
|
|
|
|
STYLES_DISABLING_NATIVE_THEMING) &&
|
2013-03-15 22:40:15 -07:00
|
|
|
!PresContext()->HasAuthorSpecifiedRules(mThumbDiv->GetPrimaryFrame(),
|
|
|
|
STYLES_DISABLING_NATIVE_THEMING);
|
2013-02-16 09:57:21 -08:00
|
|
|
}
|
2013-12-02 15:57:50 -08:00
|
|
|
|
2013-12-02 20:49:03 -08:00
|
|
|
Element*
|
|
|
|
nsRangeFrame::GetPseudoElement(nsCSSPseudoElements::Type aType)
|
2013-12-02 15:57:50 -08:00
|
|
|
{
|
|
|
|
if (aType == nsCSSPseudoElements::ePseudo_mozRangeTrack) {
|
|
|
|
return mTrackDiv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aType == nsCSSPseudoElements::ePseudo_mozRangeThumb) {
|
|
|
|
return mThumbDiv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aType == nsCSSPseudoElements::ePseudo_mozRangeProgress) {
|
|
|
|
return mProgressDiv;
|
|
|
|
}
|
|
|
|
|
2013-12-02 20:49:03 -08:00
|
|
|
return nsContainerFrame::GetPseudoElement(aType);
|
2013-12-02 15:57:50 -08:00
|
|
|
}
|
2014-02-18 15:35:07 -08:00
|
|
|
|
|
|
|
nsStyleContext*
|
|
|
|
nsRangeFrame::GetAdditionalStyleContext(int32_t aIndex) const
|
|
|
|
{
|
|
|
|
// We only implement this so that SetAdditionalStyleContext will be
|
|
|
|
// called if style changes that would change the -moz-focus-outer
|
|
|
|
// pseudo-element have occurred.
|
|
|
|
return aIndex == 0 ? mOuterFocusStyle : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRangeFrame::SetAdditionalStyleContext(int32_t aIndex,
|
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aIndex == 0,
|
|
|
|
"GetAdditionalStyleContext is handling other indexes?");
|
|
|
|
|
|
|
|
// The -moz-focus-outer pseudo-element's style has changed.
|
|
|
|
mOuterFocusStyle = aStyleContext;
|
|
|
|
}
|