| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 402 |
| 403 bool InputMethodController::CommitText( | 403 bool InputMethodController::CommitText( |
| 404 const String& text, | 404 const String& text, |
| 405 const Vector<CompositionUnderline>& underlines, | 405 const Vector<CompositionUnderline>& underlines, |
| 406 int relative_caret_position) { | 406 int relative_caret_position) { |
| 407 if (HasComposition()) { | 407 if (HasComposition()) { |
| 408 return ReplaceCompositionAndMoveCaret(text, relative_caret_position, | 408 return ReplaceCompositionAndMoveCaret(text, relative_caret_position, |
| 409 underlines); | 409 underlines); |
| 410 } | 410 } |
| 411 | 411 |
| 412 // We should do nothing in this case, because: | |
| 413 // 1. No need to insert text when text is empty. | |
| 414 // 2. Shouldn't move caret when relativeCaretPosition == 0 to avoid | |
| 415 // duplicate selection change event. | |
| 416 if (!text.length() && !relative_caret_position) | |
| 417 return false; | |
| 418 | |
| 419 return InsertTextAndMoveCaret(text, relative_caret_position, underlines); | 412 return InsertTextAndMoveCaret(text, relative_caret_position, underlines); |
| 420 } | 413 } |
| 421 | 414 |
| 422 bool InputMethodController::ReplaceComposition(const String& text) { | 415 bool InputMethodController::ReplaceComposition(const String& text) { |
| 423 if (!HasComposition()) | 416 if (!HasComposition()) |
| 424 return false; | 417 return false; |
| 425 | 418 |
| 426 // Select the text that will be deleted or replaced. | 419 // Select the text that will be deleted or replaced. |
| 427 SelectComposition(); | 420 SelectComposition(); |
| 428 | 421 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 513 |
| 521 bool InputMethodController::InsertTextAndMoveCaret( | 514 bool InputMethodController::InsertTextAndMoveCaret( |
| 522 const String& text, | 515 const String& text, |
| 523 int relative_caret_position, | 516 int relative_caret_position, |
| 524 const Vector<CompositionUnderline>& underlines) { | 517 const Vector<CompositionUnderline>& underlines) { |
| 525 PlainTextRange selection_range = GetSelectionOffsets(); | 518 PlainTextRange selection_range = GetSelectionOffsets(); |
| 526 if (selection_range.IsNull()) | 519 if (selection_range.IsNull()) |
| 527 return false; | 520 return false; |
| 528 int text_start = selection_range.Start(); | 521 int text_start = selection_range.Start(); |
| 529 | 522 |
| 530 if (text.length()) { | 523 if (!InsertText(text)) |
| 531 if (!InsertText(text)) | 524 return false; |
| 532 return false; | 525 Element* root_editable_element = |
| 533 | 526 GetFrame() |
| 534 Element* root_editable_element = | 527 .Selection() |
| 535 GetFrame() | 528 .ComputeVisibleSelectionInDOMTreeDeprecated() |
| 536 .Selection() | 529 .RootEditableElement(); |
| 537 .ComputeVisibleSelectionInDOMTreeDeprecated() | 530 if (root_editable_element) { |
| 538 .RootEditableElement(); | 531 AddCompositionUnderlines(underlines, root_editable_element, text_start); |
| 539 if (root_editable_element) { | |
| 540 AddCompositionUnderlines(underlines, root_editable_element, text_start); | |
| 541 } | |
| 542 } | 532 } |
| 543 | 533 |
| 544 int absolute_caret_position = ComputeAbsoluteCaretPosition( | 534 int absolute_caret_position = ComputeAbsoluteCaretPosition( |
| 545 text_start, text.length(), relative_caret_position); | 535 text_start, text.length(), relative_caret_position); |
| 546 return MoveCaret(absolute_caret_position); | 536 return MoveCaret(absolute_caret_position); |
| 547 } | 537 } |
| 548 | 538 |
| 549 void InputMethodController::CancelComposition() { | 539 void InputMethodController::CancelComposition() { |
| 550 if (!HasComposition()) | 540 if (!HasComposition()) |
| 551 return; | 541 return; |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 FinishComposingText(kKeepSelection); | 1237 FinishComposingText(kKeepSelection); |
| 1248 } | 1238 } |
| 1249 | 1239 |
| 1250 DEFINE_TRACE(InputMethodController) { | 1240 DEFINE_TRACE(InputMethodController) { |
| 1251 visitor->Trace(frame_); | 1241 visitor->Trace(frame_); |
| 1252 visitor->Trace(composition_range_); | 1242 visitor->Trace(composition_range_); |
| 1253 SynchronousMutationObserver::Trace(visitor); | 1243 SynchronousMutationObserver::Trace(visitor); |
| 1254 } | 1244 } |
| 1255 | 1245 |
| 1256 } // namespace blink | 1246 } // namespace blink |
| OLD | NEW |