TextPlaceholderElement.cpp [plain text]
#include "config.h"
#include "TextPlaceholderElement.h"
#include "HTMLNames.h"
#include "HTMLTextFormControlElement.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(TextPlaceholderElement);
Ref<TextPlaceholderElement> TextPlaceholderElement::create(Document& document, const LayoutSize& size)
{
return adoptRef(*new TextPlaceholderElement { document, size });
}
TextPlaceholderElement::TextPlaceholderElement(Document& document, const LayoutSize& size)
: HTMLDivElement { HTMLNames::divTag, document }
{
setInlineStyleProperty(CSSPropertyDisplay, size.width() ? CSSValueInlineBlock : CSSValueBlock, false);
setInlineStyleProperty(CSSPropertyVerticalAlign, CSSValueTop, false);
setInlineStyleProperty(CSSPropertyVisibility, CSSValueHidden, true);
setInlineStyleProperty(CSSPropertyWidth, size.width(), CSSUnitType::CSS_PX);
setInlineStyleProperty(CSSPropertyHeight, size.height(), CSSUnitType::CSS_PX);
}
auto TextPlaceholderElement::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree) -> InsertedIntoAncestorResult
{
if (insertionType.treeScopeChanged) {
if (auto shadowHost = makeRefPtr(parentOfInsertedTree.shadowHost()); is<HTMLTextFormControlElement>(shadowHost))
downcast<HTMLTextFormControlElement>(*shadowHost).setCanShowPlaceholder(false);
}
return HTMLDivElement::insertedIntoAncestor(insertionType, parentOfInsertedTree);
}
void TextPlaceholderElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree)
{
if (removalType.treeScopeChanged) {
if (auto shadowHost = makeRefPtr(oldParentOfRemovedTree.shadowHost()); is<HTMLTextFormControlElement>(shadowHost))
downcast<HTMLTextFormControlElement>(*shadowHost).setCanShowPlaceholder(true);
}
HTMLDivElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
}
}