Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 2493703002: Make "compositionend" event fired after setting caret position (Closed)
Patch Set: Not able to listen to selectionchange event Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 bool InputMethodController::finishComposingText( 207 bool InputMethodController::finishComposingText(
208 ConfirmCompositionBehavior confirmBehavior) { 208 ConfirmCompositionBehavior confirmBehavior) {
209 if (!hasComposition()) 209 if (!hasComposition())
210 return false; 210 return false;
211 211
212 if (confirmBehavior == KeepSelection) { 212 if (confirmBehavior == KeepSelection) {
213 PlainTextRange oldOffsets = getSelectionOffsets(); 213 PlainTextRange oldOffsets = getSelectionOffsets();
214 Editor::RevealSelectionScope revealSelectionScope(&editor()); 214 Editor::RevealSelectionScope revealSelectionScope(&editor());
215 215
216 bool result = replaceComposition(composingText()); 216 const String& composing = composingText();
217 bool result = replaceComposition(composing);
217 218
218 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 219 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
219 // needs to be audited. see http://crbug.com/590369 for more details. 220 // needs to be audited. see http://crbug.com/590369 for more details.
220 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 221 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
221 222
222 setSelectionOffsets(oldOffsets); 223 setSelectionOffsets(oldOffsets);
224
225 // No DOM update after 'compositionend'.
226 dispatchCompositionEndEvent(frame(), composing);
227
223 return result; 228 return result;
224 } 229 }
225 230
226 return replaceCompositionAndMoveCaret(composingText(), 0); 231 return replaceCompositionAndMoveCaret(composingText(), 0);
227 } 232 }
228 233
229 bool InputMethodController::commitText(const String& text, 234 bool InputMethodController::commitText(const String& text,
230 int relativeCaretPosition) { 235 int relativeCaretPosition) {
231 if (hasComposition()) 236 if (hasComposition())
232 return replaceCompositionAndMoveCaret(text, relativeCaretPosition); 237 return replaceCompositionAndMoveCaret(text, relativeCaretPosition);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 274
270 clear(); 275 clear();
271 276
272 insertTextDuringCompositionWithEvents( 277 insertTextDuringCompositionWithEvents(
273 frame(), text, 0, 278 frame(), text, 0,
274 TypingCommand::TextCompositionType::TextCompositionConfirm); 279 TypingCommand::TextCompositionType::TextCompositionConfirm);
275 // Event handler might destroy document. 280 // Event handler might destroy document.
276 if (!frame().document()) 281 if (!frame().document())
277 return false; 282 return false;
278 283
279 // No DOM update after 'compositionend'.
280 dispatchCompositionEndEvent(frame(), text);
281
282 return true; 284 return true;
283 } 285 }
284 286
285 // relativeCaretPosition is relative to the end of the text. 287 // relativeCaretPosition is relative to the end of the text.
286 static int computeAbsoluteCaretPosition(size_t textStart, 288 static int computeAbsoluteCaretPosition(size_t textStart,
287 size_t textLength, 289 size_t textLength,
288 int relativeCaretPosition) { 290 int relativeCaretPosition) {
289 return textStart + textLength + relativeCaretPosition; 291 return textStart + textLength + relativeCaretPosition;
290 } 292 }
291 293
292 bool InputMethodController::replaceCompositionAndMoveCaret( 294 bool InputMethodController::replaceCompositionAndMoveCaret(
293 const String& text, 295 const String& text,
294 int relativeCaretPosition) { 296 int relativeCaretPosition) {
295 Element* rootEditableElement = frame().selection().rootEditableElement(); 297 Element* rootEditableElement = frame().selection().rootEditableElement();
296 if (!rootEditableElement) 298 if (!rootEditableElement)
297 return false; 299 return false;
298 PlainTextRange compositionRange = 300 PlainTextRange compositionRange =
299 PlainTextRange::create(*rootEditableElement, *m_compositionRange); 301 PlainTextRange::create(*rootEditableElement, *m_compositionRange);
300 if (compositionRange.isNull()) 302 if (compositionRange.isNull())
301 return false; 303 return false;
302 int textStart = compositionRange.start(); 304 int textStart = compositionRange.start();
303 305
304 if (!replaceComposition(text)) 306 if (!replaceComposition(text))
305 return false; 307 return false;
306 308
307 int absoluteCaretPosition = computeAbsoluteCaretPosition( 309 int absoluteCaretPosition = computeAbsoluteCaretPosition(
308 textStart, text.length(), relativeCaretPosition); 310 textStart, text.length(), relativeCaretPosition);
309 return moveCaret(absoluteCaretPosition); 311 if (!moveCaret(absoluteCaretPosition))
312 return false;
313
314 // No DOM update after 'compositionend'.
315 dispatchCompositionEndEvent(frame(), text);
316
317 return true;
310 } 318 }
311 319
312 bool InputMethodController::insertText(const String& text) { 320 bool InputMethodController::insertText(const String& text) {
313 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), 321 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(),
314 text) != DispatchEventResult::NotCanceled) 322 text) != DispatchEventResult::NotCanceled)
315 return false; 323 return false;
316 editor().insertText(text, 0); 324 editor().insertText(text, 0);
317 return true; 325 return true;
318 } 326 }
319 327
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 // we simply delete selection without sending extra events. 617 // we simply delete selection without sending extra events.
610 TypingCommand::deleteSelection(*frame().document(), 618 TypingCommand::deleteSelection(*frame().document(),
611 TypingCommand::PreventSpellChecking); 619 TypingCommand::PreventSpellChecking);
612 } 620 }
613 621
614 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 622 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
615 // needs to be audited. see http://crbug.com/590369 for more details. 623 // needs to be audited. see http://crbug.com/590369 for more details.
616 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 624 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
617 625
618 setEditableSelectionOffsets(selectedRange); 626 setEditableSelectionOffsets(selectedRange);
619 return; 627
628 // No DOM update after 'compositionend'.
629 return dispatchCompositionEndEvent(frame(), text);
620 } 630 }
621 631
622 // We should send a 'compositionstart' event only when the given text is not 632 // We should send a 'compositionstart' event only when the given text is not
623 // empty because this function doesn't create a composition node when the text 633 // empty because this function doesn't create a composition node when the text
624 // is empty. 634 // is empty.
625 if (!hasComposition()) { 635 if (!hasComposition()) {
626 target->dispatchEvent( 636 target->dispatchEvent(
627 CompositionEvent::create(EventTypeNames::compositionstart, 637 CompositionEvent::create(EventTypeNames::compositionstart,
628 frame().domWindow(), frame().selectedText())); 638 frame().domWindow(), frame().selectedText()));
629 if (!frame().document()) 639 if (!frame().document())
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 1175
1166 return WebTextInputTypeNone; 1176 return WebTextInputTypeNone;
1167 } 1177 }
1168 1178
1169 DEFINE_TRACE(InputMethodController) { 1179 DEFINE_TRACE(InputMethodController) {
1170 visitor->trace(m_frame); 1180 visitor->trace(m_frame);
1171 visitor->trace(m_compositionRange); 1181 visitor->trace(m_compositionRange);
1172 } 1182 }
1173 1183
1174 } // namespace blink 1184 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698