Source/WebCore: Add API functions to enable starting and stopping speech input,
[WebKit-https.git] / Source / WebKit / chromium / src / WebInputElement.cpp
index 5e7a1cf..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>
 
@@ -150,6 +153,59 @@ 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;