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

Unified Diff: ui/gfx/render_text.cc

Issue 2164483006: [MacViews] Implemented text context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed tapted's comments and made things work Created 4 years 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: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index c12d80357bd5d5e0483f13b4b46146e455fe941c..39ad9e5775331da67a544dd0ad00967c3023929f 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -1033,16 +1033,24 @@ bool RenderText::GetDecoratedWordAtPoint(const Point& point,
DCHECK(!word_range.is_reversed());
DCHECK(!word_range.is_empty());
- const std::vector<Rect> word_bounds = GetSubstringBounds(word_range);
- if (word_bounds.empty() ||
- !GetDecoratedTextForRange(word_range, decorated_word)) {
+ return GetDecoratedTextForRange(word_range, decorated_word, baseline_point);
+}
+
+bool RenderText::GetDecoratedTextForRange(const Range& range,
+ DecoratedText* decorated_text,
+ Point* baseline_point) {
+ if (range.is_empty() || !GetDecoratedTextForRange(range, decorated_text))
return false;
- }
// Retrieve the baseline origin of the left-most glyph.
+ const std::vector<Rect> text_bounds = GetSubstringBounds(range);
+ if (text_bounds.empty())
+ return false;
+
const auto left_rect = std::min_element(
- word_bounds.begin(), word_bounds.end(),
+ text_bounds.begin(), text_bounds.end(),
[](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); });
+
*baseline_point = left_rect->origin() + Vector2d(0, GetDisplayTextBaseline());
return true;
}

Powered by Google App Engine
This is Rietveld 408576698