/** Sets the current page rect. You must hold the monitor while calling this. */ private void setPageRect(RectF rect, RectF cssRect) { // Since the "rect" is always just a multiple of "cssRect" we don't need to // check both; this function assumes that both "rect" and "cssRect" are relative // the zoom factor in mViewportMetrics. if (mViewportMetrics.getCssPageRect().equals(cssRect)) return; mViewportMetrics = mViewportMetrics.setPageRect(rect, cssRect); // Page size is owned by the layer client, so no need to notify it of // this change. post( new Runnable() { public void run() { mPanZoomController.pageRectUpdated(); mView.requestRender(); } }); }
/** 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; }