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

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: rebased 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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 if (!multiline()) { 1024 if (!multiline()) {
1025 offset.Add(GetUpdatedDisplayOffset()); 1025 offset.Add(GetUpdatedDisplayOffset());
1026 } else { 1026 } else {
1027 DCHECK_LT(line_number, lines().size()); 1027 DCHECK_LT(line_number, lines().size());
1028 offset.Add(Vector2d(0, lines_[line_number].preceding_heights)); 1028 offset.Add(Vector2d(0, lines_[line_number].preceding_heights));
1029 } 1029 }
1030 offset.Add(GetAlignmentOffset(line_number)); 1030 offset.Add(GetAlignmentOffset(line_number));
1031 return offset; 1031 return offset;
1032 } 1032 }
1033 1033
1034 bool RenderText::GetDecoratedWordAtPoint(const Point& point, 1034 bool RenderText::GetDecoratedWordAndBaselineAtPoint(
1035 DecoratedText* decorated_word, 1035 const Point& point,
1036 Point* baseline_point) { 1036 DecoratedText* decorated_word,
1037 Point* baseline_point) {
1037 if (obscured()) 1038 if (obscured())
1038 return false; 1039 return false;
1039 1040
1040 EnsureLayout(); 1041 EnsureLayout();
1041 const SelectionModel model_at_point = FindCursorPosition(point); 1042 const SelectionModel model_at_point = FindCursorPosition(point);
1042 const size_t word_index = 1043 const size_t word_index =
1043 GetNearestWordStartBoundary(model_at_point.caret_pos()); 1044 GetNearestWordStartBoundary(model_at_point.caret_pos());
1044 if (word_index >= text().length()) 1045 if (word_index >= text().length())
1045 return false; 1046 return false;
1046 1047
1047 const Range word_range = ExpandRangeToWordBoundary(Range(word_index)); 1048 const Range word_range = ExpandRangeToWordBoundary(Range(word_index));
1048 DCHECK(!word_range.is_reversed()); 1049 DCHECK(!word_range.is_reversed());
1049 DCHECK(!word_range.is_empty()); 1050 DCHECK(!word_range.is_empty());
1050 1051
1052 return GetDecoratedTextAndBaselineForRange(word_range, decorated_word,
1053 baseline_point);
1054 }
1055
1056 bool RenderText::GetDecoratedTextAndBaselineForRange(
1057 const Range& word_range,
1058 DecoratedText* decorated_text,
1059 Point* baseline_point) {
1060 EnsureLayout();
1061
1051 const std::vector<Rect> word_bounds = GetSubstringBounds(word_range); 1062 const std::vector<Rect> word_bounds = GetSubstringBounds(word_range);
1052 if (word_bounds.empty() || 1063 if (word_bounds.empty() ||
1053 !GetDecoratedTextForRange(word_range, decorated_word)) { 1064 !GetDecoratedTextForRange(word_range, decorated_text)) {
1054 return false; 1065 return false;
1055 } 1066 }
1056 1067
1057 // Retrieve the baseline origin of the left-most glyph. 1068 // Retrieve the baseline origin of the left-most glyph.
1058 const auto left_rect = std::min_element( 1069 const auto left_rect = std::min_element(
1059 word_bounds.begin(), word_bounds.end(), 1070 word_bounds.begin(), word_bounds.end(),
1060 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); }); 1071 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); });
1061 const int line_index = GetLineContainingYCoord(left_rect->CenterPoint().y() - 1072 const int line_index = GetLineContainingYCoord(left_rect->CenterPoint().y() -
1062 GetLineOffset(0).y()); 1073 GetLineOffset(0).y());
1063 if (line_index < 0 || line_index >= static_cast<int>(lines().size())) 1074 if (line_index < 0 || line_index >= static_cast<int>(lines().size()))
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 1724
1714 for (; range_max < length; ++range_max) 1725 for (; range_max < length; ++range_max)
1715 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1726 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1716 break; 1727 break;
1717 1728
1718 return range.is_reversed() ? Range(range_max, range_min) 1729 return range.is_reversed() ? Range(range_max, range_min)
1719 : Range(range_min, range_max); 1730 : Range(range_min, range_max);
1720 } 1731 }
1721 1732
1722 } // namespace gfx 1733 } // 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