| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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.chrome.browser.util; | 5 package org.chromium.chrome.browser.util; |
| 6 | 6 |
| 7 import android.graphics.Canvas; | 7 import android.graphics.Canvas; |
| 8 import android.graphics.Region; |
| 8 import android.view.View; | 9 import android.view.View; |
| 9 import android.view.ViewGroup; | 10 import android.view.ViewGroup; |
| 10 | 11 |
| 11 /** | 12 /** |
| 12 * View-related utility methods. | 13 * View-related utility methods. |
| 13 */ | 14 */ |
| 14 public class ViewUtils { | 15 public class ViewUtils { |
| 16 private static final int[] sLocationTmp = new int[2]; |
| 17 |
| 15 /** | 18 /** |
| 16 * Invalidates a view and all of its descendants. | 19 * Invalidates a view and all of its descendants. |
| 17 */ | 20 */ |
| 18 private static void recursiveInvalidate(View view) { | 21 private static void recursiveInvalidate(View view) { |
| 19 view.invalidate(); | 22 view.invalidate(); |
| 20 if (view instanceof ViewGroup) { | 23 if (view instanceof ViewGroup) { |
| 21 ViewGroup group = (ViewGroup) view; | 24 ViewGroup group = (ViewGroup) view; |
| 22 int childCount = group.getChildCount(); | 25 int childCount = group.getChildCount(); |
| 23 for (int i = 0; i < childCount; i++) { | 26 for (int i = 0; i < childCount; i++) { |
| 24 View child = group.getChildAt(i); | 27 View child = group.getChildAt(i); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 public static void getRelativeDrawPosition(View rootView, View childView, in
t[] outPosition) { | 72 public static void getRelativeDrawPosition(View rootView, View childView, in
t[] outPosition) { |
| 70 assert outPosition.length == 2; | 73 assert outPosition.length == 2; |
| 71 outPosition[0] = 0; | 74 outPosition[0] = 0; |
| 72 outPosition[1] = 0; | 75 outPosition[1] = 0; |
| 73 while (childView != null && childView != rootView) { | 76 while (childView != null && childView != rootView) { |
| 74 outPosition[0] += childView.getX(); | 77 outPosition[0] += childView.getX(); |
| 75 outPosition[1] += childView.getY(); | 78 outPosition[1] += childView.getY(); |
| 76 childView = (View) childView.getParent(); | 79 childView = (View) childView.getParent(); |
| 77 } | 80 } |
| 78 } | 81 } |
| 82 |
| 83 /** |
| 84 * Helper for overriding {@link View#gatherTransparentRegions()} for views t
hat are fully opaque |
| 85 * and have children extending beyond their bounds. If the transparent regio
n optimization is |
| 86 * turned on (which is the case whenever the view hierarchy contains a Surfa
ceView somewhere), |
| 87 * the children might otherwise confuse the SurfaceFlinger. |
| 88 */ |
| 89 public static void gatherTransparentRegionsForOpaqueView(View view, Region r
egion) { |
| 90 view.getLocationInWindow(sLocationTmp); |
| 91 region.op(sLocationTmp[0], sLocationTmp[1], |
| 92 sLocationTmp[0] + view.getRight() - view.getLeft(), |
| 93 sLocationTmp[1] + view.getBottom() - view.getTop(), Region.Op.DI
FFERENCE); |
| 94 } |
| 79 } | 95 } |
| OLD | NEW |