 Chromium Code Reviews
 Chromium Code Reviews Issue 2020973002:
  Reland: Fix setComposingText with empty text when newCursorPosition != 1  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2020973002:
  Reland: Fix setComposingText with empty text when newCursorPosition != 1  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2307 focusedFrame->inputMethodController().confirmComposition(); | 2307 focusedFrame->inputMethodController().confirmComposition(); | 
| 2308 | 2308 | 
| 2309 if (autofillClient) | 2309 if (autofillClient) | 
| 2310 autofillClient->setIgnoreTextChanges(false); | 2310 autofillClient->setIgnoreTextChanges(false); | 
| 2311 } | 2311 } | 
| 2312 m_imeAcceptEvents = false; | 2312 m_imeAcceptEvents = false; | 
| 2313 } | 2313 } | 
| 2314 } | 2314 } | 
| 2315 } | 2315 } | 
| 2316 | 2316 | 
| 2317 std::pair<int, int> WebViewImpl::adjustSelectionForBoundary(int selectionStart, int selectionEnd, const int textLength) | |
| 2318 { | |
| 
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
 | |
| 2319 WebTextInputInfo textInputInfo = this->textInputInfo(); | |
| 2320 | |
| 2321 int compositionLength = textInputInfo.compositionEnd - textInputInfo.composi tionStart; | |
| 2322 int beforeCompositionLength; | |
| 2323 if (compositionLength != 0) | |
| 2324 beforeCompositionLength = textInputInfo.compositionStart; | |
| 2325 else | |
| 2326 beforeCompositionLength = textInputInfo.selectionStart; | |
| 2327 int afterCompositionLength = static_cast<int>(textInputInfo.value.length()) - compositionLength - beforeCompositionLength; | |
| 2328 | |
| 2329 // In case of exceeding the left boundary. | |
| 2330 selectionStart = std::max(selectionStart, -beforeCompositionLength); | |
| 2331 selectionEnd = std::max(selectionEnd, selectionStart); | |
| 2332 | |
| 2333 // In case of exceeding the right boundary. | |
| 2334 selectionEnd = std::min(selectionEnd, textLength + afterCompositionLength); | |
| 2335 selectionStart = std::min(selectionStart, selectionEnd); | |
| 2336 | |
| 2337 return std::make_pair(selectionStart, selectionEnd); | |
| 2338 } | |
| 2339 | |
| 2317 bool WebViewImpl::setComposition( | 2340 bool WebViewImpl::setComposition( | 
| 2318 const WebString& text, | 2341 const WebString& text, | 
| 2319 const WebVector<WebCompositionUnderline>& underlines, | 2342 const WebVector<WebCompositionUnderline>& underlines, | 
| 2320 int selectionStart, | 2343 int selectionStart, | 
| 2321 int selectionEnd) | 2344 int selectionEnd) | 
| 2322 { | 2345 { | 
| 2323 LocalFrame* focused = toLocalFrame(focusedCoreFrame()); | 2346 LocalFrame* focused = toLocalFrame(focusedCoreFrame()); | 
| 2324 if (!focused || !m_imeAcceptEvents) | 2347 if (!focused || !m_imeAcceptEvents) | 
| 2325 return false; | 2348 return false; | 
| 2326 | 2349 | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2347 | 2370 | 
| 2348 // A keypress event is canceled. If an ongoing composition exists, then the | 2371 // 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). | 2372 // keydown event should have arisen from a handled key (e.g., backspace). | 
| 2350 // In this case we ignore the cancellation and continue; otherwise (no | 2373 // In this case we ignore the cancellation and continue; otherwise (no | 
| 2351 // ongoing composition) we exit and signal success only for attempts to | 2374 // ongoing composition) we exit and signal success only for attempts to | 
| 2352 // clear the composition. | 2375 // clear the composition. | 
| 2353 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition()) | 2376 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition()) | 
| 2354 return text.isEmpty(); | 2377 return text.isEmpty(); | 
| 2355 | 2378 | 
| 2356 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 2379 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 
| 2357 | 2380 | 
| 
yabinh
2016/07/06 11:53:55
adjustSelectionForBoundary is moved here, thus it
 | |
| 2381 std::pair<int, int> selectionPair = adjustSelectionForBoundary(selectionStar t, selectionEnd, text.length()); | |
| 2382 | |
| 2358 // When the range of composition underlines overlap with the range between | 2383 // When the range of composition underlines overlap with the range between | 
| 2359 // selectionStart and selectionEnd, WebKit somehow won't paint the selection | 2384 // selectionStart and selectionEnd, WebKit somehow won't paint the selection | 
| 2360 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp). | 2385 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp). | 
| 2361 // But the selection range actually takes effect. | 2386 // But the selection range actually takes effect. | 
| 2362 inputMethodController.setComposition(String(text), | 2387 inputMethodController.setComposition(String(text), | 
| 2363 CompositionUnderlineVectorBuilder(underlines), | 2388 CompositionUnderlineVectorBuilder(underlines), | 
| 2364 selectionStart, selectionEnd); | 2389 selectionPair.first, selectionPair.second); | 
| 2365 | 2390 | 
| 2366 return text.isEmpty() || inputMethodController.hasComposition(); | 2391 return text.isEmpty() || inputMethodController.hasComposition(); | 
| 2367 } | 2392 } | 
| 2368 | 2393 | 
| 2369 bool WebViewImpl::confirmComposition() | 2394 bool WebViewImpl::confirmComposition() | 
| 2370 { | 2395 { | 
| 2371 return confirmComposition(DoNotKeepSelection); | 2396 return confirmComposition(DoNotKeepSelection); | 
| 2372 } | 2397 } | 
| 2373 | 2398 | 
| 2374 bool WebViewImpl::confirmComposition(ConfirmCompositionBehavior selectionBehavio r) | 2399 bool WebViewImpl::confirmComposition(ConfirmCompositionBehavior selectionBehavio r) | 
| (...skipping 2158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4533 { | 4558 { | 
| 4534 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than | 4559 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than | 
| 4535 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. | 4560 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. | 
| 4536 if (!page()) | 4561 if (!page()) | 
| 4537 return 1; | 4562 return 1; | 
| 4538 | 4563 | 
| 4539 return page()->deviceScaleFactor(); | 4564 return page()->deviceScaleFactor(); | 
| 4540 } | 4565 } | 
| 4541 | 4566 | 
| 4542 } // namespace blink | 4567 } // namespace blink | 
| OLD | NEW |