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

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

Issue 2333813002: Introduce WebInputMethodController to blink (Closed)
Patch Set: Removed an unsued enum form WebInputMethodController Created 4 years, 3 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 #include "web/LinkHighlightImpl.h" 166 #include "web/LinkHighlightImpl.h"
167 #include "web/PageOverlay.h" 167 #include "web/PageOverlay.h"
168 #include "web/PrerendererClientImpl.h" 168 #include "web/PrerendererClientImpl.h"
169 #include "web/ResizeViewportAnchor.h" 169 #include "web/ResizeViewportAnchor.h"
170 #include "web/RotationViewportAnchor.h" 170 #include "web/RotationViewportAnchor.h"
171 #include "web/SpeechRecognitionClientProxy.h" 171 #include "web/SpeechRecognitionClientProxy.h"
172 #include "web/StorageQuotaClientImpl.h" 172 #include "web/StorageQuotaClientImpl.h"
173 #include "web/ValidationMessageClientImpl.h" 173 #include "web/ValidationMessageClientImpl.h"
174 #include "web/WebDevToolsAgentImpl.h" 174 #include "web/WebDevToolsAgentImpl.h"
175 #include "web/WebInputEventConversion.h" 175 #include "web/WebInputEventConversion.h"
176 #include "web/WebInputMethodControllerImpl.h"
176 #include "web/WebLocalFrameImpl.h" 177 #include "web/WebLocalFrameImpl.h"
177 #include "web/WebPagePopupImpl.h" 178 #include "web/WebPagePopupImpl.h"
178 #include "web/WebPluginContainerImpl.h" 179 #include "web/WebPluginContainerImpl.h"
179 #include "web/WebRemoteFrameImpl.h" 180 #include "web/WebRemoteFrameImpl.h"
180 #include "web/WebSettingsImpl.h" 181 #include "web/WebSettingsImpl.h"
181 #include "wtf/AutoReset.h" 182 #include "wtf/AutoReset.h"
182 #include "wtf/CurrentTime.h" 183 #include "wtf/CurrentTime.h"
183 #include "wtf/PtrUtil.h" 184 #include "wtf/PtrUtil.h"
184 #include "wtf/RefPtr.h" 185 #include "wtf/RefPtr.h"
185 #include <memory> 186 #include <memory>
(...skipping 2117 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 2314 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as
2315 // well. This code needs to be refactored (http://crbug.com/629721). 2315 // well. This code needs to be refactored (http://crbug.com/629721).
2316 bool WebViewImpl::setComposition( 2316 bool WebViewImpl::setComposition(
2317 const WebString& text, 2317 const WebString& text,
2318 const WebVector<WebCompositionUnderline>& underlines, 2318 const WebVector<WebCompositionUnderline>& underlines,
2319 int selectionStart, 2319 int selectionStart,
2320 int selectionEnd) 2320 int selectionEnd)
2321 { 2321 {
2322 LocalFrame* focused = focusedLocalFrameAvailableForIme(); 2322 if (!getActiveWebInputMethodController())
2323 if (!focused)
2324 return false; 2323 return false;
2325 2324 return getActiveWebInputMethodController()->setComposition(text, underlines, selectionStart, selectionEnd);
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 } 2325 }
2368 2326
2369 // TODO(ekaramad):These methods are almost duplicated in WebFrameWidgetImpl as 2327 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as
2370 // well. This code needs to be refactored (http://crbug.com/629721). 2328 // well. This code needs to be refactored (http://crbug.com/629721).
2371 bool WebViewImpl::finishComposingText(ConfirmCompositionBehavior selectionBehavi or) 2329 bool WebViewImpl::finishComposingText(ConfirmCompositionBehavior selectionBehavi or)
2372 { 2330 {
2373 LocalFrame* focused = focusedLocalFrameAvailableForIme(); 2331 if (!getActiveWebInputMethodController())
2374 if (!focused)
2375 return false; 2332 return false;
2376 2333 return getActiveWebInputMethodController()->finishComposingText(selectionBeh avior);
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 } 2334 }
2400 2335
2401 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as 2336 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as
2337 // well. This code needs to be refactored (http://crbug.com/629721).
2338 bool WebViewImpl::commitText(const WebString& text, int relativeCaretPosition)
2339 {
2340 if (!getActiveWebInputMethodController())
2341 return false;
2342 return getActiveWebInputMethodController()->commitText(text, relativeCaretPo sition);
2343 }
2344
2345 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as
2402 // well. This code needs to be refactored (http://crbug.com/629721). 2346 // well. This code needs to be refactored (http://crbug.com/629721).
2403 WebRange WebViewImpl::compositionRange() 2347 WebRange WebViewImpl::compositionRange()
2404 { 2348 {
2405 LocalFrame* focused = focusedLocalFrameAvailableForIme(); 2349 LocalFrame* focused = focusedLocalFrameAvailableForIme();
2406 if (!focused) 2350 if (!focused)
2407 return WebRange(); 2351 return WebRange();
2408 2352
2409 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange(); 2353 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange();
2410 if (range.isNull()) 2354 if (range.isNull())
2411 return WebRange(); 2355 return WebRange();
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after
3961 3905
3962 if (m_layerTreeView) 3906 if (m_layerTreeView)
3963 m_layerTreeView->setHasTransparentBackground(this->isTransparent()); 3907 m_layerTreeView->setHasTransparentBackground(this->isTransparent());
3964 } 3908 }
3965 3909
3966 bool WebViewImpl::isTransparent() const 3910 bool WebViewImpl::isTransparent() const
3967 { 3911 {
3968 return m_isTransparent; 3912 return m_isTransparent;
3969 } 3913 }
3970 3914
3915 WebInputMethodControllerImpl* WebViewImpl::getActiveWebInputMethodController() c onst
3916 {
3917 return WebInputMethodControllerImpl::fromFrame(focusedLocalFrameAvailableFor Ime());
3918 }
3919
3971 void WebViewImpl::setBaseBackgroundColor(WebColor color) 3920 void WebViewImpl::setBaseBackgroundColor(WebColor color)
3972 { 3921 {
3973 if (m_baseBackgroundColor == color) 3922 if (m_baseBackgroundColor == color)
3974 return; 3923 return;
3975 3924
3976 m_baseBackgroundColor = color; 3925 m_baseBackgroundColor = color;
3977 3926
3978 if (m_page->mainFrame() && m_page->mainFrame()->isLocalFrame()) 3927 if (m_page->mainFrame() && m_page->mainFrame()->isLocalFrame())
3979 m_page->deprecatedLocalMainFrame()->view()->setBaseBackgroundColor(color ); 3928 m_page->deprecatedLocalMainFrame()->view()->setBaseBackgroundColor(color );
3980 } 3929 }
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
4605 return nullptr; 4554 return nullptr;
4606 return focusedFrame; 4555 return focusedFrame;
4607 } 4556 }
4608 4557
4609 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const 4558 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const
4610 { 4559 {
4611 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; 4560 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr;
4612 } 4561 }
4613 4562
4614 } // namespace blink 4563 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698