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

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

Powered by Google App Engine
This is Rietveld 408576698