| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 202 } |
| 203 | 203 |
| 204 PassRefPtr<SearchFieldCancelButtonElement> SearchFieldCancelButtonElement::creat
e(Document& document) | 204 PassRefPtr<SearchFieldCancelButtonElement> SearchFieldCancelButtonElement::creat
e(Document& document) |
| 205 { | 205 { |
| 206 RefPtr<SearchFieldCancelButtonElement> element = adoptRef(new SearchFieldCan
celButtonElement(document)); | 206 RefPtr<SearchFieldCancelButtonElement> element = adoptRef(new SearchFieldCan
celButtonElement(document)); |
| 207 element->setPart(AtomicString("-webkit-search-cancel-button", AtomicString::
ConstructFromLiteral)); | 207 element->setPart(AtomicString("-webkit-search-cancel-button", AtomicString::
ConstructFromLiteral)); |
| 208 element->setAttribute(idAttr, ShadowElementNames::clearButton()); | 208 element->setAttribute(idAttr, ShadowElementNames::clearButton()); |
| 209 return element.release(); | 209 return element.release(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void SearchFieldCancelButtonElement::detach(const AttachContext& context) | 212 void SearchFieldCancelButtonElement::destroyRenderTree(const AttachContext& cont
ext) |
| 213 { | 213 { |
| 214 if (m_capturing) { | 214 if (m_capturing) { |
| 215 if (Frame* frame = document().frame()) | 215 if (Frame* frame = document().frame()) |
| 216 frame->eventHandler()->setCapturingMouseEventsNode(0); | 216 frame->eventHandler()->setCapturingMouseEventsNode(0); |
| 217 } | 217 } |
| 218 HTMLDivElement::detach(context); | 218 HTMLDivElement::destroyRenderTree(context); |
| 219 } | 219 } |
| 220 | 220 |
| 221 | 221 |
| 222 void SearchFieldCancelButtonElement::defaultEventHandler(Event* event) | 222 void SearchFieldCancelButtonElement::defaultEventHandler(Event* event) |
| 223 { | 223 { |
| 224 // If the element is visible, on mouseup, clear the value, and set selection | 224 // If the element is visible, on mouseup, clear the value, and set selection |
| 225 RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost())); | 225 RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost())); |
| 226 if (!input || input->isDisabledOrReadOnly()) { | 226 if (!input || input->isDisabledOrReadOnly()) { |
| 227 if (!event->defaultHandled()) | 227 if (!event->defaultHandled()) |
| 228 HTMLDivElement::defaultEventHandler(event); | 228 HTMLDivElement::defaultEventHandler(event); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 // This event is sent after the text event so the website can perform action
s using the input field content immediately. | 414 // This event is sent after the text event so the website can perform action
s using the input field content immediately. |
| 415 // It provides alternative recognition hypotheses and notifies that the resu
lts come from speech input. | 415 // It provides alternative recognition hypotheses and notifies that the resu
lts come from speech input. |
| 416 input->dispatchEvent(SpeechInputEvent::create(eventNames().webkitspeechchang
eEvent, results)); | 416 input->dispatchEvent(SpeechInputEvent::create(eventNames().webkitspeechchang
eEvent, results)); |
| 417 | 417 |
| 418 // Check before accessing the renderer as the above event could have potenti
ally turned off | 418 // Check before accessing the renderer as the above event could have potenti
ally turned off |
| 419 // speech in the input element, hence removing this button and renderer from
the hierarchy. | 419 // speech in the input element, hence removing this button and renderer from
the hierarchy. |
| 420 if (renderer()) | 420 if (renderer()) |
| 421 renderer()->repaint(); | 421 renderer()->repaint(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 void InputFieldSpeechButtonElement::attach(const AttachContext& context) | 424 void InputFieldSpeechButtonElement::createRenderTree(const AttachContext& contex
t) |
| 425 { | 425 { |
| 426 ASSERT(!m_listenerId); | 426 ASSERT(!m_listenerId); |
| 427 if (SpeechInput* input = SpeechInput::from(document().page())) | 427 if (SpeechInput* input = SpeechInput::from(document().page())) |
| 428 m_listenerId = input->registerListener(this); | 428 m_listenerId = input->registerListener(this); |
| 429 HTMLDivElement::attach(context); | 429 HTMLDivElement::createRenderTree(context); |
| 430 } | 430 } |
| 431 | 431 |
| 432 void InputFieldSpeechButtonElement::detach(const AttachContext& context) | 432 void InputFieldSpeechButtonElement::destroyRenderTree(const AttachContext& conte
xt) |
| 433 { | 433 { |
| 434 if (m_capturing) { | 434 if (m_capturing) { |
| 435 if (Frame* frame = document().frame()) | 435 if (Frame* frame = document().frame()) |
| 436 frame->eventHandler()->setCapturingMouseEventsNode(0); | 436 frame->eventHandler()->setCapturingMouseEventsNode(0); |
| 437 } | 437 } |
| 438 | 438 |
| 439 if (m_listenerId) { | 439 if (m_listenerId) { |
| 440 if (m_state != Idle) | 440 if (m_state != Idle) |
| 441 speechInput()->cancelRecognition(m_listenerId); | 441 speechInput()->cancelRecognition(m_listenerId); |
| 442 speechInput()->unregisterListener(m_listenerId); | 442 speechInput()->unregisterListener(m_listenerId); |
| 443 m_listenerId = 0; | 443 m_listenerId = 0; |
| 444 } | 444 } |
| 445 | 445 |
| 446 HTMLDivElement::detach(context); | 446 HTMLDivElement::destroyRenderTree(context); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void InputFieldSpeechButtonElement::startSpeechInput() | 449 void InputFieldSpeechButtonElement::startSpeechInput() |
| 450 { | 450 { |
| 451 if (m_state != Idle) | 451 if (m_state != Idle) |
| 452 return; | 452 return; |
| 453 | 453 |
| 454 RefPtr<HTMLInputElement> input = toHTMLInputElement(shadowHost()); | 454 RefPtr<HTMLInputElement> input = toHTMLInputElement(shadowHost()); |
| 455 AtomicString language = input->computeInheritedLanguage(); | 455 AtomicString language = input->computeInheritedLanguage(); |
| 456 String grammar = input->getAttribute(webkitgrammarAttr); | 456 String grammar = input->getAttribute(webkitgrammarAttr); |
| 457 IntRect rect = document().view()->contentsToRootView(pixelSnappedBoundingBox
()); | 457 IntRect rect = document().view()->contentsToRootView(pixelSnappedBoundingBox
()); |
| 458 if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, d
ocument().securityOrigin())) | 458 if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, d
ocument().securityOrigin())) |
| 459 setState(Recording); | 459 setState(Recording); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void InputFieldSpeechButtonElement::stopSpeechInput() | 462 void InputFieldSpeechButtonElement::stopSpeechInput() |
| 463 { | 463 { |
| 464 if (m_state == Recording) | 464 if (m_state == Recording) |
| 465 speechInput()->stopRecording(m_listenerId); | 465 speechInput()->stopRecording(m_listenerId); |
| 466 } | 466 } |
| 467 #endif // ENABLE(INPUT_SPEECH) | 467 #endif // ENABLE(INPUT_SPEECH) |
| 468 | 468 |
| 469 } | 469 } |
| OLD | NEW |