| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/views/controls/textfield/textfield_model.h" | 5 #include "ui/views/controls/textfield/textfield_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 render_text_->SetCursorPosition(new_cursor); | 329 render_text_->SetCursorPosition(new_cursor); |
| 330 } | 330 } |
| 331 ClearSelection(); | 331 ClearSelection(); |
| 332 return changed; | 332 return changed; |
| 333 } | 333 } |
| 334 | 334 |
| 335 void TextfieldModel::Append(const base::string16& new_text) { | 335 void TextfieldModel::Append(const base::string16& new_text) { |
| 336 if (HasCompositionText()) | 336 if (HasCompositionText()) |
| 337 ConfirmCompositionText(); | 337 ConfirmCompositionText(); |
| 338 size_t save = GetCursorPosition(); | 338 size_t save = GetCursorPosition(); |
| 339 MoveCursor(gfx::LINE_BREAK, | 339 MoveCursor(gfx::LINE_BREAK, render_text_->GetVisualDirectionOfLogicalEnd(), |
| 340 render_text_->GetVisualDirectionOfLogicalEnd(), | 340 gfx::SELECTION_NONE); |
| 341 false); | |
| 342 InsertText(new_text); | 341 InsertText(new_text); |
| 343 render_text_->SetCursorPosition(save); | 342 render_text_->SetCursorPosition(save); |
| 344 ClearSelection(); | 343 ClearSelection(); |
| 345 } | 344 } |
| 346 | 345 |
| 347 bool TextfieldModel::Delete(bool add_to_kill_buffer) { | 346 bool TextfieldModel::Delete(bool add_to_kill_buffer) { |
| 348 if (HasCompositionText()) { | 347 if (HasCompositionText()) { |
| 349 // No undo/redo for composition text. | 348 // No undo/redo for composition text. |
| 350 CancelCompositionText(); | 349 CancelCompositionText(); |
| 351 return true; | 350 return true; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 } | 393 } |
| 395 return false; | 394 return false; |
| 396 } | 395 } |
| 397 | 396 |
| 398 size_t TextfieldModel::GetCursorPosition() const { | 397 size_t TextfieldModel::GetCursorPosition() const { |
| 399 return render_text_->cursor_position(); | 398 return render_text_->cursor_position(); |
| 400 } | 399 } |
| 401 | 400 |
| 402 void TextfieldModel::MoveCursor(gfx::BreakType break_type, | 401 void TextfieldModel::MoveCursor(gfx::BreakType break_type, |
| 403 gfx::VisualCursorDirection direction, | 402 gfx::VisualCursorDirection direction, |
| 404 bool select) { | 403 gfx::SelectionBehavior selection_behavior) { |
| 405 if (HasCompositionText()) | 404 if (HasCompositionText()) |
| 406 ConfirmCompositionText(); | 405 ConfirmCompositionText(); |
| 407 render_text_->MoveCursor(break_type, direction, select); | 406 render_text_->MoveCursor(break_type, direction, selection_behavior); |
| 408 } | 407 } |
| 409 | 408 |
| 410 bool TextfieldModel::MoveCursorTo(const gfx::SelectionModel& cursor) { | 409 bool TextfieldModel::MoveCursorTo(const gfx::SelectionModel& cursor) { |
| 411 if (HasCompositionText()) { | 410 if (HasCompositionText()) { |
| 412 ConfirmCompositionText(); | 411 ConfirmCompositionText(); |
| 413 // ConfirmCompositionText() updates cursor position. Need to reflect it in | 412 // ConfirmCompositionText() updates cursor position. Need to reflect it in |
| 414 // the SelectionModel parameter of MoveCursorTo(). | 413 // the SelectionModel parameter of MoveCursorTo(). |
| 415 gfx::Range range(render_text_->selection().start(), cursor.caret_pos()); | 414 gfx::Range range(render_text_->selection().start(), cursor.caret_pos()); |
| 416 if (!range.is_empty()) | 415 if (!range.is_empty()) |
| 417 return render_text_->SelectRange(range); | 416 return render_text_->SelectRange(range); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 render_text_->SetCursorPosition(new_cursor_pos); | 846 render_text_->SetCursorPosition(new_cursor_pos); |
| 848 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). | 847 // TODO(oshima): Select text that was just undone, like Mac (but not GTK). |
| 849 } | 848 } |
| 850 | 849 |
| 851 // static | 850 // static |
| 852 void TextfieldModel::ClearKillBuffer() { | 851 void TextfieldModel::ClearKillBuffer() { |
| 853 SetKillBuffer(base::string16()); | 852 SetKillBuffer(base::string16()); |
| 854 } | 853 } |
| 855 | 854 |
| 856 } // namespace views | 855 } // namespace views |
| OLD | NEW |