InsertionPoint.cpp [plain text]
#include "config.h"
#include "InsertionPoint.h"
#include "QualifiedName.h"
#include "StaticNodeList.h"
#include "Text.h"
namespace WebCore {
using namespace HTMLNames;
InsertionPoint::InsertionPoint(const QualifiedName& tagName, Document& document)
: HTMLElement(tagName, document, CreateInsertionPoint)
, m_hasDistribution(false)
{
}
InsertionPoint::~InsertionPoint()
{
}
bool InsertionPoint::shouldUseFallbackElements() const
{
return isActive() && !hasDistribution();
}
bool InsertionPoint::isActive() const
{
if (!containingShadowRoot())
return false;
const Node* node = parentNode();
while (node) {
if (node->isInsertionPoint())
return false;
node = node->parentNode();
}
return true;
}
bool InsertionPoint::rendererIsNeeded(const RenderStyle& style)
{
return !isActive() && HTMLElement::rendererIsNeeded(style);
}
void InsertionPoint::childrenChanged(const ChildChange& change)
{
HTMLElement::childrenChanged(change);
if (ShadowRoot* root = containingShadowRoot())
root->invalidateDistribution();
}
Node::InsertionNotificationRequest InsertionPoint::insertedInto(ContainerNode& insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
if (ShadowRoot* root = containingShadowRoot()) {
root->distributor().didShadowBoundaryChange(root->hostElement());
root->distributor().invalidateInsertionPointList();
}
return InsertionDone;
}
void InsertionPoint::removedFrom(ContainerNode& insertionPoint)
{
ShadowRoot* root = containingShadowRoot();
if (!root)
root = insertionPoint.containingShadowRoot();
if (root && root->hostElement()) {
root->invalidateDistribution();
root->distributor().invalidateInsertionPointList();
}
clearDistribution();
HTMLElement::removedFrom(insertionPoint);
}
Node* InsertionPoint::firstDistributed() const
{
if (!m_hasDistribution)
return 0;
for (Node* current = shadowHost()->firstChild(); current; current = current->nextSibling()) {
if (matchTypeFor(current) == InsertionPoint::AlwaysMatches)
return current;
}
return 0;
}
Node* InsertionPoint::lastDistributed() const
{
if (!m_hasDistribution)
return 0;
for (Node* current = shadowHost()->lastChild(); current; current = current->previousSibling()) {
if (matchTypeFor(current) == InsertionPoint::AlwaysMatches)
return current;
}
return 0;
}
Node* InsertionPoint::nextDistributedTo(const Node* node) const
{
for (Node* current = node->nextSibling(); current; current = current->nextSibling()) {
if (matchTypeFor(current) == InsertionPoint::AlwaysMatches)
return current;
}
return 0;
}
Node* InsertionPoint::previousDistributedTo(const Node* node) const
{
for (Node* current = node->previousSibling(); current; current = current->previousSibling()) {
if (matchTypeFor(current) == InsertionPoint::AlwaysMatches)
return current;
}
return 0;
}
InsertionPoint* findInsertionPointOf(const Node* projectedNode)
{
if (ShadowRoot* shadowRoot = shadowRootOfParentForDistribution(projectedNode)) {
if (ShadowRoot* root = projectedNode->containingShadowRoot())
ContentDistributor::ensureDistribution(root);
return shadowRoot->distributor().findInsertionPointFor(projectedNode);
}
return 0;
}
}