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

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 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 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 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 const SelectionModel model_at_point = FindCursorPosition(point); 1026 const SelectionModel model_at_point = FindCursorPosition(point);
1027 const size_t word_index = 1027 const size_t word_index =
1028 GetNearestWordStartBoundary(model_at_point.caret_pos()); 1028 GetNearestWordStartBoundary(model_at_point.caret_pos());
1029 if (word_index >= text().length()) 1029 if (word_index >= text().length())
1030 return false; 1030 return false;
1031 1031
1032 const Range word_range = ExpandRangeToWordBoundary(Range(word_index)); 1032 const Range word_range = ExpandRangeToWordBoundary(Range(word_index));
1033 DCHECK(!word_range.is_reversed()); 1033 DCHECK(!word_range.is_reversed());
1034 DCHECK(!word_range.is_empty()); 1034 DCHECK(!word_range.is_empty());
1035 1035
1036 const std::vector<Rect> word_bounds = GetSubstringBounds(word_range); 1036 return GetDecoratedTextAndBaselineForRange(word_range, decorated_word,
1037 if (word_bounds.empty() || 1037 baseline_point);
1038 !GetDecoratedTextForRange(word_range, decorated_word)) { 1038 }
1039
1040 bool RenderText::GetDecoratedTextAndBaselineForRange(
1041 const Range& range,
1042 DecoratedText* decorated_text,
1043 Point* baseline_point) {
1044 if (range.is_empty() || !GetDecoratedTextForRange(range, decorated_text))
1039 return false; 1045 return false;
1040 }
1041 1046
1042 // Retrieve the baseline origin of the left-most glyph. 1047 // Retrieve the baseline origin of the left-most glyph.
1048 const std::vector<Rect> text_bounds = GetSubstringBounds(range);
1049 if (text_bounds.empty())
1050 return false;
1051
1043 const auto left_rect = std::min_element( 1052 const auto left_rect = std::min_element(
1044 word_bounds.begin(), word_bounds.end(), 1053 text_bounds.begin(), text_bounds.end(),
1045 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); }); 1054 [](const Rect& lhs, const Rect& rhs) { return lhs.x() < rhs.x(); });
1046 *baseline_point = left_rect->origin() + Vector2d(0, GetDisplayTextBaseline()); 1055 *baseline_point = left_rect->origin() + Vector2d(0, GetDisplayTextBaseline());
1047 return true; 1056 return true;
1048 } 1057 }
1049 1058
1050 base::string16 RenderText::GetTextFromRange(const Range& range) const { 1059 base::string16 RenderText::GetTextFromRange(const Range& range) const {
1051 if (range.IsValid() && range.GetMin() < text().length()) 1060 if (range.IsValid() && range.GetMin() < text().length())
1052 return text().substr(range.GetMin(), range.length()); 1061 return text().substr(range.GetMin(), range.length());
1053 return base::string16(); 1062 return base::string16();
1054 } 1063 }
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 1697
1689 for (; range_max < length; ++range_max) 1698 for (; range_max < length; ++range_max)
1690 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1699 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1691 break; 1700 break;
1692 1701
1693 return range.is_reversed() ? Range(range_max, range_min) 1702 return range.is_reversed() ? Range(range_max, range_min)
1694 : Range(range_min, range_max); 1703 : Range(range_min, range_max);
1695 } 1704 }
1696 1705
1697 } // namespace gfx 1706 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698