Update localSelectionRect to return a LayoutRect
authorleviw@chromium.org <leviw@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Mar 2012 23:01:23 +0000 (23:01 +0000)
committerleviw@chromium.org <leviw@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Mar 2012 23:01:23 +0000 (23:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82183

Reviewed by Eric Seidel.

localSelectionRect returns a rectangle in the coordinate space of its renderer,
and therefor should remain LayoutUnits until being promoted to absolute
coordinates or painted. Also fixing an incorrect conversion of startPos and
endPos in selectionRectForRepaint.

No new tests. No change in behavior.

* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::localSelectionRect): Continuing to use enclosingIntRect
for the value being returned from the font engine since these floating point
values should not be pixel snapped.
* rendering/InlineTextBox.h:
(InlineTextBox):
* rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::localSelectionRect):
* rendering/RenderReplaced.h:
(RenderReplaced):
* rendering/RenderText.cpp:
(WebCore::localQuadForTextBox):
(WebCore::RenderText::absoluteRectsForRange):
(WebCore::RenderText::absoluteQuadsForRange):
(WebCore::RenderText::selectionRectForRepaint): Fixing an incorrect conversion of
start/endPos to LayoutUnits. These values represent a range of selected characters,
not layout values!
* rendering/svg/RenderSVGInlineText.cpp:
(WebCore::RenderSVGInlineText::localCaretRect):
* rendering/svg/SVGInlineTextBox.cpp:
(WebCore::SVGInlineTextBox::localSelectionRect):
* rendering/svg/SVGInlineTextBox.h:
(SVGInlineTextBox):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/InlineTextBox.cpp
Source/WebCore/rendering/InlineTextBox.h
Source/WebCore/rendering/RenderReplaced.cpp
Source/WebCore/rendering/RenderReplaced.h
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/svg/RenderSVGInlineText.cpp
Source/WebCore/rendering/svg/SVGInlineTextBox.cpp
Source/WebCore/rendering/svg/SVGInlineTextBox.h

index e99fe2a..823c7c7 100644 (file)
@@ -1,3 +1,41 @@
+2012-03-26  Levi Weintraub  <leviw@chromium.org>
+
+        Update localSelectionRect to return a LayoutRect
+        https://bugs.webkit.org/show_bug.cgi?id=82183
+
+        Reviewed by Eric Seidel.
+
+        localSelectionRect returns a rectangle in the coordinate space of its renderer,
+        and therefor should remain LayoutUnits until being promoted to absolute
+        coordinates or painted. Also fixing an incorrect conversion of startPos and
+        endPos in selectionRectForRepaint.
+
+        No new tests. No change in behavior.
+
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::localSelectionRect): Continuing to use enclosingIntRect
+        for the value being returned from the font engine since these floating point
+        values should not be pixel snapped.
+        * rendering/InlineTextBox.h:
+        (InlineTextBox):
+        * rendering/RenderReplaced.cpp:
+        (WebCore::RenderReplaced::localSelectionRect):
+        * rendering/RenderReplaced.h:
+        (RenderReplaced):
+        * rendering/RenderText.cpp:
+        (WebCore::localQuadForTextBox):
+        (WebCore::RenderText::absoluteRectsForRange):
+        (WebCore::RenderText::absoluteQuadsForRange):
+        (WebCore::RenderText::selectionRectForRepaint): Fixing an incorrect conversion of
+        start/endPos to LayoutUnits. These values represent a range of selected characters,
+        not layout values!
+        * rendering/svg/RenderSVGInlineText.cpp:
+        (WebCore::RenderSVGInlineText::localCaretRect):
+        * rendering/svg/SVGInlineTextBox.cpp:
+        (WebCore::SVGInlineTextBox::localSelectionRect):
+        * rendering/svg/SVGInlineTextBox.h:
+        (SVGInlineTextBox):
+
 2012-03-26  Justin Novosad  <junov@chromium.org>
 
         [Chromium] Crash in Canvas2DLayerChromium::pushPropertiesTo
index fec3bb7..9d56584 100644 (file)
@@ -174,19 +174,19 @@ static void adjustCharactersAndLengthForHyphen(BufferForAppendingHyphen& charact
     length += hyphenString.length();
 }
 
-IntRect InlineTextBox::localSelectionRect(int startPos, int endPos)
+LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos)
 {
     int sPos = max(startPos - m_start, 0);
     int ePos = min(endPos - m_start, (int)m_len);
     
     if (sPos > ePos)
-        return IntRect();
+        return LayoutRect();
 
     FontCachePurgePreventer fontCachePurgePreventer;
 
     RenderText* textObj = textRenderer();
-    int selTop = selectionTop();
-    int selHeight = selectionHeight();
+    LayoutUnit selTop = selectionTop();
+    LayoutUnit selHeight = selectionHeight();
     RenderStyle* styleToUse = textObj->style(m_firstLine);
     const Font& font = styleToUse->font();
 
@@ -196,19 +196,19 @@ IntRect InlineTextBox::localSelectionRect(int startPos, int endPos)
     if (respectHyphen)
         endPos = textRun.length();
 
-    IntRect r = enclosingIntRect(font.selectionRectForText(textRun, FloatPoint(logicalLeft(), selTop), selHeight, sPos, ePos));
+    LayoutRect r = enclosingIntRect(font.selectionRectForText(textRun, FloatPoint(logicalLeft(), selTop), selHeight, sPos, ePos));
 
-    int logicalWidth = r.width();
+    LayoutUnit logicalWidth = r.width();
     if (r.x() > logicalRight())
         logicalWidth  = 0;
     else if (r.maxX() > logicalRight())
         logicalWidth = logicalRight() - r.x();
 
-    IntPoint topPoint = isHorizontal() ? IntPoint(r.x(), selTop) : IntPoint(selTop, r.x());
-    int width = isHorizontal() ? logicalWidth : selHeight;
-    int height = isHorizontal() ? selHeight : logicalWidth;
+    LayoutPoint topPoint = isHorizontal() ? LayoutPoint(r.x(), selTop) : LayoutPoint(selTop, r.x());
+    LayoutUnit width = isHorizontal() ? logicalWidth : selHeight;
+    LayoutUnit height = isHorizontal() ? selHeight : logicalWidth;
 
-    return IntRect(topPoint, IntSize(width, height));
+    return LayoutRect(topPoint, LayoutSize(width, height));
 }
 
 void InlineTextBox::deleteLine(RenderArena* arena)
index e59660e..e4ac226 100644 (file)
@@ -110,7 +110,7 @@ private:
 public:
     virtual FloatRect calculateBoundaries() const { return FloatRect(x(), y(), width(), height()); }
 
-    virtual IntRect localSelectionRect(int startPos, int endPos);
+    virtual LayoutRect localSelectionRect(int startPos, int endPos);
     bool isSelected(int startPos, int endPos) const;
     void selectionStartEnd(int& sPos, int& ePos);
 
index bfb7b6a..e7bc9b5 100644 (file)
@@ -488,20 +488,20 @@ LayoutRect RenderReplaced::selectionRectForRepaint(RenderBoxModelObject* repaint
     return rect;
 }
 
-IntRect RenderReplaced::localSelectionRect(bool checkWhetherSelected) const
+LayoutRect RenderReplaced::localSelectionRect(bool checkWhetherSelected) const
 {
     if (checkWhetherSelected && !isSelected())
-        return IntRect();
+        return LayoutRect();
 
     if (!m_inlineBoxWrapper)
         // We're a block-level replaced element.  Just return our own dimensions.
-        return IntRect(IntPoint(), size());
+        return LayoutRect(LayoutPoint(), size());
     
     RootInlineBox* root = m_inlineBoxWrapper->root();
-    int newLogicalTop = root->block()->style()->isFlippedBlocksWritingMode() ? m_inlineBoxWrapper->logicalBottom() - root->selectionBottom() : root->selectionTop() - m_inlineBoxWrapper->logicalTop();
+    LayoutUnit newLogicalTop = root->block()->style()->isFlippedBlocksWritingMode() ? m_inlineBoxWrapper->logicalBottom() - root->selectionBottom() : root->selectionTop() - m_inlineBoxWrapper->logicalTop();
     if (root->block()->style()->isHorizontalWritingMode())
-        return IntRect(0, newLogicalTop, width(), root->selectionHeight());
-    return IntRect(newLogicalTop, 0, root->selectionHeight(), height());
+        return LayoutRect(0, newLogicalTop, width(), root->selectionHeight());
+    return LayoutRect(newLogicalTop, 0, root->selectionHeight(), height());
 }
 
 void RenderReplaced::setSelectionState(SelectionState state)
index 1c6ebbc..c0ba97d 100644 (file)
@@ -59,7 +59,7 @@ protected:
 
     virtual void paint(PaintInfo&, const LayoutPoint&);
     bool shouldPaint(PaintInfo&, const LayoutPoint&);
-    IntRect localSelectionRect(bool checkWhetherSelected = true) const; // This is in local coordinates, but it's a physical rect (so the top left corner is physical top left).
+    LayoutRect localSelectionRect(bool checkWhetherSelected = true) const; // This is in local coordinates, but it's a physical rect (so the top left corner is physical top left).
 
 private:
     virtual RenderBox* embeddedContentBox() const { return 0; }
index d497a33..00e9960 100644 (file)
@@ -312,7 +312,7 @@ void RenderText::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumu
 static FloatRect localQuadForTextBox(InlineTextBox* box, unsigned start, unsigned end, bool useSelectionHeight)
 {
     unsigned realEnd = min(box->end() + 1, end);
-    IntRect r = box->localSelectionRect(start, realEnd);
+    LayoutRect r = box->localSelectionRect(start, realEnd);
     if (r.height()) {
         if (!useSelectionHeight) {
             // Change the height and y position (or width and x for vertical text)
@@ -347,7 +347,7 @@ void RenderText::absoluteRectsForRange(Vector<IntRect>& rects, unsigned start, u
         if (start <= box->start() && box->end() < end) {
             FloatRect r = box->calculateBoundaries();
             if (useSelectionHeight) {
-                IntRect selectionRect = box->localSelectionRect(start, end);
+                LayoutRect selectionRect = box->localSelectionRect(start, end);
                 if (box->isHorizontal()) {
                     r.setHeight(selectionRect.height());
                     r.setY(selectionRect.y());
@@ -430,8 +430,7 @@ void RenderText::absoluteQuadsForRange(Vector<FloatQuad>& quads, unsigned start,
         if (start <= box->start() && box->end() < end) {
             FloatRect r = box->calculateBoundaries();
             if (useSelectionHeight) {
-                // FIXME: localSelectionRect should switch to return FloatRect soon with the subpixellayout branch.
-                IntRect selectionRect = box->localSelectionRect(start, end);
+                LayoutRect selectionRect = box->localSelectionRect(start, end);
                 if (box->isHorizontal()) {
                     r.setHeight(selectionRect.height());
                     r.setY(selectionRect.y());
@@ -1548,7 +1547,7 @@ LayoutRect RenderText::selectionRectForRepaint(RenderBoxModelObject* repaintCont
 
     // Now calculate startPos and endPos for painting selection.
     // We include a selection while endPos > 0
-    LayoutUnit startPos, endPos;
+    int startPos, endPos;
     if (selectionState() == SelectionInside) {
         // We are fully selected.
         startPos = 0;
index 2dfb5b8..dc5ed8a 100644 (file)
@@ -147,13 +147,13 @@ LayoutRect RenderSVGInlineText::localCaretRect(InlineBox* box, int caretOffset,
 
     // Use the edge of the selection rect to determine the caret rect.
     if (static_cast<unsigned>(caretOffset) < textBox->start() + textBox->len()) {
-        IntRect rect = textBox->localSelectionRect(caretOffset, caretOffset + 1);
-        int x = box->isLeftToRightDirection() ? rect.x() : rect.maxX();
+        LayoutRect rect = textBox->localSelectionRect(caretOffset, caretOffset + 1);
+        LayoutUnit x = box->isLeftToRightDirection() ? rect.x() : rect.maxX();
         return LayoutRect(x, rect.y(), caretWidth, rect.height());
     }
 
-    IntRect rect = textBox->localSelectionRect(caretOffset - 1, caretOffset);
-    int x = box->isLeftToRightDirection() ? rect.maxX() : rect.x();
+    LayoutRect rect = textBox->localSelectionRect(caretOffset - 1, caretOffset);
+    LayoutUnit x = box->isLeftToRightDirection() ? rect.maxX() : rect.x();
     return LayoutRect(x, rect.y(), caretWidth, rect.height());
 }
 
index 6db9e0a..90da251 100644 (file)
@@ -128,13 +128,13 @@ FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment&
     return selectionRect;
 }
 
-IntRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPosition)
+LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPosition)
 {
     int boxStart = start();
     startPosition = max(startPosition - boxStart, 0);
     endPosition = min(endPosition - boxStart, static_cast<int>(len()));
     if (startPosition >= endPosition)
-        return IntRect();
+        return LayoutRect();
 
     RenderText* text = textRenderer();
     ASSERT(text);
index 72e0911..d3b9d79 100644 (file)
@@ -47,7 +47,7 @@ public:
 
     void paintSelectionBackground(PaintInfo&);
     virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom);
-    virtual IntRect localSelectionRect(int startPosition, int endPosition);
+    virtual LayoutRect localSelectionRect(int startPosition, int endPosition);
 
     bool mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment&, int& startPosition, int& endPosition) const;