⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 117745 in webkit


Ignore:
Timestamp:
May 21, 2012, 1:27:42 AM (14 years ago)
Author:
abarth@webkit.org
Message:

[Chromium] Implement WebViewImpl::textInputInfo() for Android
https://bugs.webkit.org/show_bug.cgi?id=86440

Reviewed by Darin Fisher.

This patch adds WebView::textInputInfo(), which describes the text
input that currently has focus. Android is planning to use this to
determine what sort of keyboard or text entry UI to show. This API
subsumes the textInputType() API, which will be removed once the
clients have been updated.

  • WebKit.gyp:
  • public/WebTextInputInfo.h: Added.

(WebKit):
(WebTextInputInfo):
(WebKit::WebTextInputInfo::WebTextInputInfo):
(WebKit::operator==):
(WebKit::operator!=):

  • public/WebTextInputType.h:
  • public/WebWidget.h:

(WebWidget):
(WebKit::WebWidget::textInputInfo):
(WebKit::WebWidget::textInputType):

  • src/WebViewImpl.cpp:

(WebKit::WebViewImpl::textInputInfo):
(WebKit):
(WebKit::WebViewImpl::textInputType):

  • src/WebViewImpl.h:

(WebViewImpl):

Location:
trunk/Source/WebKit/chromium
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r117741 r117745  
     12012-05-21  Adam Barth  <abarth@webkit.org>
     2
     3        [Chromium] Implement WebViewImpl::textInputInfo() for Android
     4        https://bugs.webkit.org/show_bug.cgi?id=86440
     5
     6        Reviewed by Darin Fisher.
     7
     8        This patch adds WebView::textInputInfo(), which describes the text
     9        input that currently has focus.  Android is planning to use this to
     10        determine what sort of keyboard or text entry UI to show.  This API
     11        subsumes the textInputType() API, which will be removed once the
     12        clients have been updated.
     13
     14        * WebKit.gyp:
     15        * public/WebTextInputInfo.h: Added.
     16        (WebKit):
     17        (WebTextInputInfo):
     18        (WebKit::WebTextInputInfo::WebTextInputInfo):
     19        (WebKit::operator==):
     20        (WebKit::operator!=):
     21        * public/WebTextInputType.h:
     22        * public/WebWidget.h:
     23        (WebWidget):
     24        (WebKit::WebWidget::textInputInfo):
     25        (WebKit::WebWidget::textInputType):
     26        * src/WebViewImpl.cpp:
     27        (WebKit::WebViewImpl::textInputInfo):
     28        (WebKit):
     29        (WebKit::WebViewImpl::textInputType):
     30        * src/WebViewImpl.h:
     31        (WebViewImpl):
     32
    1332012-05-21  Sheriff Bot  <webkit.review.bot@gmail.com>
    234
  • trunk/Source/WebKit/chromium/WebKit.gyp

    r117538 r117745  
    273273                'public/WebTextDirection.h',
    274274                'public/WebTextFieldDecoratorClient.h',
     275                'public/WebTextInputInfo.h',
    275276                'public/WebTextInputType.h',
    276277                'public/WebTextRun.h',
     
    659660                'src/WebStorageQuotaCallbacksImpl.h',
    660661                'src/WebSurroundingText.cpp',
     662                'src/WebTextInputInfo.cpp',
    661663                'src/WebTextRun.cpp',
    662664                'src/WebURLLoadTiming.cpp',
  • trunk/Source/WebKit/chromium/public/WebWidget.h

    r117402 r117745  
    3333
    3434#include "WebCompositionUnderline.h"
    35 #include "WebTextInputType.h"
    3635#include "WebTextDirection.h"
     36#include "WebTextInputInfo.h"
    3737#include "platform/WebCanvas.h"
    3838#include "platform/WebCommon.h"
     
    171171    virtual bool compositionRange(size_t* location, size_t* length) { return false; }
    172172
     173    // Returns information about the current text input of this WebWidget.
     174    virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); }
     175
    173176    // Returns the current text input type of this WebWidget.
    174     virtual WebTextInputType textInputType() { return WebKit::WebTextInputTypeNone; }
     177    // FIXME: Remove this method. It's redundant with textInputInfo().
     178    virtual WebTextInputType textInputType() { return WebTextInputTypeNone; }
    175179
    176180    // Returns the start and end bounds of the current selection.
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r117560 r117745  
    114114#include "SpeechRecognitionClientProxy.h"
    115115#include "StyleResolver.h"
     116#include "Text.h"
    116117#include "TextFieldDecoratorImpl.h"
    117118#include "TextIterator.h"
     
    141142#include "WebRuntimeFeatures.h"
    142143#include "WebSettingsImpl.h"
     144#include "WebTextInputInfo.h"
    143145#include "WebViewClient.h"
    144146#include "WheelEvent.h"
     
    18811883}
    18821884
     1885WebTextInputInfo WebViewImpl::textInputInfo()
     1886{
     1887    WebTextInputInfo info;
     1888
     1889    Frame* focused = focusedWebCoreFrame();
     1890    if (!focused)
     1891        return info;
     1892
     1893    Editor* editor = focused->editor();
     1894    if (!editor || !editor->canEdit())
     1895        return info;
     1896
     1897    FrameSelection* selection = focused->selection();
     1898    if (!selection)
     1899        return info;
     1900
     1901    Node* node = focusedWebCoreNode();
     1902    if (!node)
     1903        return info;
     1904
     1905    info.type = textInputType();
     1906    if (info.type == WebTextInputTypeNone)
     1907        return info;
     1908
     1909    if (node->hasTagName(HTMLNames::textareaTag))
     1910        info.value = static_cast<HTMLTextAreaElement*>(node)->value();
     1911    else if (node->hasTagName(HTMLNames::inputTag))
     1912        info.value = static_cast<HTMLInputElement*>(node)->value();
     1913    else if (node->shouldUseInputMethod())
     1914        info.value = node->nodeValue();
     1915    else
     1916        return info;
     1917
     1918    if (info.value.isEmpty())
     1919        return info;
     1920
     1921    if (node->hasTagName(HTMLNames::textareaTag) || node->hasTagName(HTMLNames::inputTag)) {
     1922        HTMLTextFormControlElement* formElement = static_cast<HTMLTextFormControlElement*>(node);
     1923        info.selectionStart = formElement->selectionStart();
     1924        info.selectionEnd = formElement->selectionEnd();
     1925        if (editor->hasComposition()) {
     1926            info.compositionStart = formElement->indexForVisiblePosition(Position(editor->compositionNode(), editor->compositionStart()));
     1927            info.compositionEnd = formElement->indexForVisiblePosition(Position(editor->compositionNode(), editor->compositionEnd()));
     1928        }
     1929    } else {
     1930        info.selectionStart = selection->start().computeOffsetInContainerNode();
     1931        info.selectionEnd = selection->end().computeOffsetInContainerNode();
     1932        if (editor->hasComposition()) {
     1933            info.compositionStart = static_cast<int>(editor->compositionStart());
     1934            info.compositionEnd = static_cast<int>(editor->compositionEnd());
     1935        }
     1936    }
     1937
     1938    return info;
     1939}
     1940
    18831941WebTextInputType WebViewImpl::textInputType()
    18841942{
     
    18871945        return WebTextInputTypeNone;
    18881946
    1889     if (node->nodeType() == Node::ELEMENT_NODE) {
    1890         Element* element = static_cast<Element*>(node);
    1891         if (element->hasLocalName(HTMLNames::inputTag)) {
    1892             HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
    1893 
    1894             if (input->readOnly() || input->disabled())
    1895                 return WebTextInputTypeNone;
    1896 
    1897             if (input->isPasswordField())
    1898                 return WebTextInputTypePassword;
    1899             if (input->isSearchField())
    1900                 return WebTextInputTypeSearch;
    1901             if (input->isEmailField())
    1902                 return WebTextInputTypeEmail;
    1903             if (input->isNumberField())
    1904                 return WebTextInputTypeNumber;
    1905             if (input->isTelephoneField())
    1906                 return WebTextInputTypeTelephone;
    1907             if (input->isURLField())
    1908                 return WebTextInputTypeURL;
    1909             if (input->isDateField())
    1910                 return WebTextInputTypeDate;
    1911             if (input->isDateTimeField())
    1912                 return WebTextInputTypeDateTime;
    1913             if (input->isDateTimeLocalField())
    1914                 return WebTextInputTypeDateTimeLocal;
    1915             if (input->isMonthField())
    1916                 return WebTextInputTypeMonth;
    1917             if (input->isTimeField())
    1918                 return WebTextInputTypeTime;
    1919             if (input->isWeekField())
    1920                 return WebTextInputTypeWeek;
    1921             if (input->isTextField())
    1922                 return WebTextInputTypeText;
    1923 
     1947    if (node->hasTagName(HTMLNames::inputTag)) {
     1948        HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
     1949
     1950        if (input->readOnly() || input->disabled())
    19241951            return WebTextInputTypeNone;
    1925         }
    1926 
    1927         if (element->hasLocalName(HTMLNames::textareaTag)) {
    1928             HTMLTextAreaElement* textarea = static_cast<HTMLTextAreaElement*>(element);
    1929 
    1930             if (textarea->readOnly() || textarea->disabled())
    1931                 return WebTextInputTypeNone;
     1952
     1953        if (input->isPasswordField())
     1954            return WebTextInputTypePassword;
     1955        if (input->isSearchField())
     1956            return WebTextInputTypeSearch;
     1957        if (input->isEmailField())
     1958            return WebTextInputTypeEmail;
     1959        if (input->isNumberField())
     1960            return WebTextInputTypeNumber;
     1961        if (input->isTelephoneField())
     1962            return WebTextInputTypeTelephone;
     1963        if (input->isURLField())
     1964            return WebTextInputTypeURL;
     1965        if (input->isDateField())
     1966            return WebTextInputTypeDate;
     1967        if (input->isDateTimeField())
     1968            return WebTextInputTypeDateTime;
     1969        if (input->isDateTimeLocalField())
     1970            return WebTextInputTypeDateTimeLocal;
     1971        if (input->isMonthField())
     1972            return WebTextInputTypeMonth;
     1973        if (input->isTimeField())
     1974            return WebTextInputTypeTime;
     1975        if (input->isWeekField())
     1976            return WebTextInputTypeWeek;
     1977        if (input->isTextField())
    19321978            return WebTextInputTypeText;
    1933         }
    1934     }
    1935 
    1936     // For other situations.
     1979
     1980        return WebTextInputTypeNone;
     1981    }
     1982
     1983    if (node->hasTagName(HTMLNames::textareaTag)) {
     1984        HTMLTextAreaElement* textarea = static_cast<HTMLTextAreaElement*>(node);
     1985
     1986        if (textarea->readOnly() || textarea->disabled())
     1987            return WebTextInputTypeNone;
     1988
     1989        return WebTextInputTypeText;
     1990    }
     1991
    19371992    if (node->shouldUseInputMethod())
    19381993        return WebTextInputTypeText;
  • trunk/Source/WebKit/chromium/src/WebViewImpl.h

    r117560 r117745  
    146146    virtual bool confirmComposition(const WebString& text);
    147147    virtual bool compositionRange(size_t* location, size_t* length);
     148    virtual WebTextInputInfo textInputInfo();
    148149    virtual WebTextInputType textInputType();
    149150    virtual bool selectionBounds(WebRect& start, WebRect& end) const;
Note: See TracChangeset for help on using the changeset viewer.