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

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

Issue 2595263002: Introduce ViewRoot forwarding input/view events to native (Closed)
Patch Set: unittest Created 3 years, 11 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/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 7f233424c2afc89b6c132a8976506f041b36f0e8..ef95711700279df7ae7242f66b1366258016b6c4 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
@@ -106,6 +106,7 @@ import org.chromium.printing.PrintingControllerImpl;
import org.chromium.ui.base.LocalizationUtils;
import org.chromium.ui.base.PageTransition;
import org.chromium.ui.base.ViewAndroidDelegate;
+import org.chromium.ui.base.ViewRoot;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.mojom.WindowOpenDisposition;
@@ -165,6 +166,9 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
/** Gives {@link Tab} a way to interact with the Android window. */
private WindowAndroid mWindowAndroid;
+ /** {@link ViewRoot} used to forward input/view events down to native. */
+ private ViewRoot mViewRoot;
+
/** Whether or not this {@link Tab} is initialized and should be interacted with. */
private boolean mIsInitialized;
@@ -523,8 +527,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
* @param incognito Whether or not this tab is incognito.
* @param window An instance of a {@link WindowAndroid}.
*/
- public Tab(int id, boolean incognito, WindowAndroid window) {
- this(id, INVALID_TAB_ID, incognito, null, window, null, null, null);
+ public Tab(int id, boolean incognito, ViewRoot viewRoot) {
+ this(id, INVALID_TAB_ID, incognito, null, viewRoot, null, null, null);
}
/**
@@ -544,14 +548,15 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
*/
@SuppressLint("HandlerLeak")
public Tab(int id, int parentId, boolean incognito, Context context,
- WindowAndroid window, TabLaunchType type, TabCreationState creationState,
+ ViewRoot viewRoot, TabLaunchType type, TabCreationState creationState,
TabState frozenState) {
mId = TabIdManager.getInstance().generateValidId(id);
mParentId = parentId;
mIncognito = incognito;
mThemedApplicationContext = context != null ? new ContextThemeWrapper(
context.getApplicationContext(), ChromeActivity.getThemeId()) : null;
- mWindowAndroid = window;
+ mViewRoot = viewRoot;
+ mWindowAndroid = viewRoot != null ? viewRoot.getWindowAndroid() : null;
mLaunchType = type;
if (mThemedApplicationContext != null) {
Resources resources = mThemedApplicationContext.getResources();
@@ -1448,7 +1453,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
// TODO(yusufo): We can't call updateWindowAndroid here and set mWindowAndroid to null
// because many code paths (including navigation) expect the tab to always be associated
// with an activity, and will crash. crbug.com/657007
- if (mContentViewCore != null) mContentViewCore.updateWindowAndroid(null);
+ if (mContentViewCore != null) mContentViewCore.updateViewRoot(null);
attachTabContentManager(null);
}
@@ -1470,7 +1475,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
// TODO(yusufo): Share these calls with the construction related calls.
// crbug.com/590281
- updateWindowAndroid(activity.getWindowAndroid());
+ updateViewRoot(activity.getViewRoot());
// Update for the controllers that need the Compositor from the new Activity.
attachTabContentManager(activity.getTabContentManager());
@@ -1502,14 +1507,15 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
}
/**
- * Update and propagate the new WindowAndroid.
- * @param windowAndroid The WindowAndroid to propagate.
+ * Update and propagate the new ViewRoot and its WindowAndroid
+ * @param viewRoot New ViewRoot to update.
*/
- public void updateWindowAndroid(WindowAndroid windowAndroid) {
+ public void updateViewRoot(ViewRoot viewRoot) {
+ assert viewRoot != null;
+ mViewRoot = viewRoot;
+ mWindowAndroid = viewRoot.getWindowAndroid();
// TODO(yusufo): mWindowAndroid can never be null until crbug.com/657007 is fixed.
- assert windowAndroid != null;
- mWindowAndroid = windowAndroid;
- if (mContentViewCore != null) mContentViewCore.updateWindowAndroid(mWindowAndroid);
+ if (mContentViewCore != null) mContentViewCore.updateViewRoot(viewRoot);
}
/**
@@ -1548,6 +1554,13 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
}
/**
+ * @return {@link ViewRoot} instance used to forward view/input events.
+ */
+ public ViewRoot getViewRoot() {
+ return mViewRoot;
+ }
+
+ /**
* Called when a navigation begins and no navigation was in progress
* @param toDifferentDocument Whether this navigation will transition between
* documents (i.e., not a fragment navigation or JS History API call).
@@ -1642,8 +1655,7 @@ 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());
+ cvc.initialize(ViewAndroidDelegate.createBasicDelegate(cv), cv, webContents, mViewRoot);
ChromeActionModeCallback actionModeCallback = new ChromeActionModeCallback(
mThemedApplicationContext, this, cvc.getActionModeCallbackHelper());
cvc.setActionModeCallback(actionModeCallback);
@@ -2898,9 +2910,9 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
*/
public static Tab createFrozenTabFromState(
int id, ChromeActivity activity, boolean incognito,
- WindowAndroid nativeWindow, int parentId, TabState state) {
+ ViewRoot viewRoot, int parentId, TabState state) {
assert state != null;
- return new Tab(id, parentId, incognito, activity, nativeWindow,
+ return new Tab(id, parentId, incognito, activity, viewRoot,
TabLaunchType.FROM_RESTORE, TabCreationState.FROZEN_ON_RESTORE, state);
}
@@ -2941,10 +2953,10 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
* complete the second level initialization.
*/
public static Tab createTabForLazyLoad(ChromeActivity activity, boolean incognito,
- WindowAndroid nativeWindow, TabLaunchType type, int parentId,
+ ViewRoot viewRoot, TabLaunchType type, int parentId,
LoadUrlParams loadUrlParams) {
Tab tab = new Tab(
- INVALID_TAB_ID, parentId, incognito, activity, nativeWindow, type,
+ INVALID_TAB_ID, parentId, incognito, activity, viewRoot, type,
TabCreationState.FROZEN_FOR_LAZY_LOAD, null);
tab.setPendingLoadParams(loadUrlParams);
return tab;
@@ -2956,8 +2968,8 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
* @param initiallyHidden true iff the tab being created is initially in background
*/
public static Tab createLiveTab(int id, ChromeActivity activity, boolean incognito,
- WindowAndroid nativeWindow, TabLaunchType type, int parentId, boolean initiallyHidden) {
- return new Tab(id, parentId, incognito, activity, nativeWindow, type, initiallyHidden
+ ViewRoot viewRoot, TabLaunchType type, int parentId, boolean initiallyHidden) {
+ return new Tab(id, parentId, incognito, activity, viewRoot, type, initiallyHidden
? TabCreationState.LIVE_IN_BACKGROUND
: TabCreationState.LIVE_IN_FOREGROUND, null);
}

Powered by Google App Engine
This is Rietveld 408576698