| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 244 |
| 245 bool InputMethodController::finishComposingText( | 245 bool InputMethodController::finishComposingText( |
| 246 ConfirmCompositionBehavior confirmBehavior) { | 246 ConfirmCompositionBehavior confirmBehavior) { |
| 247 if (!hasComposition()) | 247 if (!hasComposition()) |
| 248 return false; | 248 return false; |
| 249 | 249 |
| 250 if (confirmBehavior == KeepSelection) { | 250 if (confirmBehavior == KeepSelection) { |
| 251 PlainTextRange oldOffsets = getSelectionOffsets(); | 251 PlainTextRange oldOffsets = getSelectionOffsets(); |
| 252 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 252 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| 253 | 253 |
| 254 const String& composing = composingText(); | 254 bool result = replaceComposition(composingText()); |
| 255 const bool result = replaceComposition(composing); | |
| 256 | 255 |
| 257 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 256 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 258 // needs to be audited. see http://crbug.com/590369 for more details. | 257 // needs to be audited. see http://crbug.com/590369 for more details. |
| 259 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 258 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 260 | 259 |
| 261 setSelectionOffsets(oldOffsets); | 260 setSelectionOffsets(oldOffsets); |
| 262 | |
| 263 // No DOM update after 'compositionend'. | |
| 264 dispatchCompositionEndEvent(frame(), composing); | |
| 265 | |
| 266 return result; | 261 return result; |
| 267 } | 262 } |
| 268 | 263 |
| 269 return replaceCompositionAndMoveCaret(composingText(), 0, | 264 return replaceCompositionAndMoveCaret(composingText(), 0, |
| 270 Vector<CompositionUnderline>()); | 265 Vector<CompositionUnderline>()); |
| 271 } | 266 } |
| 272 | 267 |
| 273 bool InputMethodController::commitText( | 268 bool InputMethodController::commitText( |
| 274 const String& text, | 269 const String& text, |
| 275 const Vector<CompositionUnderline>& underlines, | 270 const Vector<CompositionUnderline>& underlines, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 305 |
| 311 clear(); | 306 clear(); |
| 312 | 307 |
| 313 insertTextDuringCompositionWithEvents( | 308 insertTextDuringCompositionWithEvents( |
| 314 frame(), text, 0, | 309 frame(), text, 0, |
| 315 TypingCommand::TextCompositionType::TextCompositionConfirm); | 310 TypingCommand::TextCompositionType::TextCompositionConfirm); |
| 316 // Event handler might destroy document. | 311 // Event handler might destroy document. |
| 317 if (!isAvailable()) | 312 if (!isAvailable()) |
| 318 return false; | 313 return false; |
| 319 | 314 |
| 315 // No DOM update after 'compositionend'. |
| 316 dispatchCompositionEndEvent(frame(), text); |
| 317 |
| 320 return true; | 318 return true; |
| 321 } | 319 } |
| 322 | 320 |
| 323 // relativeCaretPosition is relative to the end of the text. | 321 // relativeCaretPosition is relative to the end of the text. |
| 324 static int computeAbsoluteCaretPosition(size_t textStart, | 322 static int computeAbsoluteCaretPosition(size_t textStart, |
| 325 size_t textLength, | 323 size_t textLength, |
| 326 int relativeCaretPosition) { | 324 int relativeCaretPosition) { |
| 327 return textStart + textLength + relativeCaretPosition; | 325 return textStart + textLength + relativeCaretPosition; |
| 328 } | 326 } |
| 329 | 327 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 357 DCHECK(hasComposition()); | 355 DCHECK(hasComposition()); |
| 358 PlainTextRange compositionRange = | 356 PlainTextRange compositionRange = |
| 359 PlainTextRange::create(*rootEditableElement, *m_compositionRange); | 357 PlainTextRange::create(*rootEditableElement, *m_compositionRange); |
| 360 if (compositionRange.isNull()) | 358 if (compositionRange.isNull()) |
| 361 return false; | 359 return false; |
| 362 int textStart = compositionRange.start(); | 360 int textStart = compositionRange.start(); |
| 363 | 361 |
| 364 if (!replaceComposition(text)) | 362 if (!replaceComposition(text)) |
| 365 return false; | 363 return false; |
| 366 | 364 |
| 365 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 366 // needs to be audited. see http://crbug.com/590369 for more details. |
| 367 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 368 |
| 367 addCompositionUnderlines(underlines, rootEditableElement, textStart); | 369 addCompositionUnderlines(underlines, rootEditableElement, textStart); |
| 368 | 370 |
| 369 int absoluteCaretPosition = computeAbsoluteCaretPosition( | 371 int absoluteCaretPosition = computeAbsoluteCaretPosition( |
| 370 textStart, text.length(), relativeCaretPosition); | 372 textStart, text.length(), relativeCaretPosition); |
| 371 if (!moveCaret(absoluteCaretPosition)) | 373 return moveCaret(absoluteCaretPosition); |
| 372 return false; | |
| 373 | |
| 374 // No DOM update after 'compositionend'. | |
| 375 dispatchCompositionEndEvent(frame(), text); | |
| 376 | |
| 377 return true; | |
| 378 } | 374 } |
| 379 | 375 |
| 380 bool InputMethodController::insertText(const String& text) { | 376 bool InputMethodController::insertText(const String& text) { |
| 381 if (dispatchBeforeInputInsertText(document().focusedElement(), text) != | 377 if (dispatchBeforeInputInsertText(document().focusedElement(), text) != |
| 382 DispatchEventResult::NotCanceled) | 378 DispatchEventResult::NotCanceled) |
| 383 return false; | 379 return false; |
| 384 editor().insertText(text, 0); | 380 editor().insertText(text, 0); |
| 385 return true; | 381 return true; |
| 386 } | 382 } |
| 387 | 383 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 // we simply delete selection without sending extra events. | 532 // we simply delete selection without sending extra events. |
| 537 TypingCommand::deleteSelection(document(), | 533 TypingCommand::deleteSelection(document(), |
| 538 TypingCommand::PreventSpellChecking); | 534 TypingCommand::PreventSpellChecking); |
| 539 } | 535 } |
| 540 | 536 |
| 541 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 537 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 542 // needs to be audited. see http://crbug.com/590369 for more details. | 538 // needs to be audited. see http://crbug.com/590369 for more details. |
| 543 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 539 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 544 | 540 |
| 545 setEditableSelectionOffsets(selectedRange); | 541 setEditableSelectionOffsets(selectedRange); |
| 546 | 542 return; |
| 547 // No DOM update after 'compositionend'. | |
| 548 return dispatchCompositionEndEvent(frame(), text); | |
| 549 } | 543 } |
| 550 | 544 |
| 551 // We should send a 'compositionstart' event only when the given text is not | 545 // We should send a 'compositionstart' event only when the given text is not |
| 552 // empty because this function doesn't create a composition node when the text | 546 // empty because this function doesn't create a composition node when the text |
| 553 // is empty. | 547 // is empty. |
| 554 if (!hasComposition()) { | 548 if (!hasComposition()) { |
| 555 target->dispatchEvent( | 549 target->dispatchEvent( |
| 556 CompositionEvent::create(EventTypeNames::compositionstart, | 550 CompositionEvent::create(EventTypeNames::compositionstart, |
| 557 frame().domWindow(), frame().selectedText())); | 551 frame().domWindow(), frame().selectedText())); |
| 558 if (!isAvailable()) | 552 if (!isAvailable()) |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 frame().chromeClient().resetInputMethod(); | 1067 frame().chromeClient().resetInputMethod(); |
| 1074 } | 1068 } |
| 1075 | 1069 |
| 1076 DEFINE_TRACE(InputMethodController) { | 1070 DEFINE_TRACE(InputMethodController) { |
| 1077 visitor->trace(m_frame); | 1071 visitor->trace(m_frame); |
| 1078 visitor->trace(m_compositionRange); | 1072 visitor->trace(m_compositionRange); |
| 1079 SynchronousMutationObserver::trace(visitor); | 1073 SynchronousMutationObserver::trace(visitor); |
| 1080 } | 1074 } |
| 1081 | 1075 |
| 1082 } // namespace blink | 1076 } // namespace blink |
| OLD | NEW |