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

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: Sync. Almost the same to the previous patch. Created 4 years, 4 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;
240 // if newCursorPosition <= 0, it is relative to the start of the text.
241 if (newCursorPosition > 0)
242 newCursorPosition += text.length() - 1;
243
244 // According to Android documentation, the new cursor position is
Changwan Ryu 2016/08/24 01:32:03 This comment is platform-specific. Could you make
yabinh 2016/08/24 06:05:01 Done.
245 // relative to the composing text if any, or relative to the selection
246 // if no composing text.
247 if (hasComposition()) {
248 Element* rootEditableElement = frame().selection().rootEditableEleme nt();
249 if (!rootEditableElement)
250 return false;
251 PlainTextRange compositionRange = PlainTextRange::create(*rootEditab leElement, *m_compositionRange);
252
253 if (text.length() == 0)
254 newCursorPosition += compositionRange.end();
255 else
256 newCursorPosition += compositionRange.start();
257 } else {
258 PlainTextRange selectionRange = getSelectionOffsets();
259 if (selectionRange.isNull())
260 return false;
261 newCursorPosition += getSelectionOffsets().start();
262 }
263 }
264
238 if (!hasComposition()) { 265 if (!hasComposition()) {
239 if (!text.length()) 266 if (!text.length())
240 return false; 267 return false;
241 268
242 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text) != DispatchEventResult::NotCanceled) 269 if (dispatchBeforeInputInsertText(frame().document()->focusedElement(), text) != DispatchEventResult::NotCanceled)
243 return false; 270 return false;
244 271
245 editor().insertText(text, 0); 272 editor().insertText(text, 0);
246 return true; 273 } else if (text.length()) {
274 confirmComposition(text);
275 } else if (confirmBehavior == DoNotKeepSelection) {
276 if (!confirmComposition(composingText(), DoNotKeepSelection))
277 return false;
278 } else {
279 SelectionOffsetsScope selectionOffsetsScope(this);
280 return confirmComposition();
247 } 281 }
248 282
249 if (text.length()) { 283 if (confirmBehavior == KeepSelection)
250 confirmComposition(text);
251 return true; 284 return true;
252 }
253 285
254 if (confirmBehavior == DoNotKeepSelection) 286 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
255 return confirmComposition(composingText(), DoNotKeepSelection);
256 287
257 SelectionOffsetsScope selectionOffsetsScope(this); 288 PlainTextRange selectedRange = createRangeForSelection(newCursorPosition, ne wCursorPosition, 0);
258 return confirmComposition(); 289 if (selectedRange.isNull())
290 return false;
291 return setEditableSelectionOffsets(selectedRange);
259 } 292 }
260 293
261 void InputMethodController::cancelComposition() 294 void InputMethodController::cancelComposition()
262 { 295 {
263 if (!hasComposition()) 296 if (!hasComposition())
264 return; 297 return;
265 298
266 Editor::RevealSelectionScope revealSelectionScope(&editor()); 299 Editor::RevealSelectionScope revealSelectionScope(&editor());
267 300
268 if (frame().selection().isNone()) 301 if (frame().selection().isNone())
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 TypingCommand::deleteSelection(*frame().document()); 608 TypingCommand::deleteSelection(*frame().document());
576 } 609 }
577 610
578 DEFINE_TRACE(InputMethodController) 611 DEFINE_TRACE(InputMethodController)
579 { 612 {
580 visitor->trace(m_frame); 613 visitor->trace(m_frame);
581 visitor->trace(m_compositionRange); 614 visitor->trace(m_compositionRange);
582 } 615 }
583 616
584 } // namespace blink 617 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698