コード例 #1
0
  /**
   * This function is invoked by Gecko via JNI; be careful when modifying signature. The compositor
   * invokes this function just before compositing a frame where the document is different from the
   * document composited on the last frame. In these cases, the viewport information we have in Java
   * is no longer valid and needs to be replaced with the new viewport information provided.
   * setPageRect will never be invoked on the same frame that this function is invoked on; and this
   * function will always be called prior to syncViewportInfo.
   */
  public void setFirstPaintViewport(
      float offsetX,
      float offsetY,
      float zoom,
      float pageLeft,
      float pageTop,
      float pageRight,
      float pageBottom,
      float cssPageLeft,
      float cssPageTop,
      float cssPageRight,
      float cssPageBottom) {
    synchronized (this) {
      final ImmutableViewportMetrics newMetrics =
          getViewportMetrics()
              .setViewportOrigin(offsetX, offsetY)
              .setZoomFactor(zoom)
              .setPageRect(
                  new RectF(pageLeft, pageTop, pageRight, pageBottom),
                  new RectF(cssPageLeft, cssPageTop, cssPageRight, cssPageBottom));
      // Since we have switched to displaying a different document, we need to update any
      // viewport-related state we have lying around. This includes mGeckoViewport and
      // mViewportMetrics. Usually this information is updated via handleViewportMessage
      // while we remain on the same document.
      post(
          new Runnable() {
            public void run() {
              mGeckoViewport = newMetrics;
            }
          });
      setViewportMetrics(newMetrics);

      Tab tab = Tabs.getInstance().getSelectedTab();
      mView.setBackgroundColor(tab.getBackgroundColor());
      setZoomConstraints(tab.getZoomConstraints());

      // At this point, we have just switched to displaying a different document than we
      // we previously displaying. This means we need to abort any panning/zooming animations
      // that are in progress and send an updated display port request to browser.js as soon
      // as possible. We accomplish this by passing true to abortPanZoomAnimation, which
      // sends the request after aborting the animation. The display port request is actually
      // a full viewport update, which is fine because if browser.js has somehow moved to
      // be out of sync with this first-paint viewport, then we force them back in sync.
      abortPanZoomAnimation();

      // Indicate that the document is about to be composited so the
      // LayerView background can be removed.
      if (mView.getPaintState() == LayerView.PAINT_START) {
        mView.setPaintState(LayerView.PAINT_BEFORE_FIRST);
      }
    }
    DisplayPortCalculator.resetPageState();
    mDrawTimingQueue.reset();
  }
コード例 #2
0
  /** Viewport message handler. */
  private DisplayPortMetrics handleViewportMessage(
      ImmutableViewportMetrics messageMetrics, ViewportMessageType type) {
    synchronized (this) {
      ImmutableViewportMetrics metrics;
      ImmutableViewportMetrics oldMetrics = getViewportMetrics();

      switch (type) {
        default:
        case UPDATE:
          // Keep the old viewport size
          metrics = messageMetrics.setViewportSize(oldMetrics.getWidth(), oldMetrics.getHeight());
          abortPanZoomAnimation();
          break;
        case PAGE_SIZE:
          // adjust the page dimensions to account for differences in zoom
          // between the rendered content (which is what Gecko tells us)
          // and our zoom level (which may have diverged).
          float scaleFactor = oldMetrics.zoomFactor / messageMetrics.zoomFactor;
          metrics =
              oldMetrics.setPageRect(
                  RectUtils.scale(messageMetrics.getPageRect(), scaleFactor),
                  messageMetrics.getCssPageRect());
          break;
      }

      final ImmutableViewportMetrics newMetrics = metrics;
      post(
          new Runnable() {
            public void run() {
              mGeckoViewport = newMetrics;
            }
          });
      setViewportMetrics(newMetrics, type == ViewportMessageType.UPDATE);
      mDisplayPort = DisplayPortCalculator.calculate(getViewportMetrics(), null);
    }
    return mDisplayPort;
  }