| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return cloneWithData(data()); | 238 return cloneWithData(data()); |
| 239 } | 239 } |
| 240 | 240 |
| 241 static inline bool hasGeneratedAnonymousTableCells(const LayoutObject& parent) | 241 static inline bool hasGeneratedAnonymousTableCells(const LayoutObject& parent) |
| 242 { | 242 { |
| 243 // We're checking whether the table part has generated anonymous table | 243 // We're checking whether the table part has generated anonymous table |
| 244 // part wrappers to hold its contents, so inspecting its first child will su
ffice. | 244 // part wrappers to hold its contents, so inspecting its first child will su
ffice. |
| 245 LayoutObject* child = parent.slowFirstChild(); | 245 LayoutObject* child = parent.slowFirstChild(); |
| 246 if (!child || !child->isAnonymous()) | 246 if (!child || !child->isAnonymous()) |
| 247 return false; | 247 return false; |
| 248 if (child->isTableCell()) | 248 if (child->isTableCell()) { |
| 249 return true; | 249 LayoutObject* firstChild = child->slowFirstChild(); |
| 250 // Ignore the anonymous table cell if it is wrapping a table cell elemen
t (e.g. because of <td style="display:block;">). |
| 251 return !firstChild || !firstChild->node() || !isHTMLTableCellElement(fir
stChild->node()); |
| 252 } |
| 250 if (child->isTableSection() || child->isTableRow()) | 253 if (child->isTableSection() || child->isTableRow()) |
| 251 return hasGeneratedAnonymousTableCells(*child); | 254 return hasGeneratedAnonymousTableCells(*child); |
| 252 return false; | 255 return false; |
| 253 } | 256 } |
| 254 | 257 |
| 255 static inline bool nodeAllowsAdjacentWhitespace(Node* node) | 258 static inline bool canHaveWhitespaceChildren(const LayoutObject& parent) |
| 256 { | |
| 257 if (!node) | |
| 258 return true; | |
| 259 const ComputedStyle* style = node->ensureComputedStyle(); | |
| 260 return style && style->originalDisplay() != TABLE_CELL && !isHTMLTableCellEl
ement(node); | |
| 261 } | |
| 262 | |
| 263 static inline bool canHaveWhitespaceChildren(const LayoutObject& parent, Text* t
ext) | |
| 264 { | 259 { |
| 265 // <button> should allow whitespace even though LayoutFlexibleBox doesn't. | 260 // <button> should allow whitespace even though LayoutFlexibleBox doesn't. |
| 266 if (parent.isLayoutButton()) | 261 if (parent.isLayoutButton()) |
| 267 return true; | 262 return true; |
| 268 | 263 |
| 264 // Allow whitespace when the text is inside a table, section or row element
that |
| 265 // has generated anonymous table cells to hold its contents. |
| 266 if (hasGeneratedAnonymousTableCells(parent)) |
| 267 return true; |
| 268 |
| 269 if (parent.isTable() || parent.isTableRow() || parent.isTableSection() | 269 if (parent.isTable() || parent.isTableRow() || parent.isTableSection() |
| 270 || parent.isLayoutTableCol() || parent.isFrameSet() | 270 || parent.isLayoutTableCol() || parent.isFrameSet() |
| 271 || parent.isFlexibleBox() || parent.isLayoutGrid() | 271 || parent.isFlexibleBox() || parent.isLayoutGrid() |
| 272 || parent.isSVGRoot() | 272 || parent.isSVGRoot() |
| 273 || parent.isSVGContainer() | 273 || parent.isSVGContainer() |
| 274 || parent.isSVGImage() | 274 || parent.isSVGImage() |
| 275 || parent.isSVGShape()) { | 275 || parent.isSVGShape()) |
| 276 // Allow whitespace when the text is inside a table, section or row elem
ent that | |
| 277 // has generated anonymous table cells to hold its contents. | |
| 278 if (hasGeneratedAnonymousTableCells(parent)) | |
| 279 return nodeAllowsAdjacentWhitespace(text->previousSibling()) && node
AllowsAdjacentWhitespace(text->nextSibling()); | |
| 280 return false; | 276 return false; |
| 281 } | |
| 282 return true; | 277 return true; |
| 283 } | 278 } |
| 284 | 279 |
| 285 bool Text::textLayoutObjectIsNeeded(const ComputedStyle& style, const LayoutObje
ct& parent) | 280 bool Text::textLayoutObjectIsNeeded(const ComputedStyle& style, const LayoutObje
ct& parent) |
| 286 { | 281 { |
| 287 if (!parent.canHaveChildren()) | 282 if (!parent.canHaveChildren()) |
| 288 return false; | 283 return false; |
| 289 | 284 |
| 290 if (isEditingText()) | 285 if (isEditingText()) |
| 291 return true; | 286 return true; |
| 292 | 287 |
| 293 if (!length()) | 288 if (!length()) |
| 294 return false; | 289 return false; |
| 295 | 290 |
| 296 if (style.display() == NONE) | 291 if (style.display() == NONE) |
| 297 return false; | 292 return false; |
| 298 | 293 |
| 299 if (!containsOnlyWhitespace()) | 294 if (!containsOnlyWhitespace()) |
| 300 return true; | 295 return true; |
| 301 | 296 |
| 302 if (!canHaveWhitespaceChildren(parent, this)) | 297 if (!canHaveWhitespaceChildren(parent)) |
| 303 return false; | 298 return false; |
| 304 | 299 |
| 305 // pre-wrap in SVG never makes layoutObject. | 300 // pre-wrap in SVG never makes layoutObject. |
| 306 if (style.whiteSpace() == PRE_WRAP && parent.isSVG()) | 301 if (style.whiteSpace() == PRE_WRAP && parent.isSVG()) |
| 307 return false; | 302 return false; |
| 308 | 303 |
| 309 // pre/pre-wrap/pre-line always make layoutObjects. | 304 // pre/pre-wrap/pre-line always make layoutObjects. |
| 310 if (style.preserveNewline()) | 305 if (style.preserveNewline()) |
| 311 return true; | 306 return true; |
| 312 | 307 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 result.appendLiteral("; "); | 456 result.appendLiteral("; "); |
| 462 result.appendLiteral("value="); | 457 result.appendLiteral("value="); |
| 463 result.append(s); | 458 result.append(s); |
| 464 } | 459 } |
| 465 | 460 |
| 466 strncpy(buffer, result.toString().utf8().data(), length - 1); | 461 strncpy(buffer, result.toString().utf8().data(), length - 1); |
| 467 } | 462 } |
| 468 #endif | 463 #endif |
| 469 | 464 |
| 470 } // namespace blink | 465 } // namespace blink |
| OLD | NEW |