Commit 04652652 authored by eae@chromium.org's avatar eae@chromium.org

Unify selection rect snapping logic

Unify the pixel snapping logic for selection rects by moving the logic
into selectionRectForText and having selectionRectForSimpleText and
selectionRectForComplexText respectively return precise values.

R=fmalita@chromium.org

Review URL: https://codereview.chromium.org/648633003

git-svn-id: svn://svn.chromium.org/blink/trunk@183632 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ddec0b5b
...@@ -326,6 +326,13 @@ PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer, float initia ...@@ -326,6 +326,13 @@ PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer, float initia
return adoptRef(builder.build()); return adoptRef(builder.build());
} }
static inline FloatRect pixelSnappedSelectionRect(FloatRect rect)
{
// Using roundf() rather than ceilf() for the right edge as a compromise to
// ensure correct caret positioning.
float roundedX = roundf(rect.x());
return FloatRect(roundedX, rect.y(), roundf(rect.maxX() - roundedX), rect.height());
}
FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const
{ {
...@@ -336,9 +343,8 @@ FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point ...@@ -336,9 +343,8 @@ FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point
runInfo.to = to; runInfo.to = to;
if (codePath(runInfo) != ComplexPath) if (codePath(runInfo) != ComplexPath)
return selectionRectForSimpleText(run, point, h, from, to, accountForGlyphBounds); return pixelSnappedSelectionRect(selectionRectForSimpleText(run, point, h, from, to, accountForGlyphBounds));
return pixelSnappedSelectionRect(selectionRectForComplexText(run, point, h, from, to));
return selectionRectForComplexText(run, point, h, from, to);
} }
int Font::offsetForPosition(const TextRun& run, float x, bool includePartialGlyphs) const int Font::offsetForPosition(const TextRun& run, float x, bool includePartialGlyphs) const
...@@ -1046,14 +1052,6 @@ float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont ...@@ -1046,14 +1052,6 @@ float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont
return shaper.runWidthSoFar(); return shaper.runWidthSoFar();
} }
FloatRect Font::pixelSnappedSelectionRect(float fromX, float toX, float y, float height)
{
// Using roundf() rather than ceilf() for the right edge as a compromise to
// ensure correct caret positioning.
float roundedX = roundf(fromX);
return FloatRect(roundedX, y, roundf(toX - roundedX), height);
}
FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const
{ {
SimpleShaper::GlyphBounds bounds; SimpleShaper::GlyphBounds bounds;
...@@ -1072,8 +1070,9 @@ FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& ...@@ -1072,8 +1070,9 @@ FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint&
toX = totalWidth - beforeWidth; toX = totalWidth - beforeWidth;
} }
return pixelSnappedSelectionRect(point.x() + fromX, point.x() + toX, return FloatRect(point.x() + fromX,
accountForGlyphBounds ? bounds.minGlyphBoundingBoxY : point.y(), accountForGlyphBounds ? bounds.minGlyphBoundingBoxY : point.y(),
toX - fromX,
accountForGlyphBounds ? bounds.maxGlyphBoundingBoxY - bounds.minGlyphBoundingBoxY : h); accountForGlyphBounds ? bounds.maxGlyphBoundingBoxY - bounds.minGlyphBoundingBoxY : h);
} }
......
...@@ -166,7 +166,6 @@ public: ...@@ -166,7 +166,6 @@ public:
void willUseFontData(UChar32) const; void willUseFontData(UChar32) const;
static FloatRect pixelSnappedSelectionRect(float fromX, float toX, float y, float height);
private: private:
bool loadingCustomFonts() const bool loadingCustomFonts() const
{ {
......
...@@ -1146,15 +1146,9 @@ FloatRect HarfBuzzShaper::selectionRect(const FloatPoint& point, int height, int ...@@ -1146,15 +1146,9 @@ FloatRect HarfBuzzShaper::selectionRect(const FloatPoint& point, int height, int
if (!foundToX) if (!foundToX)
toX = m_run.rtl() ? 0 : m_totalWidth; toX = m_run.rtl() ? 0 : m_totalWidth;
if (fromX < toX) { if (fromX < toX)
return Font::pixelSnappedSelectionRect( return FloatRect(point.x() + fromX, point.y(), toX - fromX, height);
point.x() + fromX, point.x() + toX, return FloatRect(point.x() + toX, point.y(), fromX - toX, height);
point.y(), height);
}
return Font::pixelSnappedSelectionRect(
point.x() + toX, point.x() + fromX,
point.y(), height);
} }
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment