Changeset 63315 in webkit


Ignore:
Timestamp:
Jul 14, 2010 6:57:48 AM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-07-14 Satish Sampath <satish@chromium.org>

Reviewed by Kent Tamura.

Invoke speech recognition when user clicks on the speech button of input elements.
http://bugs.webkit.org/show_bug.cgi?id=42047

No new tests, the relevant LayoutTestController bindings will be added in a subsequent patch.

  • rendering/TextControlInnerElements.cpp: (WebCore::InputFieldSpeechButtonElement::InputFieldSpeechButtonElement): (WebCore::InputFieldSpeechButtonElement::defaultEventHandler): Added click handling. (WebCore::InputFieldSpeechButtonElement::speechInput): (WebCore::InputFieldSpeechButtonElement::recordingComplete): Callback to indicate recording progress. (WebCore::InputFieldSpeechButtonElement::setRecognitionResult): Callback to receive recognized text. (WebCore::InputFieldSpeechButtonElement::detach):
  • rendering/TextControlInnerElements.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r63314 r63315  
     12010-07-14  Satish Sampath  <satish@chromium.org>
     2
     3        Reviewed by Kent Tamura.
     4
     5        Invoke speech recognition when user clicks on the speech button of input elements.
     6        http://bugs.webkit.org/show_bug.cgi?id=42047
     7
     8        No new tests, the relevant LayoutTestController bindings will be added in a subsequent patch.
     9
     10        * rendering/TextControlInnerElements.cpp:
     11        (WebCore::InputFieldSpeechButtonElement::InputFieldSpeechButtonElement):
     12        (WebCore::InputFieldSpeechButtonElement::defaultEventHandler): Added click handling.
     13        (WebCore::InputFieldSpeechButtonElement::speechInput):
     14        (WebCore::InputFieldSpeechButtonElement::recordingComplete): Callback to indicate recording progress.
     15        (WebCore::InputFieldSpeechButtonElement::setRecognitionResult): Callback to receive recognized text.
     16        (WebCore::InputFieldSpeechButtonElement::detach):
     17        * rendering/TextControlInnerElements.h:
     18
    1192010-07-14  Sheriff Bot  <webkit.review.bot@gmail.com>
    220
  • trunk/WebCore/rendering/TextControlInnerElements.cpp

    r63286 r63315  
    3737#include "HTMLTextAreaElement.h"
    3838#include "MouseEvent.h"
     39#include "Page.h"
    3940#include "RenderLayer.h"
    4041#include "RenderTextControlSingleLine.h"
     42#include "SpeechInput.h"
    4143
    4244namespace WebCore {
     
    329331inline InputFieldSpeechButtonElement::InputFieldSpeechButtonElement(Document* document)
    330332    : TextControlInnerElement(document)
     333    , m_capturing(false)
    331334{
    332335}
     
    339342void InputFieldSpeechButtonElement::defaultEventHandler(Event* event)
    340343{
    341     // FIXME: Start speech recognition here.
    342     HTMLDivElement::defaultEventHandler(event);
     344    // On mouse down, select the text and set focus.
     345    HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
     346    if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
     347        if (renderer() && renderer()->visibleToHitTesting()) {
     348            if (Frame* frame = document()->frame()) {
     349                frame->eventHandler()->setCapturingMouseEventsNode(this);
     350                m_capturing = true;
     351            }
     352        }
     353        // The call to focus() below dispatches a focus event, and an event handler in the page might
     354        // remove the input element from DOM. To make sure it remains valid until we finish our work
     355        // here, we take a temporary reference.
     356        RefPtr<HTMLInputElement> holdRef(input);
     357        input->focus();
     358        input->select();
     359        event->setDefaultHandled();
     360    }
     361    // On mouse up, start speech recognition.
     362    if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
     363        if (m_capturing && renderer() && renderer()->visibleToHitTesting()) {
     364            if (Frame* frame = document()->frame()) {
     365                frame->eventHandler()->setCapturingMouseEventsNode(0);
     366                m_capturing = false;
     367            }
     368            if (hovered()) {
     369                speechInput()->startRecognition();
     370                event->setDefaultHandled();
     371            }
     372        }
     373    }
     374
     375    if (!event->defaultHandled())
     376        HTMLDivElement::defaultEventHandler(event);
     377}
     378
     379SpeechInput* InputFieldSpeechButtonElement::speechInput()
     380{
     381    if (!m_speechInput)
     382        m_speechInput.set(new SpeechInput(document()->page()->speechInputClient(), this));
     383    return m_speechInput.get();
     384}
     385
     386void InputFieldSpeechButtonElement::recordingComplete()
     387{
     388    // FIXME: Add UI feedback here to indicate that audio recording stopped and recognition is
     389    // in progress.
     390}
     391
     392void InputFieldSpeechButtonElement::setRecognitionResult(const String& result)
     393{
     394    HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
     395    // The call to setValue() below dispatches an event, and an event handler in the page might
     396    // remove the input element from DOM. To make sure it remains valid until we finish our work
     397    // here, we take a temporary reference.
     398    RefPtr<HTMLInputElement> holdRef(input);
     399    input->setValue(result);
     400    input->dispatchFormControlChangeEvent();
     401    renderer()->repaint();
     402}
     403
     404void InputFieldSpeechButtonElement::detach()
     405{
     406    if (m_capturing) {
     407        if (Frame* frame = document()->frame())
     408            frame->eventHandler()->setCapturingMouseEventsNode(0);     
     409    }
     410    TextControlInnerElement::detach();
    343411}
    344412
  • trunk/WebCore/rendering/TextControlInnerElements.h

    r63286 r63315  
    2929
    3030#include "HTMLDivElement.h"
     31#include "SpeechInputListener.h"
    3132
    3233namespace WebCore {
    3334
     35class SpeechInput;
    3436class String;
    3537
     
    110112#if ENABLE(INPUT_SPEECH)
    111113
    112 class InputFieldSpeechButtonElement : public TextControlInnerElement {
     114class InputFieldSpeechButtonElement
     115    : public TextControlInnerElement,
     116      public SpeechInputListener {
    113117public:
    114118    static PassRefPtr<InputFieldSpeechButtonElement> create(Document*);
     
    116120    virtual void defaultEventHandler(Event*);
    117121
     122    // SpeechInputListener methods.
     123    void recordingComplete();
     124    void setRecognitionResult(const String& result);
     125
    118126private:
    119127    InputFieldSpeechButtonElement(Document*);
     128    virtual void detach();
     129    SpeechInput* speechInput();
     130
     131    bool m_capturing;
     132    OwnPtr<SpeechInput> m_speechInput;
    120133};
    121134
Note: See TracChangeset for help on using the changeset viewer.