Chromium Code Reviews| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 216 |
| 217 bool InputMethodController::finishComposingText( | 217 bool InputMethodController::finishComposingText( |
| 218 ConfirmCompositionBehavior confirmBehavior) { | 218 ConfirmCompositionBehavior confirmBehavior) { |
| 219 if (!hasComposition()) | 219 if (!hasComposition()) |
| 220 return false; | 220 return false; |
| 221 | 221 |
| 222 if (confirmBehavior == KeepSelection) { | 222 if (confirmBehavior == KeepSelection) { |
| 223 PlainTextRange oldOffsets = getSelectionOffsets(); | 223 PlainTextRange oldOffsets = getSelectionOffsets(); |
| 224 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 224 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| 225 | 225 |
| 226 bool result = replaceComposition(composingText()); | 226 const String& composing = composingText(); |
| 227 const bool result = replaceComposition(composing); | |
| 227 | 228 |
| 228 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 229 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 229 // needs to be audited. see http://crbug.com/590369 for more details. | 230 // needs to be audited. see http://crbug.com/590369 for more details. |
| 230 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 231 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 231 | 232 |
| 232 setSelectionOffsets(oldOffsets); | 233 setSelectionOffsets(oldOffsets); |
| 234 | |
| 235 // No DOM update after 'compositionend'. | |
| 236 dispatchCompositionEndEvent(frame(), composing); | |
| 237 | |
| 233 return result; | 238 return result; |
| 234 } | 239 } |
| 235 | 240 |
| 236 return replaceCompositionAndMoveCaret(composingText(), 0); | 241 return replaceCompositionAndMoveCaret(composingText(), 0); |
| 237 } | 242 } |
| 238 | 243 |
| 239 bool InputMethodController::commitText(const String& text, | 244 bool InputMethodController::commitText(const String& text, |
| 240 int relativeCaretPosition) { | 245 int relativeCaretPosition) { |
| 241 if (hasComposition()) | 246 if (hasComposition()) |
| 242 return replaceCompositionAndMoveCaret(text, relativeCaretPosition); | 247 return replaceCompositionAndMoveCaret(text, relativeCaretPosition); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 | 284 |
| 280 clear(); | 285 clear(); |
| 281 | 286 |
| 282 insertTextDuringCompositionWithEvents( | 287 insertTextDuringCompositionWithEvents( |
| 283 frame(), text, 0, | 288 frame(), text, 0, |
| 284 TypingCommand::TextCompositionType::TextCompositionConfirm); | 289 TypingCommand::TextCompositionType::TextCompositionConfirm); |
| 285 // Event handler might destroy document. | 290 // Event handler might destroy document. |
| 286 if (!isAvailable()) | 291 if (!isAvailable()) |
| 287 return false; | 292 return false; |
| 288 | 293 |
| 289 // No DOM update after 'compositionend'. | |
| 290 dispatchCompositionEndEvent(frame(), text); | |
| 291 | |
| 292 return true; | 294 return true; |
| 293 } | 295 } |
| 294 | 296 |
| 295 // relativeCaretPosition is relative to the end of the text. | 297 // relativeCaretPosition is relative to the end of the text. |
| 296 static int computeAbsoluteCaretPosition(size_t textStart, | 298 static int computeAbsoluteCaretPosition(size_t textStart, |
| 297 size_t textLength, | 299 size_t textLength, |
| 298 int relativeCaretPosition) { | 300 int relativeCaretPosition) { |
| 299 return textStart + textLength + relativeCaretPosition; | 301 return textStart + textLength + relativeCaretPosition; |
| 300 } | 302 } |
| 301 | 303 |
| 302 bool InputMethodController::replaceCompositionAndMoveCaret( | 304 bool InputMethodController::replaceCompositionAndMoveCaret( |
| 303 const String& text, | 305 const String& text, |
| 304 int relativeCaretPosition) { | 306 int relativeCaretPosition) { |
| 305 Element* rootEditableElement = frame().selection().rootEditableElement(); | 307 Element* rootEditableElement = frame().selection().rootEditableElement(); |
| 306 if (!rootEditableElement) | 308 if (!rootEditableElement) |
| 307 return false; | 309 return false; |
| 308 PlainTextRange compositionRange = | 310 PlainTextRange compositionRange = |
| 309 PlainTextRange::create(*rootEditableElement, *m_compositionRange); | 311 PlainTextRange::create(*rootEditableElement, *m_compositionRange); |
| 310 if (compositionRange.isNull()) | 312 if (compositionRange.isNull()) |
| 311 return false; | 313 return false; |
| 312 int textStart = compositionRange.start(); | 314 int textStart = compositionRange.start(); |
| 313 | 315 |
| 314 if (!replaceComposition(text)) | 316 if (!replaceComposition(text)) |
| 315 return false; | 317 return false; |
| 316 | 318 |
| 317 int absoluteCaretPosition = computeAbsoluteCaretPosition( | 319 int absoluteCaretPosition = computeAbsoluteCaretPosition( |
| 318 textStart, text.length(), relativeCaretPosition); | 320 textStart, text.length(), relativeCaretPosition); |
| 319 return moveCaret(absoluteCaretPosition); | 321 if (!moveCaret(absoluteCaretPosition)) |
| 322 return false; | |
| 323 | |
| 324 // No DOM update after 'compositionend'. | |
| 325 dispatchCompositionEndEvent(frame(), text); | |
| 326 | |
| 327 return true; | |
| 320 } | 328 } |
| 321 | 329 |
| 322 bool InputMethodController::insertText(const String& text) { | 330 bool InputMethodController::insertText(const String& text) { |
| 323 if (dispatchBeforeInputInsertText(document().focusedElement(), text) != | 331 if (dispatchBeforeInputInsertText(document().focusedElement(), text) != |
| 324 DispatchEventResult::NotCanceled) | 332 DispatchEventResult::NotCanceled) |
| 325 return false; | 333 return false; |
| 326 editor().insertText(text, 0); | 334 editor().insertText(text, 0); |
| 327 return true; | 335 return true; |
| 328 } | 336 } |
| 329 | 337 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 // we simply delete selection without sending extra events. | 628 // we simply delete selection without sending extra events. |
| 621 TypingCommand::deleteSelection(document(), | 629 TypingCommand::deleteSelection(document(), |
| 622 TypingCommand::PreventSpellChecking); | 630 TypingCommand::PreventSpellChecking); |
| 623 } | 631 } |
| 624 | 632 |
| 625 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 633 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 626 // needs to be audited. see http://crbug.com/590369 for more details. | 634 // needs to be audited. see http://crbug.com/590369 for more details. |
| 627 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 635 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 628 | 636 |
| 629 setEditableSelectionOffsets(selectedRange); | 637 setEditableSelectionOffsets(selectedRange); |
| 630 return; | 638 |
| 639 // No DOM update after 'compositionend'. | |
| 640 return dispatchCompositionEndEvent(frame(), text); | |
|
aelias_OOO_until_Jul13
2017/01/27 02:23:40
This was reverted due to http://crbug.com/674295.
| |
| 631 } | 641 } |
| 632 | 642 |
| 633 // We should send a 'compositionstart' event only when the given text is not | 643 // We should send a 'compositionstart' event only when the given text is not |
| 634 // empty because this function doesn't create a composition node when the text | 644 // empty because this function doesn't create a composition node when the text |
| 635 // is empty. | 645 // is empty. |
| 636 if (!hasComposition()) { | 646 if (!hasComposition()) { |
| 637 target->dispatchEvent( | 647 target->dispatchEvent( |
| 638 CompositionEvent::create(EventTypeNames::compositionstart, | 648 CompositionEvent::create(EventTypeNames::compositionstart, |
| 639 frame().domWindow(), frame().selectedText())); | 649 frame().domWindow(), frame().selectedText())); |
| 640 if (!isAvailable()) | 650 if (!isAvailable()) |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 | 1182 |
| 1173 return WebTextInputTypeNone; | 1183 return WebTextInputTypeNone; |
| 1174 } | 1184 } |
| 1175 | 1185 |
| 1176 DEFINE_TRACE(InputMethodController) { | 1186 DEFINE_TRACE(InputMethodController) { |
| 1177 visitor->trace(m_frame); | 1187 visitor->trace(m_frame); |
| 1178 visitor->trace(m_compositionRange); | 1188 visitor->trace(m_compositionRange); |
| 1179 } | 1189 } |
| 1180 | 1190 |
| 1181 } // namespace blink | 1191 } // namespace blink |
| OLD | NEW |