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

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

Issue 2646963002: Stop dismissing selection handles when selection is kept (Closed)
Patch Set: rebased on amaralp@'s CLs 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 260 }
261 261
262 bool InputMethodController::finishComposingText( 262 bool InputMethodController::finishComposingText(
263 ConfirmCompositionBehavior confirmBehavior) { 263 ConfirmCompositionBehavior confirmBehavior) {
264 if (!hasComposition()) 264 if (!hasComposition())
265 return false; 265 return false;
266 266
267 const String& composing = composingText(); 267 const String& composing = composingText();
268 268
269 if (confirmBehavior == KeepSelection) { 269 if (confirmBehavior == KeepSelection) {
270 PlainTextRange oldOffsets = getSelectionOffsets(); 270 // Do not dismiss handles even if we are moving selection, because we will
271 // eventually move back to the old selection offsets.
272 const bool isHandleVisible = frame().selection().isHandleVisible();
273
274 const PlainTextRange& oldOffsets = getSelectionOffsets();
271 Editor::RevealSelectionScope revealSelectionScope(&editor()); 275 Editor::RevealSelectionScope revealSelectionScope(&editor());
272 276
273 clear(); 277 clear();
274 dispatchCompositionEndEvent(frame(), composing); 278 dispatchCompositionEndEvent(frame(), composing);
275 279
276 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 280 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
277 // needs to be audited. see http://crbug.com/590369 for more details. 281 // needs to be audited. see http://crbug.com/590369 for more details.
278 document().updateStyleAndLayoutIgnorePendingStylesheets(); 282 document().updateStyleAndLayoutIgnorePendingStylesheets();
279 setSelectionOffsets(oldOffsets); 283
284 const EphemeralRange& oldSelectionRange =
285 ephemeralRangeForOffsets(oldOffsets);
286 if (oldSelectionRange.isNull())
287 return false;
288 const SelectionInDOMTree& selection =
289 SelectionInDOMTree::Builder()
290 .setBaseAndExtent(oldSelectionRange)
291 .setIsHandleVisible(isHandleVisible)
292 .build();
293 frame().selection().setSelection(selection, FrameSelection::CloseTyping);
280 return true; 294 return true;
281 } 295 }
282 296
283 Element* rootEditableElement = frame().selection().rootEditableElement(); 297 Element* rootEditableElement = frame().selection().rootEditableElement();
284 if (!rootEditableElement) 298 if (!rootEditableElement)
285 return false; 299 return false;
286 PlainTextRange compositionRange = 300 PlainTextRange compositionRange =
287 PlainTextRange::create(*rootEditableElement, *m_compositionRange); 301 PlainTextRange::create(*rootEditableElement, *m_compositionRange);
288 if (compositionRange.isNull()) 302 if (compositionRange.isNull())
289 return false; 303 return false;
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 PlainTextRange InputMethodController::getSelectionOffsets() const { 720 PlainTextRange InputMethodController::getSelectionOffsets() const {
707 EphemeralRange range = firstEphemeralRangeOf(frame().selection().selection()); 721 EphemeralRange range = firstEphemeralRangeOf(frame().selection().selection());
708 if (range.isNull()) 722 if (range.isNull())
709 return PlainTextRange(); 723 return PlainTextRange();
710 ContainerNode* editable = 724 ContainerNode* editable =
711 frame().selection().rootEditableElementOrTreeScopeRootNode(); 725 frame().selection().rootEditableElementOrTreeScopeRootNode();
712 DCHECK(editable); 726 DCHECK(editable);
713 return PlainTextRange::create(*editable, range); 727 return PlainTextRange::create(*editable, range);
714 } 728 }
715 729
730 EphemeralRange InputMethodController::ephemeralRangeForOffsets(
731 const PlainTextRange& offsets) const {
732 if (offsets.isNull())
733 return EphemeralRange();
734 Element* rootEditableElement = frame().selection().rootEditableElement();
735 if (!rootEditableElement)
736 return EphemeralRange();
737
738 DCHECK(!document().needsLayoutTreeUpdate());
739
740 return offsets.createRange(*rootEditableElement);
741 }
742
716 bool InputMethodController::setSelectionOffsets( 743 bool InputMethodController::setSelectionOffsets(
717 const PlainTextRange& selectionOffsets, 744 const PlainTextRange& selectionOffsets,
718 FrameSelection::SetSelectionOptions options) { 745 FrameSelection::SetSelectionOptions options) {
719 if (selectionOffsets.isNull()) 746 const EphemeralRange range = ephemeralRangeForOffsets(selectionOffsets);
720 return false;
721 Element* rootEditableElement = frame().selection().rootEditableElement();
722 if (!rootEditableElement)
723 return false;
724
725 DCHECK(!document().needsLayoutTreeUpdate());
726
727 const EphemeralRange range =
728 selectionOffsets.createRange(*rootEditableElement);
729 if (range.isNull()) 747 if (range.isNull())
730 return false; 748 return false;
731 749
732 return frame().selection().setSelectedRange( 750 return frame().selection().setSelectedRange(
733 range, VP_DEFAULT_AFFINITY, SelectionDirectionalMode::NonDirectional, 751 range, VP_DEFAULT_AFFINITY, SelectionDirectionalMode::NonDirectional,
734 options); 752 options);
735 } 753 }
736 754
737 bool InputMethodController::setEditableSelectionOffsets( 755 bool InputMethodController::setEditableSelectionOffsets(
738 const PlainTextRange& selectionOffsets, 756 const PlainTextRange& selectionOffsets,
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 frame().chromeClient().resetInputMethod(); 1124 frame().chromeClient().resetInputMethod();
1107 } 1125 }
1108 1126
1109 DEFINE_TRACE(InputMethodController) { 1127 DEFINE_TRACE(InputMethodController) {
1110 visitor->trace(m_frame); 1128 visitor->trace(m_frame);
1111 visitor->trace(m_compositionRange); 1129 visitor->trace(m_compositionRange);
1112 SynchronousMutationObserver::trace(visitor); 1130 SynchronousMutationObserver::trace(visitor);
1113 } 1131 }
1114 1132
1115 } // namespace blink 1133 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.h ('k') | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698