WebKitNamedFlow.cpp [plain text]
#include "config.h"
#include "WebKitNamedFlow.h"
#include "EventNames.h"
#include "NamedFlowCollection.h"
#include "RenderNamedFlowThread.h"
#include "RenderRegion.h"
#include "ScriptExecutionContext.h"
#include "StaticNodeList.h"
#include "UIEvent.h"
namespace WebCore {
WebKitNamedFlow::WebKitNamedFlow(PassRefPtr<NamedFlowCollection> manager, const AtomicString& flowThreadName)
: m_flowThreadName(flowThreadName)
, m_flowManager(manager)
, m_parentFlowThread(0)
{
}
WebKitNamedFlow::~WebKitNamedFlow()
{
m_flowManager->discardNamedFlow(this);
}
PassRefPtr<WebKitNamedFlow> WebKitNamedFlow::create(PassRefPtr<NamedFlowCollection> manager, const AtomicString& flowThreadName)
{
return adoptRef(new WebKitNamedFlow(manager, flowThreadName));
}
const AtomicString& WebKitNamedFlow::name() const
{
return m_flowThreadName;
}
bool WebKitNamedFlow::overset() const
{
if (m_flowManager->document())
m_flowManager->document()->updateLayoutIgnorePendingStylesheets();
return m_parentFlowThread ? m_parentFlowThread->overset() : true;
}
static inline bool inFlowThread(RenderObject* renderer, RenderNamedFlowThread* flowThread)
{
if (!renderer)
return false;
RenderFlowThread* currentFlowThread = renderer->flowThreadContainingBlock();
if (flowThread == currentFlowThread)
return true;
if (renderer->flowThreadState() != RenderObject::InsideInFlowThread)
return false;
return inFlowThread(currentFlowThread->containingBlock(), flowThread);
}
int WebKitNamedFlow::firstEmptyRegionIndex() const
{
if (m_flowManager->document())
m_flowManager->document()->updateLayoutIgnorePendingStylesheets();
if (!m_parentFlowThread)
return -1;
const RenderRegionList& regionList = m_parentFlowThread->renderRegionList();
if (regionList.isEmpty())
return -1;
RenderRegionList::const_iterator iter = regionList.begin();
for (int index = 0; iter != regionList.end(); ++index, ++iter) {
const RenderRegion* renderRegion = *iter;
if (renderRegion->regionState() == RenderRegion::RegionEmpty)
return index;
}
return -1;
}
PassRefPtr<NodeList> WebKitNamedFlow::getRegionsByContent(Node* contentNode)
{
Vector<RefPtr<Node> > regionNodes;
if (!contentNode)
return StaticNodeList::adopt(regionNodes);
if (m_flowManager->document())
m_flowManager->document()->updateLayoutIgnorePendingStylesheets();
if (!m_parentFlowThread)
return StaticNodeList::adopt(regionNodes);
if (inFlowThread(contentNode->renderer(), m_parentFlowThread)) {
const RenderRegionList& regionList = m_parentFlowThread->renderRegionList();
for (RenderRegionList::const_iterator iter = regionList.begin(); iter != regionList.end(); ++iter) {
const RenderRegion* renderRegion = *iter;
if (!renderRegion->node())
continue;
if (m_parentFlowThread->objectInFlowRegion(contentNode->renderer(), renderRegion))
regionNodes.append(renderRegion->node());
}
}
return StaticNodeList::adopt(regionNodes);
}
PassRefPtr<NodeList> WebKitNamedFlow::getRegions()
{
Vector<RefPtr<Node> > regionNodes;
if (m_flowManager->document())
m_flowManager->document()->updateLayoutIgnorePendingStylesheets();
if (!m_parentFlowThread)
return StaticNodeList::adopt(regionNodes);
const RenderRegionList& regionList = m_parentFlowThread->renderRegionList();
for (RenderRegionList::const_iterator iter = regionList.begin(); iter != regionList.end(); ++iter) {
const RenderRegion* renderRegion = *iter;
if (!renderRegion->node())
continue;
regionNodes.append(renderRegion->node());
}
return StaticNodeList::adopt(regionNodes);
}
PassRefPtr<NodeList> WebKitNamedFlow::getContent()
{
Vector<RefPtr<Node> > contentNodes;
if (m_flowManager->document())
m_flowManager->document()->updateLayoutIgnorePendingStylesheets();
if (!m_parentFlowThread)
return StaticNodeList::adopt(contentNodes);
const NamedFlowContentNodes& contentNodesList = m_parentFlowThread->contentNodes();
for (NamedFlowContentNodes::const_iterator it = contentNodesList.begin(); it != contentNodesList.end(); ++it) {
Node* node = *it;
ASSERT(node->computedStyle()->flowThread() == m_parentFlowThread->flowThreadName());
contentNodes.append(node);
}
return StaticNodeList::adopt(contentNodes);
}
void WebKitNamedFlow::setRenderer(RenderNamedFlowThread* parentFlowThread)
{
ASSERT((!m_parentFlowThread && parentFlowThread) || (m_parentFlowThread && !parentFlowThread));
m_parentFlowThread = parentFlowThread;
}
EventTargetData* WebKitNamedFlow::eventTargetData()
{
return &m_eventTargetData;
}
EventTargetData* WebKitNamedFlow::ensureEventTargetData()
{
return &m_eventTargetData;
}
void WebKitNamedFlow::dispatchRegionLayoutUpdateEvent()
{
ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
if (flowState() == FlowStateNull)
return;
RefPtr<Event> event = UIEvent::create(eventNames().webkitregionlayoutupdateEvent, false, false, m_flowManager->document()->defaultView(), 0);
dispatchEvent(event);
}
const AtomicString& WebKitNamedFlow::interfaceName() const
{
return eventNames().interfaceForWebKitNamedFlow;
}
ScriptExecutionContext* WebKitNamedFlow::scriptExecutionContext() const
{
return m_flowManager->document();
}
Node* WebKitNamedFlow::ownerNode() const
{
return m_flowManager->document();
}
}