2011-02-01  Darin Adler  <darin@apple.com>

        Reviewed by Chris Fleizach.

        REGRESSION: Removing focus from area element causes unwanted scrolling
        https://bugs.webkit.org/show_bug.cgi?id=50169

        Test: fast/images/imagemap-scroll.html

        * html/HTMLAreaElement.cpp:
        (WebCore::HTMLAreaElement::setFocus): Added override. Calls the new
        RenderImage::areaElementFocusChanged function.
        (WebCore::HTMLAreaElement::updateFocusAppearance): Removed the code
        here that calls setNeedsLayout on the image's renderer. This was an
        attempt to cause repaint of the renderer, but this function does not
        need to do that. Also changed this to use the imageElement function
        to avoid repeating code.

        * html/HTMLAreaElement.h: Updated for above changes.

        * rendering/RenderImage.cpp:
        (WebCore::RenderImage::paint): Updated for name change.
        (WebCore::RenderImage::paintAreaElementFocusRing): Renamed this from
        paintFocusRing, because it only paints area focus rings, and should
        not be confused with paintFocusRing functions in other classes. Also
        removed the unused style argument. Removed the code that used an
        HTMLCollection to see if the focused area element is for this image
        and instead just call imageElement on the area element.
        (WebCore::RenderImage::areaElementFocusChanged): Added. Calls repaint.

        * rendering/RenderImage.h: Added a public areaElementFocusChanged
        function for HTMLAreaElement to call. Made the paintFocusRing function
        private, renamed it to paintAreaElementFocusRing, and removed its
        unused style argument.
2011-02-01  Darin Adler  <darin@apple.com>

        Reviewed by Chris Fleizach.

        REGRESSION: Removing focus from area element causes unwanted scrolling
        https://bugs.webkit.org/show_bug.cgi?id=50169

        * fast/images/imagemap-scroll-expected.txt: Added.
        * fast/images/imagemap-scroll.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@77313 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/html/HTMLAreaElement.cpp b/Source/WebCore/html/HTMLAreaElement.cpp
index ac4c865..5b0a028 100644
--- a/Source/WebCore/html/HTMLAreaElement.cpp
+++ b/Source/WebCore/html/HTMLAreaElement.cpp
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2009, 2011 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -30,7 +30,7 @@
 #include "HTMLNames.h"
 #include "HitTestResult.h"
 #include "Path.h"
-#include "RenderObject.h"
+#include "RenderImage.h"
 
 using namespace std;
 
@@ -196,33 +196,34 @@
     return supportsFocus() && Element::tabIndex() >= 0;
 }
     
-void HTMLAreaElement::dispatchBlurEvent()
+void HTMLAreaElement::setFocus(bool shouldBeFocused)
 {
-    HTMLAnchorElement::dispatchBlurEvent();
-    
-    // On a blur, we might need to remove our focus rings by repainting.
-    updateFocusAppearance(false);
+    if (focused() == shouldBeFocused)
+        return;
+
+    HTMLAnchorElement::setFocus(shouldBeFocused);
+
+    HTMLImageElement* imageElement = this->imageElement();
+    if (!imageElement)
+        return;
+
+    RenderObject* renderer = imageElement->renderer();
+    if (!renderer || !renderer->isImage())
+        return;
+
+    toRenderImage(renderer)->areaElementFocusChanged(this);
 }
     
 void HTMLAreaElement::updateFocusAppearance(bool restorePreviousSelection)
 {
     if (!isFocusable())
         return;
-    
-    ContainerNode* parent = parentNode();
-    if (!parent || !parent->hasTagName(mapTag))
-        return;
-    
-    HTMLImageElement* imageElement = static_cast<HTMLMapElement*>(parent)->imageElement();
+
+    HTMLImageElement* imageElement = this->imageElement();
     if (!imageElement)
         return;
-    
-    // This will handle scrolling to the image if necessary.
+
     imageElement->updateFocusAppearance(restorePreviousSelection);
-    
-    RenderObject* imageRenderer = imageElement->renderer();
-    if (imageRenderer)
-        imageRenderer->setNeedsLayout(true);
 }
     
 bool HTMLAreaElement::supportsFocus() const