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

Unified Diff: third_party/WebKit/Source/core/layout/LayoutText.cpp

Issue 2517383002: Use the font height as caret height instead of the line height (Closed)
Patch Set: update comment Created 3 years, 11 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
Index: third_party/WebKit/Source/core/layout/LayoutText.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutText.cpp b/third_party/WebKit/Source/core/layout/LayoutText.cpp
index dd8366d87a8887878a576fce62ffb90d4076b5cf..823667c9c9c4c2b30cb6899dffe989dba31f12d1 100644
--- a/third_party/WebKit/Source/core/layout/LayoutText.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutText.cpp
@@ -741,9 +741,22 @@ LayoutRect LayoutText::localCaretRect(InlineBox* inlineBox,
return LayoutRect();
InlineTextBox* box = toInlineTextBox(inlineBox);
+ // Find an InlineBox before caret position, which is used to get caret height.
+ InlineBox* caretBox = box;
+ if (box->getLineLayoutItem().style(box->isFirstLineStyle())->direction() ==
+ TextDirection::Ltr) {
+ if (box->prevLeafChild() && caretOffset == 0)
+ caretBox = box->prevLeafChild();
+ } else {
+ if (box->nextLeafChild() && caretOffset == 0)
+ caretBox = box->nextLeafChild();
+ }
- int height = box->root().selectionHeight().toInt();
- int top = box->root().selectionTop().toInt();
+ // Get caret height from a font of character.
+ const ComputedStyle* styleToUse =
+ caretBox->getLineLayoutItem().style(caretBox->isFirstLineStyle());
+ int height = styleToUse->font().primaryFont()->getFontMetrics().height();
+ int top = caretBox->logicalTop().toInt();
yosin_UTC9 2017/01/05 07:31:31 Is this baseline.y - font.ascent?
joone 2017/01/06 20:40:43 Yes
// Go ahead and round left to snap it to the nearest pixel.
LayoutUnit left = box->positionForOffset(caretOffset);

Powered by Google App Engine
This is Rietveld 408576698