Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 1995333002: Handle newCursorPosition correctly for Android's commitText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2350 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 // selectionStart and selectionEnd, WebKit somehow won't paint the selection 2361 // selectionStart and selectionEnd, WebKit somehow won't paint the selection
2362 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp). 2362 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp).
2363 // But the selection range actually takes effect. 2363 // But the selection range actually takes effect.
2364 inputMethodController.setComposition(String(text), 2364 inputMethodController.setComposition(String(text),
2365 CompositionUnderlineVectorBuilder(underlines), 2365 CompositionUnderlineVectorBuilder(underlines),
2366 selectionStart, selectionEnd); 2366 selectionStart, selectionEnd);
2367 2367
2368 return text.isEmpty() || inputMethodController.hasComposition(); 2368 return text.isEmpty() || inputMethodController.hasComposition();
2369 } 2369 }
2370 2370
2371 bool WebViewImpl::confirmComposition() 2371 bool WebViewImpl::confirmComposition(int newCursorPosition)
2372 { 2372 {
2373 return confirmComposition(DoNotKeepSelection); 2373 return confirmComposition(DoNotKeepSelection, newCursorPosition);
2374 } 2374 }
2375 2375
2376 bool WebViewImpl::confirmComposition(ConfirmCompositionBehavior selectionBehavio r) 2376 bool WebViewImpl::confirmComposition(ConfirmCompositionBehavior selectionBehavio r, int newCursorPosition)
2377 { 2377 {
2378 return confirmComposition(WebString(), selectionBehavior); 2378 return confirmComposition(WebString(), selectionBehavior, newCursorPosition) ;
2379 } 2379 }
2380 2380
2381 bool WebViewImpl::confirmComposition(const WebString& text) 2381 bool WebViewImpl::confirmComposition(const WebString& text, int newCursorPositio n)
2382 { 2382 {
2383 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); 2383 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
2384 return confirmComposition(text, DoNotKeepSelection); 2384 return confirmComposition(text, DoNotKeepSelection, newCursorPosition);
2385 } 2385 }
2386 2386
2387 bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBe havior selectionBehavior) 2387 bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBe havior selectionBehavior, int newCursorPosition)
2388 { 2388 {
2389 LocalFrame* focused = toLocalFrame(focusedCoreFrame()); 2389 LocalFrame* focused = toLocalFrame(focusedCoreFrame());
2390 if (!focused || !m_imeAcceptEvents) 2390 if (!focused || !m_imeAcceptEvents)
2391 return false; 2391 return false;
2392 2392
2393 InputMethodController& inputMethodController = focused->inputMethodControlle r();
2394 if (inputMethodController.hasComposition()) {
2395 if (newCursorPosition < 1) {
2396 newCursorPosition = newCursorPosition + textInputInfo().compositionS tart;
Changwan Ryu 2016/05/24 08:35:50 1. Don't call textInputInfo() repeatedly, as it is
yabinh 2016/07/06 11:44:30 InputMethodController::m_compositionRange doesn't
2397 } else {
2398 newCursorPosition = newCursorPosition + textInputInfo().compositionE nd - 1;
2399 }
2400 } else {
2401 if (newCursorPosition < 1) {
2402 newCursorPosition = newCursorPosition + textInputInfo().selectionSta rt;
2403 } else {
2404 newCursorPosition = newCursorPosition + textInputInfo().selectionSta rt + text.length() - 1;
2405 }
2406 }
2407
2393 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) 2408 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
2394 return plugin->confirmComposition(text, selectionBehavior); 2409 return plugin->confirmComposition(text, selectionBehavior, newCursorPosi tion);
2395 2410
2396 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection); 2411 if (selectionBehavior == KeepSelection)
Changwan Ryu 2016/05/24 08:35:50 Why couldn't you pass selectionBehavior to confirm
2412 return inputMethodController.confirmCompositionOrInsertText(text, InputM ethodController::KeepSelection);
2413
2414 return inputMethodController.confirmCompositionOrInsertText(text, InputMetho dController::DoNotKeepSelection)
2415 && inputMethodController.setEditableSelectionOffsetsWithBoundaryCheck(ne wCursorPosition, newCursorPosition);
2397 } 2416 }
2398 2417
2399 bool WebViewImpl::compositionRange(size_t* location, size_t* length) 2418 bool WebViewImpl::compositionRange(size_t* location, size_t* length)
2400 { 2419 {
2401 // FIXME: Long term, the focused frame should be a local frame. For now, 2420 // FIXME: Long term, the focused frame should be a local frame. For now,
2402 // return early to avoid crashes. 2421 // return early to avoid crashes.
2403 Frame* frame = focusedCoreFrame(); 2422 Frame* frame = focusedCoreFrame();
2404 if (!frame || frame->isRemoteFrame()) 2423 if (!frame || frame->isRemoteFrame())
2405 return false; 2424 return false;
2406 2425
(...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after
4534 { 4553 {
4535 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than 4554 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than
4536 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. 4555 // page's scale factor, which can be 1 in use-zoom-for-dsf mode.
4537 if (!page()) 4556 if (!page())
4538 return 1; 4557 return 1;
4539 4558
4540 return page()->deviceScaleFactor(); 4559 return page()->deviceScaleFactor();
4541 } 4560 }
4542 4561
4543 } // namespace blink 4562 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698