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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 139 } |
140 | 140 |
141 const AtomicString& SearchFieldResultsButtonElement::shadowPseudoId() const | 141 const AtomicString& SearchFieldResultsButtonElement::shadowPseudoId() const |
142 { | 142 { |
143 DEFINE_STATIC_LOCAL(AtomicString, resultsId, ("-webkit-search-results-button
", AtomicString::ConstructFromLiteral)); | 143 DEFINE_STATIC_LOCAL(AtomicString, resultsId, ("-webkit-search-results-button
", AtomicString::ConstructFromLiteral)); |
144 DEFINE_STATIC_LOCAL(AtomicString, resultsDecorationId, ("-webkit-search-resu
lts-decoration", AtomicString::ConstructFromLiteral)); | 144 DEFINE_STATIC_LOCAL(AtomicString, resultsDecorationId, ("-webkit-search-resu
lts-decoration", AtomicString::ConstructFromLiteral)); |
145 DEFINE_STATIC_LOCAL(AtomicString, decorationId, ("-webkit-search-decoration"
, AtomicString::ConstructFromLiteral)); | 145 DEFINE_STATIC_LOCAL(AtomicString, decorationId, ("-webkit-search-decoration"
, AtomicString::ConstructFromLiteral)); |
146 Element* host = shadowHost(); | 146 Element* host = shadowHost(); |
147 if (!host) | 147 if (!host) |
148 return resultsId; | 148 return resultsId; |
149 if (HTMLInputElement* input = host->toInputElement()) { | 149 if (Handle<HTMLInputElement> input = host->toInputElement()) { |
150 if (input->maxResults() < 0) | 150 if (input->maxResults() < 0) |
151 return decorationId; | 151 return decorationId; |
152 if (input->maxResults() > 0) | 152 if (input->maxResults() > 0) |
153 return resultsId; | 153 return resultsId; |
154 return resultsDecorationId; | 154 return resultsDecorationId; |
155 } | 155 } |
156 return resultsId; | 156 return resultsId; |
157 } | 157 } |
158 | 158 |
159 void SearchFieldResultsButtonElement::defaultEventHandler(Event* event) | 159 void SearchFieldResultsButtonElement::defaultEventHandler(Event* event) |
160 { | 160 { |
161 // On mousedown, bring up a menu, if needed | 161 // On mousedown, bring up a menu, if needed |
162 HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowHost()); | 162 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost()))
; |
163 if (input && event->type() == eventNames().mousedownEvent && event->isMouseE
vent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { | 163 if (input && event->type() == eventNames().mousedownEvent && event->isMouseE
vent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { |
164 input->focus(); | 164 input->focus(); |
165 input->select(); | 165 input->select(); |
166 RenderSearchField* renderer = toRenderSearchField(input->renderer()); | 166 RenderSearchField* renderer = toRenderSearchField(input->renderer()); |
167 if (renderer->popupIsVisible()) | 167 if (renderer->popupIsVisible()) |
168 renderer->hidePopup(); | 168 renderer->hidePopup(); |
169 else if (input->maxResults() > 0) | 169 else if (input->maxResults() > 0) |
170 renderer->showPopup(); | 170 renderer->showPopup(); |
171 event->setDefaultHandled(); | 171 event->setDefaultHandled(); |
172 } | 172 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (Frame* frame = document()->frame()) | 205 if (Frame* frame = document()->frame()) |
206 frame->eventHandler()->setCapturingMouseEventsNode(0); | 206 frame->eventHandler()->setCapturingMouseEventsNode(0); |
207 } | 207 } |
208 HTMLDivElement::detach(); | 208 HTMLDivElement::detach(); |
209 } | 209 } |
210 | 210 |
211 | 211 |
212 void SearchFieldCancelButtonElement::defaultEventHandler(Event* event) | 212 void SearchFieldCancelButtonElement::defaultEventHandler(Event* event) |
213 { | 213 { |
214 // If the element is visible, on mouseup, clear the value, and set selection | 214 // If the element is visible, on mouseup, clear the value, and set selection |
215 RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost()))
; | 215 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost()))
; |
216 if (!input || input->isDisabledOrReadOnly()) { | 216 if (!input || input->isDisabledOrReadOnly()) { |
217 if (!event->defaultHandled()) | 217 if (!event->defaultHandled()) |
218 HTMLDivElement::defaultEventHandler(event); | 218 HTMLDivElement::defaultEventHandler(event); |
219 return; | 219 return; |
220 } | 220 } |
221 | 221 |
222 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() &&
static_cast<MouseEvent*>(event)->button() == LeftButton) { | 222 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() &&
static_cast<MouseEvent*>(event)->button() == LeftButton) { |
223 if (renderer() && renderer()->visibleToHitTesting()) { | 223 if (renderer() && renderer()->visibleToHitTesting()) { |
224 if (Frame* frame = document()->frame()) { | 224 if (Frame* frame = document()->frame()) { |
225 frame->eventHandler()->setCapturingMouseEventsNode(this); | 225 frame->eventHandler()->setCapturingMouseEventsNode(this); |
(...skipping 18 matching lines...) Expand all Loading... |
244 } | 244 } |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 if (!event->defaultHandled()) | 248 if (!event->defaultHandled()) |
249 HTMLDivElement::defaultEventHandler(event); | 249 HTMLDivElement::defaultEventHandler(event); |
250 } | 250 } |
251 | 251 |
252 bool SearchFieldCancelButtonElement::willRespondToMouseClickEvents() | 252 bool SearchFieldCancelButtonElement::willRespondToMouseClickEvents() |
253 { | 253 { |
254 const HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowHost())
; | 254 Handle<const HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHo
st())); |
255 if (input && !input->isDisabledOrReadOnly()) | 255 if (input && !input->isDisabledOrReadOnly()) |
256 return true; | 256 return true; |
257 | 257 |
258 return HTMLDivElement::willRespondToMouseClickEvents(); | 258 return HTMLDivElement::willRespondToMouseClickEvents(); |
259 } | 259 } |
260 | 260 |
261 // ---------------------------- | 261 // ---------------------------- |
262 | 262 |
263 #if ENABLE(INPUT_SPEECH) | 263 #if ENABLE(INPUT_SPEECH) |
264 | 264 |
(...skipping 24 matching lines...) Expand all Loading... |
289 { | 289 { |
290 // For privacy reasons, only allow clicks directly coming from the user. | 290 // For privacy reasons, only allow clicks directly coming from the user. |
291 if (!ScriptController::processingUserGesture()) { | 291 if (!ScriptController::processingUserGesture()) { |
292 HTMLDivElement::defaultEventHandler(event); | 292 HTMLDivElement::defaultEventHandler(event); |
293 return; | 293 return; |
294 } | 294 } |
295 | 295 |
296 // The call to focus() below dispatches a focus event, and an event handler
in the page might | 296 // The call to focus() below dispatches a focus event, and an event handler
in the page might |
297 // remove the input element from DOM. To make sure it remains valid until we
finish our work | 297 // remove the input element from DOM. To make sure it remains valid until we
finish our work |
298 // here, we take a temporary reference. | 298 // here, we take a temporary reference. |
299 RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost()))
; | 299 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost()))
; |
300 | 300 |
301 if (!input || input->isDisabledOrReadOnly()) { | 301 if (!input || input->isDisabledOrReadOnly()) { |
302 if (!event->defaultHandled()) | 302 if (!event->defaultHandled()) |
303 HTMLDivElement::defaultEventHandler(event); | 303 HTMLDivElement::defaultEventHandler(event); |
304 return; | 304 return; |
305 } | 305 } |
306 | 306 |
307 // On mouse down, select the text and set focus. | 307 // On mouse down, select the text and set focus. |
308 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() &&
static_cast<MouseEvent*>(event)->button() == LeftButton) { | 308 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() &&
static_cast<MouseEvent*>(event)->button() == LeftButton) { |
309 if (renderer() && renderer()->visibleToHitTesting()) { | 309 if (renderer() && renderer()->visibleToHitTesting()) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 341 } |
342 event->setDefaultHandled(); | 342 event->setDefaultHandled(); |
343 } | 343 } |
344 | 344 |
345 if (!event->defaultHandled()) | 345 if (!event->defaultHandled()) |
346 HTMLDivElement::defaultEventHandler(event); | 346 HTMLDivElement::defaultEventHandler(event); |
347 } | 347 } |
348 | 348 |
349 bool InputFieldSpeechButtonElement::willRespondToMouseClickEvents() | 349 bool InputFieldSpeechButtonElement::willRespondToMouseClickEvents() |
350 { | 350 { |
351 const HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowHost())
; | 351 Handle<const HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHo
st())); |
352 if (input && !input->isDisabledOrReadOnly()) | 352 if (input && !input->isDisabledOrReadOnly()) |
353 return true; | 353 return true; |
354 | 354 |
355 return HTMLDivElement::willRespondToMouseClickEvents(); | 355 return HTMLDivElement::willRespondToMouseClickEvents(); |
356 } | 356 } |
357 | 357 |
358 void InputFieldSpeechButtonElement::setState(SpeechInputState state) | 358 void InputFieldSpeechButtonElement::setState(SpeechInputState state) |
359 { | 359 { |
360 if (m_state != state) { | 360 if (m_state != state) { |
361 m_state = state; | 361 m_state = state; |
(...skipping 16 matching lines...) Expand all Loading... |
378 setState(Idle); | 378 setState(Idle); |
379 } | 379 } |
380 | 380 |
381 void InputFieldSpeechButtonElement::setRecognitionResult(int, const SpeechInputR
esultArray& results) | 381 void InputFieldSpeechButtonElement::setRecognitionResult(int, const SpeechInputR
esultArray& results) |
382 { | 382 { |
383 m_results = results; | 383 m_results = results; |
384 | 384 |
385 // The call to setValue() below dispatches an event, and an event handler in
the page might | 385 // The call to setValue() below dispatches an event, and an event handler in
the page might |
386 // remove the input element from DOM. To make sure it remains valid until we
finish our work | 386 // remove the input element from DOM. To make sure it remains valid until we
finish our work |
387 // here, we take a temporary reference. | 387 // here, we take a temporary reference. |
388 RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost()))
; | 388 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost()))
; |
389 if (!input || input->isDisabledOrReadOnly()) | 389 if (!input || input->isDisabledOrReadOnly()) |
390 return; | 390 return; |
391 | 391 |
392 RefPtr<InputFieldSpeechButtonElement> holdRefButton(this); | 392 RefPtr<InputFieldSpeechButtonElement> holdRefButton(this); |
393 if (document() && document()->domWindow()) { | 393 if (document() && document()->domWindow()) { |
394 // Call selectionChanged, causing the element to cache the selection, | 394 // Call selectionChanged, causing the element to cache the selection, |
395 // so that the text event inserts the text in this element even if | 395 // so that the text event inserts the text in this element even if |
396 // focus has moved away from it. | 396 // focus has moved away from it. |
397 input->selectionChanged(false); | 397 input->selectionChanged(false); |
398 input->dispatchEvent(TextEvent::create(document()->domWindow(), results.
isEmpty() ? "" : results[0]->utterance(), TextEventInputOther)); | 398 input->dispatchEvent(TextEvent::create(document()->domWindow(), results.
isEmpty() ? "" : results[0]->utterance(), TextEventInputOther)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 } | 431 } |
432 | 432 |
433 HTMLDivElement::detach(); | 433 HTMLDivElement::detach(); |
434 } | 434 } |
435 | 435 |
436 void InputFieldSpeechButtonElement::startSpeechInput() | 436 void InputFieldSpeechButtonElement::startSpeechInput() |
437 { | 437 { |
438 if (m_state != Idle) | 438 if (m_state != Idle) |
439 return; | 439 return; |
440 | 440 |
441 RefPtr<HTMLInputElement> input = static_cast<HTMLInputElement*>(shadowHost()
); | 441 Handle<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost()))
; |
442 AtomicString language = input->computeInheritedLanguage(); | 442 AtomicString language = input->computeInheritedLanguage(); |
443 String grammar = input->getAttribute(webkitgrammarAttr); | 443 String grammar = input->getAttribute(webkitgrammarAttr); |
444 IntRect rect = document()->view()->contentsToRootView(pixelSnappedBoundingBo
x()); | 444 IntRect rect = document()->view()->contentsToRootView(pixelSnappedBoundingBo
x()); |
445 if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, d
ocument()->securityOrigin())) | 445 if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, d
ocument()->securityOrigin())) |
446 setState(Recording); | 446 setState(Recording); |
447 } | 447 } |
448 | 448 |
449 void InputFieldSpeechButtonElement::stopSpeechInput() | 449 void InputFieldSpeechButtonElement::stopSpeechInput() |
450 { | 450 { |
451 if (m_state == Recording) | 451 if (m_state == Recording) |
452 speechInput()->stopRecording(m_listenerId); | 452 speechInput()->stopRecording(m_listenerId); |
453 } | 453 } |
454 | 454 |
455 const AtomicString& InputFieldSpeechButtonElement::shadowPseudoId() const | 455 const AtomicString& InputFieldSpeechButtonElement::shadowPseudoId() const |
456 { | 456 { |
457 DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-input-speech-button",
AtomicString::ConstructFromLiteral)); | 457 DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-input-speech-button",
AtomicString::ConstructFromLiteral)); |
458 return pseudoId; | 458 return pseudoId; |
459 } | 459 } |
460 | 460 |
461 #endif // ENABLE(INPUT_SPEECH) | 461 #endif // ENABLE(INPUT_SPEECH) |
462 | 462 |
463 } | 463 } |
OLD | NEW |