2010-12-07  Antonio Gomes  <agomes@rim.com>

        Reviewed by Daniel Bates.

        Spatial Navigation: code clean up
        https://bugs.webkit.org/show_bug.cgi?id=50666

        Patch unifies two FocusCandidate constructors, making caller sites
        simpler. Now the special handling HTMLAreaElement gets is done within
        the non default constructor (i.e. FocusCanditate(Node*, FocusDirection)).

        No new tests needed.

        * page/FocusController.cpp:
        (WebCore::FocusController::findFocusCandidateInContainer):
        * page/SpatialNavigation.cpp:
        (WebCore::FocusCandidate::FocusCandidate):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73627 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/page/SpatialNavigation.cpp b/WebCore/page/SpatialNavigation.cpp
index 1750500..f6ba009 100644
--- a/WebCore/page/SpatialNavigation.cpp
+++ b/WebCore/page/SpatialNavigation.cpp
@@ -36,6 +36,7 @@
 #include "HTMLFrameOwnerElement.h"
 #include "HTMLImageElement.h"
 #include "HTMLMapElement.h"
+#include "HTMLNames.h"
 #include "IntRect.h"
 #include "Node.h"
 #include "Page.h"
@@ -55,20 +56,6 @@
 
 
 FocusCandidate::FocusCandidate(Node* n, FocusDirection direction)
-    : visibleNode(n)
-    , focusableNode(n)
-    , enclosingScrollableBox(0)
-    , distance(maxDistance())
-    , parentDistance(maxDistance())
-    , alignment(None)
-    , parentAlignment(None)
-    , rect(nodeRectInAbsoluteCoordinates(n, true /* ignore border */))
-    , isOffscreen(hasOffscreenRect(n))
-    , isOffscreenAfterScrolling(hasOffscreenRect(n, direction))
-{
-}
-
-FocusCandidate::FocusCandidate(HTMLAreaElement* area, FocusDirection direction)
     : visibleNode(0)
     , focusableNode(0)
     , enclosingScrollableBox(0)
@@ -79,15 +66,25 @@
     , isOffscreen(true)
     , isOffscreenAfterScrolling(true)
 {
-    HTMLImageElement* image = area->imageElement();
-    if (!image)
-        return;
+    if (n->hasTagName(HTMLNames::areaTag)) {
+        HTMLAreaElement* area = static_cast<HTMLAreaElement*>(n);
+        HTMLImageElement* image = area->imageElement();
+        if (!image || !image->renderer())
+            return;
 
-    focusableNode = area;
-    visibleNode = image;
-    rect = virtualRectForAreaElementAndDirection(direction, area);
-    isOffscreen = hasOffscreenRect(image);
-    isOffscreenAfterScrolling = hasOffscreenRect(image, direction);
+        visibleNode = image;
+        rect = virtualRectForAreaElementAndDirection(direction, area);
+    } else {
+        if (!n->renderer())
+            return;
+
+        visibleNode = n;
+        rect = nodeRectInAbsoluteCoordinates(n, true /* ignore border */);
+    }
+
+    focusableNode = n;
+    isOffscreen = hasOffscreenRect(visibleNode);
+    isOffscreenAfterScrolling = hasOffscreenRect(visibleNode, direction);
 }
 
 bool isSpatialNavigationEnabled(const Frame* frame)