| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 if (caretBrowsing && !currentNode) | 348 if (caretBrowsing && !currentNode) |
| 349 currentNode = frame->selection().start().deprecatedNode(); | 349 currentNode = frame->selection().start().deprecatedNode(); |
| 350 | 350 |
| 351 document->updateLayoutIgnorePendingStylesheets(); | 351 document->updateLayoutIgnorePendingStylesheets(); |
| 352 | 352 |
| 353 RefPtr<Node> node = findFocusableNodeAcrossFocusScope(type, FocusNavigationS
cope::focusNavigationScopeOf(currentNode ? currentNode : document), currentNode)
; | 353 RefPtr<Node> node = findFocusableNodeAcrossFocusScope(type, FocusNavigationS
cope::focusNavigationScopeOf(currentNode ? currentNode : document), currentNode)
; |
| 354 | 354 |
| 355 if (!node) { | 355 if (!node) { |
| 356 // We didn't find a node to focus, so we should try to pass focus to Chr
ome. | 356 // We didn't find a node to focus, so we should try to pass focus to Chr
ome. |
| 357 if (!initialFocus && m_page->chrome().canTakeFocus(type)) { | 357 if (!initialFocus && m_page->chrome().canTakeFocus(type)) { |
| 358 document->setFocusedElement(0); | 358 document->setFocusedElement(nullptr); |
| 359 setFocusedFrame(0); | 359 setFocusedFrame(nullptr); |
| 360 m_page->chrome().takeFocus(type); | 360 m_page->chrome().takeFocus(type); |
| 361 return true; | 361 return true; |
| 362 } | 362 } |
| 363 | 363 |
| 364 // Chrome doesn't want focus, so we should wrap focus. | 364 // Chrome doesn't want focus, so we should wrap focus. |
| 365 node = findFocusableNodeRecursively(type, FocusNavigationScope::focusNav
igationScopeOf(m_page->mainFrame()->document()), 0); | 365 node = findFocusableNodeRecursively(type, FocusNavigationScope::focusNav
igationScopeOf(m_page->mainFrame()->document()), 0); |
| 366 node = findFocusableNodeDecendingDownIntoFrameDocument(type, node.get())
; | 366 node = findFocusableNodeDecendingDownIntoFrameDocument(type, node.get())
; |
| 367 | 367 |
| 368 if (!node) | 368 if (!node) |
| 369 return false; | 369 return false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 380 return false; | 380 return false; |
| 381 | 381 |
| 382 Element* element = toElement(node); | 382 Element* element = toElement(node); |
| 383 if (element->isFrameOwnerElement() && (!element->isPluginElement() || !eleme
nt->isKeyboardFocusable())) { | 383 if (element->isFrameOwnerElement() && (!element->isPluginElement() || !eleme
nt->isKeyboardFocusable())) { |
| 384 // We focus frames rather than frame owners. | 384 // We focus frames rather than frame owners. |
| 385 // FIXME: We should not focus frames that have no scrollbars, as focusin
g them isn't useful to the user. | 385 // FIXME: We should not focus frames that have no scrollbars, as focusin
g them isn't useful to the user. |
| 386 HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(element); | 386 HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(element); |
| 387 if (!owner->contentFrame()) | 387 if (!owner->contentFrame()) |
| 388 return false; | 388 return false; |
| 389 | 389 |
| 390 document->setFocusedElement(0); | 390 document->setFocusedElement(nullptr); |
| 391 setFocusedFrame(owner->contentFrame()); | 391 setFocusedFrame(owner->contentFrame()); |
| 392 return true; | 392 return true; |
| 393 } | 393 } |
| 394 | 394 |
| 395 // FIXME: It would be nice to just be able to call setFocusedElement(node) | 395 // FIXME: It would be nice to just be able to call setFocusedElement(node) |
| 396 // here, but we can't do that because some elements (e.g. HTMLInputElement | 396 // here, but we can't do that because some elements (e.g. HTMLInputElement |
| 397 // and HTMLTextAreaElement) do extra work in their focus() methods. | 397 // and HTMLTextAreaElement) do extra work in their focus() methods. |
| 398 Document& newDocument = element->document(); | 398 Document& newDocument = element->document(); |
| 399 | 399 |
| 400 if (&newDocument != document) { | 400 if (&newDocument != document) { |
| 401 // Focus is going away from this document, so clear the focused node. | 401 // Focus is going away from this document, so clear the focused node. |
| 402 document->setFocusedElement(0); | 402 document->setFocusedElement(nullptr); |
| 403 } | 403 } |
| 404 | 404 |
| 405 setFocusedFrame(newDocument.frame()); | 405 setFocusedFrame(newDocument.frame()); |
| 406 | 406 |
| 407 if (caretBrowsing) { | 407 if (caretBrowsing) { |
| 408 Position position = firstPositionInOrBeforeNode(element); | 408 Position position = firstPositionInOrBeforeNode(element); |
| 409 VisibleSelection newSelection(position, position, DOWNSTREAM); | 409 VisibleSelection newSelection(position, position, DOWNSTREAM); |
| 410 frame->selection().setSelection(newSelection); | 410 frame->selection().setSelection(newSelection); |
| 411 } | 411 } |
| 412 | 412 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 newDocument = &element->document(); | 643 newDocument = &element->document(); |
| 644 else if (newFocusedFrame) | 644 else if (newFocusedFrame) |
| 645 newDocument = newFocusedFrame->document(); | 645 newDocument = newFocusedFrame->document(); |
| 646 | 646 |
| 647 if (newDocument && oldDocument == newDocument && newDocument->focusedElement
() == element) | 647 if (newDocument && oldDocument == newDocument && newDocument->focusedElement
() == element) |
| 648 return true; | 648 return true; |
| 649 | 649 |
| 650 clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), element
); | 650 clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), element
); |
| 651 | 651 |
| 652 if (oldDocument && oldDocument != newDocument) | 652 if (oldDocument && oldDocument != newDocument) |
| 653 oldDocument->setFocusedElement(0); | 653 oldDocument->setFocusedElement(nullptr); |
| 654 | 654 |
| 655 if (newFocusedFrame && !newFocusedFrame->page()) { | 655 if (newFocusedFrame && !newFocusedFrame->page()) { |
| 656 setFocusedFrame(0); | 656 setFocusedFrame(nullptr); |
| 657 return false; | 657 return false; |
| 658 } | 658 } |
| 659 setFocusedFrame(newFocusedFrame); | 659 setFocusedFrame(newFocusedFrame); |
| 660 | 660 |
| 661 // Setting the focused node can result in losing our last reft to node when
JS event handlers fire. | 661 // Setting the focused node can result in losing our last reft to node when
JS event handlers fire. |
| 662 RefPtr<Element> protect = element; | 662 RefPtr<Element> protect = element; |
| 663 if (newDocument) { | 663 if (newDocument) { |
| 664 bool successfullyFocused = newDocument->setFocusedElement(element, type)
; | 664 bool successfullyFocused = newDocument->setFocusedElement(element, type)
; |
| 665 if (!successfullyFocused) | 665 if (!successfullyFocused) |
| 666 return false; | 666 return false; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b
order */); | 902 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b
order */); |
| 903 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type,
container); | 903 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type,
container); |
| 904 if (container && container->isDocumentNode()) | 904 if (container && container->isDocumentNode()) |
| 905 toDocument(container)->updateLayoutIgnorePendingStylesheets(); | 905 toDocument(container)->updateLayoutIgnorePendingStylesheets(); |
| 906 } while (!consumed && container); | 906 } while (!consumed && container); |
| 907 | 907 |
| 908 return consumed; | 908 return consumed; |
| 909 } | 909 } |
| 910 | 910 |
| 911 } // namespace WebCore | 911 } // namespace WebCore |
| OLD | NEW |