IFrameShimSupport.cpp [plain text]
#include "config.h"
#include "IFrameShimSupport.h"
#include "Element.h"
#include "Frame.h"
#include "FrameView.h"
#include "HTMLElement.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLNames.h"
#include "RenderBox.h"
#include "RenderObject.h"
#include "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;
}
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());
if (!frameView->frame() || !frameView->frame()->ownerElement()
|| !frameView->frame()->ownerElement()->renderer())
continue;
HTMLElement* element = frameView->frame()->ownerElement();
RenderObject* iframeRenderer = element->renderer();
if (element->hasTagName(HTMLNames::iframeTag)
&& iframeRenderer->absoluteBoundingBoxRectIgnoringTransforms().intersects(frameRect)
&& (!iframeRenderer->style() || iframeRenderer->style()->visibility() == VISIBLE)) {
getObjectStack(iframeRenderer, &iframeZstack);
if (iframeIsAbovePlugin(iframeZstack, pluginZstack)) {
IntPoint point = roundedIntPoint(iframeRenderer->localToAbsolute());
RenderBox* rbox = toRenderBox(iframeRenderer);
IntSize size(rbox->width(), rbox->height());
occlusions.append(IntRect(point, size));
}
}
}
}
}