OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.widget; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.graphics.Rect; |
| 9 import android.util.AttributeSet; |
| 10 import android.view.View; |
| 11 import android.view.ViewParent; |
| 12 import android.widget.FrameLayout; |
| 13 |
| 14 import org.chromium.ui.resources.dynamics.ViewResourceAdapter; |
| 15 |
| 16 /** |
| 17 * Extension to FrameLayout that handles tracking the necessary invalidates to g
enerate |
| 18 * a corresponding {@link org.chromium.ui.resources.Resource} for use in the bro
wser compositor. |
| 19 */ |
| 20 public class ViewResourceFrameLayout extends FrameLayout { |
| 21 private ViewResourceAdapter mResourceAdapter; |
| 22 |
| 23 /** |
| 24 * Constructs a ViewResourceFrameLayout. |
| 25 * <p> |
| 26 * This constructor is used when inflating from XML. |
| 27 * |
| 28 * @param context The context used to build this view. |
| 29 * @param attrs The attributes used to determine how to construct this view. |
| 30 */ |
| 31 public ViewResourceFrameLayout(Context context, AttributeSet attrs) { |
| 32 super(context, attrs); |
| 33 } |
| 34 |
| 35 @Override |
| 36 protected void onFinishInflate() { |
| 37 super.onFinishInflate(); |
| 38 |
| 39 mResourceAdapter = createResourceAdapter(); |
| 40 } |
| 41 |
| 42 /** |
| 43 * @return A {@link ViewResourceAdapter} instance. This can be overridden f
or custom behavior. |
| 44 */ |
| 45 protected ViewResourceAdapter createResourceAdapter() { |
| 46 return new ViewResourceAdapter(this); |
| 47 } |
| 48 |
| 49 /** |
| 50 * @return The {@link ViewResourceAdapter} that exposes this {@link View} as
a CC resource. |
| 51 */ |
| 52 public ViewResourceAdapter getResourceAdapter() { |
| 53 return mResourceAdapter; |
| 54 } |
| 55 |
| 56 /** |
| 57 * @return Whether the control container is ready for capturing snapshots. |
| 58 */ |
| 59 protected boolean isReadyForCapture() { |
| 60 return true; |
| 61 } |
| 62 |
| 63 @Override |
| 64 public ViewParent invalidateChildInParent(int[] location, Rect dirty) { |
| 65 ViewParent retVal = super.invalidateChildInParent(location, dirty); |
| 66 if (isReadyForCapture()) mResourceAdapter.invalidate(dirty); |
| 67 return retVal; |
| 68 } |
| 69 } |
OLD | NEW |