Chromium Code Reviews| Index: third_party/WebKit/Source/web/WebViewImpl.cpp |
| diff --git a/third_party/WebKit/Source/web/WebViewImpl.cpp b/third_party/WebKit/Source/web/WebViewImpl.cpp |
| index 05a2cb933392fec03b0db6ba59e92dd287e0b68f..28fcf82639c876f925ee233994d39491ea503fba 100644 |
| --- a/third_party/WebKit/Source/web/WebViewImpl.cpp |
| +++ b/third_party/WebKit/Source/web/WebViewImpl.cpp |
| @@ -2320,10 +2320,20 @@ bool WebViewImpl::setComposition( |
| int selectionStart, |
| int selectionEnd) |
| { |
| + // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget |
|
lfg
2016/07/11 20:55:51
What happens when mainFrameImpl() is not remote, b
EhsanK
2016/07/11 21:06:08
As we discussed offline, I think the change in lin
|
| + // belonging to the local root. |
| + if (!mainFrameImpl()) |
| + return false; |
| + |
| LocalFrame* focused = toLocalFrame(focusedCoreFrame()); |
| if (!focused || !m_imeAcceptEvents) |
| return false; |
| + // In case the focused frame has changed and IME on browser side has did |
| + // not know this when it sent the IPC. |
| + if (focused->localFrameRoot() != mainFrameImpl()->frame()) |
| + return false; |
| + |
| if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) |
| return plugin->setComposition(text, underlines, selectionStart, selectionEnd); |
| @@ -2384,10 +2394,20 @@ bool WebViewImpl::confirmComposition(const WebString& text) |
| bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBehavior selectionBehavior) |
| { |
| + // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget |
| + // belonging to the local root. |
| + if (!mainFrameImpl()) |
| + return false; |
| + |
| LocalFrame* focused = toLocalFrame(focusedCoreFrame()); |
| if (!focused || !m_imeAcceptEvents) |
| return false; |
| + // In case the focused frame has changed and IME on browser side has did |
| + // not know this when it sent the IPC. |
| + if (focused->localFrameRoot() != mainFrameImpl()->frame()) |
| + return false; |
| + |
| if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) |
| return plugin->confirmComposition(text, selectionBehavior); |
| @@ -2396,6 +2416,11 @@ bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBe |
| bool WebViewImpl::compositionRange(size_t* location, size_t* length) |
| { |
| + // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget |
| + // belonging to the local root. |
| + if (!mainFrameImpl()) |
| + return false; |
| + |
| // FIXME: Long term, the focused frame should be a local frame. For now, |
| // return early to avoid crashes. |
| Frame* frame = focusedCoreFrame(); |
| @@ -2406,6 +2431,11 @@ bool WebViewImpl::compositionRange(size_t* location, size_t* length) |
| if (!focused || !m_imeAcceptEvents) |
| return false; |
| + // In case the focused frame has changed and IME on browser side has did |
| + // not know this when sent the IPC. |
| + if (focused->localFrameRoot() != mainFrameImpl()->frame()) |
| + return false; |
| + |
| const EphemeralRange range = focused->inputMethodController().compositionEphemeralRange(); |
| if (range.isNull()) |
| return false; |
| @@ -2424,6 +2454,11 @@ WebTextInputInfo WebViewImpl::textInputInfo() |
| { |
| WebTextInputInfo info; |
| + // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget |
| + // belonging to the local root. |
| + if (!mainFrameImpl()) |
| + return info; |
| + |
| Frame* focusedFrame = focusedCoreFrame(); |
| if (!focusedFrame->isLocalFrame()) |
| return info; |
| @@ -2432,6 +2467,11 @@ WebTextInputInfo WebViewImpl::textInputInfo() |
| if (!focused) |
| return info; |
| + // We can only have a text input type when focused frame belongs to this |
| + // WebViewImpl, i.e., its local root is the main frame. |
| + if (focused->localFrameRoot() != mainFrameImpl()->frame()) |
| + return info; |
| + |
| FrameSelection& selection = focused->selection(); |
| if (!selection.isAvailable()) { |
| // plugins/mouse-capture-inside-shadow.html reaches here. |
| @@ -2481,10 +2521,21 @@ WebTextInputInfo WebViewImpl::textInputInfo() |
| WebTextInputType WebViewImpl::textInputType() |
| { |
| + // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget |
| + // belonging to the local root. |
| + if (!mainFrameImpl()) |
| + return WebTextInputTypeNone; |
| + |
| LocalFrame* focusedFrame = m_page->focusController().focusedFrame(); |
| if (!focusedFrame) |
| return WebTextInputTypeNone; |
| + if (focusedFrame != mainFrameImpl()->frame()) { |
| + // We can only report a text input type when the focused frame belongs |
| + // to this WebViewImpl, i.e., its local root is the main frame. |
| + return WebTextInputTypeNone; |
| + } |
| + |
| if (!focusedFrame->selection().isAvailable()) { |
| // "mouse-capture-inside-shadow.html" reaches here. |
| return WebTextInputTypeNone; |
| @@ -2824,6 +2875,46 @@ void WebViewImpl::didChangeWindowResizerRect() |
| mainFrameImpl()->frameView()->windowResizerRectChanged(); |
| } |
| +bool WebViewImpl::getCompositionCharacterBounds(WebVector<WebRect>& bounds) |
| +{ |
| + size_t offset = 0; |
| + size_t characterCount = 0; |
| + if (!compositionRange(&offset, &characterCount)) |
| + return false; |
| + |
| + if (characterCount == 0) |
| + return false; |
| + |
| + WebLocalFrame* frame = focusedFrame(); |
| + |
| + // Only consider frames whose local root is the main frame. For other |
| + // local frames which have different local roots, the corresponding |
| + // WebFrameWidget will handle this task. |
| + if (frame->localRoot() != mainFrameImpl()) |
| + return false; |
| + |
| + WebVector<WebRect> result(characterCount); |
| + WebRect webrect; |
| + for (size_t i = 0; i < characterCount; ++i) { |
| + if (!frame->firstRectForCharacterRange(offset + i, 1, webrect)) { |
| + DLOG(ERROR) << "Could not retrieve character rectangle at " << i; |
| + return false; |
| + } |
| + result[i] = webrect; |
| + } |
| + bounds.swap(result); |
| + return true; |
| +} |
| + |
| +void WebViewImpl::applyReplacementRange(int start, int length) |
| +{ |
| + if (WebLocalFrame* frame = focusedFrame()) { |
| + WebRange webrange = WebRange::fromDocumentRange(frame, start, length); |
| + if (!webrange.isNull()) |
| + frame->selectRange(webrange); |
| + } |
| +} |
| + |
| // WebView -------------------------------------------------------------------- |
| WebSettingsImpl* WebViewImpl::settingsImpl() |