mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1048865 - Sync with upstream TwoWayView (r=mcomella)
This commit is contained in:
parent
4c951d170c
commit
373ef9ab3b
@ -947,7 +947,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
if (distance < minDistance) {
|
if (distance < minDistance) {
|
||||||
minDistance = distance;
|
minDistance = distance;
|
||||||
closetChildIndex = i;
|
closetChildIndex = i;
|
||||||
closestChildStart = (mIsVertical ? other.getTop() : other.getLeft());
|
closestChildStart = getChildStartEdge(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2086,7 +2086,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
|
|
||||||
final int selectedStart;
|
final int selectedStart;
|
||||||
if (selectedView != null) {
|
if (selectedView != null) {
|
||||||
selectedStart = (mIsVertical ? selectedView.getTop() : selectedView.getLeft());
|
selectedStart = getChildStartEdge(selectedView);
|
||||||
} else {
|
} else {
|
||||||
selectedStart = start;
|
selectedStart = start;
|
||||||
}
|
}
|
||||||
@ -2275,7 +2275,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
if (needToRedraw) {
|
if (needToRedraw) {
|
||||||
if (selectedView != null) {
|
if (selectedView != null) {
|
||||||
positionSelector(selectedPos, selectedView);
|
positionSelector(selectedPos, selectedView);
|
||||||
mSelectedStart = selectedView.getTop();
|
mSelectedStart = getChildStartEdge(selectedView);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!awakenScrollbarsInternal()) {
|
if (!awakenScrollbarsInternal()) {
|
||||||
@ -2733,15 +2733,14 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
int motionViewPrevStart = 0;
|
int motionViewPrevStart = 0;
|
||||||
View motionView = this.getChildAt(motionIndex);
|
View motionView = this.getChildAt(motionIndex);
|
||||||
if (motionView != null) {
|
if (motionView != null) {
|
||||||
motionViewPrevStart = (mIsVertical ? motionView.getTop() : motionView.getLeft());
|
motionViewPrevStart = getChildStartEdge(motionView);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean atEdge = scrollListItemsBy(delta);
|
boolean atEdge = scrollListItemsBy(delta);
|
||||||
|
|
||||||
motionView = this.getChildAt(motionIndex);
|
motionView = this.getChildAt(motionIndex);
|
||||||
if (motionView != null) {
|
if (motionView != null) {
|
||||||
final int motionViewRealStart =
|
final int motionViewRealStart = getChildStartEdge(motionView);
|
||||||
(mIsVertical ? motionView.getTop() : motionView.getLeft());
|
|
||||||
|
|
||||||
if (atEdge) {
|
if (atEdge) {
|
||||||
final int overscroll = -delta - (motionViewRealStart - motionViewPrevStart);
|
final int overscroll = -delta - (motionViewRealStart - motionViewPrevStart);
|
||||||
@ -3928,9 +3927,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
switch (mLayoutMode) {
|
switch (mLayoutMode) {
|
||||||
case LAYOUT_SET_SELECTION:
|
case LAYOUT_SET_SELECTION:
|
||||||
if (newSelected != null) {
|
if (newSelected != null) {
|
||||||
final int newSelectedStart =
|
final int newSelectedStart = getChildStartEdge(newSelected);
|
||||||
(mIsVertical ? newSelected.getTop() : newSelected.getLeft());
|
|
||||||
|
|
||||||
selected = fillFromSelection(newSelectedStart, start, end);
|
selected = fillFromSelection(newSelectedStart, start, end);
|
||||||
} else {
|
} else {
|
||||||
selected = fillFromMiddle(start, end);
|
selected = fillFromMiddle(start, end);
|
||||||
@ -3970,13 +3967,13 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
if (mSelectedPosition >= 0 && mSelectedPosition < mItemCount) {
|
if (mSelectedPosition >= 0 && mSelectedPosition < mItemCount) {
|
||||||
int offset = start;
|
int offset = start;
|
||||||
if (oldSelected != null) {
|
if (oldSelected != null) {
|
||||||
offset = (mIsVertical ? oldSelected.getTop() : oldSelected.getLeft());
|
offset = getChildStartEdge(oldSelected);
|
||||||
}
|
}
|
||||||
selected = fillSpecific(mSelectedPosition, offset);
|
selected = fillSpecific(mSelectedPosition, offset);
|
||||||
} else if (mFirstPosition < mItemCount) {
|
} else if (mFirstPosition < mItemCount) {
|
||||||
int offset = start;
|
int offset = start;
|
||||||
if (oldFirstChild != null) {
|
if (oldFirstChild != null) {
|
||||||
offset = (mIsVertical ? oldFirstChild.getTop() : oldFirstChild.getLeft());
|
offset = getChildStartEdge(oldFirstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
selected = fillSpecific(mFirstPosition, offset);
|
selected = fillSpecific(mFirstPosition, offset);
|
||||||
@ -4015,7 +4012,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
positionSelector(INVALID_POSITION, selected);
|
positionSelector(INVALID_POSITION, selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSelectedStart = (mIsVertical ? selected.getTop() : selected.getLeft());
|
mSelectedStart = getChildStartEdge(selected);
|
||||||
} else {
|
} else {
|
||||||
if (mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_DRAGGING) {
|
if (mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_DRAGGING) {
|
||||||
View child = getChildAt(mMotionPosition - mFirstPosition);
|
View child = getChildAt(mMotionPosition - mFirstPosition);
|
||||||
@ -4168,7 +4165,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
|
|
||||||
if (newSelected != null) {
|
if (newSelected != null) {
|
||||||
// Try to position the top of newSel (A) where it was before it was selected
|
// Try to position the top of newSel (A) where it was before it was selected
|
||||||
final int newSelectedStart = (mIsVertical ? newSelected.getTop() : newSelected.getLeft());
|
final int newSelectedStart = getChildStartEdge(newSelected);
|
||||||
selected = makeAndAddView(selectedPosition, newSelectedStart, true, true);
|
selected = makeAndAddView(selectedPosition, newSelectedStart, true, true);
|
||||||
} else {
|
} else {
|
||||||
// If (A) was not on screen and so did not have a view, position
|
// If (A) was not on screen and so did not have a view, position
|
||||||
@ -4415,14 +4412,14 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
selectedPosition = toPosition;
|
selectedPosition = toPosition;
|
||||||
|
|
||||||
final View selected = getChildAt(selectedPosition - mFirstPosition);
|
final View selected = getChildAt(selectedPosition - mFirstPosition);
|
||||||
selectedStart = (mIsVertical ? selected.getTop() : selected.getLeft());
|
selectedStart = getChildStartEdge(selected);
|
||||||
} else if (toPosition < firstPosition) {
|
} else if (toPosition < firstPosition) {
|
||||||
// Default to selecting whatever is first
|
// Default to selecting whatever is first
|
||||||
selectedPosition = firstPosition;
|
selectedPosition = firstPosition;
|
||||||
|
|
||||||
for (int i = 0; i < childCount; i++) {
|
for (int i = 0; i < childCount; i++) {
|
||||||
final View child = getChildAt(i);
|
final View child = getChildAt(i);
|
||||||
final int childStart = (mIsVertical ? child.getTop() : child.getLeft());
|
final int childStart = getChildStartEdge(child);
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
// Remember the position of the first item
|
// Remember the position of the first item
|
||||||
@ -4742,12 +4739,14 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
final int top;
|
final int top;
|
||||||
final int left;
|
final int left;
|
||||||
|
|
||||||
|
// Compensate item margin on the first item of the list if the item margin
|
||||||
|
// is negative to avoid incorrect offset for the very first child.
|
||||||
if (mIsVertical) {
|
if (mIsVertical) {
|
||||||
top = offset;
|
top = offset - (mItemMargin < 0 && position == 0 && !flow ? mItemMargin : 0);
|
||||||
left = getPaddingLeft();
|
left = getPaddingLeft();
|
||||||
} else {
|
} else {
|
||||||
top = getPaddingTop();
|
top = getPaddingTop();
|
||||||
left = offset;
|
left = offset - (mItemMargin < 0 && position == 0 && !flow ? mItemMargin: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mDataChanged) {
|
if (!mDataChanged) {
|
||||||
@ -4842,21 +4841,14 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
final int childCount = getChildCount();
|
final int childCount = getChildCount();
|
||||||
|
|
||||||
if (down) {
|
if (down) {
|
||||||
final int paddingStart = (mIsVertical ? getPaddingTop() : getPaddingLeft());
|
final int start = getStartEdge();
|
||||||
final int lastEnd = getChildEndEdge(getChildAt(childCount - 1));
|
final int lastEnd = getChildEndEdge(getChildAt(childCount - 1));
|
||||||
|
final int offset = (childCount > 0 ? lastEnd + mItemMargin : start);
|
||||||
final int offset = (childCount > 0 ? lastEnd + mItemMargin : paddingStart);
|
|
||||||
fillAfter(mFirstPosition + childCount, offset);
|
fillAfter(mFirstPosition + childCount, offset);
|
||||||
correctTooHigh(getChildCount());
|
correctTooHigh(getChildCount());
|
||||||
} else {
|
} else {
|
||||||
final int end = getEndEdge();
|
final int end = getEndEdge();
|
||||||
final int firstStart;
|
final int firstStart = getChildStartEdge(getChildAt(0));
|
||||||
if (mIsVertical) {
|
|
||||||
firstStart = getChildAt(0).getTop();
|
|
||||||
} else {
|
|
||||||
firstStart = getChildAt(0).getLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
final int offset = (childCount > 0 ? firstStart - mItemMargin : end);
|
final int offset = (childCount > 0 ? firstStart - mItemMargin : end);
|
||||||
fillBefore(mFirstPosition - 1, offset);
|
fillBefore(mFirstPosition - 1, offset);
|
||||||
correctTooLow(getChildCount());
|
correctTooLow(getChildCount());
|
||||||
@ -4870,13 +4862,9 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
|
|
||||||
while (nextOffset > start && pos >= 0) {
|
while (nextOffset > start && pos >= 0) {
|
||||||
boolean isSelected = (pos == mSelectedPosition);
|
boolean isSelected = (pos == mSelectedPosition);
|
||||||
View child = makeAndAddView(pos, nextOffset, false, isSelected);
|
|
||||||
|
|
||||||
if (mIsVertical) {
|
View child = makeAndAddView(pos, nextOffset, false, isSelected);
|
||||||
nextOffset = child.getTop() - mItemMargin;
|
nextOffset = getChildStartEdge(child) - mItemMargin;
|
||||||
} else {
|
|
||||||
nextOffset = child.getLeft() - mItemMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
selectedView = child;
|
selectedView = child;
|
||||||
@ -5084,8 +5072,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final View first = getChildAt(0);
|
final int firstStart = getChildStartEdge(getChildAt(0));
|
||||||
final int firstStart = (mIsVertical ? first.getTop() : first.getLeft());
|
|
||||||
|
|
||||||
final int start = getStartEdge();
|
final int start = getStartEdge();
|
||||||
final int end = getEndEdge();
|
final int end = getEndEdge();
|
||||||
@ -5133,13 +5120,12 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final View firstChild = getChildAt(0);
|
int delta = getChildStartEdge(getChildAt(0)) - getStartEdge();
|
||||||
|
|
||||||
int delta;
|
// If item margin is negative we shouldn't apply it in the
|
||||||
if (mIsVertical) {
|
// first item of the list to avoid offsetting it incorrectly.
|
||||||
delta = firstChild.getTop() - getPaddingTop() - mItemMargin;
|
if (mItemMargin >= 0 || mFirstPosition != 0) {
|
||||||
} else {
|
delta -= mItemMargin;
|
||||||
delta = firstChild.getLeft() - getPaddingLeft() - mItemMargin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delta < 0) {
|
if (delta < 0) {
|
||||||
@ -5342,7 +5328,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
mSyncPosition = mNextSelectedPosition;
|
mSyncPosition = mNextSelectedPosition;
|
||||||
|
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
mSpecificStart = (mIsVertical ? child.getTop() : child.getLeft());
|
mSpecificStart = getChildStartEdge(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSyncMode = SYNC_SELECTED_POSITION;
|
mSyncMode = SYNC_SELECTED_POSITION;
|
||||||
@ -5360,7 +5346,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
mSyncPosition = mFirstPosition;
|
mSyncPosition = mFirstPosition;
|
||||||
|
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
mSpecificStart = (mIsVertical ? child.getTop() : child.getLeft());
|
mSpecificStart = getChildStartEdge(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSyncMode = SYNC_FIRST_POSITION;
|
mSyncMode = SYNC_FIRST_POSITION;
|
||||||
@ -5526,8 +5512,7 @@ public class TwoWayView extends AdapterView<ListAdapter> implements
|
|||||||
// and the user wouldn't expect to end up somewhere else when
|
// and the user wouldn't expect to end up somewhere else when
|
||||||
// they revisit the list even if its content has changed.
|
// they revisit the list even if its content has changed.
|
||||||
|
|
||||||
View child = getChildAt(0);
|
ss.viewStart = getChildStartEdge(getChildAt(0));
|
||||||
ss.viewStart = (mIsVertical ? child.getTop() : child.getLeft());
|
|
||||||
|
|
||||||
int firstPos = mFirstPosition;
|
int firstPos = mFirstPosition;
|
||||||
if (firstPos >= mItemCount) {
|
if (firstPos >= mItemCount) {
|
||||||
|
Loading…
Reference in New Issue
Block a user