Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
2010-03-19 Joseph Pecoraro <joepeck@webkit.org>
Reviewed by David Kilzer. <input type=range> does not validate correctly without a renderer and the tests are incorrect https://bugs.webkit.org/show_bug.cgi?id=36259 Part 1 of 2: Refactoring the SliderRange struct out of RenderSlider into a more appropriate place. Changed the named to StepRange. Changed from a struct to a class. Added new files to the build. * GNUmakefile.am: * WebCore.gypi: * WebCore.pro: * WebCore.vcproj/WebCore.vcproj: * WebCore.xcodeproj/project.pbxproj: Renamed and moved class SliderRange to StepRange. * html/StepRange.cpp: Added. (WebCore::StepRange::StepRange): (WebCore::StepRange::clampValue): (WebCore::StepRange::valueFromElement): (WebCore::sliderPosition): * html/StepRange.h: Added. (WebCore::StepRange::proportionFromValue): (WebCore::StepRange::valueFromProportion): * rendering/RenderSlider.cpp: (WebCore::RenderSlider::updateFromElement): updated to use StepRange (WebCore::RenderSlider::setValueForPosition): updated to use StepRange Canonical link: https://commits.webkit.org/47535@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@56241 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
194 additions
and 74 deletions.
- +33 −0 WebCore/ChangeLog
- +2 −0 WebCore/GNUmakefile.am
- +2 −0 WebCore/WebCore.gypi
- +2 −0 WebCore/WebCore.pro
- +8 −0 WebCore/WebCore.vcproj/WebCore.vcproj
- +8 −0 WebCore/WebCore.xcodeproj/project.pbxproj
- +74 −0 WebCore/html/StepRange.cpp
- +60 −0 WebCore/html/StepRange.h
- +5 −74 WebCore/rendering/RenderSlider.cpp
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public License | ||
* along with this library; see the file COPYING.LIB. If not, write to | ||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
#include "config.h" | ||
#include "StepRange.h" | ||
|
||
#include "HTMLInputElement.h" | ||
#include "HTMLNames.h" | ||
#include <wtf/MathExtras.h> | ||
|
||
using namespace std; | ||
|
||
namespace WebCore { | ||
|
||
using namespace HTMLNames; | ||
|
||
StepRange::StepRange(HTMLInputElement* element) | ||
{ | ||
if (element->hasAttribute(precisionAttr)) { | ||
step = 1.0; | ||
hasStep = !equalIgnoringCase(element->getAttribute(precisionAttr), "float"); | ||
} else | ||
hasStep = element->getAllowedValueStep(&step); | ||
|
||
maximum = element->maximum(); | ||
minimum = element->minimum(); | ||
} | ||
|
||
double StepRange::clampValue(double value) | ||
{ | ||
double clampedValue = max(minimum, min(value, maximum)); | ||
if (!hasStep) | ||
return clampedValue; | ||
// Rounds clampedValue to minimum + N * step. | ||
clampedValue = minimum + round((clampedValue - minimum) / step) * step; | ||
if (clampedValue > maximum) | ||
clampedValue -= step; | ||
ASSERT(clampedValue >= minimum); | ||
ASSERT(clampedValue <= maximum); | ||
return clampedValue; | ||
} | ||
|
||
double StepRange::valueFromElement(HTMLInputElement* element, bool* wasClamped) | ||
{ | ||
double oldValue; | ||
bool parseSuccess = HTMLInputElement::parseToDoubleForNumberType(element->value(), &oldValue); | ||
if (!parseSuccess) | ||
oldValue = (minimum + maximum) / 2; | ||
double newValue = clampValue(oldValue); | ||
|
||
if (wasClamped) | ||
*wasClamped = !parseSuccess || newValue != oldValue; | ||
|
||
return newValue; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Library General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public License | ||
* along with this library; see the file COPYING.LIB. If not, write to | ||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
* | ||
*/ | ||
|
||
#ifndef StepRange_h | ||
#define StepRange_h | ||
|
||
#include <wtf/Noncopyable.h> | ||
|
||
namespace WebCore { | ||
|
||
class HTMLInputElement; | ||
|
||
class StepRange : public Noncopyable { | ||
public: | ||
bool hasStep; | ||
double step; | ||
double minimum; | ||
double maximum; // maximum must be >= minimum. | ||
|
||
explicit StepRange(HTMLInputElement*); | ||
double clampValue(double value); | ||
|
||
// Map value into 0-1 range | ||
double proportionFromValue(double value) | ||
{ | ||
if (minimum == maximum) | ||
return 0; | ||
|
||
return (value - minimum) / (maximum - minimum); | ||
} | ||
|
||
// Map from 0-1 range to value | ||
double valueFromProportion(double proportion) | ||
{ | ||
return minimum + proportion * (maximum - minimum); | ||
} | ||
|
||
double valueFromElement(HTMLInputElement*, bool* wasClamped = 0); | ||
}; | ||
|
||
} | ||
|
||
#endif // StepRange_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters