Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17c3bfc8 authored by Leon Scroggins's avatar Leon Scroggins Committed by The Android Open Source Project
Browse files

AI 146153: Make the TextDialog invisible, so that we only show WebKit's...

AI 146153: Make the TextDialog invisible, so that we only show WebKit's rendering of the textfield, yet we retain the benefits of having the TextDialog.
  Frame.cpp:
  Removed a line that should not be there anyway.  Somehow when merging in Apple's ENABLE(TEXT_CARET) changes we left in a line that disables the blinking Cursor.
  Platform.h:
  Let WebKit draw the cursor.
  RenderThemeAndroid.cpp:
  Make the active selection color (the color of a selection in an active <textfield> or <textarea>) visible, and match the selection color shown in other places in Android.
  WebViewCore.cpp:
  Make the focused node's document's focus controller active.  This allows webkit to draw the cursor.
  TextDialog.java:
  Set WillNotDraw to true, and remove our background, so that the TextDialog is completely invisible.  Note that I have not changed its visibility to View.VISIBLE, which would have other undesired effects (would not accept touch events, for example).  Since we are not drawing, remove onPreDraw, which is no longer necessary.  In onSelectionChanged, pass a message to webkit telling it that the selection has changed.  It is important that the two threads always agree (albeit webkit may be behind) because the user will now only see the selection drawn by webkit.  Remove some old flawed code whose purpose was to keep the selection up to date and do not send key events for arrow keys (which would mess up the selection that was correct thanks to onSelectionChanged).
  BUG=1781070,1712752,916193,1411370,1160999,1775425,1354814

Automated import of CL 146153
parent 3ff7eb92
Loading
Loading
Loading
Loading
+14 −48
Original line number Diff line number Diff line
@@ -17,19 +17,11 @@
package android.webkit;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.MovementMethod;
import android.view.inputmethod.EditorInfo;
@@ -86,32 +78,10 @@ import java.util.ArrayList;
    /* package */ TextDialog(Context context, WebView webView) {
        super(context);
        mWebView = webView;
        ShapeDrawable background = new ShapeDrawable(new RectShape());
        Paint shapePaint = background.getPaint();
        shapePaint.setStyle(Paint.Style.STROKE);
        ColorDrawable color = new ColorDrawable(Color.WHITE);
        Drawable[] array = new Drawable[2];
        array[0] = color;
        array[1] = background;
        LayerDrawable layers = new LayerDrawable(array);
        // Hide WebCore's text behind this and allow the WebView
        // to draw its own focusring.
        setBackgroundDrawable(layers);
        // Align the text better with the text behind it, so moving
        // off of the textfield will not appear to move the text.
        setPadding(3, 2, 0, 0);
        mMaxLength = -1;
        // Turn on subpixel text, and turn off kerning, so it better matches
        // the text in webkit.
        TextPaint paint = getPaint();
        int flags = paint.getFlags() | Paint.SUBPIXEL_TEXT_FLAG |
                Paint.ANTI_ALIAS_FLAG & ~Paint.DEV_KERN_TEXT_FLAG;
        paint.setFlags(flags);
        // Set the text color to black, regardless of the theme.  This ensures
        // that other applications that use embedded WebViews will properly
        // display the text in textfields.
        setTextColor(Color.BLACK);
        setImeOptions(EditorInfo.IME_ACTION_NONE);
        // Allow webkit's drawing to show through
        setWillNotDraw(true);
    }

    @Override
@@ -225,19 +195,21 @@ import java.util.ArrayList;
                    return true;
                }
            }
            /* FIXME:
             * In theory, we would like to send the events for the arrow keys.
             * However, the TextView can arbitrarily change the selection (i.e.
             * long press followed by using the trackball).  Therefore, we keep
             * in sync with the TextView via onSelectionChanged.  If we also
             * send the DOM event, we lose the correct selection.
            if (isArrowKey) {
                // Arrow key does not change the text, but we still want to send
                // the DOM events.
                sendDomEvent(event);
            }
             */
            mScrollToAccommodateCursor = true;
            return true;
        }
        // FIXME: TextViews return false for up and down key events even though
        // they change the selection. Since we don't want the get out of sync
        // with WebCore's notion of the current selection, reset the selection
        // to what it was before the key event.
        Selection.setSelection(text, oldStart, oldEnd);
        // Ignore the key up event for newlines. This prevents
        // multiple newlines in the native textarea.
        if (mGotEnterDown && !down) {
@@ -290,11 +262,10 @@ import java.util.ArrayList;
    }

    @Override
    public boolean onPreDraw() {
        if (getLayout() == null) {
            measure(mWidthSpec, mHeightSpec);
    protected void onSelectionChanged(int selStart, int selEnd) {
        if (mWebView != null) {
            mWebView.setSelection(selStart, selEnd);
        }
        return super.onPreDraw();
    }

    @Override
@@ -366,12 +337,7 @@ import java.util.ArrayList;
        MovementMethod move = getMovementMethod();
        if (move != null && getLayout() != null &&
            move.onTrackballEvent(this, text, event)) {
            // Need to pass down the selection, which has changed.
            // FIXME: This should work, but does not, so we set the selection
            // in onTextChanged.
            //int start = Selection.getSelectionStart(text);
            //int end = Selection.getSelectionEnd(text);
            //mWebView.setSelection(start, end);
            // Selection is changed in onSelectionChanged
            return true;
        }
        // If the user is in a textfield, and the movement method is not