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

Unified Diff: Source/core/html/shadow/PluginPlaceholderElement.cpp

Issue 522783002: Add a custom element to own structure of shadow DOM plugin placeholders. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/shadow/PluginPlaceholderElement.cpp
diff --git a/Source/core/html/shadow/PluginPlaceholderElement.cpp b/Source/core/html/shadow/PluginPlaceholderElement.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..aeb6d7b90f3b5865b394ccc1d1fa918a34475c08
--- /dev/null
+++ b/Source/core/html/shadow/PluginPlaceholderElement.cpp
@@ -0,0 +1,87 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/html/shadow/PluginPlaceholderElement.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "core/CSSPropertyNames.h"
+#include "core/CSSValueKeywords.h"
+#include "wtf/StdLibExtras.h"
+#include "wtf/text/AtomicString.h"
+
+namespace blink {
+
+PluginPlaceholderElement::PluginPlaceholderElement(Document& document)
+ : HTMLDivElement(document)
+{
+}
+
+PassRefPtrWillBeRawPtr<PluginPlaceholderElement> PluginPlaceholderElement::create(Document& document)
+{
+ RefPtrWillBeRawPtr<PluginPlaceholderElement> element = adoptRefWillBeNoop(new PluginPlaceholderElement(document));
+
+ if (element->initializePlaceholderElements())
esprehn 2014/08/29 21:13:26 This shouldn't be allowed to return nullptr, creat
jbroman 2014/08/30 13:55:48 The shadow root host is the HTMLPlugInElement (obj
+ return element.release();
+
+ return nullptr;
+}
+
+void PluginPlaceholderElement::trace(Visitor* visitor)
+{
+ visitor->trace(m_messageElement);
+ HTMLDivElement::trace(visitor);
+}
+
+void PluginPlaceholderElement::setMessage(const String& message)
+{
+ m_messageElement->setInnerHTML(message, ASSERT_NO_EXCEPTION);
+}
+
+bool PluginPlaceholderElement::initializePlaceholderElements()
esprehn 2014/08/29 21:13:26 Just use didAddUserAgentShadowRoot(ShadowRoot& roo
jbroman 2014/08/30 13:55:48 See above.
+{
+ // Produces DOM roughly equivalent to the following HTML:
+ //
+ // <div id="plugin-placeholder">
+ // <div id="plugin-placeholder-content">
+ // <div id="plugin-placeholder-message"></div>
+ // </div>
+ // </div>
+
+ // FIXME: Move style out of C++ and into CSS.
+
+ TrackExceptionState exceptionState;
+
+ DEFINE_STATIC_LOCAL(AtomicString, id, ("plugin-placeholder"));
+ setIdAttribute(id);
+ setInlineStyleProperty(CSSPropertyWidth, 100, CSSPrimitiveValue::CSS_PERCENTAGE);
+ setInlineStyleProperty(CSSPropertyHeight, 100, CSSPrimitiveValue::CSS_PERCENTAGE);
+ setInlineStyleProperty(CSSPropertyOverflow, CSSValueHidden);
+ setInlineStyleProperty(CSSPropertyDisplay, CSSValueFlex);
+ setInlineStyleProperty(CSSPropertyAlignItems, CSSValueCenter);
+ setInlineStyleProperty(CSSPropertyBackgroundColor, CSSValueGray);
+ setInlineStyleProperty(CSSPropertyFont, "12px -webkit-control");
+
+ DEFINE_STATIC_LOCAL(AtomicString, contentId, ("plugin-placeholder-content"));
+ RefPtrWillBeRawPtr<HTMLDivElement> contentElement = HTMLDivElement::create(document());
+ contentElement->setIdAttribute(contentId);
+ contentElement->setInlineStyleProperty(CSSPropertyTextAlign, CSSValueCenter);
+ contentElement->setInlineStyleProperty(CSSPropertyMargin, CSSValueAuto);
+
+ DEFINE_STATIC_LOCAL(AtomicString, messageId, ("plugin-placeholder-message"));
+ RefPtrWillBeRawPtr<HTMLDivElement> messageElement = HTMLDivElement::create(document());
+ messageElement->setIdAttribute(messageId);
+ m_messageElement = messageElement.get();
+ contentElement->appendChild(messageElement.release(), exceptionState);
+ if (exceptionState.hadException())
esprehn 2014/08/29 21:13:26 ASSERT_NO_EXCEPTION
jbroman 2014/08/30 13:55:48 Okay. I assumed that tracking the exception and po
+ return false;
+
+ appendChild(contentElement.release(), exceptionState);
esprehn 2014/08/29 21:13:26 ASSERT_NO_EXCEPTION, don't check it. Internal code
jbroman 2014/08/30 13:55:48 Ditto.
+ if (exceptionState.hadException())
+ return false;
+
+ return true;
esprehn 2014/08/29 21:13:26 no return value, just use the Shadow DOM framework
jbroman 2014/08/30 13:55:48 I understand the "no return value", though I'm not
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698