Skip to content

Commit 36a7f2a

Browse files
jreckAndroid (Google) Code Review
authored andcommitted
Merge "Fix determining find on page overlap" into ics-mr1
2 parents eae6c99 + d6ac727 commit 36a7f2a

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

core/java/android/webkit/FindActionModeCallback.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import android.content.Context;
2020
import android.content.res.Resources;
21+
import android.graphics.Point;
22+
import android.graphics.Rect;
2123
import android.text.Editable;
2224
import android.text.Selection;
2325
import android.text.Spannable;
@@ -254,13 +256,18 @@ public void afterTextChanged(Editable s) {
254256
// Does nothing. Needed to implement TextWatcher.
255257
}
256258

257-
public int getActionModeHeight() {
259+
private Rect mGlobalVisibleRect = new Rect();
260+
private Point mGlobalVisibleOffset = new Point();
261+
public int getActionModeGlobalBottom() {
258262
if (mActionMode == null) {
259263
return 0;
260264
}
261-
View parent = (View) mCustomView.getParent();
262-
return parent != null ? parent.getMeasuredHeight()
263-
: mCustomView.getMeasuredHeight();
265+
View view = (View) mCustomView.getParent();
266+
if (view == null) {
267+
view = mCustomView;
268+
}
269+
view.getGlobalVisibleRect(mGlobalVisibleRect, mGlobalVisibleOffset);
270+
return mGlobalVisibleRect.bottom;
264271
}
265272

266273
}

core/java/android/webkit/WebView.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,21 @@ public int getVisibleTitleHeight() {
14841484
private int getVisibleTitleHeightImpl() {
14851485
// need to restrict mScrollY due to over scroll
14861486
return Math.max(getTitleHeight() - Math.max(0, mScrollY),
1487-
mFindCallback != null ? mFindCallback.getActionModeHeight() : 0);
1487+
getOverlappingActionModeHeight());
1488+
}
1489+
1490+
private int mCachedOverlappingActionModeHeight = -1;
1491+
1492+
private int getOverlappingActionModeHeight() {
1493+
if (mFindCallback == null) {
1494+
return 0;
1495+
}
1496+
if (mCachedOverlappingActionModeHeight < 0) {
1497+
getGlobalVisibleRect(mGlobalVisibleRect, mGlobalVisibleOffset);
1498+
mCachedOverlappingActionModeHeight = Math.max(0,
1499+
mFindCallback.getActionModeGlobalBottom() - mGlobalVisibleRect.top);
1500+
}
1501+
return mCachedOverlappingActionModeHeight;
14881502
}
14891503

14901504
/*
@@ -3375,6 +3389,7 @@ public boolean showFindDialog(String text, boolean showIme) {
33753389
// Could not start the action mode, so end Find on page
33763390
return false;
33773391
}
3392+
mCachedOverlappingActionModeHeight = -1;
33783393
mFindCallback = callback;
33793394
setFindIsUp(true);
33803395
mFindCallback.setWebView(this);
@@ -3492,6 +3507,7 @@ public void clearMatches() {
34923507
*/
34933508
void notifyFindDialogDismissed() {
34943509
mFindCallback = null;
3510+
mCachedOverlappingActionModeHeight = -1;
34953511
if (mWebViewCore == null) {
34963512
return;
34973513
}
@@ -4341,6 +4357,7 @@ boolean selectText(int x, int y) {
43414357

43424358
@Override
43434359
protected void onConfigurationChanged(Configuration newConfig) {
4360+
mCachedOverlappingActionModeHeight = -1;
43444361
if (mSelectingText && mOrientation != newConfig.orientation) {
43454362
selectionDone();
43464363
}

0 commit comments

Comments
 (0)