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 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2312 if (autofillClient) | 2313 if (autofillClient) |
2313 autofillClient->setIgnoreTextChanges(false); | 2314 autofillClient->setIgnoreTextChanges(false); |
2314 } | 2315 } |
2315 m_imeAcceptEvents = false; | 2316 m_imeAcceptEvents = false; |
2316 } | 2317 } |
2317 } | 2318 } |
2318 } | 2319 } |
2319 | 2320 |
2320 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as | 2321 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as |
2321 // well. This code needs to be refactored (http://crbug.com/629721). | 2322 // well. This code needs to be refactored (http://crbug.com/629721). |
2322 bool WebViewImpl::setComposition( | |
2323 const WebString& text, | |
2324 const WebVector<WebCompositionUnderline>& underlines, | |
2325 int selectionStart, | |
2326 int selectionEnd) { | |
2327 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
2328 if (!focused) | |
2329 return false; | |
2330 | |
2331 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
2332 return plugin->setComposition(text, underlines, selectionStart, | |
2333 selectionEnd); | |
2334 | |
2335 // The input focus has been moved to another WebWidget object. | |
2336 // We should use this |editor| object only to complete the ongoing | |
2337 // composition. | |
2338 InputMethodController& inputMethodController = | |
2339 focused->inputMethodController(); | |
2340 if (!focused->editor().canEdit() && !inputMethodController.hasComposition()) | |
2341 return false; | |
2342 | |
2343 // We should verify the parent node of this IME composition node are | |
2344 // editable because JavaScript may delete a parent node of the composition | |
2345 // node. In this case, WebKit crashes while deleting texts from the parent | |
2346 // node, which doesn't exist any longer. | |
2347 const EphemeralRange range = | |
2348 inputMethodController.compositionEphemeralRange(); | |
2349 if (range.isNotNull()) { | |
2350 Node* node = range.startPosition().computeContainerNode(); | |
2351 focused->document()->updateStyleAndLayoutTree(); | |
2352 if (!node || !hasEditableStyle(*node)) | |
2353 return false; | |
2354 } | |
2355 | |
2356 // A keypress event is canceled. If an ongoing composition exists, then the | |
2357 // keydown event should have arisen from a handled key (e.g., backspace). | |
2358 // In this case we ignore the cancellation and continue; otherwise (no | |
2359 // ongoing composition) we exit and signal success only for attempts to | |
2360 // clear the composition. | |
2361 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition()) | |
2362 return text.isEmpty(); | |
2363 | |
2364 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create( | |
2365 focused->document(), UserGestureToken::NewGesture)); | |
2366 | |
2367 // When the range of composition underlines overlap with the range between | |
2368 // selectionStart and selectionEnd, WebKit somehow won't paint the selection | |
2369 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp). | |
2370 // But the selection range actually takes effect. | |
2371 inputMethodController.setComposition( | |
2372 String(text), CompositionUnderlineVectorBuilder(underlines), | |
2373 selectionStart, selectionEnd); | |
2374 | |
2375 return text.isEmpty() || inputMethodController.hasComposition(); | |
2376 } | |
2377 | |
2378 // TODO(ekaramad):These methods are almost duplicated in WebFrameWidgetImpl as | |
2379 // well. This code needs to be refactored (http://crbug.com/629721). | |
2380 bool WebViewImpl::finishComposingText( | |
2381 ConfirmCompositionBehavior selectionBehavior) { | |
2382 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
2383 if (!focused) | |
2384 return false; | |
2385 | |
2386 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
2387 return plugin->finishComposingText(selectionBehavior); | |
2388 | |
2389 return focused->inputMethodController().finishComposingText( | |
2390 selectionBehavior == KeepSelection | |
2391 ? InputMethodController::KeepSelection | |
2392 : InputMethodController::DoNotKeepSelection); | |
2393 } | |
2394 | |
2395 bool WebViewImpl::commitText(const WebString& text, int relativeCaretPosition) { | |
2396 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
2397 if (!focused) | |
2398 return false; | |
2399 | |
2400 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create( | |
2401 focused->document(), UserGestureToken::NewGesture)); | |
2402 | |
2403 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
2404 return plugin->commitText(text, relativeCaretPosition); | |
2405 | |
2406 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | |
2407 // needs to be audited. See http://crbug.com/590369 for more details. | |
2408 focused->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | |
2409 | |
2410 return focused->inputMethodController().commitText(text, | |
2411 relativeCaretPosition); | |
2412 } | |
2413 | |
2414 // TODO(ekaramad):This method is almost duplicated in WebFrameWidgetImpl as | |
2415 // well. This code needs to be refactored (http://crbug.com/629721). | |
2416 WebRange WebViewImpl::compositionRange() { | 2323 WebRange WebViewImpl::compositionRange() { |
2417 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | 2324 LocalFrame* focused = focusedLocalFrameAvailableForIme(); |
2418 if (!focused) | 2325 if (!focused) |
2419 return WebRange(); | 2326 return WebRange(); |
2420 | 2327 |
2421 const EphemeralRange range = | 2328 const EphemeralRange range = |
2422 focused->inputMethodController().compositionEphemeralRange(); | 2329 focused->inputMethodController().compositionEphemeralRange(); |
2423 if (range.isNull()) | 2330 if (range.isNull()) |
2424 return WebRange(); | 2331 return WebRange(); |
2425 | 2332 |
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3805 m_isTransparent = isTransparent; | 3712 m_isTransparent = isTransparent; |
3806 | 3713 |
3807 if (m_layerTreeView) | 3714 if (m_layerTreeView) |
3808 m_layerTreeView->setHasTransparentBackground(this->isTransparent()); | 3715 m_layerTreeView->setHasTransparentBackground(this->isTransparent()); |
3809 } | 3716 } |
3810 | 3717 |
3811 bool WebViewImpl::isTransparent() const { | 3718 bool WebViewImpl::isTransparent() const { |
3812 return m_isTransparent; | 3719 return m_isTransparent; |
3813 } | 3720 } |
3814 | 3721 |
| 3722 WebInputMethodControllerImpl* WebViewImpl::getActiveWebInputMethodController() |
| 3723 const { |
| 3724 return WebInputMethodControllerImpl::fromFrame( |
| 3725 focusedLocalFrameAvailableForIme()); |
| 3726 } |
| 3727 |
3815 void WebViewImpl::setBaseBackgroundColor(WebColor color) { | 3728 void WebViewImpl::setBaseBackgroundColor(WebColor color) { |
3816 if (m_baseBackgroundColor == color) | 3729 if (m_baseBackgroundColor == color) |
3817 return; | 3730 return; |
3818 | 3731 |
3819 m_baseBackgroundColor = color; | 3732 m_baseBackgroundColor = color; |
3820 | 3733 |
3821 if (m_page->mainFrame() && m_page->mainFrame()->isLocalFrame()) | 3734 if (m_page->mainFrame() && m_page->mainFrame()->isLocalFrame()) |
3822 m_page->deprecatedLocalMainFrame()->view()->setBaseBackgroundColor(color); | 3735 m_page->deprecatedLocalMainFrame()->view()->setBaseBackgroundColor(color); |
3823 } | 3736 } |
3824 | 3737 |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4443 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame()) | 4356 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame()) |
4444 return nullptr; | 4357 return nullptr; |
4445 return focusedFrame; | 4358 return focusedFrame; |
4446 } | 4359 } |
4447 | 4360 |
4448 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const { | 4361 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const { |
4449 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; | 4362 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; |
4450 } | 4363 } |
4451 | 4364 |
4452 } // namespace blink | 4365 } // namespace blink |
OLD | NEW |