示例#1
0
nsresult
BoxObject::GetOffsetRect(nsIntRect& aRect)
{
    aRect.SetRect(0, 0, 0, 0);

    if (!mContent)
        return NS_ERROR_NOT_INITIALIZED;

    // Get the Frame for our content
    nsIFrame* frame = GetFrame(true);
    if (frame) {
        // Get its origin
        nsPoint origin = frame->GetPositionIgnoringScrolling();

        // Find the frame parent whose content is the document element.
        Element* docElement = mContent->GetComposedDoc()->GetRootElement();
        nsIFrame* parent = frame->GetParent();
        for (;;) {
            // If we've hit the document element, break here
            if (parent->GetContent() == docElement) {
                break;
            }

            nsIFrame* next = parent->GetParent();
            if (!next) {
                NS_WARNING("We should have hit the document element...");
                origin += parent->GetPosition();
                break;
            }

            // Add the parent's origin to our own to get to the
            // right coordinate system
            origin += next->GetPositionOfChildIgnoringScrolling(parent);
            parent = next;
        }

        // For the origin, add in the border for the frame
        const nsStyleBorder* border = frame->StyleBorder();
        origin.x += border->GetComputedBorderWidth(NS_SIDE_LEFT);
        origin.y += border->GetComputedBorderWidth(NS_SIDE_TOP);

        // And subtract out the border for the parent
        const nsStyleBorder* parentBorder = parent->StyleBorder();
        origin.x -= parentBorder->GetComputedBorderWidth(NS_SIDE_LEFT);
        origin.y -= parentBorder->GetComputedBorderWidth(NS_SIDE_TOP);

        aRect.x = nsPresContext::AppUnitsToIntCSSPixels(origin.x);
        aRect.y = nsPresContext::AppUnitsToIntCSSPixels(origin.y);

        // Get the union of all rectangles in this and continuation frames.
        // It doesn't really matter what we use as aRelativeTo here, since
        // we only care about the size. Using 'parent' might make things
        // a bit faster by speeding up the internal GetOffsetTo operations.
        nsRect rcFrame = nsLayoutUtils::GetAllInFlowRectsUnion(frame, parent);
        aRect.width = nsPresContext::AppUnitsToIntCSSPixels(rcFrame.width);
        aRect.height = nsPresContext::AppUnitsToIntCSSPixels(rcFrame.height);
    }

    return NS_OK;
}
示例#2
0
bool
AndroidGeckoSoftwareLayerClient::BeginDrawing(int aWidth, int aHeight, int aTileWidth, int aTileHeight, nsIntRect &aDirtyRect, const nsAString &aMetadata, bool aHasDirectTexture)
{
    NS_ASSERTION(!isNull(), "BeginDrawing() called on null software layer client!");
    JNIEnv *env = AndroidBridge::GetJNIEnv();
    if (!env)
        return false;

    AndroidBridge::AutoLocalJNIFrame(env, 1);
    jstring jMetadata = env->NewString(nsPromiseFlatString(aMetadata).get(), aMetadata.Length());

    jobject rectObject = env->CallObjectMethod(wrapped_obj, jBeginDrawingMethod,
                                               aWidth, aHeight, aTileWidth, aTileHeight,
                                               jMetadata, aHasDirectTexture);

    if (rectObject == nsnull)
        return false;

    AndroidRect rect(env, rectObject);
    nsIntRect newDirtyRect = aDirtyRect.Intersect(nsIntRect(rect.Top(), rect.Left(),
                                                            rect.Width(), rect.Height()));
    aDirtyRect.SetRect(newDirtyRect.x, newDirtyRect.y, newDirtyRect.width, newDirtyRect.height);

    return true;
}
示例#3
0
void
LayerManagerOGL::WorldTransformRect(nsIntRect& aRect)
{
    gfxRect grect(aRect.x, aRect.y, aRect.width, aRect.height);
    grect = mWorldMatrix.TransformBounds(grect);
    aRect.SetRect(grect.X(), grect.Y(), grect.Width(), grect.Height());
}