Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarControlContainer.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarControlContainer.java b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarControlContainer.java |
| index eb6c5ef8a688ac8a972d51393c9f880f13511c2d..7d3c6604e620bac52262f9eb35dbb3faa0c7d82f 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarControlContainer.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarControlContainer.java |
| @@ -6,11 +6,9 @@ package org.chromium.chrome.browser.toolbar; |
| import android.content.Context; |
| import android.graphics.Canvas; |
| +import android.graphics.Color; |
| import android.graphics.PorterDuff; |
| import android.graphics.Rect; |
| -import android.graphics.drawable.Drawable; |
| -import android.graphics.drawable.LayerDrawable; |
| -import android.graphics.drawable.ScaleDrawable; |
| import android.util.AttributeSet; |
| import android.view.MotionEvent; |
| import android.view.View; |
| @@ -19,9 +17,9 @@ import android.widget.FrameLayout; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandler; |
| import org.chromium.chrome.browser.contextualsearch.SwipeRecognizer; |
| +import org.chromium.chrome.browser.widget.ClipDrawableProgressBar.InvalidationListener; |
| import org.chromium.chrome.browser.widget.ControlContainer; |
| -import org.chromium.chrome.browser.widget.SmoothProgressBar; |
| -import org.chromium.chrome.browser.widget.SmoothProgressBar.ProgressChangeListener; |
| +import org.chromium.chrome.browser.widget.ToolbarProgressBar; |
| import org.chromium.chrome.browser.widget.ViewResourceFrameLayout; |
| import org.chromium.ui.UiUtils; |
| import org.chromium.ui.resources.dynamics.ViewResourceAdapter; |
| @@ -79,7 +77,7 @@ public class ToolbarControlContainer extends FrameLayout implements ControlConta |
| // TODO(yusufo): Get rid of the calls below and avoid casting to the layout without making |
| // the interface bigger. |
| - SmoothProgressBar progressView = ((ToolbarLayout) mToolbar).getProgressBar(); |
| + ToolbarProgressBar progressView = ((ToolbarLayout) mToolbar).getProgressBar(); |
| if (progressView != null) { |
| mProgressResourceAdapter = new ProgressViewResourceAdapter(progressView); |
| } |
| @@ -136,94 +134,54 @@ public class ToolbarControlContainer extends FrameLayout implements ControlConta |
| } |
| private static class ProgressViewResourceAdapter extends ViewResourceAdapter |
| - implements ProgressChangeListener { |
| + implements InvalidationListener { |
| - private final SmoothProgressBar mProgressView; |
| - private final Rect mPreviousDrawBounds = new Rect(); |
| - private int mProgressVisibility; |
| - private int mProgress; |
| + private final ToolbarProgressBar mProgressView; |
| + private final Rect mAlphaBound = new Rect(); |
| - ProgressViewResourceAdapter(SmoothProgressBar progressView) { |
| + ProgressViewResourceAdapter(ToolbarProgressBar progressView) { |
| super(progressView); |
| mProgressView = progressView; |
| - mProgressVisibility = mProgressView.getVisibility(); |
| - progressView.addProgressChangeListener(this); |
| + progressView.setInvalidationListener(this); |
| } |
| @Override |
| - public void onProgressChanged(int progress) { |
| - if (mProgressVisibility != View.VISIBLE) return; |
| - if (progress < mProgress) { |
| - mPreviousDrawBounds.setEmpty(); |
| - } |
| - mProgress = progress; |
| - invalidate(null); |
| - } |
| - |
| - @Override |
| - public void onProgressVisibilityChanged(int visibility) { |
| - if (mProgressVisibility == visibility) return; |
| + protected void capture(Canvas canvas) { |
| + if (mProgressView.getVisibility() != View.VISIBLE) { |
| + canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| + } else { |
| + // If we're drawing alpha somewhere, we need to clear that part of the canvas to |
| + // avoid undesired accumulation (getting darker). |
| + canvas.save(); |
| + mProgressView.getAlphaBound(mAlphaBound); |
|
Ted C
2015/07/15 02:41:12
getAlphaBound[s]
or maybe
getAlphaDrawRegion
or
Kibeom Kim (inactive)
2015/07/15 11:22:45
Done. getAlphaDrawRegion sounds better..
|
| + mAlphaBound.intersect(getDirtyRect()); |
| + canvas.clipRect(mAlphaBound); |
| + canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); |
| + canvas.restore(); |
| - if (visibility == View.VISIBLE || mProgressVisibility == View.VISIBLE) { |
| - invalidate(null); |
| - mPreviousDrawBounds.setEmpty(); |
| + super.capture(canvas); |
| } |
| - mProgressVisibility = visibility; |
| } |
| @Override |
| - protected void onCaptureStart(Canvas canvas, Rect dirtyRect) { |
| - canvas.save(); |
| - canvas.clipRect( |
| - mPreviousDrawBounds.right, 0, |
| - mProgressView.getWidth(), mProgressView.getHeight()); |
| - canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| - canvas.restore(); |
| - |
| - super.onCaptureStart(canvas, dirtyRect); |
| + protected void computeContentPadding(Rect outContentPadding) { |
| + super.computeContentPadding(outContentPadding); |
| + MarginLayoutParams layoutParams = (MarginLayoutParams) mProgressView.getLayoutParams(); |
| + outContentPadding.offset(0, layoutParams.topMargin); |
| } |
| @Override |
| - protected void capture(Canvas canvas) { |
| - if (mProgressVisibility != View.VISIBLE) { |
| - canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| - } else { |
| - super.capture(canvas); |
| - } |
| + public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, |
| + int oldTop, int oldRight, int oldBottom) { |
| + // Purposefully ignore as invalidation listener handles it. |
| } |
| - @Override |
| - protected void onCaptureEnd() { |
| - super.onCaptureEnd(); |
| - // If we are unable to get accurate draw bounds, then set the draw bounds to |
| - // ensure the entire view is cleared. |
| - mPreviousDrawBounds.setEmpty(); |
| - |
| - // The secondary drawable has an alpha component, so track the bounds of the |
| - // primary drawable. This will allow the subsequent draw call to clear the secondary |
| - // portion not overlapped by the primary to prevent the alpha components from |
| - // stacking and getting progressively darker. |
| - Drawable progressDrawable = mProgressView.getProgressDrawable(); |
| - if (progressDrawable instanceof LayerDrawable) { |
| - LayerDrawable progressLayerDrawable = (LayerDrawable) progressDrawable; |
| - for (int i = 0; i < progressLayerDrawable.getNumberOfLayers(); i++) { |
| - if (progressLayerDrawable.getId(i) != android.R.id.progress) continue; |
| - Drawable primaryProgressDrawable = progressLayerDrawable.getDrawable(i); |
| - if (!(primaryProgressDrawable instanceof ScaleDrawable)) continue; |
| - |
| - ((ScaleDrawable) primaryProgressDrawable).getDrawable().copyBounds( |
| - mPreviousDrawBounds); |
| - } |
| - } |
| - } |
| + // InvalidationListener implementation. |
| @Override |
| - protected void computeContentPadding(Rect outContentPadding) { |
| - super.computeContentPadding(outContentPadding); |
| - MarginLayoutParams layoutParams = |
| - (MarginLayoutParams) mProgressView.getLayoutParams(); |
| - outContentPadding.offset(0, layoutParams.topMargin); |
| + public void onInvalidation(Rect dirtyRect) { |
| + invalidate(dirtyRect); |
| } |
| } |