Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / page / FocusController.cpp
index 149ff8a..f9cb3d9 100644 (file)
@@ -40,8 +40,8 @@
 #include "core/editing/FrameSelection.h"
 #include "core/editing/htmlediting.h" // For firstPositionInOrBeforeNode
 #include "core/events/Event.h"
-#include "core/frame/LocalDOMWindow.h"
 #include "core/frame/FrameView.h"
+#include "core/frame/LocalDOMWindow.h"
 #include "core/frame/LocalFrame.h"
 #include "core/html/HTMLAreaElement.h"
 #include "core/html/HTMLImageElement.h"
@@ -162,9 +162,9 @@ static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool
         focusedElement->setFocus(true);
         focusedElement->dispatchFocusEvent(0, FocusTypePage);
         if (focusedElement == document->focusedElement()) {
-            document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, 0);
+            document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, 0, FocusTypePage);
             if (focusedElement == document->focusedElement())
-                document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, 0);
+                document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, 0, FocusTypePage);
         }
     }
 }
@@ -229,12 +229,12 @@ FocusController::FocusController(Page* page)
 {
 }
 
-PassOwnPtr<FocusController> FocusController::create(Page* page)
+PassOwnPtrWillBeRawPtr<FocusController> FocusController::create(Page* page)
 {
-    return adoptPtr(new FocusController(page));
+    return adoptPtrWillBeNoop(new FocusController(page));
 }
 
-void FocusController::setFocusedFrame(PassRefPtr<Frame> frame)
+void FocusController::setFocusedFrame(PassRefPtrWillBeRawPtr<Frame> frame)
 {
     ASSERT(!frame || frame->page() == m_page);
     if (m_focusedFrame == frame || m_isChangingFocusedFrame)
@@ -242,8 +242,9 @@ void FocusController::setFocusedFrame(PassRefPtr<Frame> frame)
 
     m_isChangingFocusedFrame = true;
 
-    RefPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
-    RefPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : 0;
+    RefPtrWillBeRawPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
+
+    RefPtrWillBeRawPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : 0;
 
     m_focusedFrame = frame.get();
 
@@ -263,13 +264,13 @@ void FocusController::setFocusedFrame(PassRefPtr<Frame> frame)
     m_page->chrome().client().focusedFrameChanged(newFrame.get());
 }
 
-void FocusController::focusDocumentView(PassRefPtr<Frame> frame)
+void FocusController::focusDocumentView(PassRefPtrWillBeRawPtr<Frame> frame)
 {
     ASSERT(!frame || frame->page() == m_page);
     if (m_focusedFrame == frame)
         return;
 
-    RefPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
+    RefPtrWillBeRawPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
     if (focusedFrame && focusedFrame->view()) {
         RefPtrWillBeRawPtr<Document> document = focusedFrame->document();
         Element* focusedElement = document ? document->focusedElement() : 0;
@@ -283,16 +284,16 @@ void FocusController::focusDocumentView(PassRefPtr<Frame> frame)
         }
     }
 
-    RefPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : 0;
+    RefPtrWillBeRawPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : 0;
     if (newFocusedFrame && newFocusedFrame->view()) {
         RefPtrWillBeRawPtr<Document> document = newFocusedFrame->document();
         Element* focusedElement = document ? document->focusedElement() : 0;
         if (focusedElement) {
             focusedElement->dispatchFocusEvent(0, FocusTypePage);
             if (focusedElement == document->focusedElement()) {
-                document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, 0);
+                document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, 0, FocusTypePage);
                 if (focusedElement == document->focusedElement())
-                    document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, 0);
+                    document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, 0, FocusTypePage);
             }
         }
     }
@@ -579,12 +580,11 @@ Node* FocusController::nextFocusableNode(FocusNavigationScope scope, Node* start
                 if (shouldVisit(node) && adjustedTabIndex(node) >= 0)
                     return node;
             }
+        } else {
+            // First try to find a node with the same tabindex as start that comes after start in the scope.
+            if (Node* winner = findNodeWithExactTabIndex(NodeTraversal::next(*start), tabIndex, FocusTypeForward))
+                return winner;
         }
-
-        // First try to find a node with the same tabindex as start that comes after start in the scope.
-        if (Node* winner = findNodeWithExactTabIndex(NodeTraversal::next(*start), tabIndex, FocusTypeForward))
-            return winner;
-
         if (!tabIndex)
             // We've reached the last node in the document with a tabindex of 0. This is the end of the tabbing order.
             return 0;
@@ -626,11 +626,11 @@ Node* FocusController::previousFocusableNode(FocusNavigationScope scope, Node* s
             if (shouldVisit(node) && adjustedTabIndex(node) >= 0)
                 return node;
         }
+    } else {
+        if (Node* winner = findNodeWithExactTabIndex(startingNode, startingTabIndex, FocusTypeBackward))
+            return winner;
     }
 
-    if (Node* winner = findNodeWithExactTabIndex(startingNode, startingTabIndex, FocusTypeBackward))
-        return winner;
-
     // There are no nodes before start with the same tabindex as start, so look for a node that:
     // 1) has the highest non-zero tabindex (that is less than start's tabindex), and
     // 2) comes last in the scope, if there's a tie.
@@ -674,9 +674,9 @@ static void clearSelectionIfNeeded(LocalFrame* oldFocusedFrame, LocalFrame* newF
     selection.clear();
 }
 
-bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newFocusedFrame, FocusType type)
+bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr<Frame> newFocusedFrame, FocusType type)
 {
-    RefPtr<LocalFrame> oldFocusedFrame = toLocalFrame(focusedFrame());
+    RefPtrWillBeRawPtr<LocalFrame> oldFocusedFrame = toLocalFrame(focusedFrame());
     RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0;
 
     Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0;
@@ -925,4 +925,10 @@ bool FocusController::advanceFocusDirectionally(FocusType type)
     return consumed;
 }
 
+void FocusController::trace(Visitor* visitor)
+{
+    visitor->trace(m_page);
+    visitor->trace(m_focusedFrame);
+}
+
 } // namespace blink