зеркало из https://github.com/mozilla/gecko-dev.git
Bug 838256, part 1 - Initial work on the layout pieces for <input type=range>. DONTBUILD separately from jwatt's changeset (the next one) to finish this work. r=dholbert for the combined diff.
This commit is contained in:
Родитель
648e17e8b6
Коммит
54936aa0ff
|
@ -1488,6 +1488,69 @@ nsHTMLInputElement::SetValueAsNumber(double aValueAsNumber)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
double
|
||||
nsHTMLInputElement::GetPositionAsPercent()
|
||||
{
|
||||
// Should only be used for <input type='range'> for the moment.
|
||||
MOZ_ASSERT(mType == NS_FORM_INPUT_RANGE);
|
||||
|
||||
double minimum = GetMinimum();
|
||||
if (MOZ_DOUBLE_IS_NaN(minimum)) {
|
||||
return MOZ_DOUBLE_NaN();
|
||||
}
|
||||
|
||||
double maximum = GetMaximum();
|
||||
if (MOZ_DOUBLE_IS_NaN(maximum)) {
|
||||
return MOZ_DOUBLE_NaN();
|
||||
}
|
||||
|
||||
double value = GetValueAsDouble();
|
||||
if (MOZ_DOUBLE_IS_NaN(value)) {
|
||||
return MOZ_DOUBLE_NaN();
|
||||
}
|
||||
|
||||
return (value - minimum) / (maximum - minimum);
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLInputElement::SetPositionAsPercent(double position)
|
||||
{
|
||||
// TODO: datalist support
|
||||
|
||||
double minimum = GetMinimum();
|
||||
if (MOZ_DOUBLE_IS_NaN(minimum)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double maximum = GetMaximum();
|
||||
if (MOZ_DOUBLE_IS_NaN(maximum)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double currentValue = GetValueAsDouble();
|
||||
if (MOZ_DOUBLE_IS_NaN(currentValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double val = (maximum - minimum)*position + minimum;
|
||||
if (DoesStepApply()) {
|
||||
double increment = GetStep();
|
||||
val = minimum + NSToIntRound(val / float(increment)) * increment;
|
||||
}
|
||||
|
||||
// get the new position and make sure it is in bounds
|
||||
if (val < minimum || maximum < minimum)
|
||||
val = minimum;
|
||||
else if (val > maximum)
|
||||
val = maximum;
|
||||
|
||||
if (val == currentValue)
|
||||
return;
|
||||
|
||||
SetValue(val);
|
||||
FireChangeEventIfNeeded();
|
||||
}
|
||||
|
||||
double
|
||||
nsHTMLInputElement::GetMinimum() const
|
||||
{
|
||||
|
|
|
@ -283,6 +283,38 @@ public:
|
|||
*/
|
||||
void FireChangeEventIfNeeded();
|
||||
|
||||
/**
|
||||
* Returns the input's "minimum" (as defined by the HTML5 spec) as a double.
|
||||
* Note this takes account of any default minimum that the type may have.
|
||||
* Returns NaN if the min attribute isn't a valid floating point number and
|
||||
* the input's type does not have a default minimum.
|
||||
*
|
||||
* NOTE: Only call this if you know DoesMinMaxApply() returns true.
|
||||
*/
|
||||
double GetMinimum() const;
|
||||
|
||||
/**
|
||||
* Returns the input's "maximum" (as defined by the HTML5 spec) as a double.
|
||||
* Note this takes account of any default maximum that the type may have.
|
||||
* Returns NaN if the max attribute isn't a valid floating point number and
|
||||
* the input's type does not have a default maximum.
|
||||
*
|
||||
* NOTE:Only call this if you know DoesMinMaxApply() returns true.
|
||||
*/
|
||||
double GetMaximum() const;
|
||||
|
||||
/**
|
||||
* Returns the input element's value as a double-precision float.
|
||||
* Returns NaN if the current element's value is not a floating point number.
|
||||
*
|
||||
* @return the input element's value as a double-precision float.
|
||||
*/
|
||||
double GetValueAsDouble() const;
|
||||
|
||||
double GetPositionAsPercent();
|
||||
|
||||
void SetPositionAsPercent(double position);
|
||||
|
||||
protected:
|
||||
// Pull IsSingleLineTextControl into our scope, otherwise it'd be hidden
|
||||
// by the nsITextControlElement version.
|
||||
|
@ -569,14 +601,6 @@ protected:
|
|||
*/
|
||||
nsIRadioGroupContainer* GetRadioGroupContainer() const;
|
||||
|
||||
/**
|
||||
* Returns the input element's value as a double-precision float.
|
||||
* Returns NaN if the current element's value is not a floating point number.
|
||||
*
|
||||
* @return the input element's value as a double-precision float.
|
||||
*/
|
||||
double GetValueAsDouble() const;
|
||||
|
||||
/**
|
||||
* Convert a string to a number in a type specific way,
|
||||
* http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#concept-input-value-string-number
|
||||
|
@ -659,26 +683,6 @@ protected:
|
|||
*/
|
||||
void UpdateHasRange();
|
||||
|
||||
/**
|
||||
* Returns the input's "minimum" (as defined by the HTML5 spec) as a double.
|
||||
* Note this takes account of any default minimum that the type may have.
|
||||
* Returns NaN if the min attribute isn't a valid floating point number and
|
||||
* the input's type does not have a default minimum.
|
||||
*
|
||||
* NOTE: Only call this if you know DoesMinMaxApply() returns true.
|
||||
*/
|
||||
double GetMinimum() const;
|
||||
|
||||
/**
|
||||
* Returns the input's "maximum" (as defined by the HTML5 spec) as a double.
|
||||
* Note this takes account of any default maximum that the type may have.
|
||||
* Returns NaN if the max attribute isn't a valid floating point number and
|
||||
* the input's type does not have a default maximum.
|
||||
*
|
||||
* NOTE:Only call this if you know DoesMinMaxApply() returns true.
|
||||
*/
|
||||
double GetMaximum() const;
|
||||
|
||||
/**
|
||||
* Get the step scale value for the current type.
|
||||
* See:
|
||||
|
|
|
@ -275,6 +275,9 @@ NS_NewStackFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|||
nsIFrame*
|
||||
NS_NewProgressMeterFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
|
||||
|
||||
nsIFrame*
|
||||
NS_NewRangeFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
|
||||
|
||||
nsIFrame*
|
||||
NS_NewImageBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext);
|
||||
|
||||
|
@ -3475,6 +3478,7 @@ nsCSSFrameConstructor::FindInputData(Element* aElement,
|
|||
SIMPLE_INT_CREATE(NS_FORM_INPUT_TEXT, NS_NewTextControlFrame),
|
||||
SIMPLE_INT_CREATE(NS_FORM_INPUT_TEL, NS_NewTextControlFrame),
|
||||
SIMPLE_INT_CREATE(NS_FORM_INPUT_URL, NS_NewTextControlFrame),
|
||||
SIMPLE_INT_CREATE(NS_FORM_INPUT_RANGE, NS_NewRangeFrame),
|
||||
SIMPLE_INT_CREATE(NS_FORM_INPUT_PASSWORD, NS_NewTextControlFrame),
|
||||
// TODO: this is temporary until a frame is written: bug 635240.
|
||||
SIMPLE_INT_CREATE(NS_FORM_INPUT_NUMBER, NS_NewTextControlFrame),
|
||||
|
|
|
@ -42,6 +42,7 @@ CPPSRCS = \
|
|||
nsGfxCheckboxControlFrame.cpp \
|
||||
nsGfxRadioControlFrame.cpp \
|
||||
nsProgressFrame.cpp \
|
||||
nsRangeFrame.cpp \
|
||||
nsMeterFrame.cpp \
|
||||
nsTextControlFrame.cpp \
|
||||
nsHTMLButtonControlFrame.cpp \
|
||||
|
|
|
@ -0,0 +1,370 @@
|
|||
/* -*- 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"
|
||||
|
||||
#include "nsHTMLInputElement.h"
|
||||
#include "nsIDOMHTMLInputElement.h"
|
||||
#include "nsIContent.h"
|
||||
#include "prtypes.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsNodeInfoManager.h"
|
||||
#include "nsINodeInfo.h"
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsFormControlFrame.h"
|
||||
#include "nsContentList.h"
|
||||
#include "nsFontMetrics.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsContentList.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRangeFrame::SetInitialChildList(ChildListID aListID,
|
||||
nsFrameList& aChildList)
|
||||
{
|
||||
nsresult rv = nsContainerFrame::SetInitialChildList(aListID, aChildList);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIFrame*
|
||||
NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
||||
{
|
||||
return new (aPresShell) nsRangeFrame(aContext);
|
||||
}
|
||||
|
||||
NS_IMPL_FRAMEARENA_HELPERS(nsRangeFrame)
|
||||
|
||||
nsRangeFrame::nsRangeFrame(nsStyleContext* aContext)
|
||||
: nsContainerFrame(aContext)
|
||||
, mThumbDiv(nullptr)
|
||||
, mProgressDiv(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
nsRangeFrame::~nsRangeFrame()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
nsRangeFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
||||
{
|
||||
NS_ASSERTION(!GetPrevContinuation(),
|
||||
"nsRangeFrame should not have continuations; if it does we "
|
||||
"need to call RegUnregAccessKey only for the first.");
|
||||
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
||||
nsContentUtils::DestroyAnonymousContent(&mThumbDiv);
|
||||
nsContentUtils::DestroyAnonymousContent(&mProgressDiv);
|
||||
nsContainerFrame::DestroyFrom(aDestructRoot);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsRangeFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
||||
{
|
||||
// Get the NodeInfoManager and tag necessary to create the progress bar div.
|
||||
nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
|
||||
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo;
|
||||
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::div, nullptr,
|
||||
kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// Create the div.
|
||||
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::div, nullptr,
|
||||
kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
nsresult rv = NS_NewHTMLElement(getter_AddRefs(mThumbDiv), nodeInfo.forget(),
|
||||
mozilla::dom::NOT_FROM_PARSER);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCSSPseudoElements::Type pseudoType = nsCSSPseudoElements::ePseudo_mozRangeThumb;
|
||||
nsRefPtr<nsStyleContext> newStyleContext = PresContext()->StyleSet()->
|
||||
ResolvePseudoElementStyle(mContent->AsElement(), pseudoType, GetStyleContext());
|
||||
|
||||
if (!aElements.AppendElement(ContentInfo(mThumbDiv, newStyleContext))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Progress div
|
||||
rv = NS_NewHTMLElement(getter_AddRefs(mProgressDiv), nodeInfo.forget(),
|
||||
mozilla::dom::NOT_FROM_PARSER);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
pseudoType = nsCSSPseudoElements::ePseudo_mozRangeActive;
|
||||
newStyleContext = PresContext()->StyleSet()->
|
||||
ResolvePseudoElementStyle(mContent->AsElement(), pseudoType, GetStyleContext());
|
||||
|
||||
if (!aElements.AppendElement(ContentInfo(mProgressDiv, newStyleContext))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsRangeFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
|
||||
uint32_t aFilter)
|
||||
{
|
||||
aElements.MaybeAppendElement(mThumbDiv);
|
||||
aElements.MaybeAppendElement(mProgressDiv);
|
||||
}
|
||||
|
||||
NS_QUERYFRAME_HEAD(nsRangeFrame)
|
||||
NS_QUERYFRAME_ENTRY(nsRangeFrame)
|
||||
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
||||
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRangeFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
||||
const nsRect& aDirtyRect,
|
||||
const nsDisplayListSet& aLists)
|
||||
{
|
||||
return BuildDisplayListForInline(aBuilder, aDirtyRect, aLists);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRangeFrame::Reflow(nsPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
DO_GLOBAL_REFLOW_COUNT("nsRangeFrame");
|
||||
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
||||
|
||||
NS_ASSERTION(mThumbDiv, "Thumb div must exist!");
|
||||
NS_ASSERTION(!GetPrevContinuation(),
|
||||
"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);
|
||||
}
|
||||
|
||||
aDesiredSize.width = aReflowState.ComputedWidth() +
|
||||
aReflowState.mComputedBorderPadding.LeftRight();
|
||||
aDesiredSize.height = aReflowState.ComputedHeight() +
|
||||
aReflowState.mComputedBorderPadding.TopBottom();
|
||||
|
||||
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
||||
nsIFrame* barFrame = mThumbDiv->GetPrimaryFrame();
|
||||
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, barFrame);
|
||||
|
||||
nsIFrame* progressFrame = mProgressDiv->GetPrimaryFrame();
|
||||
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, progressFrame);
|
||||
|
||||
FinishAndStoreOverflow(&aDesiredSize);
|
||||
|
||||
ReflowBarFrame(aPresContext, aReflowState, aStatus);
|
||||
|
||||
aStatus = NS_FRAME_COMPLETE;
|
||||
|
||||
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsRangeFrame::ReflowBarFrame(nsPresContext* aPresContext,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus)
|
||||
{
|
||||
nsIFrame* barFrame = mThumbDiv->GetPrimaryFrame();
|
||||
NS_ASSERTION(barFrame, "The range frame should have a child with a frame!");
|
||||
|
||||
nsIFrame* progressFrame = mProgressDiv->GetPrimaryFrame();
|
||||
NS_ASSERTION(progressFrame, "The range frame should have a child with a frame!");
|
||||
|
||||
bool vertical = !IsHorizontal(aReflowState.ComputedWidth(), aReflowState.ComputedHeight());
|
||||
nsHTMLReflowState barReflowState(aPresContext, aReflowState, barFrame,
|
||||
nsSize(aReflowState.ComputedWidth(),
|
||||
NS_UNCONSTRAINEDSIZE));
|
||||
nsHTMLReflowState progressReflowState(aPresContext, aReflowState, progressFrame,
|
||||
nsSize(aReflowState.ComputedWidth(),
|
||||
NS_UNCONSTRAINEDSIZE));
|
||||
|
||||
nscoord parentHeight = aReflowState.ComputedHeight() + aReflowState.mComputedBorderPadding.TopBottom();
|
||||
nscoord parentWidth = aReflowState.ComputedWidth() + aReflowState.mComputedBorderPadding.LeftRight();
|
||||
|
||||
nscoord size = vertical ? aReflowState.ComputedHeight() : aReflowState.ComputedWidth();
|
||||
nscoord progressSize = size;
|
||||
|
||||
nsSize thumbSize = barFrame->GetSize();
|
||||
size -= vertical ? thumbSize.height : thumbSize.width;
|
||||
|
||||
nscoord xoffset = vertical ? 0 : aReflowState.mComputedBorderPadding.left;
|
||||
nscoord yoffset = vertical ? aReflowState.mComputedBorderPadding.top : 0;
|
||||
nscoord xProgressOffset = 0;
|
||||
nscoord yProgressOffset = 0;
|
||||
|
||||
// center the thumb in the box
|
||||
xoffset += vertical ? (parentWidth - barReflowState.ComputedWidth()) / 2 : 0;
|
||||
yoffset += vertical ? 0 : (parentHeight - barReflowState.ComputedHeight()) / 2;
|
||||
|
||||
nsHTMLInputElement* element = static_cast<nsHTMLInputElement*>(mContent);
|
||||
double position = element->GetPositionAsPercent();
|
||||
|
||||
if (position >= 0.0) {
|
||||
size *= vertical ? (1 - position) : position;
|
||||
progressSize *= vertical ? (1 - position) : position;
|
||||
}
|
||||
|
||||
if (!vertical && GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
||||
xoffset += parentWidth - size;
|
||||
xProgressOffset += parentWidth - progressSize;
|
||||
}
|
||||
|
||||
if (position != -1 || ShouldUseNativeStyle()) {
|
||||
if (vertical) {
|
||||
size -= barReflowState.mComputedMargin.TopBottom() +
|
||||
barReflowState.mComputedBorderPadding.TopBottom();
|
||||
size = std::max(size, 0);
|
||||
yoffset += size;
|
||||
yProgressOffset = yoffset;
|
||||
|
||||
progressSize = parentHeight - yoffset;
|
||||
progressSize = std::max(progressSize, 0);
|
||||
progressReflowState.SetComputedHeight(progressSize);
|
||||
progressReflowState.SetComputedWidth(parentWidth);
|
||||
} else {
|
||||
size -= barReflowState.mComputedMargin.LeftRight() +
|
||||
barReflowState.mComputedBorderPadding.LeftRight();
|
||||
size = std::max(size, 0);
|
||||
xoffset += size;
|
||||
|
||||
progressReflowState.SetComputedWidth(xoffset + thumbSize.width);
|
||||
progressReflowState.SetComputedHeight(parentHeight);
|
||||
}
|
||||
} else if (vertical) {
|
||||
yoffset += parentHeight - barReflowState.ComputedHeight();
|
||||
yProgressOffset += parentHeight - progressReflowState.ComputedHeight();
|
||||
}
|
||||
|
||||
nsHTMLReflowMetrics barDesiredSize;
|
||||
ReflowChild(barFrame, aPresContext, barDesiredSize, barReflowState, xoffset, yoffset, 0, aStatus);
|
||||
FinishReflowChild(barFrame, aPresContext, &barReflowState, barDesiredSize, xoffset, yoffset, 0);
|
||||
|
||||
nsHTMLReflowMetrics progressDesiredSize;
|
||||
ReflowChild(progressFrame, aPresContext, progressDesiredSize, progressReflowState, 0,
|
||||
xProgressOffset, yProgressOffset, aStatus);
|
||||
FinishReflowChild(progressFrame, aPresContext, &progressReflowState, progressDesiredSize,
|
||||
xProgressOffset, yProgressOffset, 0);}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRangeFrame::AttributeChanged(int32_t aNameSpaceID,
|
||||
nsIAtom* aAttribute,
|
||||
int32_t aModType)
|
||||
{
|
||||
NS_ASSERTION(mThumbDiv, "Thumb div must exist!");
|
||||
NS_ASSERTION(mProgressDiv, "Progress div must exist!");
|
||||
|
||||
if (aNameSpaceID == kNameSpaceID_None &&
|
||||
(aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max)) {
|
||||
nsIFrame* barFrame = mThumbDiv->GetPrimaryFrame();
|
||||
NS_ASSERTION(barFrame, "The range frame should have a child with a frame!");
|
||||
PresContext()->PresShell()->FrameNeedsReflow(barFrame, nsIPresShell::eResize,
|
||||
NS_FRAME_IS_DIRTY);
|
||||
|
||||
nsIFrame* progressFrame = mProgressDiv->GetPrimaryFrame();
|
||||
NS_ASSERTION(progressFrame, "The range frame should have a child with a frame!");
|
||||
PresContext()->PresShell()->FrameNeedsReflow(progressFrame, nsIPresShell::eResize,
|
||||
NS_FRAME_IS_DIRTY);
|
||||
|
||||
InvalidateFrame();
|
||||
}
|
||||
|
||||
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
||||
}
|
||||
|
||||
nsSize
|
||||
nsRangeFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
|
||||
nsSize aCBSize, nscoord aAvailableWidth,
|
||||
nsSize aMargin, nsSize aBorder,
|
||||
nsSize aPadding, bool aShrinkWrap)
|
||||
{
|
||||
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
||||
nsRefPtr<nsFontMetrics> fontMet;
|
||||
NS_ENSURE_SUCCESS(nsLayoutUtils::GetFontMetricsForFrame(this,
|
||||
getter_AddRefs(fontMet),
|
||||
inflation),
|
||||
nsSize(0, 0));
|
||||
|
||||
nsSize autoSize;
|
||||
autoSize.height = autoSize.width = fontMet->Font().size; // 1em
|
||||
|
||||
if (IsHorizontal(autoSize.width, autoSize.height)) {
|
||||
autoSize.width *= 10; // 10em
|
||||
} else {
|
||||
autoSize.height *= 10; // 10em
|
||||
}
|
||||
|
||||
return autoSize;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsRangeFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
||||
{
|
||||
nsRefPtr<nsFontMetrics> fontMet;
|
||||
NS_ENSURE_SUCCESS(
|
||||
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet)), 0);
|
||||
|
||||
nscoord minWidth = fontMet->Font().size; // 1em
|
||||
|
||||
nsSize size = GetSize();
|
||||
if (IsHorizontal(size.width, size.height)) {
|
||||
minWidth *= 10; // 10em
|
||||
}
|
||||
|
||||
return minWidth;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsRangeFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
||||
{
|
||||
return GetMinWidth(aRenderingContext);
|
||||
}
|
||||
|
||||
double
|
||||
nsRangeFrame::GetMin() const
|
||||
{
|
||||
return static_cast<nsHTMLInputElement*>(mContent)->GetMinimum();
|
||||
}
|
||||
|
||||
double
|
||||
nsRangeFrame::GetMax() const
|
||||
{
|
||||
return static_cast<nsHTMLInputElement*>(mContent)->GetMaximum();
|
||||
}
|
||||
|
||||
double
|
||||
nsRangeFrame::GetValue() const
|
||||
{
|
||||
return static_cast<nsHTMLInputElement*>(mContent)->GetValueAsDouble();
|
||||
}
|
||||
|
||||
bool
|
||||
nsRangeFrame::ShouldUseNativeStyle() const
|
||||
{
|
||||
// Use the native style if these conditions are satisfied:
|
||||
// - both frames use the native appearance;
|
||||
// - neither frame has author specified rules setting the border or the
|
||||
// background.
|
||||
return (GetStyleDisplay()->mAppearance == NS_THEME_SCALE_HORIZONTAL) &&
|
||||
(mThumbDiv->GetPrimaryFrame()->GetStyleDisplay()->mAppearance == NS_THEME_SCALE_THUMB_HORIZONTAL) &&
|
||||
!PresContext()->HasAuthorSpecifiedRules(const_cast<nsRangeFrame*>(this),
|
||||
NS_AUTHOR_SPECIFIED_BORDER | NS_AUTHOR_SPECIFIED_BACKGROUND) &&
|
||||
!PresContext()->HasAuthorSpecifiedRules(mThumbDiv->GetPrimaryFrame(),
|
||||
NS_AUTHOR_SPECIFIED_BORDER | NS_AUTHOR_SPECIFIED_BACKGROUND);
|
||||
}
|
||||
|
||||
bool nsRangeFrame::IsHorizontal(nscoord width, nscoord height) {
|
||||
if (GetStyleDisplay()->mOrient == NS_STYLE_ORIENT_VERTICAL)
|
||||
return false;
|
||||
|
||||
return width >= height;
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsRangeFrame_h___
|
||||
#define nsRangeFrame_h___
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsContainerFrame.h"
|
||||
#include "nsIAnonymousContentCreator.h"
|
||||
#include "nsRepeatService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsDOMTouchEvent.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
|
||||
class nsBaseContentList;
|
||||
class nsRangeFrame;
|
||||
|
||||
class nsRangeMediator : public nsIDOMEventListener
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsRangeFrame* mRange;
|
||||
|
||||
nsRangeMediator(nsRangeFrame* aRange) { mRange = aRange; }
|
||||
virtual ~nsRangeMediator() {}
|
||||
|
||||
virtual void SetRange(nsRangeFrame* aRange) { mRange = aRange; }
|
||||
};
|
||||
|
||||
class nsRangeFrame : public nsContainerFrame,
|
||||
public nsIAnonymousContentCreator
|
||||
{
|
||||
public:
|
||||
NS_DECL_QUERYFRAME_TARGET(nsRangeFrame)
|
||||
NS_DECL_QUERYFRAME
|
||||
NS_DECL_FRAMEARENA_HELPERS
|
||||
|
||||
// nsIFrame overrides
|
||||
NS_IMETHODIMP SetInitialChildList(ChildListID aListID,
|
||||
nsFrameList& aChildList) MOZ_OVERRIDE;
|
||||
|
||||
nsRangeFrame(nsStyleContext* aContext);
|
||||
virtual ~nsRangeFrame();
|
||||
|
||||
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
|
||||
|
||||
NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
||||
const nsRect& aDirtyRect,
|
||||
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
||||
|
||||
NS_IMETHOD Reflow(nsPresContext* aCX,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
|
||||
#ifdef DEBUG
|
||||
NS_IMETHOD GetFrameName(nsAString& aResult) const {
|
||||
return MakeFrameName(NS_LITERAL_STRING("Range"), aResult);
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual bool IsLeaf() const MOZ_OVERRIDE { return true; }
|
||||
|
||||
// nsIAnonymousContentCreator
|
||||
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
|
||||
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
|
||||
uint32_t aFilter) MOZ_OVERRIDE;
|
||||
|
||||
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
|
||||
nsIAtom* aAttribute,
|
||||
int32_t aModType);
|
||||
|
||||
virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext,
|
||||
nsSize aCBSize, nscoord aAvailableWidth,
|
||||
nsSize aMargin, nsSize aBorder,
|
||||
nsSize aPadding, bool aShrinkWrap) MOZ_OVERRIDE;
|
||||
|
||||
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext);
|
||||
virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext);
|
||||
|
||||
virtual bool IsFrameOfType(uint32_t aFlags) const
|
||||
{
|
||||
return nsContainerFrame::IsFrameOfType(aFlags &
|
||||
~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
|
||||
}
|
||||
|
||||
double GetMin() const;
|
||||
double GetMax() const;
|
||||
double GetValue() const;
|
||||
|
||||
/**
|
||||
* Returns whether the frame and its child should use the native style.
|
||||
*/
|
||||
bool ShouldUseNativeStyle() const;
|
||||
|
||||
private:
|
||||
bool IsHorizontal(nscoord width, nscoord height);
|
||||
void SetCurrentThumbPosition(double position);
|
||||
void AddListener();
|
||||
void RemoveListener();
|
||||
|
||||
nscoord mChange;
|
||||
|
||||
protected:
|
||||
// Helper function which reflow the anonymous div frame.
|
||||
void ReflowBarFrame(nsPresContext* aPresContext,
|
||||
const nsHTMLReflowState& aReflowState,
|
||||
nsReflowStatus& aStatus);
|
||||
|
||||
/**
|
||||
* The div used to show the thumb.
|
||||
* @see nsRangeFrame::CreateAnonymousContent
|
||||
*/
|
||||
nsCOMPtr<nsIContent> mThumbDiv;
|
||||
|
||||
/**
|
||||
* The div used to show the active progress.
|
||||
* @see nsRangeFrame::CreateAnonymousContent
|
||||
*/
|
||||
nsCOMPtr<nsIContent> mProgressDiv;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -113,6 +113,7 @@ FRAME_ID(nsPlaceholderFrame)
|
|||
FRAME_ID(nsPopupSetFrame)
|
||||
FRAME_ID(nsProgressFrame)
|
||||
FRAME_ID(nsProgressMeterFrame)
|
||||
FRAME_ID(nsRangeFrame)
|
||||
FRAME_ID(nsResizerFrame)
|
||||
FRAME_ID(nsRootBoxFrame)
|
||||
FRAME_ID(nsScrollbarButtonFrame)
|
||||
|
|
|
@ -189,6 +189,8 @@ nsIFrame*
|
|||
NS_NewProgressFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
||||
nsIFrame*
|
||||
NS_NewMeterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
||||
nsIFrame*
|
||||
NS_NewRangeFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
||||
|
||||
// Table frame factories
|
||||
nsIFrame*
|
||||
|
|
|
@ -717,6 +717,37 @@ meter {
|
|||
background: -moz-linear-gradient(top, #f77, #f77, #fcc 20%, #d44 45%, #d44 55%);
|
||||
}
|
||||
|
||||
input[type="range"] {
|
||||
cursor: move;
|
||||
-moz-appearance: scale-horizontal;
|
||||
display: inline-block;
|
||||
|
||||
/* Default style in case of there is -moz-appearance: none; */
|
||||
border: 2px solid;
|
||||
/* #e6e6e6 is a light gray. */
|
||||
-moz-border-top-colors: ThreeDShadow #e6e6e6;
|
||||
-moz-border-right-colors: ThreeDHighlight #e6e6e6;
|
||||
-moz-border-bottom-colors: ThreeDHighlight #e6e6e6;
|
||||
-moz-border-left-colors: ThreeDShadow #e6e6e6;
|
||||
background-color: #e6e6e6;
|
||||
}
|
||||
|
||||
::-moz-range-thumb {
|
||||
/* Block styles that would change the type of frame we construct. */
|
||||
display: inline-block ! important;
|
||||
float: none ! important;
|
||||
position: static ! important;
|
||||
overflow: visible ! important;
|
||||
-moz-box-sizing: border-box ! important;
|
||||
|
||||
-moz-appearance: scale-thumb-horizontal;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
/* Default style in case of there is -moz-appearance: none; */
|
||||
background-color: #0064b4; /* blue */
|
||||
}
|
||||
|
||||
%ifdef XP_OS2
|
||||
input {
|
||||
font: medium serif; font-family: inherit
|
||||
|
|
|
@ -561,6 +561,8 @@ CSS_KEY(menulist-text, menulist_text)
|
|||
CSS_KEY(menulist-textfield, menulist_textfield)
|
||||
CSS_KEY(meterbar, meterbar)
|
||||
CSS_KEY(meterchunk, meterchunk)
|
||||
CSS_KEY(range-thumb, range_thumb)
|
||||
CSS_KEY(range-active, range_active)
|
||||
CSS_KEY(scale-horizontal, scale_horizontal)
|
||||
CSS_KEY(scale-vertical, scale_vertical)
|
||||
CSS_KEY(scalethumb-horizontal, scalethumb_horizontal)
|
||||
|
|
|
@ -53,5 +53,7 @@ CSS_PSEUDO_ELEMENT(mozMathAnonymous, ":-moz-math-anonymous", 0)
|
|||
|
||||
// HTML5 Forms pseudo elements
|
||||
CSS_PSEUDO_ELEMENT(mozProgressBar, ":-moz-progress-bar", 0)
|
||||
CSS_PSEUDO_ELEMENT(mozRangeThumb, ":-moz-range-thumb", 0)
|
||||
CSS_PSEUDO_ELEMENT(mozRangeActive, ":-moz-range-active", 0)
|
||||
CSS_PSEUDO_ELEMENT(mozMeterBar, ":-moz-meter-bar", 0)
|
||||
CSS_PSEUDO_ELEMENT(mozPlaceholder, ":-moz-placeholder", 0)
|
||||
|
|
Загрузка…
Ссылка в новой задаче