Changeset 63315 in webkit
- Timestamp:
- Jul 14, 2010 6:57:48 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r63314 r63315 1 2010-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 1 19 2010-07-14 Sheriff Bot <webkit.review.bot@gmail.com> 2 20 -
trunk/WebCore/rendering/TextControlInnerElements.cpp
r63286 r63315 37 37 #include "HTMLTextAreaElement.h" 38 38 #include "MouseEvent.h" 39 #include "Page.h" 39 40 #include "RenderLayer.h" 40 41 #include "RenderTextControlSingleLine.h" 42 #include "SpeechInput.h" 41 43 42 44 namespace WebCore { … … 329 331 inline InputFieldSpeechButtonElement::InputFieldSpeechButtonElement(Document* document) 330 332 : TextControlInnerElement(document) 333 , m_capturing(false) 331 334 { 332 335 } … … 339 342 void InputFieldSpeechButtonElement::defaultEventHandler(Event* event) 340 343 { 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 379 SpeechInput* InputFieldSpeechButtonElement::speechInput() 380 { 381 if (!m_speechInput) 382 m_speechInput.set(new SpeechInput(document()->page()->speechInputClient(), this)); 383 return m_speechInput.get(); 384 } 385 386 void InputFieldSpeechButtonElement::recordingComplete() 387 { 388 // FIXME: Add UI feedback here to indicate that audio recording stopped and recognition is 389 // in progress. 390 } 391 392 void 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 404 void InputFieldSpeechButtonElement::detach() 405 { 406 if (m_capturing) { 407 if (Frame* frame = document()->frame()) 408 frame->eventHandler()->setCapturingMouseEventsNode(0); 409 } 410 TextControlInnerElement::detach(); 343 411 } 344 412 -
trunk/WebCore/rendering/TextControlInnerElements.h
r63286 r63315 29 29 30 30 #include "HTMLDivElement.h" 31 #include "SpeechInputListener.h" 31 32 32 33 namespace WebCore { 33 34 35 class SpeechInput; 34 36 class String; 35 37 … … 110 112 #if ENABLE(INPUT_SPEECH) 111 113 112 class InputFieldSpeechButtonElement : public TextControlInnerElement { 114 class InputFieldSpeechButtonElement 115 : public TextControlInnerElement, 116 public SpeechInputListener { 113 117 public: 114 118 static PassRefPtr<InputFieldSpeechButtonElement> create(Document*); … … 116 120 virtual void defaultEventHandler(Event*); 117 121 122 // SpeechInputListener methods. 123 void recordingComplete(); 124 void setRecognitionResult(const String& result); 125 118 126 private: 119 127 InputFieldSpeechButtonElement(Document*); 128 virtual void detach(); 129 SpeechInput* speechInput(); 130 131 bool m_capturing; 132 OwnPtr<SpeechInput> m_speechInput; 120 133 }; 121 134
Note: See TracChangeset
for help on using the changeset viewer.