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

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

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 { 201 {
202 RefPtr<SearchFieldCancelButtonElement> element = adoptRef(new SearchFieldCan celButtonElement(document)); 202 RefPtr<SearchFieldCancelButtonElement> element = adoptRef(new SearchFieldCan celButtonElement(document));
203 element->setPart(AtomicString("-webkit-search-cancel-button", AtomicString:: ConstructFromLiteral)); 203 element->setPart(AtomicString("-webkit-search-cancel-button", AtomicString:: ConstructFromLiteral));
204 element->setAttribute(idAttr, ShadowElementNames::clearButton()); 204 element->setAttribute(idAttr, ShadowElementNames::clearButton());
205 return element.release(); 205 return element.release();
206 } 206 }
207 207
208 void SearchFieldCancelButtonElement::detach(const AttachContext& context) 208 void SearchFieldCancelButtonElement::detach(const AttachContext& context)
209 { 209 {
210 if (m_capturing) { 210 if (m_capturing) {
211 if (Frame* frame = document()->frame()) 211 if (Frame* frame = document().frame())
212 frame->eventHandler()->setCapturingMouseEventsNode(0); 212 frame->eventHandler()->setCapturingMouseEventsNode(0);
213 } 213 }
214 HTMLDivElement::detach(context); 214 HTMLDivElement::detach(context);
215 } 215 }
216 216
217 217
218 void SearchFieldCancelButtonElement::defaultEventHandler(Event* event) 218 void SearchFieldCancelButtonElement::defaultEventHandler(Event* event)
219 { 219 {
220 // If the element is visible, on mouseup, clear the value, and set selection 220 // If the element is visible, on mouseup, clear the value, and set selection
221 RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost())); 221 RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost()));
222 if (!input || input->isDisabledOrReadOnly()) { 222 if (!input || input->isDisabledOrReadOnly()) {
223 if (!event->defaultHandled()) 223 if (!event->defaultHandled())
224 HTMLDivElement::defaultEventHandler(event); 224 HTMLDivElement::defaultEventHandler(event);
225 return; 225 return;
226 } 226 }
227 227
228 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) { 228 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) {
229 if (renderer() && renderer()->visibleToHitTesting()) { 229 if (renderer() && renderer()->visibleToHitTesting()) {
230 if (Frame* frame = document()->frame()) { 230 if (Frame* frame = document().frame()) {
231 frame->eventHandler()->setCapturingMouseEventsNode(this); 231 frame->eventHandler()->setCapturingMouseEventsNode(this);
232 m_capturing = true; 232 m_capturing = true;
233 } 233 }
234 } 234 }
235 input->focus(); 235 input->focus();
236 input->select(); 236 input->select();
237 event->setDefaultHandled(); 237 event->setDefaultHandled();
238 } 238 }
239 if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton) { 239 if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton) {
240 if (m_capturing) { 240 if (m_capturing) {
241 if (Frame* frame = document()->frame()) { 241 if (Frame* frame = document().frame()) {
242 frame->eventHandler()->setCapturingMouseEventsNode(0); 242 frame->eventHandler()->setCapturingMouseEventsNode(0);
243 m_capturing = false; 243 m_capturing = false;
244 } 244 }
245 if (hovered()) { 245 if (hovered()) {
246 String oldValue = input->value(); 246 String oldValue = input->value();
247 input->setValueForUser(""); 247 input->setValueForUser("");
248 input->onSearch(); 248 input->onSearch();
249 event->setDefaultHandled(); 249 event->setDefaultHandled();
250 } 250 }
251 } 251 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 309
310 if (!input || input->isDisabledOrReadOnly()) { 310 if (!input || input->isDisabledOrReadOnly()) {
311 if (!event->defaultHandled()) 311 if (!event->defaultHandled())
312 HTMLDivElement::defaultEventHandler(event); 312 HTMLDivElement::defaultEventHandler(event);
313 return; 313 return;
314 } 314 }
315 315
316 // On mouse down, select the text and set focus. 316 // On mouse down, select the text and set focus.
317 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) { 317 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() == LeftButton) {
318 if (renderer() && renderer()->visibleToHitTesting()) { 318 if (renderer() && renderer()->visibleToHitTesting()) {
319 if (Frame* frame = document()->frame()) { 319 if (Frame* frame = document().frame()) {
320 frame->eventHandler()->setCapturingMouseEventsNode(this); 320 frame->eventHandler()->setCapturingMouseEventsNode(this);
321 m_capturing = true; 321 m_capturing = true;
322 } 322 }
323 } 323 }
324 RefPtr<InputFieldSpeechButtonElement> holdRefButton(this); 324 RefPtr<InputFieldSpeechButtonElement> holdRefButton(this);
325 input->focus(); 325 input->focus();
326 input->select(); 326 input->select();
327 event->setDefaultHandled(); 327 event->setDefaultHandled();
328 } 328 }
329 // On mouse up, release capture cleanly. 329 // On mouse up, release capture cleanly.
330 if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton) { 330 if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton) {
331 if (m_capturing && renderer() && renderer()->visibleToHitTesting()) { 331 if (m_capturing && renderer() && renderer()->visibleToHitTesting()) {
332 if (Frame* frame = document()->frame()) { 332 if (Frame* frame = document().frame()) {
333 frame->eventHandler()->setCapturingMouseEventsNode(0); 333 frame->eventHandler()->setCapturingMouseEventsNode(0);
334 m_capturing = false; 334 m_capturing = false;
335 } 335 }
336 } 336 }
337 } 337 }
338 338
339 if (event->type() == eventNames().clickEvent && m_listenerId) { 339 if (event->type() == eventNames().clickEvent && m_listenerId) {
340 switch (m_state) { 340 switch (m_state) {
341 case Idle: 341 case Idle:
342 startSpeechInput(); 342 startSpeechInput();
(...skipping 24 matching lines...) Expand all
367 void InputFieldSpeechButtonElement::setState(SpeechInputState state) 367 void InputFieldSpeechButtonElement::setState(SpeechInputState state)
368 { 368 {
369 if (m_state != state) { 369 if (m_state != state) {
370 m_state = state; 370 m_state = state;
371 shadowHost()->renderer()->repaint(); 371 shadowHost()->renderer()->repaint();
372 } 372 }
373 } 373 }
374 374
375 SpeechInput* InputFieldSpeechButtonElement::speechInput() 375 SpeechInput* InputFieldSpeechButtonElement::speechInput()
376 { 376 {
377 return SpeechInput::from(document()->page()); 377 return SpeechInput::from(document().page());
378 } 378 }
379 379
380 void InputFieldSpeechButtonElement::didCompleteRecording(int) 380 void InputFieldSpeechButtonElement::didCompleteRecording(int)
381 { 381 {
382 setState(Recognizing); 382 setState(Recognizing);
383 } 383 }
384 384
385 void InputFieldSpeechButtonElement::didCompleteRecognition(int) 385 void InputFieldSpeechButtonElement::didCompleteRecognition(int)
386 { 386 {
387 setState(Idle); 387 setState(Idle);
388 } 388 }
389 389
390 void InputFieldSpeechButtonElement::setRecognitionResult(int, const SpeechInputR esultArray& results) 390 void InputFieldSpeechButtonElement::setRecognitionResult(int, const SpeechInputR esultArray& results)
391 { 391 {
392 m_results = results; 392 m_results = results;
393 393
394 // The call to setValue() below dispatches an event, and an event handler in the page might 394 // The call to setValue() below dispatches an event, and an event handler in the page might
395 // remove the input element from DOM. To make sure it remains valid until we finish our work 395 // remove the input element from DOM. To make sure it remains valid until we finish our work
396 // here, we take a temporary reference. 396 // here, we take a temporary reference.
397 RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost())); 397 RefPtr<HTMLInputElement> input(toHTMLInputElement(shadowHost()));
398 if (!input || input->isDisabledOrReadOnly()) 398 if (!input || input->isDisabledOrReadOnly())
399 return; 399 return;
400 400
401 RefPtr<InputFieldSpeechButtonElement> holdRefButton(this); 401 RefPtr<InputFieldSpeechButtonElement> holdRefButton(this);
402 if (document() && document()->domWindow()) { 402 if (document().domWindow()) {
403 // Call selectionChanged, causing the element to cache the selection, 403 // Call selectionChanged, causing the element to cache the selection,
404 // so that the text event inserts the text in this element even if 404 // so that the text event inserts the text in this element even if
405 // focus has moved away from it. 405 // focus has moved away from it.
406 input->selectionChanged(false); 406 input->selectionChanged(false);
407 input->dispatchEvent(TextEvent::create(document()->domWindow(), results. isEmpty() ? "" : results[0]->utterance(), TextEventInputOther)); 407 input->dispatchEvent(TextEvent::create(document().domWindow(), results.i sEmpty() ? "" : results[0]->utterance(), TextEventInputOther));
408 } 408 }
409 409
410 // This event is sent after the text event so the website can perform action s using the input field content immediately. 410 // This event is sent after the text event so the website can perform action s using the input field content immediately.
411 // It provides alternative recognition hypotheses and notifies that the resu lts come from speech input. 411 // It provides alternative recognition hypotheses and notifies that the resu lts come from speech input.
412 input->dispatchEvent(SpeechInputEvent::create(eventNames().webkitspeechchang eEvent, results)); 412 input->dispatchEvent(SpeechInputEvent::create(eventNames().webkitspeechchang eEvent, results));
413 413
414 // Check before accessing the renderer as the above event could have potenti ally turned off 414 // Check before accessing the renderer as the above event could have potenti ally turned off
415 // speech in the input element, hence removing this button and renderer from the hierarchy. 415 // speech in the input element, hence removing this button and renderer from the hierarchy.
416 if (renderer()) 416 if (renderer())
417 renderer()->repaint(); 417 renderer()->repaint();
418 } 418 }
419 419
420 void InputFieldSpeechButtonElement::attach(const AttachContext& context) 420 void InputFieldSpeechButtonElement::attach(const AttachContext& context)
421 { 421 {
422 ASSERT(!m_listenerId); 422 ASSERT(!m_listenerId);
423 if (SpeechInput* input = SpeechInput::from(document()->page())) 423 if (SpeechInput* input = SpeechInput::from(document().page()))
424 m_listenerId = input->registerListener(this); 424 m_listenerId = input->registerListener(this);
425 HTMLDivElement::attach(context); 425 HTMLDivElement::attach(context);
426 } 426 }
427 427
428 void InputFieldSpeechButtonElement::detach(const AttachContext& context) 428 void InputFieldSpeechButtonElement::detach(const AttachContext& context)
429 { 429 {
430 if (m_capturing) { 430 if (m_capturing) {
431 if (Frame* frame = document()->frame()) 431 if (Frame* frame = document().frame())
432 frame->eventHandler()->setCapturingMouseEventsNode(0); 432 frame->eventHandler()->setCapturingMouseEventsNode(0);
433 } 433 }
434 434
435 if (m_listenerId) { 435 if (m_listenerId) {
436 if (m_state != Idle) 436 if (m_state != Idle)
437 speechInput()->cancelRecognition(m_listenerId); 437 speechInput()->cancelRecognition(m_listenerId);
438 speechInput()->unregisterListener(m_listenerId); 438 speechInput()->unregisterListener(m_listenerId);
439 m_listenerId = 0; 439 m_listenerId = 0;
440 } 440 }
441 441
442 HTMLDivElement::detach(context); 442 HTMLDivElement::detach(context);
443 } 443 }
444 444
445 void InputFieldSpeechButtonElement::startSpeechInput() 445 void InputFieldSpeechButtonElement::startSpeechInput()
446 { 446 {
447 if (m_state != Idle) 447 if (m_state != Idle)
448 return; 448 return;
449 449
450 RefPtr<HTMLInputElement> input = toHTMLInputElement(shadowHost()); 450 RefPtr<HTMLInputElement> input = toHTMLInputElement(shadowHost());
451 AtomicString language = input->computeInheritedLanguage(); 451 AtomicString language = input->computeInheritedLanguage();
452 String grammar = input->getAttribute(webkitgrammarAttr); 452 String grammar = input->getAttribute(webkitgrammarAttr);
453 IntRect rect = document()->view()->contentsToRootView(pixelSnappedBoundingBo x()); 453 IntRect rect = document().view()->contentsToRootView(pixelSnappedBoundingBox ());
454 if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, d ocument()->securityOrigin())) 454 if (speechInput()->startRecognition(m_listenerId, rect, language, grammar, d ocument().securityOrigin()))
455 setState(Recording); 455 setState(Recording);
456 } 456 }
457 457
458 void InputFieldSpeechButtonElement::stopSpeechInput() 458 void InputFieldSpeechButtonElement::stopSpeechInput()
459 { 459 {
460 if (m_state == Recording) 460 if (m_state == Recording)
461 speechInput()->stopRecording(m_listenerId); 461 speechInput()->stopRecording(m_listenerId);
462 } 462 }
463 #endif // ENABLE(INPUT_SPEECH) 463 #endif // ENABLE(INPUT_SPEECH)
464 464
465 } 465 }
OLDNEW
« no previous file with comments | « Source/core/html/shadow/SpinButtonElement.cpp ('k') | Source/core/html/track/LoadableTextTrack.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698