OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.Canvas; | 10 import android.graphics.Canvas; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 | 115 |
116 // Since we sometimes overflow the bounds of the mViewClipRect, we need to a llow scrolling. | 116 // Since we sometimes overflow the bounds of the mViewClipRect, we need to a llow scrolling. |
117 // Current scroll position. | 117 // Current scroll position. |
118 private float mPopupScrollX, mPopupScrollY; | 118 private float mPopupScrollX, mPopupScrollY; |
119 // Scroll bounds. | 119 // Scroll bounds. |
120 private float mMinScrollX, mMaxScrollX; | 120 private float mMinScrollX, mMaxScrollX; |
121 private float mMinScrollY, mMaxScrollY; | 121 private float mMinScrollY, mMaxScrollY; |
122 | 122 |
123 private GestureDetector mGestureDetector; | 123 private GestureDetector mGestureDetector; |
124 | 124 |
125 // These bounds are computed in onDraw(). | |
Yaron
2014/09/10 01:37:16
perhaps update to say:
// These bounds are compute
wajahat
2014/09/10 11:34:52
Done.
| |
126 private RectF mDrawRect; | |
127 | |
125 private static float getOverlayCornerRadius(Context context) { | 128 private static float getOverlayCornerRadius(Context context) { |
126 if (sOverlayCornerRadius == 0) { | 129 if (sOverlayCornerRadius == 0) { |
127 try { | 130 try { |
128 sOverlayCornerRadius = context.getResources().getDimension( | 131 sOverlayCornerRadius = context.getResources().getDimension( |
129 R.dimen.link_preview_overlay_radius); | 132 R.dimen.link_preview_overlay_radius); |
130 } catch (Resources.NotFoundException e) { | 133 } catch (Resources.NotFoundException e) { |
131 Log.w(LOGTAG, "No corner radius resource for PopupZoomer overlay found."); | 134 Log.w(LOGTAG, "No corner radius resource for PopupZoomer overlay found."); |
132 sOverlayCornerRadius = 1.0f; | 135 sOverlayCornerRadius = 1.0f; |
133 } | 136 } |
134 } | 137 } |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 // i.e. scale grows from 1/mScale to 1. Note that extrusion values are a lready zoomed | 458 // i.e. scale grows from 1/mScale to 1. Note that extrusion values are a lready zoomed |
456 // with mScale. | 459 // with mScale. |
457 float scale = fractionAnimation * (mScale - 1.0f) / mScale + 1.0f / mSca le; | 460 float scale = fractionAnimation * (mScale - 1.0f) / mScale + 1.0f / mSca le; |
458 | 461 |
459 // Since we want the content to appear directly above its counterpart on the | 462 // Since we want the content to appear directly above its counterpart on the |
460 // page, we need to remove the mShiftX/Y effect at the beginning of the animation. | 463 // page, we need to remove the mShiftX/Y effect at the beginning of the animation. |
461 // The unshifting decreases with the animation. | 464 // The unshifting decreases with the animation. |
462 float unshiftX = -mShiftX * (1.0f - fractionAnimation) / mScale; | 465 float unshiftX = -mShiftX * (1.0f - fractionAnimation) / mScale; |
463 float unshiftY = -mShiftY * (1.0f - fractionAnimation) / mScale; | 466 float unshiftY = -mShiftY * (1.0f - fractionAnimation) / mScale; |
464 | 467 |
465 // Compute the rect to show. | 468 // Compute the |mDrawRect| to show. |
466 RectF rect = new RectF(); | 469 mDrawRect.left = mTouch.x - mLeftExtrusion * scale + unshiftX; |
467 rect.left = mTouch.x - mLeftExtrusion * scale + unshiftX; | 470 mDrawRect.top = mTouch.y - mTopExtrusion * scale + unshiftY; |
468 rect.top = mTouch.y - mTopExtrusion * scale + unshiftY; | 471 mDrawRect.right = mTouch.x + mRightExtrusion * scale + unshiftX; |
469 rect.right = mTouch.x + mRightExtrusion * scale + unshiftX; | 472 mDrawRect.bottom = mTouch.y + mBottomExtrusion * scale + unshiftY; |
470 rect.bottom = mTouch.y + mBottomExtrusion * scale + unshiftY; | 473 canvas.clipRect(mDrawRect); |
471 canvas.clipRect(rect); | |
472 | 474 |
473 // Since the canvas transform APIs all pre-concat the transformations, t his is done in | 475 // Since the canvas transform APIs all pre-concat the transformations, t his is done in |
474 // reverse order. The canvas is first scaled up, then shifted the approp riate amount of | 476 // reverse order. The canvas is first scaled up, then shifted the approp riate amount of |
475 // pixels. | 477 // pixels. |
476 canvas.scale(scale, scale, rect.left, rect.top); | 478 canvas.scale(scale, scale, mDrawRect.left, mDrawRect.top); |
477 canvas.translate(mPopupScrollX, mPopupScrollY); | 479 canvas.translate(mPopupScrollX, mPopupScrollY); |
478 canvas.drawBitmap(mZoomedBitmap, rect.left, rect.top, null); | 480 canvas.drawBitmap(mZoomedBitmap, mDrawRect.left, mDrawRect.top, null); |
479 canvas.restore(); | 481 canvas.restore(); |
480 Drawable overlayNineTile = getOverlayDrawable(getContext()); | 482 Drawable overlayNineTile = getOverlayDrawable(getContext()); |
481 overlayNineTile.setBounds((int) rect.left - sOverlayPadding.left, | 483 overlayNineTile.setBounds((int) mDrawRect.left - sOverlayPadding.left, |
482 (int) rect.top - sOverlayPadding.top, | 484 (int) mDrawRect.top - sOverlayPadding.top, |
483 (int) rect.right + sOverlayPadding.right, | 485 (int) mDrawRect.right + sOverlayPadding.right, |
484 (int) rect.bottom + sOverlayPadding.bottom); | 486 (int) mDrawRect.bottom + sOverlayPadding.bottom); |
485 // TODO(nileshagrawal): We should use time here instead of fractionAnima tion | 487 // TODO(nileshagrawal): We should use time here instead of fractionAnima tion |
486 // as fractionAnimaton is interpolated and can go over 1. | 488 // as fractionAnimaton is interpolated and can go over 1. |
487 int alpha = constrain((int) (fractionAnimation * 255), 0, 255); | 489 int alpha = constrain((int) (fractionAnimation * 255), 0, 255); |
488 overlayNineTile.setAlpha(alpha); | 490 overlayNineTile.setAlpha(alpha); |
489 overlayNineTile.draw(canvas); | 491 overlayNineTile.draw(canvas); |
490 canvas.restore(); | 492 canvas.restore(); |
491 } | 493 } |
492 | 494 |
493 /** | 495 /** |
494 * Show the PopupZoomer view with given target bounds. | 496 * Show the PopupZoomer view with given target bounds. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 } | 548 } |
547 | 549 |
548 @Override | 550 @Override |
549 public float getInterpolation(float input) { | 551 public float getInterpolation(float input) { |
550 input = 1.0f - input; | 552 input = 1.0f - input; |
551 if (mInterpolator == null) return input; | 553 if (mInterpolator == null) return input; |
552 return mInterpolator.getInterpolation(input); | 554 return mInterpolator.getInterpolation(input); |
553 } | 555 } |
554 } | 556 } |
555 } | 557 } |
OLD | NEW |