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

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: Fix for tapted 3 Created 3 years, 12 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 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 Vector2d offset = display_rect().OffsetFromOrigin(); 1007 Vector2d offset = display_rect().OffsetFromOrigin();
1008 // TODO(ckocagil): Apply the display offset for multiline scrolling. 1008 // TODO(ckocagil): Apply the display offset for multiline scrolling.
1009 if (!multiline()) 1009 if (!multiline())
1010 offset.Add(GetUpdatedDisplayOffset()); 1010 offset.Add(GetUpdatedDisplayOffset());
1011 else 1011 else
1012 offset.Add(Vector2d(0, lines_[line_number].preceding_heights)); 1012 offset.Add(Vector2d(0, lines_[line_number].preceding_heights));
1013 offset.Add(GetAlignmentOffset(line_number)); 1013 offset.Add(GetAlignmentOffset(line_number));
1014 return offset; 1014 return offset;
1015 } 1015 }
1016 1016
1017 bool RenderText::GetDecoratedWordAtPoint(const Point& point, 1017 bool RenderText::GetDecoratedWordAndBaselineAtPoint(
1018 DecoratedText* decorated_word, 1018 const Point& point,
1019 Point* baseline_point) { 1019 DecoratedText* decorated_word,
1020 Point* baseline_point) {
1020 // FindCursorPosition doesn't currently support multiline. See 1021 // FindCursorPosition doesn't currently support multiline. See
1021 // http://crbug.com/650120. 1022 // http://crbug.com/650120.
1022 if (multiline() || obscured()) 1023 if (multiline() || obscured())
1023 return false; 1024 return false;
1024 1025
1025 // Note: FindCursorPosition will trigger a layout via EnsureLayout. 1026 // Note: FindCursorPosition will trigger a layout via EnsureLayout.
1026 const SelectionModel model_at_point = FindCursorPosition(point); 1027 const SelectionModel model_at_point = FindCursorPosition(point);
1027 const size_t word_index = 1028 const size_t word_index =
1028 GetNearestWordStartBoundary(model_at_point.caret_pos()); 1029 GetNearestWordStartBoundary(model_at_point.caret_pos());
1029 if (word_index >= text().length()) 1030 if (word_index >= text().length())
1030 return false; 1031 return false;
1031 1032
1032 const Range word_range = ExpandRangeToWordBoundary(Range(word_index)); 1033 const Range word_range = ExpandRangeToWordBoundary(Range(word_index));
1033 DCHECK(!word_range.is_reversed()); 1034 DCHECK(!word_range.is_reversed());
1034 DCHECK(!word_range.is_empty()); 1035 DCHECK(!word_range.is_empty());
1035 1036
1036 const std::vector<Rect> word_bounds = GetSubstringBounds(word_range); 1037 return GetDecoratedTextAndBaselineForRange(word_range, decorated_word,
1037 if (word_bounds.empty() || 1038 baseline_point);
1038 !GetDecoratedTextForRange(word_range, decorated_word)) { 1039 }
1040
1041 bool RenderText::GetDecoratedTextAndBaselineForRange(
1042 const Range& range,
1043 DecoratedText* decorated_text,
1044 Point* baseline_point) {
1045 if (range.is_empty() || !GetDecoratedTextForRange(range, decorated_text))
1039 return false; 1046 return false;
1040 }
1041 1047
1042 // Retrieve the baseline origin of the left-most glyph. 1048 // Retrieve the baseline origin of the left-most glyph.
1049 const std::vector<Rect> text_bounds = GetSubstringBounds(range);
1050 if (text_bounds.empty())
1051 return false;
1052
1043 const auto left_rect = std::min_element( 1053 const auto left_rect = std::min_element(
1044 word_bounds.begin(), word_bounds.end(), 1054 text_bounds.begin(), text_bounds.end(),
1045 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); }); 1055 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); });
1046 *baseline_point = left_rect->origin() + Vector2d(0, GetDisplayTextBaseline()); 1056 *baseline_point = left_rect->origin() + Vector2d(0, GetDisplayTextBaseline());
1047 return true; 1057 return true;
1048 } 1058 }
1049 1059
1050 base::string16 RenderText::GetTextFromRange(const Range& range) const { 1060 base::string16 RenderText::GetTextFromRange(const Range& range) const {
1051 if (range.IsValid() && range.GetMin() < text().length()) 1061 if (range.IsValid() && range.GetMin() < text().length())
1052 return text().substr(range.GetMin(), range.length()); 1062 return text().substr(range.GetMin(), range.length());
1053 return base::string16(); 1063 return base::string16();
1054 } 1064 }
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 1698
1689 for (; range_max < length; ++range_max) 1699 for (; range_max < length; ++range_max)
1690 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1700 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1691 break; 1701 break;
1692 1702
1693 return range.is_reversed() ? Range(range_max, range_min) 1703 return range.is_reversed() ? Range(range_max, range_min)
1694 : Range(range_min, range_max); 1704 : Range(range_min, range_max);
1695 } 1705 }
1696 1706
1697 } // namespace gfx 1707 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698