Esempio n. 1
0
gfx::Matrix
ComputeTransformForUnRotation(const nsIntRect& aBounds,
                              ScreenRotation aRotation)
{
    gfx::Matrix transform;
    static const gfx::Float floatPi = static_cast<gfx::Float>(M_PI);

    switch (aRotation) {
    case ROTATION_0:
        break;
    case ROTATION_90:
        transform.PreTranslate(0, aBounds.Height());
        transform.PreRotate(floatPi * 3 / 2);
        break;
    case ROTATION_180:
        transform.PreTranslate(aBounds.Width(), aBounds.Height());
        transform.PreRotate(floatPi);
        break;
    case ROTATION_270:
        transform.PreTranslate(aBounds.Width(), 0);
        transform.PreRotate(floatPi / 2);
        break;
    default:
        MOZ_CRASH("Unknown rotation");
    }
    return transform;
}
Esempio n. 2
0
nsIntRect RotateRect(nsIntRect aRect,
                     const nsIntRect& aBounds,
                     ScreenRotation aRotation)
{
  switch (aRotation) {
    case ROTATION_0:
      return aRect;
    case ROTATION_90:
      return nsIntRect(aRect.Y(),
                       aBounds.Width() - aRect.XMost(),
                       aRect.Height(), aRect.Width());
    case ROTATION_180:
      return nsIntRect(aBounds.Width() - aRect.XMost(),
                       aBounds.Height() - aRect.YMost(),
                       aRect.Width(), aRect.Height());
    case ROTATION_270:
      return nsIntRect(aBounds.Height() - aRect.YMost(),
                       aRect.X(),
                       aRect.Height(), aRect.Width());
    default:
      MOZ_CRASH("Unknown rotation");
  }
}
Esempio n. 3
0
bool
TabChild::RecvUpdateFrame(const nsIntRect& aDisplayPort,
                          const nsIntPoint& aScrollOffset,
                          const gfxSize& aResolution,
                          const nsIntRect& aScreenSize)
{
    if (!mCx || !mTabChildGlobal) {
        return true;
    }
    nsCString data;
    data += nsPrintfCString("{ \"x\" : %d", aScrollOffset.x);
    data += nsPrintfCString(", \"y\" : %d", aScrollOffset.y);
    // We don't treat the x and y scales any differently for this
    // semi-platform-specific code.
    data += nsPrintfCString(", \"zoom\" : %f", aResolution.width);
    data += nsPrintfCString(", \"displayPort\" : ");
        data += nsPrintfCString("{ \"left\" : %d", aDisplayPort.X());
        data += nsPrintfCString(", \"top\" : %d", aDisplayPort.Y());
        data += nsPrintfCString(", \"width\" : %d", aDisplayPort.Width());
        data += nsPrintfCString(", \"height\" : %d", aDisplayPort.Height());
        data += nsPrintfCString(", \"resolution\" : %f", aResolution.width);
        data += nsPrintfCString(" }");
    data += nsPrintfCString(", \"screenSize\" : ");
        data += nsPrintfCString("{ \"width\" : %d", aScreenSize.width);
        data += nsPrintfCString(", \"height\" : %d", aScreenSize.height);
        data += nsPrintfCString(" }");
    data += nsPrintfCString(" }");

    jsval json = JSVAL_NULL;
    StructuredCloneData cloneData;
    JSAutoStructuredCloneBuffer buffer;
    if (JS_ParseJSON(mCx,
                      static_cast<const jschar*>(NS_ConvertUTF8toUTF16(data).get()),
                      data.Length(),
                      &json)) {
        WriteStructuredClone(mCx, json, buffer, cloneData.mClosure);
    }

    nsFrameScriptCx cx(static_cast<nsIWebBrowserChrome*>(this), this);
    // Let the BrowserElementScrolling helper (if it exists) for this
    // content manipulate the frame state.
    nsRefPtr<nsFrameMessageManager> mm =
      static_cast<nsFrameMessageManager*>(mTabChildGlobal->mMessageManager.get());
    mm->ReceiveMessage(static_cast<nsIDOMEventTarget*>(mTabChildGlobal),
                       NS_LITERAL_STRING("Viewport:Change"), false,
                       &cloneData, nullptr, nullptr);
    return true;
}