1/* 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 * 19 */ 20 21#include "config.h" 22#include "RenderSlider.h" 23 24#include "CSSPropertyNames.h" 25#include "Document.h" 26#include "Event.h" 27#include "EventHandler.h" 28#include "EventNames.h" 29#include "Frame.h" 30#include "HTMLInputElement.h" 31#include "HTMLNames.h" 32#include "HTMLParserIdioms.h" 33#include "MediaControlElements.h" 34#include "MouseEvent.h" 35#include "Node.h" 36#include "RenderLayer.h" 37#include "RenderTheme.h" 38#include "RenderView.h" 39#include "ShadowRoot.h" 40#include "SliderThumbElement.h" 41#include "StepRange.h" 42#include "StyleResolver.h" 43#include <wtf/MathExtras.h> 44#include <wtf/StackStats.h> 45 46namespace WebCore { 47 48const int RenderSlider::defaultTrackLength = 129; 49 50RenderSlider::RenderSlider(HTMLInputElement& element, PassRef<RenderStyle> style) 51 : RenderFlexibleBox(element, WTF::move(style)) 52{ 53 // We assume RenderSlider works only with <input type=range>. 54 ASSERT(element.isRangeControl()); 55} 56 57RenderSlider::~RenderSlider() 58{ 59} 60 61HTMLInputElement& RenderSlider::element() const 62{ 63 return toHTMLInputElement(nodeForNonAnonymous()); 64} 65 66int RenderSlider::baselinePosition(FontBaseline, bool /*firstLine*/, LineDirectionMode, LinePositionMode) const 67{ 68 // FIXME: Patch this function for writing-mode. 69 return height() + marginTop(); 70} 71 72void RenderSlider::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const 73{ 74 maxLogicalWidth = defaultTrackLength * style().effectiveZoom(); 75 if (!style().width().isPercent()) 76 minLogicalWidth = maxLogicalWidth; 77} 78 79void RenderSlider::computePreferredLogicalWidths() 80{ 81 m_minPreferredLogicalWidth = 0; 82 m_maxPreferredLogicalWidth = 0; 83 84 if (style().width().isFixed() && style().width().value() > 0) 85 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(style().width().value()); 86 else 87 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth); 88 89 if (style().minWidth().isFixed() && style().minWidth().value() > 0) { 90 m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().minWidth().value())); 91 m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().minWidth().value())); 92 } 93 94 if (style().maxWidth().isFixed()) { 95 m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().maxWidth().value())); 96 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style().maxWidth().value())); 97 } 98 99 LayoutUnit toAdd = horizontalBorderAndPaddingExtent(); 100 m_minPreferredLogicalWidth += toAdd; 101 m_maxPreferredLogicalWidth += toAdd; 102 103 setPreferredLogicalWidthsDirty(false); 104} 105 106void RenderSlider::layout() 107{ 108 StackStats::LayoutCheckPoint layoutCheckPoint; 109 110 // FIXME: Find a way to cascade appearance. http://webkit.org/b/62535 111 RenderBox* thumbBox = element().sliderThumbElement()->renderBox(); 112 if (thumbBox && thumbBox->isSliderThumb()) 113 static_cast<RenderSliderThumb*>(thumbBox)->updateAppearance(&style()); 114 115 RenderFlexibleBox::layout(); 116} 117 118bool RenderSlider::inDragMode() const 119{ 120 return element().sliderThumbElement()->active(); 121} 122 123} // namespace WebCore 124