Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / rendering / RenderSlider.cpp
index c57d035..39b5554 100644 (file)
 #include "RenderSlider.h"
 
 #include "CSSPropertyNames.h"
-#include "CSSStyleSelector.h"
 #include "Document.h"
 #include "Event.h"
-#include "EventHandler.h"
-#include "EventNames.h"
 #include "Frame.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "ShadowRoot.h"
 #include "SliderThumbElement.h"
 #include "StepRange.h"
+#include "StyleResolver.h"
 #include <wtf/MathExtras.h>
-
-using std::min;
+#include <wtf/StackStats.h>
 
 namespace WebCore {
 
-static const int defaultTrackLength = 129;
+const int RenderSlider::defaultTrackLength = 129;
 
-RenderSlider::RenderSlider(HTMLInputElement* element)
-    : RenderBlock(element)
+RenderSlider::RenderSlider(HTMLInputElement& element, RenderStyle&& style)
+    : RenderFlexibleBox(element, WTFMove(style))
 {
     // We assume RenderSlider works only with <input type=range>.
-    ASSERT(element->isRangeControl());
+    ASSERT(element.isRangeControl());
 }
 
-RenderSlider::~RenderSlider()
+RenderSlider::~RenderSlider() = default;
+
+HTMLInputElement& RenderSlider::element() const
 {
+    return downcast<HTMLInputElement>(nodeForNonAnonymous());
 }
 
 int RenderSlider::baselinePosition(FontBaseline, bool /*firstLine*/, LineDirectionMode, LinePositionMode) const
@@ -65,30 +65,34 @@ int RenderSlider::baselinePosition(FontBaseline, bool /*firstLine*/, LineDirecti
     return height() + marginTop();
 }
 
+void RenderSlider::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
+{
+    maxLogicalWidth = defaultTrackLength * style().effectiveZoom();
+    if (!style().width().isPercentOrCalculated())
+        minLogicalWidth = maxLogicalWidth;
+}
+
 void RenderSlider::computePreferredLogicalWidths()
 {
     m_minPreferredLogicalWidth = 0;
     m_maxPreferredLogicalWidth = 0;
 
-    if (style()->width().isFixed() && style()->width().value() > 0)
-        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeContentBoxLogicalWidth(style()->width().value());
+    if (style().width().isFixed() && style().width().value() > 0)
+        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(style().width().value());
     else
-        m_maxPreferredLogicalWidth = defaultTrackLength * style()->effectiveZoom();
+        computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth);
 
-    if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) {
-        m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->minWidth().value()));
-        m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->minWidth().value()));
-    } else if (style()->width().isPercent() || (style()->width().isAuto() && style()->height().isPercent()))
-        m_minPreferredLogicalWidth = 0;
-    else
-        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
-    
-    if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
-        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
-        m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
+    if (style().minWidth().isFixed() && style().minWidth().value() > 0) {
+        m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().minWidth().value()));
+        m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().minWidth().value()));
     }
 
-    LayoutUnit toAdd = borderAndPaddingWidth();
+    if (style().maxWidth().isFixed()) {
+        m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().maxWidth().value()));
+        m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().maxWidth().value()));
+    }
+
+    LayoutUnit toAdd = horizontalBorderAndPaddingExtent();
     m_minPreferredLogicalWidth += toAdd;
     m_maxPreferredLogicalWidth += toAdd;
 
@@ -97,28 +101,19 @@ void RenderSlider::computePreferredLogicalWidths()
 
 void RenderSlider::layout()
 {
-    // FIXME: Find a way to cascade appearance.
-    // http://webkit.org/b/62535
-    RenderBox* thumbBox = sliderThumbElementOf(node())->renderBox();
-    if (thumbBox && thumbBox->isSliderThumb())
-        static_cast<RenderSliderThumb*>(thumbBox)->updateAppearance(style());
-    if (RenderObject* limiterRenderer = trackLimiterElementOf(node())->renderer()) {
-        if (limiterRenderer->isSliderThumb())
-          static_cast<RenderSliderThumb*>(limiterRenderer)->updateAppearance(style());
-    }
+    StackStats::LayoutCheckPoint layoutCheckPoint;
 
-    RenderBlock::layout();
+    // FIXME: Find a way to cascade appearance. http://webkit.org/b/62535
+    RenderBox* thumbBox = element().sliderThumbElement()->renderBox();
+    if (thumbBox && thumbBox->isSliderThumb())
+        static_cast<RenderSliderThumb*>(thumbBox)->updateAppearance(&style());
 
-    if (!thumbBox)
-        return;
-    LayoutUnit heightDiff = thumbBox->height() - contentHeight();
-    if (heightDiff > 0)
-        thumbBox->setY(thumbBox->y() - (heightDiff / 2));
+    RenderFlexibleBox::layout();
 }
 
 bool RenderSlider::inDragMode() const
 {
-    return sliderThumbElementOf(node())->active();
+    return element().sliderThumbElement()->active();
 }
 
 } // namespace WebCore