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

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

Issue 1995333002: Handle newCursorPosition correctly for Android's commitText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add 3 tests Created 4 years, 3 months 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // Event handler might destroy document. 226 // Event handler might destroy document.
227 if (!frame().document()) 227 if (!frame().document())
228 return false; 228 return false;
229 229
230 // No DOM update after 'compositionend'. 230 // No DOM update after 'compositionend'.
231 dispatchCompositionEndEvent(frame(), text); 231 dispatchCompositionEndEvent(frame(), text);
232 232
233 return true; 233 return true;
234 } 234 }
235 235
236 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior) 236 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior, int newCursorPosition)
237 { 237 {
238 if (confirmBehavior == DoNotKeepSelection) {
239 // If newCursorPosition > 0, it's relative to the end of the text - 1;
aelias_OOO_until_Jul13 2016/08/24 08:13:07 Please add a comment that this is to match Android
yabinh 2016/08/25 02:32:21 Done.
240 // if newCursorPosition <= 0, it is relative to the start of the text.
241 if (newCursorPosition > 0)
242 newCursorPosition += text.length() - 1;
243
244 // The new cursor position is relative to the composing text if any, or
245 // relative to the selection if no composing text.
246 if (hasComposition()) {
247 Element* rootEditableElement = frame().selection().rootEditableEleme nt();
248 if (!rootEditableElement)
249 return false;
250 PlainTextRange compositionRange = PlainTextRange::create(*rootEditab leElement, *m_compositionRange);
251
252 if (text.length() == 0)
253 newCursorPosition += compositionRange.end();
aelias_OOO_until_Jul13 2016/08/24 08:13:07 I read your explanation above that text.length() =
yabinh 2016/08/25 02:32:21 Done.
254 else
255 newCursorPosition += compositionRange.start();
256 } else {
257 PlainTextRange selectionRange = getSelectionOffsets();
258 if (selectionRange.isNull())
259 return false;
260 newCursorPosition += getSelectionOffsets().start();
261 }
262 }
263
238 if (!hasComposition()) { 264 if (!hasComposition()) {
239 if (!text.length()) 265 if (!text.length())
240 return false; 266 return false;
241 267
242 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text) != DispatchEventResult::NotCanceled) 268 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text) != DispatchEventResult::NotCanceled)
243 return false; 269 return false;
244 270
245 editor().insertText(text, 0); 271 editor().insertText(text, 0);
246 return true; 272 } else if (text.length()) {
aelias_OOO_until_Jul13 2016/08/24 08:13:07 The code flow is getting difficult to follow. The
yabinh 2016/08/25 02:32:21 For#1, The old InputMethodController#confirmCompos
273 confirmComposition(text);
274 } else if (confirmBehavior == DoNotKeepSelection) {
275 if (!confirmComposition(composingText(), DoNotKeepSelection))
276 return false;
277 } else {
278 SelectionOffsetsScope selectionOffsetsScope(this);
279 return confirmComposition();
247 } 280 }
248 281
249 if (text.length()) { 282 if (confirmBehavior == KeepSelection)
250 confirmComposition(text);
251 return true; 283 return true;
252 }
253 284
254 if (confirmBehavior == DoNotKeepSelection) 285 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
255 return confirmComposition(composingText(), DoNotKeepSelection);
256 286
257 SelectionOffsetsScope selectionOffsetsScope(this); 287 PlainTextRange selectedRange = createRangeForSelection(newCursorPosition, ne wCursorPosition, 0);
258 return confirmComposition(); 288 if (selectedRange.isNull())
289 return false;
290 return setEditableSelectionOffsets(selectedRange);
259 } 291 }
260 292
261 void InputMethodController::cancelComposition() 293 void InputMethodController::cancelComposition()
262 { 294 {
263 if (!hasComposition()) 295 if (!hasComposition())
264 return; 296 return;
265 297
266 Editor::RevealSelectionScope revealSelectionScope(&editor()); 298 Editor::RevealSelectionScope revealSelectionScope(&editor());
267 299
268 if (frame().selection().isNone()) 300 if (frame().selection().isNone())
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 TypingCommand::deleteSelection(*frame().document()); 607 TypingCommand::deleteSelection(*frame().document());
576 } 608 }
577 609
578 DEFINE_TRACE(InputMethodController) 610 DEFINE_TRACE(InputMethodController)
579 { 611 {
580 visitor->trace(m_frame); 612 visitor->trace(m_frame);
581 visitor->trace(m_compositionRange); 613 visitor->trace(m_compositionRange);
582 } 614 }
583 615
584 } // namespace blink 616 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698