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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 frame().selection().setSelection( | 241 frame().selection().setSelection( |
| 242 SelectionInDOMTree::Builder().setBaseAndExtent(range).build(), 0); | 242 SelectionInDOMTree::Builder().setBaseAndExtent(range).build(), 0); |
| 243 } | 243 } |
| 244 | 244 |
| 245 bool InputMethodController::finishComposingText( | 245 bool InputMethodController::finishComposingText( |
| 246 ConfirmCompositionBehavior confirmBehavior) { | 246 ConfirmCompositionBehavior confirmBehavior) { |
| 247 if (!hasComposition()) | 247 if (!hasComposition()) |
| 248 return false; | 248 return false; |
| 249 | 249 |
| 250 if (confirmBehavior == KeepSelection) { | 250 if (confirmBehavior == KeepSelection) { |
| 251 PlainTextRange oldOffsets = getSelectionOffsets(); | 251 // Do not dismiss handles even if we are moving selection, because we will |
| 252 // eventually move back to the old selection offsets. | |
| 253 bool isHandleVisible = frame().selection().isHandleVisible(); | |
| 254 EphemeralRange oldSelectionRange = | |
| 255 ephemeralRangeForOffsets(getSelectionOffsets()); | |
| 256 | |
| 252 Editor::RevealSelectionScope revealSelectionScope(&editor()); | 257 Editor::RevealSelectionScope revealSelectionScope(&editor()); |
| 253 | 258 |
| 254 bool result = replaceComposition(composingText()); | 259 bool result = replaceComposition(composingText()); |
| 255 | 260 |
| 256 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 261 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 257 // needs to be audited. see http://crbug.com/590369 for more details. | 262 // needs to be audited. see http://crbug.com/590369 for more details. |
| 258 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 263 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 259 | 264 |
| 260 setSelectionOffsets(oldOffsets); | 265 if (oldSelectionRange.isNull()) |
| 266 return false; | |
| 267 SelectionInDOMTree::Builder& selectionBuilder = | |
| 268 SelectionInDOMTree::Builder().setBaseAndExtent(oldSelectionRange); | |
| 269 | |
| 270 if (isHandleVisible) | |
|
yosin_UTC9
2017/01/20 07:54:07
This line should be include in L268. One of benefi
Changwan Ryu
2017/01/24 06:38:45
Done.
| |
| 271 selectionBuilder.setIsHandleVisible(true); | |
| 272 | |
| 273 frame().selection().setSelection(selectionBuilder.build(), | |
| 274 FrameSelection::CloseTyping); | |
| 261 return result; | 275 return result; |
| 262 } | 276 } |
| 263 | 277 |
| 264 return replaceCompositionAndMoveCaret(composingText(), 0, | 278 return replaceCompositionAndMoveCaret(composingText(), 0, |
| 265 Vector<CompositionUnderline>()); | 279 Vector<CompositionUnderline>()); |
| 266 } | 280 } |
| 267 | 281 |
| 268 bool InputMethodController::commitText( | 282 bool InputMethodController::commitText( |
| 269 const String& text, | 283 const String& text, |
| 270 const Vector<CompositionUnderline>& underlines, | 284 const Vector<CompositionUnderline>& underlines, |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 PlainTextRange InputMethodController::getSelectionOffsets() const { | 686 PlainTextRange InputMethodController::getSelectionOffsets() const { |
| 673 EphemeralRange range = firstEphemeralRangeOf(frame().selection().selection()); | 687 EphemeralRange range = firstEphemeralRangeOf(frame().selection().selection()); |
| 674 if (range.isNull()) | 688 if (range.isNull()) |
| 675 return PlainTextRange(); | 689 return PlainTextRange(); |
| 676 ContainerNode* editable = | 690 ContainerNode* editable = |
| 677 frame().selection().rootEditableElementOrTreeScopeRootNode(); | 691 frame().selection().rootEditableElementOrTreeScopeRootNode(); |
| 678 DCHECK(editable); | 692 DCHECK(editable); |
| 679 return PlainTextRange::create(*editable, range); | 693 return PlainTextRange::create(*editable, range); |
| 680 } | 694 } |
| 681 | 695 |
| 696 EphemeralRange InputMethodController::ephemeralRangeForOffsets( | |
| 697 const PlainTextRange& offsets) const { | |
| 698 if (offsets.isNull()) | |
| 699 return EphemeralRange(); | |
| 700 Element* rootEditableElement = frame().selection().rootEditableElement(); | |
| 701 if (!rootEditableElement) | |
| 702 return EphemeralRange(); | |
| 703 | |
| 704 DCHECK(!document().needsLayoutTreeUpdate()); | |
| 705 | |
| 706 return offsets.createRange(*rootEditableElement); | |
| 707 } | |
| 708 | |
| 682 bool InputMethodController::setSelectionOffsets( | 709 bool InputMethodController::setSelectionOffsets( |
| 683 const PlainTextRange& selectionOffsets, | 710 const PlainTextRange& selectionOffsets, |
| 684 FrameSelection::SetSelectionOptions options) { | 711 FrameSelection::SetSelectionOptions options) { |
|
yosin_UTC9
2017/01/20 07:54:07
Please avoid to use FrameSelection::SetSelectionOp
Changwan Ryu
2017/01/24 06:38:45
Hmm... Most cases passing CloseTyping is necessary
yosin_UTC9
2017/01/24 07:58:27
I see.
| |
| 685 if (selectionOffsets.isNull()) | 712 const EphemeralRange range = ephemeralRangeForOffsets(selectionOffsets); |
| 686 return false; | |
| 687 Element* rootEditableElement = frame().selection().rootEditableElement(); | |
| 688 if (!rootEditableElement) | |
| 689 return false; | |
| 690 | |
| 691 DCHECK(!document().needsLayoutTreeUpdate()); | |
| 692 | |
| 693 const EphemeralRange range = | |
| 694 selectionOffsets.createRange(*rootEditableElement); | |
| 695 if (range.isNull()) | 713 if (range.isNull()) |
| 696 return false; | 714 return false; |
| 697 | 715 |
| 698 return frame().selection().setSelectedRange( | 716 return frame().selection().setSelectedRange( |
| 699 range, VP_DEFAULT_AFFINITY, SelectionDirectionalMode::NonDirectional, | 717 range, VP_DEFAULT_AFFINITY, SelectionDirectionalMode::NonDirectional, |
| 700 options); | 718 options); |
| 701 } | 719 } |
| 702 | 720 |
| 703 bool InputMethodController::setEditableSelectionOffsets( | 721 bool InputMethodController::setEditableSelectionOffsets( |
| 704 const PlainTextRange& selectionOffsets, | 722 const PlainTextRange& selectionOffsets, |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1067 frame().chromeClient().resetInputMethod(); | 1085 frame().chromeClient().resetInputMethod(); |
| 1068 } | 1086 } |
| 1069 | 1087 |
| 1070 DEFINE_TRACE(InputMethodController) { | 1088 DEFINE_TRACE(InputMethodController) { |
| 1071 visitor->trace(m_frame); | 1089 visitor->trace(m_frame); |
| 1072 visitor->trace(m_compositionRange); | 1090 visitor->trace(m_compositionRange); |
| 1073 SynchronousMutationObserver::trace(visitor); | 1091 SynchronousMutationObserver::trace(visitor); |
| 1074 } | 1092 } |
| 1075 | 1093 |
| 1076 } // namespace blink | 1094 } // namespace blink |
| OLD | NEW |