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 "core/rendering/RenderSlider.h" 23 24 #include "core/html/HTMLInputElement.h" 25 #include "core/html/shadow/SliderThumbElement.h" 26 #include "wtf/MathExtras.h" 27 28 using std::min; 29 30 namespace WebCore { 31 32 const int RenderSlider::defaultTrackLength = 129; 33 34 RenderSlider::RenderSlider(HTMLInputElement* element) 35 : RenderFlexibleBox(element) 36 { 37 // We assume RenderSlider works only with <input type=range>. 38 ASSERT(element->isRangeControl()); 39 } 40 41 RenderSlider::~RenderSlider() 42 { 43 } 44 45 bool RenderSlider::canBeReplacedWithInlineRunIn() const 46 { 47 return false; 48 } 49 50 int RenderSlider::baselinePosition(FontBaseline, bool /*firstLine*/, LineDirectionMode, LinePositionMode linePositionMode) const 51 { 52 ASSERT(linePositionMode == PositionOnContainingLine); 53 // FIXME: Patch this function for writing-mode. 54 return height() + marginTop(); 55 } 56 57 void RenderSlider::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const 58 { 59 maxLogicalWidth = defaultTrackLength * style()->effectiveZoom(); 60 if (!style()->width().isPercent()) 61 minLogicalWidth = maxLogicalWidth; 62 } 63 64 void RenderSlider::computePreferredLogicalWidths() 65 { 66 m_minPreferredLogicalWidth = 0; 67 m_maxPreferredLogicalWidth = 0; 68 69 if (style()->width().isFixed() && style()->width().value() > 0) 70 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(style()->width().value()); 71 else 72 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth); 73 74 if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) { 75 m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->minWidth().value())); 76 m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->minWidth().value())); 77 } 78 79 if (style()->maxWidth().isFixed()) { 80 m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->maxWidth().value())); 81 m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->maxWidth().value())); 82 } 83 84 LayoutUnit toAdd = borderAndPaddingWidth(); 85 m_minPreferredLogicalWidth += toAdd; 86 m_maxPreferredLogicalWidth += toAdd; 87 88 setPreferredLogicalWidthsDirty(false); 89 } 90 91 void RenderSlider::layout() 92 { 93 StackStats::LayoutCheckPoint layoutCheckPoint; 94 // FIXME: Find a way to cascade appearance. 95 // http://webkit.org/b/62535 96 RenderBox* thumbBox = sliderThumbElementOf(node())->renderBox(); 97 if (thumbBox && thumbBox->isSliderThumb()) 98 static_cast<RenderSliderThumb*>(thumbBox)->updateAppearance(style()); 99 100 RenderFlexibleBox::layout(); 101 } 102 103 bool RenderSlider::inDragMode() const 104 { 105 return sliderThumbElementOf(node())->active(); 106 } 107 108 } // namespace WebCore 109