Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1993)

Unified Diff: Source/platform/fonts/Font.cpp

Issue 648633003: Unify selection rect snapping logic (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/fonts/Font.h ('k') | Source/platform/fonts/shaping/HarfBuzzShaper.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/Font.cpp
diff --git a/Source/platform/fonts/Font.cpp b/Source/platform/fonts/Font.cpp
index 62b6354dcaf64e55160b115bd26b8b38823397ea..4755b998329bc1116b9caccc38f9ac046ebe1228 100644
--- a/Source/platform/fonts/Font.cpp
+++ b/Source/platform/fonts/Font.cpp
@@ -326,6 +326,13 @@ PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer, float initia
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
{
@@ -336,9 +343,8 @@ FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point
runInfo.to = to;
if (codePath(runInfo) != ComplexPath)
- return selectionRectForSimpleText(run, point, h, from, to, accountForGlyphBounds);
-
- return selectionRectForComplexText(run, point, h, from, to);
+ return pixelSnappedSelectionRect(selectionRectForSimpleText(run, point, h, from, to, accountForGlyphBounds));
+ return pixelSnappedSelectionRect(selectionRectForComplexText(run, point, h, from, to));
}
int Font::offsetForPosition(const TextRun& run, float x, bool includePartialGlyphs) const
@@ -1046,14 +1052,6 @@ float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont
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
{
SimpleShaper::GlyphBounds bounds;
@@ -1072,8 +1070,9 @@ FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint&
toX = totalWidth - beforeWidth;
}
- return pixelSnappedSelectionRect(point.x() + fromX, point.x() + toX,
+ return FloatRect(point.x() + fromX,
accountForGlyphBounds ? bounds.minGlyphBoundingBoxY : point.y(),
+ toX - fromX,
accountForGlyphBounds ? bounds.maxGlyphBoundingBoxY - bounds.minGlyphBoundingBoxY : h);
}
« no previous file with comments | « Source/platform/fonts/Font.h ('k') | Source/platform/fonts/shaping/HarfBuzzShaper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698