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

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: Store Position objects as local variables... 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 correct Position in that case,
348 // we should make sure |value1| is within range at least.
349 const EphemeralRange& startRange = PlainTextRange(0, start).createRange(*roo tEditableElement);
350 const EphemeralRange& endRange = PlainTextRange(0, end).createRange(*rootEdi tableElement);
351
352 // TODO(yabinh): There should be a better way to create |startPosition| and
353 // |endPosition|. But for now, since we can't get |anchorNode| and |offset|,
354 // we can't create the 2 Position objects directly. So we use
355 // PlainTextRange::createRange as a workaround.
356 const Position& startPosition = startRange.endPosition();
357 const Position& endPosition = endRange.endPosition();
358 Range* selectedRange = Range::create(rootEditableElement->document(), startP osition, endPosition);
338 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered); 359 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered);
339 360
340 if (underlines.isEmpty()) { 361 if (underlines.isEmpty()) {
341 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor()); 362 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor());
342 return; 363 return;
343 } 364 }
344 for (const auto& underline : underlines) { 365 for (const auto& underline : underlines) {
345 unsigned underlineStart = baseOffset + underline.startOffset; 366 unsigned underlineStart = baseOffset + underline.startOffset;
346 unsigned underlineEnd = baseOffset + underline.endOffset; 367 unsigned underlineEnd = baseOffset + underline.endOffset;
347 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un derlineStart), Position(baseNode, underlineEnd)); 368 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()); 489 TypingCommand::deleteSelection(*frame().document());
469 } 490 }
470 491
471 DEFINE_TRACE(InputMethodController) 492 DEFINE_TRACE(InputMethodController)
472 { 493 {
473 visitor->trace(m_frame); 494 visitor->trace(m_frame);
474 visitor->trace(m_compositionRange); 495 visitor->trace(m_compositionRange);
475 } 496 }
476 497
477 } // namespace blink 498 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698