| OLD | NEW |
| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 SelectionModel cursor = FindCursorPosition(point); | 514 SelectionModel cursor = FindCursorPosition(point); |
| 515 return RangeContainsCaret( | 515 return RangeContainsCaret( |
| 516 selection(), cursor.caret_pos(), cursor.caret_affinity()); | 516 selection(), cursor.caret_pos(), cursor.caret_affinity()); |
| 517 } | 517 } |
| 518 | 518 |
| 519 void RenderText::ClearSelection() { | 519 void RenderText::ClearSelection() { |
| 520 SetSelectionModel(SelectionModel(cursor_position(), | 520 SetSelectionModel(SelectionModel(cursor_position(), |
| 521 selection_model_.caret_affinity())); | 521 selection_model_.caret_affinity())); |
| 522 } | 522 } |
| 523 | 523 |
| 524 void RenderText::SelectAll() { | 524 void RenderText::SelectAll(bool reversed) { |
| 525 SelectionModel all; | 525 const size_t length = text().length(); |
| 526 if (GetTextDirection() == base::i18n::LEFT_TO_RIGHT) | 526 const ui::Range all = reversed ? ui::Range(length, 0) : ui::Range(0, length); |
| 527 all = SelectionModel(ui::Range(0, text().length()), CURSOR_FORWARD); | 527 const bool success = SelectRange(all); |
| 528 else | 528 DCHECK(success); |
| 529 all = SelectionModel(ui::Range(text().length(), 0), CURSOR_BACKWARD); | |
| 530 SetSelectionModel(all); | |
| 531 } | 529 } |
| 532 | 530 |
| 533 void RenderText::SelectWord() { | 531 void RenderText::SelectWord() { |
| 534 if (obscured_) { | 532 if (obscured_) { |
| 535 SelectAll(); | 533 SelectAll(false); |
| 536 return; | 534 return; |
| 537 } | 535 } |
| 538 | 536 |
| 539 size_t cursor_pos = cursor_position(); | 537 size_t cursor_pos = cursor_position(); |
| 540 | 538 |
| 541 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); | 539 base::i18n::BreakIterator iter(text(), base::i18n::BreakIterator::BREAK_WORD); |
| 542 bool success = iter.Init(); | 540 bool success = iter.Init(); |
| 543 DCHECK(success); | 541 DCHECK(success); |
| 544 if (!success) | 542 if (!success) |
| 545 return; | 543 return; |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 if (cursor_enabled() && cursor_visible() && focused()) { | 966 if (cursor_enabled() && cursor_visible() && focused()) { |
| 969 const Rect& bounds = GetUpdatedCursorBounds(); | 967 const Rect& bounds = GetUpdatedCursorBounds(); |
| 970 if (bounds.width() != 0) | 968 if (bounds.width() != 0) |
| 971 canvas->FillRect(bounds, cursor_color_); | 969 canvas->FillRect(bounds, cursor_color_); |
| 972 else | 970 else |
| 973 canvas->DrawRect(bounds, cursor_color_); | 971 canvas->DrawRect(bounds, cursor_color_); |
| 974 } | 972 } |
| 975 } | 973 } |
| 976 | 974 |
| 977 } // namespace gfx | 975 } // namespace gfx |
| OLD | NEW |