Skip to content

Commit

Permalink
[TLDD] Added placeholder strategy for drag drop reorder
Browse files Browse the repository at this point in the history
Bug: 381285152
Change-Id: I6b7aa2645ebf4b7cfaed8d3d44afd3d317d58bf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6064021
Commit-Queue: Sirisha Kavuluru <[email protected]>
Code-Coverage: [email protected] <[email protected]>
Reviewed-by: Neil Coronado <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1391249}
  • Loading branch information
Sirisha Kavuluru authored and pull[bot] committed Dec 6, 2024
1 parent 3e1fb16 commit ade1cef
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public class ReorderDelegate {
private StripLayoutTab mInteractingTab;

private ReorderStrategy mActiveStrategy;
private final ReorderTabStrategy mTabStrategy = new ReorderTabStrategy();
private final ReorderGroupStrategy mGroupStrategy = new ReorderGroupStrategy();
private final TabReorderStrategy mTabStrategy = new TabReorderStrategy();
private final GroupReorderStrategy mGroupStrategy = new GroupReorderStrategy();
private final DragDropReorderStrategy mDragDropStrategy = new DragDropReorderStrategy();

// Auto-scroll State.
private long mLastReorderScrollTime;
Expand Down Expand Up @@ -125,6 +126,19 @@ void setInteractingTab(StripLayoutTab interactingTab) {
mInteractingTab = interactingTab;
}

private ReorderStrategy getReorderStrategy(
StripLayoutView interactingView, boolean isReorderForDrop) {
if (isReorderForDrop) {
return mDragDropStrategy;
} else if (interactingView instanceof StripLayoutTab) {
return mTabStrategy;
} else if (interactingView instanceof StripLayoutGroupTitle) {
return mGroupStrategy;
}
assert false : "Attempted to start reorder on an unexpected view type: " + interactingView;
return null;
}

// ============================================================================================
// Initialization
// ============================================================================================
Expand Down Expand Up @@ -160,28 +174,16 @@ void initialize(
// Reorder API
// ============================================================================================

/**
* Begin reordering the interacting view.
*
* @param stripTabs The list of {@link StripLayoutTab}.
* @param interactingView The interacting {@link StripLayoutView}.
* @param effectiveTabWidth The width of a tab, accounting for overlap.
* @param x The x coordinate that the reorder action began at.
*/
void startReorder(
/** See {@link ReorderStrategy#startReorderMode} */
void startReorderMode(
StripLayoutTab[] stripTabs,
@NonNull StripLayoutView interactingView,
float effectiveTabWidth,
float x) {
if (interactingView instanceof StripLayoutTab interactingTab) {
mTabStrategy.startReorderTab(stripTabs, interactingTab, effectiveTabWidth, x);
mActiveStrategy = mTabStrategy;
} else if (interactingView instanceof StripLayoutGroupTitle) {
mGroupStrategy.startReorderGroup();
mActiveStrategy = mGroupStrategy;
} else {
assert false : "Attempted to start reorder on an unexpected view type.";
}
assert mActiveStrategy == null && !getInReorderMode();
// TODO(crbug.com/381285152): Pass isReorderForDrop as arg.
mActiveStrategy = getReorderStrategy(interactingView, /* isReorderForDrop= */ false);
mActiveStrategy.startReorderMode(stripTabs, interactingView, effectiveTabWidth, x);
}

/** See {@link ReorderStrategy#updateReorderPosition} */
Expand All @@ -190,13 +192,15 @@ void updateReorderPosition(
StripLayoutGroupTitle[] groupTitles,
StripLayoutTab[] stripTabs,
float deltaX) {
assert mActiveStrategy != null : "Attempted to update reorder without an active Strategy.";
assert mActiveStrategy != null && getInReorderMode()
: "Attempted to update reorder without an active Strategy.";
mActiveStrategy.updateReorderPosition(stripViews, groupTitles, stripTabs, deltaX);
}

/** See {@link ReorderStrategy#stopReorderMode} */
void stopReorderMode(StripLayoutGroupTitle[] groupTitles, StripLayoutTab[] stripTabs) {
assert mActiveStrategy != null : "Attempted to stop reorder without an active Strategy.";
assert mActiveStrategy != null && getInReorderMode()
: "Attempted to stop reorder without an active Strategy.";
mActiveStrategy.stopReorderMode(groupTitles, stripTabs);
mActiveStrategy = null;
}
Expand Down Expand Up @@ -341,22 +345,17 @@ private void resetTabGroupMargins(
// Tab reorder helpers
// ============================================================================================

private class ReorderTabStrategy implements ReorderStrategy {
/**
* Begin reordering the interacting tab.
*
* @param stripTabs The list of {@link StripLayoutTab}.
* @param interactingTab The interacting {@link StripLayoutTab}.
* @param effectiveTabWidth The width of a tab, accounting for overlap.
* @param x The x coordinate that the reorder action began at.
*/
void startReorderTab(
private class TabReorderStrategy implements ReorderStrategy {

/** See {@link ReorderStrategy#startReorderMode} */
@Override
public void startReorderMode(
StripLayoutTab[] stripTabs,
StripLayoutTab interactingTab,
StripLayoutView interactingTab,
float effectiveTabWidth,
float x) {
RecordUserAction.record("MobileToolbarStartReorderTab");
setInteractingTab(interactingTab);
setInteractingTab((StripLayoutTab) interactingTab);

// 1. Set reorder mode to true before selecting this tab to prevent unnecessarily
// triggering #bringSelectedTabToVisibleArea for edge tabs when the tab strip is full.
Expand Down Expand Up @@ -711,8 +710,13 @@ private float getHalfTabWidth() {
// Group reorder helpers
// ============================================================================================

private static class ReorderGroupStrategy implements ReorderStrategy {
void startReorderGroup() {
private static class GroupReorderStrategy implements ReorderStrategy {
@Override
public void startReorderMode(
StripLayoutTab[] stripTabs,
@NonNull StripLayoutView interactingView,
float effectiveTabWidth,
float x) {
// TODO(crbug.com/376069497): Implement.
}

Expand Down Expand Up @@ -743,6 +747,33 @@ void onReorderingForTabDrop() {
mActiveStrategy = mTabStrategy;
}

private static class DragDropReorderStrategy implements ReorderStrategy {

@Override
public void startReorderMode(
StripLayoutTab[] stripTabs,
@NonNull StripLayoutView interactingView,
float effectiveTabWidth,
float x) {
// TODO(crbug.com/381285152): Implement.
}

@Override
public void updateReorderPosition(
StripLayoutView[] stripViews,
StripLayoutGroupTitle[] groupTitles,
StripLayoutTab[] stripTabs,
float deltaX) {
// TODO(crbug.com/381285152): Implement.
}

@Override
public void stopReorderMode(
StripLayoutGroupTitle[] groupTitles, StripLayoutTab[] stripTabs) {
// TODO(crbug.com/381285152): Implement.
}
}

// ============================================================================================
// Animation helpers
// ============================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@

package org.chromium.chrome.browser.compositor.overlays.strip;

import androidx.annotation.NonNull;

interface ReorderStrategy {
/**
* Begin reordering the interacting view.
*
* @param stripTabs The list of {@link StripLayoutTab}.
* @param interactingView The interacting {@link StripLayoutView}.
* @param effectiveTabWidth The width of a tab, accounting for overlap.
* @param x The x coordinate that the reorder action began at.
*/
void startReorderMode(
StripLayoutTab[] stripTabs,
@NonNull StripLayoutView interactingView,
float effectiveTabWidth,
float x);

/**
* Updates the location of the reordering tab. This 1. visually offsets the tab (clamped to the
* bounds of the strip) and 2. triggers a reorder (with animations) if the threshold is reached.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3817,7 +3817,7 @@ private void startReorderMode(float x, StripLayoutView interactingView) {
return;
}

mReorderDelegate.startReorder(mStripTabs, interactingView, getEffectiveTabWidth(), x);
mReorderDelegate.startReorderMode(mStripTabs, interactingView, getEffectiveTabWidth(), x);
}

void updateStripForExternalTabDrop(float startX) {
Expand Down

0 comments on commit ade1cef

Please sign in to comment.