/** * This function is invoked by Gecko via JNI; be careful when modifying signature. The compositor * invokes this function whenever it determines that the page rect has changed (based on the * information it gets from layout). If setFirstPaintViewport is invoked on a frame, then this * function will not be. For any given frame, this function will be invoked before * syncViewportInfo. */ public void setPageRect( float cssPageLeft, float cssPageTop, float cssPageRight, float cssPageBottom) { synchronized (this) { RectF cssPageRect = new RectF(cssPageLeft, cssPageTop, cssPageRight, cssPageBottom); float ourZoom = getViewportMetrics().zoomFactor; setPageRect(RectUtils.scale(cssPageRect, ourZoom), cssPageRect); // Here the page size of the document has changed, but the document being displayed // is still the same. Therefore, we don't need to send anything to browser.js; any // changes we need to make to the display port will get sent the next time we call // adjustViewport(). } }
/** 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; }