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

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

Issue 2689233006: Fix bug on Android causing composition underlines to appear in the wrong place (Closed)
Patch Set: Got test case working (the trick is to manually add the line break) Created 3 years, 10 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 345
346 // relativeCaretPosition is relative to the end of the text. 346 // relativeCaretPosition is relative to the end of the text.
347 static int computeAbsoluteCaretPosition(size_t textStart, 347 static int computeAbsoluteCaretPosition(size_t textStart,
348 size_t textLength, 348 size_t textLength,
349 int relativeCaretPosition) { 349 int relativeCaretPosition) {
350 return textStart + textLength + relativeCaretPosition; 350 return textStart + textLength + relativeCaretPosition;
351 } 351 }
352 352
353 void InputMethodController::addCompositionUnderlines( 353 void InputMethodController::addCompositionUnderlines(
354 const Vector<CompositionUnderline>& underlines, 354 const Vector<CompositionUnderline>& underlines,
355 ContainerNode* rootEditableElement, 355 ContainerNode* baseElement,
yosin_UTC9 2017/02/20 06:29:10 Please do renaming in another patch for ease of re
356 unsigned offset) { 356 unsigned offsetInPlainChars) {
357 for (const auto& underline : underlines) { 357 for (const auto& underline : underlines) {
358 unsigned underlineStart = offset + underline.startOffset(); 358 unsigned underlineStart = offsetInPlainChars + underline.startOffset();
359 unsigned underlineEnd = offset + underline.endOffset(); 359 unsigned underlineEnd = offsetInPlainChars + underline.endOffset();
360 360
361 EphemeralRange ephemeralLineRange = 361 EphemeralRange ephemeralLineRange =
362 PlainTextRange(underlineStart, underlineEnd) 362 PlainTextRange(underlineStart, underlineEnd).createRange(*baseElement);
363 .createRange(*rootEditableElement);
364 if (ephemeralLineRange.isNull()) 363 if (ephemeralLineRange.isNull())
365 continue; 364 continue;
366 365
367 document().markers().addCompositionMarker( 366 document().markers().addCompositionMarker(
368 ephemeralLineRange.startPosition(), ephemeralLineRange.endPosition(), 367 ephemeralLineRange.startPosition(), ephemeralLineRange.endPosition(),
369 underline.color(), underline.thick(), underline.backgroundColor()); 368 underline.color(), underline.thick(), underline.backgroundColor());
370 } 369 }
371 } 370 }
372 371
373 bool InputMethodController::replaceCompositionAndMoveCaret( 372 bool InputMethodController::replaceCompositionAndMoveCaret(
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 setEditableSelectionOffsets(selectedRange, NotUserTriggered); 600 setEditableSelectionOffsets(selectedRange, NotUserTriggered);
602 601
603 if (underlines.isEmpty()) { 602 if (underlines.isEmpty()) {
604 document().markers().addCompositionMarker( 603 document().markers().addCompositionMarker(
605 m_compositionRange->startPosition(), m_compositionRange->endPosition(), 604 m_compositionRange->startPosition(), m_compositionRange->endPosition(),
606 Color::black, false, 605 Color::black, false,
607 LayoutTheme::theme().platformDefaultCompositionBackgroundColor()); 606 LayoutTheme::theme().platformDefaultCompositionBackgroundColor());
608 return; 607 return;
609 } 608 }
610 609
611 addCompositionUnderlines(underlines, baseNode->parentNode(), baseOffset); 610 PlainTextRange compositionPlainTextRange =
yosin_UTC9 2017/02/20 06:29:10 nit: s/PlainTextRange/const PlainTextRange/
611 PlainTextRange::create(*baseNode->parentNode(), *m_compositionRange);
612 addCompositionUnderlines(underlines, baseNode->parentNode(),
613 compositionPlainTextRange.start());
612 } 614 }
613 615
614 PlainTextRange InputMethodController::createSelectionRangeForSetComposition( 616 PlainTextRange InputMethodController::createSelectionRangeForSetComposition(
615 int selectionStart, 617 int selectionStart,
616 int selectionEnd, 618 int selectionEnd,
617 size_t textLength) const { 619 size_t textLength) const {
618 const int selectionOffsetsStart = 620 const int selectionOffsetsStart =
619 static_cast<int>(getSelectionOffsets().start()); 621 static_cast<int>(getSelectionOffsets().start());
620 const int start = selectionOffsetsStart + selectionStart; 622 const int start = selectionOffsetsStart + selectionStart;
621 const int end = selectionOffsetsStart + selectionEnd; 623 const int end = selectionOffsetsStart + selectionEnd;
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 frame().chromeClient().resetInputMethod(); 1086 frame().chromeClient().resetInputMethod();
1085 } 1087 }
1086 1088
1087 DEFINE_TRACE(InputMethodController) { 1089 DEFINE_TRACE(InputMethodController) {
1088 visitor->trace(m_frame); 1090 visitor->trace(m_frame);
1089 visitor->trace(m_compositionRange); 1091 visitor->trace(m_compositionRange);
1090 SynchronousMutationObserver::trace(visitor); 1092 SynchronousMutationObserver::trace(visitor);
1091 } 1093 }
1092 1094
1093 } // namespace blink 1095 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698