Source/WebCore: Add API functions to enable starting and stopping speech input,
[WebKit-https.git] / Source / WebKit / chromium / src / WebInputElement.cpp
index 697c096..49fe19e 100644 (file)
@@ -33,6 +33,9 @@
 
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
+#include "RenderObject.h"
+#include "RenderTextControlSingleLine.h"
+#include "TextControlInnerElements.h"
 #include "WebString.h"
 #include <wtf/PassRefPtr.h>
 
@@ -62,17 +65,7 @@ bool WebInputElement::isImageButton() const
 
 bool WebInputElement::autoComplete() const
 {
-    return constUnwrap<HTMLInputElement>()->autoComplete();
-}
-
-bool WebInputElement::isReadOnly() const
-{
-    return constUnwrap<HTMLInputElement>()->readOnly();
-}
-
-bool WebInputElement::isEnabledFormControl() const
-{
-    return constUnwrap<HTMLInputElement>()->isEnabledFormControl();
+    return constUnwrap<HTMLInputElement>()->shouldAutocomplete();
 }
 
 int WebInputElement::maxLength() const
@@ -130,9 +123,9 @@ bool WebInputElement::isAutofilled() const
     return constUnwrap<HTMLInputElement>()->isAutofilled();
 }
 
-void WebInputElement::setAutofilled(bool autoFilled)
+void WebInputElement::setAutofilled(bool autofilled)
 {
-    unwrap<HTMLInputElement>()->setAutofilled(autoFilled);
+    unwrap<HTMLInputElement>()->setAutofilled(autofilled);
 }
 
 void WebInputElement::setSelectionRange(int start, int end)
@@ -155,7 +148,68 @@ bool WebInputElement::isValidValue(const WebString& value) const
     return constUnwrap<HTMLInputElement>()->isValidValue(value);
 }
 
-const int WebInputElement::defaultMaxLength = HTMLInputElement::s_maximumLength;
+bool WebInputElement::isChecked() const
+{
+    return constUnwrap<HTMLInputElement>()->checked();
+}
+
+bool WebInputElement::isSpeechInputEnabled() const
+{
+#if ENABLE(INPUT_SPEECH)
+    return constUnwrap<HTMLInputElement>()->isSpeechEnabled();
+#else
+    return false;
+#endif
+}
+
+WebInputElement::SpeechInputState WebInputElement::getSpeechInputState() const
+{
+#if ENABLE(INPUT_SPEECH)
+    RenderObject* renderer = constUnwrap<HTMLInputElement>()->renderer();
+    if (!renderer)
+        return Idle;
+
+    RenderTextControlSingleLine* control = toRenderTextControlSingleLine(renderer);
+    InputFieldSpeechButtonElement* speechButton = toInputFieldSpeechButtonElement(control->speechButtonElement());
+    if (speechButton)
+        return static_cast<WebInputElement::SpeechInputState>(speechButton->state());
+#endif
+
+    return Idle;
+}
+
+void WebInputElement::startSpeechInput()
+{
+#if ENABLE(INPUT_SPEECH)
+    RenderObject* renderer = constUnwrap<HTMLInputElement>()->renderer();
+    if (!renderer)
+        return;
+
+    RenderTextControlSingleLine* control = toRenderTextControlSingleLine(renderer);
+    InputFieldSpeechButtonElement* speechButton = toInputFieldSpeechButtonElement(control->speechButtonElement());
+    if (speechButton)
+        speechButton->startSpeechInput();
+#endif
+}
+
+void WebInputElement::stopSpeechInput()
+{
+#if ENABLE(INPUT_SPEECH)
+    RenderObject* renderer = constUnwrap<HTMLInputElement>()->renderer();
+    if (!renderer)
+        return;
+
+    RenderTextControlSingleLine* control = toRenderTextControlSingleLine(renderer);
+    InputFieldSpeechButtonElement* speechButton = toInputFieldSpeechButtonElement(control->speechButtonElement());
+    if (speechButton)
+        speechButton->stopSpeechInput();
+#endif
+}
+
+int WebInputElement::defaultMaxLength()
+{
+    return HTMLInputElement::maximumLength;
+}
 
 WebInputElement::WebInputElement(const PassRefPtr<HTMLInputElement>& elem)
     : WebFormControlElement(elem)
@@ -173,4 +227,13 @@ WebInputElement::operator PassRefPtr<HTMLInputElement>() const
     return static_cast<HTMLInputElement*>(m_private.get());
 }
 
+WebInputElement* toWebInputElement(WebElement* webElement)
+{
+    HTMLInputElement* inputElement = webElement->unwrap<Element>()->toInputElement();
+    if (!inputElement)
+        return 0;
+
+    return static_cast<WebInputElement*>(webElement);
+}
+
 } // namespace WebKit