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

Side by Side 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 msw's comments, changed 2016 to 2017 Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <climits> 10 #include <climits>
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 if (!multiline()) { 1021 if (!multiline()) {
1022 offset.Add(GetUpdatedDisplayOffset()); 1022 offset.Add(GetUpdatedDisplayOffset());
1023 } else { 1023 } else {
1024 DCHECK_LT(line_number, lines().size()); 1024 DCHECK_LT(line_number, lines().size());
1025 offset.Add(Vector2d(0, lines_[line_number].preceding_heights)); 1025 offset.Add(Vector2d(0, lines_[line_number].preceding_heights));
1026 } 1026 }
1027 offset.Add(GetAlignmentOffset(line_number)); 1027 offset.Add(GetAlignmentOffset(line_number));
1028 return offset; 1028 return offset;
1029 } 1029 }
1030 1030
1031 bool RenderText::GetDecoratedWordAtPoint(const Point& point, 1031 bool RenderText::GetDecoratedWordAndBaselineAtPoint(
1032 DecoratedText* decorated_word, 1032 const Point& point,
1033 Point* baseline_point) { 1033 DecoratedText* decorated_word,
1034 Point* baseline_point) {
1034 if (obscured()) 1035 if (obscured())
1035 return false; 1036 return false;
1036 1037
1037 EnsureLayout(); 1038 EnsureLayout();
1038 const SelectionModel model_at_point = FindCursorPosition(point); 1039 const SelectionModel model_at_point = FindCursorPosition(point);
1039 const size_t word_index = 1040 const size_t word_index =
1040 GetNearestWordStartBoundary(model_at_point.caret_pos()); 1041 GetNearestWordStartBoundary(model_at_point.caret_pos());
1041 if (word_index >= text().length()) 1042 if (word_index >= text().length())
1042 return false; 1043 return false;
1043 1044
1044 const Range word_range = ExpandRangeToWordBoundary(Range(word_index)); 1045 const Range word_range = ExpandRangeToWordBoundary(Range(word_index));
1045 DCHECK(!word_range.is_reversed()); 1046 DCHECK(!word_range.is_reversed());
1046 DCHECK(!word_range.is_empty()); 1047 DCHECK(!word_range.is_empty());
1047 1048
1049 return GetDecoratedTextAndBaselineForRange(word_range, decorated_word,
1050 baseline_point);
1051 }
1052
1053 bool RenderText::GetDecoratedTextAndBaselineForRange(
1054 const Range& word_range,
1055 DecoratedText* decorated_text,
1056 Point* baseline_point) {
1057 EnsureLayout();
1058
1048 const std::vector<Rect> word_bounds = GetSubstringBounds(word_range); 1059 const std::vector<Rect> word_bounds = GetSubstringBounds(word_range);
1049 if (word_bounds.empty() || 1060 if (word_bounds.empty() ||
1050 !GetDecoratedTextForRange(word_range, decorated_word)) { 1061 !GetDecoratedTextForRange(word_range, decorated_text)) {
1051 return false; 1062 return false;
1052 } 1063 }
1053 1064
1054 // Retrieve the baseline origin of the left-most glyph. 1065 // Retrieve the baseline origin of the left-most glyph.
1055 const auto left_rect = std::min_element( 1066 const auto left_rect = std::min_element(
1056 word_bounds.begin(), word_bounds.end(), 1067 word_bounds.begin(), word_bounds.end(),
1057 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); }); 1068 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); });
1058 const int line_index = GetLineContainingYCoord(left_rect->CenterPoint().y() - 1069 const int line_index = GetLineContainingYCoord(left_rect->CenterPoint().y() -
1059 GetLineOffset(0).y()); 1070 GetLineOffset(0).y());
1060 if (line_index < 0 || line_index >= static_cast<int>(lines().size())) 1071 if (line_index < 0 || line_index >= static_cast<int>(lines().size()))
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 1721
1711 for (; range_max < length; ++range_max) 1722 for (; range_max < length; ++range_max)
1712 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1723 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1713 break; 1724 break;
1714 1725
1715 return range.is_reversed() ? Range(range_max, range_min) 1726 return range.is_reversed() ? Range(range_max, range_min)
1716 : Range(range_min, range_max); 1727 : Range(range_min, range_max);
1717 } 1728 }
1718 1729
1719 } // namespace gfx 1730 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698