Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / page / FocusController.cpp
index 48d9e8c..21c276e 100644 (file)
@@ -91,45 +91,44 @@ Element* FocusNavigationScope::owner() const
     // FIXME: Figure out the right thing for OOPI here.
     if (Frame* frame = root->document().frame())
         return frame->deprecatedLocalOwner();
-    return 0;
+    return nullptr;
 }
 
-FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node* node)
+FocusNavigationScope FocusNavigationScope::focusNavigationScopeOf(Node& node)
 {
-    ASSERT(node);
-    Node* root = node;
-    for (Node* n = node; n; n = n->parentNode())
+    Node* root = &node;
+    for (Node* n = &node; n; n = n->parentNode())
         root = n;
     // The result is not always a ShadowRoot nor a DocumentNode since
     // a starting node is in an orphaned tree in composed shadow tree.
     return FocusNavigationScope(&root->treeScope());
 }
 
-FocusNavigationScope FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(Node* node)
+FocusNavigationScope FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(Node& node)
 {
-    ASSERT(node);
     if (isShadowHost(node))
         return FocusNavigationScope::ownedByShadowHost(node);
-    ASSERT(isShadowInsertionPointFocusScopeOwner(*node));
+    ASSERT(isShadowInsertionPointFocusScopeOwner(node));
     return FocusNavigationScope::ownedByShadowInsertionPoint(toHTMLShadowElement(node));
 }
 
-FocusNavigationScope FocusNavigationScope::ownedByShadowHost(Node* node)
+FocusNavigationScope FocusNavigationScope::ownedByShadowHost(Node& node)
 {
     ASSERT(isShadowHost(node));
-    return FocusNavigationScope(toElement(node)->shadow()->youngestShadowRoot());
+    return FocusNavigationScope(toElement(node).shadow()->youngestShadowRoot());
 }
 
-FocusNavigationScope FocusNavigationScope::ownedByIFrame(HTMLFrameOwnerElement* frame)
+FocusNavigationScope FocusNavigationScope::ownedByIFrame(HTMLFrameOwnerElement& frame)
 {
-    ASSERT(frame && frame->contentFrame() && frame->contentFrame()->isLocalFrame());
-    return FocusNavigationScope(toLocalFrame(frame->contentFrame())->document());
+    ASSERT(frame.contentFrame());
+    ASSERT(frame.contentFrame()->isLocalFrame());
+    return FocusNavigationScope(toLocalFrame(frame.contentFrame())->document());
 }
 
-FocusNavigationScope FocusNavigationScope::ownedByShadowInsertionPoint(HTMLShadowElement* shadowInsertionPoint)
+FocusNavigationScope FocusNavigationScope::ownedByShadowInsertionPoint(HTMLShadowElement& shadowInsertionPoint)
 {
-    ASSERT(isShadowInsertionPointFocusScopeOwner(*shadowInsertionPoint));
-    return FocusNavigationScope(shadowInsertionPoint->olderShadowRoot());
+    ASSERT(isShadowInsertionPointFocusScopeOwner(shadowInsertionPoint));
+    return FocusNavigationScope(shadowInsertionPoint.olderShadowRoot());
 }
 
 static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool focused)
@@ -147,11 +146,11 @@ static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool
     if (!focused && document->focusedElement()) {
         RefPtrWillBeRawPtr<Element> focusedElement(document->focusedElement());
         focusedElement->setFocus(false);
-        focusedElement->dispatchBlurEvent(0);
+        focusedElement->dispatchBlurEvent(nullptr);
         if (focusedElement == document->focusedElement()) {
-            focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, 0);
+            focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, nullptr);
             if (focusedElement == document->focusedElement())
-                focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, 0);
+                focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, nullptr);
         }
     }
 
@@ -162,63 +161,57 @@ static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool
         focusedElement->setFocus(true);
         focusedElement->dispatchFocusEvent(0, FocusTypePage);
         if (focusedElement == document->focusedElement()) {
-            document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, 0, FocusTypePage);
+            document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, nullptr, FocusTypePage);
             if (focusedElement == document->focusedElement())
-                document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, 0, FocusTypePage);
+                document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, nullptr, FocusTypePage);
         }
     }
 }
 
-static inline bool hasCustomFocusLogic(Element* element)
+static inline bool hasCustomFocusLogic(const Element& element)
 {
-    return element->isHTMLElement() && toHTMLElement(element)->hasCustomFocusLogic();
+    return element.isHTMLElement() && toHTMLElement(element).hasCustomFocusLogic();
 }
 
 #if ENABLE(ASSERT)
-static inline bool isNonFocusableShadowHost(Node* node)
+static inline bool isNonFocusableShadowHost(const Node& node)
 {
-    ASSERT(node);
-    if (!node->isElementNode())
+    if (!node.isElementNode())
         return false;
-    Element* element = toElement(node);
-    return !element->isFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
+    const Element& element = toElement(node);
+    return !element.isFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
 }
 #endif
 
-static inline bool isNonKeyboardFocusableShadowHost(Node* node)
+static inline bool isNonKeyboardFocusableShadowHost(const Node& node)
 {
-    ASSERT(node);
-    if (!node->isElementNode())
+    if (!node.isElementNode())
         return false;
-    Element* element = toElement(node);
-    return !element->isKeyboardFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
+    const Element& element = toElement(node);
+    return !element.isKeyboardFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
 }
 
-static inline bool isKeyboardFocusableShadowHost(Node* node)
+static inline bool isKeyboardFocusableShadowHost(const Node& node)
 {
-    ASSERT(node);
-    if (!node->isElementNode())
+    if (!node.isElementNode())
         return false;
-    Element* element = toElement(node);
-    return element->isKeyboardFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
+    const Element& element = toElement(node);
+    return element.isKeyboardFocusable() && isShadowHost(element) && !hasCustomFocusLogic(element);
 }
 
-static inline bool isNonFocusableFocusScopeOwner(Node* node)
+static inline bool isNonFocusableFocusScopeOwner(Node& node)
 {
-    ASSERT(node);
-    return isNonKeyboardFocusableShadowHost(node) || isShadowInsertionPointFocusScopeOwner(*node);
+    return isNonKeyboardFocusableShadowHost(node) || isShadowInsertionPointFocusScopeOwner(node);
 }
 
-static inline int adjustedTabIndex(Node* node)
+static inline int adjustedTabIndex(Node& node)
 {
-    ASSERT(node);
-    return isNonFocusableFocusScopeOwner(node) ? 0 : node->tabIndex();
+    return isNonFocusableFocusScopeOwner(node) ? 0 : node.tabIndex();
 }
 
-static inline bool shouldVisit(Node* node)
+static inline bool shouldVisit(Node& node)
 {
-    ASSERT(node);
-    return (node->isElementNode() && toElement(node)->isKeyboardFocusable()) || isNonFocusableFocusScopeOwner(node);
+    return (node.isElementNode() && toElement(node).isKeyboardFocusable()) || isNonFocusableFocusScopeOwner(node);
 }
 
 FocusController::FocusController(Page* page)
@@ -242,9 +235,9 @@ void FocusController::setFocusedFrame(PassRefPtrWillBeRawPtr<Frame> frame)
 
     m_isChangingFocusedFrame = true;
 
-    RefPtrWillBeRawPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
+    RefPtrWillBeRawPtr<LocalFrame> oldFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : nullptr;
 
-    RefPtrWillBeRawPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : 0;
+    RefPtrWillBeRawPtr<LocalFrame> newFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : nullptr;
 
     m_focusedFrame = frame.get();
 
@@ -270,30 +263,30 @@ void FocusController::focusDocumentView(PassRefPtrWillBeRawPtr<Frame> frame)
     if (m_focusedFrame == frame)
         return;
 
-    RefPtrWillBeRawPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : 0;
+    RefPtrWillBeRawPtr<LocalFrame> focusedFrame = (m_focusedFrame && m_focusedFrame->isLocalFrame()) ? toLocalFrame(m_focusedFrame.get()) : nullptr;
     if (focusedFrame && focusedFrame->view()) {
         RefPtrWillBeRawPtr<Document> document = focusedFrame->document();
-        Element* focusedElement = document ? document->focusedElement() : 0;
+        Element* focusedElement = document ? document->focusedElement() : nullptr;
         if (focusedElement) {
-            focusedElement->dispatchBlurEvent(0);
+            focusedElement->dispatchBlurEvent(nullptr);
             if (focusedElement == document->focusedElement()) {
-                focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, 0);
+                focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, nullptr);
                 if (focusedElement == document->focusedElement())
-                    focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, 0);
+                    focusedElement->dispatchFocusOutEvent(EventTypeNames::DOMFocusOut, nullptr);
             }
         }
     }
 
-    RefPtrWillBeRawPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : 0;
+    RefPtrWillBeRawPtr<LocalFrame> newFocusedFrame = (frame && frame->isLocalFrame()) ? toLocalFrame(frame.get()) : nullptr;
     if (newFocusedFrame && newFocusedFrame->view()) {
         RefPtrWillBeRawPtr<Document> document = newFocusedFrame->document();
-        Element* focusedElement = document ? document->focusedElement() : 0;
+        Element* focusedElement = document ? document->focusedElement() : nullptr;
         if (focusedElement) {
             focusedElement->dispatchFocusEvent(0, FocusTypePage);
             if (focusedElement == document->focusedElement()) {
-                document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, 0, FocusTypePage);
+                document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, nullptr, FocusTypePage);
                 if (focusedElement == document->focusedElement())
-                    document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, 0, FocusTypePage);
+                    document->focusedElement()->dispatchFocusInEvent(EventTypeNames::DOMFocusIn, nullptr, FocusTypePage);
             }
         }
     }
@@ -343,10 +336,10 @@ Node* FocusController::findFocusableNodeDecendingDownIntoFrameDocument(FocusType
     // 1) a focusable node, or
     // 2) the deepest-nested HTMLFrameOwnerElement.
     while (node && node->isFrameOwnerElement()) {
-        HTMLFrameOwnerElement* owner = toHTMLFrameOwnerElement(node);
-        if (!owner->contentFrame() || !owner->contentFrame()->isLocalFrame())
+        HTMLFrameOwnerElement& owner = toHTMLFrameOwnerElement(*node);
+        if (!owner.contentFrame() || !owner.contentFrame()->isLocalFrame())
             break;
-        Node* foundNode = findFocusableNode(type, FocusNavigationScope::ownedByIFrame(owner), 0);
+        Node* foundNode = findFocusableNode(type, FocusNavigationScope::ownedByIFrame(owner), nullptr);
         if (!foundNode)
             break;
         ASSERT(node != foundNode);
@@ -365,7 +358,7 @@ bool FocusController::setInitialFocus(FocusType type)
     if (focusedOrMainFrame()->isLocalFrame()) {
         Document* document = toLocalFrame(focusedOrMainFrame())->document();
         if (AXObjectCache* cache = document->existingAXObjectCache())
-            cache->postNotification(document, AXObjectCache::AXFocusedUIElementChanged, true);
+            cache->handleInitialFocus();
     }
 
     return didAdvanceFocus;
@@ -408,7 +401,7 @@ bool FocusController::advanceFocusInDocumentOrder(FocusType type, bool initialFo
 
     document->updateLayoutIgnorePendingStylesheets();
 
-    RefPtrWillBeRawPtr<Node> node = findFocusableNodeAcrossFocusScope(type, FocusNavigationScope::focusNavigationScopeOf(currentNode ? currentNode : document), currentNode);
+    RefPtrWillBeRawPtr<Node> node = findFocusableNodeAcrossFocusScope(type, FocusNavigationScope::focusNavigationScopeOf(currentNode ? *currentNode : *document), currentNode);
 
     if (!node) {
         // We didn't find a node to focus, so we should try to pass focus to Chrome.
@@ -422,7 +415,7 @@ bool FocusController::advanceFocusInDocumentOrder(FocusType type, bool initialFo
         // Chrome doesn't want focus, so we should wrap focus.
         if (!m_page->mainFrame()->isLocalFrame())
             return false;
-        node = findFocusableNodeRecursively(type, FocusNavigationScope::focusNavigationScopeOf(m_page->deprecatedLocalMainFrame()->document()), 0);
+        node = findFocusableNodeRecursively(type, FocusNavigationScope::focusNavigationScopeOf(*m_page->deprecatedLocalMainFrame()->document()), nullptr);
         node = findFocusableNodeDecendingDownIntoFrameDocument(type, node.get());
 
         if (!node)
@@ -476,10 +469,10 @@ bool FocusController::advanceFocusInDocumentOrder(FocusType type, bool initialFo
 
 Node* FocusController::findFocusableNodeAcrossFocusScope(FocusType type, FocusNavigationScope scope, Node* currentNode)
 {
-    ASSERT(!currentNode || !isNonFocusableShadowHost(currentNode));
+    ASSERT(!currentNode || !isNonFocusableShadowHost(*currentNode));
     Node* found;
-    if (currentNode && type == FocusTypeForward && isKeyboardFocusableShadowHost(currentNode)) {
-        Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByShadowHost(currentNode), 0);
+    if (currentNode && type == FocusTypeForward && isKeyboardFocusableShadowHost(*currentNode)) {
+        Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByShadowHost(*currentNode), nullptr);
         found = foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableNodeRecursively(type, scope, currentNode);
     } else {
         found = findFocusableNodeRecursively(type, scope, currentNode);
@@ -490,8 +483,8 @@ Node* FocusController::findFocusableNodeAcrossFocusScope(FocusType type, FocusNa
         Node* owner = scope.owner();
         if (!owner)
             break;
-        scope = FocusNavigationScope::focusNavigationScopeOf(owner);
-        if (type == FocusTypeBackward && isKeyboardFocusableShadowHost(owner)) {
+        scope = FocusNavigationScope::focusNavigationScopeOf(*owner);
+        if (type == FocusTypeBackward && isKeyboardFocusableShadowHost(*owner)) {
             found = owner;
             break;
         }
@@ -504,25 +497,26 @@ Node* FocusController::findFocusableNodeAcrossFocusScope(FocusType type, FocusNa
 Node* FocusController::findFocusableNodeRecursively(FocusType type, FocusNavigationScope scope, Node* start)
 {
     // Starting node is exclusive.
-    Node* found = findFocusableNode(type, scope, start);
-    if (!found)
-        return 0;
+    Node* foundOrNull = findFocusableNode(type, scope, start);
+    if (!foundOrNull)
+        return nullptr;
+    Node& found = *foundOrNull;
     if (type == FocusTypeForward) {
         if (!isNonFocusableFocusScopeOwner(found))
-            return found;
-        Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(found), 0);
-        return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableNodeRecursively(type, scope, found);
+            return &found;
+        Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(found), nullptr);
+        return foundInInnerFocusScope ? foundInInnerFocusScope : findFocusableNodeRecursively(type, scope, &found);
     }
     ASSERT(type == FocusTypeBackward);
     if (isKeyboardFocusableShadowHost(found)) {
-        Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByShadowHost(found), 0);
-        return foundInInnerFocusScope ? foundInInnerFocusScope : found;
+        Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByShadowHost(found), nullptr);
+        return foundInInnerFocusScope ? foundInInnerFocusScope : &found;
     }
     if (isNonFocusableFocusScopeOwner(found)) {
-        Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(found), 0);
-        return foundInInnerFocusScope ? foundInInnerFocusScope :findFocusableNodeRecursively(type, scope, found);
+        Node* foundInInnerFocusScope = findFocusableNodeRecursively(type, FocusNavigationScope::ownedByNonFocusableFocusScopeOwner(found), nullptr);
+        return foundInInnerFocusScope ? foundInInnerFocusScope :findFocusableNodeRecursively(type, scope, &found);
     }
-    return found;
+    return &found;
 }
 
 Node* FocusController::findFocusableNode(FocusType type, FocusNavigationScope scope, Node* node)
@@ -534,21 +528,21 @@ Node* FocusController::findNodeWithExactTabIndex(Node* start, int tabIndex, Focu
 {
     // Search is inclusive of start
     for (Node* node = start; node; node = type == FocusTypeForward ? NodeTraversal::next(*node) : NodeTraversal::previous(*node)) {
-        if (shouldVisit(node) && adjustedTabIndex(node) == tabIndex)
+        if (shouldVisit(*node) && adjustedTabIndex(*node) == tabIndex)
             return node;
     }
-    return 0;
+    return nullptr;
 }
 
 static Node* nextNodeWithGreaterTabIndex(Node* start, int tabIndex)
 {
     // Search is inclusive of start
     int winningTabIndex = std::numeric_limits<short>::max() + 1;
-    Node* winner = 0;
-    for (Node* node = start; node; node = NodeTraversal::next(*node)) {
+    Node* winner = nullptr;
+    for (Node& node : NodeTraversal::startsAt(start)) {
         int currentTabIndex = adjustedTabIndex(node);
         if (shouldVisit(node) && currentTabIndex > tabIndex && currentTabIndex < winningTabIndex) {
-            winner = node;
+            winner = &node;
             winningTabIndex = currentTabIndex;
         }
     }
@@ -560,10 +554,10 @@ static Node* previousNodeWithLowerTabIndex(Node* start, int tabIndex)
 {
     // Search is inclusive of start
     int winningTabIndex = 0;
-    Node* winner = 0;
+    Node* winner = nullptr;
     for (Node* node = start; node; node = NodeTraversal::previous(*node)) {
-        int currentTabIndex = adjustedTabIndex(node);
-        if ((shouldVisit(node) || isNonKeyboardFocusableShadowHost(node)) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) {
+        int currentTabIndex = adjustedTabIndex(*node);
+        if (shouldVisit(*node) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) {
             winner = node;
             winningTabIndex = currentTabIndex;
         }
@@ -574,27 +568,28 @@ static Node* previousNodeWithLowerTabIndex(Node* start, int tabIndex)
 Node* FocusController::nextFocusableNode(FocusNavigationScope scope, Node* start)
 {
     if (start) {
-        int tabIndex = adjustedTabIndex(start);
+        int tabIndex = adjustedTabIndex(*start);
         // If a node is excluded from the normal tabbing cycle, the next focusable node is determined by tree order
         if (tabIndex < 0) {
-            for (Node* node = NodeTraversal::next(*start); node; node = NodeTraversal::next(*node)) {
+            for (Node& node : NodeTraversal::startsAfter(*start)) {
                 if (shouldVisit(node) && adjustedTabIndex(node) >= 0)
-                    return node;
+                    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;
         }
-        if (!tabIndex)
+        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;
+            return nullptr;
+        }
     }
 
     // Look for the first node in the scope that:
     // 1) has the lowest tabindex that is higher than start's tabindex (or 0, if start is null), and
     // 2) comes first in the scope, if there's a tie.
-    if (Node* winner = nextNodeWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(start) : 0))
+    if (Node* winner = nextNodeWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(*start) : 0))
         return winner;
 
     // There are no nodes with a tabindex greater than start's tabindex,
@@ -604,7 +599,7 @@ Node* FocusController::nextFocusableNode(FocusNavigationScope scope, Node* start
 
 Node* FocusController::previousFocusableNode(FocusNavigationScope scope, Node* start)
 {
-    Node* last = 0;
+    Node* last = nullptr;
     for (Node* node = scope.rootNode(); node; node = node->lastChild())
         last = node;
     ASSERT(last);
@@ -615,7 +610,7 @@ Node* FocusController::previousFocusableNode(FocusNavigationScope scope, Node* s
     int startingTabIndex;
     if (start) {
         startingNode = NodeTraversal::previous(*start);
-        startingTabIndex = adjustedTabIndex(start);
+        startingTabIndex = adjustedTabIndex(*start);
     } else {
         startingNode = last;
         startingTabIndex = 0;
@@ -624,7 +619,7 @@ Node* FocusController::previousFocusableNode(FocusNavigationScope scope, Node* s
     // However, if a node is excluded from the normal tabbing cycle, the previous focusable node is determined by tree order
     if (startingTabIndex < 0) {
         for (Node* node = startingNode; node; node = NodeTraversal::previous(*node)) {
-            if (shouldVisit(node) && adjustedTabIndex(node) >= 0)
+            if (shouldVisit(*node) && adjustedTabIndex(*node) >= 0)
                 return node;
         }
     } else {
@@ -639,11 +634,10 @@ Node* FocusController::previousFocusableNode(FocusNavigationScope scope, Node* s
     return previousNodeWithLowerTabIndex(last, startingTabIndex);
 }
 
-static bool relinquishesEditingFocus(Node *node)
+static bool relinquishesEditingFocus(const Element& element)
 {
-    ASSERT(node);
-    ASSERT(node->hasEditableStyle());
-    return node->document().frame() && node->rootEditableElement();
+    ASSERT(element.hasEditableStyle());
+    return element.document().frame() && element.rootEditableElement();
 }
 
 static void clearSelectionIfNeeded(LocalFrame* oldFocusedFrame, LocalFrame* newFocusedFrame, Node* newFocusedNode)
@@ -678,14 +672,14 @@ static void clearSelectionIfNeeded(LocalFrame* oldFocusedFrame, LocalFrame* newF
 bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr<Frame> newFocusedFrame, FocusType type)
 {
     RefPtrWillBeRawPtr<LocalFrame> oldFocusedFrame = toLocalFrame(focusedFrame());
-    RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0;
+    RefPtrWillBeRawPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : nullptr;
 
-    Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : 0;
+    Element* oldFocusedElement = oldDocument ? oldDocument->focusedElement() : nullptr;
     if (element && oldFocusedElement == element)
         return true;
 
     // FIXME: Might want to disable this check for caretBrowsing
-    if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !relinquishesEditingFocus(oldFocusedElement))
+    if (oldFocusedElement && oldFocusedElement->isRootEditableElement() && !relinquishesEditingFocus(*oldFocusedElement))
         return false;
 
     m_page->chrome().client().willSetInputMethodState();
@@ -711,7 +705,8 @@ bool FocusController::setFocusedElement(Element* element, PassRefPtrWillBeRawPtr
     setFocusedFrame(newFocusedFrame);
 
     // Setting the focused node can result in losing our last reft to node when JS event handlers fire.
-    RefPtrWillBeRawPtr<Element> protect ALLOW_UNUSED = element;
+    RefPtrWillBeRawPtr<Element> protect = element;
+    ALLOW_UNUSED_LOCAL(protect);
     if (newDocument) {
         bool successfullyFocused = newDocument->setFocusedElement(element, type);
         if (!successfullyFocused)
@@ -787,7 +782,7 @@ static void updateFocusCandidateIfNeeded(FocusType type, const FocusCandidate& c
 
 void FocusController::findFocusCandidateInContainer(Node& container, const LayoutRect& startingRect, FocusType type, FocusCandidate& closest)
 {
-    Element* focusedElement = (focusedFrame() && toLocalFrame(focusedFrame())->document()) ? toLocalFrame(focusedFrame())->document()->focusedElement() : 0;
+    Element* focusedElement = (focusedFrame() && toLocalFrame(focusedFrame())->document()) ? toLocalFrame(focusedFrame())->document()->focusedElement() : nullptr;
 
     Element* element = ElementTraversal::firstWithin(container);
     FocusCandidate current;