| OLD | NEW |
| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 if (!selection.isNone() && !m_compositionRange->collapsed()) { | 227 if (!selection.isNone() && !m_compositionRange->collapsed()) { |
| 228 if (selection.start().compareTo(m_compositionRange->startPosition()) >=
0 | 228 if (selection.start().compareTo(m_compositionRange->startPosition()) >=
0 |
| 229 && selection.end().compareTo(m_compositionRange->endPosition()) <= 0
) | 229 && selection.end().compareTo(m_compositionRange->endPosition()) <= 0
) |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 | 232 |
| 233 cancelComposition(); | 233 cancelComposition(); |
| 234 frame().chromeClient().didCancelCompositionOnSelectionChange(); | 234 frame().chromeClient().didCancelCompositionOnSelectionChange(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void InputMethodController::setComposition(const String& text, const Vector<Comp
ositionUnderline>& underlines, unsigned selectionStart, unsigned selectionEnd) | 237 void InputMethodController::setComposition(const String& text, const Vector<Comp
ositionUnderline>& underlines, int selectionStart, int selectionEnd) |
| 238 { | 238 { |
| 239 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 239 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| 240 | 240 |
| 241 // Updates styles before setting selection for composition to prevent | 241 // Updates styles before setting selection for composition to prevent |
| 242 // inserting the previous composition text into text nodes oddly. | 242 // inserting the previous composition text into text nodes oddly. |
| 243 // See https://bugs.webkit.org/show_bug.cgi?id=46868 | 243 // See https://bugs.webkit.org/show_bug.cgi?id=46868 |
| 244 frame().document()->updateLayoutTree(); | 244 frame().document()->updateLayoutTree(); |
| 245 | 245 |
| 246 selectComposition(); | 246 selectComposition(); |
| 247 | 247 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 m_isDirty = true; | 315 m_isDirty = true; |
| 316 m_hasComposition = true; | 316 m_hasComposition = true; |
| 317 if (!m_compositionRange) | 317 if (!m_compositionRange) |
| 318 m_compositionRange = Range::create(baseNode->document()); | 318 m_compositionRange = Range::create(baseNode->document()); |
| 319 m_compositionRange->setStart(baseNode, baseOffset); | 319 m_compositionRange->setStart(baseNode, baseOffset); |
| 320 m_compositionRange->setEnd(baseNode, extentOffset); | 320 m_compositionRange->setEnd(baseNode, extentOffset); |
| 321 | 321 |
| 322 if (baseNode->layoutObject()) | 322 if (baseNode->layoutObject()) |
| 323 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); | 323 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); |
| 324 | 324 |
| 325 unsigned start = std::min(baseOffset + selectionStart, extentOffset); | 325 // The case when cursor position exceeds left boundary is handled here |
| 326 unsigned end = std::min(std::max(start, baseOffset + selectionEnd), extentOf
fset); | 326 int start = std::max(static_cast<int>(baseOffset) + selectionStart, 0); |
| 327 RawPtr<Range> selectedRange = Range::create(baseNode->document(), baseNode,
start, baseNode, end); | 327 int end = std::max(static_cast<int>(baseOffset) + selectionEnd, start); |
| 328 frame().selection().setSelectedRange(selectedRange.get(), TextAffinity::Down
stream, SelectionDirectionalMode::NonDirectional, NotUserTriggered); | 328 |
| 329 Element* rootEditableElement = frame().selection().rootEditableElement(); |
| 330 if (!rootEditableElement) |
| 331 return; |
| 332 |
| 333 // The case when cursor position exceeds right boundary is handled here |
| 334 const EphemeralRange selectedRange = PlainTextRange(start, end).createRange(
*rootEditableElement); |
| 335 |
| 336 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream
, SelectionDirectionalMode::NonDirectional, NotUserTriggered); |
| 329 | 337 |
| 330 if (underlines.isEmpty()) { | 338 if (underlines.isEmpty()) { |
| 331 frame().document()->markers().addCompositionMarker(m_compositionRange->s
tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh
eme::theme().platformDefaultCompositionBackgroundColor()); | 339 frame().document()->markers().addCompositionMarker(m_compositionRange->s
tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh
eme::theme().platformDefaultCompositionBackgroundColor()); |
| 332 return; | 340 return; |
| 333 } | 341 } |
| 334 for (const auto& underline : underlines) { | 342 for (const auto& underline : underlines) { |
| 335 unsigned underlineStart = baseOffset + underline.startOffset; | 343 unsigned underlineStart = baseOffset + underline.startOffset; |
| 336 unsigned underlineEnd = baseOffset + underline.endOffset; | 344 unsigned underlineEnd = baseOffset + underline.endOffset; |
| 337 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un
derlineStart), Position(baseNode, underlineEnd)); | 345 EphemeralRange ephemeralLineRange = EphemeralRange(Position(baseNode, un
derlineStart), Position(baseNode, underlineEnd)); |
| 338 if (ephemeralLineRange.isNull()) | 346 if (ephemeralLineRange.isNull()) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 TypingCommand::deleteSelection(*frame().document()); | 464 TypingCommand::deleteSelection(*frame().document()); |
| 457 } | 465 } |
| 458 | 466 |
| 459 DEFINE_TRACE(InputMethodController) | 467 DEFINE_TRACE(InputMethodController) |
| 460 { | 468 { |
| 461 visitor->trace(m_frame); | 469 visitor->trace(m_frame); |
| 462 visitor->trace(m_compositionRange); | 470 visitor->trace(m_compositionRange); |
| 463 } | 471 } |
| 464 | 472 |
| 465 } // namespace blink | 473 } // namespace blink |
| OLD | NEW |