OLD | NEW |
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 Loading... |
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 2148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2334 if (autofillClient) | 2335 if (autofillClient) |
2335 autofillClient->setIgnoreTextChanges(false); | 2336 autofillClient->setIgnoreTextChanges(false); |
2336 } | 2337 } |
2337 m_imeAcceptEvents = false; | 2338 m_imeAcceptEvents = false; |
2338 } | 2339 } |
2339 } | 2340 } |
2340 } | 2341 } |
2341 | 2342 |
2342 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as | 2343 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as |
2343 // well. This code needs to be refactored (http://crbug.com/629721). | 2344 // well. This code needs to be refactored (http://crbug.com/629721). |
2344 bool WebViewImpl::setComposition( | |
2345 const WebString& text, | |
2346 const WebVector<WebCompositionUnderline>& underlines, | |
2347 int selectionStart, | |
2348 int selectionEnd) { | |
2349 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
2350 if (!focused) | |
2351 return false; | |
2352 | |
2353 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
2354 return plugin->setComposition(text, underlines, selectionStart, | |
2355 selectionEnd); | |
2356 | |
2357 // The input focus has been moved to another WebWidget object. | |
2358 // We should use this |editor| object only to complete the ongoing | |
2359 // composition. | |
2360 InputMethodController& inputMethodController = | |
2361 focused->inputMethodController(); | |
2362 if (!focused->editor().canEdit() && !inputMethodController.hasComposition()) | |
2363 return false; | |
2364 | |
2365 // We should verify the parent node of this IME composition node are | |
2366 // editable because JavaScript may delete a parent node of the composition | |
2367 // node. In this case, WebKit crashes while deleting texts from the parent | |
2368 // node, which doesn't exist any longer. | |
2369 const EphemeralRange range = | |
2370 inputMethodController.compositionEphemeralRange(); | |
2371 if (range.isNotNull()) { | |
2372 Node* node = range.startPosition().computeContainerNode(); | |
2373 focused->document()->updateStyleAndLayoutTree(); | |
2374 if (!node || !hasEditableStyle(*node)) | |
2375 return false; | |
2376 } | |
2377 | |
2378 // A keypress event is canceled. If an ongoing composition exists, then the | |
2379 // keydown event should have arisen from a handled key (e.g., backspace). | |
2380 // In this case we ignore the cancellation and continue; otherwise (no | |
2381 // ongoing composition) we exit and signal success only for attempts to | |
2382 // clear the composition. | |
2383 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition()) | |
2384 return text.isEmpty(); | |
2385 | |
2386 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create( | |
2387 focused->document(), UserGestureToken::NewGesture)); | |
2388 | |
2389 // When the range of composition underlines overlap with the range between | |
2390 // selectionStart and selectionEnd, WebKit somehow won't paint the selection | |
2391 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp). | |
2392 // But the selection range actually takes effect. | |
2393 inputMethodController.setComposition( | |
2394 String(text), CompositionUnderlineVectorBuilder(underlines), | |
2395 selectionStart, selectionEnd); | |
2396 | |
2397 return text.isEmpty() || inputMethodController.hasComposition(); | |
2398 } | |
2399 | |
2400 // TODO(ekaramad):These methods are almost duplicated in WebFrameWidgetImpl as | |
2401 // well. This code needs to be refactored (http://crbug.com/629721). | |
2402 bool WebViewImpl::finishComposingText( | |
2403 ConfirmCompositionBehavior selectionBehavior) { | |
2404 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
2405 if (!focused) | |
2406 return false; | |
2407 | |
2408 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
2409 return plugin->finishComposingText(selectionBehavior); | |
2410 | |
2411 return focused->inputMethodController().finishComposingText( | |
2412 selectionBehavior == KeepSelection | |
2413 ? InputMethodController::KeepSelection | |
2414 : InputMethodController::DoNotKeepSelection); | |
2415 } | |
2416 | |
2417 bool WebViewImpl::commitText(const WebString& text, int relativeCaretPosition) { | |
2418 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
2419 if (!focused) | |
2420 return false; | |
2421 | |
2422 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create( | |
2423 focused->document(), UserGestureToken::NewGesture)); | |
2424 | |
2425 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
2426 return plugin->commitText(text, relativeCaretPosition); | |
2427 | |
2428 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | |
2429 // needs to be audited. See http://crbug.com/590369 for more details. | |
2430 focused->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | |
2431 | |
2432 return focused->inputMethodController().commitText(text, | |
2433 relativeCaretPosition); | |
2434 } | |
2435 | |
2436 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as | |
2437 // well. This code needs to be refactored (http://crbug.com/629721). | |
2438 WebRange WebViewImpl::compositionRange() { | 2345 WebRange WebViewImpl::compositionRange() { |
2439 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | 2346 LocalFrame* focused = focusedLocalFrameAvailableForIme(); |
2440 if (!focused) | 2347 if (!focused) |
2441 return WebRange(); | 2348 return WebRange(); |
2442 | 2349 |
2443 const EphemeralRange range = | 2350 const EphemeralRange range = |
2444 focused->inputMethodController().compositionEphemeralRange(); | 2351 focused->inputMethodController().compositionEphemeralRange(); |
2445 if (range.isNull()) | 2352 if (range.isNull()) |
2446 return WebRange(); | 2353 return WebRange(); |
2447 | 2354 |
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3828 m_isTransparent = isTransparent; | 3735 m_isTransparent = isTransparent; |
3829 | 3736 |
3830 if (m_layerTreeView) | 3737 if (m_layerTreeView) |
3831 m_layerTreeView->setHasTransparentBackground(this->isTransparent()); | 3738 m_layerTreeView->setHasTransparentBackground(this->isTransparent()); |
3832 } | 3739 } |
3833 | 3740 |
3834 bool WebViewImpl::isTransparent() const { | 3741 bool WebViewImpl::isTransparent() const { |
3835 return m_isTransparent; | 3742 return m_isTransparent; |
3836 } | 3743 } |
3837 | 3744 |
| 3745 WebInputMethodControllerImpl* WebViewImpl::getActiveWebInputMethodController() |
| 3746 const { |
| 3747 return WebInputMethodControllerImpl::fromFrame( |
| 3748 focusedLocalFrameAvailableForIme()); |
| 3749 } |
| 3750 |
3838 void WebViewImpl::setBaseBackgroundColor(WebColor color) { | 3751 void WebViewImpl::setBaseBackgroundColor(WebColor color) { |
3839 if (m_baseBackgroundColor == color) | 3752 if (m_baseBackgroundColor == color) |
3840 return; | 3753 return; |
3841 | 3754 |
3842 m_baseBackgroundColor = color; | 3755 m_baseBackgroundColor = color; |
3843 | 3756 |
3844 if (m_page->mainFrame() && m_page->mainFrame()->isLocalFrame()) | 3757 if (m_page->mainFrame() && m_page->mainFrame()->isLocalFrame()) |
3845 m_page->deprecatedLocalMainFrame()->view()->setBaseBackgroundColor(color); | 3758 m_page->deprecatedLocalMainFrame()->view()->setBaseBackgroundColor(color); |
3846 } | 3759 } |
3847 | 3760 |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4453 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame()) | 4366 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame()) |
4454 return nullptr; | 4367 return nullptr; |
4455 return focusedFrame; | 4368 return focusedFrame; |
4456 } | 4369 } |
4457 | 4370 |
4458 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const { | 4371 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const { |
4459 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; | 4372 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; |
4460 } | 4373 } |
4461 | 4374 |
4462 } // namespace blink | 4375 } // namespace blink |
OLD | NEW |