Chromium Code Reviews| 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 2302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // 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
| |
| 2324 // belonging to the local root. | |
| 2325 if (!mainFrameImpl()) | |
| 2326 return false; | |
| 2327 | |
| 2323 LocalFrame* focused = toLocalFrame(focusedCoreFrame()); | 2328 LocalFrame* focused = toLocalFrame(focusedCoreFrame()); |
| 2324 if (!focused || !m_imeAcceptEvents) | 2329 if (!focused || !m_imeAcceptEvents) |
| 2325 return false; | 2330 return false; |
| 2326 | 2331 |
| 2332 // In case the focused frame has changed and IME on browser side has did | |
| 2333 // not know this when it sent the IPC. | |
| 2334 if (focused->localFrameRoot() != mainFrameImpl()->frame()) | |
| 2335 return false; | |
| 2336 | |
| 2327 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | 2337 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) |
| 2328 return plugin->setComposition(text, underlines, selectionStart, selectio nEnd); | 2338 return plugin->setComposition(text, underlines, selectionStart, selectio nEnd); |
| 2329 | 2339 |
| 2330 // The input focus has been moved to another WebWidget object. | 2340 // The input focus has been moved to another WebWidget object. |
| 2331 // We should use this |editor| object only to complete the ongoing | 2341 // We should use this |editor| object only to complete the ongoing |
| 2332 // composition. | 2342 // composition. |
| 2333 InputMethodController& inputMethodController = focused->inputMethodControlle r(); | 2343 InputMethodController& inputMethodController = focused->inputMethodControlle r(); |
| 2334 if (!focused->editor().canEdit() && !inputMethodController.hasComposition()) | 2344 if (!focused->editor().canEdit() && !inputMethodController.hasComposition()) |
| 2335 return false; | 2345 return false; |
| 2336 | 2346 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2377 } | 2387 } |
| 2378 | 2388 |
| 2379 bool WebViewImpl::confirmComposition(const WebString& text) | 2389 bool WebViewImpl::confirmComposition(const WebString& text) |
| 2380 { | 2390 { |
| 2381 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 2391 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); |
| 2382 return confirmComposition(text, DoNotKeepSelection); | 2392 return confirmComposition(text, DoNotKeepSelection); |
| 2383 } | 2393 } |
| 2384 | 2394 |
| 2385 bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBe havior selectionBehavior) | 2395 bool WebViewImpl::confirmComposition(const WebString& text, ConfirmCompositionBe havior selectionBehavior) |
| 2386 { | 2396 { |
| 2397 // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget | |
| 2398 // belonging to the local root. | |
| 2399 if (!mainFrameImpl()) | |
| 2400 return false; | |
| 2401 | |
| 2387 LocalFrame* focused = toLocalFrame(focusedCoreFrame()); | 2402 LocalFrame* focused = toLocalFrame(focusedCoreFrame()); |
| 2388 if (!focused || !m_imeAcceptEvents) | 2403 if (!focused || !m_imeAcceptEvents) |
| 2389 return false; | 2404 return false; |
| 2390 | 2405 |
| 2406 // In case the focused frame has changed and IME on browser side has did | |
| 2407 // not know this when it sent the IPC. | |
| 2408 if (focused->localFrameRoot() != mainFrameImpl()->frame()) | |
| 2409 return false; | |
| 2410 | |
| 2391 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | 2411 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) |
| 2392 return plugin->confirmComposition(text, selectionBehavior); | 2412 return plugin->confirmComposition(text, selectionBehavior); |
| 2393 | 2413 |
| 2394 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection); | 2414 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection); |
| 2395 } | 2415 } |
| 2396 | 2416 |
| 2397 bool WebViewImpl::compositionRange(size_t* location, size_t* length) | 2417 bool WebViewImpl::compositionRange(size_t* location, size_t* length) |
| 2398 { | 2418 { |
| 2419 // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget | |
| 2420 // belonging to the local root. | |
| 2421 if (!mainFrameImpl()) | |
| 2422 return false; | |
| 2423 | |
| 2399 // FIXME: Long term, the focused frame should be a local frame. For now, | 2424 // FIXME: Long term, the focused frame should be a local frame. For now, |
| 2400 // return early to avoid crashes. | 2425 // return early to avoid crashes. |
| 2401 Frame* frame = focusedCoreFrame(); | 2426 Frame* frame = focusedCoreFrame(); |
| 2402 if (!frame || frame->isRemoteFrame()) | 2427 if (!frame || frame->isRemoteFrame()) |
| 2403 return false; | 2428 return false; |
| 2404 | 2429 |
| 2405 LocalFrame* focused = toLocalFrame(frame); | 2430 LocalFrame* focused = toLocalFrame(frame); |
| 2406 if (!focused || !m_imeAcceptEvents) | 2431 if (!focused || !m_imeAcceptEvents) |
| 2407 return false; | 2432 return false; |
| 2408 | 2433 |
| 2434 // In case the focused frame has changed and IME on browser side has did | |
| 2435 // not know this when sent the IPC. | |
| 2436 if (focused->localFrameRoot() != mainFrameImpl()->frame()) | |
| 2437 return false; | |
| 2438 | |
| 2409 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange(); | 2439 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange(); |
| 2410 if (range.isNull()) | 2440 if (range.isNull()) |
| 2411 return false; | 2441 return false; |
| 2412 | 2442 |
| 2413 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t(); | 2443 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t(); |
| 2414 DCHECK(editable); | 2444 DCHECK(editable); |
| 2415 PlainTextRange plainTextRange(PlainTextRange::create(*editable, range)); | 2445 PlainTextRange plainTextRange(PlainTextRange::create(*editable, range)); |
| 2416 if (plainTextRange.isNull()) | 2446 if (plainTextRange.isNull()) |
| 2417 return false; | 2447 return false; |
| 2418 *location = plainTextRange.start(); | 2448 *location = plainTextRange.start(); |
| 2419 *length = plainTextRange.length(); | 2449 *length = plainTextRange.length(); |
| 2420 return true; | 2450 return true; |
| 2421 } | 2451 } |
| 2422 | 2452 |
| 2423 WebTextInputInfo WebViewImpl::textInputInfo() | 2453 WebTextInputInfo WebViewImpl::textInputInfo() |
| 2424 { | 2454 { |
| 2425 WebTextInputInfo info; | 2455 WebTextInputInfo info; |
| 2426 | 2456 |
| 2457 // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget | |
| 2458 // belonging to the local root. | |
| 2459 if (!mainFrameImpl()) | |
| 2460 return info; | |
| 2461 | |
| 2427 Frame* focusedFrame = focusedCoreFrame(); | 2462 Frame* focusedFrame = focusedCoreFrame(); |
| 2428 if (!focusedFrame->isLocalFrame()) | 2463 if (!focusedFrame->isLocalFrame()) |
| 2429 return info; | 2464 return info; |
| 2430 | 2465 |
| 2431 LocalFrame* focused = toLocalFrame(focusedFrame); | 2466 LocalFrame* focused = toLocalFrame(focusedFrame); |
| 2432 if (!focused) | 2467 if (!focused) |
| 2433 return info; | 2468 return info; |
| 2434 | 2469 |
| 2470 // We can only have a text input type when focused frame belongs to this | |
| 2471 // WebViewImpl, i.e., its local root is the main frame. | |
| 2472 if (focused->localFrameRoot() != mainFrameImpl()->frame()) | |
| 2473 return info; | |
| 2474 | |
| 2435 FrameSelection& selection = focused->selection(); | 2475 FrameSelection& selection = focused->selection(); |
| 2436 if (!selection.isAvailable()) { | 2476 if (!selection.isAvailable()) { |
| 2437 // plugins/mouse-capture-inside-shadow.html reaches here. | 2477 // plugins/mouse-capture-inside-shadow.html reaches here. |
| 2438 return info; | 2478 return info; |
| 2439 } | 2479 } |
| 2440 Element* element = selection.selection().rootEditableElement(); | 2480 Element* element = selection.selection().rootEditableElement(); |
| 2441 if (!element) | 2481 if (!element) |
| 2442 return info; | 2482 return info; |
| 2443 | 2483 |
| 2444 info.inputMode = inputModeOfFocusedElement(); | 2484 info.inputMode = inputModeOfFocusedElement(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 2474 info.compositionStart = plainTextRange.start(); | 2514 info.compositionStart = plainTextRange.start(); |
| 2475 info.compositionEnd = plainTextRange.end(); | 2515 info.compositionEnd = plainTextRange.end(); |
| 2476 } | 2516 } |
| 2477 } | 2517 } |
| 2478 | 2518 |
| 2479 return info; | 2519 return info; |
| 2480 } | 2520 } |
| 2481 | 2521 |
| 2482 WebTextInputType WebViewImpl::textInputType() | 2522 WebTextInputType WebViewImpl::textInputType() |
| 2483 { | 2523 { |
| 2524 // When mainFrameImpl() is nullptr/remote, IME is handled at the Widget | |
| 2525 // belonging to the local root. | |
| 2526 if (!mainFrameImpl()) | |
| 2527 return WebTextInputTypeNone; | |
| 2528 | |
| 2484 LocalFrame* focusedFrame = m_page->focusController().focusedFrame(); | 2529 LocalFrame* focusedFrame = m_page->focusController().focusedFrame(); |
| 2485 if (!focusedFrame) | 2530 if (!focusedFrame) |
| 2486 return WebTextInputTypeNone; | 2531 return WebTextInputTypeNone; |
| 2487 | 2532 |
| 2533 if (focusedFrame != mainFrameImpl()->frame()) { | |
| 2534 // We can only report a text input type when the focused frame belongs | |
| 2535 // to this WebViewImpl, i.e., its local root is the main frame. | |
| 2536 return WebTextInputTypeNone; | |
| 2537 } | |
| 2538 | |
| 2488 if (!focusedFrame->selection().isAvailable()) { | 2539 if (!focusedFrame->selection().isAvailable()) { |
| 2489 // "mouse-capture-inside-shadow.html" reaches here. | 2540 // "mouse-capture-inside-shadow.html" reaches here. |
| 2490 return WebTextInputTypeNone; | 2541 return WebTextInputTypeNone; |
| 2491 } | 2542 } |
| 2492 | 2543 |
| 2493 // It's important to preserve the equivalence of textInputInfo().type and te xtInputType(), | 2544 // 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. | 2545 // so perform the same rootEditableElement() existence check here for consis tency. |
| 2495 if (!focusedFrame->selection().selection().rootEditableElement()) | 2546 if (!focusedFrame->selection().selection().rootEditableElement()) |
| 2496 return WebTextInputTypeNone; | 2547 return WebTextInputTypeNone; |
| 2497 | 2548 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2817 if (page()) | 2868 if (page()) |
| 2818 page()->pointerLockController().didLosePointerLock(); | 2869 page()->pointerLockController().didLosePointerLock(); |
| 2819 } | 2870 } |
| 2820 | 2871 |
| 2821 void WebViewImpl::didChangeWindowResizerRect() | 2872 void WebViewImpl::didChangeWindowResizerRect() |
| 2822 { | 2873 { |
| 2823 if (mainFrameImpl()->frameView()) | 2874 if (mainFrameImpl()->frameView()) |
| 2824 mainFrameImpl()->frameView()->windowResizerRectChanged(); | 2875 mainFrameImpl()->frameView()->windowResizerRectChanged(); |
| 2825 } | 2876 } |
| 2826 | 2877 |
| 2878 bool WebViewImpl::getCompositionCharacterBounds(WebVector<WebRect>& bounds) | |
| 2879 { | |
| 2880 size_t offset = 0; | |
| 2881 size_t characterCount = 0; | |
| 2882 if (!compositionRange(&offset, &characterCount)) | |
| 2883 return false; | |
| 2884 | |
| 2885 if (characterCount == 0) | |
| 2886 return false; | |
| 2887 | |
| 2888 WebLocalFrame* frame = focusedFrame(); | |
| 2889 | |
| 2890 // Only consider frames whose local root is the main frame. For other | |
| 2891 // local frames which have different local roots, the corresponding | |
| 2892 // WebFrameWidget will handle this task. | |
| 2893 if (frame->localRoot() != mainFrameImpl()) | |
| 2894 return false; | |
| 2895 | |
| 2896 WebVector<WebRect> result(characterCount); | |
| 2897 WebRect webrect; | |
| 2898 for (size_t i = 0; i < characterCount; ++i) { | |
| 2899 if (!frame->firstRectForCharacterRange(offset + i, 1, webrect)) { | |
| 2900 DLOG(ERROR) << "Could not retrieve character rectangle at " << i; | |
| 2901 return false; | |
| 2902 } | |
| 2903 result[i] = webrect; | |
| 2904 } | |
| 2905 bounds.swap(result); | |
| 2906 return true; | |
| 2907 } | |
| 2908 | |
| 2909 void WebViewImpl::applyReplacementRange(int start, int length) | |
| 2910 { | |
| 2911 if (WebLocalFrame* frame = focusedFrame()) { | |
| 2912 WebRange webrange = WebRange::fromDocumentRange(frame, start, length); | |
| 2913 if (!webrange.isNull()) | |
| 2914 frame->selectRange(webrange); | |
| 2915 } | |
| 2916 } | |
| 2917 | |
| 2827 // WebView -------------------------------------------------------------------- | 2918 // WebView -------------------------------------------------------------------- |
| 2828 | 2919 |
| 2829 WebSettingsImpl* WebViewImpl::settingsImpl() | 2920 WebSettingsImpl* WebViewImpl::settingsImpl() |
| 2830 { | 2921 { |
| 2831 if (!m_webSettings) | 2922 if (!m_webSettings) |
| 2832 m_webSettings = wrapUnique(new WebSettingsImpl(&m_page->settings(), m_de vToolsEmulator.get())); | 2923 m_webSettings = wrapUnique(new WebSettingsImpl(&m_page->settings(), m_de vToolsEmulator.get())); |
| 2833 DCHECK(m_webSettings); | 2924 DCHECK(m_webSettings); |
| 2834 return m_webSettings.get(); | 2925 return m_webSettings.get(); |
| 2835 } | 2926 } |
| 2836 | 2927 |
| (...skipping 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4569 { | 4660 { |
| 4570 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than | 4661 // 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. | 4662 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. |
| 4572 if (!page()) | 4663 if (!page()) |
| 4573 return 1; | 4664 return 1; |
| 4574 | 4665 |
| 4575 return page()->deviceScaleFactor(); | 4666 return page()->deviceScaleFactor(); |
| 4576 } | 4667 } |
| 4577 | 4668 |
| 4578 } // namespace blink | 4669 } // namespace blink |
| OLD | NEW |