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

Side by Side Diff: third_party/WebKit/Source/web/WebInputMethodControllerImpl.cpp

Issue 2674253004: [refactor] Remove WebWidget::applyReplacementRange (Closed)
Patch Set: Rebased 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "web/WebInputMethodControllerImpl.h" 5 #include "web/WebInputMethodControllerImpl.h"
6 6
7 #include "core/InputTypeNames.h" 7 #include "core/InputTypeNames.h"
8 #include "core/dom/DocumentUserGestureToken.h" 8 #include "core/dom/DocumentUserGestureToken.h"
9 #include "core/editing/EditingUtilities.h" 9 #include "core/editing/EditingUtilities.h"
10 #include "core/editing/Editor.h" 10 #include "core/editing/Editor.h"
(...skipping 28 matching lines...) Expand all
39 : nullptr; 39 : nullptr;
40 } 40 }
41 41
42 DEFINE_TRACE(WebInputMethodControllerImpl) { 42 DEFINE_TRACE(WebInputMethodControllerImpl) {
43 visitor->trace(m_webLocalFrame); 43 visitor->trace(m_webLocalFrame);
44 } 44 }
45 45
46 bool WebInputMethodControllerImpl::setComposition( 46 bool WebInputMethodControllerImpl::setComposition(
47 const WebString& text, 47 const WebString& text,
48 const WebVector<WebCompositionUnderline>& underlines, 48 const WebVector<WebCompositionUnderline>& underlines,
49 const WebRange& replacementRange,
49 int selectionStart, 50 int selectionStart,
50 int selectionEnd) { 51 int selectionEnd) {
51 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported()) { 52 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported()) {
52 return plugin->setComposition(text, underlines, selectionStart, 53 return plugin->setComposition(text, underlines, selectionStart,
53 selectionEnd); 54 selectionEnd);
54 } 55 }
55 56
56 // We should use this |editor| object only to complete the ongoing 57 // We should use this |editor| object only to complete the ongoing
57 // composition. 58 // composition.
58 if (!frame()->editor().canEdit() && !inputMethodController().hasComposition()) 59 if (!frame()->editor().canEdit() && !inputMethodController().hasComposition())
59 return false; 60 return false;
60 61
62 // Select the range to be replaced with the composition later.
63 if (!replacementRange.isNull())
64 m_webLocalFrame->selectRange(replacementRange);
65
61 // We should verify the parent node of this IME composition node are 66 // We should verify the parent node of this IME composition node are
62 // editable because JavaScript may delete a parent node of the composition 67 // editable because JavaScript may delete a parent node of the composition
63 // node. In this case, WebKit crashes while deleting texts from the parent 68 // node. In this case, WebKit crashes while deleting texts from the parent
64 // node, which doesn't exist any longer. 69 // node, which doesn't exist any longer.
65 const EphemeralRange range = 70 const EphemeralRange range =
66 inputMethodController().compositionEphemeralRange(); 71 inputMethodController().compositionEphemeralRange();
67 if (range.isNotNull()) { 72 if (range.isNotNull()) {
68 Node* node = range.startPosition().computeContainerNode(); 73 Node* node = range.startPosition().computeContainerNode();
69 frame()->document()->updateStyleAndLayoutTree(); 74 frame()->document()->updateStyleAndLayoutTree();
70 if (!node || !hasEditableStyle(*node)) 75 if (!node || !hasEditableStyle(*node))
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 116
112 return inputMethodController().finishComposingText( 117 return inputMethodController().finishComposingText(
113 selectionBehavior == WebInputMethodController::KeepSelection 118 selectionBehavior == WebInputMethodController::KeepSelection
114 ? InputMethodController::KeepSelection 119 ? InputMethodController::KeepSelection
115 : InputMethodController::DoNotKeepSelection); 120 : InputMethodController::DoNotKeepSelection);
116 } 121 }
117 122
118 bool WebInputMethodControllerImpl::commitText( 123 bool WebInputMethodControllerImpl::commitText(
119 const WebString& text, 124 const WebString& text,
120 const WebVector<WebCompositionUnderline>& underlines, 125 const WebVector<WebCompositionUnderline>& underlines,
126 const WebRange& replacementRange,
121 int relativeCaretPosition) { 127 int relativeCaretPosition) {
122 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create( 128 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create(
123 frame()->document(), UserGestureToken::NewGesture)); 129 frame()->document(), UserGestureToken::NewGesture));
124 130
125 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported()) 131 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported())
126 return plugin->commitText(text, underlines, relativeCaretPosition); 132 return plugin->commitText(text, underlines, relativeCaretPosition);
127 133
134 // Select the range to be replaced with the composition later.
135 if (!replacementRange.isNull())
136 m_webLocalFrame->selectRange(replacementRange);
137
128 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 138 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
129 // needs to be audited. See http://crbug.com/590369 for more details. 139 // needs to be audited. See http://crbug.com/590369 for more details.
130 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 140 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
131 141
132 return inputMethodController().commitText( 142 return inputMethodController().commitText(
133 text, CompositionUnderlineVectorBuilder(underlines), 143 text, CompositionUnderlineVectorBuilder(underlines),
134 relativeCaretPosition); 144 relativeCaretPosition);
135 } 145 }
136 146
137 WebTextInputInfo WebInputMethodControllerImpl::textInputInfo() { 147 WebTextInputInfo WebInputMethodControllerImpl::textInputInfo() {
(...skipping 16 matching lines...) Expand all
154 WebPlugin* WebInputMethodControllerImpl::focusedPluginIfInputMethodSupported() 164 WebPlugin* WebInputMethodControllerImpl::focusedPluginIfInputMethodSupported()
155 const { 165 const {
156 WebPluginContainerImpl* container = 166 WebPluginContainerImpl* container =
157 WebLocalFrameImpl::currentPluginContainer(frame()); 167 WebLocalFrameImpl::currentPluginContainer(frame());
158 if (container && container->supportsInputMethod()) 168 if (container && container->supportsInputMethod())
159 return container->plugin(); 169 return container->plugin();
160 return nullptr; 170 return nullptr;
161 } 171 }
162 172
163 } // namespace blink 173 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebInputMethodControllerImpl.h ('k') | third_party/WebKit/Source/web/WebViewFrameWidget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698