Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: Source/core/dom/Element.cpp

Issue 474683003: Not for review - Rebase of crrev.com/62833003 Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 #include "core/page/FocusController.h" 102 #include "core/page/FocusController.h"
103 #include "core/page/Page.h" 103 #include "core/page/Page.h"
104 #include "core/page/PointerLockController.h" 104 #include "core/page/PointerLockController.h"
105 #include "core/rendering/RenderLayer.h" 105 #include "core/rendering/RenderLayer.h"
106 #include "core/rendering/RenderView.h" 106 #include "core/rendering/RenderView.h"
107 #include "core/rendering/compositing/RenderLayerCompositor.h" 107 #include "core/rendering/compositing/RenderLayerCompositor.h"
108 #include "core/svg/SVGDocumentExtensions.h" 108 #include "core/svg/SVGDocumentExtensions.h"
109 #include "core/svg/SVGElement.h" 109 #include "core/svg/SVGElement.h"
110 #include "platform/EventDispatchForbiddenScope.h" 110 #include "platform/EventDispatchForbiddenScope.h"
111 #include "platform/RuntimeEnabledFeatures.h" 111 #include "platform/RuntimeEnabledFeatures.h"
112 #include "platform/TraceEvent.h"
112 #include "platform/UserGestureIndicator.h" 113 #include "platform/UserGestureIndicator.h"
113 #include "platform/scroll/ScrollableArea.h" 114 #include "platform/scroll/ScrollableArea.h"
115 #include "platform/transforms/MatrixTransformOperation.h"
116 #include "public/platform/WebTeleportCallback.h"
114 #include "wtf/BitVector.h" 117 #include "wtf/BitVector.h"
115 #include "wtf/HashFunctions.h" 118 #include "wtf/HashFunctions.h"
116 #include "wtf/text/CString.h" 119 #include "wtf/text/CString.h"
117 #include "wtf/text/StringBuilder.h" 120 #include "wtf/text/StringBuilder.h"
118 #include "wtf/text/TextPosition.h" 121 #include "wtf/text/TextPosition.h"
119 122
120 namespace blink { 123 namespace blink {
121 124
125 typedef WTF::HashMap<const Element*, OwnPtr<Vector<String> > > BoundAnimatedProp ertyMap;
126 static BoundAnimatedPropertyMap* gBoundAnimatedPropertyMap = 0;
127
122 using namespace HTMLNames; 128 using namespace HTMLNames;
123 using namespace XMLNames; 129 using namespace XMLNames;
124 130
125 typedef WillBeHeapVector<RefPtrWillBeMember<Attr> > AttrNodeList; 131 typedef WillBeHeapVector<RefPtrWillBeMember<Attr> > AttrNodeList;
126 132
127 static Attr* findAttrNodeInList(const AttrNodeList& attrNodeList, const Qualifie dName& name) 133 static Attr* findAttrNodeInList(const AttrNodeList& attrNodeList, const Qualifie dName& name)
128 { 134 {
129 for (const auto& attr : attrNodeList) { 135 for (const auto& attr : attrNodeList) {
130 if (attr->qualifiedName() == name) 136 if (attr->qualifiedName() == name)
131 return attr.get(); 137 return attr.get();
132 } 138 }
133 return nullptr; 139 return nullptr;
134 } 140 }
135 141
136 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do cument* document) 142 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do cument* document)
137 { 143 {
138 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement)); 144 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement));
139 } 145 }
140 146
141 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT ype type) 147 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT ype type)
142 : ContainerNode(document, type) 148 : ContainerNode(document, type)
143 , m_tagName(tagName) 149 , m_tagName(tagName)
144 { 150 {
145 } 151 }
146 152
147 Element::~Element() 153 Element::~Element()
148 { 154 {
149 ASSERT(needsAttach()); 155 ASSERT(needsAttach());
156 if (gBoundAnimatedPropertyMap)
157 gBoundAnimatedPropertyMap->remove(this);
150 158
151 #if !ENABLE(OILPAN) 159 #if !ENABLE(OILPAN)
152 if (hasRareData()) 160 if (hasRareData())
153 elementRareData()->clearShadow(); 161 elementRareData()->clearShadow();
154 162
155 if (isCustomElement()) 163 if (isCustomElement())
156 CustomElement::wasDestroyed(this); 164 CustomElement::wasDestroyed(this);
157 165
158 if (hasSyntheticAttrChildNodes()) 166 if (hasSyntheticAttrChildNodes())
159 detachAllAttrNodesFromElement(); 167 detachAllAttrNodesFromElement();
(...skipping 2506 matching lines...) Expand 10 before | Expand all | Expand 10 after
2666 // top layer position, or in its usual place if not in the top layer. 2674 // top layer position, or in its usual place if not in the top layer.
2667 lazyReattachIfAttached(); 2675 lazyReattachIfAttached();
2668 } 2676 }
2669 2677
2670 void Element::requestPointerLock() 2678 void Element::requestPointerLock()
2671 { 2679 {
2672 if (document().page()) 2680 if (document().page())
2673 document().page()->pointerLockController().requestPointerLock(this); 2681 document().page()->pointerLockController().requestPointerLock(this);
2674 } 2682 }
2675 2683
2684 String Element::bindAnimatedProperty(const String& propertyName, ExceptionState& exceptionState)
2685 {
2686 static uint64_t nextBoundId = 1;
2687 TRACE_EVENT0("teleport", "Element::bindAnimatedProperty");
2688 if (propertyName != "transform" && propertyName != "opacity" && propertyName != "scrollTop" && propertyName != "pendingScrollDelta") {
2689 exceptionState.throwTypeError("The given property, '" + propertyName + " ' cannot be bound");
2690 return "";
2691 }
2692
2693 String token;
2694 if (getBoundAnimatedProperty(propertyName, token))
2695 return token;
2696
2697 if (!gBoundAnimatedPropertyMap)
2698 gBoundAnimatedPropertyMap = new BoundAnimatedPropertyMap();
2699
2700 gBoundAnimatedPropertyMap->add(this, adoptPtr(new Vector<String>()));
2701 token = String::number(WTF::intHash(nextBoundId++)) + ":" + propertyName;
2702 gBoundAnimatedPropertyMap->get(this)->append(token);
2703
2704 setNeedsCompositingUpdate();
2705
2706 return token;
2707 }
2708
2709 void Element::unbindAnimatedProperty(const String& propertyName, ExceptionState& exceptionState)
2710 {
2711 TRACE_EVENT0("teleport", "Element::unbindAnimatedProperty");
2712 String token;
2713 if (!getBoundAnimatedProperty(propertyName, token)) {
2714 exceptionState.throwTypeError("Cannot unbind a property that has not bee n bound.");
2715 return;
2716 }
2717
2718 Vector<String>& boundProperties = *gBoundAnimatedPropertyMap->get(this);
2719 boundProperties.remove(boundProperties.find(token));
2720 RenderBoxModelObject* renderer = renderBoxModelObject();
2721 if (renderer && renderer->hasLayer())
2722 renderer->layer()->unbindAnimatedProperties();
2723
2724 setNeedsCompositingUpdate();
2725 }
2726
2727 void Element::updateBoundAnimatedPropertiesIfNeeded()
2728 {
2729 if (!gBoundAnimatedPropertyMap)
2730 return;
2731
2732 BoundAnimatedPropertyMap::const_iterator iter = gBoundAnimatedPropertyMap->b egin();
2733 for (; iter != gBoundAnimatedPropertyMap->end(); ++iter) {
2734 RenderBoxModelObject* renderer = iter->key->renderBoxModelObject();
2735 if (renderer && renderer->hasLayer())
2736 renderer->layer()->bindAnimatedProperties(*iter->value);
2737 }
2738 }
2739
2740 void Element::applyToBoundAnimatedProperties(const WebVector<WebTeleportValue>& values)
2741 {
2742 TRACE_EVENT0("teleport,teleport-backchannel", "Element::applyToBoundAnimated Properties");
2743
2744 // FIXME: we need to store this stuff and apply it during style.
2745 if (!gBoundAnimatedPropertyMap)
2746 return;
2747
2748 BoundAnimatedPropertyMap::const_iterator iter = gBoundAnimatedPropertyMap->b egin();
2749 for (; iter != gBoundAnimatedPropertyMap->end(); ++iter) {
2750 const Vector<String>& properties = *iter->value;
2751 for (size_t i = 0; i < values.size(); ++i) {
2752 const WebTeleportValue& value = values[i];
2753 String id = value.id;
2754 size_t j = properties.find(id);
2755 if (j == kNotFound)
2756 continue;
2757
2758 if (!iter->key->renderer())
2759 continue;
2760
2761 RenderStyle* style = iter->key->renderer()->style();
2762 if (!style)
2763 continue;
2764
2765 RefPtr<RenderStyle> updated = RenderStyle::clone(style);
2766
2767 switch (value.type) {
2768 case WebTeleportValue::ValueTypeTransform: {
2769 TransformOperations operations;
2770 operations.operations().append(MatrixTransformOperation::create(
2771 TransformationMatrix(
2772 value.value.matrix[0],
2773 value.value.matrix[4],
2774 value.value.matrix[8],
2775 value.value.matrix[12],
2776 value.value.matrix[1],
2777 value.value.matrix[5],
2778 value.value.matrix[9],
2779 value.value.matrix[13],
2780 value.value.matrix[2],
2781 value.value.matrix[6],
2782 value.value.matrix[10],
2783 value.value.matrix[14],
2784 value.value.matrix[3],
2785 value.value.matrix[7],
2786 value.value.matrix[11],
2787 value.value.matrix[15])));
2788 updated->setTransform(operations);
2789 break;
2790 }
2791 case WebTeleportValue::ValueTypeOpacity: {
2792 updated->setOpacity(value.value.scalar);
2793 break;
2794 }
2795 case WebTeleportValue::ValueTypeScrollTop: {
2796 const_cast<Element*>(iter->key)->setScrollTop(static_cast<int>(v alue.value.scalar));
2797 break;
2798 }
2799 case WebTeleportValue::ValueTypePendingScrollDelta: {
2800 // const_cast<Element*>(iter->key)->setPendingScrollDelta(static _cast<int>(value.value.scalar));
2801 // TODO
2802 break;
2803 }
2804 case WebTeleportValue::ValueTypeTimestamp:
2805 case WebTeleportValue::ValueTypeError:
2806 break;
2807 default:
2808 RELEASE_ASSERT_NOT_REACHED();
2809 }
2810
2811 iter->key->renderer()->setStyle(updated.release());
2812 }
2813 }
2814 }
2815
2816 bool Element::getBoundAnimatedProperty(const String& propertyName, String& token ) const
2817 {
2818 if (!gBoundAnimatedPropertyMap)
2819 return false;
2820
2821 BoundAnimatedPropertyMap::const_iterator iter = gBoundAnimatedPropertyMap->f ind(this);
2822 if (iter == gBoundAnimatedPropertyMap->end())
2823 return false;
2824
2825 Vector<String>& boundProperties = *iter->value;
2826 for (size_t i = 0; i < boundProperties.size(); ++i) {
2827 Vector<String> components;
2828 boundProperties[i].split(":", components);
2829 if (components[1] == propertyName) {
2830 token = boundProperties[i];
2831 return true;
2832 }
2833 }
2834
2835 return false;
2836 }
2837
2838 bool Element::hasBoundAnimatedProperty() const
2839 {
2840 return gBoundAnimatedPropertyMap && gBoundAnimatedPropertyMap->contains(this );
2841 }
2842
2676 SpellcheckAttributeState Element::spellcheckAttributeState() const 2843 SpellcheckAttributeState Element::spellcheckAttributeState() const
2677 { 2844 {
2678 const AtomicString& value = fastGetAttribute(spellcheckAttr); 2845 const AtomicString& value = fastGetAttribute(spellcheckAttr);
2679 if (value == nullAtom) 2846 if (value == nullAtom)
2680 return SpellcheckAttributeDefault; 2847 return SpellcheckAttributeDefault;
2681 if (equalIgnoringCase(value, "true") || equalIgnoringCase(value, "")) 2848 if (equalIgnoringCase(value, "true") || equalIgnoringCase(value, ""))
2682 return SpellcheckAttributeTrue; 2849 return SpellcheckAttributeTrue;
2683 if (equalIgnoringCase(value, "false")) 2850 if (equalIgnoringCase(value, "false"))
2684 return SpellcheckAttributeFalse; 2851 return SpellcheckAttributeFalse;
2685 2852
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
3266 return wrapper; 3433 return wrapper;
3267 3434
3268 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition()); 3435 CustomElementBinding* binding = perContextData->customElementBinding(customE lementDefinition());
3269 3436
3270 wrapper->SetPrototype(binding->prototype()); 3437 wrapper->SetPrototype(binding->prototype());
3271 3438
3272 return V8DOMWrapper::associateObjectWithWrapperNonTemplate(this, wrapperType , wrapper, isolate); 3439 return V8DOMWrapper::associateObjectWithWrapperNonTemplate(this, wrapperType , wrapper, isolate);
3273 } 3440 }
3274 3441
3275 } // namespace blink 3442 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698