Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / HTMLEmbedElement.cpp
blobcf88b0ccf0bdfd9f1aa4ed67a38ab6d3f7b0158a
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de)
5 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #include "config.h"
25 #include "core/html/HTMLEmbedElement.h"
27 #include "core/CSSPropertyNames.h"
28 #include "core/HTMLNames.h"
29 #include "core/dom/Attribute.h"
30 #include "core/dom/ElementTraversal.h"
31 #include "core/dom/shadow/ShadowRoot.h"
32 #include "core/html/HTMLImageLoader.h"
33 #include "core/html/HTMLObjectElement.h"
34 #include "core/html/PluginDocument.h"
35 #include "core/html/parser/HTMLParserIdioms.h"
36 #include "core/layout/LayoutEmbeddedObject.h"
37 #include "core/layout/LayoutPart.h"
39 namespace blink {
41 using namespace HTMLNames;
43 inline HTMLEmbedElement::HTMLEmbedElement(Document& document, bool createdByParser)
44 : HTMLPlugInElement(embedTag, document, createdByParser, ShouldPreferPlugInsForImages)
48 PassRefPtrWillBeRawPtr<HTMLEmbedElement> HTMLEmbedElement::create(Document& document, bool createdByParser)
50 RefPtrWillBeRawPtr<HTMLEmbedElement> element = adoptRefWillBeNoop(new HTMLEmbedElement(document, createdByParser));
51 element->ensureUserAgentShadowRoot();
52 return element.release();
55 static inline LayoutPart* findPartLayoutObject(const Node* n)
57 if (!n->layoutObject())
58 n = Traversal<HTMLObjectElement>::firstAncestor(*n);
60 if (n && n->layoutObject() && n->layoutObject()->isLayoutPart())
61 return toLayoutPart(n->layoutObject());
63 return nullptr;
66 LayoutPart* HTMLEmbedElement::existingLayoutPart() const
68 return findPartLayoutObject(this);
71 bool HTMLEmbedElement::isPresentationAttribute(const QualifiedName& name) const
73 if (name == hiddenAttr)
74 return true;
75 return HTMLPlugInElement::isPresentationAttribute(name);
78 void HTMLEmbedElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
80 if (name == hiddenAttr) {
81 if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, "true")) {
82 addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, 0, CSSPrimitiveValue::UnitType::Pixels);
83 addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, 0, CSSPrimitiveValue::UnitType::Pixels);
85 } else {
86 HTMLPlugInElement::collectStyleForPresentationAttribute(name, value, style);
90 void HTMLEmbedElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
92 if (name == typeAttr) {
93 m_serviceType = value.lower();
94 size_t pos = m_serviceType.find(";");
95 if (pos != kNotFound)
96 m_serviceType = m_serviceType.left(pos);
97 if (layoutObject()) {
98 setNeedsWidgetUpdate(true);
99 layoutObject()->setNeedsLayoutAndFullPaintInvalidation("Embed type changed");
100 } else {
101 requestPluginCreationWithoutLayoutObjectIfPossible();
103 } else if (name == codeAttr) { // TODO(schenney): Remove this? It's not in the spec and we're not in the HTMLAppletElement hierarchy
104 m_url = stripLeadingAndTrailingHTMLSpaces(value);
105 } else if (name == srcAttr) {
106 m_url = stripLeadingAndTrailingHTMLSpaces(value);
107 if (layoutObject() && isImageType()) {
108 if (!m_imageLoader)
109 m_imageLoader = HTMLImageLoader::create(this);
110 m_imageLoader->updateFromElement(ImageLoader::UpdateIgnorePreviousError);
112 } else {
113 HTMLPlugInElement::parseAttribute(name, value);
117 void HTMLEmbedElement::parametersForPlugin(Vector<String>& paramNames, Vector<String>& paramValues)
119 AttributeCollection attributes = this->attributes();
120 for (const Attribute& attribute : attributes) {
121 paramNames.append(attribute.localName().string());
122 paramValues.append(attribute.value().string());
126 // FIXME: This should be unified with HTMLObjectElement::updateWidget and
127 // moved down into HTMLPluginElement.cpp
128 void HTMLEmbedElement::updateWidgetInternal()
130 ASSERT(!layoutEmbeddedObject()->showsUnavailablePluginIndicator());
131 ASSERT(needsWidgetUpdate());
132 setNeedsWidgetUpdate(false);
134 if (m_url.isEmpty() && m_serviceType.isEmpty())
135 return;
137 // Note these pass m_url and m_serviceType to allow better code sharing with
138 // <object> which modifies url and serviceType before calling these.
139 if (!allowedToLoadFrameURL(m_url))
140 return;
142 // FIXME: These should be joined into a PluginParameters class.
143 Vector<String> paramNames;
144 Vector<String> paramValues;
145 parametersForPlugin(paramNames, paramValues);
147 RefPtrWillBeRawPtr<HTMLEmbedElement> protect(this); // Loading the plugin might remove us from the document.
149 // FIXME: Can we not have layoutObject here now that beforeload events are gone?
150 if (!layoutObject())
151 return;
153 requestObject(m_url, m_serviceType, paramNames, paramValues);
156 bool HTMLEmbedElement::layoutObjectIsNeeded(const ComputedStyle& style)
158 if (isImageType())
159 return HTMLPlugInElement::layoutObjectIsNeeded(style);
161 // If my parent is an <object> and is not set to use fallback content, I
162 // should be ignored and not get a layoutObject.
163 ContainerNode* p = parentNode();
164 if (isHTMLObjectElement(p)) {
165 ASSERT(p->layoutObject());
166 if (!toHTMLObjectElement(p)->useFallbackContent()) {
167 ASSERT(!p->layoutObject()->isEmbeddedObject());
168 return false;
171 return HTMLPlugInElement::layoutObjectIsNeeded(style);
174 bool HTMLEmbedElement::isURLAttribute(const Attribute& attribute) const
176 return attribute.name() == srcAttr || HTMLPlugInElement::isURLAttribute(attribute);
179 const QualifiedName& HTMLEmbedElement::subResourceAttributeName() const
181 return srcAttr;
184 bool HTMLEmbedElement::isInteractiveContent() const
186 return true;
189 bool HTMLEmbedElement::isExposed() const
191 // http://www.whatwg.org/specs/web-apps/current-work/#exposed
192 for (HTMLObjectElement* object = Traversal<HTMLObjectElement>::firstAncestor(*this); object; object = Traversal<HTMLObjectElement>::firstAncestor(*object)) {
193 if (object->isExposed())
194 return false;
196 return true;