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

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: Fix setComposingText when newCursorPosition < 1 Created 4 years, 8 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 if (!selection.isNone() && !m_compositionRange->collapsed()) { 224 if (!selection.isNone() && !m_compositionRange->collapsed()) {
225 if (selection.start().compareTo(m_compositionRange->startPosition()) >= 0 225 if (selection.start().compareTo(m_compositionRange->startPosition()) >= 0
226 && selection.end().compareTo(m_compositionRange->endPosition()) <= 0 ) 226 && selection.end().compareTo(m_compositionRange->endPosition()) <= 0 )
227 return; 227 return;
228 } 228 }
229 229
230 cancelComposition(); 230 cancelComposition();
231 frame().chromeClient().didCancelCompositionOnSelectionChange(); 231 frame().chromeClient().didCancelCompositionOnSelectionChange();
232 } 232 }
233 233
234 void InputMethodController::setComposition(const String& text, const Vector<Comp ositionUnderline>& underlines, unsigned selectionStart, unsigned selectionEnd) 234 void InputMethodController::setComposition(const String& text, const Vector<Comp ositionUnderline>& underlines, int selectionStart, int selectionEnd)
235 { 235 {
236 Editor::RevealSelectionScope revealSelectionScope(&editor()); 236 Editor::RevealSelectionScope revealSelectionScope(&editor());
237 237
238 // Updates styles before setting selection for composition to prevent 238 // Updates styles before setting selection for composition to prevent
239 // inserting the previous composition text into text nodes oddly. 239 // inserting the previous composition text into text nodes oddly.
240 // See https://bugs.webkit.org/show_bug.cgi?id=46868 240 // See https://bugs.webkit.org/show_bug.cgi?id=46868
241 frame().document()->updateLayoutTree(); 241 frame().document()->updateLayoutTree();
242 242
243 selectComposition(); 243 selectComposition();
244 244
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 m_isDirty = true; 312 m_isDirty = true;
313 m_hasComposition = true; 313 m_hasComposition = true;
314 if (!m_compositionRange) 314 if (!m_compositionRange)
315 m_compositionRange = Range::create(baseNode->document()); 315 m_compositionRange = Range::create(baseNode->document());
316 m_compositionRange->setStart(baseNode, baseOffset); 316 m_compositionRange->setStart(baseNode, baseOffset);
317 m_compositionRange->setEnd(baseNode, extentOffset); 317 m_compositionRange->setEnd(baseNode, extentOffset);
318 318
319 if (baseNode->layoutObject()) 319 if (baseNode->layoutObject())
320 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); 320 baseNode->layoutObject()->setShouldDoFullPaintInvalidation();
321 321
322 unsigned start = std::min(baseOffset + selectionStart, extentOffset); 322 int start = std::min(std::max((int)baseOffset + selectionStart, 0), (int)ext entOffset);
Changwan Ryu 2016/04/01 00:37:26 baseOffset >= 0 so you just need to make sure sele
yabinh 2016/04/01 04:14:17 selectionStart can be negative, because it is the
Changwan Ryu 2016/04/01 05:36:15 I see. Thanks for clarification. By the way, we pr
323 unsigned end = std::min(std::max(start, baseOffset + selectionEnd), extentOf fset); 323 int end = std::min(std::max((int)baseOffset + selectionEnd, start), (int)ext entOffset);
324 RefPtrWillBeRawPtr<Range> selectedRange = Range::create(baseNode->document() , baseNode, start, baseNode, end); 324 RefPtrWillBeRawPtr<Range> selectedRange = Range::create(baseNode->document() , baseNode, start, baseNode, end);
325 frame().selection().setSelectedRange(selectedRange.get(), TextAffinity::Down stream, SelectionDirectionalMode::NonDirectional, NotUserTriggered); 325 frame().selection().setSelectedRange(selectedRange.get(), TextAffinity::Down stream, SelectionDirectionalMode::NonDirectional, NotUserTriggered);
326 326
327 if (underlines.isEmpty()) { 327 if (underlines.isEmpty()) {
328 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor()); 328 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor());
329 return; 329 return;
330 } 330 }
331 for (const auto& underline : underlines) { 331 for (const auto& underline : underlines) {
332 unsigned underlineStart = baseOffset + underline.startOffset; 332 unsigned underlineStart = baseOffset + underline.startOffset;
333 unsigned underlineEnd = baseOffset + underline.endOffset; 333 unsigned underlineEnd = baseOffset + underline.endOffset;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 TypingCommand::deleteSelection(*frame().document()); 453 TypingCommand::deleteSelection(*frame().document());
454 } 454 }
455 455
456 DEFINE_TRACE(InputMethodController) 456 DEFINE_TRACE(InputMethodController)
457 { 457 {
458 visitor->trace(m_frame); 458 visitor->trace(m_frame);
459 visitor->trace(m_compositionRange); 459 visitor->trace(m_compositionRange);
460 } 460 }
461 461
462 } // namespace blink 462 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698