This source file includes following definitions.
- getObjectStack
- iframeIsAbovePlugin
- intersectsRect
- addToOcclusions
- addTreeToOcclusions
- topLayerAncestor
- getPluginOcclusions
#include "config.h"
#include "core/plugins/PluginOcclusionSupport.h"
#include "HTMLNames.h"
#include "core/dom/Element.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLElement.h"
#include "core/html/HTMLFrameOwnerElement.h"
#include "core/rendering/RenderBox.h"
#include "core/rendering/RenderObject.h"
#include "platform/Widget.h"
#include "wtf/HashSet.h"
namespace WebCore {
static void getObjectStack(const RenderObject* ro, Vector<const RenderObject*>* roStack)
{
roStack->clear();
while (ro) {
roStack->append(ro);
ro = ro->parent();
}
}
static bool iframeIsAbovePlugin(const Vector<const RenderObject*>& iframeZstack, const Vector<const RenderObject*>& pluginZstack)
{
for (size_t i = 0; i < iframeZstack.size() && i < pluginZstack.size(); i++) {
const RenderObject* ro1 = iframeZstack[iframeZstack.size() - 1 - i];
const RenderObject* ro2 = pluginZstack[pluginZstack.size() - 1 - i];
if (ro1 != ro2) {
if (ro1->style() && ro2->style()) {
int z1 = ro1->style()->zIndex();
int z2 = ro2->style()->zIndex();
if (z1 > z2)
return true;
if (z1 < z2)
return false;
}
if (ro2->style()->position() == StaticPosition) {
const RenderObject* pluginRenderObject = pluginZstack[0];
const RenderObject* iframeRenderObject = iframeZstack[0];
if (pluginRenderObject->style() && iframeRenderObject->style()) {
if (pluginRenderObject->style()->zIndex() > iframeRenderObject->style()->zIndex())
return false;
}
return true;
}
const RenderObject* parent = ro1->parent();
if (!parent)
return false;
ASSERT(parent == ro2->parent());
for (const RenderObject* ro = parent->firstChild(); ro; ro = ro->nextSibling()) {
if (ro == ro1)
return false;
if (ro == ro2)
return true;
}
ASSERT(false);
return false;
}
}
return true;
}
static bool intersectsRect(const RenderObject* renderer, const IntRect& rect)
{
return renderer->absoluteBoundingBoxRectIgnoringTransforms().intersects(rect)
&& (!renderer->style() || renderer->style()->visibility() == VISIBLE);
}
static void addToOcclusions(const RenderBox* renderer, Vector<IntRect>& occlusions)
{
IntPoint point = roundedIntPoint(renderer->localToAbsolute());
IntSize size(renderer->width(), renderer->height());
occlusions.append(IntRect(point, size));
}
static void addTreeToOcclusions(const RenderObject* renderer, const IntRect& frameRect, Vector<IntRect>& occlusions)
{
if (!renderer)
return;
if (renderer->isBox() && intersectsRect(renderer, frameRect))
addToOcclusions(toRenderBox(renderer), occlusions);
for (RenderObject* child = renderer->firstChild(); child; child = child->nextSibling())
addTreeToOcclusions(child, frameRect, occlusions);
}
static const Element* topLayerAncestor(const Element* element)
{
while (element && !element->isInTopLayer())
element = element->parentOrShadowHostElement();
return element;
}
void getPluginOcclusions(Element* element, Widget* parentWidget, const IntRect& frameRect, Vector<IntRect>& occlusions)
{
RenderObject* pluginNode = element->renderer();
ASSERT(pluginNode);
if (!pluginNode->style())
return;
Vector<const RenderObject*> pluginZstack;
Vector<const RenderObject*> iframeZstack;
getObjectStack(pluginNode, &pluginZstack);
if (!parentWidget->isFrameView())
return;
FrameView* parentFrameView = toFrameView(parentWidget);
const HashSet<RefPtr<Widget> >* children = parentFrameView->children();
for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != children->end(); ++it) {
if (!(*it)->isFrameView())
continue;
const FrameView* frameView = toFrameView((*it).get());
HTMLElement* element = frameView->frame().ownerElement();
if (!element || !element->renderer())
continue;
RenderObject* iframeRenderer = element->renderer();
if (isHTMLIFrameElement(*element) && intersectsRect(iframeRenderer, frameRect)) {
getObjectStack(iframeRenderer, &iframeZstack);
if (iframeIsAbovePlugin(iframeZstack, pluginZstack))
addToOcclusions(toRenderBox(iframeRenderer), occlusions);
}
}
const Element* ancestor = topLayerAncestor(element);
Document* document = parentFrameView->frame().document();
const Vector<RefPtr<Element> >& elements = document->topLayerElements();
size_t start = ancestor ? elements.find(ancestor) + 1 : 0;
for (size_t i = start; i < elements.size(); ++i)
addTreeToOcclusions(elements[i]->renderer(), frameRect, occlusions);
}
}