Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(589)

Unified Diff: ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceInflater.java

Issue 1823203002: [Contextual Search] Fixing ViewResourceInflater layout invalidation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelInflater.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceInflater.java
diff --git a/ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceInflater.java b/ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceInflater.java
index 38888dd17f86d6ad7edfffb3ef59670a0daf5bfa..c0414d3d2b737ba50fea0ebabdfb97dc36062d19 100644
--- a/ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceInflater.java
+++ b/ui/android/java/src/org/chromium/ui/resources/dynamics/ViewResourceInflater.java
@@ -120,38 +120,20 @@ public class ViewResourceInflater {
// Allow subclasses to access/modify the View before it's attached
// to the hierarchy (if allowed) or snapshots are captured.
onFinishInflate();
-
- registerResource();
}
/**
* Invalidate the inflated View, causing a snapshot of the View to be captured.
*/
public void invalidate() {
- // View must be inflated at this point. If it's not, do it now.
- if (mView == null) {
- inflate();
- }
-
- mIsInvalidated = true;
+ invalidate(false);
+ }
- // If the View is already attached, we don't need to do anything because the
- // snapshot will be captured automatically when the View is drawn.
- if (!mIsAttached) {
- if (shouldAttachView()) {
- // TODO(pedrosimonetti): investigate if complex views can be rendered offline.
- // NOTE(pedrosimonetti): it seems that complex views don't get rendered
- // properly if not attached to the hierarchy. The problem seem to be related
- // to the use of the property "layout_gravity: end", possibly in combination
- // of other things like elastic views (layout_weight: 1) and/or fading edges.
- attachView();
- } else {
- // When the View is not attached, we need to manually layout the View
- // and invalidate the resource in order to capture a new snapshot.
- layout();
- invalidateResource();
- }
- }
+ /**
+ * Request a layout update, causing the {@link ViewResourceInflater} to be invalidated.
+ */
+ public void requestLayout() {
+ invalidate(true);
}
/**
@@ -282,13 +264,68 @@ public class ViewResourceInflater {
}
}
+ private void invalidate(boolean requestLayout) {
+ // View must be inflated at this point. If it's not, do it now.
+ if (mView == null) {
+ inflate();
+ }
+
+ // Layout the View if necessary, updating its size.
+ if (requestLayout) {
+ layout(true);
+ }
+
+ // Register the resource, if not registered yet.
+ if (mResourceAdapter == null) {
+ registerResource();
+ }
+
+ mIsInvalidated = true;
+
+ if (!mIsAttached && shouldAttachView()) {
+ // TODO(pedrosimonetti): investigate if complex views can be rendered offline.
+ // NOTE(pedrosimonetti): it seems that complex views don't get rendered
+ // properly if not attached to the hierarchy. The problem seem to be related
+ // to the use of the property "layout_gravity: end", possibly in combination
+ // of other things like elastic views (layout_weight: 1) and/or fading edges.
+ attachView();
+ }
+
+ if (!mIsAttached) {
+ // When the View is not attached, we need to manually layout the View and
+ // invalidate the resource in order to capture a new snapshot.
+ layout(false);
+ invalidateResource();
+ }
+ }
+
/**
- * Layout the View. This is to be used when the View is not attached to the hierarchy.
+ * Lays out the view according to the current width and height measure specs.
*/
- private void layout() {
+ private void layout(boolean updateLayoutParams) {
// View must be inflated at this point.
assert mView != null;
+ // Update LayoutParams according to the current measure spec.
+ if (updateLayoutParams) {
+ final int widthMeasureSpec = getWidthMeasureSpec();
+ int width = ViewGroup.LayoutParams.WRAP_CONTENT;
+ if (View.MeasureSpec.getMode(widthMeasureSpec) == View.MeasureSpec.EXACTLY) {
+ width = View.MeasureSpec.getSize(widthMeasureSpec);
+ }
+
+ final int heightMeasureSpec = getHeightMeasureSpec();
+ int height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ if (View.MeasureSpec.getMode(heightMeasureSpec) == View.MeasureSpec.EXACTLY) {
+ height = View.MeasureSpec.getSize(heightMeasureSpec);
+ }
+
+ ViewGroup.LayoutParams params = mView.getLayoutParams();
+ params.width = width;
+ params.height = height;
+ mView.setLayoutParams(params);
+ }
+
mView.measure(getWidthMeasureSpec(), getHeightMeasureSpec());
newt (away) 2016/03/24 22:31:36 If you're going to attach this view to the view hi
pedro (no code reviews) 2016/03/25 00:37:47 Made changes based on our offline discussion.
mView.layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/OverlayPanelInflater.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698