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

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

Issue 2408623002: Views: Extract text selection code from Textfield. (Closed)
Patch Set: Check for |handles_selection_clipboard_| Created 4 years, 1 month 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 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 std::min(model.caret_pos(), text_length)); 680 std::min(model.caret_pos(), text_length));
681 // The current model only supports caret positions at valid cursor indices. 681 // The current model only supports caret positions at valid cursor indices.
682 if (!IsValidCursorIndex(range.start()) || !IsValidCursorIndex(range.end())) 682 if (!IsValidCursorIndex(range.start()) || !IsValidCursorIndex(range.end()))
683 return false; 683 return false;
684 SelectionModel sel(range, model.caret_affinity()); 684 SelectionModel sel(range, model.caret_affinity());
685 bool changed = sel != selection_model_; 685 bool changed = sel != selection_model_;
686 SetSelectionModel(sel); 686 SetSelectionModel(sel);
687 return changed; 687 return changed;
688 } 688 }
689 689
690 bool RenderText::MoveCursorTo(const gfx::Point& point, bool select) {
691 gfx::SelectionModel model = FindCursorPosition(point);
692 if (select)
693 model.set_selection_start(selection().start());
694 return MoveCursorTo(model);
695 }
696
690 bool RenderText::SelectRange(const Range& range) { 697 bool RenderText::SelectRange(const Range& range) {
691 uint32_t text_length = static_cast<uint32_t>(text().length()); 698 uint32_t text_length = static_cast<uint32_t>(text().length());
692 Range sel(std::min(range.start(), text_length), 699 Range sel(std::min(range.start(), text_length),
693 std::min(range.end(), text_length)); 700 std::min(range.end(), text_length));
694 // Allow selection bounds at valid indicies amid multi-character graphemes. 701 // Allow selection bounds at valid indicies amid multi-character graphemes.
695 if (!IsValidLogicalIndex(sel.start()) || !IsValidLogicalIndex(sel.end())) 702 if (!IsValidLogicalIndex(sel.start()) || !IsValidLogicalIndex(sel.end()))
696 return false; 703 return false;
697 LogicalCursorDirection affinity = 704 LogicalCursorDirection affinity =
698 (sel.is_reversed() || sel.is_empty()) ? CURSOR_FORWARD : CURSOR_BACKWARD; 705 (sel.is_reversed() || sel.is_empty()) ? CURSOR_FORWARD : CURSOR_BACKWARD;
699 SetSelectionModel(SelectionModel(sel, affinity)); 706 SetSelectionModel(SelectionModel(sel, affinity));
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 1691
1685 for (; range_max < length; ++range_max) 1692 for (; range_max < length; ++range_max)
1686 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1693 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1687 break; 1694 break;
1688 1695
1689 return range.is_reversed() ? Range(range_max, range_min) 1696 return range.is_reversed() ? Range(range_max, range_min)
1690 : Range(range_min, range_max); 1697 : Range(range_min, range_max);
1691 } 1698 }
1692 1699
1693 } // namespace gfx 1700 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.h ('k') | ui/views/BUILD.gn » ('j') | ui/views/selection_controller.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698