2011-06-30 Levi Weintraub <leviw@chromium.org>
authorleviw@chromium.org <leviw@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jun 2011 23:48:22 +0000 (23:48 +0000)
committerleviw@chromium.org <leviw@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jun 2011 23:48:22 +0000 (23:48 +0000)
        Reviewed by Eric Seidel.

        Remove positionForCoordinates
        https://bugs.webkit.org/show_bug.cgi?id=63765

        Removing positionForCoordinate. We should always use positionForPoint. Also cleaning up
        RenderBox's implementation of positionForPoint.

        No new tests, there should be no functionality changes.

        * accessibility/AccessibilityRenderObject.cpp:
        (WebCore::AccessibilityRenderObject::stringValue): Removing dead, or at least untested, code and
        adding an ASSERT_NOT_REACHED.
        (WebCore::AccessibilityRenderObject::visiblePositionRangeForLine):
        * rendering/RenderBox.cpp:
        (WebCore::RenderBox::positionForPoint): cleaning up some ugly code.
        * rendering/RenderInline.cpp:
        (WebCore::RenderInline::positionForPoint):
        * rendering/RenderObject.cpp:
        * rendering/RenderObject.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@90186 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderInline.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h

index b49e2db..4778e82 100644 (file)
@@ -1,3 +1,26 @@
+2011-06-30  Levi Weintraub  <leviw@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        Remove positionForCoordinates
+        https://bugs.webkit.org/show_bug.cgi?id=63765
+
+        Removing positionForCoordinate. We should always use positionForPoint. Also cleaning up
+        RenderBox's implementation of positionForPoint.
+
+        No new tests, there should be no functionality changes.
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::stringValue): Removing dead, or at least untested, code and
+        adding an ASSERT_NOT_REACHED.
+        (WebCore::AccessibilityRenderObject::visiblePositionRangeForLine):
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::positionForPoint): cleaning up some ugly code.
+        * rendering/RenderInline.cpp:
+        (WebCore::RenderInline::positionForPoint):
+        * rendering/RenderObject.cpp:
+        * rendering/RenderObject.h:
+
 2011-06-30  Zhenyao Mo  <zmo@google.com>
 
         Reviewed by Kenneth Russell.
index 4d4d7c0..dded8e6 100644 (file)
@@ -1157,17 +1157,11 @@ String AccessibilityRenderObject::stringValue() const
         return toRenderButton(m_renderer)->text();
 
     if (isWebArea()) {
+        // FIXME: Why would a renderer exist when the Document isn't attached to a frame?
         if (m_renderer->frame())
             return String();
-        
-        // FIXME: should use startOfDocument and endOfDocument (or rangeForDocument?) here
-        VisiblePosition startVisiblePosition = m_renderer->positionForCoordinates(0, 0);
-        VisiblePosition endVisiblePosition = m_renderer->positionForCoordinates(INT_MAX, INT_MAX);
-        if (startVisiblePosition.isNull() || endVisiblePosition.isNull())
-            return String();
 
-        return plainText(makeRange(startVisiblePosition, endVisiblePosition).get(),
-                         textIteratorBehaviorForTextRange());
+        ASSERT_NOT_REACHED();
     }
     
     if (isTextControl())
@@ -2450,7 +2444,7 @@ VisiblePositionRange AccessibilityRenderObject::visiblePositionRangeForLine(unsi
     // iterate over the lines
     // FIXME: this is wrong when lineNumber is lineCount+1,  because nextLinePosition takes you to the
     // last offset of the last line
-    VisiblePosition visiblePos = m_renderer->document()->renderer()->positionForCoordinates(0, 0);
+    VisiblePosition visiblePos = m_renderer->document()->renderer()->positionForPoint(IntPoint());
     VisiblePosition savedVisiblePos;
     while (--lineCount) {
         savedVisiblePos = visiblePos;
index 0e82867..7ffeb4c 100644 (file)
@@ -3108,8 +3108,8 @@ VisiblePosition RenderBox::positionForPoint(const IntPoint& point)
         int right = contentWidth() + borderAndPaddingWidth();
         int bottom = contentHeight() + borderAndPaddingHeight();
         
-        if (xPos < 0 || xPos > right || yPos < 0 || yPos > bottom) {
-            if (xPos <= right / 2)
+        if (point.x() < 0 || point.x() > right || point.y() < 0 || point.y() > bottom) {
+            if (point.x() <= right / 2)
                 return createVisiblePosition(firstPositionInOrBeforeNode(node()));
             return createVisiblePosition(lastPositionInOrAfterNode(node()));
         }
@@ -3118,12 +3118,10 @@ VisiblePosition RenderBox::positionForPoint(const IntPoint& point)
     // Pass off to the closest child.
     int minDist = INT_MAX;
     RenderBox* closestRenderer = 0;
-    int newX = xPos;
-    int newY = yPos;
-    if (isTableRow()) {
-        newX += x();
-        newY += y();
-    }
+    IntPoint adjustedPoint = point;
+    if (isTableRow())
+        adjustedPoint.move(location());
+
     for (RenderObject* renderObject = firstChild(); renderObject; renderObject = renderObject->nextSibling()) {
         if ((!renderObject->firstChild() && !renderObject->isInline() && !renderObject->isBlockFlow() )
             || renderObject->style()->visibility() != VISIBLE)
@@ -3139,10 +3137,10 @@ VisiblePosition RenderBox::positionForPoint(const IntPoint& point)
         int left = renderer->borderLeft() + renderer->paddingLeft() + (isTableRow() ? 0 : renderer->x());
         int right = left + renderer->contentWidth();
         
-        if (xPos <= right && xPos >= left && yPos <= top && yPos >= bottom) {
+        if (point.x() <= right && point.x() >= left && point.y() <= top && point.y() >= bottom) {
             if (renderer->isTableRow())
-                return renderer->positionForCoordinates(xPos + newX - renderer->x(), yPos + newY - renderer->y());
-            return renderer->positionForCoordinates(xPos - renderer->x(), yPos - renderer->y());
+                return renderer->positionForPoint(point + adjustedPoint - renderer->locationOffset());
+            return renderer->positionForPoint(point - renderer->locationOffset());
         }
 
         // Find the distance from (x, y) to the box.  Split the space around the box into 8 pieces
@@ -3168,11 +3166,10 @@ VisiblePosition RenderBox::positionForPoint(const IntPoint& point)
             else
                 cmp = IntPoint(xPos, bottom);
         }
-        
-        int x1minusx2 = cmp.x() - xPos;
-        int y1minusy2 = cmp.y() - yPos;
-        
-        int dist = x1minusx2 * x1minusx2 + y1minusy2 * y1minusy2;
+
+        IntSize difference = cmp - point;
+
+        int dist = difference.width() * difference.width() + difference.height() * difference.height();
         if (dist < minDist) {
             closestRenderer = renderer;
             minDist = dist;
@@ -3180,7 +3177,7 @@ VisiblePosition RenderBox::positionForPoint(const IntPoint& point)
     }
     
     if (closestRenderer)
-        return closestRenderer->positionForCoordinates(newX - closestRenderer->x(), newY - closestRenderer->y());
+        return closestRenderer->positionForPoint(adjustedPoint - closestRenderer->locationOffset());
     
     return createVisiblePosition(firstPositionInOrBeforeNode(node()));
 }
index a5ec605..d433785 100644 (file)
@@ -726,13 +726,12 @@ VisiblePosition RenderInline::positionForPoint(const IntPoint& point)
     }
 
     // Translate the coords from the pre-anonymous block to the post-anonymous block.
-    int parentBlockX = cb->x() + point.x();
-    int parentBlockY = cb->y() + point.y();
+    IntPoint parentBlockPoint = cb->location() + point;  
     RenderBoxModelObject* c = continuation();
     while (c) {
         RenderBox* contBlock = c->isInline() ? c->containingBlock() : toRenderBlock(c);
         if (c->isInline() || c->firstChild())
-            return c->positionForCoordinates(parentBlockX - contBlock->x(), parentBlockY - contBlock->y());
+            return c->positionForPoint(parentBlockPoint - contBlock->locationOffset());
         c = toRenderBlock(c)->inlineElementContinuation();
     }
     
index 5296dfa..33db2ec 100644 (file)
@@ -2122,11 +2122,6 @@ void RenderObject::arenaDelete(RenderArena* arena, void* base)
     arena->free(*(size_t*)base, base);
 }
 
-VisiblePosition RenderObject::positionForCoordinates(int x, int y)
-{
-    return positionForPoint(IntPoint(x, y));
-}
-
 VisiblePosition RenderObject::positionForPoint(const IntPoint&)
 {
     return createVisiblePosition(caretMinOffset(), DOWNSTREAM);
index 154f306..a07cfa4 100644 (file)
@@ -552,7 +552,6 @@ public:
     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const IntPoint& pointInContainer, const IntPoint& accumulatedOffset, HitTestAction);
     virtual void updateHitTestResult(HitTestResult&, const IntPoint&);
 
-    VisiblePosition positionForCoordinates(int x, int y);
     virtual VisiblePosition positionForPoint(const IntPoint&);
     VisiblePosition createVisiblePosition(int offset, EAffinity);
     VisiblePosition createVisiblePosition(const Position&);