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

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

Powered by Google App Engine
This is Rietveld 408576698