<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[194796] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/194796">194796</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2016-01-08 15:19:50 -0800 (Fri, 08 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>InputType::findClosestTickMarkValue should return an Optional&lt;Decimal&gt;
https://bugs.webkit.org/show_bug.cgi?id=152931

Reviewed by Andreas Kling.

This will make it possible to get rid of the notion of infinity from Decimal, allowing for more code simplification.

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::findClosestTickMarkValue):
* html/HTMLInputElement.h:
* html/InputType.cpp:
(WebCore::InputType::findClosestTickMarkValue):
* html/InputType.h:
* html/RangeInputType.cpp:
(WebCore::RangeInputType::findClosestTickMarkValue):
* html/RangeInputType.h:
* html/shadow/SliderThumbElement.cpp:
(WebCore::SliderThumbElement::setPositionFromPoint):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLInputElementcpp">trunk/Source/WebCore/html/HTMLInputElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLInputElementh">trunk/Source/WebCore/html/HTMLInputElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmlInputTypecpp">trunk/Source/WebCore/html/InputType.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlInputTypeh">trunk/Source/WebCore/html/InputType.h</a></li>
<li><a href="#trunkSourceWebCorehtmlRangeInputTypecpp">trunk/Source/WebCore/html/RangeInputType.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlRangeInputTypeh">trunk/Source/WebCore/html/RangeInputType.h</a></li>
<li><a href="#trunkSourceWebCorehtmlshadowSliderThumbElementcpp">trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (194795 => 194796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-01-08 23:19:19 UTC (rev 194795)
+++ trunk/Source/WebCore/ChangeLog        2016-01-08 23:19:50 UTC (rev 194796)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2016-01-08  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        InputType::findClosestTickMarkValue should return an Optional&lt;Decimal&gt;
+        https://bugs.webkit.org/show_bug.cgi?id=152931
+
+        Reviewed by Andreas Kling.
+
+        This will make it possible to get rid of the notion of infinity from Decimal, allowing for more code simplification.
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::findClosestTickMarkValue):
+        * html/HTMLInputElement.h:
+        * html/InputType.cpp:
+        (WebCore::InputType::findClosestTickMarkValue):
+        * html/InputType.h:
+        * html/RangeInputType.cpp:
+        (WebCore::RangeInputType::findClosestTickMarkValue):
+        * html/RangeInputType.h:
+        * html/shadow/SliderThumbElement.cpp:
+        (WebCore::SliderThumbElement::setPositionFromPoint):
+
</ins><span class="cx"> 2016-01-08  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Modern IDB: IDBBindingUtilities chokes on unicode strings for get/set.
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLInputElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (194795 => 194796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLInputElement.cpp        2016-01-08 23:19:19 UTC (rev 194795)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp        2016-01-08 23:19:50 UTC (rev 194796)
</span><span class="lines">@@ -342,7 +342,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATALIST_ELEMENT)
</span><del>-Decimal HTMLInputElement::findClosestTickMarkValue(const Decimal&amp; value)
</del><ins>+Optional&lt;Decimal&gt; HTMLInputElement::findClosestTickMarkValue(const Decimal&amp; value)
</ins><span class="cx"> {
</span><span class="cx">     return m_inputType-&gt;findClosestTickMarkValue(value);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLInputElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLInputElement.h (194795 => 194796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLInputElement.h        2016-01-08 23:19:19 UTC (rev 194795)
+++ trunk/Source/WebCore/html/HTMLInputElement.h        2016-01-08 23:19:50 UTC (rev 194796)
</span><span class="lines">@@ -90,7 +90,7 @@
</span><span class="cx">     StepRange createStepRange(AnyStepHandling) const;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATALIST_ELEMENT)
</span><del>-    Decimal findClosestTickMarkValue(const Decimal&amp;);
</del><ins>+    Optional&lt;Decimal&gt; findClosestTickMarkValue(const Decimal&amp;);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // Implementations of HTMLInputElement::stepUp() and stepDown().
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlInputTypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/InputType.cpp (194795 => 194796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/InputType.cpp        2016-01-08 23:19:19 UTC (rev 194795)
+++ trunk/Source/WebCore/html/InputType.cpp        2016-01-08 23:19:50 UTC (rev 194796)
</span><span class="lines">@@ -952,10 +952,10 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Decimal InputType::findClosestTickMarkValue(const Decimal&amp;)
</del><ins>+Optional&lt;Decimal&gt; InputType::findClosestTickMarkValue(const Decimal&amp;)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><del>-    return Decimal::nan();
</del><ins>+    return Nullopt;
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlInputTypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/InputType.h (194795 => 194796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/InputType.h        2016-01-08 23:19:19 UTC (rev 194795)
+++ trunk/Source/WebCore/html/InputType.h        2016-01-08 23:19:50 UTC (rev 194796)
</span><span class="lines">@@ -298,7 +298,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATALIST_ELEMENT)
</span><span class="cx">     virtual void listAttributeTargetChanged();
</span><del>-    virtual Decimal findClosestTickMarkValue(const Decimal&amp;);
</del><ins>+    virtual Optional&lt;Decimal&gt; findClosestTickMarkValue(const Decimal&amp;);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlRangeInputTypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/RangeInputType.cpp (194795 => 194796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/RangeInputType.cpp        2016-01-08 23:19:19 UTC (rev 194795)
+++ trunk/Source/WebCore/html/RangeInputType.cpp        2016-01-08 23:19:50 UTC (rev 194796)
</span><span class="lines">@@ -382,11 +382,11 @@
</span><span class="cx">     std::sort(m_tickMarkValues.begin(), m_tickMarkValues.end());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Decimal RangeInputType::findClosestTickMarkValue(const Decimal&amp; value)
</del><ins>+Optional&lt;Decimal&gt; RangeInputType::findClosestTickMarkValue(const Decimal&amp; value)
</ins><span class="cx"> {
</span><span class="cx">     updateTickMarkValues();
</span><span class="cx">     if (!m_tickMarkValues.size())
</span><del>-        return Decimal::nan();
</del><ins>+        return Nullopt;
</ins><span class="cx"> 
</span><span class="cx">     size_t left = 0;
</span><span class="cx">     size_t right = m_tickMarkValues.size();
</span><span class="lines">@@ -408,10 +408,18 @@
</span><span class="cx">         else
</span><span class="cx">             right = middle;
</span><span class="cx">     }
</span><del>-    const Decimal closestLeft = middle ? m_tickMarkValues[middle - 1] : Decimal::infinity(Decimal::Negative);
-    const Decimal closestRight = middle != m_tickMarkValues.size() ? m_tickMarkValues[middle] : Decimal::infinity(Decimal::Positive);
-    if (closestRight - value &lt; value - closestLeft)
</del><ins>+
+    Optional&lt;Decimal&gt; closestLeft = middle ? makeOptional(m_tickMarkValues[middle - 1]) : Nullopt;
+    Optional&lt;Decimal&gt; closestRight = middle != m_tickMarkValues.size() ? makeOptional(m_tickMarkValues[middle]) : Nullopt;
+
+    if (!closestLeft)
</ins><span class="cx">         return closestRight;
</span><ins>+    if (!closestRight)
+        return closestLeft;
+
+    if (*closestRight - value &lt; value - *closestLeft)
+        return closestRight;
+
</ins><span class="cx">     return closestLeft;
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlRangeInputTypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/RangeInputType.h (194795 => 194796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/RangeInputType.h        2016-01-08 23:19:19 UTC (rev 194795)
+++ trunk/Source/WebCore/html/RangeInputType.h        2016-01-08 23:19:50 UTC (rev 194796)
</span><span class="lines">@@ -72,7 +72,7 @@
</span><span class="cx"> #if ENABLE(DATALIST_ELEMENT)
</span><span class="cx">     virtual void listAttributeTargetChanged() override;
</span><span class="cx">     void updateTickMarkValues();
</span><del>-    virtual Decimal findClosestTickMarkValue(const Decimal&amp;) override;
</del><ins>+    virtual Optional&lt;Decimal&gt; findClosestTickMarkValue(const Decimal&amp;) override;
</ins><span class="cx"> 
</span><span class="cx">     bool m_tickMarkValuesDirty;
</span><span class="cx">     Vector&lt;Decimal&gt; m_tickMarkValues;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlshadowSliderThumbElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp (194795 => 194796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp        2016-01-08 23:19:19 UTC (rev 194795)
+++ trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp        2016-01-08 23:19:50 UTC (rev 194796)
</span><span class="lines">@@ -289,13 +289,12 @@
</span><span class="cx"> #if ENABLE(DATALIST_ELEMENT)
</span><span class="cx">     const LayoutUnit snappingThreshold = renderer()-&gt;theme().sliderTickSnappingThreshold();
</span><span class="cx">     if (snappingThreshold &gt; 0) {
</span><del>-        Decimal closest = input-&gt;findClosestTickMarkValue(value);
-        if (closest.isFinite()) {
-            double closestFraction = stepRange.proportionFromValue(closest).toDouble();
</del><ins>+        if (Optional&lt;Decimal&gt; closest = input-&gt;findClosestTickMarkValue(value)) {
+            double closestFraction = stepRange.proportionFromValue(*closest).toDouble();
</ins><span class="cx">             double closestRatio = isVertical || !isLeftToRightDirection ? 1.0 - closestFraction : closestFraction;
</span><span class="cx">             LayoutUnit closestPosition = trackLength * closestRatio;
</span><span class="cx">             if ((closestPosition - position).abs() &lt;= snappingThreshold)
</span><del>-                value = closest;
</del><ins>+                value = *closest;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>