Пример #1
0
FloatRect findInPageRectFromAbsoluteRect(const FloatRect& inputRect, const LayoutObject* baseLayoutObject)
{
    if (!baseLayoutObject || inputRect.isEmpty())
        return FloatRect();

    // Normalize the input rect to its container block.
    const LayoutBlock* baseContainer = enclosingScrollableAncestor(baseLayoutObject);
    FloatRect normalizedRect = toNormalizedRect(inputRect, baseLayoutObject, baseContainer);

    // Go up across frames.
    for (const LayoutBox* layoutObject = baseContainer; layoutObject; ) {

        // Go up the layout tree until we reach the root of the current frame (the LayoutView).
        while (!layoutObject->isLayoutView()) {
            const LayoutBlock* container = enclosingScrollableAncestor(layoutObject);

            // Compose the normalized rects.
            FloatRect normalizedBoxRect = toNormalizedRect(layoutObject->absoluteBoundingBoxRect(), layoutObject, container);
            normalizedRect.scale(normalizedBoxRect.width(), normalizedBoxRect.height());
            normalizedRect.moveBy(normalizedBoxRect.location());

            layoutObject = container;
        }

        ASSERT(layoutObject->isLayoutView());

        // Jump to the layoutObject owning the frame, if any.
        layoutObject = layoutObject->frame() ? layoutObject->frame()->ownerLayoutObject() : 0;
    }

    return normalizedRect;
}
Пример #2
0
FloatRect findInPageRectFromAbsoluteRect(const FloatRect& inputRect, const RenderObject* baseRenderer)
{
    if (!baseRenderer || inputRect.isEmpty())
        return FloatRect();

    // Normalize the input rect to its container block.
    const RenderBlock* baseContainer = enclosingScrollableAncestor(baseRenderer);
    FloatRect normalizedRect = toNormalizedRect(inputRect, baseRenderer, baseContainer);

    // Go up across frames.
    for (const RenderBox* renderer = baseContainer; renderer; ) {

        // Go up the render tree until we reach the root of the current frame (the RenderView).
        while (!renderer->isRenderView()) {
            const RenderBlock* container = enclosingScrollableAncestor(renderer);

            // Compose the normalized rects.
            FloatRect normalizedBoxRect = toNormalizedRect(renderer->absoluteBoundingBoxRect(), renderer, container);
            normalizedRect.scale(normalizedBoxRect.width(), normalizedBoxRect.height());
            normalizedRect.moveBy(normalizedBoxRect.location());

            renderer = container;
        }

        ASSERT(renderer->isRenderView());

        // Jump to the renderer owning the frame, if any.
        renderer = renderer->frame() ? renderer->frame()->ownerRenderer() : 0;
    }

    return normalizedRect;
}