| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return m_rootTreeScope->rootNode(); | 74 return m_rootTreeScope->rootNode(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 Element* FocusNavigationScope::owner() const | 77 Element* FocusNavigationScope::owner() const |
| 78 { | 78 { |
| 79 Node* root = rootNode(); | 79 Node* root = rootNode(); |
| 80 if (root->isShadowRoot()) { | 80 if (root->isShadowRoot()) { |
| 81 ShadowRoot* shadowRoot = toShadowRoot(root); | 81 ShadowRoot* shadowRoot = toShadowRoot(root); |
| 82 return shadowRoot->isYoungest() ? shadowRoot->host() : shadowRoot->inser
tionPoint(); | 82 return shadowRoot->isYoungest() ? shadowRoot->host() : shadowRoot->inser
tionPoint(); |
| 83 } | 83 } |
| 84 if (Frame* frame = root->document()->frame()) | 84 if (Frame* frame = root->document().frame()) |
| 85 return frame->ownerElement(); | 85 return frame->ownerElement(); |
| 86 return 0; | 86 return 0; |
| 87 } | 87 } |
| 88 | 88 |
| 89 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node) | 89 FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node) |
| 90 { | 90 { |
| 91 ASSERT(node); | 91 ASSERT(node); |
| 92 Node* root = node; | 92 Node* root = node; |
| 93 for (Node* n = node; n; n = n->parentNode()) | 93 for (Node* n = node; n; n = n->parentNode()) |
| 94 root = n; | 94 root = n; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 return false; | 361 return false; |
| 362 | 362 |
| 363 document->setFocusedElement(0); | 363 document->setFocusedElement(0); |
| 364 setFocusedFrame(owner->contentFrame()); | 364 setFocusedFrame(owner->contentFrame()); |
| 365 return true; | 365 return true; |
| 366 } | 366 } |
| 367 | 367 |
| 368 // FIXME: It would be nice to just be able to call setFocusedElement(node) | 368 // FIXME: It would be nice to just be able to call setFocusedElement(node) |
| 369 // here, but we can't do that because some elements (e.g. HTMLInputElement | 369 // here, but we can't do that because some elements (e.g. HTMLInputElement |
| 370 // and HTMLTextAreaElement) do extra work in their focus() methods. | 370 // and HTMLTextAreaElement) do extra work in their focus() methods. |
| 371 Document* newDocument = element->document(); | 371 Document& newDocument = element->document(); |
| 372 | 372 |
| 373 if (newDocument != document) { | 373 if (&newDocument != document) { |
| 374 // Focus is going away from this document, so clear the focused node. | 374 // Focus is going away from this document, so clear the focused node. |
| 375 document->setFocusedElement(0); | 375 document->setFocusedElement(0); |
| 376 } | 376 } |
| 377 | 377 |
| 378 if (newDocument) | 378 setFocusedFrame(newDocument.frame()); |
| 379 setFocusedFrame(newDocument->frame()); | |
| 380 | 379 |
| 381 if (caretBrowsing) { | 380 if (caretBrowsing) { |
| 382 Position position = firstPositionInOrBeforeNode(element); | 381 Position position = firstPositionInOrBeforeNode(element); |
| 383 VisibleSelection newSelection(position, position, DOWNSTREAM); | 382 VisibleSelection newSelection(position, position, DOWNSTREAM); |
| 384 if (frame->selection()->shouldChangeSelection(newSelection)) | 383 if (frame->selection()->shouldChangeSelection(newSelection)) |
| 385 frame->selection()->setSelection(newSelection); | 384 frame->selection()->setSelection(newSelection); |
| 386 } | 385 } |
| 387 | 386 |
| 388 element->focus(false, direction); | 387 element->focus(false, direction); |
| 389 return true; | 388 return true; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 startingTabIndex = (start && startingTabIndex) ? startingTabIndex : std::num
eric_limits<short>::max(); | 554 startingTabIndex = (start && startingTabIndex) ? startingTabIndex : std::num
eric_limits<short>::max(); |
| 556 return previousNodeWithLowerTabIndex(last, startingTabIndex); | 555 return previousNodeWithLowerTabIndex(last, startingTabIndex); |
| 557 } | 556 } |
| 558 | 557 |
| 559 static bool relinquishesEditingFocus(Node *node) | 558 static bool relinquishesEditingFocus(Node *node) |
| 560 { | 559 { |
| 561 ASSERT(node); | 560 ASSERT(node); |
| 562 ASSERT(node->rendererIsEditable()); | 561 ASSERT(node->rendererIsEditable()); |
| 563 | 562 |
| 564 Node* root = node->rootEditableElement(); | 563 Node* root = node->rootEditableElement(); |
| 565 Frame* frame = node->document()->frame(); | 564 Frame* frame = node->document().frame(); |
| 566 if (!frame || !root) | 565 if (!frame || !root) |
| 567 return false; | 566 return false; |
| 568 | 567 |
| 569 return frame->editor().shouldEndEditing(rangeOfContents(root).get()); | 568 return frame->editor().shouldEndEditing(rangeOfContents(root).get()); |
| 570 } | 569 } |
| 571 | 570 |
| 572 static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Frame* newFocusedFram
e, Node* newFocusedNode) | 571 static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Frame* newFocusedFram
e, Node* newFocusedNode) |
| 573 { | 572 { |
| 574 if (!oldFocusedFrame || !newFocusedFrame) | 573 if (!oldFocusedFrame || !newFocusedFrame) |
| 575 return; | 574 return; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 m_page->editorClient().willSetInputMethodState(); | 621 m_page->editorClient().willSetInputMethodState(); |
| 623 | 622 |
| 624 clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), element
); | 623 clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), element
); |
| 625 | 624 |
| 626 if (!element) { | 625 if (!element) { |
| 627 if (oldDocument) | 626 if (oldDocument) |
| 628 oldDocument->setFocusedElement(0); | 627 oldDocument->setFocusedElement(0); |
| 629 return true; | 628 return true; |
| 630 } | 629 } |
| 631 | 630 |
| 632 RefPtr<Document> newDocument = element->document(); | 631 RefPtr<Document> newDocument = &element->document(); |
| 633 | 632 |
| 634 if (newDocument && newDocument->focusedElement() == element) | 633 if (newDocument && newDocument->focusedElement() == element) |
| 635 return true; | 634 return true; |
| 636 | 635 |
| 637 if (oldDocument && oldDocument != newDocument) | 636 if (oldDocument && oldDocument != newDocument) |
| 638 oldDocument->setFocusedElement(0); | 637 oldDocument->setFocusedElement(0); |
| 639 | 638 |
| 640 if (newFocusedFrame && !newFocusedFrame->page()) { | 639 if (newFocusedFrame && !newFocusedFrame->page()) { |
| 641 setFocusedFrame(0); | 640 setFocusedFrame(0); |
| 642 return false; | 641 return false; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 if (closest.isNull()) { | 730 if (closest.isNull()) { |
| 732 closest = candidate; | 731 closest = candidate; |
| 733 return; | 732 return; |
| 734 } | 733 } |
| 735 | 734 |
| 736 LayoutRect intersectionRect = intersection(candidate.rect, closest.rect); | 735 LayoutRect intersectionRect = intersection(candidate.rect, closest.rect); |
| 737 if (!intersectionRect.isEmpty() && !areElementsOnSameLine(closest, candidate
)) { | 736 if (!intersectionRect.isEmpty() && !areElementsOnSameLine(closest, candidate
)) { |
| 738 // If 2 nodes are intersecting, do hit test to find which node in on top
. | 737 // If 2 nodes are intersecting, do hit test to find which node in on top
. |
| 739 LayoutUnit x = intersectionRect.x() + intersectionRect.width() / 2; | 738 LayoutUnit x = intersectionRect.x() + intersectionRect.width() / 2; |
| 740 LayoutUnit y = intersectionRect.y() + intersectionRect.height() / 2; | 739 LayoutUnit y = intersectionRect.y() + intersectionRect.height() / 2; |
| 741 HitTestResult result = candidate.visibleNode->document()->page()->mainFr
ame()->eventHandler()->hitTestResultAtPoint(IntPoint(x, y), HitTestRequest::Read
Only | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest:
:DisallowShadowContent); | 740 HitTestResult result = candidate.visibleNode->document().page()->mainFra
me()->eventHandler()->hitTestResultAtPoint(IntPoint(x, y), HitTestRequest::ReadO
nly | HitTestRequest::Active | HitTestRequest::IgnoreClipping | HitTestRequest::
DisallowShadowContent); |
| 742 if (candidate.visibleNode->contains(result.innerNode())) { | 741 if (candidate.visibleNode->contains(result.innerNode())) { |
| 743 closest = candidate; | 742 closest = candidate; |
| 744 return; | 743 return; |
| 745 } | 744 } |
| 746 if (closest.visibleNode->contains(result.innerNode())) | 745 if (closest.visibleNode->contains(result.innerNode())) |
| 747 return; | 746 return; |
| 748 } | 747 } |
| 749 | 748 |
| 750 if (candidate.alignment == closest.alignment) { | 749 if (candidate.alignment == closest.alignment) { |
| 751 if (candidate.distance < closest.distance) | 750 if (candidate.distance < closest.distance) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 return scrollInDirection(container, direction); | 806 return scrollInDirection(container, direction); |
| 808 } | 807 } |
| 809 | 808 |
| 810 if (HTMLFrameOwnerElement* frameElement = frameOwnerElement(focusCandidate))
{ | 809 if (HTMLFrameOwnerElement* frameElement = frameOwnerElement(focusCandidate))
{ |
| 811 // If we have an iframe without the src attribute, it will not have a co
ntentFrame(). | 810 // If we have an iframe without the src attribute, it will not have a co
ntentFrame(). |
| 812 // We ASSERT here to make sure that | 811 // We ASSERT here to make sure that |
| 813 // updateFocusCandidateIfNeeded() will never consider such an iframe as
a candidate. | 812 // updateFocusCandidateIfNeeded() will never consider such an iframe as
a candidate. |
| 814 ASSERT(frameElement->contentFrame()); | 813 ASSERT(frameElement->contentFrame()); |
| 815 | 814 |
| 816 if (focusCandidate.isOffscreenAfterScrolling) { | 815 if (focusCandidate.isOffscreenAfterScrolling) { |
| 817 scrollInDirection(focusCandidate.visibleNode->document(), direction)
; | 816 scrollInDirection(&focusCandidate.visibleNode->document(), direction
); |
| 818 return true; | 817 return true; |
| 819 } | 818 } |
| 820 // Navigate into a new frame. | 819 // Navigate into a new frame. |
| 821 LayoutRect rect; | 820 LayoutRect rect; |
| 822 Element* focusedElement = focusedOrMainFrame()->document()->focusedEleme
nt(); | 821 Element* focusedElement = focusedOrMainFrame()->document()->focusedEleme
nt(); |
| 823 if (focusedElement && !hasOffscreenRect(focusedElement)) | 822 if (focusedElement && !hasOffscreenRect(focusedElement)) |
| 824 rect = nodeRectInAbsoluteCoordinates(focusedElement, true /* ignore
border */); | 823 rect = nodeRectInAbsoluteCoordinates(focusedElement, true /* ignore
border */); |
| 825 frameElement->contentFrame()->document()->updateLayoutIgnorePendingStyle
sheets(); | 824 frameElement->contentFrame()->document()->updateLayoutIgnorePendingStyle
sheets(); |
| 826 if (!advanceFocusDirectionallyInContainer(frameElement->contentFrame()->
document(), rect, direction)) { | 825 if (!advanceFocusDirectionallyInContainer(frameElement->contentFrame()->
document(), rect, direction)) { |
| 827 // The new frame had nothing interesting, need to find another candi
date. | 826 // The new frame had nothing interesting, need to find another candi
date. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b
order */); | 889 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b
order */); |
| 891 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct
ion, container); | 890 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct
ion, container); |
| 892 if (container && container->isDocumentNode()) | 891 if (container && container->isDocumentNode()) |
| 893 toDocument(container)->updateLayoutIgnorePendingStylesheets(); | 892 toDocument(container)->updateLayoutIgnorePendingStylesheets(); |
| 894 } while (!consumed && container); | 893 } while (!consumed && container); |
| 895 | 894 |
| 896 return consumed; | 895 return consumed; |
| 897 } | 896 } |
| 898 | 897 |
| 899 } // namespace WebCore | 898 } // namespace WebCore |
| OLD | NEW |