Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / rendering / RenderSlider.cpp
index a4e4a3b..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;
 
-// Returns a value between 0 and 1.
-static double sliderPosition(HTMLInputElement* element)
+RenderSlider::RenderSlider(HTMLInputElement& element, RenderStyle&& style)
+    : RenderFlexibleBox(element, WTFMove(style))
 {
-    StepRange range(element);
-    return range.proportionFromValue(range.valueFromElement(element));
+    // We assume RenderSlider works only with <input type=range>.
+    ASSERT(element.isRangeControl());
 }
 
-RenderSlider::RenderSlider(HTMLInputElement* element)
-    : RenderBlock(element)
-{
-}
+RenderSlider::~RenderSlider() = default;
 
-RenderSlider::~RenderSlider()
+HTMLInputElement& RenderSlider::element() const
 {
+    return downcast<HTMLInputElement>(nodeForNonAnonymous());
 }
 
 int RenderSlider::baselinePosition(FontBaseline, bool /*firstLine*/, LineDirectionMode, LinePositionMode) const
@@ -70,123 +65,55 @@ 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()));
+    }
+
+    if (style().maxWidth().isFixed()) {
+        m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().maxWidth().value()));
+        m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().maxWidth().value()));
     }
 
-    int toAdd = borderAndPaddingWidth();
+    LayoutUnit toAdd = horizontalBorderAndPaddingExtent();
     m_minPreferredLogicalWidth += toAdd;
     m_maxPreferredLogicalWidth += toAdd;
 
     setPreferredLogicalWidthsDirty(false); 
 }
 
-IntRect RenderSlider::thumbRect()
-{
-    SliderThumbElement* thumbElement = shadowSliderThumb();
-    if (!thumbElement)
-        return IntRect();
-
-    IntRect thumbRect;
-    RenderBox* thumb = toRenderBox(thumbElement->renderer());
-
-    thumbRect.setWidth(thumb->style()->width().calcMinValue(contentWidth()));
-    thumbRect.setHeight(thumb->style()->height().calcMinValue(contentHeight()));
-
-    double fraction = sliderPosition(static_cast<HTMLInputElement*>(node()));
-    IntRect contentRect = contentBoxRect();
-    if (style()->appearance() == SliderVerticalPart || style()->appearance() == MediaVolumeSliderPart) {
-        thumbRect.setX(contentRect.x() + (contentRect.width() - thumbRect.width()) / 2);
-        thumbRect.setY(contentRect.y() + static_cast<int>(nextafter((contentRect.height() - thumbRect.height()) + 1, 0) * (1 - fraction)));
-    } else {
-        thumbRect.setX(contentRect.x() + static_cast<int>(nextafter((contentRect.width() - thumbRect.width()) + 1, 0) * fraction));
-        thumbRect.setY(contentRect.y() + (contentRect.height() - thumbRect.height()) / 2);
-    }
-
-    return thumbRect;
-}
-
 void RenderSlider::layout()
 {
-    ASSERT(needsLayout());
-
-    SliderThumbElement* thumbElement = shadowSliderThumb();
-    RenderBox* thumb = thumbElement ? toRenderBox(thumbElement->renderer()) : 0;
+    StackStats::LayoutCheckPoint layoutCheckPoint;
 
-    IntSize baseSize(borderAndPaddingWidth(), borderAndPaddingHeight());
+    // 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 (thumb) {
-        // Allow the theme to set the size of the thumb.
-        if (thumb->style()->hasAppearance())
-            theme()->adjustSliderThumbSize(thumb->style());
-
-        baseSize.expand(thumb->style()->width().calcMinValue(0), thumb->style()->height().calcMinValue(0));
-    }
-
-    LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
-
-    IntSize oldSize = size();
-
-    setSize(baseSize);
-    computeLogicalWidth();
-    computeLogicalHeight();
-    updateLayerTransform();
-
-    m_overflow.clear();
-
-    if (thumb) {
-        if (oldSize != size())
-            thumb->setChildNeedsLayout(true, false);
-
-        LayoutStateMaintainer statePusher(view(), this, IntSize(x(), y()), style()->isFlippedBlocksWritingMode());
-
-        IntRect oldThumbRect = thumb->frameRect();
-
-        thumb->layoutIfNeeded();
-
-        IntRect rect = thumbRect();
-        thumb->setFrameRect(rect);
-        if (thumb->checkForRepaintDuringLayout())
-            thumb->repaintDuringLayoutIfMoved(oldThumbRect);
-
-        statePusher.pop();
-        addOverflowFromChild(thumb);
-    }
-
-    repainter.repaintAfterLayout();    
-
-    setNeedsLayout(false);
-}
-
-SliderThumbElement* RenderSlider::shadowSliderThumb() const
-{
-    Node* shadow = static_cast<Element*>(node())->shadowRoot();
-    return shadow ? toSliderThumbElement(shadow->firstChild()) : 0;
+    RenderFlexibleBox::layout();
 }
 
 bool RenderSlider::inDragMode() const
 {
-    SliderThumbElement* thumbElement = shadowSliderThumb();
-    return thumbElement && thumbElement->active();
+    return element().sliderThumbElement()->active();
 }
 
 } // namespace WebCore