| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004 Zack Rusin <zack@kde.org> | 2 * Copyright (C) 2004 Zack Rusin <zack@kde.org> |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. |
| 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> | 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
| 6 * Copyright (C) 2011 Sencha, Inc. All rights reserved. | 6 * Copyright (C) 2011 Sencha, Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 436 |
| 437 static void logUnimplementedPropertyID(CSSPropertyID propertyID) | 437 static void logUnimplementedPropertyID(CSSPropertyID propertyID) |
| 438 { | 438 { |
| 439 DEFINE_STATIC_LOCAL(HashSet<CSSPropertyID>, propertyIDSet, ()); | 439 DEFINE_STATIC_LOCAL(HashSet<CSSPropertyID>, propertyIDSet, ()); |
| 440 if (!propertyIDSet.add(propertyID).isNewEntry) | 440 if (!propertyIDSet.add(propertyID).isNewEntry) |
| 441 return; | 441 return; |
| 442 | 442 |
| 443 WTF_LOG_ERROR("WebKit does not yet implement getComputedStyle for '%s'.", ge
tPropertyName(propertyID)); | 443 WTF_LOG_ERROR("WebKit does not yet implement getComputedStyle for '%s'.", ge
tPropertyName(propertyID)); |
| 444 } | 444 } |
| 445 | 445 |
| 446 static bool isLayoutDependent(CSSPropertyID propertyID, const ComputedStyle* sty
le, LayoutObject* renderer) | 446 static bool isLayoutDependent(CSSPropertyID propertyID, const ComputedStyle* sty
le, LayoutObject* layoutObject) |
| 447 { | 447 { |
| 448 // Some properties only depend on layout in certain conditions which | 448 // Some properties only depend on layout in certain conditions which |
| 449 // are specified in the main switch statement below. So we can avoid | 449 // are specified in the main switch statement below. So we can avoid |
| 450 // forcing layout in those conditions. The conditions in this switch | 450 // forcing layout in those conditions. The conditions in this switch |
| 451 // statement must remain in sync with the conditions in the main switch. | 451 // statement must remain in sync with the conditions in the main switch. |
| 452 // FIXME: Some of these cases could be narrowed down or optimized better. | 452 // FIXME: Some of these cases could be narrowed down or optimized better. |
| 453 switch (propertyID) { | 453 switch (propertyID) { |
| 454 case CSSPropertyBottom: | 454 case CSSPropertyBottom: |
| 455 case CSSPropertyGridTemplateColumns: | 455 case CSSPropertyGridTemplateColumns: |
| 456 case CSSPropertyGridTemplateRows: | 456 case CSSPropertyGridTemplateRows: |
| 457 case CSSPropertyHeight: | 457 case CSSPropertyHeight: |
| 458 case CSSPropertyLeft: | 458 case CSSPropertyLeft: |
| 459 case CSSPropertyRight: | 459 case CSSPropertyRight: |
| 460 case CSSPropertyTop: | 460 case CSSPropertyTop: |
| 461 case CSSPropertyPerspectiveOrigin: | 461 case CSSPropertyPerspectiveOrigin: |
| 462 case CSSPropertyTransform: | 462 case CSSPropertyTransform: |
| 463 case CSSPropertyTransformOrigin: | 463 case CSSPropertyTransformOrigin: |
| 464 case CSSPropertyMotionPath: | 464 case CSSPropertyMotionPath: |
| 465 case CSSPropertyMotionOffset: | 465 case CSSPropertyMotionOffset: |
| 466 case CSSPropertyMotionRotation: | 466 case CSSPropertyMotionRotation: |
| 467 case CSSPropertyWidth: | 467 case CSSPropertyWidth: |
| 468 case CSSPropertyWebkitFilter: | 468 case CSSPropertyWebkitFilter: |
| 469 case CSSPropertyX: | 469 case CSSPropertyX: |
| 470 case CSSPropertyY: | 470 case CSSPropertyY: |
| 471 case CSSPropertyRx: | 471 case CSSPropertyRx: |
| 472 case CSSPropertyRy: | 472 case CSSPropertyRy: |
| 473 return true; | 473 return true; |
| 474 case CSSPropertyMargin: | 474 case CSSPropertyMargin: |
| 475 return renderer && renderer->isBox() && (!style || !style->marginBottom(
).isFixed() || !style->marginTop().isFixed() || !style->marginLeft().isFixed() |
| !style->marginRight().isFixed()); | 475 return layoutObject && layoutObject->isBox() |
| 476 && (!style || !style->marginBottom().isFixed() || !style->marginTop(
).isFixed() |
| 477 || !style->marginLeft().isFixed() || !style->marginRight().isFix
ed()); |
| 476 case CSSPropertyMarginLeft: | 478 case CSSPropertyMarginLeft: |
| 477 return renderer && renderer->isBox() && (!style || !style->marginLeft().
isFixed()); | 479 return layoutObject && layoutObject->isBox() && (!style || !style->margi
nLeft().isFixed()); |
| 478 case CSSPropertyMarginRight: | 480 case CSSPropertyMarginRight: |
| 479 return renderer && renderer->isBox() && (!style || !style->marginRight()
.isFixed()); | 481 return layoutObject && layoutObject->isBox() && (!style || !style->margi
nRight().isFixed()); |
| 480 case CSSPropertyMarginTop: | 482 case CSSPropertyMarginTop: |
| 481 return renderer && renderer->isBox() && (!style || !style->marginTop().i
sFixed()); | 483 return layoutObject && layoutObject->isBox() && (!style || !style->margi
nTop().isFixed()); |
| 482 case CSSPropertyMarginBottom: | 484 case CSSPropertyMarginBottom: |
| 483 return renderer && renderer->isBox() && (!style || !style->marginBottom(
).isFixed()); | 485 return layoutObject && layoutObject->isBox() && (!style || !style->margi
nBottom().isFixed()); |
| 484 case CSSPropertyPadding: | 486 case CSSPropertyPadding: |
| 485 return renderer && renderer->isBox() && (!style || !style->paddingBottom
().isFixed() || !style->paddingTop().isFixed() || !style->paddingLeft().isFixed(
) || !style->paddingRight().isFixed()); | 487 return layoutObject && layoutObject->isBox() |
| 488 && (!style || !style->paddingBottom().isFixed() || !style->paddingTo
p().isFixed() |
| 489 || !style->paddingLeft().isFixed() || !style->paddingRight().isF
ixed()); |
| 486 case CSSPropertyPaddingBottom: | 490 case CSSPropertyPaddingBottom: |
| 487 return renderer && renderer->isBox() && (!style || !style->paddingBottom
().isFixed()); | 491 return layoutObject && layoutObject->isBox() && (!style || !style->paddi
ngBottom().isFixed()); |
| 488 case CSSPropertyPaddingLeft: | 492 case CSSPropertyPaddingLeft: |
| 489 return renderer && renderer->isBox() && (!style || !style->paddingLeft()
.isFixed()); | 493 return layoutObject && layoutObject->isBox() && (!style || !style->paddi
ngLeft().isFixed()); |
| 490 case CSSPropertyPaddingRight: | 494 case CSSPropertyPaddingRight: |
| 491 return renderer && renderer->isBox() && (!style || !style->paddingRight(
).isFixed()); | 495 return layoutObject && layoutObject->isBox() && (!style || !style->paddi
ngRight().isFixed()); |
| 492 case CSSPropertyPaddingTop: | 496 case CSSPropertyPaddingTop: |
| 493 return renderer && renderer->isBox() && (!style || !style->paddingTop().
isFixed()); | 497 return layoutObject && layoutObject->isBox() && (!style || !style->paddi
ngTop().isFixed()); |
| 494 default: | 498 default: |
| 495 return false; | 499 return false; |
| 496 } | 500 } |
| 497 } | 501 } |
| 498 | 502 |
| 499 const ComputedStyle* CSSComputedStyleDeclaration::computeComputedStyle() const | 503 const ComputedStyle* CSSComputedStyleDeclaration::computeComputedStyle() const |
| 500 { | 504 { |
| 501 Node* styledNode = this->styledNode(); | 505 Node* styledNode = this->styledNode(); |
| 502 ASSERT(styledNode); | 506 ASSERT(styledNode); |
| 503 return styledNode->ensureComputedStyle(styledNode->isPseudoElement() ? NOPSE
UDO : m_pseudoElementSpecifier); | 507 return styledNode->ensureComputedStyle(styledNode->isPseudoElement() ? NOPSE
UDO : m_pseudoElementSpecifier); |
| 504 } | 508 } |
| 505 | 509 |
| 506 Node* CSSComputedStyleDeclaration::styledNode() const | 510 Node* CSSComputedStyleDeclaration::styledNode() const |
| 507 { | 511 { |
| 508 if (!m_node) | 512 if (!m_node) |
| 509 return 0; | 513 return 0; |
| 510 if (m_node->isElementNode()) { | 514 if (m_node->isElementNode()) { |
| 511 if (PseudoElement* element = toElement(m_node)->pseudoElement(m_pseudoEl
ementSpecifier)) | 515 if (PseudoElement* element = toElement(m_node)->pseudoElement(m_pseudoEl
ementSpecifier)) |
| 512 return element; | 516 return element; |
| 513 } | 517 } |
| 514 return m_node.get(); | 518 return m_node.get(); |
| 515 } | 519 } |
| 516 | 520 |
| 517 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValu
e(CSSPropertyID propertyID) const | 521 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValu
e(CSSPropertyID propertyID) const |
| 518 { | 522 { |
| 519 Node* styledNode = this->styledNode(); | 523 Node* styledNode = this->styledNode(); |
| 520 if (!styledNode) | 524 if (!styledNode) |
| 521 return nullptr; | 525 return nullptr; |
| 522 LayoutObject* renderer = styledNode->layoutObject(); | 526 LayoutObject* layoutObject = styledNode->layoutObject(); |
| 523 const ComputedStyle* style; | 527 const ComputedStyle* style; |
| 524 | 528 |
| 525 Document& document = styledNode->document(); | 529 Document& document = styledNode->document(); |
| 526 | 530 |
| 527 // A timing update may be required if a compositor animation is running. | 531 // A timing update may be required if a compositor animation is running. |
| 528 DocumentAnimations::updateAnimationTimingForGetComputedStyle(*styledNode, pr
opertyID); | 532 DocumentAnimations::updateAnimationTimingForGetComputedStyle(*styledNode, pr
opertyID); |
| 529 | 533 |
| 530 document.updateRenderTreeForNodeIfNeeded(styledNode); | 534 document.updateRenderTreeForNodeIfNeeded(styledNode); |
| 531 | 535 |
| 532 // The style recalc could have caused the styled node to be discarded or rep
laced | 536 // The style recalc could have caused the styled node to be discarded or rep
laced |
| 533 // if it was a PseudoElement so we need to update it. | 537 // if it was a PseudoElement so we need to update it. |
| 534 styledNode = this->styledNode(); | 538 styledNode = this->styledNode(); |
| 535 renderer = styledNode->layoutObject(); | 539 layoutObject = styledNode->layoutObject(); |
| 536 | 540 |
| 537 style = computeComputedStyle(); | 541 style = computeComputedStyle(); |
| 538 | 542 |
| 539 bool forceFullLayout = isLayoutDependent(propertyID, style, renderer) | 543 bool forceFullLayout = isLayoutDependent(propertyID, style, layoutObject) |
| 540 || styledNode->isInShadowTree() | 544 || styledNode->isInShadowTree() |
| 541 || (document.ownerElement() && document.ensureStyleResolver().hasViewpor
tDependentMediaQueries()); | 545 || (document.ownerElement() && document.ensureStyleResolver().hasViewpor
tDependentMediaQueries()); |
| 542 | 546 |
| 543 if (forceFullLayout) { | 547 if (forceFullLayout) { |
| 544 document.updateLayoutIgnorePendingStylesheets(); | 548 document.updateLayoutIgnorePendingStylesheets(); |
| 545 styledNode = this->styledNode(); | 549 styledNode = this->styledNode(); |
| 546 style = computeComputedStyle(); | 550 style = computeComputedStyle(); |
| 547 renderer = styledNode->layoutObject(); | 551 layoutObject = styledNode->layoutObject(); |
| 548 } | 552 } |
| 549 | 553 |
| 550 if (!style) | 554 if (!style) |
| 551 return nullptr; | 555 return nullptr; |
| 552 | 556 |
| 553 RefPtrWillBeRawPtr<CSSValue> value = ComputedStyleCSSValueMapping::get(prope
rtyID, *style, renderer, styledNode, m_allowVisitedStyle); | 557 RefPtrWillBeRawPtr<CSSValue> value = ComputedStyleCSSValueMapping::get(prope
rtyID, *style, layoutObject, styledNode, m_allowVisitedStyle); |
| 554 if (value) | 558 if (value) |
| 555 return value; | 559 return value; |
| 556 | 560 |
| 557 logUnimplementedPropertyID(propertyID); | 561 logUnimplementedPropertyID(propertyID); |
| 558 return nullptr; | 562 return nullptr; |
| 559 } | 563 } |
| 560 | 564 |
| 561 String CSSComputedStyleDeclaration::getPropertyValue(CSSPropertyID propertyID) c
onst | 565 String CSSComputedStyleDeclaration::getPropertyValue(CSSPropertyID propertyID) c
onst |
| 562 { | 566 { |
| 563 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); | 567 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 exceptionState.throwDOMException(NoModificationAllowedError, "These styles a
re computed, and therefore the '" + getPropertyNameString(id) + "' property is r
ead-only."); | 675 exceptionState.throwDOMException(NoModificationAllowedError, "These styles a
re computed, and therefore the '" + getPropertyNameString(id) + "' property is r
ead-only."); |
| 672 } | 676 } |
| 673 | 677 |
| 674 DEFINE_TRACE(CSSComputedStyleDeclaration) | 678 DEFINE_TRACE(CSSComputedStyleDeclaration) |
| 675 { | 679 { |
| 676 visitor->trace(m_node); | 680 visitor->trace(m_node); |
| 677 CSSStyleDeclaration::trace(visitor); | 681 CSSStyleDeclaration::trace(visitor); |
| 678 } | 682 } |
| 679 | 683 |
| 680 } // namespace blink | 684 } // namespace blink |
| OLD | NEW |