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

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

Issue 2029423003: OOPIF IME: Renderer Side Changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.h ('k') | third_party/WebKit/public/web/WebWidget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2286 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 2297
2298 LocalFrame* focusedFrame = m_page->focusController().focusedFrame(); 2298 LocalFrame* focusedFrame = m_page->focusController().focusedFrame();
2299 if (focusedFrame) { 2299 if (focusedFrame) {
2300 // Finish an ongoing composition to delete the composition node. 2300 // Finish an ongoing composition to delete the composition node.
2301 if (focusedFrame->inputMethodController().hasComposition()) { 2301 if (focusedFrame->inputMethodController().hasComposition()) {
2302 WebAutofillClient* autofillClient = WebLocalFrameImpl::fromFrame (focusedFrame)->autofillClient(); 2302 WebAutofillClient* autofillClient = WebLocalFrameImpl::fromFrame (focusedFrame)->autofillClient();
2303 2303
2304 if (autofillClient) 2304 if (autofillClient)
2305 autofillClient->setIgnoreTextChanges(true); 2305 autofillClient->setIgnoreTextChanges(true);
2306 2306
2307 focusedFrame->inputMethodController().confirmComposition(); 2307 focusedFrame->inputMethodController().confirmComposition();
EhsanK 2016/07/11 20:29:53 Let's say we have an ongoing composition and then
lfg 2016/07/11 20:55:51 Acknowledged.
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 bool WebViewImpl::setComposition( 2317 bool WebViewImpl::setComposition(
2318 const WebString& text, 2318 const WebString& text,
2319 const WebVector<WebCompositionUnderline>& underlines, 2319 const WebVector<WebCompositionUnderline>& underlines,
2320 int selectionStart, 2320 int selectionStart,
2321 int selectionEnd) 2321 int selectionEnd)
2322 { 2322 {
2323 LocalFrame* focused = toLocalFrame(focusedCoreFrame()); 2323 LocalFrame* focused = toLocalFrame(focusedCoreFrame());
2324 if (!focused || !m_imeAcceptEvents) 2324 if (!focused || !m_imeAcceptEvents)
2325 return false; 2325 return false;
2326 2326
2327 // In case the focused frame has changed and IME on browser side has did
2328 // not know this when it sent the IPC.
2329 if (focused->localFrameRoot() != mainFrameImpl()->frame())
2330 return false;
2331
2327 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) 2332 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
2328 return plugin->setComposition(text, underlines, selectionStart, selectio nEnd); 2333 return plugin->setComposition(text, underlines, selectionStart, selectio nEnd);
2329 2334
2330 // The input focus has been moved to another WebWidget object. 2335 // The input focus has been moved to another WebWidget object.
2331 // We should use this |editor| object only to complete the ongoing 2336 // We should use this |editor| object only to complete the ongoing
2332 // composition. 2337 // composition.
2333 InputMethodController& inputMethodController = focused->inputMethodControlle r(); 2338 InputMethodController& inputMethodController = focused->inputMethodControlle r();
2334 if (!focused->editor().canEdit() && !inputMethodController.hasComposition()) 2339 if (!focused->editor().canEdit() && !inputMethodController.hasComposition())
2335 return false; 2340 return false;
2336 2341
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2381 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); 2386 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
2382 return confirmComposition(text, DoNotKeepSelection); 2387 return confirmComposition(text, DoNotKeepSelection);
2383 } 2388 }
2384 2389
2385 bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBe havior selectionBehavior) 2390 bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBe havior selectionBehavior)
2386 { 2391 {
2387 LocalFrame* focused = toLocalFrame(focusedCoreFrame()); 2392 LocalFrame* focused = toLocalFrame(focusedCoreFrame());
2388 if (!focused || !m_imeAcceptEvents) 2393 if (!focused || !m_imeAcceptEvents)
2389 return false; 2394 return false;
2390 2395
2396 // In case the focused frame has changed and IME on browser side has did
2397 // not know this when it sent the IPC.
2398 if (focused->localFrameRoot() != mainFrameImpl()->frame())
2399 return false;
2400
2391 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) 2401 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
2392 return plugin->confirmComposition(text, selectionBehavior); 2402 return plugin->confirmComposition(text, selectionBehavior);
2393 2403
2394 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection); 2404 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection);
2395 } 2405 }
2396 2406
2397 bool WebViewImpl::compositionRange(size_t* location, size_t* length) 2407 bool WebViewImpl::compositionRange(size_t* location, size_t* length)
2398 { 2408 {
2399 // FIXME: Long term, the focused frame should be a local frame. For now, 2409 // FIXME: Long term, the focused frame should be a local frame. For now,
2400 // return early to avoid crashes. 2410 // return early to avoid crashes.
2401 Frame* frame = focusedCoreFrame(); 2411 Frame* frame = focusedCoreFrame();
2402 if (!frame || frame->isRemoteFrame()) 2412 if (!frame || frame->isRemoteFrame())
2403 return false; 2413 return false;
2404 2414
2405 LocalFrame* focused = toLocalFrame(frame); 2415 LocalFrame* focused = toLocalFrame(frame);
2406 if (!focused || !m_imeAcceptEvents) 2416 if (!focused || !m_imeAcceptEvents)
2407 return false; 2417 return false;
2408 2418
2419 // In case the focused frame has changed and IME on browser side has did
2420 // not know this when sent the IPC.
2421 if (focused->localFrameRoot() != mainFrameImpl()->frame())
2422 return false;
2423
2409 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange(); 2424 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange();
2410 if (range.isNull()) 2425 if (range.isNull())
2411 return false; 2426 return false;
2412 2427
2413 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t(); 2428 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t();
2414 DCHECK(editable); 2429 DCHECK(editable);
2415 PlainTextRange plainTextRange(PlainTextRange::create(*editable, range)); 2430 PlainTextRange plainTextRange(PlainTextRange::create(*editable, range));
2416 if (plainTextRange.isNull()) 2431 if (plainTextRange.isNull())
2417 return false; 2432 return false;
2418 *location = plainTextRange.start(); 2433 *location = plainTextRange.start();
2419 *length = plainTextRange.length(); 2434 *length = plainTextRange.length();
2420 return true; 2435 return true;
2421 } 2436 }
2422 2437
2423 WebTextInputInfo WebViewImpl::textInputInfo() 2438 WebTextInputInfo WebViewImpl::textInputInfo()
2424 { 2439 {
2425 WebTextInputInfo info; 2440 WebTextInputInfo info;
2426 2441
2442 // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget
2443 // belonging to the local root.
2444 if (!mainFrameImpl())
2445 return info;
2446
2427 Frame* focusedFrame = focusedCoreFrame(); 2447 Frame* focusedFrame = focusedCoreFrame();
2428 if (!focusedFrame->isLocalFrame()) 2448 if (!focusedFrame->isLocalFrame())
2429 return info; 2449 return info;
2430 2450
2431 LocalFrame* focused = toLocalFrame(focusedFrame); 2451 LocalFrame* focused = toLocalFrame(focusedFrame);
2432 if (!focused) 2452 if (!focused)
2433 return info; 2453 return info;
2434 2454
2455 // We can only have a text input type when focused frame belongs to this
2456 // WebViewImpl, i.e., its local root is the main frame.
2457 if (focused->localFrameRoot() != mainFrameImpl()->frame())
2458 return info;
2459
2435 FrameSelection& selection = focused->selection(); 2460 FrameSelection& selection = focused->selection();
2436 if (!selection.isAvailable()) { 2461 if (!selection.isAvailable()) {
2437 // plugins/mouse-capture-inside-shadow.html reaches here. 2462 // plugins/mouse-capture-inside-shadow.html reaches here.
2438 return info; 2463 return info;
2439 } 2464 }
2440 Element* element = selection.selection().rootEditableElement(); 2465 Element* element = selection.selection().rootEditableElement();
2441 if (!element) 2466 if (!element)
2442 return info; 2467 return info;
2443 2468
2444 info.inputMode = inputModeOfFocusedElement(); 2469 info.inputMode = inputModeOfFocusedElement();
(...skipping 29 matching lines...) Expand all
2474 info.compositionStart = plainTextRange.start(); 2499 info.compositionStart = plainTextRange.start();
2475 info.compositionEnd = plainTextRange.end(); 2500 info.compositionEnd = plainTextRange.end();
2476 } 2501 }
2477 } 2502 }
2478 2503
2479 return info; 2504 return info;
2480 } 2505 }
2481 2506
2482 WebTextInputType WebViewImpl::textInputType() 2507 WebTextInputType WebViewImpl::textInputType()
2483 { 2508 {
2509 // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget
2510 // belonging to the local root.
2511 if (!mainFrameImpl())
2512 return WebTextInputTypeNone;
2513
2484 LocalFrame* focusedFrame = m_page->focusController().focusedFrame(); 2514 LocalFrame* focusedFrame = m_page->focusController().focusedFrame();
2485 if (!focusedFrame) 2515 if (!focusedFrame)
2486 return WebTextInputTypeNone; 2516 return WebTextInputTypeNone;
2487 2517
2518 if (focusedFrame != mainFrameImpl()->frame()) {
2519 // We can only report a text input type when the focused frame belongs
2520 // to this WebViewImpl, i.e., its local root is the main frame.
2521 return WebTextInputTypeNone;
2522 }
2523
2488 if (!focusedFrame->selection().isAvailable()) { 2524 if (!focusedFrame->selection().isAvailable()) {
2489 // "mouse-capture-inside-shadow.html" reaches here. 2525 // "mouse-capture-inside-shadow.html" reaches here.
2490 return WebTextInputTypeNone; 2526 return WebTextInputTypeNone;
2491 } 2527 }
2492 2528
2493 // It's important to preserve the equivalence of textInputInfo().type and te xtInputType(), 2529 // It's important to preserve the equivalence of textInputInfo().type and te xtInputType(),
2494 // so perform the same rootEditableElement() existence check here for consis tency. 2530 // so perform the same rootEditableElement() existence check here for consis tency.
2495 if (!focusedFrame->selection().selection().rootEditableElement()) 2531 if (!focusedFrame->selection().selection().rootEditableElement())
2496 return WebTextInputTypeNone; 2532 return WebTextInputTypeNone;
2497 2533
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
2817 if (page()) 2853 if (page())
2818 page()->pointerLockController().didLosePointerLock(); 2854 page()->pointerLockController().didLosePointerLock();
2819 } 2855 }
2820 2856
2821 void WebViewImpl::didChangeWindowResizerRect() 2857 void WebViewImpl::didChangeWindowResizerRect()
2822 { 2858 {
2823 if (mainFrameImpl()->frameView()) 2859 if (mainFrameImpl()->frameView())
2824 mainFrameImpl()->frameView()->windowResizerRectChanged(); 2860 mainFrameImpl()->frameView()->windowResizerRectChanged();
2825 } 2861 }
2826 2862
2863 bool WebViewImpl::getCompositionCharacterBounds(WebVector<WebRect>& bounds)
2864 {
2865 size_t offset = 0;
2866 size_t characterCount = 0;
2867 if (!compositionRange(&offset, &characterCount))
2868 return false;
2869
2870 if (characterCount == 0)
2871 return false;
2872
2873 WebLocalFrame* frame = focusedFrame();
2874
2875 // Only consider frames whose local root is the main frame. For other
2876 // local frames which have different local roots, the corresponding
2877 // WebFrameWidget will handle this task.
2878 if (frame->localRoot() != mainFrameImpl())
2879 return false;
2880
2881 WebVector<WebRect> result(characterCount);
2882 WebRect webrect;
2883 for (size_t i = 0; i < characterCount; ++i) {
2884 if (!frame->firstRectForCharacterRange(offset + i, 1, webrect)) {
2885 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
2886 return false;
2887 }
2888 result[i] = webrect;
2889 }
2890 bounds.swap(result);
2891 return true;
2892 }
2893
2894 void WebViewImpl::applyReplacementRange(int start, int length)
2895 {
2896 if (WebLocalFrame* frame = focusedFrame()->toWebLocalFrame()) {
2897 WebRange webrange = WebRange::fromDocumentRange(frame, start, length);
2898 if (!webrange.isNull())
2899 frame->selectRange(webrange);
2900 }
2901 }
2902
2827 // WebView -------------------------------------------------------------------- 2903 // WebView --------------------------------------------------------------------
2828 2904
2829 WebSettingsImpl* WebViewImpl::settingsImpl() 2905 WebSettingsImpl* WebViewImpl::settingsImpl()
2830 { 2906 {
2831 if (!m_webSettings) 2907 if (!m_webSettings)
2832 m_webSettings = wrapUnique(new WebSettingsImpl(&m_page->settings(), m_de vToolsEmulator.get())); 2908 m_webSettings = wrapUnique(new WebSettingsImpl(&m_page->settings(), m_de vToolsEmulator.get()));
2833 DCHECK(m_webSettings); 2909 DCHECK(m_webSettings);
2834 return m_webSettings.get(); 2910 return m_webSettings.get();
2835 } 2911 }
2836 2912
(...skipping 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after
4569 { 4645 {
4570 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than 4646 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than
4571 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. 4647 // page's scale factor, which can be 1 in use-zoom-for-dsf mode.
4572 if (!page()) 4648 if (!page())
4573 return 1; 4649 return 1;
4574 4650
4575 return page()->deviceScaleFactor(); 4651 return page()->deviceScaleFactor();
4576 } 4652 }
4577 4653
4578 } // namespace blink 4654 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.h ('k') | third_party/WebKit/public/web/WebWidget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698