Chromium Code Reviews| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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>(baseOffset) + selectionStart, 0); |
| 337 int end = std::max(static_cast<int>(baseOffset) + selectionEnd, start); | |
| 338 | |
| 339 // In case of exceeding the right boundary. | |
| 340 const EphemeralRange textRange = PlainTextRange(0, end).createRange(*(baseNo de->parentElement())); | |
| 341 int textEnd = textRange.endPosition().computeOffsetInContainerNode(); | |
|
Changwan Ryu
2016/05/02 06:49:00
How about simply the following?
int textEnd = Pos
yabinh
2016/05/02 09:48:10
Do you mean:
int textEnd = EditingStrategy::lastOf
Changwan Ryu
2016/05/02 10:51:49
Ok, I couldn't find a better solution here. But ca
| |
| 342 start = std::min(start, textEnd); | |
| 343 end = std::min(end, textEnd); | |
| 344 | |
| 337 Range* selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end); | 345 Range* selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end); |
| 338 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered); | 346 frame().selection().setSelectedRange(selectedRange, TextAffinity::Downstream , SelectionDirectionalMode::NonDirectional, NotUserTriggered); |
| 339 | 347 |
| 340 if (underlines.isEmpty()) { | 348 if (underlines.isEmpty()) { |
| 341 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor()); | 349 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor()); |
| 342 return; | 350 return; |
| 343 } | 351 } |
| 344 for (const auto& underline : underlines) { | 352 for (const auto& underline : underlines) { |
| 345 unsigned underlineStart = baseOffset + underline.startOffset; | 353 unsigned underlineStart = baseOffset + underline.startOffset; |
| 346 unsigned underlineEnd = baseOffset + underline.endOffset; | 354 unsigned underlineEnd = baseOffset + underline.endOffset; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 TypingCommand::deleteSelection(*frame().document()); | 476 TypingCommand::deleteSelection(*frame().document()); |
| 469 } | 477 } |
| 470 | 478 |
| 471 DEFINE_TRACE(InputMethodController) | 479 DEFINE_TRACE(InputMethodController) |
| 472 { | 480 { |
| 473 visitor->trace(m_frame); | 481 visitor->trace(m_frame); |
| 474 visitor->trace(m_compositionRange); | 482 visitor->trace(m_compositionRange); |
| 475 } | 483 } |
| 476 | 484 |
| 477 } // namespace blink | 485 } // namespace blink |
| OLD | NEW |