OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. |
6 * All rights reserved. | 6 * All rights reserved. |
7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
10 * (http://www.torchmobile.com/) | 10 * (http://www.torchmobile.com/) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 return display; | 66 return display; |
67 case EDisplay::InlineTable: | 67 case EDisplay::InlineTable: |
68 return EDisplay::Table; | 68 return EDisplay::Table; |
69 case EDisplay::WebkitInlineBox: | 69 case EDisplay::WebkitInlineBox: |
70 return EDisplay::WebkitBox; | 70 return EDisplay::WebkitBox; |
71 case EDisplay::InlineFlex: | 71 case EDisplay::InlineFlex: |
72 return EDisplay::Flex; | 72 return EDisplay::Flex; |
73 case EDisplay::InlineGrid: | 73 case EDisplay::InlineGrid: |
74 return EDisplay::Grid; | 74 return EDisplay::Grid; |
75 | 75 |
| 76 case EDisplay::Contents: |
76 case EDisplay::Inline: | 77 case EDisplay::Inline: |
77 case EDisplay::InlineBlock: | 78 case EDisplay::InlineBlock: |
78 case EDisplay::TableRowGroup: | 79 case EDisplay::TableRowGroup: |
79 case EDisplay::TableHeaderGroup: | 80 case EDisplay::TableHeaderGroup: |
80 case EDisplay::TableFooterGroup: | 81 case EDisplay::TableFooterGroup: |
81 case EDisplay::TableRow: | 82 case EDisplay::TableRow: |
82 case EDisplay::TableColumnGroup: | 83 case EDisplay::TableColumnGroup: |
83 case EDisplay::TableColumn: | 84 case EDisplay::TableColumn: |
84 case EDisplay::TableCell: | 85 case EDisplay::TableCell: |
85 case EDisplay::TableCaption: | 86 case EDisplay::TableCaption: |
86 return EDisplay::Block; | 87 return EDisplay::Block; |
87 case EDisplay::None: | 88 case EDisplay::None: |
88 case EDisplay::Contents: | |
89 ASSERT_NOT_REACHED(); | 89 ASSERT_NOT_REACHED(); |
90 return display; | 90 return display; |
91 } | 91 } |
92 ASSERT_NOT_REACHED(); | 92 ASSERT_NOT_REACHED(); |
93 return EDisplay::Block; | 93 return EDisplay::Block; |
94 } | 94 } |
95 | 95 |
96 static bool isOutermostSVGElement(const Element* element) { | 96 static bool isOutermostSVGElement(const Element* element) { |
97 return element && element->isSVGElement() && | 97 return element && element->isSVGElement() && |
98 toSVGElement(*element).isOutermostSVGSVGElement(); | 98 toSVGElement(*element).isOutermostSVGSVGElement(); |
(...skipping 23 matching lines...) Expand all Loading... |
122 (isHTMLFontElement(element) || isHTMLAnchorElement(element)); | 122 (isHTMLFontElement(element) || isHTMLAnchorElement(element)); |
123 } | 123 } |
124 | 124 |
125 // FIXME: This helper is only needed because pseudoStyleForElement passes a null | 125 // FIXME: This helper is only needed because pseudoStyleForElement passes a null |
126 // element to adjustComputedStyle, so we can't just use element->isInTopLayer(). | 126 // element to adjustComputedStyle, so we can't just use element->isInTopLayer(). |
127 static bool isInTopLayer(const Element* element, const ComputedStyle& style) { | 127 static bool isInTopLayer(const Element* element, const ComputedStyle& style) { |
128 return (element && element->isInTopLayer()) || | 128 return (element && element->isInTopLayer()) || |
129 style.styleType() == PseudoIdBackdrop; | 129 style.styleType() == PseudoIdBackdrop; |
130 } | 130 } |
131 | 131 |
132 static bool parentStyleForcesZIndexToCreateStackingContext( | 132 static bool layoutParentStyleForcesZIndexToCreateStackingContext( |
133 const ComputedStyle& parentStyle) { | 133 const ComputedStyle& layoutParentStyle) { |
134 return parentStyle.isDisplayFlexibleOrGridBox(); | 134 return layoutParentStyle.isDisplayFlexibleOrGridBox(); |
135 } | 135 } |
136 | 136 |
137 void StyleAdjuster::adjustStyleForEditing(ComputedStyle& style) { | 137 void StyleAdjuster::adjustStyleForEditing(ComputedStyle& style) { |
138 if (style.userModify() != READ_WRITE_PLAINTEXT_ONLY) | 138 if (style.userModify() != READ_WRITE_PLAINTEXT_ONLY) |
139 return; | 139 return; |
140 // Collapsing whitespace is harmful in plain-text editing. | 140 // Collapsing whitespace is harmful in plain-text editing. |
141 if (style.whiteSpace() == EWhiteSpace::kNormal) | 141 if (style.whiteSpace() == EWhiteSpace::kNormal) |
142 style.setWhiteSpace(EWhiteSpace::kPreWrap); | 142 style.setWhiteSpace(EWhiteSpace::kPreWrap); |
143 else if (style.whiteSpace() == EWhiteSpace::kNowrap) | 143 else if (style.whiteSpace() == EWhiteSpace::kNowrap) |
144 style.setWhiteSpace(EWhiteSpace::kPre); | 144 style.setWhiteSpace(EWhiteSpace::kPre); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 309 } |
310 | 310 |
311 // Menulists should have visible overflow | 311 // Menulists should have visible overflow |
312 if (style.appearance() == MenulistPart) { | 312 if (style.appearance() == MenulistPart) { |
313 style.setOverflowX(EOverflow::Visible); | 313 style.setOverflowX(EOverflow::Visible); |
314 style.setOverflowY(EOverflow::Visible); | 314 style.setOverflowY(EOverflow::Visible); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 static void adjustStyleForDisplay(ComputedStyle& style, | 318 static void adjustStyleForDisplay(ComputedStyle& style, |
319 const ComputedStyle& parentStyle, | 319 const ComputedStyle& layoutParentStyle, |
320 Document* document) { | 320 Document* document) { |
321 if (style.display() == EDisplay::Block && !style.isFloating()) | 321 if (style.display() == EDisplay::Block && !style.isFloating()) |
322 return; | 322 return; |
323 | 323 |
| 324 if (style.display() == EDisplay::Contents) |
| 325 return; |
| 326 |
324 // FIXME: Don't support this mutation for pseudo styles like first-letter or | 327 // FIXME: Don't support this mutation for pseudo styles like first-letter or |
325 // first-line, since it's not completely clear how that should work. | 328 // first-line, since it's not completely clear how that should work. |
326 if (style.display() == EDisplay::Inline && | 329 if (style.display() == EDisplay::Inline && |
327 style.styleType() == PseudoIdNone && | 330 style.styleType() == PseudoIdNone && |
328 style.getWritingMode() != parentStyle.getWritingMode()) | 331 style.getWritingMode() != layoutParentStyle.getWritingMode()) |
329 style.setDisplay(EDisplay::InlineBlock); | 332 style.setDisplay(EDisplay::InlineBlock); |
330 | 333 |
331 // After performing the display mutation, check table rows. We do not honor | 334 // After performing the display mutation, check table rows. We do not honor |
332 // position: relative table rows. This has been established for position: | 335 // position: relative table rows. This has been established for position: |
333 // relative in CSS2.1 (and caused a crash in containingBlock() on some sites). | 336 // relative in CSS2.1 (and caused a crash in containingBlock() on some sites). |
334 if ((style.display() == EDisplay::TableHeaderGroup || | 337 if ((style.display() == EDisplay::TableHeaderGroup || |
335 style.display() == EDisplay::TableRowGroup || | 338 style.display() == EDisplay::TableRowGroup || |
336 style.display() == EDisplay::TableFooterGroup || | 339 style.display() == EDisplay::TableFooterGroup || |
337 style.display() == EDisplay::TableRow) && | 340 style.display() == EDisplay::TableRow) && |
338 style.position() == RelativePosition) | 341 style.position() == RelativePosition) |
(...skipping 11 matching lines...) Expand all Loading... |
350 // rows, and table columns. | 353 // rows, and table columns. |
351 // FIXME: Table cells should be allowed to be perpendicular or flipped with | 354 // FIXME: Table cells should be allowed to be perpendicular or flipped with |
352 // respect to the table, though. | 355 // respect to the table, though. |
353 if (style.display() == EDisplay::TableColumn || | 356 if (style.display() == EDisplay::TableColumn || |
354 style.display() == EDisplay::TableColumnGroup || | 357 style.display() == EDisplay::TableColumnGroup || |
355 style.display() == EDisplay::TableFooterGroup || | 358 style.display() == EDisplay::TableFooterGroup || |
356 style.display() == EDisplay::TableHeaderGroup || | 359 style.display() == EDisplay::TableHeaderGroup || |
357 style.display() == EDisplay::TableRow || | 360 style.display() == EDisplay::TableRow || |
358 style.display() == EDisplay::TableRowGroup || | 361 style.display() == EDisplay::TableRowGroup || |
359 style.display() == EDisplay::TableCell) | 362 style.display() == EDisplay::TableCell) |
360 style.setWritingMode(parentStyle.getWritingMode()); | 363 style.setWritingMode(layoutParentStyle.getWritingMode()); |
361 | 364 |
362 // FIXME: Since we don't support block-flow on flexible boxes yet, disallow | 365 // FIXME: Since we don't support block-flow on flexible boxes yet, disallow |
363 // setting of block-flow to anything other than TopToBottomWritingMode. | 366 // setting of block-flow to anything other than TopToBottomWritingMode. |
364 // https://bugs.webkit.org/show_bug.cgi?id=46418 - Flexible box support. | 367 // https://bugs.webkit.org/show_bug.cgi?id=46418 - Flexible box support. |
365 if (style.getWritingMode() != WritingMode::kHorizontalTb && | 368 if (style.getWritingMode() != WritingMode::kHorizontalTb && |
366 (style.display() == EDisplay::WebkitBox || | 369 (style.display() == EDisplay::WebkitBox || |
367 style.display() == EDisplay::WebkitInlineBox)) | 370 style.display() == EDisplay::WebkitInlineBox)) |
368 style.setWritingMode(WritingMode::kHorizontalTb); | 371 style.setWritingMode(WritingMode::kHorizontalTb); |
369 | 372 |
370 if (parentStyle.isDisplayFlexibleOrGridBox()) { | 373 if (layoutParentStyle.isDisplayFlexibleOrGridBox()) { |
371 style.setFloating(EFloat::kNone); | 374 style.setFloating(EFloat::kNone); |
372 style.setDisplay(equivalentBlockDisplay(style.display())); | 375 style.setDisplay(equivalentBlockDisplay(style.display())); |
373 | 376 |
374 // We want to count vertical percentage paddings/margins on flex items | 377 // We want to count vertical percentage paddings/margins on flex items |
375 // because our current behavior is different from the spec and we want to | 378 // because our current behavior is different from the spec and we want to |
376 // gather compatibility data. | 379 // gather compatibility data. |
377 if (style.paddingBefore().isPercentOrCalc() || | 380 if (style.paddingBefore().isPercentOrCalc() || |
378 style.paddingAfter().isPercentOrCalc()) | 381 style.paddingAfter().isPercentOrCalc()) |
379 UseCounter::count(document, UseCounter::FlexboxPercentagePaddingVertical); | 382 UseCounter::count(document, UseCounter::FlexboxPercentagePaddingVertical); |
380 if (style.marginBefore().isPercentOrCalc() || | 383 if (style.marginBefore().isPercentOrCalc() || |
381 style.marginAfter().isPercentOrCalc()) | 384 style.marginAfter().isPercentOrCalc()) |
382 UseCounter::count(document, UseCounter::FlexboxPercentageMarginVertical); | 385 UseCounter::count(document, UseCounter::FlexboxPercentageMarginVertical); |
383 } | 386 } |
384 } | 387 } |
385 | 388 |
386 void StyleAdjuster::adjustComputedStyle(ComputedStyle& style, | 389 void StyleAdjuster::adjustComputedStyle(ComputedStyle& style, |
387 const ComputedStyle& parentStyle, | 390 const ComputedStyle& parentStyle, |
| 391 const ComputedStyle& layoutParentStyle, |
388 Element* element) { | 392 Element* element) { |
389 if (style.display() != EDisplay::None && | 393 if (style.display() != EDisplay::None) { |
390 style.display() != EDisplay::Contents) { | |
391 if (element && element->isHTMLElement()) | 394 if (element && element->isHTMLElement()) |
392 adjustStyleForHTMLElement(style, toHTMLElement(*element)); | 395 adjustStyleForHTMLElement(style, toHTMLElement(*element)); |
393 | 396 |
394 // Per the spec, position 'static' and 'relative' in the top layer compute | 397 // Per the spec, position 'static' and 'relative' in the top layer compute |
395 // to 'absolute'. | 398 // to 'absolute'. |
396 if (isInTopLayer(element, style) && (style.position() == StaticPosition || | 399 if (isInTopLayer(element, style) && (style.position() == StaticPosition || |
397 style.position() == RelativePosition)) | 400 style.position() == RelativePosition)) |
398 style.setPosition(AbsolutePosition); | 401 style.setPosition(AbsolutePosition); |
399 | 402 |
400 // Absolute/fixed positioned elements, floating elements and the document | 403 // Absolute/fixed positioned elements, floating elements and the document |
401 // element need block-like outside display. | 404 // element need block-like outside display. |
402 if (style.hasOutOfFlowPosition() || style.isFloating() || | 405 if (style.display() != EDisplay::Contents && |
403 (element && element->document().documentElement() == element)) | 406 (style.hasOutOfFlowPosition() || style.isFloating())) |
| 407 style.setDisplay(equivalentBlockDisplay(style.display())); |
| 408 |
| 409 if (element && element->document().documentElement() == element) |
404 style.setDisplay(equivalentBlockDisplay(style.display())); | 410 style.setDisplay(equivalentBlockDisplay(style.display())); |
405 | 411 |
406 // We don't adjust the first letter style earlier because we may change the | 412 // We don't adjust the first letter style earlier because we may change the |
407 // display setting in adjustStyeForTagName() above. | 413 // display setting in adjustStyeForTagName() above. |
408 adjustStyleForFirstLetter(style); | 414 adjustStyleForFirstLetter(style); |
409 | 415 |
410 adjustStyleForDisplay(style, parentStyle, | 416 adjustStyleForDisplay(style, layoutParentStyle, |
411 element ? &element->document() : 0); | 417 element ? &element->document() : 0); |
412 | 418 |
413 // Paint containment forces a block formatting context, so we must coerce | 419 // Paint containment forces a block formatting context, so we must coerce |
414 // from inline. https://drafts.csswg.org/css-containment/#containment-paint | 420 // from inline. https://drafts.csswg.org/css-containment/#containment-paint |
415 if (style.containsPaint() && style.display() == EDisplay::Inline) | 421 if (style.containsPaint() && style.display() == EDisplay::Inline) |
416 style.setDisplay(EDisplay::Block); | 422 style.setDisplay(EDisplay::Block); |
417 } else { | 423 } else { |
418 adjustStyleForFirstLetter(style); | 424 adjustStyleForFirstLetter(style); |
419 } | 425 } |
420 | 426 |
421 if (element && element->hasCompositorProxy()) | 427 if (element && element->hasCompositorProxy()) |
422 style.setHasCompositorProxy(true); | 428 style.setHasCompositorProxy(true); |
423 | 429 |
424 // Make sure our z-index value is only applied if the object is positioned. | 430 // Make sure our z-index value is only applied if the object is positioned. |
425 if (style.position() == StaticPosition && | 431 if (style.position() == StaticPosition && |
426 !parentStyleForcesZIndexToCreateStackingContext(parentStyle)) { | 432 !layoutParentStyleForcesZIndexToCreateStackingContext( |
| 433 layoutParentStyle)) { |
427 style.setIsStackingContext(false); | 434 style.setIsStackingContext(false); |
428 // TODO(alancutter): Avoid altering z-index here. | 435 // TODO(alancutter): Avoid altering z-index here. |
429 if (!style.hasAutoZIndex()) | 436 if (!style.hasAutoZIndex()) |
430 style.setZIndex(0); | 437 style.setZIndex(0); |
431 } else if (!style.hasAutoZIndex()) { | 438 } else if (!style.hasAutoZIndex()) { |
432 style.setIsStackingContext(true); | 439 style.setIsStackingContext(true); |
433 } | 440 } |
434 | 441 |
435 if (style.overflowX() != EOverflow::Visible || | 442 if (style.overflowX() != EOverflow::Visible || |
436 style.overflowY() != EOverflow::Visible) | 443 style.overflowY() != EOverflow::Visible) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 style.setDisplay(EDisplay::Block); | 482 style.setDisplay(EDisplay::Block); |
476 | 483 |
477 // Columns don't apply to svg text elements. | 484 // Columns don't apply to svg text elements. |
478 if (isSVGTextElement(*element)) | 485 if (isSVGTextElement(*element)) |
479 style.clearMultiCol(); | 486 style.clearMultiCol(); |
480 } | 487 } |
481 adjustStyleForAlignment(style, parentStyle); | 488 adjustStyleForAlignment(style, parentStyle); |
482 } | 489 } |
483 | 490 |
484 } // namespace blink | 491 } // namespace blink |
OLD | NEW |