Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 | * (C) 2001 Peter Kelly (pmk@post.com) |
| 5 | * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 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. |
| 8 | * (C) 2007 Eric Seidel (eric@webkit.org) |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Library General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Library General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Library General Public License |
| 21 | * along with this library; see the file COPYING.LIB. If not, write to |
| 22 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 23 | * Boston, MA 02110-1301, USA. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "core/dom/Element.h" |
| 28 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 29 | #include "CSSValueKeywords.h" |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 30 | #include "RuntimeEnabledFeatures.h" |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 31 | #include "SVGNames.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 32 | #include "XMLNames.h" |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 33 | #include "bindings/v8/ExceptionState.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 34 | #include "core/accessibility/AXObjectCache.h" |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 35 | #include "core/animation/DocumentTimeline.h" |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 36 | #include "core/animation/css/CSSAnimations.h" |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 37 | #include "core/css/CSSParser.h" |
| 38 | #include "core/css/CSSStyleSheet.h" |
| 39 | #include "core/css/CSSValuePool.h" |
| 40 | #include "core/css/PropertySetCSSStyleDeclaration.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 41 | #include "core/css/StylePropertySet.h" |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 42 | #include "core/css/resolver/StyleResolver.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 43 | #include "core/dom/Attr.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 44 | #include "core/dom/CSSSelectorWatch.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 45 | #include "core/dom/ClientRect.h" |
| 46 | #include "core/dom/ClientRectList.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 47 | #include "core/dom/DatasetDOMStringMap.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 48 | #include "core/dom/DocumentSharedObjectPool.h" |
| 49 | #include "core/dom/ElementRareData.h" |
| 50 | #include "core/dom/ExceptionCode.h" |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 51 | #include "core/dom/FullscreenElementStack.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 52 | #include "core/dom/MutationObserverInterestGroup.h" |
| 53 | #include "core/dom/MutationRecord.h" |
| 54 | #include "core/dom/NamedNodeMap.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 55 | #include "core/dom/NodeRenderStyle.h" |
| 56 | #include "core/dom/NodeRenderingContext.h" |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 57 | #include "core/dom/PostAttachCallbacks.h" |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 58 | #include "core/dom/PresentationAttributeStyle.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 59 | #include "core/dom/PseudoElement.h" |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 60 | #include "core/dom/ScriptableDocumentParser.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 61 | #include "core/dom/SelectorQuery.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 62 | #include "core/dom/Text.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 63 | #include "core/dom/custom/CustomElement.h" |
| 64 | #include "core/dom/custom/CustomElementRegistrationContext.h" |
Torne (Richard Coles) | e524955 | 2013-05-15 11:35:13 +0100 | [diff] [blame] | 65 | #include "core/dom/shadow/InsertionPoint.h" |
| 66 | #include "core/dom/shadow/ShadowRoot.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 67 | #include "core/editing/FrameSelection.h" |
| 68 | #include "core/editing/TextIterator.h" |
| 69 | #include "core/editing/htmlediting.h" |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 70 | #include "core/editing/markup.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 71 | #include "core/events/EventDispatcher.h" |
| 72 | #include "core/events/FocusEvent.h" |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 73 | #include "core/frame/ContentSecurityPolicy.h" |
| 74 | #include "core/frame/Frame.h" |
| 75 | #include "core/frame/FrameView.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 76 | #include "core/html/ClassList.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 77 | #include "core/html/HTMLCollection.h" |
| 78 | #include "core/html/HTMLDocument.h" |
| 79 | #include "core/html/HTMLElement.h" |
| 80 | #include "core/html/HTMLFormControlsCollection.h" |
| 81 | #include "core/html/HTMLFrameOwnerElement.h" |
| 82 | #include "core/html/HTMLLabelElement.h" |
| 83 | #include "core/html/HTMLOptionsCollection.h" |
| 84 | #include "core/html/HTMLTableRowsCollection.h" |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 85 | #include "core/html/HTMLTemplateElement.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 86 | #include "core/html/parser/HTMLParserIdioms.h" |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 87 | #include "core/inspector/InspectorInstrumentation.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 88 | #include "core/page/FocusController.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 89 | #include "core/page/Page.h" |
| 90 | #include "core/page/PointerLockController.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 91 | #include "core/rendering/FlowThreadController.h" |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 92 | #include "core/rendering/RenderNamedFlowFragment.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 93 | #include "core/rendering/RenderView.h" |
| 94 | #include "core/rendering/RenderWidget.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 95 | #include "core/svg/SVGDocumentExtensions.h" |
| 96 | #include "core/svg/SVGElement.h" |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 97 | #include "wtf/BitVector.h" |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 98 | #include "wtf/HashFunctions.h" |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 99 | #include "wtf/text/CString.h" |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 100 | #include "wtf/text/TextPosition.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 101 | |
| 102 | namespace WebCore { |
| 103 | |
| 104 | using namespace HTMLNames; |
| 105 | using namespace XMLNames; |
| 106 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 107 | class StyleResolverParentPusher { |
| 108 | public: |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 109 | explicit StyleResolverParentPusher(Element& parent) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 110 | : m_parent(parent) |
| 111 | , m_pushedStyleResolver(0) |
| 112 | { |
| 113 | } |
| 114 | void push() |
| 115 | { |
| 116 | if (m_pushedStyleResolver) |
| 117 | return; |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 118 | m_pushedStyleResolver = &m_parent.document().ensureStyleResolver(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 119 | m_pushedStyleResolver->pushParentElement(m_parent); |
| 120 | } |
| 121 | ~StyleResolverParentPusher() |
| 122 | { |
| 123 | |
| 124 | if (!m_pushedStyleResolver) |
| 125 | return; |
| 126 | |
| 127 | // This tells us that our pushed style selector is in a bad state, |
| 128 | // so we should just bail out in that scenario. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 129 | ASSERT(m_pushedStyleResolver == m_parent.document().styleResolver()); |
| 130 | if (m_pushedStyleResolver != m_parent.document().styleResolver()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 131 | return; |
| 132 | |
| 133 | m_pushedStyleResolver->popParentElement(m_parent); |
| 134 | } |
| 135 | |
| 136 | private: |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 137 | Element& m_parent; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 138 | StyleResolver* m_pushedStyleResolver; |
| 139 | }; |
| 140 | |
| 141 | typedef Vector<RefPtr<Attr> > AttrNodeList; |
| 142 | typedef HashMap<Element*, OwnPtr<AttrNodeList> > AttrNodeListMap; |
| 143 | |
| 144 | static AttrNodeListMap& attrNodeListMap() |
| 145 | { |
| 146 | DEFINE_STATIC_LOCAL(AttrNodeListMap, map, ()); |
| 147 | return map; |
| 148 | } |
| 149 | |
| 150 | static AttrNodeList* attrNodeListForElement(Element* element) |
| 151 | { |
| 152 | if (!element->hasSyntheticAttrChildNodes()) |
| 153 | return 0; |
| 154 | ASSERT(attrNodeListMap().contains(element)); |
| 155 | return attrNodeListMap().get(element); |
| 156 | } |
| 157 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 158 | static AttrNodeList& ensureAttrNodeListForElement(Element* element) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 159 | { |
| 160 | if (element->hasSyntheticAttrChildNodes()) { |
| 161 | ASSERT(attrNodeListMap().contains(element)); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 162 | return *attrNodeListMap().get(element); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 163 | } |
| 164 | ASSERT(!attrNodeListMap().contains(element)); |
| 165 | element->setHasSyntheticAttrChildNodes(true); |
| 166 | AttrNodeListMap::AddResult result = attrNodeListMap().add(element, adoptPtr(new AttrNodeList)); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 167 | return *result.iterator->value; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static void removeAttrNodeListForElement(Element* element) |
| 171 | { |
| 172 | ASSERT(element->hasSyntheticAttrChildNodes()); |
| 173 | ASSERT(attrNodeListMap().contains(element)); |
| 174 | attrNodeListMap().remove(element); |
| 175 | element->setHasSyntheticAttrChildNodes(false); |
| 176 | } |
| 177 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 178 | static Attr* findAttrNodeInList(const AttrNodeList& attrNodeList, const QualifiedName& name) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 179 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 180 | AttrNodeList::const_iterator end = attrNodeList.end(); |
| 181 | for (AttrNodeList::const_iterator it = attrNodeList.begin(); it != end; ++it) { |
| 182 | if ((*it)->qualifiedName() == name) |
| 183 | return it->get(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 184 | } |
| 185 | return 0; |
| 186 | } |
| 187 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 188 | PassRefPtr<Element> Element::create(const QualifiedName& tagName, Document* document) |
| 189 | { |
| 190 | return adoptRef(new Element(tagName, document, CreateElement)); |
| 191 | } |
| 192 | |
| 193 | Element::~Element() |
| 194 | { |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 195 | // When the document is not destroyed, an element that was part of a named flow |
| 196 | // content nodes should have been removed from the content nodes collection |
| 197 | // and the inNamedFlow flag reset. |
| 198 | ASSERT(!document().renderView() || !inNamedFlow()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 199 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 200 | if (PropertySetCSSStyleDeclaration* cssomWrapper = inlineStyleCSSOMWrapper()) |
| 201 | cssomWrapper->clearParentElement(); |
| 202 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 203 | if (hasRareData()) { |
| 204 | ElementRareData* data = elementRareData(); |
| 205 | data->setPseudoElement(BEFORE, 0); |
| 206 | data->setPseudoElement(AFTER, 0); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 207 | data->setPseudoElement(BACKDROP, 0); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 208 | data->clearShadow(); |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 209 | |
| 210 | if (RuntimeEnabledFeatures::webAnimationsCSSEnabled()) { |
| 211 | if (ActiveAnimations* activeAnimations = data->activeAnimations()) |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 212 | activeAnimations->cssAnimations().cancel(); |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 213 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 216 | if (isCustomElement()) |
| 217 | CustomElement::wasDestroyed(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 218 | |
| 219 | if (hasSyntheticAttrChildNodes()) |
| 220 | detachAllAttrNodesFromElement(); |
| 221 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 222 | if (hasPendingResources()) { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 223 | document().accessSVGExtensions()->removeElementFromPendingResources(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 224 | ASSERT(!hasPendingResources()); |
| 225 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | inline ElementRareData* Element::elementRareData() const |
| 229 | { |
| 230 | ASSERT(hasRareData()); |
| 231 | return static_cast<ElementRareData*>(rareData()); |
| 232 | } |
| 233 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 234 | inline ElementRareData& Element::ensureElementRareData() |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 235 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 236 | return static_cast<ElementRareData&>(ensureRareData()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void Element::clearTabIndexExplicitlyIfNeeded() |
| 240 | { |
| 241 | if (hasRareData()) |
| 242 | elementRareData()->clearTabIndexExplicitly(); |
| 243 | } |
| 244 | |
| 245 | void Element::setTabIndexExplicitly(short tabIndex) |
| 246 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 247 | ensureElementRareData().setTabIndexExplicitly(tabIndex); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | bool Element::supportsFocus() const |
| 251 | { |
| 252 | return hasRareData() && elementRareData()->tabIndexSetExplicitly(); |
| 253 | } |
| 254 | |
| 255 | short Element::tabIndex() const |
| 256 | { |
| 257 | return hasRareData() ? elementRareData()->tabIndex() : 0; |
| 258 | } |
| 259 | |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 260 | bool Element::rendererIsFocusable() const |
| 261 | { |
| 262 | // Elements in canvas fallback content are not rendered, but they are allowed to be |
| 263 | // focusable as long as their canvas is displayed and visible. |
| 264 | if (isInCanvasSubtree()) { |
| 265 | const Element* e = this; |
| 266 | while (e && !e->hasLocalName(canvasTag)) |
| 267 | e = e->parentElement(); |
| 268 | ASSERT(e); |
| 269 | return e->renderer() && e->renderer()->style()->visibility() == VISIBLE; |
| 270 | } |
| 271 | |
| 272 | // FIXME: These asserts should be in Node::isFocusable, but there are some |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 273 | // callsites like Document::setFocusedElement that would currently fail on |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 274 | // them. See crbug.com/251163 |
| 275 | if (renderer()) { |
| 276 | ASSERT(!renderer()->needsLayout()); |
| 277 | } else { |
| 278 | // We can't just use needsStyleRecalc() because if the node is in a |
| 279 | // display:none tree it might say it needs style recalc but the whole |
| 280 | // document is actually up to date. |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 281 | ASSERT(!document().childNeedsStyleRecalc()); |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | // FIXME: Even if we are not visible, we might have a child that is visible. |
| 285 | // Hyatt wants to fix that some day with a "has visible content" flag or the like. |
| 286 | if (!renderer() || renderer()->style()->visibility() != VISIBLE) |
| 287 | return false; |
| 288 | |
| 289 | return true; |
| 290 | } |
| 291 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 292 | PassRefPtr<Node> Element::cloneNode(bool deep) |
| 293 | { |
| 294 | return deep ? cloneElementWithChildren() : cloneElementWithoutChildren(); |
| 295 | } |
| 296 | |
| 297 | PassRefPtr<Element> Element::cloneElementWithChildren() |
| 298 | { |
| 299 | RefPtr<Element> clone = cloneElementWithoutChildren(); |
| 300 | cloneChildNodes(clone.get()); |
| 301 | return clone.release(); |
| 302 | } |
| 303 | |
| 304 | PassRefPtr<Element> Element::cloneElementWithoutChildren() |
| 305 | { |
| 306 | RefPtr<Element> clone = cloneElementWithoutAttributesAndChildren(); |
| 307 | // This will catch HTML elements in the wrong namespace that are not correctly copied. |
| 308 | // This is a sanity check as HTML overloads some of the DOM methods. |
| 309 | ASSERT(isHTMLElement() == clone->isHTMLElement()); |
| 310 | |
| 311 | clone->cloneDataFromElement(*this); |
| 312 | return clone.release(); |
| 313 | } |
| 314 | |
| 315 | PassRefPtr<Element> Element::cloneElementWithoutAttributesAndChildren() |
| 316 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 317 | return document().createElement(tagQName(), false); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | PassRefPtr<Attr> Element::detachAttribute(size_t index) |
| 321 | { |
| 322 | ASSERT(elementData()); |
Torne (Richard Coles) | e524955 | 2013-05-15 11:35:13 +0100 | [diff] [blame] | 323 | const Attribute* attribute = elementData()->attributeItem(index); |
| 324 | RefPtr<Attr> attrNode = attrIfExists(attribute->name()); |
| 325 | if (attrNode) |
| 326 | detachAttrNodeAtIndex(attrNode.get(), index); |
| 327 | else { |
| 328 | attrNode = Attr::create(document(), attribute->name(), attribute->value()); |
| 329 | removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); |
| 330 | } |
| 331 | return attrNode.release(); |
| 332 | } |
| 333 | |
| 334 | void Element::detachAttrNodeAtIndex(Attr* attr, size_t index) |
| 335 | { |
| 336 | ASSERT(attr); |
| 337 | ASSERT(elementData()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 338 | |
| 339 | const Attribute* attribute = elementData()->attributeItem(index); |
| 340 | ASSERT(attribute); |
Torne (Richard Coles) | e524955 | 2013-05-15 11:35:13 +0100 | [diff] [blame] | 341 | ASSERT(attribute->name() == attr->qualifiedName()); |
| 342 | detachAttrNodeFromElementWithValue(attr, attribute->value()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 343 | removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void Element::removeAttribute(const QualifiedName& name) |
| 347 | { |
| 348 | if (!elementData()) |
| 349 | return; |
| 350 | |
| 351 | size_t index = elementData()->getAttributeItemIndex(name); |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 352 | if (index == kNotFound) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 353 | return; |
| 354 | |
| 355 | removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); |
| 356 | } |
| 357 | |
| 358 | void Element::setBooleanAttribute(const QualifiedName& name, bool value) |
| 359 | { |
| 360 | if (value) |
| 361 | setAttribute(name, emptyAtom); |
| 362 | else |
| 363 | removeAttribute(name); |
| 364 | } |
| 365 | |
| 366 | NamedNodeMap* Element::attributes() const |
| 367 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 368 | ElementRareData& rareData = const_cast<Element*>(this)->ensureElementRareData(); |
| 369 | if (NamedNodeMap* attributeMap = rareData.attributeMap()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 370 | return attributeMap; |
| 371 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 372 | rareData.setAttributeMap(NamedNodeMap::create(const_cast<Element*>(this))); |
| 373 | return rareData.attributeMap(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 374 | } |
| 375 | |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 376 | ActiveAnimations* Element::activeAnimations() const |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 377 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 378 | if (hasRareData()) |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 379 | return elementRareData()->activeAnimations(); |
| 380 | return 0; |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 381 | } |
| 382 | |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 383 | ActiveAnimations* Element::ensureActiveAnimations() |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 384 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 385 | ElementRareData& rareData = ensureElementRareData(); |
| 386 | if (!rareData.activeAnimations()) |
| 387 | rareData.setActiveAnimations(adoptPtr(new ActiveAnimations())); |
| 388 | return rareData.activeAnimations(); |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | bool Element::hasActiveAnimations() const |
| 392 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 393 | if (!RuntimeEnabledFeatures::webAnimationsCSSEnabled()) |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 394 | return false; |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 395 | |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 396 | if (!hasRareData()) |
| 397 | return false; |
| 398 | |
| 399 | ActiveAnimations* activeAnimations = elementRareData()->activeAnimations(); |
| 400 | return activeAnimations && !activeAnimations->isEmpty(); |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 401 | } |
| 402 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 403 | Node::NodeType Element::nodeType() const |
| 404 | { |
| 405 | return ELEMENT_NODE; |
| 406 | } |
| 407 | |
| 408 | bool Element::hasAttribute(const QualifiedName& name) const |
| 409 | { |
| 410 | return hasAttributeNS(name.namespaceURI(), name.localName()); |
| 411 | } |
| 412 | |
| 413 | void Element::synchronizeAllAttributes() const |
| 414 | { |
| 415 | if (!elementData()) |
| 416 | return; |
| 417 | if (elementData()->m_styleAttributeIsDirty) { |
| 418 | ASSERT(isStyledElement()); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 419 | synchronizeStyleAttributeInternal(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 420 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 421 | if (elementData()->m_animatedSVGAttributesAreDirty) { |
| 422 | ASSERT(isSVGElement()); |
| 423 | toSVGElement(this)->synchronizeAnimatedSVGAttribute(anyQName()); |
| 424 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | inline void Element::synchronizeAttribute(const QualifiedName& name) const |
| 428 | { |
| 429 | if (!elementData()) |
| 430 | return; |
| 431 | if (UNLIKELY(name == styleAttr && elementData()->m_styleAttributeIsDirty)) { |
| 432 | ASSERT(isStyledElement()); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 433 | synchronizeStyleAttributeInternal(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 434 | return; |
| 435 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 436 | if (UNLIKELY(elementData()->m_animatedSVGAttributesAreDirty)) { |
| 437 | ASSERT(isSVGElement()); |
| 438 | toSVGElement(this)->synchronizeAnimatedSVGAttribute(name); |
| 439 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 442 | void Element::synchronizeAttribute(const AtomicString& localName) const |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 443 | { |
| 444 | // This version of synchronizeAttribute() is streamlined for the case where you don't have a full QualifiedName, |
| 445 | // e.g when called from DOM API. |
| 446 | if (!elementData()) |
| 447 | return; |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 448 | if (elementData()->m_styleAttributeIsDirty && equalPossiblyIgnoringCase(localName, styleAttr.localName(), shouldIgnoreAttributeCase())) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 449 | ASSERT(isStyledElement()); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 450 | synchronizeStyleAttributeInternal(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 451 | return; |
| 452 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 453 | if (elementData()->m_animatedSVGAttributesAreDirty) { |
| 454 | // We're not passing a namespace argument on purpose. SVGNames::*Attr are defined w/o namespaces as well. |
| 455 | ASSERT(isSVGElement()); |
| 456 | static_cast<const SVGElement*>(this)->synchronizeAnimatedSVGAttribute(QualifiedName(nullAtom, localName, nullAtom)); |
| 457 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | const AtomicString& Element::getAttribute(const QualifiedName& name) const |
| 461 | { |
| 462 | if (!elementData()) |
| 463 | return nullAtom; |
| 464 | synchronizeAttribute(name); |
| 465 | if (const Attribute* attribute = getAttributeItem(name)) |
| 466 | return attribute->value(); |
| 467 | return nullAtom; |
| 468 | } |
| 469 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 470 | void Element::scrollIntoView(bool alignToTop) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 471 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 472 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 473 | |
| 474 | if (!renderer()) |
| 475 | return; |
| 476 | |
| 477 | LayoutRect bounds = boundingBox(); |
| 478 | // Align to the top / bottom and to the closest edge. |
| 479 | if (alignToTop) |
| 480 | renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignTopAlways); |
| 481 | else |
| 482 | renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignBottomAlways); |
| 483 | } |
| 484 | |
| 485 | void Element::scrollIntoViewIfNeeded(bool centerIfNeeded) |
| 486 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 487 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 488 | |
| 489 | if (!renderer()) |
| 490 | return; |
| 491 | |
| 492 | LayoutRect bounds = boundingBox(); |
| 493 | if (centerIfNeeded) |
| 494 | renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeeded); |
| 495 | else |
| 496 | renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded); |
| 497 | } |
| 498 | |
| 499 | void Element::scrollByUnits(int units, ScrollGranularity granularity) |
| 500 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 501 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 502 | |
| 503 | if (!renderer()) |
| 504 | return; |
| 505 | |
| 506 | if (!renderer()->hasOverflowClip()) |
| 507 | return; |
| 508 | |
| 509 | ScrollDirection direction = ScrollDown; |
| 510 | if (units < 0) { |
| 511 | direction = ScrollUp; |
| 512 | units = -units; |
| 513 | } |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 514 | toRenderBox(renderer())->scroll(direction, granularity, units); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | void Element::scrollByLines(int lines) |
| 518 | { |
| 519 | scrollByUnits(lines, ScrollByLine); |
| 520 | } |
| 521 | |
| 522 | void Element::scrollByPages(int pages) |
| 523 | { |
| 524 | scrollByUnits(pages, ScrollByPage); |
| 525 | } |
| 526 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 527 | static float localZoomForRenderer(RenderObject& renderer) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 528 | { |
| 529 | // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each |
| 530 | // other out, but the alternative is that we'd have to crawl up the whole render tree every |
| 531 | // time (or store an additional bit in the RenderStyle to indicate that a zoom was specified). |
| 532 | float zoomFactor = 1; |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 533 | if (renderer.style()->effectiveZoom() != 1) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 534 | // Need to find the nearest enclosing RenderObject that set up |
| 535 | // a differing zoom, and then we divide our result by it to eliminate the zoom. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 536 | RenderObject* prev = &renderer; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 537 | for (RenderObject* curr = prev->parent(); curr; curr = curr->parent()) { |
| 538 | if (curr->style()->effectiveZoom() != prev->style()->effectiveZoom()) { |
| 539 | zoomFactor = prev->style()->zoom(); |
| 540 | break; |
| 541 | } |
| 542 | prev = curr; |
| 543 | } |
| 544 | if (prev->isRenderView()) |
| 545 | zoomFactor = prev->style()->zoom(); |
| 546 | } |
| 547 | return zoomFactor; |
| 548 | } |
| 549 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 550 | static int adjustForLocalZoom(LayoutUnit value, RenderObject& renderer) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 551 | { |
| 552 | float zoomFactor = localZoomForRenderer(renderer); |
| 553 | if (zoomFactor == 1) |
| 554 | return value; |
| 555 | return lroundf(value / zoomFactor); |
| 556 | } |
| 557 | |
| 558 | int Element::offsetLeft() |
| 559 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 560 | document().partialUpdateLayoutIgnorePendingStylesheets(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 561 | if (RenderBoxModelObject* renderer = renderBoxModelObject()) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 562 | return adjustForLocalZoom(renderer->pixelSnappedOffsetLeft(), *renderer); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | int Element::offsetTop() |
| 567 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 568 | document().partialUpdateLayoutIgnorePendingStylesheets(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 569 | if (RenderBoxModelObject* renderer = renderBoxModelObject()) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 570 | return adjustForLocalZoom(renderer->pixelSnappedOffsetTop(), *renderer); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | int Element::offsetWidth() |
| 575 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 576 | document().updateStyleForNodeIfNeeded(this); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 577 | |
| 578 | if (RenderBox* renderer = renderBox()) { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 579 | if (renderer->canDetermineWidthWithoutLayout()) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 580 | return adjustLayoutUnitForAbsoluteZoom(renderer->fixedOffsetWidth(), *renderer).round(); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 581 | } |
| 582 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 583 | document().partialUpdateLayoutIgnorePendingStylesheets(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 584 | if (RenderBoxModelObject* renderer = renderBoxModelObject()) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 585 | return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedOffsetWidth(), *renderer).round(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | int Element::offsetHeight() |
| 590 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 591 | document().partialUpdateLayoutIgnorePendingStylesheets(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 592 | if (RenderBoxModelObject* renderer = renderBoxModelObject()) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 593 | return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedOffsetHeight(), *renderer).round(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | Element* Element::bindingsOffsetParent() |
| 598 | { |
| 599 | Element* element = offsetParent(); |
| 600 | if (!element || !element->isInShadowTree()) |
| 601 | return element; |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 602 | return element->containingShadowRoot()->shouldExposeToBindings() ? element : 0; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | Element* Element::offsetParent() |
| 606 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 607 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 608 | if (RenderObject* renderer = this->renderer()) |
| 609 | return renderer->offsetParent(); |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | int Element::clientLeft() |
| 614 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 615 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 616 | |
| 617 | if (RenderBox* renderer = renderBox()) |
| 618 | return adjustForAbsoluteZoom(roundToInt(renderer->clientLeft()), renderer); |
| 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | int Element::clientTop() |
| 623 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 624 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 625 | |
| 626 | if (RenderBox* renderer = renderBox()) |
| 627 | return adjustForAbsoluteZoom(roundToInt(renderer->clientTop()), renderer); |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | int Element::clientWidth() |
| 632 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 633 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 634 | |
| 635 | // When in strict mode, clientWidth for the document element should return the width of the containing frame. |
| 636 | // When in quirks mode, clientWidth for the body element should return the width of the containing frame. |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 637 | bool inQuirksMode = document().inQuirksMode(); |
| 638 | if ((!inQuirksMode && document().documentElement() == this) |
| 639 | || (inQuirksMode && isHTMLElement() && document().body() == this)) { |
| 640 | if (FrameView* view = document().view()) { |
| 641 | if (RenderView* renderView = document().renderView()) |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 642 | return adjustForAbsoluteZoom(view->layoutSize().width(), renderView); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 643 | } |
| 644 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 645 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 646 | if (RenderBox* renderer = renderBox()) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 647 | return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedClientWidth(), *renderer).round(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | int Element::clientHeight() |
| 652 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 653 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 654 | |
| 655 | // When in strict mode, clientHeight for the document element should return the height of the containing frame. |
| 656 | // When in quirks mode, clientHeight for the body element should return the height of the containing frame. |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 657 | bool inQuirksMode = document().inQuirksMode(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 658 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 659 | if ((!inQuirksMode && document().documentElement() == this) |
| 660 | || (inQuirksMode && isHTMLElement() && document().body() == this)) { |
| 661 | if (FrameView* view = document().view()) { |
| 662 | if (RenderView* renderView = document().renderView()) |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 663 | return adjustForAbsoluteZoom(view->layoutSize().height(), renderView); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 664 | } |
| 665 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 666 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 667 | if (RenderBox* renderer = renderBox()) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 668 | return adjustLayoutUnitForAbsoluteZoom(renderer->pixelSnappedClientHeight(), *renderer).round(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | int Element::scrollLeft() |
| 673 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 674 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 675 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 676 | if (document().documentElement() != this) { |
| 677 | if (RenderBox* rend = renderBox()) |
| 678 | return adjustForAbsoluteZoom(rend->scrollLeft(), rend); |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 683 | if (document().inQuirksMode()) |
| 684 | return 0; |
| 685 | |
| 686 | if (FrameView* view = document().view()) { |
| 687 | if (RenderView* renderView = document().renderView()) |
| 688 | return adjustForAbsoluteZoom(view->scrollX(), renderView); |
| 689 | } |
| 690 | } |
| 691 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | int Element::scrollTop() |
| 696 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 697 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 698 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 699 | if (document().documentElement() != this) { |
| 700 | if (RenderBox* rend = renderBox()) |
| 701 | return adjustForAbsoluteZoom(rend->scrollTop(), rend); |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 706 | if (document().inQuirksMode()) |
| 707 | return 0; |
| 708 | |
| 709 | if (FrameView* view = document().view()) { |
| 710 | if (RenderView* renderView = document().renderView()) |
| 711 | return adjustForAbsoluteZoom(view->scrollY(), renderView); |
| 712 | } |
| 713 | } |
| 714 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | void Element::setScrollLeft(int newLeft) |
| 719 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 720 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 721 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 722 | if (document().documentElement() != this) { |
| 723 | if (RenderBox* rend = renderBox()) |
| 724 | rend->setScrollLeft(static_cast<int>(newLeft * rend->style()->effectiveZoom())); |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 729 | if (document().inQuirksMode()) |
| 730 | return; |
| 731 | |
| 732 | Frame* frame = document().frame(); |
| 733 | if (!frame) |
| 734 | return; |
| 735 | FrameView* view = frame->view(); |
| 736 | if (!view) |
| 737 | return; |
| 738 | |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 739 | view->setScrollPosition(IntPoint(static_cast<int>(newLeft * frame->pageZoomFactor()), view->scrollY())); |
| 740 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | void Element::setScrollTop(int newTop) |
| 744 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 745 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 746 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 747 | if (document().documentElement() != this) { |
| 748 | if (RenderBox* rend = renderBox()) |
| 749 | rend->setScrollTop(static_cast<int>(newTop * rend->style()->effectiveZoom())); |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 754 | if (document().inQuirksMode()) |
| 755 | return; |
| 756 | |
| 757 | Frame* frame = document().frame(); |
| 758 | if (!frame) |
| 759 | return; |
| 760 | FrameView* view = frame->view(); |
| 761 | if (!view) |
| 762 | return; |
| 763 | |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 764 | view->setScrollPosition(IntPoint(view->scrollX(), static_cast<int>(newTop * frame->pageZoomFactor()))); |
| 765 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | int Element::scrollWidth() |
| 769 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 770 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 771 | if (RenderBox* rend = renderBox()) |
| 772 | return adjustForAbsoluteZoom(rend->scrollWidth(), rend); |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | int Element::scrollHeight() |
| 777 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 778 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 779 | if (RenderBox* rend = renderBox()) |
| 780 | return adjustForAbsoluteZoom(rend->scrollHeight(), rend); |
| 781 | return 0; |
| 782 | } |
| 783 | |
| 784 | IntRect Element::boundsInRootViewSpace() |
| 785 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 786 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 787 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 788 | FrameView* view = document().view(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 789 | if (!view) |
| 790 | return IntRect(); |
| 791 | |
| 792 | Vector<FloatQuad> quads; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 793 | if (isSVGElement() && renderer()) { |
| 794 | // Get the bounding rectangle from the SVG model. |
| 795 | SVGElement* svgElement = toSVGElement(this); |
| 796 | FloatRect localRect; |
| 797 | if (svgElement->getBoundingBox(localRect)) |
| 798 | quads.append(renderer()->localToAbsoluteQuad(localRect)); |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 799 | } else { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 800 | // Get the bounding rectangle from the box model. |
| 801 | if (renderBoxModelObject()) |
| 802 | renderBoxModelObject()->absoluteQuads(quads); |
| 803 | } |
| 804 | |
| 805 | if (quads.isEmpty()) |
| 806 | return IntRect(); |
| 807 | |
| 808 | IntRect result = quads[0].enclosingBoundingBox(); |
| 809 | for (size_t i = 1; i < quads.size(); ++i) |
| 810 | result.unite(quads[i].enclosingBoundingBox()); |
| 811 | |
| 812 | result = view->contentsToRootView(result); |
| 813 | return result; |
| 814 | } |
| 815 | |
| 816 | PassRefPtr<ClientRectList> Element::getClientRects() |
| 817 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 818 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 819 | |
| 820 | RenderBoxModelObject* renderBoxModelObject = this->renderBoxModelObject(); |
| 821 | if (!renderBoxModelObject) |
| 822 | return ClientRectList::create(); |
| 823 | |
| 824 | // FIXME: Handle SVG elements. |
| 825 | // FIXME: Handle table/inline-table with a caption. |
| 826 | |
| 827 | Vector<FloatQuad> quads; |
| 828 | renderBoxModelObject->absoluteQuads(quads); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 829 | document().adjustFloatQuadsForScrollAndAbsoluteZoom(quads, *renderBoxModelObject); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 830 | return ClientRectList::create(quads); |
| 831 | } |
| 832 | |
| 833 | PassRefPtr<ClientRect> Element::getBoundingClientRect() |
| 834 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 835 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 836 | |
| 837 | Vector<FloatQuad> quads; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 838 | if (isSVGElement() && renderer() && !renderer()->isSVGRoot()) { |
| 839 | // Get the bounding rectangle from the SVG model. |
| 840 | SVGElement* svgElement = toSVGElement(this); |
| 841 | FloatRect localRect; |
| 842 | if (svgElement->getBoundingBox(localRect)) |
| 843 | quads.append(renderer()->localToAbsoluteQuad(localRect)); |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 844 | } else { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 845 | // Get the bounding rectangle from the box model. |
| 846 | if (renderBoxModelObject()) |
| 847 | renderBoxModelObject()->absoluteQuads(quads); |
| 848 | } |
| 849 | |
| 850 | if (quads.isEmpty()) |
| 851 | return ClientRect::create(); |
| 852 | |
| 853 | FloatRect result = quads[0].boundingBox(); |
| 854 | for (size_t i = 1; i < quads.size(); ++i) |
| 855 | result.unite(quads[i].boundingBox()); |
| 856 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 857 | ASSERT(renderer()); |
| 858 | document().adjustFloatRectForScrollAndAbsoluteZoom(result, *renderer()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 859 | return ClientRect::create(result); |
| 860 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 861 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 862 | IntRect Element::screenRect() const |
| 863 | { |
| 864 | if (!renderer()) |
| 865 | return IntRect(); |
| 866 | // FIXME: this should probably respect transforms |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 867 | return document().view()->contentsToScreen(renderer()->absoluteBoundingBoxRectIgnoringTransforms()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | const AtomicString& Element::getAttribute(const AtomicString& localName) const |
| 871 | { |
| 872 | if (!elementData()) |
| 873 | return nullAtom; |
| 874 | synchronizeAttribute(localName); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 875 | if (const Attribute* attribute = elementData()->getAttributeItem(localName, shouldIgnoreAttributeCase())) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 876 | return attribute->value(); |
| 877 | return nullAtom; |
| 878 | } |
| 879 | |
| 880 | const AtomicString& Element::getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const |
| 881 | { |
| 882 | return getAttribute(QualifiedName(nullAtom, localName, namespaceURI)); |
| 883 | } |
| 884 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 885 | void Element::setAttribute(const AtomicString& localName, const AtomicString& value, ExceptionState& exceptionState) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 886 | { |
| 887 | if (!Document::isValidName(localName)) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 888 | exceptionState.throwUninformativeAndGenericDOMException(InvalidCharacterError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 889 | return; |
| 890 | } |
| 891 | |
| 892 | synchronizeAttribute(localName); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 893 | const AtomicString& caseAdjustedLocalName = shouldIgnoreAttributeCase() ? localName.lower() : localName; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 894 | |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 895 | size_t index = elementData() ? elementData()->getAttributeItemIndex(caseAdjustedLocalName, false) : kNotFound; |
| 896 | const QualifiedName& qName = index != kNotFound ? attributeItem(index)->name() : QualifiedName(nullAtom, caseAdjustedLocalName, nullAtom); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 897 | setAttributeInternal(index, qName, value, NotInSynchronizationOfLazyAttribute); |
| 898 | } |
| 899 | |
| 900 | void Element::setAttribute(const QualifiedName& name, const AtomicString& value) |
| 901 | { |
| 902 | synchronizeAttribute(name); |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 903 | size_t index = elementData() ? elementData()->getAttributeItemIndex(name) : kNotFound; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 904 | setAttributeInternal(index, name, value, NotInSynchronizationOfLazyAttribute); |
| 905 | } |
| 906 | |
| 907 | void Element::setSynchronizedLazyAttribute(const QualifiedName& name, const AtomicString& value) |
| 908 | { |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 909 | size_t index = elementData() ? elementData()->getAttributeItemIndex(name) : kNotFound; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 910 | setAttributeInternal(index, name, value, InSynchronizationOfLazyAttribute); |
| 911 | } |
| 912 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 913 | ALWAYS_INLINE void Element::setAttributeInternal(size_t index, const QualifiedName& name, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 914 | { |
| 915 | if (newValue.isNull()) { |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 916 | if (index != kNotFound) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 917 | removeAttributeInternal(index, inSynchronizationOfLazyAttribute); |
| 918 | return; |
| 919 | } |
| 920 | |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 921 | if (index == kNotFound) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 922 | addAttributeInternal(name, newValue, inSynchronizationOfLazyAttribute); |
| 923 | return; |
| 924 | } |
| 925 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 926 | const Attribute* existingAttribute = attributeItem(index); |
| 927 | QualifiedName existingAttributeName = existingAttribute->name(); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 928 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 929 | if (!inSynchronizationOfLazyAttribute) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 930 | willModifyAttribute(existingAttributeName, existingAttribute->value(), newValue); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 931 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 932 | if (newValue != existingAttribute->value()) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 933 | // If there is an Attr node hooked to this attribute, the Attr::setValue() call below |
| 934 | // will write into the ElementData. |
| 935 | // FIXME: Refactor this so it makes some sense. |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 936 | if (RefPtr<Attr> attrNode = inSynchronizationOfLazyAttribute ? 0 : attrIfExists(existingAttributeName)) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 937 | attrNode->setValue(newValue); |
| 938 | else |
| 939 | ensureUniqueElementData()->attributeItem(index)->setValue(newValue); |
| 940 | } |
| 941 | |
| 942 | if (!inSynchronizationOfLazyAttribute) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 943 | didModifyAttribute(existingAttributeName, newValue); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | static inline AtomicString makeIdForStyleResolution(const AtomicString& value, bool inQuirksMode) |
| 947 | { |
| 948 | if (inQuirksMode) |
| 949 | return value.lower(); |
| 950 | return value; |
| 951 | } |
| 952 | |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 953 | static bool checkNeedsStyleInvalidationForIdChange(const AtomicString& oldId, const AtomicString& newId, const RuleFeatureSet& features) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 954 | { |
| 955 | ASSERT(newId != oldId); |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 956 | if (!oldId.isEmpty() && features.hasSelectorForId(oldId)) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 957 | return true; |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 958 | if (!newId.isEmpty() && features.hasSelectorForId(newId)) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 959 | return true; |
| 960 | return false; |
| 961 | } |
| 962 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 963 | void Element::attributeChanged(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason reason) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 964 | { |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 965 | if (ElementShadow* parentElementShadow = shadowWhereNodeCanBeDistributed(*this)) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 966 | if (shouldInvalidateDistributionWhenAttributeChanged(parentElementShadow, name, newValue)) |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 967 | parentElementShadow->setNeedsDistributionRecalc(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | parseAttribute(name, newValue); |
| 971 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 972 | document().incDOMTreeVersion(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 973 | |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 974 | StyleResolver* styleResolver = document().styleResolver(); |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 975 | bool testShouldInvalidateStyle = inActiveDocument() && styleResolver && styleChangeType() < SubtreeStyleChange; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 976 | bool shouldInvalidateStyle = false; |
| 977 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 978 | if (isStyledElement() && name == styleAttr) { |
| 979 | styleAttributeChanged(newValue, reason); |
| 980 | } else if (isStyledElement() && isPresentationAttribute(name)) { |
| 981 | elementData()->m_presentationAttributeStyleIsDirty = true; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 982 | setNeedsStyleRecalc(LocalStyleChange); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 983 | } |
| 984 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 985 | if (isIdAttributeName(name)) { |
| 986 | AtomicString oldId = elementData()->idForStyleResolution(); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 987 | AtomicString newId = makeIdForStyleResolution(newValue, document().inQuirksMode()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 988 | if (newId != oldId) { |
| 989 | elementData()->setIdForStyleResolution(newId); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 990 | shouldInvalidateStyle = testShouldInvalidateStyle && checkNeedsStyleInvalidationForIdChange(oldId, newId, styleResolver->ensureRuleFeatureSet()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 991 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 992 | } else if (name == classAttr) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 993 | classAttributeChanged(newValue); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 994 | } else if (name == HTMLNames::nameAttr) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 995 | setHasName(!newValue.isNull()); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 996 | } else if (name == HTMLNames::pseudoAttr) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 997 | shouldInvalidateStyle |= testShouldInvalidateStyle && isInShadowTree(); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 998 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 999 | |
| 1000 | invalidateNodeListCachesInAncestors(&name, this); |
| 1001 | |
| 1002 | // If there is currently no StyleResolver, we can't be sure that this attribute change won't affect style. |
| 1003 | shouldInvalidateStyle |= !styleResolver; |
| 1004 | |
| 1005 | if (shouldInvalidateStyle) |
| 1006 | setNeedsStyleRecalc(); |
| 1007 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1008 | if (AXObjectCache* cache = document().existingAXObjectCache()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1009 | cache->handleAttributeChanged(name, this); |
| 1010 | } |
| 1011 | |
| 1012 | inline void Element::attributeChangedFromParserOrByCloning(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason reason) |
| 1013 | { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1014 | if (name == isAttr) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1015 | CustomElementRegistrationContext::setTypeExtension(this, newValue); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1016 | attributeChanged(name, newValue, reason); |
| 1017 | } |
| 1018 | |
| 1019 | template <typename CharacterType> |
| 1020 | static inline bool classStringHasClassName(const CharacterType* characters, unsigned length) |
| 1021 | { |
| 1022 | ASSERT(length > 0); |
| 1023 | |
| 1024 | unsigned i = 0; |
| 1025 | do { |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 1026 | if (isNotHTMLSpace<CharacterType>(characters[i])) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1027 | break; |
| 1028 | ++i; |
| 1029 | } while (i < length); |
| 1030 | |
| 1031 | return i < length; |
| 1032 | } |
| 1033 | |
| 1034 | static inline bool classStringHasClassName(const AtomicString& newClassString) |
| 1035 | { |
| 1036 | unsigned length = newClassString.length(); |
| 1037 | |
| 1038 | if (!length) |
| 1039 | return false; |
| 1040 | |
| 1041 | if (newClassString.is8Bit()) |
| 1042 | return classStringHasClassName(newClassString.characters8(), length); |
| 1043 | return classStringHasClassName(newClassString.characters16(), length); |
| 1044 | } |
| 1045 | |
| 1046 | template<typename Checker> |
| 1047 | static bool checkSelectorForClassChange(const SpaceSplitString& changedClasses, const Checker& checker) |
| 1048 | { |
| 1049 | unsigned changedSize = changedClasses.size(); |
| 1050 | for (unsigned i = 0; i < changedSize; ++i) { |
| 1051 | if (checker.hasSelectorForClass(changedClasses[i])) |
| 1052 | return true; |
| 1053 | } |
| 1054 | return false; |
| 1055 | } |
| 1056 | |
| 1057 | template<typename Checker> |
| 1058 | static bool checkSelectorForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, const Checker& checker) |
| 1059 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1060 | if (!oldClasses.size()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1061 | return checkSelectorForClassChange(newClasses, checker); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1062 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1063 | // Class vectors tend to be very short. This is faster than using a hash table. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1064 | BitVector remainingClassBits; |
| 1065 | remainingClassBits.ensureSize(oldClasses.size()); |
| 1066 | |
| 1067 | for (unsigned i = 0; i < newClasses.size(); ++i) { |
| 1068 | bool found = false; |
| 1069 | for (unsigned j = 0; j < oldClasses.size(); ++j) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1070 | if (newClasses[i] == oldClasses[j]) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1071 | // Mark each class that is still in the newClasses so we can skip doing |
| 1072 | // an n^2 search below when looking for removals. We can't break from |
| 1073 | // this loop early since a class can appear more than once. |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1074 | remainingClassBits.quickSet(j); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1075 | found = true; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1076 | } |
| 1077 | } |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1078 | // Class was added. |
| 1079 | if (!found && checker.hasSelectorForClass(newClasses[i])) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1080 | return true; |
| 1081 | } |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1082 | |
| 1083 | for (unsigned i = 0; i < oldClasses.size(); ++i) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1084 | if (remainingClassBits.quickGet(i)) |
| 1085 | continue; |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1086 | // Class was removed. |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1087 | if (checker.hasSelectorForClass(oldClasses[i])) |
| 1088 | return true; |
| 1089 | } |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1090 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1091 | return false; |
| 1092 | } |
| 1093 | |
| 1094 | void Element::classAttributeChanged(const AtomicString& newClassString) |
| 1095 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 1096 | StyleResolver* styleResolver = document().styleResolver(); |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 1097 | bool testShouldInvalidateStyle = inActiveDocument() && styleResolver && styleChangeType() < SubtreeStyleChange; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1098 | bool shouldInvalidateStyle = false; |
| 1099 | |
| 1100 | if (classStringHasClassName(newClassString)) { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1101 | const bool shouldFoldCase = document().inQuirksMode(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1102 | const SpaceSplitString oldClasses = elementData()->classNames(); |
| 1103 | elementData()->setClass(newClassString, shouldFoldCase); |
| 1104 | const SpaceSplitString& newClasses = elementData()->classNames(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1105 | shouldInvalidateStyle = testShouldInvalidateStyle && checkSelectorForClassChange(oldClasses, newClasses, styleResolver->ensureRuleFeatureSet()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1106 | } else { |
| 1107 | const SpaceSplitString& oldClasses = elementData()->classNames(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1108 | shouldInvalidateStyle = testShouldInvalidateStyle && checkSelectorForClassChange(oldClasses, styleResolver->ensureRuleFeatureSet()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1109 | elementData()->clearClass(); |
| 1110 | } |
| 1111 | |
| 1112 | if (hasRareData()) |
| 1113 | elementRareData()->clearClassListValueForQuirksMode(); |
| 1114 | |
| 1115 | if (shouldInvalidateStyle) |
| 1116 | setNeedsStyleRecalc(); |
| 1117 | } |
| 1118 | |
| 1119 | bool Element::shouldInvalidateDistributionWhenAttributeChanged(ElementShadow* elementShadow, const QualifiedName& name, const AtomicString& newValue) |
| 1120 | { |
| 1121 | ASSERT(elementShadow); |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 1122 | const SelectRuleFeatureSet& featureSet = elementShadow->ensureSelectFeatureSet(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1123 | |
| 1124 | if (isIdAttributeName(name)) { |
| 1125 | AtomicString oldId = elementData()->idForStyleResolution(); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1126 | AtomicString newId = makeIdForStyleResolution(newValue, document().inQuirksMode()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1127 | if (newId != oldId) { |
| 1128 | if (!oldId.isEmpty() && featureSet.hasSelectorForId(oldId)) |
| 1129 | return true; |
| 1130 | if (!newId.isEmpty() && featureSet.hasSelectorForId(newId)) |
| 1131 | return true; |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | if (name == HTMLNames::classAttr) { |
| 1136 | const AtomicString& newClassString = newValue; |
| 1137 | if (classStringHasClassName(newClassString)) { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1138 | const bool shouldFoldCase = document().inQuirksMode(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1139 | const SpaceSplitString& oldClasses = elementData()->classNames(); |
| 1140 | const SpaceSplitString newClasses(newClassString, shouldFoldCase); |
| 1141 | if (checkSelectorForClassChange(oldClasses, newClasses, featureSet)) |
| 1142 | return true; |
| 1143 | } else { |
| 1144 | const SpaceSplitString& oldClasses = elementData()->classNames(); |
| 1145 | if (checkSelectorForClassChange(oldClasses, featureSet)) |
| 1146 | return true; |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | return featureSet.hasSelectorForAttribute(name.localName()); |
| 1151 | } |
| 1152 | |
| 1153 | // Returns true is the given attribute is an event handler. |
| 1154 | // We consider an event handler any attribute that begins with "on". |
| 1155 | // It is a simple solution that has the advantage of not requiring any |
| 1156 | // code or configuration change if a new event handler is defined. |
| 1157 | |
| 1158 | static inline bool isEventHandlerAttribute(const Attribute& attribute) |
| 1159 | { |
| 1160 | return attribute.name().namespaceURI().isNull() && attribute.name().localName().startsWith("on"); |
| 1161 | } |
| 1162 | |
| 1163 | bool Element::isJavaScriptURLAttribute(const Attribute& attribute) const |
| 1164 | { |
| 1165 | return isURLAttribute(attribute) && protocolIsJavaScript(stripLeadingAndTrailingHTMLSpaces(attribute.value())); |
| 1166 | } |
| 1167 | |
| 1168 | void Element::stripScriptingAttributes(Vector<Attribute>& attributeVector) const |
| 1169 | { |
| 1170 | size_t destination = 0; |
| 1171 | for (size_t source = 0; source < attributeVector.size(); ++source) { |
| 1172 | if (isEventHandlerAttribute(attributeVector[source]) |
| 1173 | || isJavaScriptURLAttribute(attributeVector[source]) |
| 1174 | || isHTMLContentAttribute(attributeVector[source])) |
| 1175 | continue; |
| 1176 | |
| 1177 | if (source != destination) |
| 1178 | attributeVector[destination] = attributeVector[source]; |
| 1179 | |
| 1180 | ++destination; |
| 1181 | } |
| 1182 | attributeVector.shrink(destination); |
| 1183 | } |
| 1184 | |
| 1185 | void Element::parserSetAttributes(const Vector<Attribute>& attributeVector) |
| 1186 | { |
| 1187 | ASSERT(!inDocument()); |
| 1188 | ASSERT(!parentNode()); |
| 1189 | ASSERT(!m_elementData); |
| 1190 | |
| 1191 | if (attributeVector.isEmpty()) |
| 1192 | return; |
| 1193 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1194 | if (document().sharedObjectPool()) |
| 1195 | m_elementData = document().sharedObjectPool()->cachedShareableElementDataWithAttributes(attributeVector); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1196 | else |
| 1197 | m_elementData = ShareableElementData::createWithAttributes(attributeVector); |
| 1198 | |
| 1199 | // Use attributeVector instead of m_elementData because attributeChanged might modify m_elementData. |
| 1200 | for (unsigned i = 0; i < attributeVector.size(); ++i) |
| 1201 | attributeChangedFromParserOrByCloning(attributeVector[i].name(), attributeVector[i].value(), ModifiedDirectly); |
| 1202 | } |
| 1203 | |
| 1204 | bool Element::hasAttributes() const |
| 1205 | { |
| 1206 | synchronizeAllAttributes(); |
| 1207 | return elementData() && elementData()->length(); |
| 1208 | } |
| 1209 | |
| 1210 | bool Element::hasEquivalentAttributes(const Element* other) const |
| 1211 | { |
| 1212 | synchronizeAllAttributes(); |
| 1213 | other->synchronizeAllAttributes(); |
| 1214 | if (elementData() == other->elementData()) |
| 1215 | return true; |
| 1216 | if (elementData()) |
| 1217 | return elementData()->isEquivalent(other->elementData()); |
| 1218 | if (other->elementData()) |
| 1219 | return other->elementData()->isEquivalent(elementData()); |
| 1220 | return true; |
| 1221 | } |
| 1222 | |
| 1223 | String Element::nodeName() const |
| 1224 | { |
| 1225 | return m_tagName.toString(); |
| 1226 | } |
| 1227 | |
| 1228 | String Element::nodeNamePreservingCase() const |
| 1229 | { |
| 1230 | return m_tagName.toString(); |
| 1231 | } |
| 1232 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1233 | void Element::setPrefix(const AtomicString& prefix, ExceptionState& exceptionState) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1234 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1235 | checkSetPrefix(prefix, exceptionState); |
| 1236 | if (exceptionState.hadException()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1237 | return; |
| 1238 | |
| 1239 | m_tagName.setPrefix(prefix.isEmpty() ? AtomicString() : prefix); |
| 1240 | } |
| 1241 | |
| 1242 | KURL Element::baseURI() const |
| 1243 | { |
| 1244 | const AtomicString& baseAttribute = getAttribute(baseAttr); |
| 1245 | KURL base(KURL(), baseAttribute); |
| 1246 | if (!base.protocol().isEmpty()) |
| 1247 | return base; |
| 1248 | |
| 1249 | ContainerNode* parent = parentNode(); |
| 1250 | if (!parent) |
| 1251 | return base; |
| 1252 | |
| 1253 | const KURL& parentBase = parent->baseURI(); |
| 1254 | if (parentBase.isNull()) |
| 1255 | return base; |
| 1256 | |
| 1257 | return KURL(parentBase, baseAttribute); |
| 1258 | } |
| 1259 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1260 | const AtomicString Element::imageSourceURL() const |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1261 | { |
| 1262 | return getAttribute(srcAttr); |
| 1263 | } |
| 1264 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1265 | bool Element::rendererIsNeeded(const RenderStyle& style) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1266 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1267 | return style.display() != NONE; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1268 | } |
| 1269 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1270 | RenderObject* Element::createRenderer(RenderStyle* style) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1271 | { |
| 1272 | return RenderObject::createObject(this, style); |
| 1273 | } |
| 1274 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1275 | Node::InsertionNotificationRequest Element::insertedInto(ContainerNode* insertionPoint) |
| 1276 | { |
| 1277 | // need to do superclass processing first so inDocument() is true |
| 1278 | // by the time we reach updateId |
| 1279 | ContainerNode::insertedInto(insertionPoint); |
| 1280 | |
| 1281 | if (containsFullScreenElement() && parentElement() && !parentElement()->containsFullScreenElement()) |
| 1282 | setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(true); |
| 1283 | |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 1284 | ASSERT(!hasRareData() || !elementRareData()->hasPseudoElements()); |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 1285 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1286 | if (!insertionPoint->isInTreeScope()) |
| 1287 | return InsertionDone; |
| 1288 | |
| 1289 | if (hasRareData()) |
| 1290 | elementRareData()->clearClassListValueForQuirksMode(); |
| 1291 | |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 1292 | if (isUpgradedCustomElement() && inDocument()) |
| 1293 | CustomElement::didEnterDocument(this, document()); |
| 1294 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1295 | TreeScope& scope = insertionPoint->treeScope(); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1296 | if (scope != treeScope()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1297 | return InsertionDone; |
| 1298 | |
| 1299 | const AtomicString& idValue = getIdAttribute(); |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 1300 | if (!idValue.isNull()) |
| 1301 | updateId(scope, nullAtom, idValue); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1302 | |
| 1303 | const AtomicString& nameValue = getNameAttribute(); |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 1304 | if (!nameValue.isNull()) |
| 1305 | updateName(nullAtom, nameValue); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1306 | |
| 1307 | if (hasTagName(labelTag)) { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1308 | if (scope.shouldCacheLabelsByForAttribute()) |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 1309 | updateLabel(scope, nullAtom, fastGetAttribute(forAttr)); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1310 | } |
| 1311 | |
Ben Murdoch | 3c9e4ae | 2013-08-12 14:20:44 +0100 | [diff] [blame] | 1312 | if (parentElement() && parentElement()->isInCanvasSubtree()) |
| 1313 | setIsInCanvasSubtree(true); |
| 1314 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1315 | return InsertionDone; |
| 1316 | } |
| 1317 | |
| 1318 | void Element::removedFrom(ContainerNode* insertionPoint) |
| 1319 | { |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 1320 | bool wasInDocument = insertionPoint->inDocument(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1321 | |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 1322 | ASSERT(!hasRareData() || !elementRareData()->hasPseudoElements()); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1323 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1324 | if (containsFullScreenElement()) |
| 1325 | setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(false); |
| 1326 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1327 | if (document().page()) |
| 1328 | document().page()->pointerLockController().elementRemoved(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1329 | |
| 1330 | setSavedLayerScrollOffset(IntSize()); |
| 1331 | |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1332 | if (insertionPoint->isInTreeScope() && treeScope() == document()) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1333 | const AtomicString& idValue = getIdAttribute(); |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 1334 | if (!idValue.isNull()) |
| 1335 | updateId(insertionPoint->treeScope(), idValue, nullAtom); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1336 | |
| 1337 | const AtomicString& nameValue = getNameAttribute(); |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 1338 | if (!nameValue.isNull()) |
| 1339 | updateName(nameValue, nullAtom); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1340 | |
| 1341 | if (hasTagName(labelTag)) { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1342 | TreeScope& treeScope = insertionPoint->treeScope(); |
| 1343 | if (treeScope.shouldCacheLabelsByForAttribute()) |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 1344 | updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | ContainerNode::removedFrom(insertionPoint); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1349 | if (wasInDocument) { |
| 1350 | if (hasPendingResources()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1351 | document().accessSVGExtensions()->removeElementFromPendingResources(this); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1352 | |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1353 | if (isUpgradedCustomElement()) |
Ben Murdoch | fff8884 | 2013-07-30 15:20:09 +0100 | [diff] [blame] | 1354 | CustomElement::didLeaveDocument(this, insertionPoint->document()); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1355 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1356 | |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 1357 | document().removeFromTopLayer(this); |
| 1358 | |
Ben Murdoch | 3c9e4ae | 2013-08-12 14:20:44 +0100 | [diff] [blame] | 1359 | if (hasRareData()) |
| 1360 | elementRareData()->setIsInCanvasSubtree(false); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1361 | } |
| 1362 | |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 1363 | void Element::attach(const AttachContext& context) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1364 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1365 | ASSERT(document().inStyleRecalc()); |
| 1366 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1367 | StyleResolverParentPusher parentPusher(*this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1368 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1369 | // We've already been through detach when doing an attach, but we might |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 1370 | // need to clear any state that's been added since then. |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1371 | if (hasRareData() && styleChangeType() == NeedsReattachStyleChange) { |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 1372 | ElementRareData* data = elementRareData(); |
| 1373 | data->clearComputedStyle(); |
| 1374 | data->resetDynamicRestyleObservations(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1375 | // Only clear the style state if we're not going to reuse the style from recalcStyle. |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 1376 | if (!context.resolvedStyle) |
| 1377 | data->resetStyleState(); |
| 1378 | } |
| 1379 | |
Ben Murdoch | 3c9e4ae | 2013-08-12 14:20:44 +0100 | [diff] [blame] | 1380 | NodeRenderingContext(this, context.resolvedStyle).createRendererForElementIfNeeded(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1381 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1382 | addCallbackSelectors(); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1383 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1384 | createPseudoElementIfNeeded(BEFORE); |
| 1385 | |
| 1386 | // When a shadow root exists, it does the work of attaching the children. |
| 1387 | if (ElementShadow* shadow = this->shadow()) { |
| 1388 | parentPusher.push(); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1389 | shadow->attach(context); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1390 | } else if (firstChild()) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1391 | parentPusher.push(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1392 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1393 | |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 1394 | ContainerNode::attach(context); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1395 | |
| 1396 | createPseudoElementIfNeeded(AFTER); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1397 | createPseudoElementIfNeeded(BACKDROP); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1398 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1399 | if (hasRareData()) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1400 | ElementRareData* data = elementRareData(); |
| 1401 | if (data->needsFocusAppearanceUpdateSoonAfterAttach()) { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1402 | if (isFocusable() && document().focusedElement() == this) |
| 1403 | document().updateFocusAppearanceSoon(false /* don't restore selection */); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1404 | data->setNeedsFocusAppearanceUpdateSoonAfterAttach(false); |
| 1405 | } |
| 1406 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1407 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1408 | InspectorInstrumentation::didRecalculateStyleForElement(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | void Element::unregisterNamedFlowContentNode() |
| 1412 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1413 | if (RuntimeEnabledFeatures::cssRegionsEnabled() && inNamedFlow() && document().renderView()) |
| 1414 | document().renderView()->flowThreadController()->unregisterNamedFlowContentNode(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1415 | } |
| 1416 | |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 1417 | void Element::detach(const AttachContext& context) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1418 | { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1419 | RenderWidget::UpdateSuspendScope suspendWidgetHierarchyUpdates; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1420 | unregisterNamedFlowContentNode(); |
| 1421 | cancelFocusAppearanceUpdate(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1422 | removeCallbackSelectors(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1423 | if (hasRareData()) { |
| 1424 | ElementRareData* data = elementRareData(); |
| 1425 | data->setPseudoElement(BEFORE, 0); |
| 1426 | data->setPseudoElement(AFTER, 0); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1427 | data->setPseudoElement(BACKDROP, 0); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1428 | data->setIsInsideRegion(false); |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 1429 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1430 | // attach() will perform the below steps for us when inside recalcStyle. |
| 1431 | if (!document().inStyleRecalc()) { |
Ben Murdoch | 3c9e4ae | 2013-08-12 14:20:44 +0100 | [diff] [blame] | 1432 | data->resetStyleState(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1433 | data->clearComputedStyle(); |
| 1434 | data->resetDynamicRestyleObservations(); |
| 1435 | } |
Ben Murdoch | 3c9e4ae | 2013-08-12 14:20:44 +0100 | [diff] [blame] | 1436 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1437 | if (RuntimeEnabledFeatures::webAnimationsCSSEnabled()) { |
| 1438 | if (ActiveAnimations* activeAnimations = data->activeAnimations()) { |
| 1439 | if (context.performingReattach) { |
| 1440 | // FIXME: restart compositor animations rather than pull back to the main thread |
| 1441 | activeAnimations->cancelAnimationOnCompositor(); |
| 1442 | } else { |
| 1443 | activeAnimations->cssAnimations().cancel(); |
| 1444 | } |
| 1445 | } |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 1446 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1447 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1448 | if (ElementShadow* shadow = this->shadow()) |
| 1449 | shadow->detach(context); |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 1450 | ContainerNode::detach(context); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | bool Element::pseudoStyleCacheIsInvalid(const RenderStyle* currentStyle, RenderStyle* newStyle) |
| 1454 | { |
| 1455 | ASSERT(currentStyle == renderStyle()); |
| 1456 | ASSERT(renderer()); |
| 1457 | |
| 1458 | if (!currentStyle) |
| 1459 | return false; |
| 1460 | |
| 1461 | const PseudoStyleCache* pseudoStyleCache = currentStyle->cachedPseudoStyles(); |
| 1462 | if (!pseudoStyleCache) |
| 1463 | return false; |
| 1464 | |
| 1465 | size_t cacheSize = pseudoStyleCache->size(); |
| 1466 | for (size_t i = 0; i < cacheSize; ++i) { |
| 1467 | RefPtr<RenderStyle> newPseudoStyle; |
| 1468 | PseudoId pseudoId = pseudoStyleCache->at(i)->styleType(); |
| 1469 | if (pseudoId == FIRST_LINE || pseudoId == FIRST_LINE_INHERITED) |
| 1470 | newPseudoStyle = renderer()->uncachedFirstLineStyle(newStyle); |
| 1471 | else |
| 1472 | newPseudoStyle = renderer()->getUncachedPseudoStyle(PseudoStyleRequest(pseudoId), newStyle, newStyle); |
| 1473 | if (!newPseudoStyle) |
| 1474 | return true; |
| 1475 | if (*newPseudoStyle != *pseudoStyleCache->at(i)) { |
| 1476 | if (pseudoId < FIRST_INTERNAL_PSEUDOID) |
| 1477 | newStyle->setHasPseudoStyle(pseudoId); |
| 1478 | newStyle->addCachedPseudoStyle(newPseudoStyle); |
| 1479 | if (pseudoId == FIRST_LINE || pseudoId == FIRST_LINE_INHERITED) { |
| 1480 | // FIXME: We should do an actual diff to determine whether a repaint vs. layout |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1481 | // is needed, but for now just assume a layout will be required. The diff code |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1482 | // in RenderObject::setStyle would need to be factored out so that it could be reused. |
| 1483 | renderer()->setNeedsLayoutAndPrefWidthsRecalc(); |
| 1484 | } |
| 1485 | return true; |
| 1486 | } |
| 1487 | } |
| 1488 | return false; |
| 1489 | } |
| 1490 | |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 1491 | PassRefPtr<RenderStyle> Element::styleForRenderer() |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1492 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 1493 | ASSERT(document().inStyleRecalc()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1494 | |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 1495 | RefPtr<RenderStyle> style; |
| 1496 | |
| 1497 | // FIXME: Instead of clearing updates that may have been added from calls to styleForElement |
| 1498 | // outside recalcStyle, we should just never set them if we're not inside recalcStyle. |
| 1499 | if (ActiveAnimations* activeAnimations = this->activeAnimations()) |
| 1500 | activeAnimations->cssAnimations().setPendingUpdate(nullptr); |
| 1501 | |
| 1502 | if (hasCustomStyleCallbacks()) |
| 1503 | style = customStyleForRenderer(); |
| 1504 | if (!style) |
| 1505 | style = originalStyleForRenderer(); |
| 1506 | |
| 1507 | // styleForElement() might add active animations so we need to get it again. |
| 1508 | if (ActiveAnimations* activeAnimations = this->activeAnimations()) |
| 1509 | activeAnimations->cssAnimations().maybeApplyPendingUpdate(this); |
| 1510 | |
| 1511 | ASSERT(style); |
| 1512 | return style.release(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1513 | } |
| 1514 | |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 1515 | PassRefPtr<RenderStyle> Element::originalStyleForRenderer() |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 1516 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 1517 | ASSERT(document().inStyleRecalc()); |
| 1518 | return document().ensureStyleResolver().styleForElement(this); |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 1519 | } |
| 1520 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1521 | void Element::recalcStyle(StyleRecalcChange change, Text* nextTextSibling) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1522 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1523 | ASSERT(document().inStyleRecalc()); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1524 | ASSERT(!parentOrShadowHostNode()->needsStyleRecalc()); |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 1525 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 1526 | if (hasCustomStyleCallbacks()) |
| 1527 | willRecalcStyle(change); |
| 1528 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1529 | if (change >= Inherit || needsStyleRecalc()) { |
| 1530 | if (hasRareData()) { |
| 1531 | ElementRareData* data = elementRareData(); |
| 1532 | data->resetStyleState(); |
| 1533 | data->clearComputedStyle(); |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 1534 | |
| 1535 | if (change >= Inherit) { |
| 1536 | if (ActiveAnimations* activeAnimations = data->activeAnimations()) |
| 1537 | activeAnimations->setAnimationStyleChange(false); |
| 1538 | } |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1539 | } |
| 1540 | if (parentRenderStyle()) |
| 1541 | change = recalcOwnStyle(change); |
| 1542 | clearNeedsStyleRecalc(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1543 | } |
Ben Murdoch | 3c9e4ae | 2013-08-12 14:20:44 +0100 | [diff] [blame] | 1544 | |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1545 | // If we reattached we don't need to recalc the style of our descendants anymore. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1546 | if ((change >= Inherit && change < Reattach) || childNeedsStyleRecalc()) |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1547 | recalcChildStyle(change); |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1548 | clearChildNeedsStyleRecalc(); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1549 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 1550 | if (hasCustomStyleCallbacks()) |
| 1551 | didRecalcStyle(change); |
| 1552 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1553 | if (change == Reattach) |
| 1554 | reattachWhitespaceSiblings(nextTextSibling); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1555 | } |
| 1556 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1557 | StyleRecalcChange Element::recalcOwnStyle(StyleRecalcChange change) |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1558 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1559 | ASSERT(document().inStyleRecalc()); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1560 | ASSERT(!parentOrShadowHostNode()->needsStyleRecalc()); |
| 1561 | ASSERT(change >= Inherit || needsStyleRecalc()); |
| 1562 | ASSERT(parentRenderStyle()); |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1563 | |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1564 | RefPtr<RenderStyle> oldStyle = renderStyle(); |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 1565 | RefPtr<RenderStyle> newStyle = styleForRenderer(); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1566 | StyleRecalcChange localChange = RenderStyle::compare(oldStyle.get(), newStyle.get()); |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1567 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1568 | ASSERT(newStyle); |
| 1569 | |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1570 | if (localChange == Reattach) { |
| 1571 | AttachContext reattachContext; |
| 1572 | reattachContext.resolvedStyle = newStyle.get(); |
| 1573 | reattach(reattachContext); |
| 1574 | return Reattach; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1575 | } |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1576 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1577 | ASSERT(oldStyle); |
| 1578 | |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1579 | InspectorInstrumentation::didRecalculateStyleForElement(this); |
| 1580 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1581 | if (localChange != NoChange) |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1582 | updateCallbackSelectors(oldStyle.get(), newStyle.get()); |
| 1583 | |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1584 | if (RenderObject* renderer = this->renderer()) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1585 | if (localChange != NoChange || pseudoStyleCacheIsInvalid(oldStyle.get(), newStyle.get()) || shouldNotifyRendererWithIdenticalStyles()) { |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1586 | renderer->setAnimatableStyle(newStyle.get()); |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 1587 | } else { |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1588 | // Although no change occurred, we use the new style so that the cousin style sharing code won't get |
| 1589 | // fooled into believing this style is the same. |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 1590 | // FIXME: We may be able to remove this hack, see discussion in |
| 1591 | // https://codereview.chromium.org/30453002/ |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1592 | renderer->setStyleInternal(newStyle.get()); |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | // If "rem" units are used anywhere in the document, and if the document element's font size changes, then go ahead and force font updating |
| 1597 | // all the way down the tree. This is simpler than having to maintain a cache of objects (and such font size changes should be rare anyway). |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1598 | if (document().styleEngine()->usesRemUnits() && document().documentElement() == this && oldStyle->fontSize() != newStyle->fontSize()) { |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1599 | // Cached RenderStyles may depend on the re units. |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 1600 | document().ensureStyleResolver().invalidateMatchedPropertiesCache(); |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1601 | return Force; |
| 1602 | } |
| 1603 | |
| 1604 | if (styleChangeType() >= SubtreeStyleChange) |
| 1605 | return Force; |
| 1606 | |
| 1607 | return max(localChange, change); |
| 1608 | } |
| 1609 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1610 | void Element::recalcChildStyle(StyleRecalcChange change) |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1611 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1612 | ASSERT(document().inStyleRecalc()); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1613 | ASSERT(change >= Inherit || childNeedsStyleRecalc()); |
| 1614 | ASSERT(!needsStyleRecalc()); |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 1615 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1616 | StyleResolverParentPusher parentPusher(*this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1617 | |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 1618 | for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot()) { |
| 1619 | if (shouldRecalcStyle(change, root)) { |
| 1620 | parentPusher.push(); |
| 1621 | root->recalcStyle(change); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | if (shouldRecalcStyle(change, this)) |
| 1626 | updatePseudoElement(BEFORE, change); |
| 1627 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1628 | if (change < Force && hasRareData() && childNeedsStyleRecalc()) |
| 1629 | checkForChildrenAdjacentRuleChanges(); |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 1630 | |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1631 | // This loop is deliberately backwards because we use insertBefore in the rendering tree, and want to avoid |
| 1632 | // a potentially n^2 loop to find the insertion point while resolving style. Having us start from the last |
| 1633 | // child and work our way back means in the common case, we'll find the insertion point in O(1) time. |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1634 | // See crbug.com/288225 |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 1635 | StyleResolver& styleResolver = document().ensureStyleResolver(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1636 | Text* lastTextNode = 0; |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1637 | for (Node* child = lastChild(); child; child = child->previousSibling()) { |
| 1638 | if (child->isTextNode()) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1639 | toText(child)->recalcTextStyle(change, lastTextNode); |
| 1640 | lastTextNode = toText(child); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1641 | } else if (child->isElementNode()) { |
| 1642 | Element* element = toElement(child); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1643 | if (shouldRecalcStyle(change, element)) { |
| 1644 | parentPusher.push(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1645 | element->recalcStyle(change, lastTextNode); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 1646 | } else if (element->supportsStyleSharing()) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1647 | styleResolver.addToStyleSharingList(*element); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1648 | } |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1649 | if (element->renderer()) |
| 1650 | lastTextNode = 0; |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1651 | } |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 1652 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1653 | |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 1654 | if (shouldRecalcStyle(change, this)) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1655 | updatePseudoElement(AFTER, change); |
Torne (Richard Coles) | e1f1df5 | 2013-08-23 16:39:30 +0100 | [diff] [blame] | 1656 | updatePseudoElement(BACKDROP, change); |
| 1657 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1658 | } |
| 1659 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1660 | void Element::checkForChildrenAdjacentRuleChanges() |
| 1661 | { |
| 1662 | bool hasDirectAdjacentRules = childrenAffectedByDirectAdjacentRules(); |
| 1663 | bool hasIndirectAdjacentRules = childrenAffectedByForwardPositionalRules(); |
| 1664 | |
| 1665 | if (!hasDirectAdjacentRules && !hasIndirectAdjacentRules) |
| 1666 | return; |
| 1667 | |
| 1668 | unsigned forceCheckOfNextElementCount = 0; |
| 1669 | bool forceCheckOfAnyElementSibling = false; |
| 1670 | |
| 1671 | for (Node* child = firstChild(); child; child = child->nextSibling()) { |
| 1672 | if (!child->isElementNode()) |
| 1673 | continue; |
| 1674 | Element* element = toElement(child); |
| 1675 | bool childRulesChanged = element->needsStyleRecalc() && element->styleChangeType() >= SubtreeStyleChange; |
| 1676 | |
| 1677 | if (forceCheckOfNextElementCount || forceCheckOfAnyElementSibling) |
| 1678 | element->setNeedsStyleRecalc(); |
| 1679 | |
| 1680 | if (forceCheckOfNextElementCount) |
| 1681 | forceCheckOfNextElementCount--; |
| 1682 | |
| 1683 | if (childRulesChanged && hasDirectAdjacentRules) |
| 1684 | forceCheckOfNextElementCount = document().styleEngine()->maxDirectAdjacentSelectors(); |
| 1685 | |
| 1686 | forceCheckOfAnyElementSibling = forceCheckOfAnyElementSibling || (childRulesChanged && hasIndirectAdjacentRules); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | void Element::updateCallbackSelectors(RenderStyle* oldStyle, RenderStyle* newStyle) |
| 1691 | { |
| 1692 | Vector<String> emptyVector; |
| 1693 | const Vector<String>& oldCallbackSelectors = oldStyle ? oldStyle->callbackSelectors() : emptyVector; |
| 1694 | const Vector<String>& newCallbackSelectors = newStyle ? newStyle->callbackSelectors() : emptyVector; |
| 1695 | if (oldCallbackSelectors.isEmpty() && newCallbackSelectors.isEmpty()) |
| 1696 | return; |
| 1697 | if (oldCallbackSelectors != newCallbackSelectors) |
| 1698 | CSSSelectorWatch::from(document()).updateSelectorMatches(oldCallbackSelectors, newCallbackSelectors); |
| 1699 | } |
| 1700 | |
| 1701 | void Element::addCallbackSelectors() |
| 1702 | { |
| 1703 | updateCallbackSelectors(0, renderStyle()); |
| 1704 | } |
| 1705 | |
| 1706 | void Element::removeCallbackSelectors() |
| 1707 | { |
| 1708 | updateCallbackSelectors(renderStyle(), 0); |
| 1709 | } |
| 1710 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1711 | ElementShadow* Element::shadow() const |
| 1712 | { |
| 1713 | return hasRareData() ? elementRareData()->shadow() : 0; |
| 1714 | } |
| 1715 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 1716 | ElementShadow& Element::ensureShadow() |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1717 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 1718 | return ensureElementRareData().ensureShadow(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | void Element::didAffectSelector(AffectedSelectorMask mask) |
| 1722 | { |
| 1723 | setNeedsStyleRecalc(); |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 1724 | if (ElementShadow* elementShadow = shadowWhereNodeCanBeDistributed(*this)) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1725 | elementShadow->didAffectSelector(mask); |
| 1726 | } |
| 1727 | |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 1728 | void Element::setAnimationStyleChange(bool animationStyleChange) |
| 1729 | { |
| 1730 | if (ActiveAnimations* activeAnimations = elementRareData()->activeAnimations()) |
| 1731 | activeAnimations->setAnimationStyleChange(animationStyleChange); |
| 1732 | } |
| 1733 | |
| 1734 | void Element::setNeedsAnimationStyleRecalc() |
| 1735 | { |
| 1736 | if (styleChangeType() != NoStyleChange) |
| 1737 | return; |
| 1738 | |
| 1739 | setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); |
| 1740 | setAnimationStyleChange(true); |
| 1741 | } |
| 1742 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1743 | PassRefPtr<ShadowRoot> Element::createShadowRoot(ExceptionState& exceptionState) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1744 | { |
| 1745 | if (alwaysCreateUserAgentShadowRoot()) |
| 1746 | ensureUserAgentShadowRoot(); |
| 1747 | |
| 1748 | if (RuntimeEnabledFeatures::authorShadowDOMForAnyElementEnabled()) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1749 | return PassRefPtr<ShadowRoot>(ensureShadow().addShadowRoot(*this, ShadowRoot::AuthorShadowRoot)); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1750 | |
| 1751 | // Since some elements recreates shadow root dynamically, multiple shadow |
| 1752 | // subtrees won't work well in that element. Until they are fixed, we disable |
| 1753 | // adding author shadow root for them. |
| 1754 | if (!areAuthorShadowsAllowed()) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1755 | exceptionState.throwUninformativeAndGenericDOMException(HierarchyRequestError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1756 | return 0; |
| 1757 | } |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1758 | return PassRefPtr<ShadowRoot>(ensureShadow().addShadowRoot(*this, ShadowRoot::AuthorShadowRoot)); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | ShadowRoot* Element::shadowRoot() const |
| 1762 | { |
| 1763 | ElementShadow* elementShadow = shadow(); |
| 1764 | if (!elementShadow) |
| 1765 | return 0; |
| 1766 | ShadowRoot* shadowRoot = elementShadow->youngestShadowRoot(); |
| 1767 | if (shadowRoot->type() == ShadowRoot::AuthorShadowRoot) |
| 1768 | return shadowRoot; |
| 1769 | return 0; |
| 1770 | } |
| 1771 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 1772 | void Element::didAddShadowRoot(ShadowRoot&) |
| 1773 | { |
| 1774 | } |
| 1775 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1776 | ShadowRoot* Element::userAgentShadowRoot() const |
| 1777 | { |
| 1778 | if (ElementShadow* elementShadow = shadow()) { |
| 1779 | if (ShadowRoot* shadowRoot = elementShadow->oldestShadowRoot()) { |
| 1780 | ASSERT(shadowRoot->type() == ShadowRoot::UserAgentShadowRoot); |
| 1781 | return shadowRoot; |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | return 0; |
| 1786 | } |
| 1787 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1788 | ShadowRoot& Element::ensureUserAgentShadowRoot() |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1789 | { |
| 1790 | if (ShadowRoot* shadowRoot = userAgentShadowRoot()) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1791 | return *shadowRoot; |
| 1792 | ShadowRoot& shadowRoot = ensureShadow().addShadowRoot(*this, ShadowRoot::UserAgentShadowRoot); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1793 | didAddUserAgentShadowRoot(shadowRoot); |
| 1794 | return shadowRoot; |
| 1795 | } |
| 1796 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1797 | bool Element::childTypeAllowed(NodeType type) const |
| 1798 | { |
| 1799 | switch (type) { |
| 1800 | case ELEMENT_NODE: |
| 1801 | case TEXT_NODE: |
| 1802 | case COMMENT_NODE: |
| 1803 | case PROCESSING_INSTRUCTION_NODE: |
| 1804 | case CDATA_SECTION_NODE: |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1805 | return true; |
| 1806 | default: |
| 1807 | break; |
| 1808 | } |
| 1809 | return false; |
| 1810 | } |
| 1811 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1812 | void Element::checkForEmptyStyleChange(RenderStyle* style) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1813 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1814 | if (!style && !styleAffectedByEmpty()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1815 | return; |
| 1816 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1817 | if (!style || (styleAffectedByEmpty() && (!style->emptyState() || hasChildNodes()))) |
| 1818 | setNeedsStyleRecalc(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1819 | } |
| 1820 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1821 | void Element::checkForSiblingStyleChanges(bool finishedParsingCallback, Node* beforeChange, Node* afterChange, int childCountDelta) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1822 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1823 | if (!inActiveDocument() || document().hasPendingForcedStyleRecalc() || styleChangeType() >= SubtreeStyleChange) |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1824 | return; |
| 1825 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1826 | RenderStyle* style = renderStyle(); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1827 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1828 | // :empty selector. |
| 1829 | checkForEmptyStyleChange(style); |
| 1830 | |
| 1831 | if (!style || (needsStyleRecalc() && childrenAffectedByPositionalRules())) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1832 | return; |
| 1833 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1834 | // Forward positional selectors include the ~ selector, nth-child, nth-of-type, first-of-type and only-of-type. |
| 1835 | // Backward positional selectors include nth-last-child, nth-last-of-type, last-of-type and only-of-type. |
| 1836 | // We have to invalidate everything following the insertion point in the forward case, and everything before the insertion point in the |
| 1837 | // backward case. |
| 1838 | // |afterChange| is 0 in the parser callback case, so we won't do any work for the forward case if we don't have to. |
| 1839 | // For performance reasons we just mark the parent node as changed, since we don't want to make childrenChanged O(n^2) by crawling all our kids |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1840 | // here. recalcStyle will then force a walk of the children when it sees that this has happened. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1841 | if ((childrenAffectedByForwardPositionalRules() && afterChange) || (childrenAffectedByBackwardPositionalRules() && beforeChange)) { |
| 1842 | setNeedsStyleRecalc(); |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1843 | return; |
| 1844 | } |
| 1845 | |
| 1846 | // :first-child. In the parser callback case, we don't have to check anything, since we were right the first time. |
| 1847 | // In the DOM case, we only need to do something if |afterChange| is not 0. |
| 1848 | // |afterChange| is 0 in the parser case, so it works out that we'll skip this block. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1849 | if (childrenAffectedByFirstChildRules() && afterChange) { |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1850 | // Find our new first child. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1851 | Node* newFirstChild = firstElementChild(); |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1852 | RenderStyle* newFirstChildStyle = newFirstChild ? newFirstChild->renderStyle() : 0; |
| 1853 | |
| 1854 | // Find the first element node following |afterChange| |
| 1855 | Node* firstElementAfterInsertion = afterChange->isElementNode() ? afterChange : afterChange->nextElementSibling(); |
| 1856 | RenderStyle* firstElementAfterInsertionStyle = firstElementAfterInsertion ? firstElementAfterInsertion->renderStyle() : 0; |
| 1857 | |
| 1858 | // This is the insert/append case. |
| 1859 | if (newFirstChild != firstElementAfterInsertion && firstElementAfterInsertionStyle && firstElementAfterInsertionStyle->firstChildState()) |
| 1860 | firstElementAfterInsertion->setNeedsStyleRecalc(); |
| 1861 | |
| 1862 | // We also have to handle node removal. |
| 1863 | if (childCountDelta < 0 && newFirstChild == firstElementAfterInsertion && newFirstChild && (!newFirstChildStyle || !newFirstChildStyle->firstChildState())) |
| 1864 | newFirstChild->setNeedsStyleRecalc(); |
| 1865 | } |
| 1866 | |
| 1867 | // :last-child. In the parser callback case, we don't have to check anything, since we were right the first time. |
| 1868 | // In the DOM case, we only need to do something if |afterChange| is not 0. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1869 | if (childrenAffectedByLastChildRules() && beforeChange) { |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1870 | // Find our new last child. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1871 | Node* newLastChild = lastElementChild(); |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1872 | RenderStyle* newLastChildStyle = newLastChild ? newLastChild->renderStyle() : 0; |
| 1873 | |
| 1874 | // Find the last element node going backwards from |beforeChange| |
| 1875 | Node* lastElementBeforeInsertion = beforeChange->isElementNode() ? beforeChange : beforeChange->previousElementSibling(); |
| 1876 | RenderStyle* lastElementBeforeInsertionStyle = lastElementBeforeInsertion ? lastElementBeforeInsertion->renderStyle() : 0; |
| 1877 | |
| 1878 | if (newLastChild != lastElementBeforeInsertion && lastElementBeforeInsertionStyle && lastElementBeforeInsertionStyle->lastChildState()) |
| 1879 | lastElementBeforeInsertion->setNeedsStyleRecalc(); |
| 1880 | |
| 1881 | // We also have to handle node removal. The parser callback case is similar to node removal as well in that we need to change the last child |
| 1882 | // to match now. |
| 1883 | if ((childCountDelta < 0 || finishedParsingCallback) && newLastChild == lastElementBeforeInsertion && newLastChild && (!newLastChildStyle || !newLastChildStyle->lastChildState())) |
| 1884 | newLastChild->setNeedsStyleRecalc(); |
| 1885 | } |
| 1886 | |
| 1887 | // The + selector. We need to invalidate the first element following the insertion point. It is the only possible element |
| 1888 | // that could be affected by this DOM change. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1889 | if (childrenAffectedByDirectAdjacentRules() && afterChange) { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 1890 | if (Node* firstElementAfterInsertion = afterChange->isElementNode() ? afterChange : afterChange->nextElementSibling()) |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1891 | firstElementAfterInsertion->setNeedsStyleRecalc(); |
| 1892 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | void Element::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) |
| 1896 | { |
| 1897 | ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); |
| 1898 | if (changedByParser) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1899 | checkForEmptyStyleChange(renderStyle()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1900 | else |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1901 | checkForSiblingStyleChanges(false, beforeChange, afterChange, childCountDelta); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1902 | |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 1903 | if (ElementShadow* shadow = this->shadow()) |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 1904 | shadow->setNeedsDistributionRecalc(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | void Element::removeAllEventListeners() |
| 1908 | { |
| 1909 | ContainerNode::removeAllEventListeners(); |
| 1910 | if (ElementShadow* shadow = this->shadow()) |
| 1911 | shadow->removeAllEventListeners(); |
| 1912 | } |
| 1913 | |
| 1914 | void Element::beginParsingChildren() |
| 1915 | { |
| 1916 | clearIsParsingChildrenFinished(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | void Element::finishParsingChildren() |
| 1920 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1921 | setIsParsingChildrenFinished(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1922 | checkForSiblingStyleChanges(this, lastChild(), 0, 0); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | #ifndef NDEBUG |
| 1926 | void Element::formatForDebugger(char* buffer, unsigned length) const |
| 1927 | { |
| 1928 | StringBuilder result; |
| 1929 | String s; |
| 1930 | |
| 1931 | result.append(nodeName()); |
| 1932 | |
| 1933 | s = getIdAttribute(); |
| 1934 | if (s.length() > 0) { |
| 1935 | if (result.length() > 0) |
| 1936 | result.appendLiteral("; "); |
| 1937 | result.appendLiteral("id="); |
| 1938 | result.append(s); |
| 1939 | } |
| 1940 | |
| 1941 | s = getAttribute(classAttr); |
| 1942 | if (s.length() > 0) { |
| 1943 | if (result.length() > 0) |
| 1944 | result.appendLiteral("; "); |
| 1945 | result.appendLiteral("class="); |
| 1946 | result.append(s); |
| 1947 | } |
| 1948 | |
| 1949 | strncpy(buffer, result.toString().utf8().data(), length - 1); |
| 1950 | } |
| 1951 | #endif |
| 1952 | |
| 1953 | const Vector<RefPtr<Attr> >& Element::attrNodeList() |
| 1954 | { |
| 1955 | ASSERT(hasSyntheticAttrChildNodes()); |
| 1956 | return *attrNodeListForElement(this); |
| 1957 | } |
| 1958 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1959 | PassRefPtr<Attr> Element::setAttributeNode(Attr* attrNode, ExceptionState& exceptionState) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1960 | { |
| 1961 | if (!attrNode) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1962 | exceptionState.throwUninformativeAndGenericDOMException(TypeMismatchError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1963 | return 0; |
| 1964 | } |
| 1965 | |
| 1966 | RefPtr<Attr> oldAttrNode = attrIfExists(attrNode->qualifiedName()); |
| 1967 | if (oldAttrNode.get() == attrNode) |
| 1968 | return attrNode; // This Attr is already attached to the element. |
| 1969 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 1970 | // InUseAttributeError: Raised if node is an Attr that is already an attribute of another Element object. |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1971 | // The DOM user must explicitly clone Attr nodes to re-use them in other elements. |
| 1972 | if (attrNode->ownerElement()) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1973 | exceptionState.throwUninformativeAndGenericDOMException(InUseAttributeError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1974 | return 0; |
| 1975 | } |
| 1976 | |
| 1977 | synchronizeAllAttributes(); |
| 1978 | UniqueElementData* elementData = ensureUniqueElementData(); |
| 1979 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 1980 | size_t index = elementData->getAttributeItemIndex(attrNode->qualifiedName(), shouldIgnoreAttributeCase()); |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 1981 | if (index != kNotFound) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1982 | if (oldAttrNode) |
| 1983 | detachAttrNodeFromElementWithValue(oldAttrNode.get(), elementData->attributeItem(index)->value()); |
| 1984 | else |
| 1985 | oldAttrNode = Attr::create(document(), attrNode->qualifiedName(), elementData->attributeItem(index)->value()); |
| 1986 | } |
| 1987 | |
| 1988 | setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), NotInSynchronizationOfLazyAttribute); |
| 1989 | |
| 1990 | attrNode->attachToElement(this); |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 1991 | treeScope().adoptIfNeeded(*attrNode); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 1992 | ensureAttrNodeListForElement(this).append(attrNode); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1993 | |
| 1994 | return oldAttrNode.release(); |
| 1995 | } |
| 1996 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1997 | PassRefPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionState& exceptionState) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1998 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 1999 | return setAttributeNode(attr, exceptionState); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2000 | } |
| 2001 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2002 | PassRefPtr<Attr> Element::removeAttributeNode(Attr* attr, ExceptionState& exceptionState) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2003 | { |
| 2004 | if (!attr) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2005 | exceptionState.throwUninformativeAndGenericDOMException(TypeMismatchError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2006 | return 0; |
| 2007 | } |
| 2008 | if (attr->ownerElement() != this) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2009 | exceptionState.throwUninformativeAndGenericDOMException(NotFoundError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2010 | return 0; |
| 2011 | } |
| 2012 | |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 2013 | ASSERT(document() == attr->document()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2014 | |
| 2015 | synchronizeAttribute(attr->qualifiedName()); |
| 2016 | |
Torne (Richard Coles) | e524955 | 2013-05-15 11:35:13 +0100 | [diff] [blame] | 2017 | size_t index = elementData()->getAttrIndex(attr); |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 2018 | if (index == kNotFound) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2019 | exceptionState.throwUninformativeAndGenericDOMException(NotFoundError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2020 | return 0; |
| 2021 | } |
| 2022 | |
Torne (Richard Coles) | e524955 | 2013-05-15 11:35:13 +0100 | [diff] [blame] | 2023 | RefPtr<Attr> guard(attr); |
| 2024 | detachAttrNodeAtIndex(attr, index); |
| 2025 | return guard.release(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2026 | } |
| 2027 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2028 | bool Element::parseAttributeName(QualifiedName& out, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState& exceptionState) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2029 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 2030 | AtomicString prefix, localName; |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2031 | if (!Document::parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2032 | return false; |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2033 | ASSERT(!exceptionState.hadException()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2034 | |
| 2035 | QualifiedName qName(prefix, localName, namespaceURI); |
| 2036 | |
| 2037 | if (!Document::hasValidNamespaceForAttributes(qName)) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2038 | exceptionState.throwUninformativeAndGenericDOMException(NamespaceError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2039 | return false; |
| 2040 | } |
| 2041 | |
| 2042 | out = qName; |
| 2043 | return true; |
| 2044 | } |
| 2045 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2046 | void Element::setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionState& exceptionState) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2047 | { |
| 2048 | QualifiedName parsedName = anyName; |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2049 | if (!parseAttributeName(parsedName, namespaceURI, qualifiedName, exceptionState)) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2050 | return; |
| 2051 | setAttribute(parsedName, value); |
| 2052 | } |
| 2053 | |
| 2054 | void Element::removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute) |
| 2055 | { |
| 2056 | ASSERT_WITH_SECURITY_IMPLICATION(index < attributeCount()); |
| 2057 | |
| 2058 | UniqueElementData* elementData = ensureUniqueElementData(); |
| 2059 | |
| 2060 | QualifiedName name = elementData->attributeItem(index)->name(); |
| 2061 | AtomicString valueBeingRemoved = elementData->attributeItem(index)->value(); |
| 2062 | |
| 2063 | if (!inSynchronizationOfLazyAttribute) { |
| 2064 | if (!valueBeingRemoved.isNull()) |
| 2065 | willModifyAttribute(name, valueBeingRemoved, nullAtom); |
| 2066 | } |
| 2067 | |
| 2068 | if (RefPtr<Attr> attrNode = attrIfExists(name)) |
| 2069 | detachAttrNodeFromElementWithValue(attrNode.get(), elementData->attributeItem(index)->value()); |
| 2070 | |
| 2071 | elementData->removeAttribute(index); |
| 2072 | |
| 2073 | if (!inSynchronizationOfLazyAttribute) |
| 2074 | didRemoveAttribute(name); |
| 2075 | } |
| 2076 | |
| 2077 | void Element::addAttributeInternal(const QualifiedName& name, const AtomicString& value, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute) |
| 2078 | { |
| 2079 | if (!inSynchronizationOfLazyAttribute) |
| 2080 | willModifyAttribute(name, nullAtom, value); |
| 2081 | ensureUniqueElementData()->addAttribute(name, value); |
| 2082 | if (!inSynchronizationOfLazyAttribute) |
| 2083 | didAddAttribute(name, value); |
| 2084 | } |
| 2085 | |
| 2086 | void Element::removeAttribute(const AtomicString& name) |
| 2087 | { |
| 2088 | if (!elementData()) |
| 2089 | return; |
| 2090 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2091 | AtomicString localName = shouldIgnoreAttributeCase() ? name.lower() : name; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2092 | size_t index = elementData()->getAttributeItemIndex(localName, false); |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 2093 | if (index == kNotFound) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2094 | if (UNLIKELY(localName == styleAttr) && elementData()->m_styleAttributeIsDirty && isStyledElement()) |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2095 | removeAllInlineStyleProperties(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2096 | return; |
| 2097 | } |
| 2098 | |
| 2099 | removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute); |
| 2100 | } |
| 2101 | |
| 2102 | void Element::removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) |
| 2103 | { |
| 2104 | removeAttribute(QualifiedName(nullAtom, localName, namespaceURI)); |
| 2105 | } |
| 2106 | |
| 2107 | PassRefPtr<Attr> Element::getAttributeNode(const AtomicString& localName) |
| 2108 | { |
| 2109 | if (!elementData()) |
| 2110 | return 0; |
| 2111 | synchronizeAttribute(localName); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2112 | const Attribute* attribute = elementData()->getAttributeItem(localName, shouldIgnoreAttributeCase()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2113 | if (!attribute) |
| 2114 | return 0; |
| 2115 | return ensureAttr(attribute->name()); |
| 2116 | } |
| 2117 | |
| 2118 | PassRefPtr<Attr> Element::getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName) |
| 2119 | { |
| 2120 | if (!elementData()) |
| 2121 | return 0; |
| 2122 | QualifiedName qName(nullAtom, localName, namespaceURI); |
| 2123 | synchronizeAttribute(qName); |
| 2124 | const Attribute* attribute = elementData()->getAttributeItem(qName); |
| 2125 | if (!attribute) |
| 2126 | return 0; |
| 2127 | return ensureAttr(attribute->name()); |
| 2128 | } |
| 2129 | |
| 2130 | bool Element::hasAttribute(const AtomicString& localName) const |
| 2131 | { |
| 2132 | if (!elementData()) |
| 2133 | return false; |
| 2134 | synchronizeAttribute(localName); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2135 | return elementData()->getAttributeItem(shouldIgnoreAttributeCase() ? localName.lower() : localName, false); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | bool Element::hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const |
| 2139 | { |
| 2140 | if (!elementData()) |
| 2141 | return false; |
| 2142 | QualifiedName qName(nullAtom, localName, namespaceURI); |
| 2143 | synchronizeAttribute(qName); |
| 2144 | return elementData()->getAttributeItem(qName); |
| 2145 | } |
| 2146 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2147 | void Element::focus(bool restorePreviousSelection, FocusDirection direction) |
| 2148 | { |
| 2149 | if (!inDocument()) |
| 2150 | return; |
| 2151 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2152 | Document& doc = document(); |
| 2153 | if (doc.focusedElement() == this) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2154 | return; |
| 2155 | |
| 2156 | // If the stylesheets have already been loaded we can reliably check isFocusable. |
| 2157 | // If not, we continue and set the focused node on the focus controller below so |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2158 | // that it can be updated soon after attach. |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2159 | if (doc.haveStylesheetsLoaded()) { |
| 2160 | doc.updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2161 | if (!isFocusable()) |
| 2162 | return; |
| 2163 | } |
| 2164 | |
| 2165 | if (!supportsFocus()) |
| 2166 | return; |
| 2167 | |
| 2168 | RefPtr<Node> protect; |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2169 | if (Page* page = doc.page()) { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2170 | // Focus and change event handlers can cause us to lose our last ref. |
| 2171 | // If a focus event handler changes the focus to a different node it |
| 2172 | // does not make sense to continue and update appearence. |
| 2173 | protect = this; |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2174 | if (!page->focusController().setFocusedElement(this, doc.frame(), direction)) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2175 | return; |
| 2176 | } |
| 2177 | |
| 2178 | // Setting the focused node above might have invalidated the layout due to scripts. |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2179 | doc.updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2180 | |
| 2181 | if (!isFocusable()) { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2182 | ensureElementRareData().setNeedsFocusAppearanceUpdateSoonAfterAttach(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2183 | return; |
| 2184 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2185 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2186 | cancelFocusAppearanceUpdate(); |
| 2187 | updateFocusAppearance(restorePreviousSelection); |
| 2188 | } |
| 2189 | |
| 2190 | void Element::updateFocusAppearance(bool /*restorePreviousSelection*/) |
| 2191 | { |
| 2192 | if (isRootEditableElement()) { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2193 | Frame* frame = document().frame(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2194 | if (!frame) |
| 2195 | return; |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2196 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2197 | // When focusing an editable element in an iframe, don't reset the selection if it already contains a selection. |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2198 | if (this == frame->selection().rootEditableElement()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2199 | return; |
| 2200 | |
| 2201 | // FIXME: We should restore the previous selection if there is one. |
| 2202 | VisibleSelection newSelection = VisibleSelection(firstPositionInOrBeforeNode(this), DOWNSTREAM); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 2203 | frame->selection().setSelection(newSelection); |
| 2204 | frame->selection().revealSelection(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2205 | } else if (renderer() && !renderer()->isWidget()) |
| 2206 | renderer()->scrollRectToVisible(boundingBox()); |
| 2207 | } |
| 2208 | |
| 2209 | void Element::blur() |
| 2210 | { |
| 2211 | cancelFocusAppearanceUpdate(); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2212 | if (treeScope().adjustedFocusedElement() == this) { |
| 2213 | Document& doc = document(); |
| 2214 | if (doc.page()) |
| 2215 | doc.page()->focusController().setFocusedElement(0, doc.frame()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2216 | else |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2217 | doc.setFocusedElement(0); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 2221 | bool Element::isFocusable() const |
| 2222 | { |
| 2223 | return inDocument() && supportsFocus() && !isInert() && rendererIsFocusable(); |
| 2224 | } |
| 2225 | |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 2226 | bool Element::isKeyboardFocusable() const |
| 2227 | { |
| 2228 | return isFocusable() && tabIndex() >= 0; |
| 2229 | } |
| 2230 | |
| 2231 | bool Element::isMouseFocusable() const |
| 2232 | { |
| 2233 | return isFocusable(); |
| 2234 | } |
| 2235 | |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 2236 | void Element::dispatchFocusEvent(Element* oldFocusedElement, FocusDirection) |
| 2237 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2238 | RefPtr<FocusEvent> event = FocusEvent::create(EventTypeNames::focus, false, false, document().domWindow(), 0, oldFocusedElement); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 2239 | EventDispatcher::dispatchEvent(this, FocusEventDispatchMediator::create(event.release())); |
| 2240 | } |
| 2241 | |
| 2242 | void Element::dispatchBlurEvent(Element* newFocusedElement) |
| 2243 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2244 | RefPtr<FocusEvent> event = FocusEvent::create(EventTypeNames::blur, false, false, document().domWindow(), 0, newFocusedElement); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 2245 | EventDispatcher::dispatchEvent(this, BlurEventDispatchMediator::create(event.release())); |
| 2246 | } |
| 2247 | |
| 2248 | void Element::dispatchFocusInEvent(const AtomicString& eventType, Element* oldFocusedElement) |
| 2249 | { |
| 2250 | ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 2251 | ASSERT(eventType == EventTypeNames::focusin || eventType == EventTypeNames::DOMFocusIn); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2252 | dispatchScopedEventDispatchMediator(FocusInEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document().domWindow(), 0, oldFocusedElement))); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | void Element::dispatchFocusOutEvent(const AtomicString& eventType, Element* newFocusedElement) |
| 2256 | { |
| 2257 | ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 2258 | ASSERT(eventType == EventTypeNames::focusout || eventType == EventTypeNames::DOMFocusOut); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2259 | dispatchScopedEventDispatchMediator(FocusOutEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document().domWindow(), 0, newFocusedElement))); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 2260 | } |
| 2261 | |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2262 | String Element::innerHTML() const |
| 2263 | { |
| 2264 | return createMarkup(this, ChildrenOnly); |
| 2265 | } |
| 2266 | |
| 2267 | String Element::outerHTML() const |
| 2268 | { |
| 2269 | return createMarkup(this); |
| 2270 | } |
| 2271 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2272 | void Element::setInnerHTML(const String& html, ExceptionState& exceptionState) |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2273 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2274 | if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, "innerHTML", exceptionState)) { |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2275 | ContainerNode* container = this; |
| 2276 | if (hasTagName(templateTag)) |
| 2277 | container = toHTMLTemplateElement(this)->content(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2278 | replaceChildrenWithFragment(container, fragment.release(), exceptionState); |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2282 | void Element::setOuterHTML(const String& html, ExceptionState& exceptionState) |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2283 | { |
| 2284 | Node* p = parentNode(); |
| 2285 | if (!p || !p->isElementNode()) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2286 | exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowedError); |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2287 | return; |
| 2288 | } |
| 2289 | RefPtr<Element> parent = toElement(p); |
| 2290 | RefPtr<Node> prev = previousSibling(); |
| 2291 | RefPtr<Node> next = nextSibling(); |
| 2292 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2293 | RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, parent.get(), AllowScriptingContent, "outerHTML", exceptionState); |
| 2294 | if (exceptionState.hadException()) |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2295 | return; |
| 2296 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2297 | parent->replaceChild(fragment.release(), this, exceptionState); |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2298 | RefPtr<Node> node = next ? next->previousSibling() : 0; |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2299 | if (!exceptionState.hadException() && node && node->isTextNode()) |
| 2300 | mergeWithNextTextNode(node.release(), exceptionState); |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2301 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2302 | if (!exceptionState.hadException() && prev && prev->isTextNode()) |
| 2303 | mergeWithNextTextNode(prev.release(), exceptionState); |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2304 | } |
| 2305 | |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 2306 | Node* Element::insertAdjacent(const String& where, Node* newChild, ExceptionState& exceptionState) |
| 2307 | { |
| 2308 | if (equalIgnoringCase(where, "beforeBegin")) { |
| 2309 | if (ContainerNode* parent = this->parentNode()) { |
| 2310 | parent->insertBefore(newChild, this, exceptionState); |
| 2311 | if (!exceptionState.hadException()) |
| 2312 | return newChild; |
| 2313 | } |
| 2314 | return 0; |
| 2315 | } |
| 2316 | |
| 2317 | if (equalIgnoringCase(where, "afterBegin")) { |
| 2318 | insertBefore(newChild, firstChild(), exceptionState); |
| 2319 | return exceptionState.hadException() ? 0 : newChild; |
| 2320 | } |
| 2321 | |
| 2322 | if (equalIgnoringCase(where, "beforeEnd")) { |
| 2323 | appendChild(newChild, exceptionState); |
| 2324 | return exceptionState.hadException() ? 0 : newChild; |
| 2325 | } |
| 2326 | |
| 2327 | if (equalIgnoringCase(where, "afterEnd")) { |
| 2328 | if (ContainerNode* parent = this->parentNode()) { |
| 2329 | parent->insertBefore(newChild, nextSibling(), exceptionState); |
| 2330 | if (!exceptionState.hadException()) |
| 2331 | return newChild; |
| 2332 | } |
| 2333 | return 0; |
| 2334 | } |
| 2335 | |
| 2336 | exceptionState.throwDOMException(SyntaxError, "The value provided ('" + where + "') is not one of 'beforeBegin', 'afterBegin', 'beforeEnd', or 'afterEnd'."); |
| 2337 | return 0; |
| 2338 | } |
| 2339 | |
| 2340 | // Step 1 of http://domparsing.spec.whatwg.org/#insertadjacenthtml() |
| 2341 | static Element* contextElementForInsertion(const String& where, Element* element, ExceptionState& exceptionState) |
| 2342 | { |
| 2343 | if (equalIgnoringCase(where, "beforeBegin") || equalIgnoringCase(where, "afterEnd")) { |
| 2344 | ContainerNode* parent = element->parentNode(); |
| 2345 | if (!parent || !parent->isElementNode()) { |
| 2346 | exceptionState.throwDOMException(NoModificationAllowedError, "The element has no parent."); |
| 2347 | return 0; |
| 2348 | } |
| 2349 | return toElement(parent); |
| 2350 | } |
| 2351 | if (equalIgnoringCase(where, "afterBegin") || equalIgnoringCase(where, "beforeEnd")) |
| 2352 | return element; |
| 2353 | exceptionState.throwDOMException(SyntaxError, "The value provided ('" + where + "') is not one of 'beforeBegin', 'afterBegin', 'beforeEnd', or 'afterEnd'."); |
| 2354 | return 0; |
| 2355 | } |
| 2356 | |
| 2357 | void Element::insertAdjacentHTML(const String& where, const String& markup, ExceptionState& exceptionState) |
| 2358 | { |
| 2359 | RefPtr<Element> contextElement = contextElementForInsertion(where, this, exceptionState); |
| 2360 | if (!contextElement) |
| 2361 | return; |
| 2362 | |
| 2363 | RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, contextElement.get(), AllowScriptingContent, "insertAdjacentHTML", exceptionState); |
| 2364 | if (!fragment) |
| 2365 | return; |
| 2366 | insertAdjacent(where, fragment.get(), exceptionState); |
| 2367 | } |
| 2368 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2369 | String Element::innerText() |
| 2370 | { |
| 2371 | // We need to update layout, since plainText uses line boxes in the render tree. |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2372 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2373 | |
| 2374 | if (!renderer()) |
| 2375 | return textContent(true); |
| 2376 | |
| 2377 | return plainText(rangeOfContents(const_cast<Element*>(this)).get()); |
| 2378 | } |
| 2379 | |
| 2380 | String Element::outerText() |
| 2381 | { |
| 2382 | // Getting outerText is the same as getting innerText, only |
| 2383 | // setting is different. You would think this should get the plain |
| 2384 | // text for the outer range, but this is wrong, <br> for instance |
| 2385 | // would return different values for inner and outer text by such |
| 2386 | // a rule, but it doesn't in WinIE, and we want to match that. |
| 2387 | return innerText(); |
| 2388 | } |
| 2389 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2390 | String Element::textFromChildren() |
| 2391 | { |
| 2392 | Text* firstTextNode = 0; |
| 2393 | bool foundMultipleTextNodes = false; |
| 2394 | unsigned totalLength = 0; |
| 2395 | |
| 2396 | for (Node* child = firstChild(); child; child = child->nextSibling()) { |
| 2397 | if (!child->isTextNode()) |
| 2398 | continue; |
| 2399 | Text* text = toText(child); |
| 2400 | if (!firstTextNode) |
| 2401 | firstTextNode = text; |
| 2402 | else |
| 2403 | foundMultipleTextNodes = true; |
| 2404 | unsigned length = text->data().length(); |
| 2405 | if (length > std::numeric_limits<unsigned>::max() - totalLength) |
| 2406 | return emptyString(); |
| 2407 | totalLength += length; |
| 2408 | } |
| 2409 | |
| 2410 | if (!firstTextNode) |
| 2411 | return emptyString(); |
| 2412 | |
| 2413 | if (firstTextNode && !foundMultipleTextNodes) { |
| 2414 | firstTextNode->atomize(); |
| 2415 | return firstTextNode->data(); |
| 2416 | } |
| 2417 | |
| 2418 | StringBuilder content; |
| 2419 | content.reserveCapacity(totalLength); |
| 2420 | for (Node* child = firstTextNode; child; child = child->nextSibling()) { |
| 2421 | if (!child->isTextNode()) |
| 2422 | continue; |
| 2423 | content.append(toText(child)->data()); |
| 2424 | } |
| 2425 | |
| 2426 | ASSERT(content.length() == totalLength); |
| 2427 | return content.toString(); |
| 2428 | } |
| 2429 | |
Ben Murdoch | 3c9e4ae | 2013-08-12 14:20:44 +0100 | [diff] [blame] | 2430 | // pseudo is used via shadowPseudoId. |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2431 | const AtomicString& Element::pseudo() const |
| 2432 | { |
| 2433 | return getAttribute(pseudoAttr); |
| 2434 | } |
| 2435 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2436 | void Element::setPseudo(const AtomicString& value) |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 2437 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2438 | setAttribute(pseudoAttr, value); |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 2439 | } |
| 2440 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2441 | bool Element::isInDescendantTreeOf(const Element* shadowHost) const |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 2442 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2443 | ASSERT(shadowHost); |
| 2444 | ASSERT(isShadowHost(shadowHost)); |
| 2445 | |
| 2446 | const ShadowRoot* shadowRoot = containingShadowRoot(); |
| 2447 | while (shadowRoot) { |
| 2448 | const Element* ancestorShadowHost = shadowRoot->shadowHost(); |
| 2449 | if (ancestorShadowHost == shadowHost) |
| 2450 | return true; |
| 2451 | shadowRoot = ancestorShadowHost->containingShadowRoot(); |
| 2452 | } |
| 2453 | return false; |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 2454 | } |
| 2455 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2456 | LayoutSize Element::minimumSizeForResizing() const |
| 2457 | { |
| 2458 | return hasRareData() ? elementRareData()->minimumSizeForResizing() : defaultMinimumSizeForResizing(); |
| 2459 | } |
| 2460 | |
| 2461 | void Element::setMinimumSizeForResizing(const LayoutSize& size) |
| 2462 | { |
| 2463 | if (!hasRareData() && size == defaultMinimumSizeForResizing()) |
| 2464 | return; |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2465 | ensureElementRareData().setMinimumSizeForResizing(size); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | RenderStyle* Element::computedStyle(PseudoId pseudoElementSpecifier) |
| 2469 | { |
| 2470 | if (PseudoElement* element = pseudoElement(pseudoElementSpecifier)) |
| 2471 | return element->computedStyle(); |
| 2472 | |
| 2473 | // FIXME: Find and use the renderer from the pseudo element instead of the actual element so that the 'length' |
| 2474 | // properties, which are only known by the renderer because it did the layout, will be correct and so that the |
| 2475 | // values returned for the ":selection" pseudo-element will be correct. |
| 2476 | if (RenderStyle* usedStyle = renderStyle()) { |
| 2477 | if (pseudoElementSpecifier) { |
| 2478 | RenderStyle* cachedPseudoStyle = usedStyle->getCachedPseudoStyle(pseudoElementSpecifier); |
| 2479 | return cachedPseudoStyle ? cachedPseudoStyle : usedStyle; |
| 2480 | } else |
| 2481 | return usedStyle; |
| 2482 | } |
| 2483 | |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 2484 | if (!inActiveDocument()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2485 | // FIXME: Try to do better than this. Ensure that styleForElement() works for elements that are not in the |
| 2486 | // document tree and figure out when to destroy the computed style for such elements. |
| 2487 | return 0; |
| 2488 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2489 | ElementRareData& rareData = ensureElementRareData(); |
| 2490 | if (!rareData.computedStyle()) |
| 2491 | rareData.setComputedStyle(document().styleForElementIgnoringPendingStylesheets(this)); |
| 2492 | return pseudoElementSpecifier ? rareData.computedStyle()->getCachedPseudoStyle(pseudoElementSpecifier) : rareData.computedStyle(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | void Element::setStyleAffectedByEmpty() |
| 2496 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2497 | ensureElementRareData().setStyleAffectedByEmpty(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2498 | } |
| 2499 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2500 | void Element::setChildrenAffectedByFocus() |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2501 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2502 | ensureElementRareData().setChildrenAffectedByFocus(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2503 | } |
| 2504 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2505 | void Element::setChildrenAffectedByHover() |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2506 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2507 | ensureElementRareData().setChildrenAffectedByHover(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2508 | } |
| 2509 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2510 | void Element::setChildrenAffectedByActive() |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2511 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2512 | ensureElementRareData().setChildrenAffectedByActive(true); |
| 2513 | } |
| 2514 | |
| 2515 | void Element::setChildrenAffectedByDrag() |
| 2516 | { |
| 2517 | ensureElementRareData().setChildrenAffectedByDrag(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | void Element::setChildrenAffectedByFirstChildRules() |
| 2521 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2522 | ensureElementRareData().setChildrenAffectedByFirstChildRules(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | void Element::setChildrenAffectedByLastChildRules() |
| 2526 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2527 | ensureElementRareData().setChildrenAffectedByLastChildRules(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | void Element::setChildrenAffectedByDirectAdjacentRules() |
| 2531 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2532 | ensureElementRareData().setChildrenAffectedByDirectAdjacentRules(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | void Element::setChildrenAffectedByForwardPositionalRules() |
| 2536 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2537 | ensureElementRareData().setChildrenAffectedByForwardPositionalRules(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | void Element::setChildrenAffectedByBackwardPositionalRules() |
| 2541 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2542 | ensureElementRareData().setChildrenAffectedByBackwardPositionalRules(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | void Element::setChildIndex(unsigned index) |
| 2546 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2547 | ElementRareData& rareData = ensureElementRareData(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2548 | if (RenderStyle* style = renderStyle()) |
| 2549 | style->setUnique(); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2550 | rareData.setChildIndex(index); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2551 | } |
| 2552 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2553 | bool Element::childrenSupportStyleSharing() const |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2554 | { |
| 2555 | if (!hasRareData()) |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2556 | return true; |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2557 | return !rareDataChildrenAffectedByFocus() |
| 2558 | && !rareDataChildrenAffectedByHover() |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2559 | && !rareDataChildrenAffectedByActive() |
| 2560 | && !rareDataChildrenAffectedByDrag() |
| 2561 | && !rareDataChildrenAffectedByFirstChildRules() |
| 2562 | && !rareDataChildrenAffectedByLastChildRules() |
| 2563 | && !rareDataChildrenAffectedByDirectAdjacentRules() |
| 2564 | && !rareDataChildrenAffectedByForwardPositionalRules() |
| 2565 | && !rareDataChildrenAffectedByBackwardPositionalRules(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | bool Element::rareDataStyleAffectedByEmpty() const |
| 2569 | { |
| 2570 | ASSERT(hasRareData()); |
| 2571 | return elementRareData()->styleAffectedByEmpty(); |
| 2572 | } |
| 2573 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2574 | bool Element::rareDataChildrenAffectedByFocus() const |
| 2575 | { |
| 2576 | ASSERT(hasRareData()); |
| 2577 | return elementRareData()->childrenAffectedByFocus(); |
| 2578 | } |
| 2579 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2580 | bool Element::rareDataChildrenAffectedByHover() const |
| 2581 | { |
| 2582 | ASSERT(hasRareData()); |
| 2583 | return elementRareData()->childrenAffectedByHover(); |
| 2584 | } |
| 2585 | |
| 2586 | bool Element::rareDataChildrenAffectedByActive() const |
| 2587 | { |
| 2588 | ASSERT(hasRareData()); |
| 2589 | return elementRareData()->childrenAffectedByActive(); |
| 2590 | } |
| 2591 | |
| 2592 | bool Element::rareDataChildrenAffectedByDrag() const |
| 2593 | { |
| 2594 | ASSERT(hasRareData()); |
| 2595 | return elementRareData()->childrenAffectedByDrag(); |
| 2596 | } |
| 2597 | |
| 2598 | bool Element::rareDataChildrenAffectedByFirstChildRules() const |
| 2599 | { |
| 2600 | ASSERT(hasRareData()); |
| 2601 | return elementRareData()->childrenAffectedByFirstChildRules(); |
| 2602 | } |
| 2603 | |
| 2604 | bool Element::rareDataChildrenAffectedByLastChildRules() const |
| 2605 | { |
| 2606 | ASSERT(hasRareData()); |
| 2607 | return elementRareData()->childrenAffectedByLastChildRules(); |
| 2608 | } |
| 2609 | |
| 2610 | bool Element::rareDataChildrenAffectedByDirectAdjacentRules() const |
| 2611 | { |
| 2612 | ASSERT(hasRareData()); |
| 2613 | return elementRareData()->childrenAffectedByDirectAdjacentRules(); |
| 2614 | } |
| 2615 | |
| 2616 | bool Element::rareDataChildrenAffectedByForwardPositionalRules() const |
| 2617 | { |
| 2618 | ASSERT(hasRareData()); |
| 2619 | return elementRareData()->childrenAffectedByForwardPositionalRules(); |
| 2620 | } |
| 2621 | |
| 2622 | bool Element::rareDataChildrenAffectedByBackwardPositionalRules() const |
| 2623 | { |
| 2624 | ASSERT(hasRareData()); |
| 2625 | return elementRareData()->childrenAffectedByBackwardPositionalRules(); |
| 2626 | } |
| 2627 | |
| 2628 | unsigned Element::rareDataChildIndex() const |
| 2629 | { |
| 2630 | ASSERT(hasRareData()); |
| 2631 | return elementRareData()->childIndex(); |
| 2632 | } |
| 2633 | |
| 2634 | void Element::setIsInCanvasSubtree(bool isInCanvasSubtree) |
| 2635 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2636 | ensureElementRareData().setIsInCanvasSubtree(isInCanvasSubtree); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | bool Element::isInCanvasSubtree() const |
| 2640 | { |
| 2641 | return hasRareData() && elementRareData()->isInCanvasSubtree(); |
| 2642 | } |
| 2643 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2644 | void Element::setIsInsideRegion(bool value) |
| 2645 | { |
| 2646 | if (value == isInsideRegion()) |
| 2647 | return; |
| 2648 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2649 | ensureElementRareData().setIsInsideRegion(value); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | bool Element::isInsideRegion() const |
| 2653 | { |
| 2654 | return hasRareData() ? elementRareData()->isInsideRegion() : false; |
| 2655 | } |
| 2656 | |
| 2657 | void Element::setRegionOversetState(RegionOversetState state) |
| 2658 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2659 | ensureElementRareData().setRegionOversetState(state); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | RegionOversetState Element::regionOversetState() const |
| 2663 | { |
| 2664 | return hasRareData() ? elementRareData()->regionOversetState() : RegionUndefined; |
| 2665 | } |
| 2666 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2667 | AtomicString Element::computeInheritedLanguage() const |
| 2668 | { |
| 2669 | const Node* n = this; |
| 2670 | AtomicString value; |
| 2671 | // The language property is inherited, so we iterate over the parents to find the first language. |
| 2672 | do { |
| 2673 | if (n->isElementNode()) { |
| 2674 | if (const ElementData* elementData = toElement(n)->elementData()) { |
| 2675 | // Spec: xml:lang takes precedence -- http://www.w3.org/TR/xhtml1/#C_7 |
| 2676 | if (const Attribute* attribute = elementData->getAttributeItem(XMLNames::langAttr)) |
| 2677 | value = attribute->value(); |
| 2678 | else if (const Attribute* attribute = elementData->getAttributeItem(HTMLNames::langAttr)) |
| 2679 | value = attribute->value(); |
| 2680 | } |
| 2681 | } else if (n->isDocumentNode()) { |
| 2682 | // checking the MIME content-language |
| 2683 | value = toDocument(n)->contentLanguage(); |
| 2684 | } |
| 2685 | |
| 2686 | n = n->parentNode(); |
| 2687 | } while (n && value.isNull()); |
| 2688 | |
| 2689 | return value; |
| 2690 | } |
| 2691 | |
| 2692 | Locale& Element::locale() const |
| 2693 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2694 | return document().getCachedLocale(computeInheritedLanguage()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | void Element::cancelFocusAppearanceUpdate() |
| 2698 | { |
| 2699 | if (hasRareData()) |
| 2700 | elementRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(false); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2701 | if (document().focusedElement() == this) |
| 2702 | document().cancelFocusAppearanceUpdate(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | void Element::normalizeAttributes() |
| 2706 | { |
| 2707 | if (!hasAttributes()) |
| 2708 | return; |
| 2709 | for (unsigned i = 0; i < attributeCount(); ++i) { |
| 2710 | if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name())) |
| 2711 | attr->normalize(); |
| 2712 | } |
| 2713 | } |
| 2714 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2715 | void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2716 | { |
| 2717 | PseudoElement* element = pseudoElement(pseudoId); |
| 2718 | if (element && (needsStyleRecalc() || shouldRecalcStyle(change, element))) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2719 | // Need to clear the cached style if the PseudoElement wants a recalc so it |
| 2720 | // computes a new style. |
| 2721 | if (element->needsStyleRecalc()) |
| 2722 | renderer()->style()->removeCachedPseudoStyle(pseudoId); |
| 2723 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2724 | // PseudoElement styles hang off their parent element's style so if we needed |
| 2725 | // a style recalc we should Force one on the pseudo. |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2726 | // FIXME: We should figure out the right text sibling to pass. |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2727 | element->recalcStyle(needsStyleRecalc() ? Force : change); |
| 2728 | |
| 2729 | // Wait until our parent is not displayed or pseudoElementRendererIsNeeded |
| 2730 | // is false, otherwise we could continously create and destroy PseudoElements |
| 2731 | // when RenderObject::isChildAllowed on our parent returns false for the |
| 2732 | // PseudoElement's renderer for each style recalc. |
| 2733 | if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedPseudoStyle(pseudoId))) |
Torne (Richard Coles) | 521d96e | 2013-06-19 11:58:24 +0100 | [diff] [blame] | 2734 | elementRareData()->setPseudoElement(pseudoId, 0); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2735 | } else if (change >= Inherit || needsStyleRecalc()) |
| 2736 | createPseudoElementIfNeeded(pseudoId); |
| 2737 | } |
| 2738 | |
| 2739 | void Element::createPseudoElementIfNeeded(PseudoId pseudoId) |
| 2740 | { |
Torne (Richard Coles) | 9bbd2f5 | 2013-09-19 22:37:05 +0100 | [diff] [blame] | 2741 | if (needsPseudoElement(pseudoId)) |
| 2742 | createPseudoElement(pseudoId); |
| 2743 | } |
| 2744 | |
| 2745 | bool Element::needsPseudoElement(PseudoId pseudoId) const |
| 2746 | { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 2747 | if (pseudoId == BACKDROP && !isInTopLayer()) |
Torne (Richard Coles) | 9bbd2f5 | 2013-09-19 22:37:05 +0100 | [diff] [blame] | 2748 | return false; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2749 | if (!renderer() || !pseudoElementRendererIsNeeded(renderer()->getCachedPseudoStyle(pseudoId))) |
Torne (Richard Coles) | 9bbd2f5 | 2013-09-19 22:37:05 +0100 | [diff] [blame] | 2750 | return false; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2751 | if (!renderer()->canHaveGeneratedChildren()) |
Torne (Richard Coles) | 9bbd2f5 | 2013-09-19 22:37:05 +0100 | [diff] [blame] | 2752 | return false; |
| 2753 | return true; |
| 2754 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2755 | |
Torne (Richard Coles) | 9bbd2f5 | 2013-09-19 22:37:05 +0100 | [diff] [blame] | 2756 | void Element::createPseudoElement(PseudoId pseudoId) |
| 2757 | { |
| 2758 | ASSERT(needsPseudoElement(pseudoId)); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2759 | ASSERT(!isPseudoElement()); |
| 2760 | RefPtr<PseudoElement> element = PseudoElement::create(this, pseudoId); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 2761 | if (pseudoId == BACKDROP) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2762 | document().addToTopLayer(element.get(), this); |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2763 | element->insertedInto(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2764 | element->attach(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 2765 | |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2766 | InspectorInstrumentation::pseudoElementCreated(element.get()); |
| 2767 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2768 | ensureElementRareData().setPseudoElement(pseudoId, element.release()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | PseudoElement* Element::pseudoElement(PseudoId pseudoId) const |
| 2772 | { |
| 2773 | return hasRareData() ? elementRareData()->pseudoElement(pseudoId) : 0; |
| 2774 | } |
| 2775 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2776 | RenderObject* Element::pseudoElementRenderer(PseudoId pseudoId) const |
| 2777 | { |
| 2778 | if (PseudoElement* element = pseudoElement(pseudoId)) |
| 2779 | return element->renderer(); |
| 2780 | return 0; |
| 2781 | } |
| 2782 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2783 | bool Element::webkitMatchesSelector(const String& selector, ExceptionState& exceptionState) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2784 | { |
| 2785 | if (selector.isEmpty()) { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2786 | exceptionState.throwUninformativeAndGenericDOMException(SyntaxError); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2787 | return false; |
| 2788 | } |
| 2789 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2790 | SelectorQuery* selectorQuery = document().selectorQueryCache().add(selector, document(), exceptionState); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2791 | if (!selectorQuery) |
| 2792 | return false; |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 2793 | return selectorQuery->matches(*this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2794 | } |
| 2795 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2796 | DOMTokenList* Element::classList() |
| 2797 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2798 | ElementRareData& rareData = ensureElementRareData(); |
| 2799 | if (!rareData.classList()) |
| 2800 | rareData.setClassList(ClassList::create(this)); |
| 2801 | return rareData.classList(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | DOMStringMap* Element::dataset() |
| 2805 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2806 | ElementRareData& rareData = ensureElementRareData(); |
| 2807 | if (!rareData.dataset()) |
| 2808 | rareData.setDataset(DatasetDOMStringMap::create(this)); |
| 2809 | return rareData.dataset(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | KURL Element::getURLAttribute(const QualifiedName& name) const |
| 2813 | { |
| 2814 | #if !ASSERT_DISABLED |
| 2815 | if (elementData()) { |
| 2816 | if (const Attribute* attribute = getAttributeItem(name)) |
| 2817 | ASSERT(isURLAttribute(*attribute)); |
| 2818 | } |
| 2819 | #endif |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2820 | return document().completeURL(stripLeadingAndTrailingHTMLSpaces(getAttribute(name))); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | KURL Element::getNonEmptyURLAttribute(const QualifiedName& name) const |
| 2824 | { |
| 2825 | #if !ASSERT_DISABLED |
| 2826 | if (elementData()) { |
| 2827 | if (const Attribute* attribute = getAttributeItem(name)) |
| 2828 | ASSERT(isURLAttribute(*attribute)); |
| 2829 | } |
| 2830 | #endif |
| 2831 | String value = stripLeadingAndTrailingHTMLSpaces(getAttribute(name)); |
| 2832 | if (value.isEmpty()) |
| 2833 | return KURL(); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2834 | return document().completeURL(value); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | int Element::getIntegralAttribute(const QualifiedName& attributeName) const |
| 2838 | { |
| 2839 | return getAttribute(attributeName).string().toInt(); |
| 2840 | } |
| 2841 | |
| 2842 | void Element::setIntegralAttribute(const QualifiedName& attributeName, int value) |
| 2843 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2844 | setAttribute(attributeName, AtomicString::number(value)); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | unsigned Element::getUnsignedIntegralAttribute(const QualifiedName& attributeName) const |
| 2848 | { |
| 2849 | return getAttribute(attributeName).string().toUInt(); |
| 2850 | } |
| 2851 | |
| 2852 | void Element::setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value) |
| 2853 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2854 | setAttribute(attributeName, AtomicString::number(value)); |
| 2855 | } |
| 2856 | |
| 2857 | double Element::getFloatingPointAttribute(const QualifiedName& attributeName, double fallbackValue) const |
| 2858 | { |
| 2859 | return parseToDoubleForNumberType(getAttribute(attributeName), fallbackValue); |
| 2860 | } |
| 2861 | |
| 2862 | void Element::setFloatingPointAttribute(const QualifiedName& attributeName, double value) |
| 2863 | { |
| 2864 | setAttribute(attributeName, AtomicString::number(value)); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2865 | } |
| 2866 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2867 | bool Element::childShouldCreateRenderer(const Node& child) const |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2868 | { |
| 2869 | // Only create renderers for SVG elements whose parents are SVG elements, or for proper <svg xmlns="svgNS"> subdocuments. |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2870 | if (child.isSVGElement()) |
| 2871 | return child.hasTagName(SVGNames::svgTag) || isSVGElement(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2872 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2873 | return ContainerNode::childShouldCreateRenderer(child); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2874 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2875 | |
| 2876 | void Element::webkitRequestFullscreen() |
| 2877 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2878 | FullscreenElementStack::from(&document())->requestFullScreenForElement(this, ALLOW_KEYBOARD_INPUT, FullscreenElementStack::EnforceIFrameAllowFullScreenRequirement); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | void Element::webkitRequestFullScreen(unsigned short flags) |
| 2882 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2883 | FullscreenElementStack::from(&document())->requestFullScreenForElement(this, (flags | LEGACY_MOZILLA_REQUEST), FullscreenElementStack::EnforceIFrameAllowFullScreenRequirement); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | bool Element::containsFullScreenElement() const |
| 2887 | { |
| 2888 | return hasRareData() && elementRareData()->containsFullScreenElement(); |
| 2889 | } |
| 2890 | |
| 2891 | void Element::setContainsFullScreenElement(bool flag) |
| 2892 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2893 | ensureElementRareData().setContainsFullScreenElement(flag); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 2894 | setNeedsStyleRecalc(SubtreeStyleChange); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | static Element* parentCrossingFrameBoundaries(Element* element) |
| 2898 | { |
| 2899 | ASSERT(element); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2900 | return element->parentElement() ? element->parentElement() : element->document().ownerElement(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | void Element::setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool flag) |
| 2904 | { |
| 2905 | Element* element = this; |
| 2906 | while ((element = parentCrossingFrameBoundaries(element))) |
| 2907 | element->setContainsFullScreenElement(flag); |
| 2908 | } |
| 2909 | |
| 2910 | bool Element::isInTopLayer() const |
| 2911 | { |
| 2912 | return hasRareData() && elementRareData()->isInTopLayer(); |
| 2913 | } |
| 2914 | |
| 2915 | void Element::setIsInTopLayer(bool inTopLayer) |
| 2916 | { |
| 2917 | if (isInTopLayer() == inTopLayer) |
| 2918 | return; |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 2919 | ensureElementRareData().setIsInTopLayer(inTopLayer); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2920 | |
| 2921 | // We must ensure a reattach occurs so the renderer is inserted in the correct sibling order under RenderView according to its |
| 2922 | // top layer position, or in its usual place if not in the top layer. |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 2923 | lazyReattachIfAttached(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | void Element::webkitRequestPointerLock() |
| 2927 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2928 | if (document().page()) |
| 2929 | document().page()->pointerLockController().requestPointerLock(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | SpellcheckAttributeState Element::spellcheckAttributeState() const |
| 2933 | { |
| 2934 | const AtomicString& value = getAttribute(HTMLNames::spellcheckAttr); |
| 2935 | if (value == nullAtom) |
| 2936 | return SpellcheckAttributeDefault; |
| 2937 | if (equalIgnoringCase(value, "true") || equalIgnoringCase(value, "")) |
| 2938 | return SpellcheckAttributeTrue; |
| 2939 | if (equalIgnoringCase(value, "false")) |
| 2940 | return SpellcheckAttributeFalse; |
| 2941 | |
| 2942 | return SpellcheckAttributeDefault; |
| 2943 | } |
| 2944 | |
| 2945 | bool Element::isSpellCheckingEnabled() const |
| 2946 | { |
| 2947 | for (const Element* element = this; element; element = element->parentOrShadowHostElement()) { |
| 2948 | switch (element->spellcheckAttributeState()) { |
| 2949 | case SpellcheckAttributeTrue: |
| 2950 | return true; |
| 2951 | case SpellcheckAttributeFalse: |
| 2952 | return false; |
| 2953 | case SpellcheckAttributeDefault: |
| 2954 | break; |
| 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | return true; |
| 2959 | } |
| 2960 | |
| 2961 | RenderRegion* Element::renderRegion() const |
| 2962 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2963 | if (renderer() && renderer()->isRenderNamedFlowFragmentContainer()) |
| 2964 | return toRenderBlockFlow(renderer())->renderNamedFlowFragment(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2965 | |
| 2966 | return 0; |
| 2967 | } |
| 2968 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2969 | bool Element::shouldMoveToFlowThread(RenderStyle* styleToUse) const |
| 2970 | { |
| 2971 | ASSERT(styleToUse); |
| 2972 | |
Torne (Richard Coles) | f5e4ad5 | 2013-08-05 13:57:57 +0100 | [diff] [blame] | 2973 | if (FullscreenElementStack::isActiveFullScreenElement(this)) |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2974 | return false; |
| 2975 | |
| 2976 | if (isInShadowTree()) |
| 2977 | return false; |
| 2978 | |
| 2979 | if (styleToUse->flowThread().isEmpty()) |
| 2980 | return false; |
| 2981 | |
| 2982 | return !isRegisteredWithNamedFlow(); |
| 2983 | } |
| 2984 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2985 | const AtomicString& Element::webkitRegionOverset() const |
| 2986 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2987 | DEFINE_STATIC_LOCAL(AtomicString, undefinedState, ("undefined", AtomicString::ConstructFromLiteral)); |
| 2988 | if (!RuntimeEnabledFeatures::cssRegionsEnabled()) |
| 2989 | return undefinedState; |
| 2990 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 2991 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2992 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 2993 | if (!renderRegion()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2994 | return undefinedState; |
| 2995 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 2996 | switch (renderRegion()->regionOversetState()) { |
| 2997 | case RegionFit: { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 2998 | DEFINE_STATIC_LOCAL(AtomicString, fitState, ("fit", AtomicString::ConstructFromLiteral)); |
| 2999 | return fitState; |
| 3000 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3001 | case RegionEmpty: { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3002 | DEFINE_STATIC_LOCAL(AtomicString, emptyState, ("empty", AtomicString::ConstructFromLiteral)); |
| 3003 | return emptyState; |
| 3004 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3005 | case RegionOverset: { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3006 | DEFINE_STATIC_LOCAL(AtomicString, overflowState, ("overset", AtomicString::ConstructFromLiteral)); |
| 3007 | return overflowState; |
| 3008 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3009 | case RegionUndefined: |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3010 | return undefinedState; |
| 3011 | } |
| 3012 | |
| 3013 | ASSERT_NOT_REACHED(); |
| 3014 | return undefinedState; |
| 3015 | } |
| 3016 | |
| 3017 | Vector<RefPtr<Range> > Element::webkitGetRegionFlowRanges() const |
| 3018 | { |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 3019 | Vector<RefPtr<Range> > rangeObjects; |
| 3020 | if (!RuntimeEnabledFeatures::cssRegionsEnabled()) |
| 3021 | return rangeObjects; |
| 3022 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3023 | document().updateLayoutIgnorePendingStylesheets(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3024 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 3025 | if (renderer() && renderer()->isRenderNamedFlowFragmentContainer()) { |
| 3026 | RenderNamedFlowFragment* region = toRenderBlockFlow(renderer())->renderNamedFlowFragment(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3027 | if (region->isValid()) |
| 3028 | region->getRanges(rangeObjects); |
| 3029 | } |
| 3030 | |
| 3031 | return rangeObjects; |
| 3032 | } |
| 3033 | |
| 3034 | #ifndef NDEBUG |
| 3035 | bool Element::fastAttributeLookupAllowed(const QualifiedName& name) const |
| 3036 | { |
| 3037 | if (name == HTMLNames::styleAttr) |
| 3038 | return false; |
| 3039 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3040 | if (isSVGElement()) |
| 3041 | return !static_cast<const SVGElement*>(this)->isAnimatableAttribute(name); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3042 | |
| 3043 | return true; |
| 3044 | } |
| 3045 | #endif |
| 3046 | |
| 3047 | #ifdef DUMP_NODE_STATISTICS |
| 3048 | bool Element::hasNamedNodeMap() const |
| 3049 | { |
| 3050 | return hasRareData() && elementRareData()->attributeMap(); |
| 3051 | } |
| 3052 | #endif |
| 3053 | |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 3054 | inline void Element::updateName(const AtomicString& oldName, const AtomicString& newName) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3055 | { |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 3056 | if (!inDocument() || isInShadowTree()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3057 | return; |
| 3058 | |
| 3059 | if (oldName == newName) |
| 3060 | return; |
| 3061 | |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 3062 | if (shouldRegisterAsNamedItem()) |
| 3063 | updateNamedItemRegistration(oldName, newName); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3064 | } |
| 3065 | |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 3066 | inline void Element::updateId(const AtomicString& oldId, const AtomicString& newId) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3067 | { |
| 3068 | if (!isInTreeScope()) |
| 3069 | return; |
| 3070 | |
| 3071 | if (oldId == newId) |
| 3072 | return; |
| 3073 | |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 3074 | updateId(treeScope(), oldId, newId); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3075 | } |
| 3076 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3077 | inline void Element::updateId(TreeScope& scope, const AtomicString& oldId, const AtomicString& newId) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3078 | { |
| 3079 | ASSERT(isInTreeScope()); |
| 3080 | ASSERT(oldId != newId); |
| 3081 | |
| 3082 | if (!oldId.isEmpty()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3083 | scope.removeElementById(oldId, this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3084 | if (!newId.isEmpty()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3085 | scope.addElementById(newId, this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3086 | |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 3087 | if (shouldRegisterAsExtraNamedItem()) |
| 3088 | updateExtraNamedItemRegistration(oldId, newId); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3089 | } |
| 3090 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3091 | void Element::updateLabel(TreeScope& scope, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3092 | { |
| 3093 | ASSERT(hasTagName(labelTag)); |
| 3094 | |
| 3095 | if (!inDocument()) |
| 3096 | return; |
| 3097 | |
| 3098 | if (oldForAttributeValue == newForAttributeValue) |
| 3099 | return; |
| 3100 | |
| 3101 | if (!oldForAttributeValue.isEmpty()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3102 | scope.removeLabel(oldForAttributeValue, toHTMLLabelElement(this)); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3103 | if (!newForAttributeValue.isEmpty()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3104 | scope.addLabel(newForAttributeValue, toHTMLLabelElement(this)); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3105 | } |
| 3106 | |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 3107 | static bool hasSelectorForAttribute(Document* document, const AtomicString& localName) |
| 3108 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 3109 | return document->ensureStyleResolver().ensureRuleFeatureSet().hasSelectorForAttribute(localName); |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 3110 | } |
| 3111 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3112 | void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue) |
| 3113 | { |
| 3114 | if (isIdAttributeName(name)) |
| 3115 | updateId(oldValue, newValue); |
| 3116 | else if (name == HTMLNames::nameAttr) |
| 3117 | updateName(oldValue, newValue); |
| 3118 | else if (name == HTMLNames::forAttr && hasTagName(labelTag)) { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3119 | TreeScope& scope = treeScope(); |
| 3120 | if (scope.shouldCacheLabelsByForAttribute()) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3121 | updateLabel(scope, oldValue, newValue); |
| 3122 | } |
| 3123 | |
| 3124 | if (oldValue != newValue) { |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 3125 | if (inActiveDocument() && hasSelectorForAttribute(&document(), name.localName())) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3126 | setNeedsStyleRecalc(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3127 | |
| 3128 | if (isUpgradedCustomElement()) |
Ben Murdoch | 8375017 | 2013-07-24 10:36:59 +0100 | [diff] [blame] | 3129 | CustomElement::attributeDidChange(this, name.localName(), oldValue, newValue); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3130 | } |
| 3131 | |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 3132 | if (OwnPtr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(*this, name)) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3133 | recipients->enqueueMutationRecord(MutationRecord::createAttributes(this, name, oldValue)); |
| 3134 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3135 | InspectorInstrumentation::willModifyDOMAttr(this, oldValue, newValue); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | void Element::didAddAttribute(const QualifiedName& name, const AtomicString& value) |
| 3139 | { |
| 3140 | attributeChanged(name, value); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3141 | InspectorInstrumentation::didModifyDOMAttr(this, name.localName(), value); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3142 | dispatchSubtreeModifiedEvent(); |
| 3143 | } |
| 3144 | |
| 3145 | void Element::didModifyAttribute(const QualifiedName& name, const AtomicString& value) |
| 3146 | { |
| 3147 | attributeChanged(name, value); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3148 | InspectorInstrumentation::didModifyDOMAttr(this, name.localName(), value); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3149 | // Do not dispatch a DOMSubtreeModified event here; see bug 81141. |
| 3150 | } |
| 3151 | |
| 3152 | void Element::didRemoveAttribute(const QualifiedName& name) |
| 3153 | { |
| 3154 | attributeChanged(name, nullAtom); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3155 | InspectorInstrumentation::didRemoveDOMAttr(this, name.localName()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3156 | dispatchSubtreeModifiedEvent(); |
| 3157 | } |
| 3158 | |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 3159 | void Element::didMoveToNewDocument(Document& oldDocument) |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3160 | { |
| 3161 | Node::didMoveToNewDocument(oldDocument); |
| 3162 | |
| 3163 | // If the documents differ by quirks mode then they differ by case sensitivity |
| 3164 | // for class and id names so we need to go through the attribute change logic |
| 3165 | // to pick up the new casing in the ElementData. |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 3166 | if (oldDocument.inQuirksMode() != document().inQuirksMode()) { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3167 | if (hasID()) |
| 3168 | setIdAttribute(getIdAttribute()); |
| 3169 | if (hasClass()) |
| 3170 | setAttribute(HTMLNames::classAttr, getClassAttribute()); |
| 3171 | } |
| 3172 | } |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3173 | |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 3174 | void Element::updateNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName) |
| 3175 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3176 | if (!document().isHTMLDocument()) |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 3177 | return; |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 3178 | |
| 3179 | if (!oldName.isEmpty()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3180 | toHTMLDocument(document()).removeNamedItem(oldName); |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 3181 | |
| 3182 | if (!newName.isEmpty()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3183 | toHTMLDocument(document()).addNamedItem(newName); |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | void Element::updateExtraNamedItemRegistration(const AtomicString& oldId, const AtomicString& newId) |
| 3187 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3188 | if (!document().isHTMLDocument()) |
Ben Murdoch | 00d3faa | 2013-08-14 11:52:03 +0100 | [diff] [blame] | 3189 | return; |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 3190 | |
| 3191 | if (!oldId.isEmpty()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3192 | toHTMLDocument(document()).removeExtraNamedItem(oldId); |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 3193 | |
| 3194 | if (!newId.isEmpty()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3195 | toHTMLDocument(document()).addExtraNamedItem(newId); |
Ben Murdoch | df95704 | 2013-08-06 11:01:27 +0100 | [diff] [blame] | 3196 | } |
| 3197 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3198 | PassRefPtr<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType type) |
| 3199 | { |
| 3200 | if (HTMLCollection* collection = cachedHTMLCollection(type)) |
| 3201 | return collection; |
| 3202 | |
| 3203 | RefPtr<HTMLCollection> collection; |
| 3204 | if (type == TableRows) { |
| 3205 | ASSERT(hasTagName(tableTag)); |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 3206 | return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLTableRowsCollection>(this, type); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3207 | } else if (type == SelectOptions) { |
| 3208 | ASSERT(hasTagName(selectTag)); |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 3209 | return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLOptionsCollection>(this, type); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3210 | } else if (type == FormControls) { |
| 3211 | ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag)); |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 3212 | return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLFormControlsCollection>(this, type); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3213 | } |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 3214 | return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLCollection>(this, type); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3215 | } |
| 3216 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3217 | static void scheduleLayerUpdateCallback(Node* node) |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 3218 | { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3219 | // Notify the renderer even is the styles are identical since it may need to |
| 3220 | // create or destroy a RenderLayer. |
| 3221 | node->setNeedsStyleRecalc(LocalStyleChange, StyleChangeFromRenderer); |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 3222 | } |
| 3223 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3224 | void Element::scheduleLayerUpdate() |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 3225 | { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3226 | if (document().inStyleRecalc()) |
| 3227 | PostAttachCallbacks::queueCallback(scheduleLayerUpdateCallback, this); |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 3228 | else |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3229 | scheduleLayerUpdateCallback(this); |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 3230 | } |
| 3231 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3232 | HTMLCollection* Element::cachedHTMLCollection(CollectionType type) |
| 3233 | { |
| 3234 | return hasRareData() && rareData()->nodeLists() ? rareData()->nodeLists()->cacheWithAtomicName<HTMLCollection>(type) : 0; |
| 3235 | } |
| 3236 | |
| 3237 | IntSize Element::savedLayerScrollOffset() const |
| 3238 | { |
| 3239 | return hasRareData() ? elementRareData()->savedLayerScrollOffset() : IntSize(); |
| 3240 | } |
| 3241 | |
| 3242 | void Element::setSavedLayerScrollOffset(const IntSize& size) |
| 3243 | { |
| 3244 | if (size.isZero() && !hasRareData()) |
| 3245 | return; |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3246 | ensureElementRareData().setSavedLayerScrollOffset(size); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | PassRefPtr<Attr> Element::attrIfExists(const QualifiedName& name) |
| 3250 | { |
| 3251 | if (AttrNodeList* attrNodeList = attrNodeListForElement(this)) |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3252 | return findAttrNodeInList(*attrNodeList, name); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3253 | return 0; |
| 3254 | } |
| 3255 | |
| 3256 | PassRefPtr<Attr> Element::ensureAttr(const QualifiedName& name) |
| 3257 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3258 | AttrNodeList& attrNodeList = ensureAttrNodeListForElement(this); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3259 | RefPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name); |
| 3260 | if (!attrNode) { |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3261 | attrNode = Attr::create(*this, name); |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 3262 | treeScope().adoptIfNeeded(*attrNode); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3263 | attrNodeList.append(attrNode); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3264 | } |
| 3265 | return attrNode.release(); |
| 3266 | } |
| 3267 | |
| 3268 | void Element::detachAttrNodeFromElementWithValue(Attr* attrNode, const AtomicString& value) |
| 3269 | { |
| 3270 | ASSERT(hasSyntheticAttrChildNodes()); |
| 3271 | attrNode->detachFromElementWithValue(value); |
| 3272 | |
| 3273 | AttrNodeList* attrNodeList = attrNodeListForElement(this); |
| 3274 | for (unsigned i = 0; i < attrNodeList->size(); ++i) { |
| 3275 | if (attrNodeList->at(i)->qualifiedName() == attrNode->qualifiedName()) { |
| 3276 | attrNodeList->remove(i); |
| 3277 | if (attrNodeList->isEmpty()) |
| 3278 | removeAttrNodeListForElement(this); |
| 3279 | return; |
| 3280 | } |
| 3281 | } |
| 3282 | ASSERT_NOT_REACHED(); |
| 3283 | } |
| 3284 | |
| 3285 | void Element::detachAllAttrNodesFromElement() |
| 3286 | { |
| 3287 | AttrNodeList* attrNodeList = attrNodeListForElement(this); |
| 3288 | ASSERT(attrNodeList); |
| 3289 | |
| 3290 | for (unsigned i = 0; i < attributeCount(); ++i) { |
| 3291 | const Attribute* attribute = attributeItem(i); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3292 | if (RefPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList, attribute->name())) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3293 | attrNode->detachFromElementWithValue(attribute->value()); |
| 3294 | } |
| 3295 | |
| 3296 | removeAttrNodeListForElement(this); |
| 3297 | } |
| 3298 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3299 | void Element::willRecalcStyle(StyleRecalcChange) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3300 | { |
| 3301 | ASSERT(hasCustomStyleCallbacks()); |
| 3302 | } |
| 3303 | |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3304 | void Element::didRecalcStyle(StyleRecalcChange) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3305 | { |
| 3306 | ASSERT(hasCustomStyleCallbacks()); |
| 3307 | } |
| 3308 | |
| 3309 | |
| 3310 | PassRefPtr<RenderStyle> Element::customStyleForRenderer() |
| 3311 | { |
| 3312 | ASSERT(hasCustomStyleCallbacks()); |
| 3313 | return 0; |
| 3314 | } |
| 3315 | |
| 3316 | void Element::cloneAttributesFromElement(const Element& other) |
| 3317 | { |
| 3318 | if (hasSyntheticAttrChildNodes()) |
| 3319 | detachAllAttrNodesFromElement(); |
| 3320 | |
| 3321 | other.synchronizeAllAttributes(); |
| 3322 | if (!other.m_elementData) { |
| 3323 | m_elementData.clear(); |
| 3324 | return; |
| 3325 | } |
| 3326 | |
| 3327 | const AtomicString& oldID = getIdAttribute(); |
| 3328 | const AtomicString& newID = other.getIdAttribute(); |
| 3329 | |
| 3330 | if (!oldID.isNull() || !newID.isNull()) |
| 3331 | updateId(oldID, newID); |
| 3332 | |
| 3333 | const AtomicString& oldName = getNameAttribute(); |
| 3334 | const AtomicString& newName = other.getNameAttribute(); |
| 3335 | |
| 3336 | if (!oldName.isNull() || !newName.isNull()) |
| 3337 | updateName(oldName, newName); |
| 3338 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3339 | // Quirks mode makes class and id not case sensitive. We can't share the ElementData |
| 3340 | // if the idForStyleResolution and the className need different casing. |
| 3341 | bool ownerDocumentsHaveDifferentCaseSensitivity = false; |
| 3342 | if (other.hasClass() || other.hasID()) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3343 | ownerDocumentsHaveDifferentCaseSensitivity = other.document().inQuirksMode() != document().inQuirksMode(); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3344 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3345 | // If 'other' has a mutable ElementData, convert it to an immutable one so we can share it between both elements. |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3346 | // We can only do this if there is no CSSOM wrapper for other's inline style, and there are no presentation attributes, |
| 3347 | // and sharing the data won't result in different case sensitivity of class or id. |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3348 | if (other.m_elementData->isUnique() |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3349 | && !ownerDocumentsHaveDifferentCaseSensitivity |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3350 | && !other.m_elementData->presentationAttributeStyle() |
| 3351 | && (!other.m_elementData->inlineStyle() || !other.m_elementData->inlineStyle()->hasCSSOMWrapper())) |
| 3352 | const_cast<Element&>(other).m_elementData = static_cast<const UniqueElementData*>(other.m_elementData.get())->makeShareableCopy(); |
| 3353 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3354 | if (!other.m_elementData->isUnique() && !ownerDocumentsHaveDifferentCaseSensitivity) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3355 | m_elementData = other.m_elementData; |
| 3356 | else |
| 3357 | m_elementData = other.m_elementData->makeUniqueCopy(); |
| 3358 | |
| 3359 | for (unsigned i = 0; i < m_elementData->length(); ++i) { |
| 3360 | const Attribute* attribute = const_cast<const ElementData*>(m_elementData.get())->attributeItem(i); |
| 3361 | attributeChangedFromParserOrByCloning(attribute->name(), attribute->value(), ModifiedByCloning); |
| 3362 | } |
| 3363 | } |
| 3364 | |
| 3365 | void Element::cloneDataFromElement(const Element& other) |
| 3366 | { |
| 3367 | cloneAttributesFromElement(other); |
| 3368 | copyNonAttributePropertiesFromElement(other); |
| 3369 | } |
| 3370 | |
| 3371 | void Element::createUniqueElementData() |
| 3372 | { |
| 3373 | if (!m_elementData) |
| 3374 | m_elementData = UniqueElementData::create(); |
| 3375 | else { |
| 3376 | ASSERT(!m_elementData->isUnique()); |
| 3377 | m_elementData = static_cast<ShareableElementData*>(m_elementData.get())->makeUniqueCopy(); |
| 3378 | } |
| 3379 | } |
| 3380 | |
Ben Murdoch | 1fad5ca | 2013-08-07 11:05:11 +0100 | [diff] [blame] | 3381 | InputMethodContext* Element::inputMethodContext() |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 3382 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3383 | return ensureElementRareData().ensureInputMethodContext(toHTMLElement(this)); |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 3384 | } |
| 3385 | |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 3386 | bool Element::hasInputMethodContext() const |
| 3387 | { |
| 3388 | return hasRareData() && elementRareData()->hasInputMethodContext(); |
| 3389 | } |
| 3390 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3391 | bool Element::hasPendingResources() const |
| 3392 | { |
| 3393 | return hasRareData() && elementRareData()->hasPendingResources(); |
| 3394 | } |
| 3395 | |
| 3396 | void Element::setHasPendingResources() |
| 3397 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3398 | ensureElementRareData().setHasPendingResources(true); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | void Element::clearHasPendingResources() |
| 3402 | { |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3403 | ensureElementRareData().setHasPendingResources(false); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | void Element::synchronizeStyleAttributeInternal() const |
| 3407 | { |
| 3408 | ASSERT(isStyledElement()); |
| 3409 | ASSERT(elementData()); |
| 3410 | ASSERT(elementData()->m_styleAttributeIsDirty); |
| 3411 | elementData()->m_styleAttributeIsDirty = false; |
| 3412 | if (const StylePropertySet* inlineStyle = this->inlineStyle()) |
| 3413 | const_cast<Element*>(this)->setSynchronizedLazyAttribute(styleAttr, inlineStyle->asText()); |
| 3414 | } |
| 3415 | |
| 3416 | CSSStyleDeclaration* Element::style() |
| 3417 | { |
| 3418 | if (!isStyledElement()) |
| 3419 | return 0; |
| 3420 | return ensureMutableInlineStyle()->ensureInlineCSSStyleDeclaration(this); |
| 3421 | } |
| 3422 | |
| 3423 | MutableStylePropertySet* Element::ensureMutableInlineStyle() |
| 3424 | { |
| 3425 | ASSERT(isStyledElement()); |
| 3426 | RefPtr<StylePropertySet>& inlineStyle = ensureUniqueElementData()->m_inlineStyle; |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 3427 | if (!inlineStyle) { |
| 3428 | CSSParserMode mode = (!isHTMLElement() || document().inQuirksMode()) ? HTMLQuirksMode : HTMLStandardMode; |
| 3429 | inlineStyle = MutableStylePropertySet::create(mode); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 3430 | } else if (!inlineStyle->isMutable()) { |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3431 | inlineStyle = inlineStyle->mutableCopy(); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 3432 | } |
| 3433 | return toMutableStylePropertySet(inlineStyle); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | PropertySetCSSStyleDeclaration* Element::inlineStyleCSSOMWrapper() |
| 3437 | { |
| 3438 | if (!inlineStyle() || !inlineStyle()->hasCSSOMWrapper()) |
| 3439 | return 0; |
| 3440 | PropertySetCSSStyleDeclaration* cssomWrapper = ensureMutableInlineStyle()->cssStyleDeclaration(); |
| 3441 | ASSERT(cssomWrapper && cssomWrapper->parentElement() == this); |
| 3442 | return cssomWrapper; |
| 3443 | } |
| 3444 | |
| 3445 | inline void Element::setInlineStyleFromString(const AtomicString& newStyleString) |
| 3446 | { |
| 3447 | ASSERT(isStyledElement()); |
| 3448 | RefPtr<StylePropertySet>& inlineStyle = elementData()->m_inlineStyle; |
| 3449 | |
| 3450 | // Avoid redundant work if we're using shared attribute data with already parsed inline style. |
| 3451 | if (inlineStyle && !elementData()->isUnique()) |
| 3452 | return; |
| 3453 | |
| 3454 | // We reconstruct the property set instead of mutating if there is no CSSOM wrapper. |
| 3455 | // This makes wrapperless property sets immutable and so cacheable. |
| 3456 | if (inlineStyle && !inlineStyle->isMutable()) |
| 3457 | inlineStyle.clear(); |
| 3458 | |
| 3459 | if (!inlineStyle) { |
| 3460 | inlineStyle = CSSParser::parseInlineStyleDeclaration(newStyleString, this); |
| 3461 | } else { |
| 3462 | ASSERT(inlineStyle->isMutable()); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3463 | static_pointer_cast<MutableStylePropertySet>(inlineStyle)->parseDeclaration(newStyleString, document().elementSheet()->contents()); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3464 | } |
| 3465 | } |
| 3466 | |
| 3467 | void Element::styleAttributeChanged(const AtomicString& newStyleString, AttributeModificationReason modificationReason) |
| 3468 | { |
| 3469 | ASSERT(isStyledElement()); |
| 3470 | WTF::OrdinalNumber startLineNumber = WTF::OrdinalNumber::beforeFirst(); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3471 | if (document().scriptableDocumentParser() && !document().isInDocumentWrite()) |
| 3472 | startLineNumber = document().scriptableDocumentParser()->lineNumber(); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3473 | |
| 3474 | if (newStyleString.isNull()) { |
| 3475 | if (PropertySetCSSStyleDeclaration* cssomWrapper = inlineStyleCSSOMWrapper()) |
| 3476 | cssomWrapper->clearParentElement(); |
| 3477 | ensureUniqueElementData()->m_inlineStyle.clear(); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3478 | } else if (modificationReason == ModifiedByCloning || document().contentSecurityPolicy()->allowInlineStyle(document().url(), startLineNumber)) { |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3479 | setInlineStyleFromString(newStyleString); |
| 3480 | } |
| 3481 | |
| 3482 | elementData()->m_styleAttributeIsDirty = false; |
| 3483 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3484 | setNeedsStyleRecalc(LocalStyleChange); |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3485 | InspectorInstrumentation::didInvalidateStyleAttr(this); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | void Element::inlineStyleChanged() |
| 3489 | { |
| 3490 | ASSERT(isStyledElement()); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 3491 | setNeedsStyleRecalc(LocalStyleChange); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3492 | ASSERT(elementData()); |
| 3493 | elementData()->m_styleAttributeIsDirty = true; |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3494 | InspectorInstrumentation::didInvalidateStyleAttr(this); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | bool Element::setInlineStyleProperty(CSSPropertyID propertyID, CSSValueID identifier, bool important) |
| 3498 | { |
| 3499 | ASSERT(isStyledElement()); |
| 3500 | ensureMutableInlineStyle()->setProperty(propertyID, cssValuePool().createIdentifierValue(identifier), important); |
| 3501 | inlineStyleChanged(); |
| 3502 | return true; |
| 3503 | } |
| 3504 | |
| 3505 | bool Element::setInlineStyleProperty(CSSPropertyID propertyID, CSSPropertyID identifier, bool important) |
| 3506 | { |
| 3507 | ASSERT(isStyledElement()); |
| 3508 | ensureMutableInlineStyle()->setProperty(propertyID, cssValuePool().createIdentifierValue(identifier), important); |
| 3509 | inlineStyleChanged(); |
| 3510 | return true; |
| 3511 | } |
| 3512 | |
| 3513 | bool Element::setInlineStyleProperty(CSSPropertyID propertyID, double value, CSSPrimitiveValue::UnitTypes unit, bool important) |
| 3514 | { |
| 3515 | ASSERT(isStyledElement()); |
| 3516 | ensureMutableInlineStyle()->setProperty(propertyID, cssValuePool().createValue(value, unit), important); |
| 3517 | inlineStyleChanged(); |
| 3518 | return true; |
| 3519 | } |
| 3520 | |
| 3521 | bool Element::setInlineStyleProperty(CSSPropertyID propertyID, const String& value, bool important) |
| 3522 | { |
| 3523 | ASSERT(isStyledElement()); |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3524 | bool changes = ensureMutableInlineStyle()->setProperty(propertyID, value, important, document().elementSheet()->contents()); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3525 | if (changes) |
| 3526 | inlineStyleChanged(); |
| 3527 | return changes; |
| 3528 | } |
| 3529 | |
| 3530 | bool Element::removeInlineStyleProperty(CSSPropertyID propertyID) |
| 3531 | { |
| 3532 | ASSERT(isStyledElement()); |
| 3533 | if (!inlineStyle()) |
| 3534 | return false; |
| 3535 | bool changes = ensureMutableInlineStyle()->removeProperty(propertyID); |
| 3536 | if (changes) |
| 3537 | inlineStyleChanged(); |
| 3538 | return changes; |
| 3539 | } |
| 3540 | |
| 3541 | void Element::removeAllInlineStyleProperties() |
| 3542 | { |
| 3543 | ASSERT(isStyledElement()); |
| 3544 | if (!inlineStyle() || inlineStyle()->isEmpty()) |
| 3545 | return; |
| 3546 | ensureMutableInlineStyle()->clear(); |
| 3547 | inlineStyleChanged(); |
| 3548 | } |
| 3549 | |
| 3550 | void Element::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const |
| 3551 | { |
| 3552 | ASSERT(isStyledElement()); |
| 3553 | if (const StylePropertySet* inlineStyle = elementData() ? elementData()->inlineStyle() : 0) |
Torne (Richard Coles) | 8abfc58 | 2013-09-12 12:10:38 +0100 | [diff] [blame] | 3554 | inlineStyle->addSubresourceStyleURLs(urls, document().elementSheet()->contents()); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3555 | } |
| 3556 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3557 | void Element::updatePresentationAttributeStyle() |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3558 | { |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3559 | // ShareableElementData doesn't store presentation attribute style, so make sure we have a UniqueElementData. |
| 3560 | UniqueElementData* elementData = ensureUniqueElementData(); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3561 | elementData->m_presentationAttributeStyleIsDirty = false; |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3562 | elementData->m_presentationAttributeStyle = computePresentationAttributeStyle(*this); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | void Element::addPropertyToPresentationAttributeStyle(MutableStylePropertySet* style, CSSPropertyID propertyID, CSSValueID identifier) |
| 3566 | { |
| 3567 | ASSERT(isStyledElement()); |
| 3568 | style->setProperty(propertyID, cssValuePool().createIdentifierValue(identifier)); |
| 3569 | } |
| 3570 | |
| 3571 | void Element::addPropertyToPresentationAttributeStyle(MutableStylePropertySet* style, CSSPropertyID propertyID, double value, CSSPrimitiveValue::UnitTypes unit) |
| 3572 | { |
| 3573 | ASSERT(isStyledElement()); |
| 3574 | style->setProperty(propertyID, cssValuePool().createValue(value, unit)); |
| 3575 | } |
| 3576 | |
| 3577 | void Element::addPropertyToPresentationAttributeStyle(MutableStylePropertySet* style, CSSPropertyID propertyID, const String& value) |
| 3578 | { |
| 3579 | ASSERT(isStyledElement()); |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 3580 | style->setProperty(propertyID, value, false); |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 3581 | } |
| 3582 | |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3583 | bool Element::supportsStyleSharing() const |
| 3584 | { |
| 3585 | if (!isStyledElement() || !parentElement()) |
| 3586 | return false; |
| 3587 | // If the element has inline style it is probably unique. |
| 3588 | if (inlineStyle()) |
| 3589 | return false; |
| 3590 | if (isSVGElement() && toSVGElement(this)->animatedSMILStyleProperties()) |
| 3591 | return false; |
| 3592 | // Ids stop style sharing if they show up in the stylesheets. |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 3593 | if (hasID() && document().ensureStyleResolver().hasRulesForId(idForStyleResolution())) |
Torne (Richard Coles) | bfe3590 | 2013-10-22 16:41:51 +0100 | [diff] [blame] | 3594 | return false; |
| 3595 | // Active and hovered elements always make a chain towards the document node |
| 3596 | // and no siblings or cousins will have the same state. |
| 3597 | if (hovered()) |
| 3598 | return false; |
| 3599 | if (active()) |
| 3600 | return false; |
| 3601 | if (focused()) |
| 3602 | return false; |
| 3603 | if (!parentElement()->childrenSupportStyleSharing()) |
| 3604 | return false; |
| 3605 | if (hasScopedHTMLStyleChild()) |
| 3606 | return false; |
| 3607 | if (this == document().cssTarget()) |
| 3608 | return false; |
| 3609 | if (isHTMLElement() && toHTMLElement(this)->hasDirectionAuto()) |
| 3610 | return false; |
| 3611 | if (hasActiveAnimations()) |
| 3612 | return false; |
| 3613 | if (shadow() && shadow()->containsActiveStyles()) |
| 3614 | return false; |
| 3615 | // Turn off style sharing for elements that can gain layers for reasons outside of the style system. |
| 3616 | // See comments in RenderObject::setStyle(). |
| 3617 | // FIXME: Why does gaining a layer from outside the style system require disabling sharing? |
| 3618 | if (hasTagName(iframeTag) |
| 3619 | || hasTagName(frameTag) |
| 3620 | || hasTagName(embedTag) |
| 3621 | || hasTagName(objectTag) |
| 3622 | || hasTagName(appletTag) |
| 3623 | || hasTagName(canvasTag)) |
| 3624 | return false; |
| 3625 | // FIXME: We should share style for option and optgroup whenever possible. |
| 3626 | // Before doing so, we need to resolve issues in HTMLSelectElement::recalcListItems |
| 3627 | // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cgi?id=88405 |
| 3628 | if (hasTagName(optionTag) || hasTagName(optgroupTag)) |
| 3629 | return false; |
| 3630 | if (FullscreenElementStack::isActiveFullScreenElement(this)) |
| 3631 | return false; |
| 3632 | return true; |
| 3633 | } |
| 3634 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 3635 | } // namespace WebCore |