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

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

Issue 1671403002: Switch gfx::Range to use uint32_t instead of size_t. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 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/range/range.cc ('k') | ui/gfx/render_text_harfbuzz.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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 cursor = GetAdjacentSelectionModel(cursor, break_type, direction); 625 cursor = GetAdjacentSelectionModel(cursor, break_type, direction);
626 } 626 }
627 if (select) 627 if (select)
628 cursor.set_selection_start(selection().start()); 628 cursor.set_selection_start(selection().start());
629 MoveCursorTo(cursor); 629 MoveCursorTo(cursor);
630 } 630 }
631 631
632 bool RenderText::MoveCursorTo(const SelectionModel& model) { 632 bool RenderText::MoveCursorTo(const SelectionModel& model) {
633 // Enforce valid selection model components. 633 // Enforce valid selection model components.
634 size_t text_length = text().length(); 634 size_t text_length = text().length();
635 Range range(std::min(model.selection().start(), text_length), 635 Range range(std::min(model.selection().start(),
636 static_cast<uint32_t>(text_length)),
636 std::min(model.caret_pos(), text_length)); 637 std::min(model.caret_pos(), text_length));
637 // The current model only supports caret positions at valid cursor indices. 638 // The current model only supports caret positions at valid cursor indices.
638 if (!IsValidCursorIndex(range.start()) || !IsValidCursorIndex(range.end())) 639 if (!IsValidCursorIndex(range.start()) || !IsValidCursorIndex(range.end()))
639 return false; 640 return false;
640 SelectionModel sel(range, model.caret_affinity()); 641 SelectionModel sel(range, model.caret_affinity());
641 bool changed = sel != selection_model_; 642 bool changed = sel != selection_model_;
642 SetSelectionModel(sel); 643 SetSelectionModel(sel);
643 return changed; 644 return changed;
644 } 645 }
645 646
646 bool RenderText::SelectRange(const Range& range) { 647 bool RenderText::SelectRange(const Range& range) {
647 Range sel(std::min(range.start(), text().length()), 648 uint32_t text_length = static_cast<uint32_t>(text().length());
648 std::min(range.end(), text().length())); 649 Range sel(std::min(range.start(), text_length),
650 std::min(range.end(), text_length));
649 // Allow selection bounds at valid indicies amid multi-character graphemes. 651 // Allow selection bounds at valid indicies amid multi-character graphemes.
650 if (!IsValidLogicalIndex(sel.start()) || !IsValidLogicalIndex(sel.end())) 652 if (!IsValidLogicalIndex(sel.start()) || !IsValidLogicalIndex(sel.end()))
651 return false; 653 return false;
652 LogicalCursorDirection affinity = 654 LogicalCursorDirection affinity =
653 (sel.is_reversed() || sel.is_empty()) ? CURSOR_FORWARD : CURSOR_BACKWARD; 655 (sel.is_reversed() || sel.is_empty()) ? CURSOR_FORWARD : CURSOR_BACKWARD;
654 SetSelectionModel(SelectionModel(sel, affinity)); 656 SetSelectionModel(SelectionModel(sel, affinity));
655 return true; 657 return true;
656 } 658 }
657 659
658 bool RenderText::IsPointInSelection(const Point& point) { 660 bool RenderText::IsPointInSelection(const Point& point) {
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 1542
1541 SetDisplayOffset(display_offset_.x() + delta_x); 1543 SetDisplayOffset(display_offset_.x() + delta_x);
1542 } 1544 }
1543 1545
1544 void RenderText::DrawSelection(Canvas* canvas) { 1546 void RenderText::DrawSelection(Canvas* canvas) {
1545 for (const Rect& s : GetSubstringBounds(selection())) 1547 for (const Rect& s : GetSubstringBounds(selection()))
1546 canvas->FillRect(s, selection_background_focused_color_); 1548 canvas->FillRect(s, selection_background_focused_color_);
1547 } 1549 }
1548 1550
1549 } // namespace gfx 1551 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/range/range.cc ('k') | ui/gfx/render_text_harfbuzz.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698