| 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 22 matching lines...) Expand all Loading... |
| 33 #include "core/dom/Element.h" | 33 #include "core/dom/Element.h" |
| 34 #include "core/dom/ElementTraversal.h" | 34 #include "core/dom/ElementTraversal.h" |
| 35 #include "core/dom/NodeTraversal.h" | 35 #include "core/dom/NodeTraversal.h" |
| 36 #include "core/dom/Range.h" | 36 #include "core/dom/Range.h" |
| 37 #include "core/dom/shadow/ElementShadow.h" | 37 #include "core/dom/shadow/ElementShadow.h" |
| 38 #include "core/dom/shadow/ShadowRoot.h" | 38 #include "core/dom/shadow/ShadowRoot.h" |
| 39 #include "core/editing/Editor.h" | 39 #include "core/editing/Editor.h" |
| 40 #include "core/editing/FrameSelection.h" | 40 #include "core/editing/FrameSelection.h" |
| 41 #include "core/editing/htmlediting.h" // For firstPositionInOrBeforeNode | 41 #include "core/editing/htmlediting.h" // For firstPositionInOrBeforeNode |
| 42 #include "core/events/Event.h" | 42 #include "core/events/Event.h" |
| 43 #include "core/frame/FrameProtector.h" |
| 44 #include "core/frame/FrameView.h" |
| 43 #include "core/frame/LocalDOMWindow.h" | 45 #include "core/frame/LocalDOMWindow.h" |
| 44 #include "core/frame/FrameView.h" | |
| 45 #include "core/frame/LocalFrame.h" | 46 #include "core/frame/LocalFrame.h" |
| 46 #include "core/html/HTMLAreaElement.h" | 47 #include "core/html/HTMLAreaElement.h" |
| 47 #include "core/html/HTMLImageElement.h" | 48 #include "core/html/HTMLImageElement.h" |
| 48 #include "core/html/HTMLPlugInElement.h" | 49 #include "core/html/HTMLPlugInElement.h" |
| 49 #include "core/html/HTMLShadowElement.h" | 50 #include "core/html/HTMLShadowElement.h" |
| 50 #include "core/html/HTMLTextFormControlElement.h" | 51 #include "core/html/HTMLTextFormControlElement.h" |
| 51 #include "core/page/Chrome.h" | 52 #include "core/page/Chrome.h" |
| 52 #include "core/page/ChromeClient.h" | 53 #include "core/page/ChromeClient.h" |
| 53 #include "core/page/EventHandler.h" | 54 #include "core/page/EventHandler.h" |
| 54 #include "core/page/FrameTree.h" | 55 #include "core/page/FrameTree.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 223 } |
| 223 | 224 |
| 224 FocusController::FocusController(Page* page) | 225 FocusController::FocusController(Page* page) |
| 225 : m_page(page) | 226 : m_page(page) |
| 226 , m_isActive(false) | 227 , m_isActive(false) |
| 227 , m_isFocused(false) | 228 , m_isFocused(false) |
| 228 , m_isChangingFocusedFrame(false) | 229 , m_isChangingFocusedFrame(false) |
| 229 { | 230 { |
| 230 } | 231 } |
| 231 | 232 |
| 232 PassOwnPtr<FocusController> FocusController::create(Page* page) | 233 PassOwnPtrWillBeRawPtr<FocusController> FocusController::create(Page* page) |
| 233 { | 234 { |
| 234 return adoptPtr(new FocusController(page)); | 235 return adoptPtrWillBeNoop(new FocusController(page)); |
| 235 } | 236 } |
| 236 | 237 |
| 237 void FocusController::setFocusedFrame(PassRefPtr<Frame> frame) | 238 void FocusController::setFocusedFrame(PassRefPtrWillBeRawPtr<Frame> frame) |
| 238 { | 239 { |
| 239 ASSERT(!frame || frame->page() == m_page); | 240 ASSERT(!frame || frame->page() == m_page); |
| 240 if (m_focusedFrame == frame || m_isChangingFocusedFrame) | 241 if (m_focusedFrame == frame || m_isChangingFocusedFrame) |
| 241 return; | 242 return; |
| 242 | 243 |
| 243 m_isChangingFocusedFrame = true; | 244 m_isChangingFocusedFrame = true; |
| 244 | 245 |
| 245 RefPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFram
e()) ? toLocalFrame(m_focusedFrame.get()) : 0; | 246 LocalFrame* oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ?
toLocalFrame(m_focusedFrame.get()) : 0; |
| 246 RefPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFram
e(frame.get()) : 0; | 247 FrameProtector protectOld(oldFrame); |
| 248 |
| 249 LocalFrame* newFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame
.get()) : 0; |
| 250 FrameProtector protectNew(newFrame); |
| 247 | 251 |
| 248 m_focusedFrame = frame.get(); | 252 m_focusedFrame = frame.get(); |
| 249 | 253 |
| 250 // Now that the frame is updated, fire events and update the selection focus
ed states of both frames. | 254 // Now that the frame is updated, fire events and update the selection focus
ed states of both frames. |
| 251 if (oldFrame && oldFrame->view()) { | 255 if (oldFrame && oldFrame->view()) { |
| 252 oldFrame->selection().setFocused(false); | 256 oldFrame->selection().setFocused(false); |
| 253 oldFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::blur)
); | 257 oldFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::blur)
); |
| 254 } | 258 } |
| 255 | 259 |
| 256 if (newFrame && newFrame->view() && isFocused()) { | 260 if (newFrame && newFrame->view() && isFocused()) { |
| 257 newFrame->selection().setFocused(true); | 261 newFrame->selection().setFocused(true); |
| 258 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus
)); | 262 newFrame->domWindow()->dispatchEvent(Event::create(EventTypeNames::focus
)); |
| 259 } | 263 } |
| 260 | 264 |
| 261 m_isChangingFocusedFrame = false; | 265 m_isChangingFocusedFrame = false; |
| 262 | 266 |
| 263 m_page->chrome().client().focusedFrameChanged(newFrame.get()); | 267 m_page->chrome().client().focusedFrameChanged(newFrame); |
| 264 } | 268 } |
| 265 | 269 |
| 266 void FocusController::focusDocumentView(PassRefPtr<Frame> frame) | 270 void FocusController::focusDocumentView(PassRefPtrWillBeRawPtr<Frame> frame) |
| 267 { | 271 { |
| 268 ASSERT(!frame || frame->page() == m_page); | 272 ASSERT(!frame || frame->page() == m_page); |
| 269 if (m_focusedFrame == frame) | 273 if (m_focusedFrame == frame) |
| 270 return; | 274 return; |
| 271 | 275 |
| 272 RefPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFrame->isLocal
Frame()) ? toLocalFrame(m_focusedFrame.get()) : 0; | 276 LocalFrame* focusedFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()
) ? toLocalFrame(m_focusedFrame.get()) : 0; |
| 277 FrameProtector protect(focusedFrame); |
| 273 if (focusedFrame && focusedFrame->view()) { | 278 if (focusedFrame && focusedFrame->view()) { |
| 274 RefPtrWillBeRawPtr<Document> document = focusedFrame->document(); | 279 RefPtrWillBeRawPtr<Document> document = focusedFrame->document(); |
| 275 Element* focusedElement = document ? document->focusedElement() : 0; | 280 Element* focusedElement = document ? document->focusedElement() : 0; |
| 276 if (focusedElement) { | 281 if (focusedElement) { |
| 277 focusedElement->dispatchBlurEvent(0); | 282 focusedElement->dispatchBlurEvent(0); |
| 278 if (focusedElement == document->focusedElement()) { | 283 if (focusedElement == document->focusedElement()) { |
| 279 focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout,
0); | 284 focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout,
0); |
| 280 if (focusedElement == document->focusedElement()) | 285 if (focusedElement == document->focusedElement()) |
| 281 focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFoc
usOut, 0); | 286 focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFoc
usOut, 0); |
| 282 } | 287 } |
| 283 } | 288 } |
| 284 } | 289 } |
| 285 | 290 |
| 286 RefPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFrame()) ? toLo
calFrame(frame.get()) : 0; | 291 LocalFrame* newFocusedFrame = (frame && frame->isLocalFrame()) ? toLocalFram
e(frame.get()) : 0; |
| 292 FrameProtector protectNew(newFocusedFrame); |
| 287 if (newFocusedFrame && newFocusedFrame->view()) { | 293 if (newFocusedFrame && newFocusedFrame->view()) { |
| 288 RefPtrWillBeRawPtr<Document> document = newFocusedFrame->document(); | 294 RefPtrWillBeRawPtr<Document> document = newFocusedFrame->document(); |
| 289 Element* focusedElement = document ? document->focusedElement() : 0; | 295 Element* focusedElement = document ? document->focusedElement() : 0; |
| 290 if (focusedElement) { | 296 if (focusedElement) { |
| 291 focusedElement->dispatchFocusEvent(0, FocusTypePage); | 297 focusedElement->dispatchFocusEvent(0, FocusTypePage); |
| 292 if (focusedElement == document->focusedElement()) { | 298 if (focusedElement == document->focusedElement()) { |
| 293 document->focusedElement()->dispatchFocusInEvent(EventTypeNames:
:focusin, 0); | 299 document->focusedElement()->dispatchFocusInEvent(EventTypeNames:
:focusin, 0); |
| 294 if (focusedElement == document->focusedElement()) | 300 if (focusedElement == document->focusedElement()) |
| 295 document->focusedElement()->dispatchFocusInEvent(EventTypeNa
mes::DOMFocusIn, 0); | 301 document->focusedElement()->dispatchFocusInEvent(EventTypeNa
mes::DOMFocusIn, 0); |
| 296 } | 302 } |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 673 |
| 668 if (!enclosingTextFormControl(selectionStartNode)) | 674 if (!enclosingTextFormControl(selectionStartNode)) |
| 669 return; | 675 return; |
| 670 | 676 |
| 671 if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost()
== newFocusedNode) | 677 if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost()
== newFocusedNode) |
| 672 return; | 678 return; |
| 673 | 679 |
| 674 selection.clear(); | 680 selection.clear(); |
| 675 } | 681 } |
| 676 | 682 |
| 677 bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newF
ocusedFrame, FocusType type) | 683 bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr
<Frame> newFocusedFrame, FocusType type) |
| 678 { | 684 { |
| 679 RefPtr<LocalFrame> oldFocusedFrame = toLocalFrame(focusedFrame()); | 685 LocalFrame* oldFocusedFrame = toLocalFrame(focusedFrame()); |
| 686 FrameProtector protectOld(oldFocusedFrame); |
| 680 RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame
->document() : 0; | 687 RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame
->document() : 0; |
| 681 | 688 |
| 682 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0
; | 689 Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0
; |
| 683 if (element && oldFocusedElement == element) | 690 if (element && oldFocusedElement == element) |
| 684 return true; | 691 return true; |
| 685 | 692 |
| 686 // FIXME: Might want to disable this check for caretBrowsing | 693 // FIXME: Might want to disable this check for caretBrowsing |
| 687 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli
nquishesEditingFocus(oldFocusedElement)) | 694 if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !reli
nquishesEditingFocus(oldFocusedElement)) |
| 688 return false; | 695 return false; |
| 689 | 696 |
| 690 m_page->chrome().client().willSetInputMethodState(); | 697 m_page->chrome().client().willSetInputMethodState(); |
| 691 | 698 |
| 692 RefPtrWillBeRawPtr<Document> newDocument = nullptr; | 699 RefPtrWillBeRawPtr<Document> newDocument = nullptr; |
| 693 if (element) | 700 if (element) |
| 694 newDocument = &element->document(); | 701 newDocument = &element->document(); |
| 695 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) | 702 else if (newFocusedFrame && newFocusedFrame->isLocalFrame()) |
| 696 newDocument = toLocalFrame(newFocusedFrame.get())->document(); | 703 newDocument = toLocalFrame(newFocusedFrame.get())->document(); |
| 697 | 704 |
| 698 if (newDocument && oldDocument == newDocument && newDocument->focusedElement
() == element) | 705 if (newDocument && oldDocument == newDocument && newDocument->focusedElement
() == element) |
| 699 return true; | 706 return true; |
| 700 | 707 |
| 701 clearSelectionIfNeeded(oldFocusedFrame.get(), toLocalFrame(newFocusedFrame.g
et()), element); | 708 clearSelectionIfNeeded(oldFocusedFrame, toLocalFrame(newFocusedFrame.get()),
element); |
| 702 | 709 |
| 703 if (oldDocument && oldDocument != newDocument) | 710 if (oldDocument && oldDocument != newDocument) |
| 704 oldDocument->setFocusedElement(nullptr); | 711 oldDocument->setFocusedElement(nullptr); |
| 705 | 712 |
| 706 if (newFocusedFrame && !newFocusedFrame->page()) { | 713 if (newFocusedFrame && !newFocusedFrame->page()) { |
| 707 setFocusedFrame(nullptr); | 714 setFocusedFrame(nullptr); |
| 708 return false; | 715 return false; |
| 709 } | 716 } |
| 710 setFocusedFrame(newFocusedFrame); | 717 setFocusedFrame(newFocusedFrame); |
| 711 | 718 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 consumed = advanceFocusDirectionallyInContainer(container, startingRect,
type); | 925 consumed = advanceFocusDirectionallyInContainer(container, startingRect,
type); |
| 919 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b
order */); | 926 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b
order */); |
| 920 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type,
container); | 927 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(type,
container); |
| 921 if (container && container->isDocumentNode()) | 928 if (container && container->isDocumentNode()) |
| 922 toDocument(container)->updateLayoutIgnorePendingStylesheets(); | 929 toDocument(container)->updateLayoutIgnorePendingStylesheets(); |
| 923 } while (!consumed && container); | 930 } while (!consumed && container); |
| 924 | 931 |
| 925 return consumed; | 932 return consumed; |
| 926 } | 933 } |
| 927 | 934 |
| 935 void FocusController::trace(Visitor* visitor) |
| 936 { |
| 937 visitor->trace(m_focusedFrame); |
| 938 } |
| 939 |
| 928 } // namespace blink | 940 } // namespace blink |
| OLD | NEW |