#include "config.h"
#include "RenderSlider.h"
#include "CSSPropertyNames.h"
#include "Document.h"
#include "Event.h"
#include "Frame.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
#include "MediaControlElements.h"
#include "MouseEvent.h"
#include "Node.h"
#include "RenderLayer.h"
#include "RenderTheme.h"
#include "RenderView.h"
#include "ShadowRoot.h"
#include "SliderThumbElement.h"
#include "StepRange.h"
#include "StyleResolver.h"
#include <wtf/MathExtras.h>
#include <wtf/StackStats.h>
namespace WebCore {
const int RenderSlider::defaultTrackLength = 129;
RenderSlider::RenderSlider(HTMLInputElement& element, RenderStyle&& style)
: RenderFlexibleBox(element, WTFMove(style))
{
ASSERT(element.isRangeControl());
}
RenderSlider::~RenderSlider()
{
}
HTMLInputElement& RenderSlider::element() const
{
return downcast<HTMLInputElement>(nodeForNonAnonymous());
}
int RenderSlider::baselinePosition(FontBaseline, bool , LineDirectionMode, LinePositionMode) const
{
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 = adjustContentBoxLogicalWidthForBoxSizing(style().width().value());
else
computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth);
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()));
}
LayoutUnit toAdd = horizontalBorderAndPaddingExtent();
m_minPreferredLogicalWidth += toAdd;
m_maxPreferredLogicalWidth += toAdd;
setPreferredLogicalWidthsDirty(false);
}
void RenderSlider::layout()
{
StackStats::LayoutCheckPoint layoutCheckPoint;
RenderBox* thumbBox = element().sliderThumbElement()->renderBox();
if (thumbBox && thumbBox->isSliderThumb())
static_cast<RenderSliderThumb*>(thumbBox)->updateAppearance(&style());
RenderFlexibleBox::layout();
}
bool RenderSlider::inDragMode() const
{
return element().sliderThumbElement()->active();
}
}