Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1653)

Side by Side Diff: Source/core/html/shadow/TextControlInnerElements.cpp

Issue 16081007: Introduce toHTMLInputElement(Node*), and use it. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (input->maxResults() < 0) 149 if (input->maxResults() < 0)
150 return decorationId; 150 return decorationId;
151 return resultsDecorationId; 151 return resultsDecorationId;
152 } 152 }
153 return resultsDecorationId; 153 return resultsDecorationId;
154 } 154 }
155 155
156 void SearchFieldDecorationElement::defaultEventHandler(Event* event) 156 void SearchFieldDecorationElement::defaultEventHandler(Event* event)
157 { 157 {
158 // On mousedown, focus the search field 158 // On mousedown, focus the search field
159 HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowHost()); 159 HTMLInputElement* input = toHTMLInputElement(shadowHost());
160 if (input && event->type() == eventNames().mousedownEvent && event->isMouseE vent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { 160 if (input && event->type() == eventNames().mousedownEvent && event->isMouseE vent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
161 input->focus(); 161 input->focus();
162 input->select(); 162 input->select();
163 RenderSearchField* renderer = toRenderSearchField(input->renderer()); 163 RenderSearchField* renderer = toRenderSearchField(input->renderer());
164 event->setDefaultHandled(); 164 event->setDefaultHandled();
165 } 165 }
166 166
167 if (!event->defaultHandled()) 167 if (!event->defaultHandled())
168 HTMLDivElement::defaultEventHandler(event); 168 HTMLDivElement::defaultEventHandler(event);
169 } 169 }
(...skipping 28 matching lines...) Expand all
198 if (Frame* frame = document()->frame()) 198 if (Frame* frame = document()->frame())
199 frame->eventHandler()->setCapturingMouseEventsNode(0); 199 frame->eventHandler()->setCapturingMouseEventsNode(0);
200 } 200 }
201 HTMLDivElement::detach(); 201 HTMLDivElement::detach();
202 } 202 }
203 203
204 204
205 void SearchFieldCancelButtonElement::defaultEventHandler(Event* event) 205 void SearchFieldCancelButtonElement::defaultEventHandler(Event* event)
206 { 206 {
207 // If the element is visible, on mouseup, clear the value, and set selection 207 // If the element is visible, on mouseup, clear the value, and set selection
208 RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost())) ; 208 RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost()));
209 if (!input || input->isDisabledOrReadOnly()) { 209 if (!input || input->isDisabledOrReadOnly()) {
210 if (!event->defaultHandled()) 210 if (!event->defaultHandled())
211 HTMLDivElement::defaultEventHandler(event); 211 HTMLDivElement::defaultEventHandler(event);
212 return; 212 return;
213 } 213 }
214 214
215 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { 215 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
216 if (renderer() && renderer()->visibleToHitTesting()) { 216 if (renderer() && renderer()->visibleToHitTesting()) {
217 if (Frame* frame = document()->frame()) { 217 if (Frame* frame = document()->frame()) {
218 frame->eventHandler()->setCapturingMouseEventsNode(this); 218 frame->eventHandler()->setCapturingMouseEventsNode(this);
(...skipping 18 matching lines...) Expand all
237 } 237 }
238 } 238 }
239 } 239 }
240 240
241 if (!event->defaultHandled()) 241 if (!event->defaultHandled())
242 HTMLDivElement::defaultEventHandler(event); 242 HTMLDivElement::defaultEventHandler(event);
243 } 243 }
244 244
245 bool SearchFieldCancelButtonElement::willRespondToMouseClickEvents() 245 bool SearchFieldCancelButtonElement::willRespondToMouseClickEvents()
246 { 246 {
247 const HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowHost()) ; 247 const HTMLInputElement* input = toHTMLInputElement(shadowHost());
248 if (input && !input->isDisabledOrReadOnly()) 248 if (input && !input->isDisabledOrReadOnly())
249 return true; 249 return true;
250 250
251 return HTMLDivElement::willRespondToMouseClickEvents(); 251 return HTMLDivElement::willRespondToMouseClickEvents();
252 } 252 }
253 253
254 // ---------------------------- 254 // ----------------------------
255 255
256 #if ENABLE(INPUT_SPEECH) 256 #if ENABLE(INPUT_SPEECH)
257 257
(...skipping 24 matching lines...) Expand all
282 { 282 {
283 // For privacy reasons, only allow clicks directly coming from the user. 283 // For privacy reasons, only allow clicks directly coming from the user.
284 if (!ScriptController::processingUserGesture()) { 284 if (!ScriptController::processingUserGesture()) {
285 HTMLDivElement::defaultEventHandler(event); 285 HTMLDivElement::defaultEventHandler(event);
286 return; 286 return;
287 } 287 }
288 288
289 // The call to focus() below dispatches a focus event, and an event handler in the page might 289 // The call to focus() below dispatches a focus event, and an event handler in the page might
290 // remove the input element from DOM. To make sure it remains valid until we finish our work 290 // remove the input element from DOM. To make sure it remains valid until we finish our work
291 // here, we take a temporary reference. 291 // here, we take a temporary reference.
292 RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost())) ; 292 RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost()));
293 293
294 if (!input || input->isDisabledOrReadOnly()) { 294 if (!input || input->isDisabledOrReadOnly()) {
295 if (!event->defaultHandled()) 295 if (!event->defaultHandled())
296 HTMLDivElement::defaultEventHandler(event); 296 HTMLDivElement::defaultEventHandler(event);
297 return; 297 return;
298 } 298 }
299 299
300 // On mouse down, select the text and set focus. 300 // On mouse down, select the text and set focus.
301 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { 301 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
302 if (renderer() && renderer()->visibleToHitTesting()) { 302 if (renderer() && renderer()->visibleToHitTesting()) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 334 }
335 event->setDefaultHandled(); 335 event->setDefaultHandled();
336 } 336 }
337 337
338 if (!event->defaultHandled()) 338 if (!event->defaultHandled())
339 HTMLDivElement::defaultEventHandler(event); 339 HTMLDivElement::defaultEventHandler(event);
340 } 340 }
341 341
342 bool InputFieldSpeechButtonElement::willRespondToMouseClickEvents() 342 bool InputFieldSpeechButtonElement::willRespondToMouseClickEvents()
343 { 343 {
344 const HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowHost()) ; 344 const HTMLInputElement* input = toHTMLInputElement(shadowHost());
345 if (input && !input->isDisabledOrReadOnly()) 345 if (input && !input->isDisabledOrReadOnly())
346 return true; 346 return true;
347 347
348 return HTMLDivElement::willRespondToMouseClickEvents(); 348 return HTMLDivElement::willRespondToMouseClickEvents();
349 } 349 }
350 350
351 void InputFieldSpeechButtonElement::setState(SpeechInputState state) 351 void InputFieldSpeechButtonElement::setState(SpeechInputState state)
352 { 352 {
353 if (m_state != state) { 353 if (m_state != state) {
354 m_state = state; 354 m_state = state;
(...skipping 16 matching lines...) Expand all
371 setState(Idle); 371 setState(Idle);
372 } 372 }
373 373
374 void InputFieldSpeechButtonElement::setRecognitionResult(int, const SpeechInputR esultArray& results) 374 void InputFieldSpeechButtonElement::setRecognitionResult(int, const SpeechInputR esultArray& results)
375 { 375 {
376 m_results = results; 376 m_results = results;
377 377
378 // The call to setValue() below dispatches an event, and an event handler in the page might 378 // The call to setValue() below dispatches an event, and an event handler in the page might
379 // remove the input element from DOM. To make sure it remains valid until we finish our work 379 // remove the input element from DOM. To make sure it remains valid until we finish our work
380 // here, we take a temporary reference. 380 // here, we take a temporary reference.
381 RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowHost())) ; 381 RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost()));
382 if (!input || input->isDisabledOrReadOnly()) 382 if (!input || input->isDisabledOrReadOnly())
383 return; 383 return;
384 384
385 RefPtr<InputFieldSpeechButtonElement> holdRefButton(this); 385 RefPtr<InputFieldSpeechButtonElement> holdRefButton(this);
386 if (document() && document()->domWindow()) { 386 if (document() && document()->domWindow()) {
387 // Call selectionChanged, causing the element to cache the selection, 387 // Call selectionChanged, causing the element to cache the selection,
388 // so that the text event inserts the text in this element even if 388 // so that the text event inserts the text in this element even if
389 // focus has moved away from it. 389 // focus has moved away from it.
390 input->selectionChanged(false); 390 input->selectionChanged(false);
391 input->dispatchEvent(TextEvent::create(document()->domWindow(), results. isEmpty() ? "" : results[0]->utterance(), TextEventInputOther)); 391 input->dispatchEvent(TextEvent::create(document()->domWindow(), results. isEmpty() ? "" : results[0]->utterance(), TextEventInputOther));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 424 }
425 425
426 HTMLDivElement::detach(); 426 HTMLDivElement::detach();
427 } 427 }
428 428
429 void InputFieldSpeechButtonElement::startSpeechInput() 429 void InputFieldSpeechButtonElement::startSpeechInput()
430 { 430 {
431 if (m_state != Idle) 431 if (m_state != Idle)
432 return; 432 return;
433 433
434 RefPtr<HTMLInputElement> input = static_cast<HTMLInputElement*>(shadowHost() ); 434 RefPtr<HTMLInputElement> input = toHTMLInputElement(shadowHost());
435 AtomicString language = input->computeInheritedLanguage(); 435 AtomicString language = input->computeInheritedLanguage();
436 String grammar = input->getAttribute(webkitgrammarAttr); 436 String grammar = input->getAttribute(webkitgrammarAttr);
437 IntRect rect = document()->view()->contentsToRootView(pixelSnappedBoundingBo x()); 437 IntRect rect = document()->view()->contentsToRootView(pixelSnappedBoundingBo x());
438 if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, d ocument()->securityOrigin())) 438 if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, d ocument()->securityOrigin()))
439 setState(Recording); 439 setState(Recording);
440 } 440 }
441 441
442 void InputFieldSpeechButtonElement::stopSpeechInput() 442 void InputFieldSpeechButtonElement::stopSpeechInput()
443 { 443 {
444 if (m_state == Recording) 444 if (m_state == Recording)
445 speechInput()->stopRecording(m_listenerId); 445 speechInput()->stopRecording(m_listenerId);
446 } 446 }
447 447
448 const AtomicString& InputFieldSpeechButtonElement::shadowPseudoId() const 448 const AtomicString& InputFieldSpeechButtonElement::shadowPseudoId() const
449 { 449 {
450 DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-input-speech-button", AtomicString::ConstructFromLiteral)); 450 DEFINE_STATIC_LOCAL(AtomicString, pseudoId, ("-webkit-input-speech-button", AtomicString::ConstructFromLiteral));
451 return pseudoId; 451 return pseudoId;
452 } 452 }
453 453
454 #endif // ENABLE(INPUT_SPEECH) 454 #endif // ENABLE(INPUT_SPEECH)
455 455
456 } 456 }
OLDNEW
« no previous file with comments | « Source/core/html/RadioInputType.cpp ('k') | Source/core/html/shadow/TextFieldDecorationElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698