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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPosition || propertyID == CSSPropertyWebkitMaskPosition); | 625 ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPosition || propertyID == CSSPropertyWebkitMaskPosition); |
626 positionList->append(cssValuePool().createValue(layer->backgroundXOrigin ())); | 626 positionList->append(cssValuePool().createValue(layer->backgroundXOrigin ())); |
627 } | 627 } |
628 positionList->append(zoomAdjustedPixelValueForLength(layer->xPosition(), sty le)); | 628 positionList->append(zoomAdjustedPixelValueForLength(layer->xPosition(), sty le)); |
629 if (layer->isBackgroundOriginSet()) { | 629 if (layer->isBackgroundOriginSet()) { |
630 ASSERT(propertyID == CSSPropertyBackgroundPosition || propertyID == CSSP ropertyWebkitMaskPosition); | 630 ASSERT(propertyID == CSSPropertyBackgroundPosition || propertyID == CSSP ropertyWebkitMaskPosition); |
631 positionList->append(cssValuePool().createValue(layer->backgroundYOrigin ())); | 631 positionList->append(cssValuePool().createValue(layer->backgroundYOrigin ())); |
632 } | 632 } |
633 positionList->append(zoomAdjustedPixelValueForLength(layer->yPosition(), sty le)); | 633 positionList->append(zoomAdjustedPixelValueForLength(layer->yPosition(), sty le)); |
634 return positionList.release(); | 634 return positionList.release(); |
635 | |
636 } | |
637 | |
638 static Length getOffsetComputedStyle(RenderStyle* style, CSSPropertyID propertyI D) { | |
eseidel
2013/04/12 07:33:50
Blink style moves { to the next line.
mithro-old
2013/04/26 05:30:38
Done.
| |
639 // If specified as a length, the corresponding absolute length; if specified as | |
640 // a percentage, the specified value; otherwise, 'auto'. Hence, we can just | |
641 // return the value in the style. | |
642 // | |
643 // See http://www.w3.org/TR/CSS21/cascade.html#computed-value | |
644 switch (propertyID) { | |
645 case CSSPropertyLeft: | |
646 return style->left(); | |
647 case CSSPropertyRight: | |
648 return style->right(); | |
649 case CSSPropertyTop: | |
650 return style->top(); | |
651 case CSSPropertyBottom: | |
652 return style->bottom(); | |
653 default: | |
654 ASSERT_NOT_REACHED(); | |
655 } | |
656 | |
657 return Length(0); | |
658 } | |
659 | |
660 static LayoutUnit getOffsetUsedStyleRelative(RenderBox* box, RenderStyle* style, CSSPropertyID propertyID) { | |
661 // For relatively positioned boxes, the offset is with respect to the top ed ges | |
662 // of the box itself. This ties together top/bottom and left/right to be | |
663 // opposites of each other. | |
664 // | |
665 // See http://www.w3.org/TR/CSS2/visuren.html#relative-positioning | |
666 // | |
667 // Specifically; | |
668 // Since boxes are not split or stretched as a result of 'left' or | |
669 // 'right', the used values are always: left = -right. | |
670 // and | |
671 // Since boxes are not split or stretched as a result of 'top' or | |
672 // 'bottom', the used values are always: top = -bottom. | |
673 switch (propertyID) { | |
674 case CSSPropertyTop: | |
675 return box->relativePositionOffset().height(); | |
676 case CSSPropertyBottom: | |
677 return -(box->relativePositionOffset().height()); | |
678 case CSSPropertyLeft: | |
679 return box->relativePositionOffset().width(); | |
680 case CSSPropertyRight: | |
681 return -(box->relativePositionOffset().width()); | |
682 default: | |
683 ASSERT_NOT_REACHED(); | |
684 } | |
685 | |
686 return 0; | |
687 } | |
688 | |
689 static LayoutUnit getOffsetUsedStyleAbsolute(RenderBlock* container, RenderBox* box, RenderStyle* style, CSSPropertyID propertyID) { | |
690 // For absoultely positioned boxes, the offset is how far an box's margin | |
691 // edge is offset below the edge of the box's containing block. | |
692 // See http://www.w3.org/TR/CSS2/visuren.html#position-props | |
693 | |
694 // Margins are included in Webkit's offsetTop/offsetLeft so we need to | |
695 // remove them here. | |
696 switch (propertyID) { | |
697 case CSSPropertyTop: | |
698 return box->offsetTop() - box->marginTop(); | |
699 case CSSPropertyBottom: | |
700 return container->clientHeight() - (box->offsetTop() + box->offsetHeight ()) - box->marginBottom(); | |
701 case CSSPropertyLeft: | |
702 return box->offsetLeft() - box->marginLeft(); | |
703 case CSSPropertyRight: | |
704 return container->clientWidth() - (box->offsetLeft() + box->offsetWidth( )) - box->marginRight(); | |
705 default: | |
706 ASSERT_NOT_REACHED(); | |
707 } | |
708 | |
709 return 0; | |
635 } | 710 } |
636 | 711 |
637 static PassRefPtr<CSSValue> getPositionOffsetValue(RenderStyle* style, CSSProper tyID propertyID, const RenderObject* renderer, RenderView* renderView) | 712 static PassRefPtr<CSSValue> getPositionOffsetValue(RenderStyle* style, CSSProper tyID propertyID, const RenderObject* renderer, RenderView* renderView) |
638 { | 713 { |
639 if (!style) | 714 if (!style) |
640 return 0; | 715 return 0; |
641 | 716 |
642 Length l; | 717 // If the element is not displayed; return the "computed value". |
643 switch (propertyID) { | 718 if (!renderView || !renderer || !renderer->isBox()) { |
644 case CSSPropertyLeft: | 719 return zoomAdjustedPixelValueForLength(getOffsetComputedStyle(style, pro pertyID), style); |
645 l = style->left(); | 720 |
646 break; | 721 // We should return the "used value". |
647 case CSSPropertyRight: | 722 } else { |
648 l = style->right(); | 723 LayoutUnit length = 0; |
649 break; | 724 RenderBox* box = toRenderBox(renderer); |
650 case CSSPropertyTop: | 725 RenderBlock* containingBlock = renderer->containingBlock(); |
651 l = style->top(); | 726 if (box->isRelPositioned() || !containingBlock) { |
652 break; | 727 length = getOffsetUsedStyleRelative(box, style, propertyID); |
653 case CSSPropertyBottom: | 728 } else { |
654 l = style->bottom(); | 729 length = getOffsetUsedStyleAbsolute(containingBlock, box, style, pro pertyID); |
655 break; | 730 } |
656 default: | 731 return zoomAdjustedPixelValue(length, style); |
657 return 0; | |
658 } | 732 } |
659 | |
660 if (l.isPercent() && renderer && renderer->isBox()) { | |
661 LayoutUnit containingBlockSize = (propertyID == CSSPropertyLeft || prope rtyID == CSSPropertyRight) ? | |
662 toRenderBox(renderer)->containingBlockLogicalWidthForContent() : | |
663 toRenderBox(renderer)->containingBlockLogicalHeightForContent(Exclud eMarginBorderPadding); | |
664 return zoomAdjustedPixelValue(valueForLength(l, containingBlockSize, 0), style); | |
665 } if (l.isViewportPercentage()) | |
666 return zoomAdjustedPixelValue(valueForLength(l, 0, renderView), style); | |
667 if (l.isAuto()) { | |
668 // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined. | |
669 // In other words if left is auto and right is not auto, then left's com puted value is negative right(). | |
670 // So we should get the opposite length unit and see if it is auto. | |
671 return cssValuePool().createValue(l); | |
672 } | |
673 | |
674 return zoomAdjustedPixelValueForLength(l, style); | |
675 } | 733 } |
676 | 734 |
677 PassRefPtr<CSSPrimitiveValue> CSSComputedStyleDeclaration::currentColorOrValidCo lor(RenderStyle* style, const Color& color) const | 735 PassRefPtr<CSSPrimitiveValue> CSSComputedStyleDeclaration::currentColorOrValidCo lor(RenderStyle* style, const Color& color) const |
678 { | 736 { |
679 // This function does NOT look at visited information, so that computed styl e doesn't expose that. | 737 // This function does NOT look at visited information, so that computed styl e doesn't expose that. |
680 if (!color.isValid()) | 738 if (!color.isValid()) |
681 return cssValuePool().createColorValue(style->color().rgb()); | 739 return cssValuePool().createColorValue(style->color().rgb()); |
682 return cssValuePool().createColorValue(color.rgb()); | 740 return cssValuePool().createColorValue(color.rgb()); |
683 } | 741 } |
684 | 742 |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1508 { | 1566 { |
1509 if (!m_node) | 1567 if (!m_node) |
1510 return 0; | 1568 return 0; |
1511 if (m_node->isElementNode()) { | 1569 if (m_node->isElementNode()) { |
1512 if (PseudoElement* element = toElement(m_node.get())->pseudoElement(m_ps eudoElementSpecifier)) | 1570 if (PseudoElement* element = toElement(m_node.get())->pseudoElement(m_ps eudoElementSpecifier)) |
1513 return element; | 1571 return element; |
1514 } | 1572 } |
1515 return m_node.get(); | 1573 return m_node.get(); |
1516 } | 1574 } |
1517 | 1575 |
1576 // In CSS 2.1 the returned object should actually contain the "used values" | |
1577 // rather then the "computed values" (despite the name saying otherwise). | |
1578 // | |
1579 // See; | |
1580 // http://www.w3.org/TR/CSS21/cascade.html#used-value | |
1581 // http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration | |
1582 // https://developer.mozilla.org/en-US/docs/DOM/window.getComputedStyle | |
1518 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropert yID propertyID, EUpdateLayout updateLayout) const | 1583 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropert yID propertyID, EUpdateLayout updateLayout) const |
1519 { | 1584 { |
1520 Node* styledNode = this->styledNode(); | 1585 Node* styledNode = this->styledNode(); |
1521 if (!styledNode) | 1586 if (!styledNode) |
1522 return 0; | 1587 return 0; |
1523 | 1588 |
1524 if (updateLayout) { | 1589 if (updateLayout) { |
1525 Document* document = styledNode->document(); | 1590 Document* document = styledNode->document(); |
1526 // FIXME: Some of these cases could be narrowed down or optimized better . | 1591 // FIXME: Some of these cases could be narrowed down or optimized better . |
1527 bool forceFullLayout = isLayoutDependentProperty(propertyID) | 1592 bool forceFullLayout = isLayoutDependentProperty(propertyID) |
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3012 static const CSSPropertyID propertiesAfterSlashSeperator[3] = { CSSPropertyB ackgroundSize, CSSPropertyBackgroundOrigin, | 3077 static const CSSPropertyID propertiesAfterSlashSeperator[3] = { CSSPropertyB ackgroundSize, CSSPropertyBackgroundOrigin, |
3013 CSSPropertyB ackgroundClip }; | 3078 CSSPropertyB ackgroundClip }; |
3014 | 3079 |
3015 RefPtr<CSSValueList> list = CSSValueList::createSlashSeparated(); | 3080 RefPtr<CSSValueList> list = CSSValueList::createSlashSeparated(); |
3016 list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShortha nd(propertiesBeforeSlashSeperator, WTF_ARRAY_LENGTH(propertiesBeforeSlashSeperat or)))); | 3081 list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShortha nd(propertiesBeforeSlashSeperator, WTF_ARRAY_LENGTH(propertiesBeforeSlashSeperat or)))); |
3017 list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShortha nd(propertiesAfterSlashSeperator, WTF_ARRAY_LENGTH(propertiesAfterSlashSeperator )))); | 3082 list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShortha nd(propertiesAfterSlashSeperator, WTF_ARRAY_LENGTH(propertiesAfterSlashSeperator )))); |
3018 return list.release(); | 3083 return list.release(); |
3019 } | 3084 } |
3020 | 3085 |
3021 } // namespace WebCore | 3086 } // namespace WebCore |
OLD | NEW |