Skip to content

Commit

Permalink
[android] Un-delete zoom APIs.
Browse files Browse the repository at this point in the history
The Zoom APIs are still needed, so partially reverting r227763.

R=joth@chromium.org, qinmin@chromium.org
TBR=joth@chromium.org

BUG=None
TEST=None

Review URL: https://codereview.chromium.org/26737002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227793 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
qinmin@chromium.org committed Oct 9, 2013
1 parent e333012 commit c2c6c07
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,42 @@ public boolean isCrashed() {
}

/**
* Return the current scale.
* Zooms in the WebView by 25% (or less if that would result in zooming in
* more than possible).
*
* @return True if there was a zoom change, false otherwise.
*/
// This method uses the term 'zoom' for legacy reasons, but relates
// to what chrome calls the 'page scale factor'.
public boolean zoomIn() {
return mContentViewCore.zoomIn();
}

/**
* Zooms out the WebView by 20% (or less if that would result in zooming out
* more than possible).
*
* @return True if there was a zoom change, false otherwise.
*/
// This method uses the term 'zoom' for legacy reasons, but relates
// to what chrome calls the 'page scale factor'.
public boolean zoomOut() {
return mContentViewCore.zoomOut();
}

/**
* Resets the zoom factor of the WebView.
*
* @return True if there was a zoom change, false otherwise.
*/
// This method uses the term 'zoom' for legacy reasons, but relates
// to what chrome calls the 'page scale factor'.
public boolean zoomReset() {
return mContentViewCore.zoomReset();
}

/**
* Return the current scale of the WebView
* @return The current scale.
*/
public float getScale() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public class ContentViewCore implements MotionEventDelegate,

private static final String TAG = "ContentViewCore";

// Used to avoid enabling zooming in / out if resulting zooming will
// produce little visible difference.
private static final float ZOOM_CONTROLS_EPSILON = 0.007f;

// Used to represent gestures for long press and long tap.
private static final int IS_LONG_PRESS = 1;
private static final int IS_LONG_TAP = 2;
Expand Down Expand Up @@ -2574,11 +2578,82 @@ public boolean hasFocus() {
return mContainerView.hasFocus();
}

/**
* Checks whether the ContentViewCore can be zoomed in.
*
* @return True if the ContentViewCore can be zoomed in.
*/
// This method uses the term 'zoom' for legacy reasons, but relates
// to what chrome calls the 'page scale factor'.
public boolean canZoomIn() {
final float zoomInExtent = mRenderCoordinates.getMaxPageScaleFactor()
- mRenderCoordinates.getPageScaleFactor();
return zoomInExtent > ZOOM_CONTROLS_EPSILON;
}

/**
* Checks whether the ContentViewCore can be zoomed out.
*
* @return True if the ContentViewCore can be zoomed out.
*/
// This method uses the term 'zoom' for legacy reasons, but relates
// to what chrome calls the 'page scale factor'.
public boolean canZoomOut() {
final float zoomOutExtent = mRenderCoordinates.getPageScaleFactor()
- mRenderCoordinates.getMinPageScaleFactor();
return zoomOutExtent > ZOOM_CONTROLS_EPSILON;
}

/**
* Zooms in the ContentViewCore by 25% (or less if that would result in
* zooming in more than possible).
*
* @return True if there was a zoom change, false otherwise.
*/
// This method uses the term 'zoom' for legacy reasons, but relates
// to what chrome calls the 'page scale factor'.
public boolean zoomIn() {
if (!canZoomIn()) {
return false;
}
return pinchByDelta(1.25f);
}

/**
* Zooms out the ContentViewCore by 20% (or less if that would result in
* zooming out more than possible).
*
* @return True if there was a zoom change, false otherwise.
*/
// This method uses the term 'zoom' for legacy reasons, but relates
// to what chrome calls the 'page scale factor'.
public boolean zoomOut() {
if (!canZoomOut()) {
return false;
}
return pinchByDelta(0.8f);
}

/**
* Resets the zoom factor of the ContentViewCore.
*
* @return True if there was a zoom change, false otherwise.
*/
// This method uses the term 'zoom' for legacy reasons, but relates
// to what chrome calls the 'page scale factor'.
public boolean zoomReset() {
// The page scale factor is initialized to mNativeMinimumScale when
// the page finishes loading. Thus sets it back to mNativeMinimumScale.
if (!canZoomOut()) return false;
return pinchByDelta(
mRenderCoordinates.getMinPageScaleFactor()
/ mRenderCoordinates.getPageScaleFactor());
}

/**
* Simulate a pinch zoom gesture.
*
* @param delta the factor by which the current page scale should be multiplied by.
*
* @return whether the gesture was sent.
*/
public boolean pinchByDelta(float delta) {
Expand Down

0 comments on commit c2c6c07

Please sign in to comment.