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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewAndroidDelegate.java

Issue 2103243002: Factor out ContentViewAndroidDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 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: content/public/android/java/src/org/chromium/content/browser/ContentViewAndroidDelegate.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewAndroidDelegate.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewAndroidDelegate.java
new file mode 100644
index 0000000000000000000000000000000000000000..77d788d5488f22e73e872f0b1120aff00d6f23d9
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewAndroidDelegate.java
@@ -0,0 +1,72 @@
+// Copyright 2016 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.content.browser;
+
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.FrameLayout.LayoutParams;
+
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.ui.base.ViewAndroidDelegate;
no sievers 2016/07/14 23:14:31 Actually there are no more content dependencies no
Jinsuk Kim 2016/07/15 05:46:26 Sounds better. Made it an inner class of AndroidVi
no sievers 2016/07/15 18:35:00 Sorry there was a typo. I meant to say just put it
Jinsuk Kim 2016/07/18 06:45:46 Should have seen that :) Done.
+
+/**
+ * A {@link ViewAndroidDelegate} that delegates to the current container view.
+ *
+ * <p>This delegate handles the replacement of container views transparently so
+ * that clients can safely hold to instances of this class.
+ */
+public class ContentViewAndroidDelegate implements ViewAndroidDelegate {
+ private static final String TAG = "cr.ContentViewAndroidDelegate";
+
+ private final ViewGroup mContainerView;
+
+ public ContentViewAndroidDelegate(ViewGroup containerView) {
+ mContainerView = containerView;
+ }
+
+ @Override
+ public void addView(View anchorView) {
+ mContainerView.addView(anchorView);
+ }
+
+ @Override
+ public void setViewPosition(View view, float x, float y,
+ float width, float height, float scale, int leftMargin, int topMargin) {
+ if (view.getParent() == null) {
+ // Ignore. setAnchorViewPosition has been called after the anchor view has
+ // already been released.
+ return;
+ }
+ ViewGroup containerView = getContainerView();
+ assert view.getParent() == containerView;
+
+ int scaledWidth = Math.round(width * scale);
+ int scaledHeight = Math.round(height * scale);
+ int startMargin;
+ if (ApiCompatibilityUtils.isLayoutRtl(containerView)) {
+ startMargin = containerView.getMeasuredWidth() - Math.round((width + x) * scale);
+ } else {
+ startMargin = leftMargin;
+ }
+ if (scaledWidth + startMargin > containerView.getWidth()) {
+ scaledWidth = containerView.getWidth() - startMargin;
+ }
+ LayoutParams lp = new LayoutParams(scaledWidth, scaledHeight);
+ ApiCompatibilityUtils.setMarginStart(lp, startMargin);
+ lp.topMargin = topMargin;
+ view.setLayoutParams(lp);
+ }
+
+ // Can be overriden by the inherited class to return its own container view in case
+ // it allows dynamic container view switching.
+ protected ViewGroup getContainerView() {
+ return mContainerView;
+ }
+
+ @Override
+ public void removeView(View anchorView) {
+ mContainerView.removeView(anchorView);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698