| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | |
| 3 * 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions | |
| 7 * are met: | |
| 8 * | |
| 9 * 1. Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | |
| 12 * notice, this list of conditions and the following disclaimer in the | |
| 13 * documentation and/or other materials provided with the distribution. | |
| 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
| 15 * its contributors may be used to endorse or promote products derived | |
| 16 * from this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 */ | |
| 29 | |
| 30 #include "config.h" | |
| 31 #include "core/rendering/RenderListBox.h" | |
| 32 | |
| 33 #include "core/HTMLNames.h" | |
| 34 #include "core/css/CSSFontSelector.h" | |
| 35 #include "core/css/resolver/StyleResolver.h" | |
| 36 #include "core/dom/AXObjectCache.h" | |
| 37 #include "core/dom/Document.h" | |
| 38 #include "core/dom/ElementTraversal.h" | |
| 39 #include "core/dom/NodeLayoutStyle.h" | |
| 40 #include "core/dom/StyleEngine.h" | |
| 41 #include "core/editing/FrameSelection.h" | |
| 42 #include "core/frame/FrameView.h" | |
| 43 #include "core/frame/LocalFrame.h" | |
| 44 #include "core/html/HTMLDivElement.h" | |
| 45 #include "core/html/HTMLOptGroupElement.h" | |
| 46 #include "core/html/HTMLOptionElement.h" | |
| 47 #include "core/html/HTMLSelectElement.h" | |
| 48 #include "core/layout/HitTestResult.h" | |
| 49 #include "core/layout/Layer.h" | |
| 50 #include "core/layout/LayoutTheme.h" | |
| 51 #include "core/layout/PaintInfo.h" | |
| 52 #include "core/layout/TextRunConstructor.h" | |
| 53 #include "core/page/EventHandler.h" | |
| 54 #include "core/page/FocusController.h" | |
| 55 #include "core/page/Page.h" | |
| 56 #include "core/page/SpatialNavigation.h" | |
| 57 #include "core/rendering/RenderText.h" | |
| 58 #include "core/rendering/RenderView.h" | |
| 59 #include "platform/fonts/FontCache.h" | |
| 60 #include "platform/graphics/GraphicsContext.h" | |
| 61 #include "platform/text/BidiTextRun.h" | |
| 62 #include <math.h> | |
| 63 | |
| 64 namespace blink { | |
| 65 | |
| 66 using namespace HTMLNames; | |
| 67 | |
| 68 // Default size when the multiple attribute is present but size attribute is abs
ent. | |
| 69 const int defaultSize = 4; | |
| 70 | |
| 71 const int defaultPaddingBottom = 1; | |
| 72 | |
| 73 RenderListBox::RenderListBox(Element* element) | |
| 74 : RenderBlockFlow(element) | |
| 75 { | |
| 76 ASSERT(element); | |
| 77 ASSERT(element->isHTMLElement()); | |
| 78 ASSERT(isHTMLSelectElement(element)); | |
| 79 } | |
| 80 | |
| 81 RenderListBox::~RenderListBox() | |
| 82 { | |
| 83 } | |
| 84 | |
| 85 inline HTMLSelectElement* RenderListBox::selectElement() const | |
| 86 { | |
| 87 return toHTMLSelectElement(node()); | |
| 88 } | |
| 89 | |
| 90 int RenderListBox::size() const | |
| 91 { | |
| 92 int specifiedSize = selectElement()->size(); | |
| 93 if (specifiedSize >= 1) | |
| 94 return specifiedSize; | |
| 95 | |
| 96 return defaultSize; | |
| 97 } | |
| 98 | |
| 99 LayoutUnit RenderListBox::defaultItemHeight() const | |
| 100 { | |
| 101 return style()->fontMetrics().height() + defaultPaddingBottom; | |
| 102 } | |
| 103 | |
| 104 LayoutUnit RenderListBox::itemHeight() const | |
| 105 { | |
| 106 HTMLSelectElement* select = selectElement(); | |
| 107 if (!select) | |
| 108 return 0; | |
| 109 Element* baseItem = ElementTraversal::firstChild(*select); | |
| 110 if (!baseItem) | |
| 111 return defaultItemHeight(); | |
| 112 if (isHTMLOptGroupElement(baseItem)) | |
| 113 baseItem = &toHTMLOptGroupElement(baseItem)->optGroupLabelElement(); | |
| 114 else if (!isHTMLOptionElement(baseItem)) | |
| 115 return defaultItemHeight(); | |
| 116 LayoutObject* baseItemRenderer = baseItem->renderer(); | |
| 117 if (!baseItemRenderer) | |
| 118 return defaultItemHeight(); | |
| 119 if (!baseItemRenderer || !baseItemRenderer->isBox()) | |
| 120 return defaultItemHeight(); | |
| 121 return toRenderBox(baseItemRenderer)->size().height(); | |
| 122 } | |
| 123 | |
| 124 void RenderListBox::computeLogicalHeight(LayoutUnit, LayoutUnit logicalTop, Logi
calExtentComputedValues& computedValues) const | |
| 125 { | |
| 126 LayoutUnit height = itemHeight() * size(); | |
| 127 // FIXME: The item height should have been added before updateLogicalHeight
was called to avoid this hack. | |
| 128 setIntrinsicContentLogicalHeight(height); | |
| 129 | |
| 130 height += borderAndPaddingHeight(); | |
| 131 | |
| 132 RenderBox::computeLogicalHeight(height, logicalTop, computedValues); | |
| 133 } | |
| 134 | |
| 135 void RenderListBox::stopAutoscroll() | |
| 136 { | |
| 137 HTMLSelectElement* select = selectElement(); | |
| 138 if (select->isDisabledFormControl()) | |
| 139 return; | |
| 140 select->handleMouseRelease(); | |
| 141 } | |
| 142 | |
| 143 void RenderListBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, L
ayoutUnit& maxLogicalWidth) const | |
| 144 { | |
| 145 RenderBlockFlow::computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWi
dth); | |
| 146 if (style()->width().isPercent()) | |
| 147 minLogicalWidth = 0; | |
| 148 } | |
| 149 | |
| 150 void RenderListBox::scrollToRect(const LayoutRect& rect) | |
| 151 { | |
| 152 if (hasOverflowClip()) { | |
| 153 ASSERT(layer()); | |
| 154 ASSERT(layer()->scrollableArea()); | |
| 155 layer()->scrollableArea()->exposeRect(rect, ScrollAlignment::alignToEdge
IfNeeded, ScrollAlignment::alignToEdgeIfNeeded); | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 } // namespace blink | |
| OLD | NEW |