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

Unified Diff: ui/gfx/render_text.cc

Issue 2639493002: MacViews: Enable word lookup for selectable views::Labels and multi-line text. (Closed)
Patch Set: Address nits. 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
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_harfbuzz.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 78bc651aee32c479ec8f84d793b7d520ee2cba33..a0dbb0baa4511a52fce724d225a46c1f1324d4b7 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,12 @@ 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());
+ const int line_index = GetLineContainingYCoord(left_rect->CenterPoint().y() -
+ GetLineOffset(0).y());
+ if (line_index < 0 || line_index >= static_cast<int>(lines().size()))
+ return false;
+ *baseline_point =
+ left_rect->origin() + Vector2d(0, lines()[line_index].baseline);
return true;
}
@@ -1387,6 +1390,21 @@ 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();
+}
+
// static
bool RenderText::RangeContainsCaret(const Range& range,
size_t caret_pos,
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_harfbuzz.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698