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 3e92e32a2f867341300bb60c550f5729a13a1c55..c44a9fa4d494b3c77d3d0a21143e712114936821 100644 |
| --- a/third_party/WebKit/Source/web/WebViewImpl.cpp |
| +++ b/third_party/WebKit/Source/web/WebViewImpl.cpp |
| @@ -2314,6 +2314,29 @@ void WebViewImpl::setFocus(bool enable) |
| } |
| } |
| +std::pair<int, int> WebViewImpl::adjustSelectionForBoundary(int selectionStart, int selectionEnd, const int textLength) |
| +{ |
|
yabinh
2016/07/06 11:53:55
textInputInfo() is quite an expensive function, bu
Changwan Ryu
2016/07/07 09:09:33
You should avoid calling textInputInfo(). textInpu
|
| + WebTextInputInfo textInputInfo = this->textInputInfo(); |
| + |
| + int compositionLength = textInputInfo.compositionEnd - textInputInfo.compositionStart; |
| + int beforeCompositionLength; |
| + if (compositionLength != 0) |
| + beforeCompositionLength = textInputInfo.compositionStart; |
| + else |
| + beforeCompositionLength = textInputInfo.selectionStart; |
| + int afterCompositionLength = static_cast<int>(textInputInfo.value.length()) - compositionLength - beforeCompositionLength; |
| + |
| + // In case of exceeding the left boundary. |
| + selectionStart = std::max(selectionStart, -beforeCompositionLength); |
| + selectionEnd = std::max(selectionEnd, selectionStart); |
| + |
| + // In case of exceeding the right boundary. |
| + selectionEnd = std::min(selectionEnd, textLength + afterCompositionLength); |
| + selectionStart = std::min(selectionStart, selectionEnd); |
| + |
| + return std::make_pair(selectionStart, selectionEnd); |
| +} |
| + |
| bool WebViewImpl::setComposition( |
| const WebString& text, |
| const WebVector<WebCompositionUnderline>& underlines, |
| @@ -2355,13 +2378,15 @@ bool WebViewImpl::setComposition( |
| UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); |
|
yabinh
2016/07/06 11:53:55
adjustSelectionForBoundary is moved here, thus it
|
| + std::pair<int, int> selectionPair = adjustSelectionForBoundary(selectionStart, selectionEnd, text.length()); |
| + |
| // When the range of composition underlines overlap with the range between |
| // selectionStart and selectionEnd, WebKit somehow won't paint the selection |
| // at all (see InlineTextBox::paint() function in InlineTextBox.cpp). |
| // But the selection range actually takes effect. |
| inputMethodController.setComposition(String(text), |
| CompositionUnderlineVectorBuilder(underlines), |
| - selectionStart, selectionEnd); |
| + selectionPair.first, selectionPair.second); |
| return text.isEmpty() || inputMethodController.hasComposition(); |
| } |