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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java

Issue 2536223003: Refactor ContentViewClient (3/6) (Closed)
Patch Set: removed getDesiredMeasureSpec Created 4 years 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/tab/Tab.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
index fac8ca7c579645b06b5cf89d3461077a8bb47539..1476f5b3a4a6abfc18095aa61b3c99684bec66f7 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
@@ -187,6 +187,9 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
/** {@link ContentViewCore} showing the current page, or {@code null} if the tab is frozen. */
private ContentViewCore mContentViewCore;
+ /** Delegate interface of the native view for this embedder. */
+ private ViewAndroidDelegate mViewDelegate;
+
/** Listens to gesture events fired by the ContentViewCore. */
private GestureStateListener mGestureStateListener;
@@ -375,26 +378,6 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
private class TabContentViewClient extends ContentViewClient {
@Override
- public void onBackgroundColorChanged(int color) {
- Tab.this.onBackgroundColorChanged(color);
- }
-
- @Override
- public void onTopControlsChanged(float topControlsOffsetY, float topContentOffsetY) {
- super.onTopControlsChanged(topControlsOffsetY, topContentOffsetY);
- onOffsetsChanged(topControlsOffsetY, mPreviousBottomControlsOffsetY,
- topContentOffsetY, isShowingSadTab());
- }
-
- @Override
- public void onBottomControlsChanged(float bottomControlsOffsetY,
- float bottomContentOffsetY) {
- super.onBottomControlsChanged(bottomControlsOffsetY, bottomContentOffsetY);
- onOffsetsChanged(mPreviousTopControlsOffsetY, bottomControlsOffsetY,
- mPreviousContentOffsetY, isShowingSadTab());
- }
-
- @Override
public void onImeEvent() {
// Some text was set in the page. Don't reuse it if a tab is
// open from the same external application, we might lose some
@@ -407,42 +390,6 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
if (getFullscreenManager() == null) return;
updateFullscreenEnabledState();
}
-
- @Override
- public int getSystemWindowInsetLeft() {
- ChromeActivity activity = getActivity();
- if (activity != null && activity.getInsetObserverView() != null) {
- return activity.getInsetObserverView().getSystemWindowInsetsLeft();
- }
- return 0;
- }
-
- @Override
- public int getSystemWindowInsetTop() {
- ChromeActivity activity = getActivity();
- if (activity != null && activity.getInsetObserverView() != null) {
- return activity.getInsetObserverView().getSystemWindowInsetsTop();
- }
- return 0;
- }
-
- @Override
- public int getSystemWindowInsetRight() {
- ChromeActivity activity = getActivity();
- if (activity != null && activity.getInsetObserverView() != null) {
- return activity.getInsetObserverView().getSystemWindowInsetsRight();
- }
- return 0;
- }
-
- @Override
- public int getSystemWindowInsetBottom() {
- ChromeActivity activity = getActivity();
- if (activity != null && activity.getInsetObserverView() != null) {
- return activity.getInsetObserverView().getSystemWindowInsetsBottom();
- }
- return 0;
- }
}
private GestureStateListener createGestureStateListener() {
@@ -1130,6 +1077,14 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
}
/**
+ * @return The {@link ViewAndroidDelegate} associated with the current content, or
+ * {@code null} if there is no current page or the page is based on a native view.
+ */
+ public ViewAndroidDelegate getViewDelegate() {
+ return mViewDelegate;
+ }
+
+ /**
* @return The {@link NativePage} associated with the current page, or {@code null} if there is
* no current page or the current page is displayed using something besides
* {@link NativePage}.
@@ -1702,8 +1657,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
ContentView cv = ContentView.createContentView(mThemedApplicationContext, cvc);
cv.setContentDescription(mThemedApplicationContext.getResources().getString(
R.string.accessibility_content_view));
- cvc.initialize(ViewAndroidDelegate.createBasicDelegate(cv), cv, webContents,
- getWindowAndroid());
+ mViewDelegate = new TabViewAndroidDelegate(this, cv);
+ cvc.initialize(mViewDelegate, cv, webContents, getWindowAndroid());
ChromeActionModeCallback actionModeCallback = new ChromeActionModeCallback(
mThemedApplicationContext, this, cvc.getActionModeCallbackHelper());
cvc.setActionModeCallback(actionModeCallback);
@@ -2276,7 +2231,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
* Called when the background color for the content changes.
* @param color The current for the background.
*/
- protected void onBackgroundColorChanged(int color) {
+ void onBackgroundColorChanged(int color) {
for (TabObserver observer : mObservers) observer.onBackgroundColorChanged(this, color);
}
@@ -2304,6 +2259,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
mContentViewParent = null;
mContentViewCore.destroy();
mContentViewCore = null;
+ mViewDelegate = null;
mWebContentsDelegate = null;
@@ -2585,19 +2541,23 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
* Called when offset values related with fullscreen functionality has been changed by the
* compositor.
* @param topControlsOffsetY The Y offset of the top controls in physical pixels.
+ * {@code Float.NaN} if the value is invalid.
* @param bottomControlsOffsetY The Y offset of the bottom controls in physical pixels.
+ * {@code Float.NaN} if the value is invalid.
* @param contentOffsetY The Y offset of the content in physical pixels.
+ * {@code Float.NaN} if the value is invalid.
* @param isNonFullscreenPage Whether a current page is non-fullscreen page or not.
*/
- private void onOffsetsChanged(
- float topControlsOffsetY, float bottomControlsOffsetY, float contentOffsetY,
- boolean isNonFullscreenPage) {
- mPreviousTopControlsOffsetY = topControlsOffsetY;
- mPreviousBottomControlsOffsetY = bottomControlsOffsetY;
- mPreviousContentOffsetY = contentOffsetY;
+ void onOffsetsChanged(
+ float topControlsOffsetY, float bottomControlsOffsetY, float contentOffsetY) {
+ if (!Float.isNaN(topControlsOffsetY)) mPreviousTopControlsOffsetY = topControlsOffsetY;
+ if (!Float.isNaN(bottomControlsOffsetY)) {
+ mPreviousBottomControlsOffsetY = bottomControlsOffsetY;
+ }
+ if (!Float.isNaN(contentOffsetY)) mPreviousContentOffsetY = contentOffsetY;
if (mFullscreenManager == null) return;
- if (isNonFullscreenPage || isNativePage()) {
+ if (isShowingSadTab() || isNativePage()) {
mFullscreenManager.setPositionsForTabToNonFullscreen();
} else {
mFullscreenManager.setPositionsForTab(topControlsOffsetY, bottomControlsOffsetY,

Powered by Google App Engine
This is Rietveld 408576698