Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
tkent
2014/07/17 23:56:13
Please use the copyright header of SliderThumbElem
deepak.sa
2014/07/18 06:06:56
Done.
| |
| 2 // | |
| 3 // The Chromium Authors can be found at | |
| 4 // http://src.chromium.org/svn/trunk/src/AUTHORS | |
| 5 // | |
| 6 // Redistribution and use in source and binary forms, with or without | |
| 7 // modification, are permitted provided that the following conditions are | |
| 8 // met: | |
| 9 // | |
| 10 // * Redistributions of source code must retain the above copyright | |
| 11 // notice, this list of conditions and the following disclaimer. | |
| 12 // * Redistributions in binary form must reproduce the above | |
| 13 // copyright notice, this list of conditions and the following disclaimer | |
| 14 // in the documentation and/or other materials provided with the | |
| 15 // distribution. | |
| 16 // * Neither the name of Google Inc. nor the names of its | |
| 17 // contributors may be used to endorse or promote products derived from | |
| 18 // this software without specific prior written permission. | |
| 19 // | |
| 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 31 | |
| 32 #include "config.h" | |
| 33 #include "core/rendering/RenderSliderContainer.h" | |
| 34 | |
| 35 #include "core/dom/shadow/ShadowRoot.h" | |
| 36 #include "core/html/HTMLInputElement.h" | |
| 37 #include "core/html/parser/HTMLParserIdioms.h" | |
| 38 #include "core/html/shadow/ShadowElementNames.h" | |
| 39 #include "core/html/shadow/SliderThumbElement.h" | |
| 40 #include "core/rendering/RenderFlexibleBox.h" | |
| 41 #include "core/rendering/RenderSlider.h" | |
| 42 #include "core/rendering/RenderTheme.h" | |
| 43 | |
| 44 namespace WebCore { | |
| 45 | |
| 46 RenderSliderContainer::RenderSliderContainer(SliderContainerElement* element) | |
| 47 : RenderFlexibleBox(element) | |
| 48 { | |
| 49 } | |
| 50 | |
| 51 inline static Decimal sliderPosition(HTMLInputElement* element) | |
| 52 { | |
| 53 const StepRange stepRange(element->createStepRange(RejectAny)); | |
| 54 const Decimal oldValue = parseToDecimalForNumberType(element->value(), stepR ange.defaultValue()); | |
| 55 return stepRange.proportionFromValue(stepRange.clampValue(oldValue)); | |
| 56 } | |
| 57 | |
| 58 inline static bool hasVerticalAppearance(HTMLInputElement* input) | |
| 59 { | |
| 60 ASSERT(input->renderer()); | |
| 61 RenderStyle* sliderStyle = input->renderer()->style(); | |
| 62 | |
| 63 return sliderStyle->appearance() == SliderVerticalPart; | |
| 64 } | |
| 65 | |
| 66 void RenderSliderContainer::computeLogicalHeight(LayoutUnit logicalHeight, Layou tUnit logicalTop, LogicalExtentComputedValues& computedValues) const | |
| 67 { | |
| 68 HTMLInputElement* input = toHTMLInputElement(node()->shadowHost()); | |
| 69 bool isVertical = hasVerticalAppearance(input); | |
| 70 | |
| 71 if (input->renderer()->isSlider() && !isVertical && input->list()) { | |
| 72 int offsetFromCenter = RenderTheme::theme().sliderTickOffsetFromTrackCen ter(); | |
| 73 LayoutUnit trackHeight = 0; | |
| 74 if (offsetFromCenter < 0) { | |
| 75 trackHeight = -2 * offsetFromCenter; | |
| 76 } else { | |
| 77 int tickLength = RenderTheme::theme().sliderTickSize().height(); | |
| 78 trackHeight = 2 * (offsetFromCenter + tickLength); | |
| 79 } | |
| 80 float zoomFactor = style()->effectiveZoom(); | |
| 81 if (zoomFactor != 1.0) | |
| 82 trackHeight *= zoomFactor; | |
| 83 | |
| 84 // FIXME: The trackHeight should have been added before updateLogicalHei ght was called to avoid this hack. | |
| 85 updateIntrinsicContentLogicalHeight(trackHeight); | |
| 86 | |
| 87 RenderBox::computeLogicalHeight(trackHeight, logicalTop, computedValues) ; | |
| 88 return; | |
| 89 } | |
| 90 if (isVertical) | |
| 91 logicalHeight = RenderSlider::defaultTrackLength; | |
| 92 | |
| 93 // FIXME: The trackHeight should have been added before updateLogicalHeight was called to avoid this hack. | |
| 94 updateIntrinsicContentLogicalHeight(logicalHeight); | |
| 95 | |
| 96 RenderBox::computeLogicalHeight(logicalHeight, logicalTop, computedValues); | |
| 97 } | |
| 98 | |
| 99 void RenderSliderContainer::layout() | |
| 100 { | |
| 101 HTMLInputElement* input = toHTMLInputElement(node()->shadowHost()); | |
| 102 bool isVertical = hasVerticalAppearance(input); | |
| 103 style()->setFlexDirection(isVertical ? FlowColumn : FlowRow); | |
| 104 TextDirection oldTextDirection = style()->direction(); | |
| 105 if (isVertical) { | |
| 106 // FIXME: Work around rounding issues in RTL vertical sliders. We want t hem to | |
| 107 // render identically to LTR vertical sliders. We can remove this work a round when | |
| 108 // subpixel rendering is enabled on all ports. | |
| 109 style()->setDirection(LTR); | |
| 110 } | |
| 111 | |
| 112 Element* thumbElement = input->userAgentShadowRoot()->getElementById(ShadowE lementNames::sliderThumb()); | |
| 113 Element* trackElement = input->userAgentShadowRoot()->getElementById(ShadowE lementNames::sliderTrack()); | |
| 114 RenderBox* thumb = thumbElement ? thumbElement->renderBox() : 0; | |
| 115 RenderBox* track = trackElement ? trackElement->renderBox() : 0; | |
| 116 | |
| 117 SubtreeLayoutScope layoutScope(*this); | |
| 118 // Force a layout to reset the position of the thumb so the code below doesn 't move the thumb to the wrong place. | |
| 119 // FIXME: Make a custom Render class for the track and move the thumb positi oning code there. | |
| 120 if (track) | |
| 121 layoutScope.setChildNeedsLayout(track); | |
| 122 | |
| 123 RenderFlexibleBox::layout(); | |
| 124 | |
| 125 style()->setDirection(oldTextDirection); | |
| 126 // These should always exist, unless someone mutates the shadow DOM (e.g., i n the inspector). | |
| 127 if (!thumb || !track) | |
| 128 return; | |
| 129 | |
| 130 double percentageOffset = sliderPosition(input).toDouble(); | |
| 131 LayoutUnit availableExtent = isVertical ? track->contentHeight() : track->co ntentWidth(); | |
| 132 availableExtent -= isVertical ? thumb->height() : thumb->width(); | |
| 133 LayoutUnit offset = percentageOffset * availableExtent; | |
| 134 LayoutPoint thumbLocation = thumb->location(); | |
| 135 if (isVertical) | |
| 136 thumbLocation.setY(thumbLocation.y() + track->contentHeight() - thumb->h eight() - offset); | |
| 137 else if (style()->isLeftToRightDirection()) | |
| 138 thumbLocation.setX(thumbLocation.x() + offset); | |
| 139 else | |
| 140 thumbLocation.setX(thumbLocation.x() - offset); | |
| 141 thumb->setLocation(thumbLocation); | |
| 142 } | |
| 143 | |
| 144 } // namespace WebCore | |
| OLD | NEW |