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

Side by Side Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 1433103002: Use FocusParams in FocusController::setFocusedElement and Document::setFocusedElement arguments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 3383 matching lines...) Expand 10 before | Expand all | Expand 10 after
3394 void Document::removeFocusedElementOfSubtree(Node* node, bool amongChildrenOnly) 3394 void Document::removeFocusedElementOfSubtree(Node* node, bool amongChildrenOnly)
3395 { 3395 {
3396 if (!m_focusedElement) 3396 if (!m_focusedElement)
3397 return; 3397 return;
3398 3398
3399 // We can't be focused if we're not in the document. 3399 // We can't be focused if we're not in the document.
3400 if (!node->inDocument()) 3400 if (!node->inDocument())
3401 return; 3401 return;
3402 bool contains = node->containsIncludingShadowDOM(m_focusedElement.get()); 3402 bool contains = node->containsIncludingShadowDOM(m_focusedElement.get());
3403 if (contains && (m_focusedElement != node || !amongChildrenOnly)) 3403 if (contains && (m_focusedElement != node || !amongChildrenOnly))
3404 setFocusedElement(nullptr); 3404 clearFocusedElement();
3405 } 3405 }
3406 3406
3407 void Document::hoveredNodeDetached(Element& element) 3407 void Document::hoveredNodeDetached(Element& element)
3408 { 3408 {
3409 if (!m_hoverNode) 3409 if (!m_hoverNode)
3410 return; 3410 return;
3411 3411
3412 m_hoverNode->updateDistribution(); 3412 m_hoverNode->updateDistribution();
3413 if (element != m_hoverNode && (!m_hoverNode->isTextNode() || element != Comp osedTreeTraversal::parent(*m_hoverNode))) 3413 if (element != m_hoverNode && (!m_hoverNode->isTextNode() || element != Comp osedTreeTraversal::parent(*m_hoverNode)))
3414 return; 3414 return;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3446 { 3446 {
3447 return m_annotatedRegions; 3447 return m_annotatedRegions;
3448 } 3448 }
3449 3449
3450 void Document::setAnnotatedRegions(const Vector<AnnotatedRegionValue>& regions) 3450 void Document::setAnnotatedRegions(const Vector<AnnotatedRegionValue>& regions)
3451 { 3451 {
3452 m_annotatedRegions = regions; 3452 m_annotatedRegions = regions;
3453 setAnnotatedRegionsDirty(false); 3453 setAnnotatedRegionsDirty(false);
3454 } 3454 }
3455 3455
3456 bool Document::setFocusedElement(PassRefPtrWillBeRawPtr<Element> prpNewFocusedEl ement, WebFocusType type, InputDeviceCapabilities* sourceCapabilities) 3456 bool Document::setFocusedElement(PassRefPtrWillBeRawPtr<Element> prpNewFocusedEl ement, const FocusParams& params)
3457 { 3457 {
3458 ASSERT(!m_lifecycle.inDetach()); 3458 ASSERT(!m_lifecycle.inDetach());
3459 3459
3460 m_clearFocusedElementTimer.stop(); 3460 m_clearFocusedElementTimer.stop();
3461 3461
3462 RefPtrWillBeRawPtr<Element> newFocusedElement = prpNewFocusedElement; 3462 RefPtrWillBeRawPtr<Element> newFocusedElement = prpNewFocusedElement;
3463 3463
3464 // Make sure newFocusedNode is actually in this document 3464 // Make sure newFocusedNode is actually in this document
3465 if (newFocusedElement && (newFocusedElement->document() != this)) 3465 if (newFocusedElement && (newFocusedElement->document() != this))
3466 return true; 3466 return true;
(...skipping 11 matching lines...) Expand all
3478 // Remove focus from the existing focus node (if any) 3478 // Remove focus from the existing focus node (if any)
3479 if (oldFocusedElement) { 3479 if (oldFocusedElement) {
3480 if (oldFocusedElement->active()) 3480 if (oldFocusedElement->active())
3481 oldFocusedElement->setActive(false); 3481 oldFocusedElement->setActive(false);
3482 3482
3483 oldFocusedElement->setFocus(false); 3483 oldFocusedElement->setFocus(false);
3484 3484
3485 // Dispatch the blur event and let the node do any other blur related ac tivities (important for text fields) 3485 // Dispatch the blur event and let the node do any other blur related ac tivities (important for text fields)
3486 // If page lost focus, blur event will have already been dispatched 3486 // If page lost focus, blur event will have already been dispatched
3487 if (page() && (page()->focusController().isFocused())) { 3487 if (page() && (page()->focusController().isFocused())) {
3488 oldFocusedElement->dispatchBlurEvent(newFocusedElement.get(), type, sourceCapabilities); 3488 oldFocusedElement->dispatchBlurEvent(newFocusedElement.get(), params .type, params.sourceCapabilities);
3489 3489
3490 if (m_focusedElement) { 3490 if (m_focusedElement) {
3491 // handler shifted focus 3491 // handler shifted focus
3492 focusChangeBlocked = true; 3492 focusChangeBlocked = true;
3493 newFocusedElement = nullptr; 3493 newFocusedElement = nullptr;
3494 } 3494 }
3495 3495
3496 oldFocusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, n ewFocusedElement.get(), sourceCapabilities); // DOM level 3 name for the bubblin g blur event. 3496 oldFocusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, n ewFocusedElement.get(), params.sourceCapabilities); // DOM level 3 name for the bubbling blur event.
3497 // FIXME: We should remove firing DOMFocusOutEvent event when we are sure no content depends 3497 // FIXME: We should remove firing DOMFocusOutEvent event when we are sure no content depends
3498 // on it, probably when <rdar://problem/8503958> is resolved. 3498 // on it, probably when <rdar://problem/8503958> is resolved.
3499 oldFocusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut , newFocusedElement.get(), sourceCapabilities); // DOM level 2 name for compatib ility. 3499 oldFocusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut , newFocusedElement.get(), params.sourceCapabilities); // DOM level 2 name for c ompatibility.
3500 3500
3501 if (m_focusedElement) { 3501 if (m_focusedElement) {
3502 // handler shifted focus 3502 // handler shifted focus
3503 focusChangeBlocked = true; 3503 focusChangeBlocked = true;
3504 newFocusedElement = nullptr; 3504 newFocusedElement = nullptr;
3505 } 3505 }
3506 // Event handlers might make newFocusedElement dirty. 3506 // Event handlers might make newFocusedElement dirty.
3507 updateLayoutIgnorePendingStylesheets(); 3507 updateLayoutIgnorePendingStylesheets();
3508 } 3508 }
3509 3509
3510 if (view()) { 3510 if (view()) {
3511 Widget* oldWidget = widgetForElement(*oldFocusedElement); 3511 Widget* oldWidget = widgetForElement(*oldFocusedElement);
3512 if (oldWidget) 3512 if (oldWidget)
3513 oldWidget->setFocus(false, type); 3513 oldWidget->setFocus(false, params.type);
3514 else 3514 else
3515 view()->setFocus(false, type); 3515 view()->setFocus(false, params.type);
3516 } 3516 }
3517 } 3517 }
3518 3518
3519 if (newFocusedElement && newFocusedElement->isFocusable()) { 3519 if (newFocusedElement && newFocusedElement->isFocusable()) {
3520 if (newFocusedElement->isRootEditableElement() && !acceptsEditingFocus(* newFocusedElement)) { 3520 if (newFocusedElement->isRootEditableElement() && !acceptsEditingFocus(* newFocusedElement)) {
3521 // delegate blocks focus change 3521 // delegate blocks focus change
3522 focusChangeBlocked = true; 3522 focusChangeBlocked = true;
3523 goto SetFocusedElementDone; 3523 goto SetFocusedElementDone;
3524 } 3524 }
3525 // Set focus on the new node 3525 // Set focus on the new node
3526 m_focusedElement = newFocusedElement; 3526 m_focusedElement = newFocusedElement;
3527 3527
3528 m_focusedElement->setFocus(true); 3528 m_focusedElement->setFocus(true);
3529 3529
3530 // Dispatch the focus event and let the node do any other focus related activities (important for text fields) 3530 // Dispatch the focus event and let the node do any other focus related activities (important for text fields)
3531 // If page lost focus, event will be dispatched on page focus, don't dup licate 3531 // If page lost focus, event will be dispatched on page focus, don't dup licate
3532 if (page() && (page()->focusController().isFocused())) { 3532 if (page() && (page()->focusController().isFocused())) {
3533 m_focusedElement->dispatchFocusEvent(oldFocusedElement.get(), type, sourceCapabilities); 3533 m_focusedElement->dispatchFocusEvent(oldFocusedElement.get(), params .type, params.sourceCapabilities);
3534 3534
3535 3535
3536 if (m_focusedElement != newFocusedElement) { 3536 if (m_focusedElement != newFocusedElement) {
3537 // handler shifted focus 3537 // handler shifted focus
3538 focusChangeBlocked = true; 3538 focusChangeBlocked = true;
3539 goto SetFocusedElementDone; 3539 goto SetFocusedElementDone;
3540 } 3540 }
3541 m_focusedElement->dispatchFocusInEvent(EventTypeNames::focusin, oldF ocusedElement.get(), type, sourceCapabilities); // DOM level 3 bubbling focus ev ent. 3541 m_focusedElement->dispatchFocusInEvent(EventTypeNames::focusin, oldF ocusedElement.get(), params.type, params.sourceCapabilities); // DOM level 3 bub bling focus event.
3542 3542
3543 if (m_focusedElement != newFocusedElement) { 3543 if (m_focusedElement != newFocusedElement) {
3544 // handler shifted focus 3544 // handler shifted focus
3545 focusChangeBlocked = true; 3545 focusChangeBlocked = true;
3546 goto SetFocusedElementDone; 3546 goto SetFocusedElementDone;
3547 } 3547 }
3548 3548
3549 // FIXME: We should remove firing DOMFocusInEvent event when we are sure no content depends 3549 // FIXME: We should remove firing DOMFocusInEvent event when we are sure no content depends
3550 // on it, probably when <rdar://problem/8503958> is m. 3550 // on it, probably when <rdar://problem/8503958> is m.
3551 m_focusedElement->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, o ldFocusedElement.get(), type, sourceCapabilities); // DOM level 2 for compatibil ity. 3551 m_focusedElement->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, o ldFocusedElement.get(), params.type, params.sourceCapabilities); // DOM level 2 for compatibility.
3552 3552
3553 if (m_focusedElement != newFocusedElement) { 3553 if (m_focusedElement != newFocusedElement) {
3554 // handler shifted focus 3554 // handler shifted focus
3555 focusChangeBlocked = true; 3555 focusChangeBlocked = true;
3556 goto SetFocusedElementDone; 3556 goto SetFocusedElementDone;
3557 } 3557 }
3558 } 3558 }
3559 3559
3560 if (m_focusedElement->isRootEditableElement()) 3560 if (m_focusedElement->isRootEditableElement())
3561 frame()->spellChecker().didBeginEditing(m_focusedElement.get()); 3561 frame()->spellChecker().didBeginEditing(m_focusedElement.get());
3562 3562
3563 // eww, I suck. set the qt focus correctly 3563 // eww, I suck. set the qt focus correctly
3564 // ### find a better place in the code for this 3564 // ### find a better place in the code for this
3565 if (view()) { 3565 if (view()) {
3566 Widget* focusWidget = widgetForElement(*m_focusedElement); 3566 Widget* focusWidget = widgetForElement(*m_focusedElement);
3567 if (focusWidget) { 3567 if (focusWidget) {
3568 // Make sure a widget has the right size before giving it focus. 3568 // Make sure a widget has the right size before giving it focus.
3569 // Otherwise, we are testing edge cases of the Widget code. 3569 // Otherwise, we are testing edge cases of the Widget code.
3570 // Specifically, in WebCore this does not work well for text fie lds. 3570 // Specifically, in WebCore this does not work well for text fie lds.
3571 updateLayout(); 3571 updateLayout();
3572 // Re-get the widget in case updating the layout changed things. 3572 // Re-get the widget in case updating the layout changed things.
3573 focusWidget = widgetForElement(*m_focusedElement); 3573 focusWidget = widgetForElement(*m_focusedElement);
3574 } 3574 }
3575 if (focusWidget) 3575 if (focusWidget)
3576 focusWidget->setFocus(true, type); 3576 focusWidget->setFocus(true, params.type);
3577 else 3577 else
3578 view()->setFocus(true, type); 3578 view()->setFocus(true, params.type);
3579 } 3579 }
3580 } 3580 }
3581 3581
3582 if (!focusChangeBlocked && m_focusedElement) { 3582 if (!focusChangeBlocked && m_focusedElement) {
3583 // Create the AXObject cache in a focus change because Chromium relies o n it. 3583 // Create the AXObject cache in a focus change because Chromium relies o n it.
3584 if (AXObjectCache* cache = axObjectCache()) 3584 if (AXObjectCache* cache = axObjectCache())
3585 cache->handleFocusedUIElementChanged(oldFocusedElement.get(), newFoc usedElement.get()); 3585 cache->handleFocusedUIElementChanged(oldFocusedElement.get(), newFoc usedElement.get());
3586 } 3586 }
3587 3587
3588 if (!focusChangeBlocked && frameHost()) 3588 if (!focusChangeBlocked && frameHost())
3589 frameHost()->chromeClient().focusedNodeChanged(oldFocusedElement.get(), m_focusedElement.get()); 3589 frameHost()->chromeClient().focusedNodeChanged(oldFocusedElement.get(), m_focusedElement.get());
3590 3590
3591 SetFocusedElementDone: 3591 SetFocusedElementDone:
3592 updateLayoutTreeIfNeeded(); 3592 updateLayoutTreeIfNeeded();
3593 if (LocalFrame* frame = this->frame()) 3593 if (LocalFrame* frame = this->frame())
3594 frame->selection().didChangeFocus(); 3594 frame->selection().didChangeFocus();
3595 return !focusChangeBlocked; 3595 return !focusChangeBlocked;
3596 } 3596 }
3597 3597
3598 void Document::clearFocusedElement()
3599 {
3600 setFocusedElement(nullptr, FocusParams(SelectionBehaviorOnFocus::None, WebFo cusTypeNone, nullptr));
3601 }
3602
3598 void Document::setCSSTarget(Element* newTarget) 3603 void Document::setCSSTarget(Element* newTarget)
3599 { 3604 {
3600 if (m_cssTarget) 3605 if (m_cssTarget)
3601 m_cssTarget->pseudoStateChanged(CSSSelector::PseudoTarget); 3606 m_cssTarget->pseudoStateChanged(CSSSelector::PseudoTarget);
3602 m_cssTarget = newTarget; 3607 m_cssTarget = newTarget;
3603 if (m_cssTarget) 3608 if (m_cssTarget)
3604 m_cssTarget->pseudoStateChanged(CSSSelector::PseudoTarget); 3609 m_cssTarget->pseudoStateChanged(CSSSelector::PseudoTarget);
3605 } 3610 }
3606 3611
3607 void Document::registerNodeList(const LiveNodeListBase* list) 3612 void Document::registerNodeList(const LiveNodeListBase* list)
(...skipping 2219 matching lines...) Expand 10 before | Expand all | Expand 10 after
5827 #ifndef NDEBUG 5832 #ifndef NDEBUG
5828 using namespace blink; 5833 using namespace blink;
5829 void showLiveDocumentInstances() 5834 void showLiveDocumentInstances()
5830 { 5835 {
5831 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 5836 Document::WeakDocumentSet& set = Document::liveDocumentSet();
5832 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5837 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5833 for (Document* document : set) 5838 for (Document* document : set)
5834 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); 5839 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data());
5835 } 5840 }
5836 #endif 5841 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.h ('k') | third_party/WebKit/Source/core/dom/Element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698