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

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

Issue 2333813002: Introduce WebInputMethodController to blink (Closed)
Patch Set: Updated a comment Created 4 years, 2 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) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 #include "web/LinkHighlightImpl.h" 167 #include "web/LinkHighlightImpl.h"
168 #include "web/PageOverlay.h" 168 #include "web/PageOverlay.h"
169 #include "web/PrerendererClientImpl.h" 169 #include "web/PrerendererClientImpl.h"
170 #include "web/ResizeViewportAnchor.h" 170 #include "web/ResizeViewportAnchor.h"
171 #include "web/RotationViewportAnchor.h" 171 #include "web/RotationViewportAnchor.h"
172 #include "web/SpeechRecognitionClientProxy.h" 172 #include "web/SpeechRecognitionClientProxy.h"
173 #include "web/StorageQuotaClientImpl.h" 173 #include "web/StorageQuotaClientImpl.h"
174 #include "web/ValidationMessageClientImpl.h" 174 #include "web/ValidationMessageClientImpl.h"
175 #include "web/WebDevToolsAgentImpl.h" 175 #include "web/WebDevToolsAgentImpl.h"
176 #include "web/WebInputEventConversion.h" 176 #include "web/WebInputEventConversion.h"
177 #include "web/WebInputMethodControllerImpl.h"
177 #include "web/WebLocalFrameImpl.h" 178 #include "web/WebLocalFrameImpl.h"
178 #include "web/WebPagePopupImpl.h" 179 #include "web/WebPagePopupImpl.h"
179 #include "web/WebPluginContainerImpl.h" 180 #include "web/WebPluginContainerImpl.h"
180 #include "web/WebRemoteFrameImpl.h" 181 #include "web/WebRemoteFrameImpl.h"
181 #include "web/WebSettingsImpl.h" 182 #include "web/WebSettingsImpl.h"
182 #include "wtf/AutoReset.h" 183 #include "wtf/AutoReset.h"
183 #include "wtf/CurrentTime.h" 184 #include "wtf/CurrentTime.h"
184 #include "wtf/PtrUtil.h" 185 #include "wtf/PtrUtil.h"
185 #include "wtf/RefPtr.h" 186 #include "wtf/RefPtr.h"
186 #include <memory> 187 #include <memory>
(...skipping 2116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2303 focusedFrame->inputMethodController().finishComposingText(InputM ethodController::KeepSelection); 2304 focusedFrame->inputMethodController().finishComposingText(InputM ethodController::KeepSelection);
2304 2305
2305 if (autofillClient) 2306 if (autofillClient)
2306 autofillClient->setIgnoreTextChanges(false); 2307 autofillClient->setIgnoreTextChanges(false);
2307 } 2308 }
2308 m_imeAcceptEvents = false; 2309 m_imeAcceptEvents = false;
2309 } 2310 }
2310 } 2311 }
2311 } 2312 }
2312 2313
2313
2314 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as
2315 // well. This code needs to be refactored (http://crbug.com/629721).
2316 bool WebViewImpl::setComposition(
2317 const WebString& text,
2318 const WebVector<WebCompositionUnderline>& underlines,
2319 int selectionStart,
2320 int selectionEnd)
2321 {
2322 LocalFrame* focused = focusedLocalFrameAvailableForIme();
2323 if (!focused)
2324 return false;
2325
2326 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
2327 return plugin->setComposition(text, underlines, selectionStart, selectio nEnd);
2328
2329 // The input focus has been moved to another WebWidget object.
2330 // We should use this |editor| object only to complete the ongoing
2331 // composition.
2332 InputMethodController& inputMethodController = focused->inputMethodControlle r();
2333 if (!focused->editor().canEdit() && !inputMethodController.hasComposition())
2334 return false;
2335
2336 // We should verify the parent node of this IME composition node are
2337 // editable because JavaScript may delete a parent node of the composition
2338 // node. In this case, WebKit crashes while deleting texts from the parent
2339 // node, which doesn't exist any longer.
2340 const EphemeralRange range = inputMethodController.compositionEphemeralRange ();
2341 if (range.isNotNull()) {
2342 Node* node = range.startPosition().computeContainerNode();
2343 focused->document()->updateStyleAndLayoutTree();
2344 if (!node || !hasEditableStyle(*node))
2345 return false;
2346 }
2347
2348 // A keypress event is canceled. If an ongoing composition exists, then the
2349 // keydown event should have arisen from a handled key (e.g., backspace).
2350 // In this case we ignore the cancellation and continue; otherwise (no
2351 // ongoing composition) we exit and signal success only for attempts to
2352 // clear the composition.
2353 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition())
2354 return text.isEmpty();
2355
2356 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
2357
2358 // When the range of composition underlines overlap with the range between
2359 // selectionStart and selectionEnd, WebKit somehow won't paint the selection
2360 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp).
2361 // But the selection range actually takes effect.
2362 inputMethodController.setComposition(String(text),
2363 CompositionUnderlineVectorBuilder(underlines),
2364 selectionStart, selectionEnd);
2365
2366 return text.isEmpty() || inputMethodController.hasComposition();
2367 }
2368
2369 // TODO(ekaramad):These methods are almost duplicated in WebFrameWidgetImpl as
2370 // well. This code needs to be refactored (http://crbug.com/629721).
2371 bool WebViewImpl::finishComposingText(ConfirmCompositionBehavior selectionBehavi or)
2372 {
2373 LocalFrame* focused = focusedLocalFrameAvailableForIme();
2374 if (!focused)
2375 return false;
2376
2377 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
2378 return plugin->finishComposingText(selectionBehavior);
2379
2380 return focused->inputMethodController().finishComposingText(selectionBehavio r == KeepSelection ? InputMethodController::KeepSelection : InputMethodControlle r::DoNotKeepSelection);
2381 }
2382
2383 bool WebViewImpl::commitText(const WebString& text, int relativeCaretPosition)
2384 {
2385 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
2386
2387 LocalFrame* focused = focusedLocalFrameAvailableForIme();
2388 if (!focused)
2389 return false;
2390
2391 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
2392 return plugin->commitText(text, relativeCaretPosition);
2393
2394 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
2395 // needs to be audited. See http://crbug.com/590369 for more details.
2396 focused->document()->updateStyleAndLayoutIgnorePendingStylesheets();
2397
2398 return focused->inputMethodController().commitText(text, relativeCaretPositi on);
2399 }
2400
2401 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as 2314 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as
2402 // well. This code needs to be refactored (http://crbug.com/629721). 2315 // well. This code needs to be refactored (http://crbug.com/629721).
2403 WebRange WebViewImpl::compositionRange() 2316 WebRange WebViewImpl::compositionRange()
2404 { 2317 {
2405 LocalFrame* focused = focusedLocalFrameAvailableForIme(); 2318 LocalFrame* focused = focusedLocalFrameAvailableForIme();
2406 if (!focused) 2319 if (!focused)
2407 return WebRange(); 2320 return WebRange();
2408 2321
2409 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange(); 2322 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange();
2410 if (range.isNull()) 2323 if (range.isNull())
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after
3957 3870
3958 if (m_layerTreeView) 3871 if (m_layerTreeView)
3959 m_layerTreeView->setHasTransparentBackground(this->isTransparent()); 3872 m_layerTreeView->setHasTransparentBackground(this->isTransparent());
3960 } 3873 }
3961 3874
3962 bool WebViewImpl::isTransparent() const 3875 bool WebViewImpl::isTransparent() const
3963 { 3876 {
3964 return m_isTransparent; 3877 return m_isTransparent;
3965 } 3878 }
3966 3879
3880 WebInputMethodControllerImpl* WebViewImpl::getActiveWebInputMethodController() c onst
3881 {
3882 return WebInputMethodControllerImpl::fromFrame(focusedLocalFrameAvailableFor Ime());
3883 }
3884
3967 void WebViewImpl::setBaseBackgroundColor(WebColor color) 3885 void WebViewImpl::setBaseBackgroundColor(WebColor color)
3968 { 3886 {
3969 if (m_baseBackgroundColor == color) 3887 if (m_baseBackgroundColor == color)
3970 return; 3888 return;
3971 3889
3972 m_baseBackgroundColor = color; 3890 m_baseBackgroundColor = color;
3973 3891
3974 if (m_page->mainFrame() && m_page->mainFrame()->isLocalFrame()) 3892 if (m_page->mainFrame() && m_page->mainFrame()->isLocalFrame())
3975 m_page->deprecatedLocalMainFrame()->view()->setBaseBackgroundColor(color ); 3893 m_page->deprecatedLocalMainFrame()->view()->setBaseBackgroundColor(color );
3976 } 3894 }
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
4591 return nullptr; 4509 return nullptr;
4592 return focusedFrame; 4510 return focusedFrame;
4593 } 4511 }
4594 4512
4595 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const 4513 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const
4596 { 4514 {
4597 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; 4515 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr;
4598 } 4516 }
4599 4517
4600 } // namespace blink 4518 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698