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

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

Issue 2892393002: Move WebInputMethodControllerImpl to core/exported/ & break dependencies. (Closed)
Patch Set: Move WebInputMethodControllerImpl to core/exported/ Created 3 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "web/WebInputMethodControllerImpl.h"
6
7 #include "core/InputTypeNames.h"
8 #include "core/dom/DocumentUserGestureToken.h"
9 #include "core/editing/CompositionUnderlineVectorBuilder.h"
10 #include "core/editing/EditingUtilities.h"
11 #include "core/editing/Editor.h"
12 #include "core/editing/EphemeralRange.h"
13 #include "core/editing/FrameSelection.h"
14 #include "core/editing/InputMethodController.h"
15 #include "core/editing/PlainTextRange.h"
16 #include "core/exported/WebPluginContainerBase.h"
17 #include "core/frame/LocalFrame.h"
18 #include "core/page/FocusController.h"
19 #include "core/page/Page.h"
20 #include "platform/UserGestureIndicator.h"
21 #include "public/platform/WebString.h"
22 #include "public/web/WebPlugin.h"
23 #include "public/web/WebRange.h"
24 #include "web/WebLocalFrameImpl.h"
25
26 namespace blink {
27
28 WebInputMethodControllerImpl::WebInputMethodControllerImpl(
29 WebLocalFrameImpl* web_local_frame)
30 : web_local_frame_(web_local_frame) {}
31
32 WebInputMethodControllerImpl::~WebInputMethodControllerImpl() {}
33
34 // static
35 WebInputMethodControllerImpl* WebInputMethodControllerImpl::FromFrame(
36 LocalFrame* frame) {
37 WebLocalFrameImpl* web_local_frame_impl = WebLocalFrameImpl::FromFrame(frame);
38 return web_local_frame_impl ? web_local_frame_impl->GetInputMethodController()
39 : nullptr;
40 }
41
42 DEFINE_TRACE(WebInputMethodControllerImpl) {
43 visitor->Trace(web_local_frame_);
44 }
45
46 bool WebInputMethodControllerImpl::SetComposition(
47 const WebString& text,
48 const WebVector<WebCompositionUnderline>& underlines,
49 const WebRange& replacement_range,
50 int selection_start,
51 int selection_end) {
52 if (WebPlugin* plugin = FocusedPluginIfInputMethodSupported()) {
53 return plugin->SetComposition(text, underlines, replacement_range,
54 selection_start, selection_end);
55 }
56
57 // We should use this |editor| object only to complete the ongoing
58 // composition.
59 if (!GetFrame()->GetEditor().CanEdit() &&
60 !GetInputMethodController().HasComposition())
61 return false;
62
63 // Select the range to be replaced with the composition later.
64 if (!replacement_range.IsNull())
65 web_local_frame_->SelectRange(replacement_range);
66
67 // We should verify the parent node of this IME composition node are
68 // editable because JavaScript may delete a parent node of the composition
69 // node. In this case, WebKit crashes while deleting texts from the parent
70 // node, which doesn't exist any longer.
71 const EphemeralRange range =
72 GetInputMethodController().CompositionEphemeralRange();
73 if (range.IsNotNull()) {
74 Node* node = range.StartPosition().ComputeContainerNode();
75 GetFrame()->GetDocument()->UpdateStyleAndLayoutTree();
76 if (!node || !HasEditableStyle(*node))
77 return false;
78 }
79
80 UserGestureIndicator gesture_indicator(DocumentUserGestureToken::Create(
81 GetFrame()->GetDocument(), UserGestureToken::kNewGesture));
82
83 // When the range of composition underlines overlap with the range between
84 // selectionStart and selectionEnd, WebKit somehow won't paint the selection
85 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp).
86 // But the selection range actually takes effect.
87 GetInputMethodController().SetComposition(
88 String(text), CompositionUnderlineVectorBuilder::Build(underlines),
89 selection_start, selection_end);
90
91 return text.IsEmpty() || GetInputMethodController().HasComposition();
92 }
93
94 bool WebInputMethodControllerImpl::FinishComposingText(
95 ConfirmCompositionBehavior selection_behavior) {
96 // TODO(ekaramad): Here and in other IME calls we should expect the
97 // call to be made when our frame is focused. This, however, is not the case
98 // all the time. For instance, resetInputMethod call on RenderViewImpl could
99 // be after losing the focus on frame. But since we return the core frame
100 // in WebViewImpl::focusedLocalFrameInWidget(), we will reach here with
101 // |m_webLocalFrame| not focused on page.
102
103 if (WebPlugin* plugin = FocusedPluginIfInputMethodSupported())
104 return plugin->FinishComposingText(selection_behavior);
105
106 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
107 // needs to be audited. See http://crbug.com/590369 for more details.
108 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
109
110 return GetInputMethodController().FinishComposingText(
111 selection_behavior == WebInputMethodController::kKeepSelection
112 ? InputMethodController::kKeepSelection
113 : InputMethodController::kDoNotKeepSelection);
114 }
115
116 bool WebInputMethodControllerImpl::CommitText(
117 const WebString& text,
118 const WebVector<WebCompositionUnderline>& underlines,
119 const WebRange& replacement_range,
120 int relative_caret_position) {
121 UserGestureIndicator gesture_indicator(DocumentUserGestureToken::Create(
122 GetFrame()->GetDocument(), UserGestureToken::kNewGesture));
123
124 if (WebPlugin* plugin = FocusedPluginIfInputMethodSupported()) {
125 return plugin->CommitText(text, underlines, replacement_range,
126 relative_caret_position);
127 }
128
129 // Select the range to be replaced with the composition later.
130 if (!replacement_range.IsNull())
131 web_local_frame_->SelectRange(replacement_range);
132
133 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
134 // needs to be audited. See http://crbug.com/590369 for more details.
135 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
136
137 return GetInputMethodController().CommitText(
138 text, CompositionUnderlineVectorBuilder::Build(underlines),
139 relative_caret_position);
140 }
141
142 WebTextInputInfo WebInputMethodControllerImpl::TextInputInfo() {
143 return GetFrame()->GetInputMethodController().TextInputInfo();
144 }
145
146 WebTextInputType WebInputMethodControllerImpl::TextInputType() {
147 return GetFrame()->GetInputMethodController().TextInputType();
148 }
149
150 LocalFrame* WebInputMethodControllerImpl::GetFrame() const {
151 return web_local_frame_->GetFrame();
152 }
153
154 InputMethodController& WebInputMethodControllerImpl::GetInputMethodController()
155 const {
156 return GetFrame()->GetInputMethodController();
157 }
158
159 WebPlugin* WebInputMethodControllerImpl::FocusedPluginIfInputMethodSupported()
160 const {
161 WebPluginContainerBase* container = GetFrame()->GetWebPluginContainerBase();
162 if (container && container->SupportsInputMethod()) {
163 return container->Plugin();
164 }
165 return nullptr;
166 }
167
168 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698