This source file includes following definitions.
- enclosingScrollableAncestor
- toNormalizedRect
- findInPageRectFromAbsoluteRect
- findInPageRectFromRange
#include "config.h"
#include "FindInPageCoordinates.h"
#include "core/dom/Node.h"
#include "core/dom/Range.h"
#include "core/frame/LocalFrame.h"
#include "core/rendering/RenderBlock.h"
#include "core/rendering/RenderBox.h"
#include "core/rendering/RenderObject.h"
#include "core/rendering/RenderPart.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/style/RenderStyle.h"
#include "platform/geometry/FloatPoint.h"
#include "platform/geometry/FloatQuad.h"
#include "platform/geometry/IntPoint.h"
using namespace WebCore;
namespace blink {
static const RenderBlock* enclosingScrollableAncestor(const RenderObject* renderer)
{
ASSERT(!renderer->isRenderView());
const RenderBlock* container = renderer->containingBlock();
while (!container->hasOverflowClip() && !container->isRenderView())
container = container->containingBlock();
return container;
}
static FloatRect toNormalizedRect(const FloatRect& absoluteRect, const RenderObject* renderer, const RenderBlock* container)
{
ASSERT(renderer);
ASSERT(container || renderer->isRenderView());
if (!container)
return FloatRect();
FloatPoint scrolledOrigin;
if (container->hasOverflowClip())
scrolledOrigin = -IntPoint(container->scrolledContentOffset());
FloatRect overflowRect(scrolledOrigin, container->maxLayoutOverflow());
FloatRect containerRect = container->localToAbsoluteQuad(FloatQuad(overflowRect)).enclosingBoundingBox();
if (containerRect.isEmpty())
return FloatRect();
FloatRect normalizedRect = absoluteRect;
normalizedRect.moveBy(-containerRect.location());
if (renderer->style()->position() == FixedPosition && container->isRenderView())
normalizedRect.move(-toRenderView(container)->frameView()->scrollOffsetForFixedPosition());
normalizedRect.scale(1 / containerRect.width(), 1 / containerRect.height());
return normalizedRect;
}
FloatRect findInPageRectFromAbsoluteRect(const FloatRect& inputRect, const RenderObject* baseRenderer)
{
if (!baseRenderer || inputRect.isEmpty())
return FloatRect();
const RenderBlock* baseContainer = enclosingScrollableAncestor(baseRenderer);
FloatRect normalizedRect = toNormalizedRect(inputRect, baseRenderer, baseContainer);
for (const RenderBox* renderer = baseContainer; renderer; ) {
while (!renderer->isRenderView()) {
const RenderBlock* container = enclosingScrollableAncestor(renderer);
FloatRect normalizedBoxRect = toNormalizedRect(renderer->absoluteBoundingBoxRect(), renderer, container);
normalizedRect.scale(normalizedBoxRect.width(), normalizedBoxRect.height());
normalizedRect.moveBy(normalizedBoxRect.location());
renderer = container;
}
ASSERT(renderer->isRenderView());
renderer = renderer->frame() ? renderer->frame()->ownerRenderer() : 0;
}
return normalizedRect;
}
FloatRect findInPageRectFromRange(Range* range)
{
if (!range || !range->firstNode())
return FloatRect();
return findInPageRectFromAbsoluteRect(RenderObject::absoluteBoundingBoxRectForRange(range), range->firstNode()->renderer());
}
}