| 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 * (C) 2001 Peter Kelly (pmk@post.com) | 4 * (C) 2001 Peter Kelly (pmk@post.com) |
| 5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 6 * (C) 2007 David Smith (catfish.man@gmail.com) | 6 * (C) 2007 David Smith (catfish.man@gmail.com) |
| 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. | 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. |
| 8 * (C) 2007 Eric Seidel (eric@webkit.org) | 8 * (C) 2007 Eric Seidel (eric@webkit.org) |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * Boston, MA 02110-1301, USA. | 23 * Boston, MA 02110-1301, USA. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "sky/engine/core/dom/Element.h" | 26 #include "sky/engine/core/dom/Element.h" |
| 27 | 27 |
| 28 #include "gen/sky/core/CSSValueKeywords.h" | 28 #include "gen/sky/core/CSSValueKeywords.h" |
| 29 #include "gen/sky/core/HTMLNames.h" | 29 #include "gen/sky/core/HTMLNames.h" |
| 30 #include "gen/sky/platform/RuntimeEnabledFeatures.h" | 30 #include "gen/sky/platform/RuntimeEnabledFeatures.h" |
| 31 #include "sky/engine/bindings/exception_messages.h" | 31 #include "sky/engine/bindings/exception_messages.h" |
| 32 #include "sky/engine/bindings/exception_state.h" | 32 #include "sky/engine/bindings/exception_state.h" |
| 33 #include "sky/engine/core/animation/AnimationTimeline.h" | |
| 34 #include "sky/engine/core/animation/css/CSSAnimations.h" | |
| 35 #include "sky/engine/core/css/CSSStyleSheet.h" | 33 #include "sky/engine/core/css/CSSStyleSheet.h" |
| 36 #include "sky/engine/core/css/CSSValuePool.h" | 34 #include "sky/engine/core/css/CSSValuePool.h" |
| 37 #include "sky/engine/core/css/PropertySetCSSStyleDeclaration.h" | 35 #include "sky/engine/core/css/PropertySetCSSStyleDeclaration.h" |
| 38 #include "sky/engine/core/css/StylePropertySet.h" | 36 #include "sky/engine/core/css/StylePropertySet.h" |
| 39 #include "sky/engine/core/css/parser/BisonCSSParser.h" | 37 #include "sky/engine/core/css/parser/BisonCSSParser.h" |
| 40 #include "sky/engine/core/css/resolver/StyleResolver.h" | 38 #include "sky/engine/core/css/resolver/StyleResolver.h" |
| 41 #include "sky/engine/core/dom/Attr.h" | 39 #include "sky/engine/core/dom/Attr.h" |
| 42 #include "sky/engine/core/dom/ClientRect.h" | 40 #include "sky/engine/core/dom/ClientRect.h" |
| 43 #include "sky/engine/core/dom/ClientRectList.h" | 41 #include "sky/engine/core/dom/ClientRectList.h" |
| 44 #include "sky/engine/core/dom/DOMTokenList.h" | 42 #include "sky/engine/core/dom/DOMTokenList.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 188 } |
| 191 | 189 |
| 192 void Element::setBooleanAttribute(const QualifiedName& name, bool value) | 190 void Element::setBooleanAttribute(const QualifiedName& name, bool value) |
| 193 { | 191 { |
| 194 if (value) | 192 if (value) |
| 195 setAttribute(name, emptyAtom); | 193 setAttribute(name, emptyAtom); |
| 196 else | 194 else |
| 197 removeAttribute(name); | 195 removeAttribute(name); |
| 198 } | 196 } |
| 199 | 197 |
| 200 ActiveAnimations* Element::activeAnimations() const | |
| 201 { | |
| 202 if (hasRareData()) | |
| 203 return elementRareData()->activeAnimations(); | |
| 204 return 0; | |
| 205 } | |
| 206 | |
| 207 ActiveAnimations& Element::ensureActiveAnimations() | |
| 208 { | |
| 209 ElementRareData& rareData = ensureElementRareData(); | |
| 210 if (!rareData.activeAnimations()) | |
| 211 rareData.setActiveAnimations(adoptPtr(new ActiveAnimations())); | |
| 212 return *rareData.activeAnimations(); | |
| 213 } | |
| 214 | |
| 215 bool Element::hasActiveAnimations() const | |
| 216 { | |
| 217 if (!hasRareData()) | |
| 218 return false; | |
| 219 | |
| 220 ActiveAnimations* activeAnimations = elementRareData()->activeAnimations(); | |
| 221 return activeAnimations && !activeAnimations->isEmpty(); | |
| 222 } | |
| 223 | |
| 224 Node::NodeType Element::nodeType() const | 198 Node::NodeType Element::nodeType() const |
| 225 { | 199 { |
| 226 return ELEMENT_NODE; | 200 return ELEMENT_NODE; |
| 227 } | 201 } |
| 228 | 202 |
| 229 void Element::synchronizeAllAttributes() const | 203 void Element::synchronizeAllAttributes() const |
| 230 { | 204 { |
| 231 synchronizeAttribute(HTMLNames::styleAttr.localName()); | 205 synchronizeAttribute(HTMLNames::styleAttr.localName()); |
| 232 } | 206 } |
| 233 | 207 |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 | 653 |
| 680 // We've already been through detach when doing an attach, but we might | 654 // We've already been through detach when doing an attach, but we might |
| 681 // need to clear any state that's been added since then. | 655 // need to clear any state that's been added since then. |
| 682 if (hasRareData() && styleChangeType() == NeedsReattachStyleChange) { | 656 if (hasRareData() && styleChangeType() == NeedsReattachStyleChange) { |
| 683 ElementRareData* data = elementRareData(); | 657 ElementRareData* data = elementRareData(); |
| 684 data->clearComputedStyle(); | 658 data->clearComputedStyle(); |
| 685 } | 659 } |
| 686 | 660 |
| 687 RenderTreeBuilder(this, context.resolvedStyle).createRendererForElementIfNee
ded(); | 661 RenderTreeBuilder(this, context.resolvedStyle).createRendererForElementIfNee
ded(); |
| 688 | 662 |
| 689 if (hasRareData() && !renderer()) { | |
| 690 if (ActiveAnimations* activeAnimations = elementRareData()->activeAnimat
ions()) { | |
| 691 activeAnimations->cssAnimations().cancel(); | |
| 692 activeAnimations->setAnimationStyleChange(false); | |
| 693 } | |
| 694 } | |
| 695 | |
| 696 // When a shadow root exists, it does the work of attaching the children. | 663 // When a shadow root exists, it does the work of attaching the children. |
| 697 if (ElementShadow* shadow = this->shadow()) | 664 if (ElementShadow* shadow = this->shadow()) |
| 698 shadow->attach(context); | 665 shadow->attach(context); |
| 699 | 666 |
| 700 ContainerNode::attach(context); | 667 ContainerNode::attach(context); |
| 701 } | 668 } |
| 702 | 669 |
| 703 void Element::detach(const AttachContext& context) | 670 void Element::detach(const AttachContext& context) |
| 704 { | 671 { |
| 705 if (isInsertionPoint()) | 672 if (isInsertionPoint()) |
| 706 toInsertionPoint(this)->detachDistribution(context); | 673 toInsertionPoint(this)->detachDistribution(context); |
| 707 | 674 |
| 708 if (hasRareData()) { | 675 if (hasRareData()) { |
| 709 ElementRareData* data = elementRareData(); | 676 ElementRareData* data = elementRareData(); |
| 710 | 677 |
| 711 // attach() will perform the below steps for us when inside recalcStyle. | 678 // attach() will perform the below steps for us when inside recalcStyle. |
| 712 if (!document().inStyleRecalc()) { | 679 if (!document().inStyleRecalc()) { |
| 713 data->clearComputedStyle(); | 680 data->clearComputedStyle(); |
| 714 } | 681 } |
| 715 | 682 |
| 716 if (ActiveAnimations* activeAnimations = data->activeAnimations()) { | |
| 717 if (!context.performingReattach) { | |
| 718 activeAnimations->cssAnimations().cancel(); | |
| 719 activeAnimations->setAnimationStyleChange(false); | |
| 720 } | |
| 721 } | |
| 722 | |
| 723 if (ElementShadow* shadow = data->shadow()) | 683 if (ElementShadow* shadow = data->shadow()) |
| 724 shadow->detach(context); | 684 shadow->detach(context); |
| 725 } | 685 } |
| 726 ContainerNode::detach(context); | 686 ContainerNode::detach(context); |
| 727 } | 687 } |
| 728 | 688 |
| 729 PassRefPtr<RenderStyle> Element::styleForRenderer() | 689 PassRefPtr<RenderStyle> Element::styleForRenderer() |
| 730 { | 690 { |
| 731 ASSERT(document().inStyleRecalc()); | 691 ASSERT(document().inStyleRecalc()); |
| 732 | 692 |
| 733 // FIXME: Instead of clearing updates that may have been added from calls to
styleForElement | 693 // FIXME: Instead of clearing updates that may have been added from calls to
styleForElement |
| 734 // outside recalcStyle, we should just never set them if we're not inside re
calcStyle. | 694 // outside recalcStyle, we should just never set them if we're not inside re
calcStyle. |
| 735 if (ActiveAnimations* activeAnimations = this->activeAnimations()) | |
| 736 activeAnimations->cssAnimations().setPendingUpdate(nullptr); | |
| 737 | 695 |
| 738 RefPtr<RenderStyle> style = document().styleResolver().styleForElement(this)
; | 696 RefPtr<RenderStyle> style = document().styleResolver().styleForElement(this)
; |
| 739 ASSERT(style); | 697 ASSERT(style); |
| 740 | 698 |
| 741 // styleForElement() might add active animations so we need to get it again. | |
| 742 if (ActiveAnimations* activeAnimations = this->activeAnimations()) { | |
| 743 activeAnimations->cssAnimations().maybeApplyPendingUpdate(this); | |
| 744 } | |
| 745 | |
| 746 document().didRecalculateStyleForElement(); | 699 document().didRecalculateStyleForElement(); |
| 747 return style.release(); | 700 return style.release(); |
| 748 } | 701 } |
| 749 | 702 |
| 750 void Element::recalcStyle(StyleRecalcChange change) | 703 void Element::recalcStyle(StyleRecalcChange change) |
| 751 { | 704 { |
| 752 ASSERT(document().inStyleRecalc()); | 705 ASSERT(document().inStyleRecalc()); |
| 753 ASSERT(!parentOrShadowHostNode()->needsStyleRecalc()); | 706 ASSERT(!parentOrShadowHostNode()->needsStyleRecalc()); |
| 754 | 707 |
| 755 if (isInsertionPoint()) | 708 if (isInsertionPoint()) |
| 756 toInsertionPoint(this)->willRecalcStyle(change); | 709 toInsertionPoint(this)->willRecalcStyle(change); |
| 757 | 710 |
| 758 if (change >= Inherit || needsStyleRecalc()) { | 711 if (change >= Inherit || needsStyleRecalc()) { |
| 759 if (hasRareData()) { | 712 if (hasRareData()) { |
| 760 ElementRareData* data = elementRareData(); | 713 ElementRareData* data = elementRareData(); |
| 761 data->clearComputedStyle(); | 714 data->clearComputedStyle(); |
| 762 | |
| 763 if (change >= Inherit) { | |
| 764 if (ActiveAnimations* activeAnimations = data->activeAnimations(
)) | |
| 765 activeAnimations->setAnimationStyleChange(false); | |
| 766 } | |
| 767 } | 715 } |
| 768 if (parentRenderStyle()) | 716 if (parentRenderStyle()) |
| 769 change = recalcOwnStyle(change); | 717 change = recalcOwnStyle(change); |
| 770 clearNeedsStyleRecalc(); | 718 clearNeedsStyleRecalc(); |
| 771 } | 719 } |
| 772 | 720 |
| 773 // If we reattached we don't need to recalc the style of our descendants any
more. | 721 // If we reattached we don't need to recalc the style of our descendants any
more. |
| 774 if ((change >= Inherit && change < Reattach) || childNeedsStyleRecalc()) { | 722 if ((change >= Inherit && change < Reattach) || childNeedsStyleRecalc()) { |
| 775 recalcChildStyle(change); | 723 recalcChildStyle(change); |
| 776 clearChildNeedsStyleRecalc(); | 724 clearChildNeedsStyleRecalc(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 ElementShadow* Element::shadow() const | 795 ElementShadow* Element::shadow() const |
| 848 { | 796 { |
| 849 return hasRareData() ? elementRareData()->shadow() : 0; | 797 return hasRareData() ? elementRareData()->shadow() : 0; |
| 850 } | 798 } |
| 851 | 799 |
| 852 ElementShadow& Element::ensureShadow() | 800 ElementShadow& Element::ensureShadow() |
| 853 { | 801 { |
| 854 return ensureElementRareData().ensureShadow(); | 802 return ensureElementRareData().ensureShadow(); |
| 855 } | 803 } |
| 856 | 804 |
| 857 void Element::setAnimationStyleChange(bool animationStyleChange) | |
| 858 { | |
| 859 if (animationStyleChange && document().inStyleRecalc()) | |
| 860 return; | |
| 861 if (ActiveAnimations* activeAnimations = elementRareData()->activeAnimations
()) | |
| 862 activeAnimations->setAnimationStyleChange(animationStyleChange); | |
| 863 } | |
| 864 | |
| 865 void Element::setNeedsAnimationStyleRecalc() | |
| 866 { | |
| 867 if (styleChangeType() != NoStyleChange) | |
| 868 return; | |
| 869 | |
| 870 setNeedsStyleRecalc(LocalStyleChange); | |
| 871 setAnimationStyleChange(true); | |
| 872 } | |
| 873 | |
| 874 // TODO(esprehn): Implement the sky spec where shadow roots are a custom | 805 // TODO(esprehn): Implement the sky spec where shadow roots are a custom |
| 875 // element registration feature. | 806 // element registration feature. |
| 876 PassRefPtr<ShadowRoot> Element::ensureShadowRoot(ExceptionState& exceptionState) | 807 PassRefPtr<ShadowRoot> Element::ensureShadowRoot(ExceptionState& exceptionState) |
| 877 { | 808 { |
| 878 if (ShadowRoot* root = shadowRoot()) | 809 if (ShadowRoot* root = shadowRoot()) |
| 879 return root; | 810 return root; |
| 880 return PassRefPtr<ShadowRoot>(ensureShadow().addShadowRoot(*this)); | 811 return PassRefPtr<ShadowRoot>(ensureShadow().addShadowRoot(*this)); |
| 881 } | 812 } |
| 882 | 813 |
| 883 ShadowRoot* Element::shadowRoot() const | 814 ShadowRoot* Element::shadowRoot() const |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1615 if (inlineStyle()) | 1546 if (inlineStyle()) |
| 1616 return false; | 1547 return false; |
| 1617 // Ids stop style sharing if they show up in the stylesheets. | 1548 // Ids stop style sharing if they show up in the stylesheets. |
| 1618 if (hasID() && affectedByIdSelector(idForStyleResolution())) | 1549 if (hasID() && affectedByIdSelector(idForStyleResolution())) |
| 1619 return false; | 1550 return false; |
| 1620 // :active and :hover elements always make a chain towards the document node | 1551 // :active and :hover elements always make a chain towards the document node |
| 1621 // and no siblings or cousins will have the same state. There's also only on
e | 1552 // and no siblings or cousins will have the same state. There's also only on
e |
| 1622 // :focus element per scope so we don't need to attempt to share. | 1553 // :focus element per scope so we don't need to attempt to share. |
| 1623 if (isUserActionElement()) | 1554 if (isUserActionElement()) |
| 1624 return false; | 1555 return false; |
| 1625 if (hasActiveAnimations()) | |
| 1626 return false; | |
| 1627 return true; | 1556 return true; |
| 1628 } | 1557 } |
| 1629 | 1558 |
| 1630 bool Element::affectedByAttributeSelector(const AtomicString& attributeName) con
st | 1559 bool Element::affectedByAttributeSelector(const AtomicString& attributeName) con
st |
| 1631 { | 1560 { |
| 1632 if (attributeName.isEmpty()) | 1561 if (attributeName.isEmpty()) |
| 1633 return false; | 1562 return false; |
| 1634 if (treeScope().scopedStyleResolver().hasSelectorForAttribute(attributeName)
) | 1563 if (treeScope().scopedStyleResolver().hasSelectorForAttribute(attributeName)
) |
| 1635 return true; | 1564 return true; |
| 1636 // Host rules could also have effects. | 1565 // Host rules could also have effects. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 GraphicsContext context(canvas->skCanvas()); | 1600 GraphicsContext context(canvas->skCanvas()); |
| 1672 | 1601 |
| 1673 // Very simplified painting to allow painting an arbitrary (layer-less) subt
ree. | 1602 // Very simplified painting to allow painting an arbitrary (layer-less) subt
ree. |
| 1674 Vector<RenderBox*> layers; | 1603 Vector<RenderBox*> layers; |
| 1675 PaintInfo paintInfo(&context, box->absoluteBoundingBoxRect(), box); | 1604 PaintInfo paintInfo(&context, box->absoluteBoundingBoxRect(), box); |
| 1676 box->paint(paintInfo, LayoutPoint(), layers); | 1605 box->paint(paintInfo, LayoutPoint(), layers); |
| 1677 // Note we're ignoring any layers encountered. | 1606 // Note we're ignoring any layers encountered. |
| 1678 } | 1607 } |
| 1679 | 1608 |
| 1680 } // namespace blink | 1609 } // namespace blink |
| OLD | NEW |