Chromium Code Reviews| 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 |