Switch html/* to to new layout types
https://bugs.webkit.org/show_bug.cgi?id=66347

Reviewed by Eric Seidel.

Convert HTML* and shadow element to new layout abstraction as a part of
the ongoing conversion work.

No new tests, no new functionality.

* html/HTMLAreaElement.cpp:
(WebCore::HTMLAreaElement::invalidateCachedRegion):
(WebCore::HTMLAreaElement::mapMouseEvent):
(WebCore::HTMLAreaElement::computePath):
(WebCore::HTMLAreaElement::computeRect):
(WebCore::HTMLAreaElement::getRegion):
* html/HTMLAreaElement.h:
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::paint):
* html/HTMLCanvasElement.h:
* html/HTMLMapElement.cpp:
(WebCore::HTMLMapElement::mapMouseEvent):
* html/HTMLMapElement.h:
* html/ImageDocument.cpp:
(WebCore::ImageDocumentParser::finish):
(WebCore::ImageDocument::scale):
(WebCore::ImageDocument::resizeImageToFit):
(WebCore::ImageDocument::imageFitsInWindow):
* html/ValidationMessage.cpp:
(WebCore::adjustBubblePosition):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::size):
(WebCore::CanvasRenderingContext2D::drawImage):
* html/shadow/MediaControlElements.cpp:
(WebCore::MediaControlPanelElement::startDrag):
(WebCore::MediaControlPanelElement::continueDrag):
(WebCore::MediaControlPanelElement::setPosition):
(WebCore::MediaControlPanelElement::defaultEventHandler):
* html/shadow/MediaControlElements.h:
* html/shadow/SliderThumbElement.cpp:
(WebCore::SliderThumbElement::dragFrom):
(WebCore::SliderThumbElement::setPositionFromPoint):
* html/shadow/SliderThumbElement.h:
* rendering/RenderImage.cpp:
(WebCore::RenderImage::nodeAtPoint):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@93279 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index d6e7c0e..87e2283 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,51 @@
+2011-08-17  Emil A Eklund  <eae@chromium.org>
+
+        Switch html/* to to new layout types
+        https://bugs.webkit.org/show_bug.cgi?id=66347
+
+        Reviewed by Eric Seidel.
+
+        Convert HTML* and shadow element to new layout abstraction as a part of
+        the ongoing conversion work.
+
+        No new tests, no new functionality.
+
+        * html/HTMLAreaElement.cpp:
+        (WebCore::HTMLAreaElement::invalidateCachedRegion):
+        (WebCore::HTMLAreaElement::mapMouseEvent):
+        (WebCore::HTMLAreaElement::computePath):
+        (WebCore::HTMLAreaElement::computeRect):
+        (WebCore::HTMLAreaElement::getRegion):
+        * html/HTMLAreaElement.h:
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::paint):
+        * html/HTMLCanvasElement.h:
+        * html/HTMLMapElement.cpp:
+        (WebCore::HTMLMapElement::mapMouseEvent):
+        * html/HTMLMapElement.h:
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocumentParser::finish):
+        (WebCore::ImageDocument::scale):
+        (WebCore::ImageDocument::resizeImageToFit):
+        (WebCore::ImageDocument::imageFitsInWindow):
+        * html/ValidationMessage.cpp:
+        (WebCore::adjustBubblePosition):
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::size):
+        (WebCore::CanvasRenderingContext2D::drawImage):
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlPanelElement::startDrag):
+        (WebCore::MediaControlPanelElement::continueDrag):
+        (WebCore::MediaControlPanelElement::setPosition):
+        (WebCore::MediaControlPanelElement::defaultEventHandler):
+        * html/shadow/MediaControlElements.h:
+        * html/shadow/SliderThumbElement.cpp:
+        (WebCore::SliderThumbElement::dragFrom):
+        (WebCore::SliderThumbElement::setPositionFromPoint):
+        * html/shadow/SliderThumbElement.h:
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::nodeAtPoint):
+
 2011-08-17  David Grogan  <dgrogan@chromium.org>
 
         Change references to leveldb.gyp to leveldatabase.gyp as part of the
diff --git a/Source/WebCore/html/HTMLAreaElement.cpp b/Source/WebCore/html/HTMLAreaElement.cpp
index fbacea5..c2e8d6e 100644
--- a/Source/WebCore/html/HTMLAreaElement.cpp
+++ b/Source/WebCore/html/HTMLAreaElement.cpp
@@ -75,17 +75,17 @@
 
 void HTMLAreaElement::invalidateCachedRegion()
 {
-    m_lastSize = IntSize(-1, -1);
+    m_lastSize = LayoutSize(-1, -1);
 }
 
-bool HTMLAreaElement::mapMouseEvent(int x, int y, const IntSize& size, HitTestResult& result)
+bool HTMLAreaElement::mapMouseEvent(LayoutPoint location, const LayoutSize& size, HitTestResult& result)
 {
     if (m_lastSize != size) {
         m_region = adoptPtr(new Path(getRegion(size)));
         m_lastSize = size;
     }
 
-    if (!m_region->contains(IntPoint(x, y)))
+    if (!m_region->contains(location))
         return false;
     
     result.setInnerNode(this);
@@ -102,7 +102,7 @@
     FloatPoint absPos = obj->localToAbsolute();
 
     // Default should default to the size of the containing object.
-    IntSize size = m_lastSize;
+    LayoutSize size = m_lastSize;
     if (m_shape == Default)
         size = obj->absoluteOutlineBounds().size();
     
@@ -118,18 +118,18 @@
     return p;
 }
     
-IntRect HTMLAreaElement::computeRect(RenderObject* obj) const
+LayoutRect HTMLAreaElement::computeRect(RenderObject* obj) const
 {
-    return enclosingIntRect(computePath(obj).boundingRect());
+    return enclosingLayoutRect(computePath(obj).boundingRect());
 }
 
-Path HTMLAreaElement::getRegion(const IntSize& size) const
+Path HTMLAreaElement::getRegion(const LayoutSize& size) const
 {
     if (!m_coords && m_shape != Default)
         return Path();
 
-    int width = size.width();
-    int height = size.height();
+    LayoutUnit width = size.width();
+    LayoutUnit height = size.height();
 
     // If element omits the shape attribute, select shape based on number of coordinates.
     Shape shape = m_shape;
diff --git a/Source/WebCore/html/HTMLAreaElement.h b/Source/WebCore/html/HTMLAreaElement.h
index 8ad1cbc..c43ba6d 100644
--- a/Source/WebCore/html/HTMLAreaElement.h
+++ b/Source/WebCore/html/HTMLAreaElement.h
@@ -24,7 +24,7 @@
 #define HTMLAreaElement_h
 
 #include "HTMLAnchorElement.h"
-#include "IntSize.h"
+#include "LayoutTypes.h"
 #include <wtf/OwnArrayPtr.h>
 
 namespace WebCore {
@@ -39,9 +39,9 @@
 
     bool isDefault() const { return m_shape == Default; }
 
-    bool mapMouseEvent(int x, int y, const IntSize&, HitTestResult&);
+    bool mapMouseEvent(LayoutPoint location, const LayoutSize&, HitTestResult&);
 
-    IntRect computeRect(RenderObject*) const;
+    LayoutRect computeRect(RenderObject*) const;
     Path computePath(RenderObject*) const;
 
     // The parent map's image.
@@ -60,13 +60,13 @@
     virtual void setFocus(bool);
     
     enum Shape { Default, Poly, Rect, Circle, Unknown };
-    Path getRegion(const IntSize&) const;
+    Path getRegion(const LayoutSize&) const;
     void invalidateCachedRegion();
 
     OwnPtr<Path> m_region;
     OwnArrayPtr<Length> m_coords;
     int m_coordsLen;
-    IntSize m_lastSize;
+    LayoutSize m_lastSize;
     Shape m_shape;
 };
 
diff --git a/Source/WebCore/html/HTMLCanvasElement.cpp b/Source/WebCore/html/HTMLCanvasElement.cpp
index 2a7ad1d..1a0cb21 100644
--- a/Source/WebCore/html/HTMLCanvasElement.cpp
+++ b/Source/WebCore/html/HTMLCanvasElement.cpp
@@ -264,7 +264,7 @@
         (*it)->canvasResized(this);
 }
 
-void HTMLCanvasElement::paint(GraphicsContext* context, const IntRect& r, bool useLowQualityScale)
+void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r, bool useLowQualityScale)
 {
     // Clear the dirty rect
     m_dirtyRect = FloatRect();
diff --git a/Source/WebCore/html/HTMLCanvasElement.h b/Source/WebCore/html/HTMLCanvasElement.h
index acf6186..f265f42 100644
--- a/Source/WebCore/html/HTMLCanvasElement.h
+++ b/Source/WebCore/html/HTMLCanvasElement.h
@@ -97,7 +97,7 @@
     // Used for rendering
     void didDraw(const FloatRect&);
 
-    void paint(GraphicsContext*, const IntRect&, bool useLowQualityScale = false);
+    void paint(GraphicsContext*, const LayoutRect&, bool useLowQualityScale = false);
 
     GraphicsContext* drawingContext() const;
     GraphicsContext* existingDrawingContext() const;
diff --git a/Source/WebCore/html/HTMLMapElement.cpp b/Source/WebCore/html/HTMLMapElement.cpp
index f83bdc4..e944dad 100644
--- a/Source/WebCore/html/HTMLMapElement.cpp
+++ b/Source/WebCore/html/HTMLMapElement.cpp
@@ -58,7 +58,7 @@
 {
 }
 
-bool HTMLMapElement::mapMouseEvent(int x, int y, const IntSize& size, HitTestResult& result)
+bool HTMLMapElement::mapMouseEvent(LayoutPoint location, const LayoutSize& size, HitTestResult& result)
 {
     HTMLAreaElement* defaultArea = 0;
     Node *node = this;
@@ -68,7 +68,7 @@
             if (areaElt->isDefault()) {
                 if (!defaultArea)
                     defaultArea = areaElt;
-            } else if (areaElt->mapMouseEvent(x, y, size, result))
+            } else if (areaElt->mapMouseEvent(location, size, result))
                 return true;
         }
     }
diff --git a/Source/WebCore/html/HTMLMapElement.h b/Source/WebCore/html/HTMLMapElement.h
index 8e356b4..3006766 100644
--- a/Source/WebCore/html/HTMLMapElement.h
+++ b/Source/WebCore/html/HTMLMapElement.h
@@ -27,7 +27,6 @@
 
 namespace WebCore {
 
-class IntSize;
 class HitTestResult;
 class HTMLImageElement;
     
@@ -39,7 +38,7 @@
 
     const AtomicString& getName() const { return m_name; }
 
-    bool mapMouseEvent(int x, int y, const IntSize&, HitTestResult&);
+    bool mapMouseEvent(LayoutPoint location, const LayoutSize&, HitTestResult&);
     
     HTMLImageElement* imageElement();
     PassRefPtr<HTMLCollection> areas();
diff --git a/Source/WebCore/html/ImageDocument.cpp b/Source/WebCore/html/ImageDocument.cpp
index 8f4b5e9..ddcb03f 100644
--- a/Source/WebCore/html/ImageDocument.cpp
+++ b/Source/WebCore/html/ImageDocument.cpp
@@ -155,7 +155,7 @@
 
         // Report the natural image size in the page title, regardless of zoom
         // level.
-        IntSize size = cachedImage->imageSize(1.0f);
+        LayoutSize size = cachedImage->imageSize(1.0f);
         if (size.width()) {
             // Compute the title, we use the decoded filename of the resource, falling
             // back on the (decoded) hostname if there is no path.
@@ -235,8 +235,8 @@
     if (!view)
         return 1;
 
-    IntSize imageSize = m_imageElement->cachedImage()->imageSize(pageZoomFactor(this));
-    IntSize windowSize = IntSize(view->width(), view->height());
+    LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(pageZoomFactor(this));
+    LayoutSize windowSize = IntSize(view->width(), view->height());
     
     float widthScale = (float)windowSize.width() / imageSize.width();
     float heightScale = (float)windowSize.height() / imageSize.height();
@@ -249,7 +249,7 @@
     if (!m_imageElement)
         return;
 
-    IntSize imageSize = m_imageElement->cachedImage()->imageSize(pageZoomFactor(this));
+    LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(pageZoomFactor(this));
 
     float scale = this->scale();
     m_imageElement->setWidth(static_cast<int>(imageSize.width() * scale));
@@ -326,8 +326,8 @@
     if (!view)
         return true;
 
-    IntSize imageSize = m_imageElement->cachedImage()->imageSize(pageZoomFactor(this));
-    IntSize windowSize = IntSize(view->width(), view->height());
+    LayoutSize imageSize = m_imageElement->cachedImage()->imageSize(pageZoomFactor(this));
+    LayoutSize windowSize = LayoutSize(view->width(), view->height());
     
     return imageSize.width() <= windowSize.width() && imageSize.height() <= windowSize.height();    
 }
diff --git a/Source/WebCore/html/ValidationMessage.cpp b/Source/WebCore/html/ValidationMessage.cpp
index de57136..0d1f174 100644
--- a/Source/WebCore/html/ValidationMessage.cpp
+++ b/Source/WebCore/html/ValidationMessage.cpp
@@ -106,7 +106,7 @@
     }
 }
 
-static void adjustBubblePosition(const IntRect& hostRect, HTMLElement* bubble)
+static void adjustBubblePosition(const LayoutRect& hostRect, HTMLElement* bubble)
 {
     ASSERT(bubble);
     if (hostRect.isEmpty())
diff --git a/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
index 9054057..9d859c3 100644
--- a/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
+++ b/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
@@ -1185,7 +1185,7 @@
     c->setLegacyShadow(FloatSize(width, -height), state().m_shadowBlur, state().m_shadowColor, ColorSpaceDeviceRGB);
 }
 
-static IntSize size(HTMLImageElement* image)
+static LayoutSize size(HTMLImageElement* image)
 {
     if (CachedImage* cachedImage = image->cachedImage())
         return cachedImage->imageSize(1.0f); // FIXME: Not sure about this.
@@ -1215,7 +1215,7 @@
         ec = TYPE_MISMATCH_ERR;
         return;
     }
-    IntSize s = size(image);
+    LayoutSize s = size(image);
     drawImage(image, x, y, s.width(), s.height(), ec);
 }
 
@@ -1226,7 +1226,7 @@
         ec = TYPE_MISMATCH_ERR;
         return;
     }
-    IntSize s = size(image);
+    LayoutSize s = size(image);
     drawImage(image, FloatRect(0, 0, s.width(), s.height()), FloatRect(x, y, width, height), ec);
 }
 
diff --git a/Source/WebCore/html/shadow/MediaControlElements.cpp b/Source/WebCore/html/shadow/MediaControlElements.cpp
index 4a99ca3..cb95b1b 100644
--- a/Source/WebCore/html/shadow/MediaControlElements.cpp
+++ b/Source/WebCore/html/shadow/MediaControlElements.cpp
@@ -122,7 +122,7 @@
     return id;
 }
 
-void MediaControlPanelElement::startDrag(const IntPoint& eventLocation)
+void MediaControlPanelElement::startDrag(const LayoutPoint& eventLocation)
 {
     if (!m_canBeDragged)
         return;
@@ -146,12 +146,12 @@
     m_isBeingDragged = true;
 }
 
-void MediaControlPanelElement::continueDrag(const IntPoint& eventLocation)
+void MediaControlPanelElement::continueDrag(const LayoutPoint& eventLocation)
 {
     if (!m_isBeingDragged)
         return;
 
-    IntSize distanceDragged = eventLocation - m_dragStartEventLocation;
+    LayoutSize distanceDragged = eventLocation - m_dragStartEventLocation;
     setPosition(m_dragStartPosition + distanceDragged);
 }
 
@@ -169,7 +169,7 @@
     frame->eventHandler()->setCapturingMouseEventsNode(0);
 }
 
-void MediaControlPanelElement::setPosition(const IntPoint& position)
+void MediaControlPanelElement::setPosition(const LayoutPoint& position)
 {
     CSSMutableStyleDeclaration* style = getInlineStyleDecl();
 
@@ -199,7 +199,7 @@
     MediaControlElement::defaultEventHandler(event);
 
     if (event->isMouseEvent()) {
-        IntPoint location = static_cast<MouseEvent*>(event)->absoluteLocation();
+        LayoutPoint location = static_cast<MouseEvent*>(event)->absoluteLocation();
         if (event->type() == eventNames().mousedownEvent) {
             startDrag(location);
             event->setDefaultHandled();
diff --git a/Source/WebCore/html/shadow/MediaControlElements.h b/Source/WebCore/html/shadow/MediaControlElements.h
index 2128d66..0679183 100644
--- a/Source/WebCore/html/shadow/MediaControlElements.h
+++ b/Source/WebCore/html/shadow/MediaControlElements.h
@@ -108,16 +108,16 @@
     virtual const AtomicString& shadowPseudoId() const;
     virtual void defaultEventHandler(Event*);
 
-    void startDrag(const IntPoint& eventLocation);
-    void continueDrag(const IntPoint& eventLocation);
+    void startDrag(const LayoutPoint& eventLocation);
+    void continueDrag(const LayoutPoint& eventLocation);
     void endDrag();
 
-    void setPosition(const IntPoint&);
+    void setPosition(const LayoutPoint&);
 
     bool m_canBeDragged;
     bool m_isBeingDragged;
-    IntPoint m_dragStartPosition;
-    IntPoint m_dragStartEventLocation;
+    LayoutPoint m_dragStartPosition;
+    LayoutPoint m_dragStartEventLocation;
 };
 
 // ----------------------------
diff --git a/Source/WebCore/html/shadow/SliderThumbElement.cpp b/Source/WebCore/html/shadow/SliderThumbElement.cpp
index 3cd3535..5d178af 100644
--- a/Source/WebCore/html/shadow/SliderThumbElement.cpp
+++ b/Source/WebCore/html/shadow/SliderThumbElement.cpp
@@ -195,29 +195,29 @@
     return hostInput();
 }
 
-void SliderThumbElement::dragFrom(const IntPoint& point)
+void SliderThumbElement::dragFrom(const LayoutPoint& point)
 {
     setPositionFromPoint(point);
     startDragging();
 }
 
-void SliderThumbElement::setPositionFromPoint(const IntPoint& point)
+void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point)
 {
     HTMLInputElement* input = hostInput();
 
     if (!input->renderer() || !renderer())
         return;
 
-    IntPoint offset = roundedIntPoint(input->renderer()->absoluteToLocal(point, false, true));
+    LayoutPoint offset = roundedLayoutPoint(input->renderer()->absoluteToLocal(point, false, true));
     bool isVertical = hasVerticalAppearance(input);
-    int trackSize;
-    int position;
-    int currentPosition;
+    LayoutUnit trackSize;
+    LayoutUnit position;
+    LayoutUnit currentPosition;
     // We need to calculate currentPosition from absolute points becaue the
     // renderer for this node is usually on a layer and renderBox()->x() and
     // y() are unusable.
-    IntPoint absoluteThumbOrigin = renderBox()->absoluteBoundingBoxRect().location();
-    IntPoint absoluteSliderContentOrigin = roundedIntPoint(input->renderer()->localToAbsolute());
+    LayoutPoint absoluteThumbOrigin = renderBox()->absoluteBoundingBoxRect().location();
+    LayoutPoint absoluteSliderContentOrigin = roundedLayoutPoint(input->renderer()->localToAbsolute());
     if (isVertical) {
         trackSize = input->renderBox()->contentHeight() - renderBox()->height();
         position = offset.y() - renderBox()->height() / 2;
@@ -227,7 +227,7 @@
         position = offset.x() - renderBox()->width() / 2;
         currentPosition = absoluteThumbOrigin.x() - absoluteSliderContentOrigin.x();
     }
-    position = max(0, min(position, trackSize));
+    position = max<LayoutUnit>(0, min(position, trackSize));
     if (position == currentPosition)
         return;
 
diff --git a/Source/WebCore/html/shadow/SliderThumbElement.h b/Source/WebCore/html/shadow/SliderThumbElement.h
index 4a7b046..e2d8b66 100644
--- a/Source/WebCore/html/shadow/SliderThumbElement.h
+++ b/Source/WebCore/html/shadow/SliderThumbElement.h
@@ -52,7 +52,7 @@
 
     void setPositionFromValue();
 
-    void dragFrom(const IntPoint&);
+    void dragFrom(const LayoutPoint&);
     virtual void defaultEventHandler(Event*);
     virtual void detach();
     virtual const AtomicString& shadowPseudoId() const;
@@ -67,7 +67,7 @@
     virtual Node* focusDelegate();
     void startDragging();
     void stopDragging();
-    void setPositionFromPoint(const IntPoint&);
+    void setPositionFromPoint(const LayoutPoint&);
 
     bool m_inDragMode;
 };
diff --git a/Source/WebCore/rendering/RenderImage.cpp b/Source/WebCore/rendering/RenderImage.cpp
index 04347d4..7022cda 100644
--- a/Source/WebCore/rendering/RenderImage.cpp
+++ b/Source/WebCore/rendering/RenderImage.cpp
@@ -437,10 +437,11 @@
     if (tempResult.innerNode() && node()) {
         if (HTMLMapElement* map = imageMap()) {
             IntRect contentBox = contentBoxRect();
-            float zoom = style()->effectiveZoom();
-            LayoutUnit mapX = roundedLayoutUnit((pointInContainer.x() - accumulatedOffset.x() - this->x() - contentBox.x()) / zoom);
-            LayoutUnit mapY = roundedLayoutUnit((pointInContainer.y() - accumulatedOffset.y() - this->y() - contentBox.y()) / zoom);
-            if (map->mapMouseEvent(mapX, mapY, contentBox.size(), tempResult))
+            float scaleFactor = 1 / style()->effectiveZoom();
+            LayoutPoint mapLocation(pointInContainer.x() - accumulatedOffset.x() - this->x() - contentBox.x(), pointInContainer.y() - accumulatedOffset.y() - this->y() - contentBox.y());
+            mapLocation.scale(scaleFactor, scaleFactor);
+            
+            if (map->mapMouseEvent(mapLocation, contentBox.size(), tempResult))
                 tempResult.setInnerNonSharedNode(node());
         }
     }