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

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

Issue 1847583003: Fix setComposingText when newCursorPosition != 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid using innerText() Created 4 years, 7 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (!selection.isNone() && !m_compositionRange->collapsed()) { 232 if (!selection.isNone() && !m_compositionRange->collapsed()) {
233 if (selection.start().compareTo(m_compositionRange->startPosition()) >= 0 233 if (selection.start().compareTo(m_compositionRange->startPosition()) >= 0
234 && selection.end().compareTo(m_compositionRange->endPosition()) <= 0 ) 234 && selection.end().compareTo(m_compositionRange->endPosition()) <= 0 )
235 return; 235 return;
236 } 236 }
237 237
238 cancelComposition(); 238 cancelComposition();
239 frame().chromeClient().didCancelCompositionOnSelectionChange(); 239 frame().chromeClient().didCancelCompositionOnSelectionChange();
240 } 240 }
241 241
242 void InputMethodController::setComposition(const String& text, const Vector<Comp ositionUnderline>& underlines, unsigned selectionStart, unsigned selectionEnd) 242 void InputMethodController::setComposition(const String& text, const Vector<Comp ositionUnderline>& underlines, int selectionStart, int selectionEnd)
243 { 243 {
244 Editor::RevealSelectionScope revealSelectionScope(&editor()); 244 Editor::RevealSelectionScope revealSelectionScope(&editor());
245 245
246 // Updates styles before setting selection for composition to prevent 246 // Updates styles before setting selection for composition to prevent
247 // inserting the previous composition text into text nodes oddly. 247 // inserting the previous composition text into text nodes oddly.
248 // See https://bugs.webkit.org/show_bug.cgi?id=46868 248 // See https://bugs.webkit.org/show_bug.cgi?id=46868
249 frame().document()->updateLayoutTree(); 249 frame().document()->updateLayoutTree();
250 250
251 selectComposition(); 251 selectComposition();
252 252
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 m_isDirty = true; 325 m_isDirty = true;
326 m_hasComposition = true; 326 m_hasComposition = true;
327 if (!m_compositionRange) 327 if (!m_compositionRange)
328 m_compositionRange = Range::create(baseNode->document()); 328 m_compositionRange = Range::create(baseNode->document());
329 m_compositionRange->setStart(baseNode, baseOffset); 329 m_compositionRange->setStart(baseNode, baseOffset);
330 m_compositionRange->setEnd(baseNode, extentOffset); 330 m_compositionRange->setEnd(baseNode, extentOffset);
331 331
332 if (baseNode->layoutObject()) 332 if (baseNode->layoutObject())
333 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); 333 baseNode->layoutObject()->setShouldDoFullPaintInvalidation();
334 334
335 unsigned start = std::min(baseOffset + selectionStart, extentOffset); 335 // In case of exceeding the left boundary.
336 unsigned end = std::min(std::max(start, baseOffset + selectionEnd), extentOf fset); 336 int selectionOffsetsStart = static_cast<int>(getSelectionOffsets().start());
337 Range* selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end); 337 int start = std::max(selectionOffsetsStart + selectionStart, 0);
338 int end = std::max(selectionOffsetsStart + selectionEnd, start);
339
340 Element* rootEditableElement = frame().selection().rootEditableElement();
341 if (!rootEditableElement)
342 return;
343
344 // In case of exceeding the right boundary.
345 // If both |value1| and |value2| exceed right boundary,
346 // PlainTextRange(value1, value2)::createRange() will return a default
347 // value, which is [0,0]. In order to get the right boundary in that case,
348 // we should make sure |value1| is within range at least.
349 const EphemeralRange startRange = PlainTextRange(0, start).createRange(*root EditableElement);
aelias_OOO_until_Jul13 2016/05/10 20:44:11 These ranges are odd, wouldn't it have the same ef
yabinh 2016/05/11 00:28:38 That's right. But in order to create Position obje
aelias_OOO_until_Jul13 2016/05/11 02:49:35 OK, it looks like the algorithm in createRange() i
yosin_UTC9 2016/05/11 05:53:23 nit: s/const EphemeralRange/const EphemeralRange&/
350 const EphemeralRange endRange = PlainTextRange(0, end).createRange(*rootEdit ableElement);
yosin_UTC9 2016/05/11 05:53:23 nit: s/const EphemeralRange/const EphemeralRange&/
351
352 Range* selectedRange = Range::create(rootEditableElement->document(), startR ange.endPosition(), endRange.endPosition());
338 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered); 353 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered);
339 354
340 if (underlines.isEmpty()) { 355 if (underlines.isEmpty()) {
341 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor()); 356 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor());
342 return; 357 return;
343 } 358 }
344 for (const auto& underline : underlines) { 359 for (const auto& underline : underlines) {
345 unsigned underlineStart = baseOffset + underline.startOffset; 360 unsigned underlineStart = baseOffset + underline.startOffset;
346 unsigned underlineEnd = baseOffset + underline.endOffset; 361 unsigned underlineEnd = baseOffset + underline.endOffset;
347 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un derlineStart), Position(baseNode, underlineEnd)); 362 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un derlineStart), Position(baseNode, underlineEnd));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 TypingCommand::deleteSelection(*frame().document()); 483 TypingCommand::deleteSelection(*frame().document());
469 } 484 }
470 485
471 DEFINE_TRACE(InputMethodController) 486 DEFINE_TRACE(InputMethodController)
472 { 487 {
473 visitor->trace(m_frame); 488 visitor->trace(m_frame);
474 visitor->trace(m_compositionRange); 489 visitor->trace(m_compositionRange);
475 } 490 }
476 491
477 } // namespace blink 492 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698