Diff
Modified: trunk/Source/WebKit/chromium/ChangeLog (117744 => 117745)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-05-21 08:14:46 UTC (rev 117744)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-05-21 08:27:42 UTC (rev 117745)
@@ -1,3 +1,35 @@
+2012-05-21 Adam Barth <[email protected]>
+
+ [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):
+
2012-05-21 Sheriff Bot <[email protected]>
Unreviewed. Rolled DEPS.
Modified: trunk/Source/WebKit/chromium/WebKit.gyp (117744 => 117745)
--- trunk/Source/WebKit/chromium/WebKit.gyp 2012-05-21 08:14:46 UTC (rev 117744)
+++ trunk/Source/WebKit/chromium/WebKit.gyp 2012-05-21 08:27:42 UTC (rev 117745)
@@ -272,6 +272,7 @@
'public/WebTextCheckingResult.h',
'public/WebTextDirection.h',
'public/WebTextFieldDecoratorClient.h',
+ 'public/WebTextInputInfo.h',
'public/WebTextInputType.h',
'public/WebTextRun.h',
'public/WebTimeRange.h',
@@ -658,6 +659,7 @@
'src/WebStorageQuotaCallbacksImpl.cpp',
'src/WebStorageQuotaCallbacksImpl.h',
'src/WebSurroundingText.cpp',
+ 'src/WebTextInputInfo.cpp',
'src/WebTextRun.cpp',
'src/WebURLLoadTiming.cpp',
'src/WebScopedUserGesture.cpp',
Added: trunk/Source/WebKit/chromium/public/WebTextInputInfo.h (0 => 117745)
--- trunk/Source/WebKit/chromium/public/WebTextInputInfo.h (rev 0)
+++ trunk/Source/WebKit/chromium/public/WebTextInputInfo.h 2012-05-21 08:27:42 UTC (rev 117745)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebTextInputInfo_h
+#define WebTextInputInfo_h
+
+#include "WebTextInputType.h"
+#include "platform/WebString.h"
+
+namespace WebKit {
+
+struct WebTextInputInfo {
+ WebTextInputType type;
+
+ // The value of the currently focused input field.
+ WebString value;
+
+ // The cursor position of the current selection start, or the caret position
+ // if nothing is selected.
+ int selectionStart;
+
+ // The cursor position of the current selection end, or the caret position
+ // if nothing is selected.
+ int selectionEnd;
+
+ // The start position of the current composition, or -1 if there is none.
+ int compositionStart;
+
+ // The end position of the current composition, or -1 if there is none.
+ int compositionEnd;
+
+ WEBKIT_EXPORT bool equals(const WebTextInputInfo&) const;
+
+ WebTextInputInfo()
+ : type(WebTextInputTypeNone)
+ , selectionStart(0)
+ , selectionEnd(0)
+ , compositionStart(-1)
+ , compositionEnd(-1)
+ {
+ }
+};
+
+inline bool operator==(const WebTextInputInfo& a, const WebTextInputInfo& b)
+{
+ return a.equals(b);
+}
+
+inline bool operator!=(const WebTextInputInfo& a, const WebTextInputInfo& b)
+{
+ return !(a == b);
+}
+
+} // namespace WebKit
+
+#endif
Modified: trunk/Source/WebKit/chromium/public/WebWidget.h (117744 => 117745)
--- trunk/Source/WebKit/chromium/public/WebWidget.h 2012-05-21 08:14:46 UTC (rev 117744)
+++ trunk/Source/WebKit/chromium/public/WebWidget.h 2012-05-21 08:27:42 UTC (rev 117745)
@@ -32,8 +32,8 @@
#define WebWidget_h
#include "WebCompositionUnderline.h"
-#include "WebTextInputType.h"
#include "WebTextDirection.h"
+#include "WebTextInputInfo.h"
#include "platform/WebCanvas.h"
#include "platform/WebCommon.h"
#include "platform/WebRect.h"
@@ -170,8 +170,12 @@
// returns false on failure.
virtual bool compositionRange(size_t* location, size_t* length) { return false; }
+ // Returns information about the current text input of this WebWidget.
+ virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); }
+
// Returns the current text input type of this WebWidget.
- virtual WebTextInputType textInputType() { return WebKit::WebTextInputTypeNone; }
+ // FIXME: Remove this method. It's redundant with textInputInfo().
+ virtual WebTextInputType textInputType() { return WebTextInputTypeNone; }
// Returns the start and end bounds of the current selection.
// If the selection range is empty, it returns the caret bounds.
Added: trunk/Source/WebKit/chromium/src/WebTextInputInfo.cpp (0 => 117745)
--- trunk/Source/WebKit/chromium/src/WebTextInputInfo.cpp (rev 0)
+++ trunk/Source/WebKit/chromium/src/WebTextInputInfo.cpp 2012-05-21 08:27:42 UTC (rev 117745)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebTextInputInfo.h"
+
+namespace WebKit {
+
+bool WebTextInputInfo::equals(const WebTextInputInfo& other) const
+{
+ return type == other.type
+ && value == other.value
+ && selectionStart == other.selectionStart
+ && selectionEnd == other.selectionEnd
+ && compositionStart == other.compositionStart
+ && compositionEnd == other.compositionEnd;
+}
+
+} // namespace WebKit
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (117744 => 117745)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-05-21 08:14:46 UTC (rev 117744)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-05-21 08:27:42 UTC (rev 117745)
@@ -113,6 +113,7 @@
#include "SpeechInputClientImpl.h"
#include "SpeechRecognitionClientProxy.h"
#include "StyleResolver.h"
+#include "Text.h"
#include "TextFieldDecoratorImpl.h"
#include "TextIterator.h"
#include "Timer.h"
@@ -140,6 +141,7 @@
#include "WebRange.h"
#include "WebRuntimeFeatures.h"
#include "WebSettingsImpl.h"
+#include "WebTextInputInfo.h"
#include "WebViewClient.h"
#include "WheelEvent.h"
#include "cc/CCProxy.h"
@@ -1880,60 +1882,113 @@
return false;
}
-WebTextInputType WebViewImpl::textInputType()
+WebTextInputInfo WebViewImpl::textInputInfo()
{
+ WebTextInputInfo info;
+
+ Frame* focused = focusedWebCoreFrame();
+ if (!focused)
+ return info;
+
+ Editor* editor = focused->editor();
+ if (!editor || !editor->canEdit())
+ return info;
+
+ FrameSelection* selection = focused->selection();
+ if (!selection)
+ return info;
+
Node* node = focusedWebCoreNode();
if (!node)
- return WebTextInputTypeNone;
+ return info;
- if (node->nodeType() == Node::ELEMENT_NODE) {
- Element* element = static_cast<Element*>(node);
- if (element->hasLocalName(HTMLNames::inputTag)) {
- HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
+ info.type = textInputType();
+ if (info.type == WebTextInputTypeNone)
+ return info;
- if (input->readOnly() || input->disabled())
- return WebTextInputTypeNone;
+ if (node->hasTagName(HTMLNames::textareaTag))
+ info.value = static_cast<HTMLTextAreaElement*>(node)->value();
+ else if (node->hasTagName(HTMLNames::inputTag))
+ info.value = static_cast<HTMLInputElement*>(node)->value();
+ else if (node->shouldUseInputMethod())
+ info.value = node->nodeValue();
+ else
+ return info;
- if (input->isPasswordField())
- return WebTextInputTypePassword;
- if (input->isSearchField())
- return WebTextInputTypeSearch;
- if (input->isEmailField())
- return WebTextInputTypeEmail;
- if (input->isNumberField())
- return WebTextInputTypeNumber;
- if (input->isTelephoneField())
- return WebTextInputTypeTelephone;
- if (input->isURLField())
- return WebTextInputTypeURL;
- if (input->isDateField())
- return WebTextInputTypeDate;
- if (input->isDateTimeField())
- return WebTextInputTypeDateTime;
- if (input->isDateTimeLocalField())
- return WebTextInputTypeDateTimeLocal;
- if (input->isMonthField())
- return WebTextInputTypeMonth;
- if (input->isTimeField())
- return WebTextInputTypeTime;
- if (input->isWeekField())
- return WebTextInputTypeWeek;
- if (input->isTextField())
- return WebTextInputTypeText;
+ if (info.value.isEmpty())
+ return info;
- return WebTextInputTypeNone;
+ if (node->hasTagName(HTMLNames::textareaTag) || node->hasTagName(HTMLNames::inputTag)) {
+ HTMLTextFormControlElement* formElement = static_cast<HTMLTextFormControlElement*>(node);
+ info.selectionStart = formElement->selectionStart();
+ info.selectionEnd = formElement->selectionEnd();
+ if (editor->hasComposition()) {
+ info.compositionStart = formElement->indexForVisiblePosition(Position(editor->compositionNode(), editor->compositionStart()));
+ info.compositionEnd = formElement->indexForVisiblePosition(Position(editor->compositionNode(), editor->compositionEnd()));
}
+ } else {
+ info.selectionStart = selection->start().computeOffsetInContainerNode();
+ info.selectionEnd = selection->end().computeOffsetInContainerNode();
+ if (editor->hasComposition()) {
+ info.compositionStart = static_cast<int>(editor->compositionStart());
+ info.compositionEnd = static_cast<int>(editor->compositionEnd());
+ }
+ }
- if (element->hasLocalName(HTMLNames::textareaTag)) {
- HTMLTextAreaElement* textarea = static_cast<HTMLTextAreaElement*>(element);
+ return info;
+}
- if (textarea->readOnly() || textarea->disabled())
- return WebTextInputTypeNone;
+WebTextInputType WebViewImpl::textInputType()
+{
+ Node* node = focusedWebCoreNode();
+ if (!node)
+ return WebTextInputTypeNone;
+
+ if (node->hasTagName(HTMLNames::inputTag)) {
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
+
+ if (input->readOnly() || input->disabled())
+ return WebTextInputTypeNone;
+
+ if (input->isPasswordField())
+ return WebTextInputTypePassword;
+ if (input->isSearchField())
+ return WebTextInputTypeSearch;
+ if (input->isEmailField())
+ return WebTextInputTypeEmail;
+ if (input->isNumberField())
+ return WebTextInputTypeNumber;
+ if (input->isTelephoneField())
+ return WebTextInputTypeTelephone;
+ if (input->isURLField())
+ return WebTextInputTypeURL;
+ if (input->isDateField())
+ return WebTextInputTypeDate;
+ if (input->isDateTimeField())
+ return WebTextInputTypeDateTime;
+ if (input->isDateTimeLocalField())
+ return WebTextInputTypeDateTimeLocal;
+ if (input->isMonthField())
+ return WebTextInputTypeMonth;
+ if (input->isTimeField())
+ return WebTextInputTypeTime;
+ if (input->isWeekField())
+ return WebTextInputTypeWeek;
+ if (input->isTextField())
return WebTextInputTypeText;
- }
+
+ return WebTextInputTypeNone;
}
- // For other situations.
+ if (node->hasTagName(HTMLNames::textareaTag)) {
+ HTMLTextAreaElement* textarea = static_cast<HTMLTextAreaElement*>(node);
+
+ if (textarea->readOnly() || textarea->disabled())
+ return WebTextInputTypeNone;
+
+ return WebTextInputTypeText;
+ }
+
if (node->shouldUseInputMethod())
return WebTextInputTypeText;
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (117744 => 117745)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.h 2012-05-21 08:14:46 UTC (rev 117744)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h 2012-05-21 08:27:42 UTC (rev 117745)
@@ -145,6 +145,7 @@
virtual bool confirmComposition();
virtual bool confirmComposition(const WebString& text);
virtual bool compositionRange(size_t* location, size_t* length);
+ virtual WebTextInputInfo textInputInfo();
virtual WebTextInputType textInputType();
virtual bool selectionBounds(WebRect& start, WebRect& end) const;
virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const;