| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.ui.resources.dynamics; | 5 package org.chromium.ui.resources.dynamics; |
| 6 | 6 |
| 7 import android.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
| 8 import android.graphics.Canvas; | 8 import android.graphics.Canvas; |
| 9 import android.graphics.Color; | 9 import android.graphics.Color; |
| 10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
| 11 import android.view.View; | 11 import android.view.View; |
| 12 import android.view.View.OnLayoutChangeListener; | 12 import android.view.View.OnLayoutChangeListener; |
| 13 | 13 |
| 14 import org.chromium.base.TraceEvent; | 14 import org.chromium.base.TraceEvent; |
| 15 import org.chromium.ui.resources.Resource; |
| 16 import org.chromium.ui.resources.ResourceFactory; |
| 17 import org.chromium.ui.resources.statics.NinePatchData; |
| 15 | 18 |
| 16 /** | 19 /** |
| 17 * An adapter that exposes a {@link View} as a {@link DynamicResource}. In order
to properly use | 20 * An adapter that exposes a {@link View} as a {@link DynamicResource}. In order
to properly use |
| 18 * this adapter {@link ViewResourceAdapter#invalidate(Rect)} must be called when
parts of the | 21 * this adapter {@link ViewResourceAdapter#invalidate(Rect)} must be called when
parts of the |
| 19 * {@link View} are invalidated. For {@link ViewGroup}s the easiest way to do t
his is to override | 22 * {@link View} are invalidated. For {@link ViewGroup}s the easiest way to do t
his is to override |
| 20 * {@link View#invalidateChildInParent(int[], Rect)}. | 23 * {@link View#invalidateChildInParent(int[], Rect)}. |
| 21 */ | 24 */ |
| 22 public class ViewResourceAdapter implements DynamicResource, OnLayoutChangeListe
ner { | 25 public class ViewResourceAdapter implements DynamicResource, OnLayoutChangeListe
ner { |
| 23 private final View mView; | 26 private final View mView; |
| 24 private final Rect mDirtyRect = new Rect(); | 27 private final Rect mDirtyRect = new Rect(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 TraceEvent.end("ViewResourceAdapter:getBitmap"); | 69 TraceEvent.end("ViewResourceAdapter:getBitmap"); |
| 67 return mBitmap; | 70 return mBitmap; |
| 68 } | 71 } |
| 69 | 72 |
| 70 @Override | 73 @Override |
| 71 public Rect getBitmapSize() { | 74 public Rect getBitmapSize() { |
| 72 return mBitmapSize; | 75 return mBitmapSize; |
| 73 } | 76 } |
| 74 | 77 |
| 75 @Override | 78 @Override |
| 76 public Rect getPadding() { | 79 public long createNativeResource() { |
| 80 // TODO(khushalsagar): Fix this to create the correct native resource ty
pe. |
| 81 // See crbug.com/700454. |
| 77 computeContentPadding(mContentPadding); | 82 computeContentPadding(mContentPadding); |
| 78 | 83 computeContentAperture(mContentAperture); |
| 79 return mContentPadding; | 84 return ResourceFactory.createNinePatchBitmapResource(mContentPadding, mC
ontentAperture); |
| 80 } | 85 } |
| 81 | 86 |
| 82 @Override | 87 @Override |
| 83 public Rect getAperture() { | 88 public NinePatchData getNinePatchData() { |
| 84 computeContentAperture(mContentAperture); | 89 return null; |
| 85 | |
| 86 return mContentAperture; | |
| 87 } | 90 } |
| 88 | 91 |
| 89 @Override | 92 @Override |
| 90 public boolean isDirty() { | 93 public boolean isDirty() { |
| 91 if (mBitmap == null) mDirtyRect.set(0, 0, mView.getWidth(), mView.getHei
ght()); | 94 if (mBitmap == null) mDirtyRect.set(0, 0, mView.getWidth(), mView.getHei
ght()); |
| 92 | 95 |
| 93 return !mDirtyRect.isEmpty(); | 96 return !mDirtyRect.isEmpty(); |
| 94 } | 97 } |
| 95 | 98 |
| 96 @Override | 99 @Override |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if (mBitmap == null) { | 185 if (mBitmap == null) { |
| 183 mBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.A
RGB_8888); | 186 mBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.A
RGB_8888); |
| 184 mBitmap.setHasAlpha(true); | 187 mBitmap.setHasAlpha(true); |
| 185 mDirtyRect.set(0, 0, viewWidth, viewHeight); | 188 mDirtyRect.set(0, 0, viewWidth, viewHeight); |
| 186 mBitmapSize.set(0, 0, mBitmap.getWidth(), mBitmap.getHeight()); | 189 mBitmapSize.set(0, 0, mBitmap.getWidth(), mBitmap.getHeight()); |
| 187 } | 190 } |
| 188 | 191 |
| 189 return !isEmpty; | 192 return !isEmpty; |
| 190 } | 193 } |
| 191 } | 194 } |
| OLD | NEW |