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

Side by Side Diff: ui/gfx/render_text.cc

Issue 2688883002: Revert [MacViews] Implemented text context menu (Closed)
Patch Set: 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
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 if (!multiline()) { 1025 if (!multiline()) {
1026 offset.Add(GetUpdatedDisplayOffset()); 1026 offset.Add(GetUpdatedDisplayOffset());
1027 } else { 1027 } else {
1028 DCHECK_LT(line_number, lines().size()); 1028 DCHECK_LT(line_number, lines().size());
1029 offset.Add(Vector2d(0, lines_[line_number].preceding_heights)); 1029 offset.Add(Vector2d(0, lines_[line_number].preceding_heights));
1030 } 1030 }
1031 offset.Add(GetAlignmentOffset(line_number)); 1031 offset.Add(GetAlignmentOffset(line_number));
1032 return offset; 1032 return offset;
1033 } 1033 }
1034 1034
1035 bool RenderText::GetDecoratedWordAndBaselineAtPoint( 1035 bool RenderText::GetDecoratedWordAtPoint(const Point& point,
1036 const Point& point, 1036 DecoratedText* decorated_word,
1037 DecoratedText* decorated_word, 1037 Point* baseline_point) {
1038 Point* baseline_point) {
1039 if (obscured()) 1038 if (obscured())
1040 return false; 1039 return false;
1041 1040
1042 EnsureLayout(); 1041 EnsureLayout();
1043 const SelectionModel model_at_point = FindCursorPosition(point); 1042 const SelectionModel model_at_point = FindCursorPosition(point);
1044 const size_t word_index = 1043 const size_t word_index =
1045 GetNearestWordStartBoundary(model_at_point.caret_pos()); 1044 GetNearestWordStartBoundary(model_at_point.caret_pos());
1046 if (word_index >= text().length()) 1045 if (word_index >= text().length())
1047 return false; 1046 return false;
1048 1047
1049 const Range word_range = ExpandRangeToWordBoundary(Range(word_index)); 1048 const Range word_range = ExpandRangeToWordBoundary(Range(word_index));
1050 DCHECK(!word_range.is_reversed()); 1049 DCHECK(!word_range.is_reversed());
1051 DCHECK(!word_range.is_empty()); 1050 DCHECK(!word_range.is_empty());
1052 1051
1053 return GetDecoratedTextAndBaselineForRange(word_range, decorated_word,
1054 baseline_point);
1055 }
1056
1057 bool RenderText::GetDecoratedTextAndBaselineForRange(
1058 const Range& word_range,
1059 DecoratedText* decorated_text,
1060 Point* baseline_point) {
1061 EnsureLayout();
1062
1063 const std::vector<Rect> word_bounds = GetSubstringBounds(word_range); 1052 const std::vector<Rect> word_bounds = GetSubstringBounds(word_range);
1064 if (word_bounds.empty() || 1053 if (word_bounds.empty() ||
1065 !GetDecoratedTextForRange(word_range, decorated_text)) { 1054 !GetDecoratedTextForRange(word_range, decorated_word)) {
1066 return false; 1055 return false;
1067 } 1056 }
1068 1057
1069 // Retrieve the baseline origin of the left-most glyph. 1058 // Retrieve the baseline origin of the left-most glyph.
1070 const auto left_rect = std::min_element( 1059 const auto left_rect = std::min_element(
1071 word_bounds.begin(), word_bounds.end(), 1060 word_bounds.begin(), word_bounds.end(),
1072 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); }); 1061 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); });
1073 const int line_index = GetLineContainingYCoord(left_rect->CenterPoint().y() - 1062 const int line_index = GetLineContainingYCoord(left_rect->CenterPoint().y() -
1074 GetLineOffset(0).y()); 1063 GetLineOffset(0).y());
1075 if (line_index < 0 || line_index >= static_cast<int>(lines().size())) 1064 if (line_index < 0 || line_index >= static_cast<int>(lines().size()))
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 1714
1726 for (; range_max < length; ++range_max) 1715 for (; range_max < length; ++range_max)
1727 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1716 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1728 break; 1717 break;
1729 1718
1730 return range.is_reversed() ? Range(range_max, range_min) 1719 return range.is_reversed() ? Range(range_max, range_min)
1731 : Range(range_min, range_max); 1720 : Range(range_min, range_max);
1732 } 1721 }
1733 1722
1734 } // namespace gfx 1723 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698