| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Nuanti Ltd. | 3 * Copyright (C) 2008 Nuanti Ltd. |
| 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 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 if (caretBrowsing && !currentNode) | 713 if (caretBrowsing && !currentNode) |
| 714 currentNode = frame->selection().start().anchorNode(); | 714 currentNode = frame->selection().start().anchorNode(); |
| 715 | 715 |
| 716 document->updateLayoutIgnorePendingStylesheets(); | 716 document->updateLayoutIgnorePendingStylesheets(); |
| 717 | 717 |
| 718 RefPtrWillBeRawPtr<Element> element = findFocusableElementAcrossFocusScopes(
type, FocusNavigationScope::focusNavigationScopeOf(currentNode ? *currentNode :
*document), currentNode); | 718 RefPtrWillBeRawPtr<Element> element = findFocusableElementAcrossFocusScopes(
type, FocusNavigationScope::focusNavigationScopeOf(currentNode ? *currentNode :
*document), currentNode); |
| 719 | 719 |
| 720 if (!element) { | 720 if (!element) { |
| 721 // We didn't find an element to focus, so we should try to pass focus to
Chrome. | 721 // We didn't find an element to focus, so we should try to pass focus to
Chrome. |
| 722 if (!initialFocus && m_page->chromeClient().canTakeFocus(type)) { | 722 if (!initialFocus && m_page->chromeClient().canTakeFocus(type)) { |
| 723 document->setFocusedElement(nullptr); | 723 document->clearFocusedElement(); |
| 724 setFocusedFrame(nullptr); | 724 setFocusedFrame(nullptr); |
| 725 m_page->chromeClient().takeFocus(type); | 725 m_page->chromeClient().takeFocus(type); |
| 726 return true; | 726 return true; |
| 727 } | 727 } |
| 728 | 728 |
| 729 // Chrome doesn't want focus, so we should wrap focus. | 729 // Chrome doesn't want focus, so we should wrap focus. |
| 730 if (!m_page->mainFrame()->isLocalFrame()) | 730 if (!m_page->mainFrame()->isLocalFrame()) |
| 731 return false; | 731 return false; |
| 732 element = findFocusableElementRecursively(type, FocusNavigationScope::fo
cusNavigationScopeOf(*m_page->deprecatedLocalMainFrame()->document()), nullptr); | 732 element = findFocusableElementRecursively(type, FocusNavigationScope::fo
cusNavigationScopeOf(*m_page->deprecatedLocalMainFrame()->document()), nullptr); |
| 733 element = findFocusableElementDescendingDownIntoFrameDocument(type, elem
ent.get()); | 733 element = findFocusableElementDescendingDownIntoFrameDocument(type, elem
ent.get()); |
| 734 | 734 |
| 735 if (!element) | 735 if (!element) |
| 736 return false; | 736 return false; |
| 737 } | 737 } |
| 738 | 738 |
| 739 ASSERT(element); | 739 ASSERT(element); |
| 740 | 740 |
| 741 if (element == document->focusedElement()) { | 741 if (element == document->focusedElement()) { |
| 742 // Focus wrapped around to the same node. | 742 // Focus wrapped around to the same node. |
| 743 return true; | 743 return true; |
| 744 } | 744 } |
| 745 | 745 |
| 746 if (element->isFrameOwnerElement() && (!isHTMLPlugInElement(*element) || !el
ement->isKeyboardFocusable())) { | 746 if (element->isFrameOwnerElement() && (!isHTMLPlugInElement(*element) || !el
ement->isKeyboardFocusable())) { |
| 747 // We focus frames rather than frame owners. | 747 // We focus frames rather than frame owners. |
| 748 // FIXME: We should not focus frames that have no scrollbars, as focusin
g them isn't useful to the user. | 748 // FIXME: We should not focus frames that have no scrollbars, as focusin
g them isn't useful to the user. |
| 749 HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(element); | 749 HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(element); |
| 750 if (!owner->contentFrame()) | 750 if (!owner->contentFrame()) |
| 751 return false; | 751 return false; |
| 752 | 752 |
| 753 document->setFocusedElement(nullptr); | 753 document->clearFocusedElement(); |
| 754 setFocusedFrame(owner->contentFrame()); | 754 setFocusedFrame(owner->contentFrame()); |
| 755 return true; | 755 return true; |
| 756 } | 756 } |
| 757 | 757 |
| 758 // FIXME: It would be nice to just be able to call setFocusedElement(node) | 758 // FIXME: It would be nice to just be able to call setFocusedElement(node) |
| 759 // here, but we can't do that because some elements (e.g. HTMLInputElement | 759 // here, but we can't do that because some elements (e.g. HTMLInputElement |
| 760 // and HTMLTextAreaElement) do extra work in their focus() methods. | 760 // and HTMLTextAreaElement) do extra work in their focus() methods. |
| 761 Document& newDocument = element->document(); | 761 Document& newDocument = element->document(); |
| 762 | 762 |
| 763 if (&newDocument != document) { | 763 if (&newDocument != document) { |
| 764 // Focus is going away from this document, so clear the focused node. | 764 // Focus is going away from this document, so clear the focused node. |
| 765 document->setFocusedElement(nullptr); | 765 document->clearFocusedElement(); |
| 766 } | 766 } |
| 767 | 767 |
| 768 setFocusedFrame(newDocument.frame()); | 768 setFocusedFrame(newDocument.frame()); |
| 769 | 769 |
| 770 if (caretBrowsing) { | 770 if (caretBrowsing) { |
| 771 Position position = firstPositionInOrBeforeNode(element.get()); | 771 Position position = firstPositionInOrBeforeNode(element.get()); |
| 772 VisibleSelection newSelection(position, position); | 772 VisibleSelection newSelection(position, position); |
| 773 frame->selection().setSelection(newSelection); | 773 frame->selection().setSelection(newSelection); |
| 774 } | 774 } |
| 775 | 775 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 | 813 |
| 814 if (!enclosingTextFormControl(selectionStartNode)) | 814 if (!enclosingTextFormControl(selectionStartNode)) |
| 815 return; | 815 return; |
| 816 | 816 |
| 817 if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost()
== newFocusedElement) | 817 if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost()
== newFocusedElement) |
| 818 return; | 818 return; |
| 819 | 819 |
| 820 selection.clear(); | 820 selection.clear(); |
| 821 } | 821 } |
| 822 | 822 |
| 823 bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr
<Frame> newFocusedFrame, WebFocusType type, InputDeviceCapabilities* sourceCapab
ilities) | 823 bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr
<Frame> newFocusedFrame) |
| 824 { |
| 825 return setFocusedElement(element, newFocusedFrame, FocusParams(SelectionBeha
viorOnFocus::None, WebFocusTypeNone, nullptr)); |
| 826 } |
| 827 |
| 828 bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr
<Frame> newFocusedFrame, const FocusParams& params) |
| 824 { | 829 { |
| 825 RefPtrWillBeRawPtr<LocalFrame> oldFocusedFrame = focusedFrame(); | 830 RefPtrWillBeRawPtr<LocalFrame> oldFocusedFrame = focusedFrame(); |
| 826 RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame
->document() : nullptr; | 831 RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame
->document() : nullptr; |
| 827 | 832 |
| 828 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : n
ullptr; | 833 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : n
ullptr; |
| 829 if (element && oldFocusedElement == element) | 834 if (element && oldFocusedElement == element) |
| 830 return true; | 835 return true; |
| 831 | 836 |
| 832 // FIXME: Might want to disable this check for caretBrowsing | 837 // FIXME: Might want to disable this check for caretBrowsing |
| 833 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli
nquishesEditingFocus(*oldFocusedElement)) | 838 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli
nquishesEditingFocus(*oldFocusedElement)) |
| 834 return false; | 839 return false; |
| 835 | 840 |
| 836 m_page->chromeClient().willSetInputMethodState(); | 841 m_page->chromeClient().willSetInputMethodState(); |
| 837 | 842 |
| 838 RefPtrWillBeRawPtr<Document> newDocument = nullptr; | 843 RefPtrWillBeRawPtr<Document> newDocument = nullptr; |
| 839 if (element) | 844 if (element) |
| 840 newDocument = &element->document(); | 845 newDocument = &element->document(); |
| 841 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) | 846 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) |
| 842 newDocument = toLocalFrame(newFocusedFrame.get())->document(); | 847 newDocument = toLocalFrame(newFocusedFrame.get())->document(); |
| 843 | 848 |
| 844 if (newDocument && oldDocument == newDocument && newDocument->focusedElement
() == element) | 849 if (newDocument && oldDocument == newDocument && newDocument->focusedElement
() == element) |
| 845 return true; | 850 return true; |
| 846 | 851 |
| 847 if (newFocusedFrame && newFocusedFrame->isLocalFrame()) | 852 if (newFocusedFrame && newFocusedFrame->isLocalFrame()) |
| 848 clearSelectionIfNeeded(oldFocusedFrame.get(), toLocalFrame(newFocusedFra
me.get()), element); | 853 clearSelectionIfNeeded(oldFocusedFrame.get(), toLocalFrame(newFocusedFra
me.get()), element); |
| 849 | 854 |
| 850 if (oldDocument && oldDocument != newDocument) | 855 if (oldDocument && oldDocument != newDocument) |
| 851 oldDocument->setFocusedElement(nullptr); | 856 oldDocument->clearFocusedElement(); |
| 852 | 857 |
| 853 if (newFocusedFrame && !newFocusedFrame->page()) { | 858 if (newFocusedFrame && !newFocusedFrame->page()) { |
| 854 setFocusedFrame(nullptr); | 859 setFocusedFrame(nullptr); |
| 855 return false; | 860 return false; |
| 856 } | 861 } |
| 857 setFocusedFrame(newFocusedFrame); | 862 setFocusedFrame(newFocusedFrame); |
| 858 | 863 |
| 859 // Setting the focused node can result in losing our last reft to node when
JS event handlers fire. | 864 // Setting the focused node can result in losing our last reft to node when
JS event handlers fire. |
| 860 RefPtrWillBeRawPtr<Element> protect = element; | 865 RefPtrWillBeRawPtr<Element> protect = element; |
| 861 ALLOW_UNUSED_LOCAL(protect); | 866 ALLOW_UNUSED_LOCAL(protect); |
| 862 if (newDocument) { | 867 if (newDocument) { |
| 863 bool successfullyFocused = newDocument->setFocusedElement(element, type,
sourceCapabilities); | 868 bool successfullyFocused = newDocument->setFocusedElement(element, param
s); |
| 864 if (!successfullyFocused) | 869 if (!successfullyFocused) |
| 865 return false; | 870 return false; |
| 866 } | 871 } |
| 867 | 872 |
| 868 return true; | 873 return true; |
| 869 } | 874 } |
| 870 | 875 |
| 871 void FocusController::setActive(bool active) | 876 void FocusController::setActive(bool active) |
| 872 { | 877 { |
| 873 if (m_isActive == active) | 878 if (m_isActive == active) |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 return consumed; | 1078 return consumed; |
| 1074 } | 1079 } |
| 1075 | 1080 |
| 1076 DEFINE_TRACE(FocusController) | 1081 DEFINE_TRACE(FocusController) |
| 1077 { | 1082 { |
| 1078 visitor->trace(m_page); | 1083 visitor->trace(m_page); |
| 1079 visitor->trace(m_focusedFrame); | 1084 visitor->trace(m_focusedFrame); |
| 1080 } | 1085 } |
| 1081 | 1086 |
| 1082 } // namespace blink | 1087 } // namespace blink |
| OLD | NEW |