Skip to content

Commit 852585c

Browse files
Michael KolbAndroid (Google) Code Review
authored andcommitted
Merge "Draw input field focus ring in WebTextView" into ics-mr1
2 parents 8ac35e3 + edb39ce commit 852585c

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

core/java/android/webkit/WebTextView.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package android.webkit;
1818

1919
import android.content.Context;
20+
import android.graphics.Canvas;
2021
import android.graphics.Color;
2122
import android.graphics.Paint;
23+
import android.graphics.Paint.Style;
2224
import android.graphics.Rect;
2325
import android.graphics.drawable.ColorDrawable;
2426
import android.os.Bundle;
@@ -49,6 +51,7 @@
4951
import android.view.inputmethod.EditorInfo;
5052
import android.view.inputmethod.InputConnection;
5153
import android.view.inputmethod.InputMethodManager;
54+
import android.widget.AbsoluteLayout;
5255
import android.widget.AbsoluteLayout.LayoutParams;
5356
import android.widget.AdapterView;
5457
import android.widget.ArrayAdapter;
@@ -71,6 +74,9 @@
7174

7275
static final String LOGTAG = "webtextview";
7376

77+
private Paint mRingPaint;
78+
private int mRingInset;
79+
7480
private WebView mWebView;
7581
private boolean mSingle;
7682
private int mWidthSpec;
@@ -201,7 +207,13 @@ public void handleMessage(Message msg) {
201207
}
202208
}
203209
};
210+
float ringWidth = 4f * context.getResources().getDisplayMetrics().density;
204211
mReceiver = new MyResultReceiver(mHandler);
212+
mRingPaint = new Paint();
213+
mRingPaint.setColor(0x6633b5e5);
214+
mRingPaint.setStrokeWidth(ringWidth);
215+
mRingPaint.setStyle(Style.FILL);
216+
mRingInset = (int) ringWidth;
205217
}
206218

207219
public void setAutoFillable(int queryId) {
@@ -210,6 +222,40 @@ public void setAutoFillable(int queryId) {
210222
mQueryId = queryId;
211223
}
212224

225+
@Override
226+
protected void onDraw(Canvas canvas) {
227+
super.onDraw(canvas);
228+
if (isFocused()) {
229+
final int ib = getHeight() - mRingInset;
230+
canvas.drawRect(0, 0, getWidth(), mRingInset, mRingPaint);
231+
canvas.drawRect(0, ib, getWidth(), getHeight(), mRingPaint);
232+
canvas.drawRect(0, mRingInset, mRingInset, ib, mRingPaint);
233+
canvas.drawRect(getWidth() - mRingInset, mRingInset, getWidth(), ib, mRingPaint);
234+
}
235+
}
236+
237+
private void growOrShrink(boolean grow) {
238+
AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) getLayoutParams();
239+
if (grow) {
240+
Log.i("webtextview", "grow");
241+
lp.x -= mRingInset;
242+
lp.y -= mRingInset;
243+
lp.width += 2 * mRingInset;
244+
lp.height += 2 * mRingInset;
245+
setPadding(getPaddingLeft() + mRingInset, getPaddingTop() + mRingInset,
246+
getPaddingRight() + mRingInset, getPaddingBottom() + mRingInset);
247+
} else {
248+
Log.i("webtextview", "shrink");
249+
lp.x += mRingInset;
250+
lp.y += mRingInset;
251+
lp.width -= 2 * mRingInset;
252+
lp.height -= 2 * mRingInset;
253+
setPadding(getPaddingLeft() - mRingInset, getPaddingTop() - mRingInset,
254+
getPaddingRight() - mRingInset, getPaddingBottom() - mRingInset);
255+
}
256+
setLayoutParams(lp);
257+
}
258+
213259
@Override
214260
public boolean dispatchKeyEvent(KeyEvent event) {
215261
if (event.isSystem()) {
@@ -511,6 +557,7 @@ protected void onFocusChanged(boolean focused, int direction,
511557
} else if (!mInsideRemove) {
512558
mWebView.setActive(false);
513559
}
560+
growOrShrink(focused);
514561
mFromFocusChange = false;
515562
}
516563

core/java/android/webkit/WebView.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5679,13 +5679,13 @@ void setActive(boolean active) {
56795679
if (hasFocus()) {
56805680
// If our window regained focus, and we have focus, then begin
56815681
// drawing the cursor ring
5682-
mDrawCursorRing = true;
5682+
mDrawCursorRing = !inEditingMode();
56835683
setFocusControllerActive(true);
56845684
} else {
5685+
mDrawCursorRing = false;
56855686
if (!inEditingMode()) {
56865687
// If our window gained focus, but we do not have it, do not
56875688
// draw the cursor ring.
5688-
mDrawCursorRing = false;
56895689
setFocusControllerActive(false);
56905690
}
56915691
// We do not call recordButtons here because we assume
@@ -5760,7 +5760,7 @@ protected void onFocusChanged(boolean focused, int direction,
57605760
// When we regain focus, if we have window focus, resume drawing
57615761
// the cursor ring
57625762
if (hasWindowFocus()) {
5763-
mDrawCursorRing = true;
5763+
mDrawCursorRing = !inEditingMode();
57645764
setFocusControllerActive(true);
57655765
//} else {
57665766
// The WebView has gained focus while we do not have
@@ -5770,8 +5770,8 @@ protected void onFocusChanged(boolean focused, int direction,
57705770
} else {
57715771
// When we lost focus, unless focus went to the TextView (which is
57725772
// true if we are in editing mode), stop drawing the cursor ring.
5773+
mDrawCursorRing = false;
57735774
if (!inEditingMode()) {
5774-
mDrawCursorRing = false;
57755775
setFocusControllerActive(false);
57765776
}
57775777
mKeysPressed.clear();

0 commit comments

Comments
 (0)