| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after 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::Normal) | 141 if (style.whiteSpace() == EWhiteSpace::Normal) |
| 142 style.setWhiteSpace(EWhiteSpace::PreWrap); | 142 style.setWhiteSpace(EWhiteSpace::PreWrap); |
| 143 else if (style.whiteSpace() == EWhiteSpace::Nowrap) | 143 else if (style.whiteSpace() == EWhiteSpace::Nowrap) |
| 144 style.setWhiteSpace(EWhiteSpace::Pre); | 144 style.setWhiteSpace(EWhiteSpace::Pre); |
| (...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(OverflowVisible); | 313 style.setOverflowX(OverflowVisible); |
| 314 style.setOverflowY(OverflowVisible); | 314 style.setOverflowY(OverflowVisible); |
| 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 // FIXME: Don't support this mutation for pseudo styles like first-letter or | 324 // 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. | 325 // first-line, since it's not completely clear how that should work. |
| 326 if (style.display() == EDisplay::Inline && | 326 if (style.display() == EDisplay::Inline && |
| 327 style.styleType() == PseudoIdNone && | 327 style.styleType() == PseudoIdNone && |
| 328 style.getWritingMode() != parentStyle.getWritingMode()) | 328 style.getWritingMode() != layoutParentStyle.getWritingMode()) |
| 329 style.setDisplay(EDisplay::InlineBlock); | 329 style.setDisplay(EDisplay::InlineBlock); |
| 330 | 330 |
| 331 // After performing the display mutation, check table rows. We do not honor | 331 // After performing the display mutation, check table rows. We do not honor |
| 332 // position: relative table rows or cells. This has been established for | 332 // position: relative table rows or cells. This has been established for |
| 333 // position: relative in CSS2.1 (and caused a crash in containingBlock() on | 333 // position: relative in CSS2.1 (and caused a crash in containingBlock() on |
| 334 // some sites). | 334 // some sites). |
| 335 if ((style.display() == EDisplay::TableHeaderGroup || | 335 if ((style.display() == EDisplay::TableHeaderGroup || |
| 336 style.display() == EDisplay::TableRowGroup || | 336 style.display() == EDisplay::TableRowGroup || |
| 337 style.display() == EDisplay::TableFooterGroup || | 337 style.display() == EDisplay::TableFooterGroup || |
| 338 style.display() == EDisplay::TableRow) && | 338 style.display() == EDisplay::TableRow) && |
| (...skipping 12 matching lines...) Expand all Loading... |
| 351 // rows, and table columns. | 351 // rows, and table columns. |
| 352 // FIXME: Table cells should be allowed to be perpendicular or flipped with | 352 // FIXME: Table cells should be allowed to be perpendicular or flipped with |
| 353 // respect to the table, though. | 353 // respect to the table, though. |
| 354 if (style.display() == EDisplay::TableColumn || | 354 if (style.display() == EDisplay::TableColumn || |
| 355 style.display() == EDisplay::TableColumnGroup || | 355 style.display() == EDisplay::TableColumnGroup || |
| 356 style.display() == EDisplay::TableFooterGroup || | 356 style.display() == EDisplay::TableFooterGroup || |
| 357 style.display() == EDisplay::TableHeaderGroup || | 357 style.display() == EDisplay::TableHeaderGroup || |
| 358 style.display() == EDisplay::TableRow || | 358 style.display() == EDisplay::TableRow || |
| 359 style.display() == EDisplay::TableRowGroup || | 359 style.display() == EDisplay::TableRowGroup || |
| 360 style.display() == EDisplay::TableCell) | 360 style.display() == EDisplay::TableCell) |
| 361 style.setWritingMode(parentStyle.getWritingMode()); | 361 style.setWritingMode(layoutParentStyle.getWritingMode()); |
| 362 | 362 |
| 363 // FIXME: Since we don't support block-flow on flexible boxes yet, disallow | 363 // FIXME: Since we don't support block-flow on flexible boxes yet, disallow |
| 364 // setting of block-flow to anything other than TopToBottomWritingMode. | 364 // setting of block-flow to anything other than TopToBottomWritingMode. |
| 365 // https://bugs.webkit.org/show_bug.cgi?id=46418 - Flexible box support. | 365 // https://bugs.webkit.org/show_bug.cgi?id=46418 - Flexible box support. |
| 366 if (style.getWritingMode() != TopToBottomWritingMode && | 366 if (style.getWritingMode() != TopToBottomWritingMode && |
| 367 (style.display() == EDisplay::WebkitBox || | 367 (style.display() == EDisplay::WebkitBox || |
| 368 style.display() == EDisplay::WebkitInlineBox)) | 368 style.display() == EDisplay::WebkitInlineBox)) |
| 369 style.setWritingMode(TopToBottomWritingMode); | 369 style.setWritingMode(TopToBottomWritingMode); |
| 370 | 370 |
| 371 if (parentStyle.isDisplayFlexibleOrGridBox()) { | 371 if (layoutParentStyle.isDisplayFlexibleOrGridBox()) { |
| 372 style.setFloating(EFloat::None); | 372 style.setFloating(EFloat::None); |
| 373 style.setDisplay(equivalentBlockDisplay(style.display())); | 373 style.setDisplay(equivalentBlockDisplay(style.display())); |
| 374 | 374 |
| 375 // We want to count vertical percentage paddings/margins on flex items | 375 // We want to count vertical percentage paddings/margins on flex items |
| 376 // because our current behavior is different from the spec and we want to | 376 // because our current behavior is different from the spec and we want to |
| 377 // gather compatibility data. | 377 // gather compatibility data. |
| 378 if (style.paddingBefore().isPercentOrCalc() || | 378 if (style.paddingBefore().isPercentOrCalc() || |
| 379 style.paddingAfter().isPercentOrCalc()) | 379 style.paddingAfter().isPercentOrCalc()) |
| 380 UseCounter::count(document, UseCounter::FlexboxPercentagePaddingVertical); | 380 UseCounter::count(document, UseCounter::FlexboxPercentagePaddingVertical); |
| 381 if (style.marginBefore().isPercentOrCalc() || | 381 if (style.marginBefore().isPercentOrCalc() || |
| 382 style.marginAfter().isPercentOrCalc()) | 382 style.marginAfter().isPercentOrCalc()) |
| 383 UseCounter::count(document, UseCounter::FlexboxPercentageMarginVertical); | 383 UseCounter::count(document, UseCounter::FlexboxPercentageMarginVertical); |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 | 386 |
| 387 void StyleAdjuster::adjustComputedStyle(ComputedStyle& style, | 387 void StyleAdjuster::adjustComputedStyle(ComputedStyle& style, |
| 388 const ComputedStyle& parentStyle, | 388 const ComputedStyle& parentStyle, |
| 389 const ComputedStyle& layoutParentStyle, |
| 389 Element* element) { | 390 Element* element) { |
| 390 if (style.display() != EDisplay::None && | 391 if (style.display() != EDisplay::None && |
| 391 style.display() != EDisplay::Contents) { | 392 style.display() != EDisplay::Contents) { |
| 392 if (element && element->isHTMLElement()) | 393 if (element && element->isHTMLElement()) |
| 393 adjustStyleForHTMLElement(style, toHTMLElement(*element)); | 394 adjustStyleForHTMLElement(style, toHTMLElement(*element)); |
| 394 | 395 |
| 395 // Per the spec, position 'static' and 'relative' in the top layer compute | 396 // Per the spec, position 'static' and 'relative' in the top layer compute |
| 396 // to 'absolute'. | 397 // to 'absolute'. |
| 397 if (isInTopLayer(element, style) && (style.position() == StaticPosition || | 398 if (isInTopLayer(element, style) && (style.position() == StaticPosition || |
| 398 style.position() == RelativePosition)) | 399 style.position() == RelativePosition)) |
| 399 style.setPosition(AbsolutePosition); | 400 style.setPosition(AbsolutePosition); |
| 400 | 401 |
| 401 // Absolute/fixed positioned elements, floating elements and the document | 402 // Absolute/fixed positioned elements, floating elements and the document |
| 402 // element need block-like outside display. | 403 // element need block-like outside display. |
| 403 if (style.hasOutOfFlowPosition() || style.isFloating() || | 404 if (style.hasOutOfFlowPosition() || style.isFloating() || |
| 404 (element && element->document().documentElement() == element)) | 405 (element && element->document().documentElement() == element)) |
| 405 style.setDisplay(equivalentBlockDisplay(style.display())); | 406 style.setDisplay(equivalentBlockDisplay(style.display())); |
| 406 | 407 |
| 407 // We don't adjust the first letter style earlier because we may change the | 408 // We don't adjust the first letter style earlier because we may change the |
| 408 // display setting in adjustStyeForTagName() above. | 409 // display setting in adjustStyeForTagName() above. |
| 409 adjustStyleForFirstLetter(style); | 410 adjustStyleForFirstLetter(style); |
| 410 | 411 |
| 411 adjustStyleForDisplay(style, parentStyle, | 412 adjustStyleForDisplay(style, layoutParentStyle, |
| 412 element ? &element->document() : 0); | 413 element ? &element->document() : 0); |
| 413 | 414 |
| 414 // Paint containment forces a block formatting context, so we must coerce | 415 // Paint containment forces a block formatting context, so we must coerce |
| 415 // from inline. https://drafts.csswg.org/css-containment/#containment-paint | 416 // from inline. https://drafts.csswg.org/css-containment/#containment-paint |
| 416 if (style.containsPaint() && style.display() == EDisplay::Inline) | 417 if (style.containsPaint() && style.display() == EDisplay::Inline) |
| 417 style.setDisplay(EDisplay::Block); | 418 style.setDisplay(EDisplay::Block); |
| 418 } else { | 419 } else { |
| 419 adjustStyleForFirstLetter(style); | 420 adjustStyleForFirstLetter(style); |
| 420 } | 421 } |
| 421 | 422 |
| 422 if (element && element->hasCompositorProxy()) | 423 if (element && element->hasCompositorProxy()) |
| 423 style.setHasCompositorProxy(true); | 424 style.setHasCompositorProxy(true); |
| 424 | 425 |
| 425 // Make sure our z-index value is only applied if the object is positioned. | 426 // Make sure our z-index value is only applied if the object is positioned. |
| 426 if (style.position() == StaticPosition && | 427 if (style.position() == StaticPosition && |
| 427 !parentStyleForcesZIndexToCreateStackingContext(parentStyle)) { | 428 !layoutParentStyleForcesZIndexToCreateStackingContext( |
| 429 layoutParentStyle)) { |
| 428 style.setIsStackingContext(false); | 430 style.setIsStackingContext(false); |
| 429 // TODO(alancutter): Avoid altering z-index here. | 431 // TODO(alancutter): Avoid altering z-index here. |
| 430 if (!style.hasAutoZIndex()) | 432 if (!style.hasAutoZIndex()) |
| 431 style.setZIndex(0); | 433 style.setZIndex(0); |
| 432 } else if (!style.hasAutoZIndex()) { | 434 } else if (!style.hasAutoZIndex()) { |
| 433 style.setIsStackingContext(true); | 435 style.setIsStackingContext(true); |
| 434 } | 436 } |
| 435 | 437 |
| 436 if (style.overflowX() != OverflowVisible || | 438 if (style.overflowX() != OverflowVisible || |
| 437 style.overflowY() != OverflowVisible) | 439 style.overflowY() != OverflowVisible) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 style.setDisplay(EDisplay::Block); | 478 style.setDisplay(EDisplay::Block); |
| 477 | 479 |
| 478 // Columns don't apply to svg text elements. | 480 // Columns don't apply to svg text elements. |
| 479 if (isSVGTextElement(*element)) | 481 if (isSVGTextElement(*element)) |
| 480 style.clearMultiCol(); | 482 style.clearMultiCol(); |
| 481 } | 483 } |
| 482 adjustStyleForAlignment(style, parentStyle); | 484 adjustStyleForAlignment(style, parentStyle); |
| 483 } | 485 } |
| 484 | 486 |
| 485 } // namespace blink | 487 } // namespace blink |
| OLD | NEW |