eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 1 | /** |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 4 | * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 5 | * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public License |
| 18 | * along with this library; see the file COPYING.LIB. If not, write to |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 21 | * |
| 22 | */ |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 23 | |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 24 | #include "config.h" |
| 25 | #include "RenderListItem.h" |
| 26 | |
| 27 | #include "CachedImage.h" |
| 28 | #include "HTMLNames.h" |
| 29 | #include "HTMLOListElement.h" |
| 30 | #include "RenderListMarker.h" |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 31 | #include "RenderView.h" |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 32 | #include <wtf/StdLibExtras.h> |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 33 | |
| 34 | using namespace std; |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | using namespace HTMLNames; |
| 39 | |
| 40 | RenderListItem::RenderListItem(Node* node) |
| 41 | : RenderBlock(node) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 42 | , m_marker(0) |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 43 | , m_hasExplicitValue(false) |
| 44 | , m_isValueUpToDate(false) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 45 | , m_notInList(false) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 46 | { |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 47 | setInline(false); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 48 | } |
| 49 | |
weinig@apple.com | 1a57c82 | 2009-02-04 22:27:50 +0000 | [diff] [blame] | 50 | void RenderListItem::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 51 | { |
simon.fraser@apple.com | a89b8cd | 2008-10-10 03:15:31 +0000 | [diff] [blame] | 52 | RenderBlock::styleDidChange(diff, oldStyle); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 53 | |
dbates@webkit.org | 267a5c8 | 2009-12-23 07:28:54 +0000 | [diff] [blame] | 54 | if (style()->listStyleType() != NoneListStyle |
| 55 | || (style()->listStyleImage() && !style()->listStyleImage()->errorOccurred())) { |
hyatt@apple.com | dec0cbf2 | 2008-10-17 00:25:33 +0000 | [diff] [blame] | 56 | RefPtr<RenderStyle> newStyle = RenderStyle::create(); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 57 | // The marker always inherits from the list item, regardless of where it might end |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 58 | // up (e.g., in some deeply nested line box). See CSS3 spec. |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 59 | newStyle->inheritFrom(style()); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 60 | if (!m_marker) |
| 61 | m_marker = new (renderArena()) RenderListMarker(this); |
hyatt@apple.com | dec0cbf2 | 2008-10-17 00:25:33 +0000 | [diff] [blame] | 62 | m_marker->setStyle(newStyle.release()); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 63 | } else if (m_marker) { |
| 64 | m_marker->destroy(); |
| 65 | m_marker = 0; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void RenderListItem::destroy() |
| 70 | { |
| 71 | if (m_marker) { |
| 72 | m_marker->destroy(); |
| 73 | m_marker = 0; |
| 74 | } |
| 75 | RenderBlock::destroy(); |
| 76 | } |
| 77 | |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 78 | static bool isList(Node* node) |
| 79 | { |
| 80 | return (node->hasTagName(ulTag) || node->hasTagName(olTag)); |
| 81 | } |
| 82 | |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 83 | static Node* enclosingList(Node* node) |
| 84 | { |
darin | 76d3b83 | 2006-07-29 15:06:04 +0000 | [diff] [blame] | 85 | Node* parent = node->parentNode(); |
| 86 | for (Node* n = parent; n; n = n->parentNode()) |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 87 | if (isList(n)) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 88 | return n; |
darin | 76d3b83 | 2006-07-29 15:06:04 +0000 | [diff] [blame] | 89 | // If there's no actual <ul> or <ol> list element, then our parent acts as |
| 90 | // our list for purposes of determining what other list items should be |
| 91 | // numbered as part of the same list. |
| 92 | return parent; |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 93 | } |
| 94 | |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 95 | static Node* enclosingList(const RenderObject* renderer) |
| 96 | { |
| 97 | Node* node = renderer->node(); |
| 98 | if (node) |
| 99 | return enclosingList(node); |
| 100 | |
| 101 | renderer = renderer->parent(); |
| 102 | while (renderer && !renderer->node()) |
| 103 | renderer = renderer->parent(); |
| 104 | |
| 105 | node = renderer->node(); |
| 106 | if (isList(node)) |
| 107 | return node; |
| 108 | |
| 109 | return enclosingList(node); |
| 110 | } |
| 111 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 112 | static RenderListItem* previousListItem(Node* list, const RenderListItem* item) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 113 | { |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 114 | for (RenderObject* renderer = item->previousInPreOrder(); renderer != list->renderer(); renderer = renderer->previousInPreOrder()) { |
| 115 | if (!renderer->isListItem()) |
darin@apple.com | b6cb256 | 2009-08-05 21:25:09 +0000 | [diff] [blame] | 116 | continue; |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 117 | Node* otherList = enclosingList(renderer); |
darin@apple.com | b6cb256 | 2009-08-05 21:25:09 +0000 | [diff] [blame] | 118 | // This item is part of our current list, so it's what we're looking for. |
| 119 | if (list == otherList) |
| 120 | return toRenderListItem(renderer); |
| 121 | // We found ourself inside another list; lets skip the rest of it. |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 122 | // Use nextInPreOrder() here because the other list itself may actually |
darin@apple.com | b6cb256 | 2009-08-05 21:25:09 +0000 | [diff] [blame] | 123 | // be a list item itself. We need to examine it, so we do this to counteract |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 124 | // the previousInPreOrder() that will be done by the loop. |
darin@apple.com | b6cb256 | 2009-08-05 21:25:09 +0000 | [diff] [blame] | 125 | if (otherList) |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 126 | renderer = otherList->renderer()->nextInPreOrder(); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 127 | } |
| 128 | return 0; |
| 129 | } |
| 130 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 131 | inline int RenderListItem::calcValue() const |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 132 | { |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 133 | if (m_hasExplicitValue) |
| 134 | return m_explicitValue; |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 135 | Node* list = enclosingList(this); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 136 | // FIXME: This recurses to a possible depth of the length of the list. |
| 137 | // That's not good -- we need to change this to an iterative algorithm. |
| 138 | if (RenderListItem* previousItem = previousListItem(list, this)) |
| 139 | return previousItem->value() + 1; |
| 140 | if (list && list->hasTagName(olTag)) |
| 141 | return static_cast<HTMLOListElement*>(list)->start(); |
| 142 | return 1; |
| 143 | } |
| 144 | |
| 145 | void RenderListItem::updateValueNow() const |
| 146 | { |
| 147 | m_value = calcValue(); |
| 148 | m_isValueUpToDate = true; |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | bool RenderListItem::isEmpty() const |
| 152 | { |
| 153 | return lastChild() == m_marker; |
| 154 | } |
| 155 | |
bdash | ccffb43 | 2007-07-13 11:51:40 +0000 | [diff] [blame] | 156 | static RenderObject* getParentOfFirstLineBox(RenderBlock* curr, RenderObject* marker) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 157 | { |
| 158 | RenderObject* firstChild = curr->firstChild(); |
| 159 | if (!firstChild) |
| 160 | return 0; |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 161 | |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 162 | for (RenderObject* currChild = firstChild; currChild; currChild = currChild->nextSibling()) { |
| 163 | if (currChild == marker) |
| 164 | continue; |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 165 | |
hyatt@apple.com | 415d8de | 2009-01-26 22:29:19 +0000 | [diff] [blame] | 166 | if (currChild->isInline() && (!currChild->isRenderInline() || curr->generatesLineBoxesForInlineChild(currChild))) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 167 | return curr; |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 168 | |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 169 | if (currChild->isFloating() || currChild->isPositioned()) |
| 170 | continue; |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 171 | |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 172 | if (currChild->isTable() || !currChild->isRenderBlock()) |
| 173 | break; |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 174 | |
hyatt@apple.com | 7e03253 | 2009-02-11 22:06:32 +0000 | [diff] [blame] | 175 | if (curr->isListItem() && currChild->style()->htmlHacks() && currChild->node() && |
| 176 | (currChild->node()->hasTagName(ulTag)|| currChild->node()->hasTagName(olTag))) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 177 | break; |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 178 | |
hyatt@apple.com | 801ed3f | 2009-01-30 18:16:03 +0000 | [diff] [blame] | 179 | RenderObject* lineBox = getParentOfFirstLineBox(toRenderBlock(currChild), marker); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 180 | if (lineBox) |
| 181 | return lineBox; |
| 182 | } |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 183 | |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 187 | void RenderListItem::updateValue() |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 188 | { |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 189 | if (!m_hasExplicitValue) { |
| 190 | m_isValueUpToDate = false; |
| 191 | if (m_marker) |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 192 | m_marker->setNeedsLayoutAndPrefWidthsRecalc(); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 193 | } |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 194 | } |
| 195 | |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 196 | static RenderObject* firstNonMarkerChild(RenderObject* parent) |
| 197 | { |
| 198 | RenderObject* result = parent->firstChild(); |
| 199 | while (result && result->isListMarker()) |
| 200 | result = result->nextSibling(); |
| 201 | return result; |
| 202 | } |
| 203 | |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 204 | void RenderListItem::updateMarkerLocation() |
| 205 | { |
| 206 | // Sanity check the location of our marker. |
| 207 | if (m_marker) { |
| 208 | RenderObject* markerPar = m_marker->parent(); |
| 209 | RenderObject* lineBoxParent = getParentOfFirstLineBox(this, m_marker); |
| 210 | if (!lineBoxParent) { |
| 211 | // If the marker is currently contained inside an anonymous box, |
| 212 | // then we are the only item in that anonymous box (since no line box |
| 213 | // parent was found). It's ok to just leave the marker where it is |
| 214 | // in this case. |
| 215 | if (markerPar && markerPar->isAnonymousBlock()) |
| 216 | lineBoxParent = markerPar; |
| 217 | else |
| 218 | lineBoxParent = this; |
| 219 | } |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 220 | |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 221 | if (markerPar != lineBoxParent || m_marker->prefWidthsDirty()) { |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 222 | // Removing and adding the marker can trigger repainting in |
| 223 | // containers other than ourselves, so we need to disable LayoutState. |
| 224 | view()->disableLayoutState(); |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 225 | updateFirstLetter(); |
hyatt | b866344 | 2006-08-04 21:04:11 +0000 | [diff] [blame] | 226 | m_marker->remove(); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 227 | if (!lineBoxParent) |
| 228 | lineBoxParent = this; |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 229 | lineBoxParent->addChild(m_marker, firstNonMarkerChild(lineBoxParent)); |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 230 | if (m_marker->prefWidthsDirty()) |
| 231 | m_marker->calcPrefWidths(); |
weinig | fef1363 | 2007-04-29 20:09:08 +0000 | [diff] [blame] | 232 | view()->enableLayoutState(); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 237 | void RenderListItem::calcPrefWidths() |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 238 | { |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 239 | ASSERT(prefWidthsDirty()); |
| 240 | |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 241 | updateMarkerLocation(); |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 242 | |
| 243 | RenderBlock::calcPrefWidths(); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void RenderListItem::layout() |
| 247 | { |
hyatt | 818bb12 | 2007-04-25 19:10:24 +0000 | [diff] [blame] | 248 | ASSERT(needsLayout()); |
| 249 | |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 250 | updateMarkerLocation(); |
| 251 | RenderBlock::layout(); |
| 252 | } |
| 253 | |
| 254 | void RenderListItem::positionListMarker() |
| 255 | { |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 256 | if (m_marker && !m_marker->isInside() && m_marker->inlineBoxWrapper()) { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 257 | int markerOldX = m_marker->x(); |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 258 | int yOffset = 0; |
| 259 | int xOffset = 0; |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 260 | for (RenderBox* o = m_marker->parentBox(); o != this; o = o->parentBox()) { |
| 261 | yOffset += o->y(); |
| 262 | xOffset += o->x(); |
weinig | f1db1db | 2007-02-28 00:04:39 +0000 | [diff] [blame] | 263 | } |
mitz@apple.com | 8de23dd | 2008-09-10 18:17:14 +0000 | [diff] [blame] | 264 | |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 265 | bool adjustOverflow = false; |
| 266 | int markerXPos; |
| 267 | RootInlineBox* root = m_marker->inlineBoxWrapper()->root(); |
| 268 | |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 269 | // FIXME: Inline flows in the line box hierarchy that have self-painting layers should act as cutoff points |
| 270 | // and really shouldn't keep propagating overflow up. This won't really break anything other than repainting |
| 271 | // not being as tight as it could be though. |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 272 | if (style()->direction() == LTR) { |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 273 | int leftLineOffset = leftRelOffset(yOffset, leftOffset(yOffset, false), false); |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 274 | markerXPos = leftLineOffset - xOffset - paddingLeft() - borderLeft() + m_marker->marginLeft(); |
| 275 | m_marker->inlineBoxWrapper()->adjustPosition(markerXPos - markerOldX, 0); |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 276 | for (InlineFlowBox* box = m_marker->inlineBoxWrapper()->parent(); box; box = box->parent()) { |
| 277 | if (markerXPos < box->leftLayoutOverflow()) { |
| 278 | box->setHorizontalOverflowPositions(markerXPos, box->rightLayoutOverflow(), box->leftVisualOverflow(), box->rightVisualOverflow()); |
| 279 | if (box == root) |
| 280 | adjustOverflow = true; |
| 281 | } |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 282 | } |
| 283 | } else { |
hyatt@apple.com | cd6f895 | 2009-01-28 17:30:26 +0000 | [diff] [blame] | 284 | int rightLineOffset = rightRelOffset(yOffset, rightOffset(yOffset, false), false); |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 285 | markerXPos = rightLineOffset - xOffset + paddingRight() + borderRight() + m_marker->marginLeft(); |
| 286 | m_marker->inlineBoxWrapper()->adjustPosition(markerXPos - markerOldX, 0); |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 287 | for (InlineFlowBox* box = m_marker->inlineBoxWrapper()->parent(); box; box = box->parent()) { |
| 288 | if (markerXPos + m_marker->width() > box->rightLayoutOverflow()) { |
| 289 | box->setHorizontalOverflowPositions(box->leftLayoutOverflow(), markerXPos + m_marker->width(), box->leftVisualOverflow(), box->rightVisualOverflow()); |
| 290 | if (box == root) |
| 291 | adjustOverflow = true; |
| 292 | } |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | if (adjustOverflow) { |
| 297 | IntRect markerRect(markerXPos + xOffset, yOffset, m_marker->width(), m_marker->height()); |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 298 | RenderBox* o = m_marker; |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 299 | do { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 300 | o = o->parentBox(); |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 301 | if (o->isRenderBlock()) |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 302 | toRenderBlock(o)->addLayoutOverflow(markerRect); |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 303 | markerRect.move(-o->x(), -o->y()); |
hyatt@apple.com | 5dc5a31 | 2009-08-18 19:15:19 +0000 | [diff] [blame] | 304 | } while (o != this && !o->hasSelfPaintingLayer()); |
mitz@apple.com | b214133 | 2008-09-10 18:19:39 +0000 | [diff] [blame] | 305 | } |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 309 | void RenderListItem::paint(PaintInfo& paintInfo, int tx, int ty) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 310 | { |
hyatt@apple.com | d885df7 | 2009-01-22 02:31:52 +0000 | [diff] [blame] | 311 | if (!height()) |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 312 | return; |
| 313 | |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 314 | RenderBlock::paint(paintInfo, tx, ty); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 315 | } |
| 316 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 317 | const String& RenderListItem::markerText() const |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 318 | { |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 319 | if (m_marker) |
| 320 | return m_marker->text(); |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 321 | DEFINE_STATIC_LOCAL(String, staticNullString, ()); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 322 | return staticNullString; |
| 323 | } |
| 324 | |
| 325 | void RenderListItem::explicitValueChanged() |
| 326 | { |
| 327 | if (m_marker) |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 328 | m_marker->setNeedsLayoutAndPrefWidthsRecalc(); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 329 | Node* listNode = enclosingList(node()); |
adele | 60f2836 | 2007-01-06 06:24:08 +0000 | [diff] [blame] | 330 | RenderObject* listRenderer = 0; |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 331 | if (listNode) |
| 332 | listRenderer = listNode->renderer(); |
darin@apple.com | b6cb256 | 2009-08-05 21:25:09 +0000 | [diff] [blame] | 333 | for (RenderObject* renderer = this; renderer; renderer = renderer->nextInPreOrder(listRenderer)) |
| 334 | if (renderer->isListItem()) { |
| 335 | RenderListItem* item = toRenderListItem(renderer); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 336 | if (!item->m_hasExplicitValue) { |
| 337 | item->m_isValueUpToDate = false; |
| 338 | if (RenderListMarker* marker = item->m_marker) |
darin | 7e7c8e4 | 2007-04-25 01:14:03 +0000 | [diff] [blame] | 339 | marker->setNeedsLayoutAndPrefWidthsRecalc(); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | void RenderListItem::setExplicitValue(int value) |
| 345 | { |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 346 | ASSERT(node()); |
| 347 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 348 | if (m_hasExplicitValue && m_explicitValue == value) |
| 349 | return; |
| 350 | m_explicitValue = value; |
| 351 | m_value = value; |
| 352 | m_hasExplicitValue = true; |
| 353 | explicitValueChanged(); |
| 354 | } |
| 355 | |
| 356 | void RenderListItem::clearExplicitValue() |
| 357 | { |
mitz@apple.com | 9feca28 | 2010-01-26 22:48:56 +0000 | [diff] [blame] | 358 | ASSERT(node()); |
| 359 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 360 | if (!m_hasExplicitValue) |
| 361 | return; |
| 362 | m_hasExplicitValue = false; |
| 363 | m_isValueUpToDate = false; |
| 364 | explicitValueChanged(); |
eseidel | e34973b | 2006-05-15 21:16:29 +0000 | [diff] [blame] | 365 | } |
| 366 | |
weinig | c24ab18 | 2006-10-30 22:41:29 +0000 | [diff] [blame] | 367 | } // namespace WebCore |