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

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: For multiple nodes. 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 start = std::max(static_cast<int>(getSelectionOffsets().start()) + selec tionStart, 0);
337 Range* selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end); 337 int end = std::max(static_cast<int>(getSelectionOffsets().start()) + selecti onEnd, start);
338
339 Element* rootEditableElement = frame().selection().rootEditableElement();
340 if (!rootEditableElement)
341 return;
342
343 // In case of exceeding the right boundary.
344 const EphemeralRange startRange = PlainTextRange(0, start).createRange(*root EditableElement);
Changwan Ryu 2016/05/09 12:52:23 You can create only range to handle both: const E
yabinh 2016/05/09 13:02:50 If both number1 and number2 exceed the right bound
345 const EphemeralRange endRange = PlainTextRange(0, end).createRange(*rootEdit ableElement);
346
347 start = startRange.endPosition().computeOffsetInContainerNode();
348 Node* startNode = startRange.endPosition().computeContainerNode();
349
350 end = endRange.endPosition().computeOffsetInContainerNode();
351 Node* endNode = endRange.endPosition().computeContainerNode();
352
353 Range* selectedRange = Range::create(rootEditableElement->document(), startN ode, start, endNode, end);
338 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered); 354 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered);
339 355
340 if (underlines.isEmpty()) { 356 if (underlines.isEmpty()) {
341 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor()); 357 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor());
342 return; 358 return;
343 } 359 }
344 for (const auto& underline : underlines) { 360 for (const auto& underline : underlines) {
345 unsigned underlineStart = baseOffset + underline.startOffset; 361 unsigned underlineStart = baseOffset + underline.startOffset;
346 unsigned underlineEnd = baseOffset + underline.endOffset; 362 unsigned underlineEnd = baseOffset + underline.endOffset;
347 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un derlineStart), Position(baseNode, underlineEnd)); 363 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()); 484 TypingCommand::deleteSelection(*frame().document());
469 } 485 }
470 486
471 DEFINE_TRACE(InputMethodController) 487 DEFINE_TRACE(InputMethodController)
472 { 488 {
473 visitor->trace(m_frame); 489 visitor->trace(m_frame);
474 visitor->trace(m_compositionRange); 490 visitor->trace(m_compositionRange);
475 } 491 }
476 492
477 } // namespace blink 493 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698