Commit 03dd0691 authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Scroll TabGridDialog when open to show selected Tab

Bug: 999444
Change-Id: I753ea4f5865cb676cd8b34bcd2abc71cc52645c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1783061Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693194}
parent 615a0e5d
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.tasks.tab_management;
import static org.chromium.chrome.browser.tasks.tab_management.TabSwitcherMediator.INITIAL_SCROLL_INDEX_OFFSET;
import android.content.Context;
import android.content.res.ColorStateList;
import android.support.annotation.Nullable;
......@@ -206,6 +208,7 @@ public class TabGridDialogMediator {
mModel.set(TabGridSheetProperties.ANIMATION_PARAMS, params);
}
updateDialog();
updateDialogScrollPosition();
mModel.set(TabGridSheetProperties.IS_DIALOG_VISIBLE, true);
} else {
mModel.set(TabGridSheetProperties.IS_DIALOG_VISIBLE, false);
......@@ -247,6 +250,19 @@ public class TabGridDialogMediator {
R.plurals.bottom_tab_grid_title_placeholder, tabsCount, tabsCount));
}
private void updateDialogScrollPosition() {
// If current selected tab is not within this dialog, always scroll to the top.
if (mCurrentTabId != mTabModelSelector.getCurrentTabId()) {
mModel.set(TabGridSheetProperties.INITIAL_SCROLL_INDEX, 0);
return;
}
List<Tab> relatedTabs = getRelatedTabs(mCurrentTabId);
Tab currentTab = mTabModelSelector.getTabById(mCurrentTabId);
int initialPosition =
Math.max(relatedTabs.indexOf(currentTab) - INITIAL_SCROLL_INDEX_OFFSET, 0);
mModel.set(TabGridSheetProperties.INITIAL_SCROLL_INDEX, initialPosition);
}
private void setupToolbarClickHandlers() {
mModel.set(
TabGridSheetProperties.COLLAPSE_CLICK_LISTENER, getCollapseButtonClickListener());
......
......@@ -46,9 +46,16 @@ class TabGridSheetProperties {
new PropertyModel.WritableIntPropertyKey();
public static final PropertyModel.WritableIntPropertyKey DIALOG_UNGROUP_BAR_TEXT_APPEARANCE =
new PropertyModel.WritableIntPropertyKey();
/**
* Integer, but not {@link PropertyModel.WritableIntPropertyKey} so that we can force update on
* the same value.
*/
public static final PropertyModel.WritableObjectPropertyKey INITIAL_SCROLL_INDEX =
new PropertyModel.WritableObjectPropertyKey(true);
public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {COLLAPSE_CLICK_LISTENER,
ADD_CLICK_LISTENER, HEADER_TITLE, CONTENT_TOP_MARGIN, PRIMARY_COLOR, TINT,
IS_DIALOG_VISIBLE, SCRIMVIEW_OBSERVER, ANIMATION_PARAMS, UNGROUP_BAR_STATUS,
DIALOG_BACKGROUND_RESOUCE_ID, DIALOG_UNGROUP_BAR_BACKGROUND_COLOR_ID,
DIALOG_UNGROUP_BAR_HOVERED_BACKGROUND_COLOR_ID, DIALOG_UNGROUP_BAR_TEXT_APPEARANCE};
DIALOG_UNGROUP_BAR_HOVERED_BACKGROUND_COLOR_ID, DIALOG_UNGROUP_BAR_TEXT_APPEARANCE,
INITIAL_SCROLL_INDEX};
}
......@@ -5,9 +5,9 @@
package org.chromium.chrome.browser.tasks.tab_management;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.tab_ui.R;
......@@ -32,11 +32,11 @@ class TabGridSheetToolbarCoordinator implements Destroyable {
* the toolbar.
*/
TabGridSheetToolbarCoordinator(
Context context, ViewGroup contentView, PropertyModel toolbarPropertyModel) {
Context context, RecyclerView contentView, PropertyModel toolbarPropertyModel) {
this(context, contentView, toolbarPropertyModel, null);
}
TabGridSheetToolbarCoordinator(Context context, ViewGroup contentView,
TabGridSheetToolbarCoordinator(Context context, RecyclerView contentView,
PropertyModel toolbarPropertyModel, TabGridDialogParent dialog) {
mToolbarView = (TabGroupUiToolbarView) LayoutInflater.from(context).inflate(
R.layout.bottom_tab_grid_toolbar, contentView, false);
......
......@@ -13,6 +13,7 @@ import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetPrope
import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetProperties.DIALOG_UNGROUP_BAR_HOVERED_BACKGROUND_COLOR_ID;
import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetProperties.DIALOG_UNGROUP_BAR_TEXT_APPEARANCE;
import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetProperties.HEADER_TITLE;
import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetProperties.INITIAL_SCROLL_INDEX;
import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetProperties.IS_DIALOG_VISIBLE;
import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetProperties.PRIMARY_COLOR;
import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetProperties.SCRIMVIEW_OBSERVER;
......@@ -20,6 +21,8 @@ import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetPrope
import static org.chromium.chrome.browser.tasks.tab_management.TabGridSheetProperties.UNGROUP_BAR_STATUS;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.FrameLayout;
......@@ -35,11 +38,11 @@ class TabGridSheetViewBinder {
*/
public static class ViewHolder {
public final TabGroupUiToolbarView toolbarView;
public final View contentView;
public final RecyclerView contentView;
@Nullable
public TabGridDialogParent dialogView;
ViewHolder(TabGroupUiToolbarView toolbarView, View contentView,
ViewHolder(TabGroupUiToolbarView toolbarView, RecyclerView contentView,
@Nullable TabGridDialogParent dialogView) {
this.toolbarView = toolbarView;
this.contentView = contentView;
......@@ -103,6 +106,10 @@ class TabGridSheetViewBinder {
viewHolder.dialogView.updateUngroupBarTextAppearance(
model.get(DIALOG_UNGROUP_BAR_TEXT_APPEARANCE));
}
} else if (INITIAL_SCROLL_INDEX == propertyKey) {
int index = (Integer) model.get(INITIAL_SCROLL_INDEX);
((LinearLayoutManager) viewHolder.contentView.getLayoutManager())
.scrollToPositionWithOffset(index, 0);
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment