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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarViewResourceAdapter.java

Issue 1221333007: Get rid of ToolbarViewResourceFrameLayout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Start sending ToolbarLayout itself as container Created 5 years, 5 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
Index: chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarViewResourceAdapter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarViewResourceAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarViewResourceAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..ec77f1d2259a987138fa54d0ef01232dfa6fd0fb
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarViewResourceAdapter.java
@@ -0,0 +1,84 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.toolbar;
+
+import android.graphics.Canvas;
+import android.graphics.PorterDuff;
+import android.graphics.Rect;
+import android.view.View;
+
+import org.chromium.chrome.R;
+import org.chromium.ui.resources.dynamics.ViewResourceAdapter;
+
+/**
+ * A {@link ViewResourceAdapter} specified for {@link ToolbarLayout}.
+ */
+public class ToolbarViewResourceAdapter extends ViewResourceAdapter {
+ private final int mToolbarActualHeightPx;
+ private final int[] mTempPosition = new int[2];
+
+ private final View mToolbarContainer;
+ private final Toolbar mToolbar;
+
+ /** Builds the resource adapter for the toolbar. */
+ public ToolbarViewResourceAdapter(View toolbarContainer, Toolbar toolbar) {
+ super(toolbarContainer);
+
+ mToolbarContainer = toolbarContainer;
+ mToolbar = toolbar;
+ mToolbarActualHeightPx = toolbarContainer.getResources().getDimensionPixelSize(
+ R.dimen.control_container_height);
+ }
+
+ /**
+ * Force this resource to be recaptured in full, ignoring the checks
+ * {@link #invalidate(Rect)} does.
+ */
+ public void forceInvalidate() {
+ super.invalidate(null);
+ }
+
+ @Override
+ public boolean isDirty() {
+ return mToolbar != null && mToolbar.isReadyForTextureCapture() && super.isDirty();
+ }
+
+ @Override
+ protected void onCaptureStart(Canvas canvas, Rect dirtyRect) {
+ // Erase the shadow component of the bitmap if the clip rect included shadow. Because
+ // this region is not opaque painting twice would be bad.
+ if (dirtyRect.intersects(
+ 0, mToolbarActualHeightPx,
+ mToolbarContainer.getWidth(), mToolbarContainer.getHeight())) {
+ canvas.save();
+ canvas.clipRect(
+ 0, mToolbarActualHeightPx,
+ mToolbarContainer.getWidth(), mToolbarContainer.getHeight());
+ canvas.drawColor(0, PorterDuff.Mode.CLEAR);
+ canvas.restore();
+ }
+
+ mToolbar.setTextureCaptureMode(true);
+
+ super.onCaptureStart(canvas, dirtyRect);
+ }
+
+ @Override
+ protected void onCaptureEnd() {
+ mToolbar.setTextureCaptureMode(false);
+ }
+
+ @Override
+ protected void computeContentPadding(Rect outContentPadding) {
+ outContentPadding.set(0, 0, mToolbarContainer.getWidth(), mToolbarActualHeightPx);
+ }
+
+ @Override
+ protected void computeContentAperture(Rect outContentAperture) {
+ mToolbar.getLocationBarContentRect(outContentAperture);
+ mToolbar.getPositionRelativeToContainer(mToolbarContainer, mTempPosition);
+ outContentAperture.offset(mTempPosition[0], mTempPosition[1]);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698