Chromium Code Reviews| Index: ui/gfx/render_text.cc |
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
| index 78bc651aee32c479ec8f84d793b7d520ee2cba33..e83eaaafc184745b1b6943e3f666999bddfe7939 100644 |
| --- a/ui/gfx/render_text.cc |
| +++ b/ui/gfx/render_text.cc |
| @@ -1031,12 +1031,10 @@ Vector2d RenderText::GetLineOffset(size_t line_number) { |
| bool RenderText::GetDecoratedWordAtPoint(const Point& point, |
| DecoratedText* decorated_word, |
| Point* baseline_point) { |
| - // FindCursorPosition doesn't currently support multiline. See |
| - // http://crbug.com/650120. |
| - if (multiline() || obscured()) |
| + if (obscured()) |
| return false; |
| - // Note: FindCursorPosition will trigger a layout via EnsureLayout. |
| + EnsureLayout(); |
| const SelectionModel model_at_point = FindCursorPosition(point); |
| const size_t word_index = |
| GetNearestWordStartBoundary(model_at_point.caret_pos()); |
| @@ -1057,7 +1055,11 @@ bool RenderText::GetDecoratedWordAtPoint(const Point& point, |
| const auto left_rect = std::min_element( |
| word_bounds.begin(), word_bounds.end(), |
| [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); }); |
| - *baseline_point = left_rect->origin() + Vector2d(0, GetDisplayTextBaseline()); |
| + int line_index = GetLineContainingYCoord(left_rect->y()); |
| + if (line_index == -1 || line_index == static_cast<int>(lines().size())) |
|
karandeepb
2017/01/17 04:20:12
Don't think this should happen, but still added th
|
| + return false; |
| + *baseline_point = |
| + left_rect->origin() + Vector2d(0, lines()[line_index].baseline); |
| return true; |
| } |
| @@ -1387,6 +1389,42 @@ void RenderText::UpdateStyleLengths() { |
| styles_[style].SetMax(text_length); |
| } |
| +int RenderText::GetLineContainingYCoord(float text_y) { |
| + if (text_y < 0) |
| + return -1; |
| + |
| + for (size_t i = 0; i < lines().size(); i++) { |
| + const internal::Line& line = lines()[i]; |
| + |
| + if (text_y <= line.size.height()) |
| + return i; |
| + text_y -= line.size.height(); |
| + } |
| + |
| + return lines().size(); |
| +} |
| + |
| +int RenderText::GetLineSegmentContainingXCoord(const internal::Line& line, |
| + float line_x, |
| + float* offset_relative_segment) { |
| + DCHECK(offset_relative_segment); |
| + |
| + *offset_relative_segment = 0; |
| + if (line_x < 0) |
| + return -1; |
| + for (size_t i = 0; i < line.segments.size(); i++) { |
| + const internal::LineSegment& segment = line.segments[i]; |
| + |
| + // segment.x_range is not used because it is in text space. |
| + if (line_x < segment.width()) { |
| + *offset_relative_segment = line_x; |
| + return i; |
| + } |
| + line_x -= segment.width(); |
| + } |
| + return line.segments.size(); |
| +} |
| + |
| // static |
| bool RenderText::RangeContainsCaret(const Range& range, |
| size_t caret_pos, |