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

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: Fix for tapted 3 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..96ae9482adacfd8f05126d2b47fd09f75880f32a 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -1014,9 +1014,10 @@ Vector2d RenderText::GetLineOffset(size_t line_number) {
return offset;
}
-bool RenderText::GetDecoratedWordAtPoint(const Point& point,
- DecoratedText* decorated_word,
- Point* baseline_point) {
+bool RenderText::GetDecoratedWordAndBaselineAtPoint(
+ const Point& point,
+ DecoratedText* decorated_word,
+ Point* baseline_point) {
// FindCursorPosition doesn't currently support multiline. See
// http://crbug.com/650120.
if (multiline() || obscured())
@@ -1033,15 +1034,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 GetDecoratedTextAndBaselineForRange(word_range, decorated_word,
+ baseline_point);
+}
+
+bool RenderText::GetDecoratedTextAndBaselineForRange(
+ 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