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

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

Issue 2029423003: OOPIF IME: Renderer Side Changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing lfg@'s comments. 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "web/WebFrameWidgetImpl.h" 31 #include "web/WebFrameWidgetImpl.h"
32 32
33 #include "core/InputTypeNames.h"
33 #include "core/editing/EditingUtilities.h" 34 #include "core/editing/EditingUtilities.h"
34 #include "core/editing/Editor.h" 35 #include "core/editing/Editor.h"
35 #include "core/editing/FrameSelection.h" 36 #include "core/editing/FrameSelection.h"
36 #include "core/editing/InputMethodController.h" 37 #include "core/editing/InputMethodController.h"
37 #include "core/editing/PlainTextRange.h" 38 #include "core/editing/PlainTextRange.h"
38 #include "core/frame/FrameHost.h" 39 #include "core/frame/FrameHost.h"
39 #include "core/frame/FrameView.h" 40 #include "core/frame/FrameView.h"
40 #include "core/frame/RemoteFrame.h" 41 #include "core/frame/RemoteFrame.h"
41 #include "core/frame/Settings.h" 42 #include "core/frame/Settings.h"
42 #include "core/frame/VisualViewport.h" 43 #include "core/frame/VisualViewport.h"
44 #include "core/html/HTMLInputElement.h"
45 #include "core/html/HTMLTextAreaElement.h"
43 #include "core/input/EventHandler.h" 46 #include "core/input/EventHandler.h"
44 #include "core/layout/LayoutView.h" 47 #include "core/layout/LayoutView.h"
45 #include "core/layout/api/LayoutViewItem.h" 48 #include "core/layout/api/LayoutViewItem.h"
46 #include "core/layout/compositing/PaintLayerCompositor.h" 49 #include "core/layout/compositing/PaintLayerCompositor.h"
47 #include "core/page/ContextMenuController.h" 50 #include "core/page/ContextMenuController.h"
48 #include "core/page/FocusController.h" 51 #include "core/page/FocusController.h"
49 #include "core/page/Page.h" 52 #include "core/page/Page.h"
50 #include "core/page/PointerLockController.h" 53 #include "core/page/PointerLockController.h"
51 #include "platform/KeyboardCodes.h" 54 #include "platform/KeyboardCodes.h"
52 #include "platform/graphics/CompositorMutatorClient.h" 55 #include "platform/graphics/CompositorMutatorClient.h"
53 #include "public/platform/WebFrameScheduler.h" 56 #include "public/platform/WebFrameScheduler.h"
57 #include "public/web/WebPlugin.h"
58 #include "public/web/WebRange.h"
54 #include "public/web/WebWidgetClient.h" 59 #include "public/web/WebWidgetClient.h"
60 #include "web/CompositionUnderlineVectorBuilder.h"
55 #include "web/CompositorMutatorImpl.h" 61 #include "web/CompositorMutatorImpl.h"
56 #include "web/CompositorProxyClientImpl.h" 62 #include "web/CompositorProxyClientImpl.h"
57 #include "web/ContextMenuAllowedScope.h" 63 #include "web/ContextMenuAllowedScope.h"
58 #include "web/WebDevToolsAgentImpl.h" 64 #include "web/WebDevToolsAgentImpl.h"
59 #include "web/WebInputEventConversion.h" 65 #include "web/WebInputEventConversion.h"
60 #include "web/WebLocalFrameImpl.h" 66 #include "web/WebLocalFrameImpl.h"
61 #include "web/WebPluginContainerImpl.h" 67 #include "web/WebPluginContainerImpl.h"
62 #include "web/WebRemoteFrameImpl.h" 68 #include "web/WebRemoteFrameImpl.h"
63 #include "web/WebViewFrameWidget.h" 69 #include "web/WebViewFrameWidget.h"
64 #include "wtf/PtrUtil.h" 70 #include "wtf/PtrUtil.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 , m_localRoot(toWebLocalFrameImpl(localRoot)) 103 , m_localRoot(toWebLocalFrameImpl(localRoot))
98 , m_mutator(nullptr) 104 , m_mutator(nullptr)
99 , m_layerTreeView(nullptr) 105 , m_layerTreeView(nullptr)
100 , m_rootLayer(nullptr) 106 , m_rootLayer(nullptr)
101 , m_rootGraphicsLayer(nullptr) 107 , m_rootGraphicsLayer(nullptr)
102 , m_isAcceleratedCompositingActive(false) 108 , m_isAcceleratedCompositingActive(false)
103 , m_layerTreeViewClosed(false) 109 , m_layerTreeViewClosed(false)
104 , m_suppressNextKeypressEvent(false) 110 , m_suppressNextKeypressEvent(false)
105 , m_ignoreInputEvents(false) 111 , m_ignoreInputEvents(false)
106 , m_isTransparent(false) 112 , m_isTransparent(false)
113 , m_imeAcceptEvents(true)
lfg 2016/07/07 15:13:31 Should this be initialized to false?
EhsanK 2016/07/07 20:25:08 WebViewImpl initializes this to true. But I guess
lfg 2016/07/07 20:58:27 Yes, indeed.
107 , m_selfKeepAlive(this) 114 , m_selfKeepAlive(this)
108 { 115 {
109 DCHECK(m_localRoot->frame()->isLocalRoot()); 116 DCHECK(m_localRoot->frame()->isLocalRoot());
110 initializeLayerTreeView(); 117 initializeLayerTreeView();
111 m_localRoot->setFrameWidget(this); 118 m_localRoot->setFrameWidget(this);
112 allInstances().add(this); 119 allInstances().add(this);
113 120
114 if (localRoot->parent()) 121 if (localRoot->parent())
115 setIsTransparent(true); 122 setIsTransparent(true);
116 } 123 }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 439 }
433 440
434 void WebFrameWidgetImpl::mouseCaptureLost() 441 void WebFrameWidgetImpl::mouseCaptureLost()
435 { 442 {
436 TRACE_EVENT_ASYNC_END0("input", "capturing mouse", this); 443 TRACE_EVENT_ASYNC_END0("input", "capturing mouse", this);
437 m_mouseCaptureNode = nullptr; 444 m_mouseCaptureNode = nullptr;
438 } 445 }
439 446
440 void WebFrameWidgetImpl::setFocus(bool enable) 447 void WebFrameWidgetImpl::setFocus(bool enable)
441 { 448 {
449 m_imeAcceptEvents = enable;
lfg 2016/07/07 15:13:31 Is it possible for the widget to have focus, but m
EhsanK 2016/07/07 20:25:08 m_imeAcceptEvents is apparent tracking page level
lfg 2016/07/07 20:58:27 That's right, can you dig a bit more to see if we
EhsanK 2016/07/11 20:29:53 I have explained what might happen in WebViewImpl:
442 page()->focusController().setFocused(enable); 450 page()->focusController().setFocused(enable);
443 if (enable) { 451 if (enable) {
444 page()->focusController().setActive(true); 452 page()->focusController().setActive(true);
445 LocalFrame* focusedFrame = page()->focusController().focusedFrame(); 453 LocalFrame* focusedFrame = page()->focusController().focusedFrame();
446 if (focusedFrame) { 454 if (focusedFrame) {
447 Element* element = focusedFrame->document()->focusedElement(); 455 Element* element = focusedFrame->document()->focusedElement();
448 if (element && focusedFrame->selection().selection().isNone()) { 456 if (element && focusedFrame->selection().selection().isNone()) {
449 // If the selection was cleared while the WebView was not 457 // If the selection was cleared while the WebView was not
450 // focused, then the focus element shows with a focus ring but 458 // focused, then the focus element shows with a focus ring but
451 // no caret and does respond to keyboard inputs. 459 // no caret and does respond to keyboard inputs.
(...skipping 11 matching lines...) Expand all
463 } 471 }
464 } 472 }
465 } 473 }
466 474
467 bool WebFrameWidgetImpl::setComposition( 475 bool WebFrameWidgetImpl::setComposition(
468 const WebString& text, 476 const WebString& text,
469 const WebVector<WebCompositionUnderline>& underlines, 477 const WebVector<WebCompositionUnderline>& underlines,
470 int selectionStart, 478 int selectionStart,
471 int selectionEnd) 479 int selectionEnd)
472 { 480 {
473 // FIXME: To be implemented. 481 if (!m_imeAcceptEvents)
474 return false; 482 return false;
483
484 LocalFrame* focused = focusedLocalFrameInWidget();
485
486 if (!focused)
487 return false;
488
489 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
490 return plugin->setComposition(text, underlines, selectionStart, selectio nEnd);
491
492 // The input focus has been moved to another WebWidget object.
493 // We should use this |editor| object only to complete the ongoing
494 // composition.
495 InputMethodController& inputMethodController = focused->inputMethodControlle r();
496 if (!focused->editor().canEdit() && !inputMethodController.hasComposition())
497 return false;
498
499 // We should verify the parent node of this IME composition node are
500 // editable because JavaScript may delete a parent node of the composition
501 // node. In this case, WebKit crashes while deleting texts from the parent
502 // node, which doesn't exist any longer.
503 const EphemeralRange range = inputMethodController.compositionEphemeralRange ();
504 if (range.isNotNull()) {
505 Node* node = range.startPosition().computeContainerNode();
506 if (!node || !node->isContentEditable())
507 return false;
508 }
509
510 // A keypress event is canceled. If an ongoing composition exists, then the
511 // keydown event should have arisen from a handled key (e.g., backspace).
512 // In this case we ignore the cancellation and continue; otherwise (no
513 // ongoing composition) we exit and signal success only for attempts to
514 // clear the composition.
515 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition())
516 return text.isEmpty();
517
518 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
519
520 // When the range of composition underlines overlap with the range between
521 // selectionStart and selectionEnd, WebKit somehow won't paint the selection
522 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp).
523 // But the selection range actually takes effect.
524 inputMethodController.setComposition(String(text),
525 CompositionUnderlineVectorBuilder(underlines),
526 selectionStart, selectionEnd);
527
528 return text.isEmpty() || inputMethodController.hasComposition();
475 } 529 }
476 530
477 bool WebFrameWidgetImpl::confirmComposition() 531 bool WebFrameWidgetImpl::confirmComposition()
478 { 532 {
479 // FIXME: To be implemented. 533 return confirmComposition(DoNotKeepSelection);
480 return false;
481 } 534 }
482 535
483 bool WebFrameWidgetImpl::confirmComposition(ConfirmCompositionBehavior selection Behavior) 536 bool WebFrameWidgetImpl::confirmComposition(ConfirmCompositionBehavior selection Behavior)
484 { 537 {
485 // FIXME: To be implemented. 538 return confirmComposition(WebString(), selectionBehavior);
486 return false;
487 } 539 }
488 540
489 bool WebFrameWidgetImpl::confirmComposition(const WebString& text) 541 bool WebFrameWidgetImpl::confirmComposition(const WebString& text)
490 { 542 {
491 // FIXME: To be implemented. 543 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
492 return false; 544 return confirmComposition(text, DoNotKeepSelection);
545 }
546
547 bool WebFrameWidgetImpl::confirmComposition(const WebString& text, ConfirmCompos itionBehavior selectionBehavior) const
548 {
549 if (!m_imeAcceptEvents)
550 return false;
551
552 LocalFrame* focused = focusedLocalFrameInWidget();
553 if (!focused)
554 return false;
555
556 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused))
557 return plugin->confirmComposition(text, selectionBehavior);
558
559 return focused->inputMethodController().confirmCompositionOrInsertText(text, selectionBehavior == KeepSelection ? InputMethodController::KeepSelection : Inp utMethodController::DoNotKeepSelection);
493 } 560 }
494 561
495 bool WebFrameWidgetImpl::compositionRange(size_t* location, size_t* length) 562 bool WebFrameWidgetImpl::compositionRange(size_t* location, size_t* length)
496 { 563 {
497 // FIXME: To be implemented. 564 if (!m_imeAcceptEvents)
498 return false; 565 return false;
566
567 LocalFrame* focused = focusedLocalFrameInWidget();
568 if (!focused)
569 return false;
570
571 const EphemeralRange range = focused->inputMethodController().compositionEph emeralRange();
572 if (range.isNull())
573 return false;
574
575 Element* editable = focused->selection().rootEditableElementOrDocumentElemen t();
576 DCHECK(editable);
577 PlainTextRange plainTextRange(PlainTextRange::create(*editable, range));
578 if (plainTextRange.isNull())
579 return false;
580 *location = plainTextRange.start();
581 *length = plainTextRange.length();
582 return true;
499 } 583 }
500 584
501 WebTextInputInfo WebFrameWidgetImpl::textInputInfo() 585 WebTextInputInfo WebFrameWidgetImpl::textInputInfo()
502 { 586 {
503 return view()->textInputInfo(); 587 WebTextInputInfo info;
588
589 LocalFrame* focused = focusedLocalFrameInWidget();
590 if (!focused)
591 return info;
592
593 FrameSelection& selection = focused->selection();
594 if (!selection.isAvailable()) {
595 // plugins/mouse-capture-inside-shadow.html reaches here.
596 return info;
597 }
598 Element* element = selection.selection().rootEditableElement();
599 if (!element)
600 return info;
601
602 info.inputMode = inputModeOfFocusedElement();
603
604 info.type = textInputType();
605 info.flags = textInputFlags();
606 if (info.type == WebTextInputTypeNone)
607 return info;
608
609 if (!focused->editor().canEdit())
610 return info;
611
612 // Emits an object replacement character for each replaced element so that
613 // it is exposed to IME and thus could be deleted by IME on android.
614 info.value = plainText(EphemeralRange::rangeOfContents(*element), TextIterat orEmitsObjectReplacementCharacter);
615
616 if (info.value.isEmpty())
617 return info;
618
619 EphemeralRange firstRange = firstEphemeralRangeOf(selection.selection());
620 if (firstRange.isNotNull()) {
621 PlainTextRange plainTextRange(PlainTextRange::create(*element, firstRang e));
622 if (plainTextRange.isNotNull()) {
623 info.selectionStart = plainTextRange.start();
624 info.selectionEnd = plainTextRange.end();
625 }
626 }
627
628 EphemeralRange range = focused->inputMethodController().compositionEphemeral Range();
629 if (range.isNotNull()) {
630 PlainTextRange plainTextRange(PlainTextRange::create(*element, range));
631 if (plainTextRange.isNotNull()) {
632 info.compositionStart = plainTextRange.start();
633 info.compositionEnd = plainTextRange.end();
634 }
635 }
636
637 return info;
504 } 638 }
505 639
506 WebTextInputType WebFrameWidgetImpl::textInputType() 640 WebTextInputType WebFrameWidgetImpl::textInputType()
507 { 641 {
508 return view()->textInputType(); 642 LocalFrame* focusedFrame = focusedLocalFrameInWidget();
643 if (!focusedFrame)
644 return WebTextInputTypeNone;
645
646 if (!focusedFrame->selection().isAvailable()) {
647 // "mouse-capture-inside-shadow.html" reaches here.
648 return WebTextInputTypeNone;
649 }
650
651 // It's important to preserve the equivalence of textInputInfo().type and te xtInputType(),
652 // so perform the same rootEditableElement() existence check here for consis tency.
653 if (!focusedFrame->selection().selection().rootEditableElement())
654 return WebTextInputTypeNone;
655
656 Document* document = focusedFrame->document();
657 if (!document)
658 return WebTextInputTypeNone;
659
660 Element* element = document->focusedElement();
661 if (!element)
662 return WebTextInputTypeNone;
663
664 if (isHTMLInputElement(*element)) {
665 HTMLInputElement& input = toHTMLInputElement(*element);
666 const AtomicString& type = input.type();
667
668 if (input.isDisabledOrReadOnly())
669 return WebTextInputTypeNone;
670
671 if (type == InputTypeNames::password)
672 return WebTextInputTypePassword;
673 if (type == InputTypeNames::search)
674 return WebTextInputTypeSearch;
675 if (type == InputTypeNames::email)
676 return WebTextInputTypeEmail;
677 if (type == InputTypeNames::number)
678 return WebTextInputTypeNumber;
679 if (type == InputTypeNames::tel)
680 return WebTextInputTypeTelephone;
681 if (type == InputTypeNames::url)
682 return WebTextInputTypeURL;
683 if (type == InputTypeNames::date)
684 return WebTextInputTypeDate;
685 if (type == InputTypeNames::datetime_local)
686 return WebTextInputTypeDateTimeLocal;
687 if (type == InputTypeNames::month)
688 return WebTextInputTypeMonth;
689 if (type == InputTypeNames::time)
690 return WebTextInputTypeTime;
691 if (type == InputTypeNames::week)
692 return WebTextInputTypeWeek;
693 if (type == InputTypeNames::text)
694 return WebTextInputTypeText;
695
696 return WebTextInputTypeNone;
697 }
698
699 if (isHTMLTextAreaElement(*element)) {
700 if (toHTMLTextAreaElement(*element).isDisabledOrReadOnly())
701 return WebTextInputTypeNone;
702 return WebTextInputTypeTextArea;
703 }
704
705 if (element->isHTMLElement()) {
706 if (toHTMLElement(element)->isDateTimeFieldElement())
707 return WebTextInputTypeDateTimeField;
708 }
709
710 if (element->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable))
711 return WebTextInputTypeContentEditable;
712
713 return WebTextInputTypeNone;
509 } 714 }
510 715
511 WebColor WebFrameWidgetImpl::backgroundColor() const 716 WebColor WebFrameWidgetImpl::backgroundColor() const
512 { 717 {
513 if (isTransparent()) 718 if (isTransparent())
514 return Color::transparent; 719 return Color::transparent;
515 if (!m_localRoot->frameView()) 720 if (!m_localRoot->frameView())
516 return m_baseBackgroundColor; 721 return m_baseBackgroundColor;
517 FrameView* view = m_localRoot->frameView(); 722 FrameView* view = m_localRoot->frameView();
518 return view->documentBackgroundColor().rgb(); 723 return view->documentBackgroundColor().rgb();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 void WebFrameWidgetImpl::didNotAcquirePointerLock() 862 void WebFrameWidgetImpl::didNotAcquirePointerLock()
658 { 863 {
659 page()->pointerLockController().didNotAcquirePointerLock(); 864 page()->pointerLockController().didNotAcquirePointerLock();
660 } 865 }
661 866
662 void WebFrameWidgetImpl::didLosePointerLock() 867 void WebFrameWidgetImpl::didLosePointerLock()
663 { 868 {
664 page()->pointerLockController().didLosePointerLock(); 869 page()->pointerLockController().didLosePointerLock();
665 } 870 }
666 871
872 bool WebFrameWidgetImpl::getCompositionCharacterBounds(WebVector<WebRect>& bound s)
873 {
874 size_t offset = 0;
875 size_t characterCount = 0;
876 if (!compositionRange(&offset, &characterCount))
877 return false;
878
879 if (characterCount == 0)
880 return false;
881
882 LocalFrame* frame = focusedLocalFrameInWidget();
883 if (!frame)
884 return false;
885
886 WebLocalFrameImpl* webLocalFrame = WebLocalFrameImpl::fromFrame(frame);
887 WebVector<WebRect> result(characterCount);
888 WebRect webrect;
889 for (size_t i = 0; i < characterCount; ++i) {
890 if (!webLocalFrame->firstRectForCharacterRange(offset + i, 1, webrect)) {
891 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
892 return false;
893 }
894 result[i] = webrect;
895 }
896 bounds.swap(result);
897 return true;
898 }
899
900 void WebFrameWidgetImpl::applyReplacementRange(int start, int length)
901 {
902 if (LocalFrame* frame = focusedLocalFrameInWidget()) {
903 WebLocalFrameImpl* webLocalFrame = WebLocalFrameImpl::fromFrame(frame);
904 WebRange webrange = WebRange::fromDocumentRange(webLocalFrame, start, le ngth);
905 if (!webrange.isNull())
906 webLocalFrame->selectRange(webrange);
907 }
908 }
909
667 void WebFrameWidgetImpl::handleMouseLeave(LocalFrame& mainFrame, const WebMouseE vent& event) 910 void WebFrameWidgetImpl::handleMouseLeave(LocalFrame& mainFrame, const WebMouseE vent& event)
668 { 911 {
669 // FIXME: WebWidget doesn't have the method below. 912 // FIXME: WebWidget doesn't have the method below.
670 // m_client->setMouseOverURL(WebURL()); 913 // m_client->setMouseOverURL(WebURL());
671 PageWidgetEventHandler::handleMouseLeave(mainFrame, event); 914 PageWidgetEventHandler::handleMouseLeave(mainFrame, event);
672 } 915 }
673 916
674 void WebFrameWidgetImpl::handleMouseDown(LocalFrame& mainFrame, const WebMouseEv ent& event) 917 void WebFrameWidgetImpl::handleMouseDown(LocalFrame& mainFrame, const WebMouseEv ent& event)
675 { 918 {
676 // Take capture on a mouse down on a plugin so we can send it mouse events. 919 // Take capture on a mouse down on a plugin so we can send it mouse events.
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 } 1360 }
1118 1361
1119 HitTestResult WebFrameWidgetImpl::hitTestResultForRootFramePos(const IntPoint& p osInRootFrame) 1362 HitTestResult WebFrameWidgetImpl::hitTestResultForRootFramePos(const IntPoint& p osInRootFrame)
1120 { 1363 {
1121 IntPoint docPoint(m_localRoot->frame()->view()->rootFrameToContents(posInRoo tFrame)); 1364 IntPoint docPoint(m_localRoot->frame()->view()->rootFrameToContents(posInRoo tFrame));
1122 HitTestResult result = m_localRoot->frame()->eventHandler().hitTestResultAtP oint(docPoint, HitTestRequest::ReadOnly | HitTestRequest::Active); 1365 HitTestResult result = m_localRoot->frame()->eventHandler().hitTestResultAtP oint(docPoint, HitTestRequest::ReadOnly | HitTestRequest::Active);
1123 result.setToShadowHostIfInUserAgentShadowRoot(); 1366 result.setToShadowHostIfInUserAgentShadowRoot();
1124 return result; 1367 return result;
1125 } 1368 }
1126 1369
1370 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameInWidget() const
1371 {
1372 LocalFrame* frame = page()->focusController().focusedFrame();
1373 return (frame && frame->localFrameRoot() == m_localRoot->frame()) ? frame : nullptr;
1374 }
1375
1376 WebPlugin* WebFrameWidgetImpl::focusedPluginIfInputMethodSupported(LocalFrame* f rame) const
1377 {
1378 WebPluginContainerImpl* container = WebLocalFrameImpl::currentPluginContaine r(frame);
1379 if (container && container->supportsInputMethod())
1380 return container->plugin();
1381 return nullptr;
1382 }
1383
1384 WebString WebFrameWidgetImpl::inputModeOfFocusedElement() const
1385 {
1386 if (!RuntimeEnabledFeatures::inputModeAttributeEnabled())
1387 return WebString();
1388
1389 Element* element = focusedElement();
1390 if (!element)
1391 return WebString();
1392
1393 if (isHTMLInputElement(*element)) {
1394 const HTMLInputElement& input = toHTMLInputElement(*element);
1395 if (input.supportsInputModeAttribute())
1396 return input.fastGetAttribute(HTMLNames::inputmodeAttr).lower();
1397 return WebString();
1398 }
1399 if (isHTMLTextAreaElement(*element)) {
1400 const HTMLTextAreaElement& textarea = toHTMLTextAreaElement(*element);
1401 return textarea.fastGetAttribute(HTMLNames::inputmodeAttr).lower();
1402 }
1403
1404 return WebString();
1405 }
1406
1407 int WebFrameWidgetImpl::textInputFlags() const
1408 {
1409 Element* element = focusedElement();
1410 if (!element)
1411 return WebTextInputFlagNone;
1412
1413 DEFINE_STATIC_LOCAL(AtomicString, autocompleteString, ("autocomplete"));
1414 DEFINE_STATIC_LOCAL(AtomicString, autocorrectString, ("autocorrect"));
1415 int flags = 0;
1416
1417 const AtomicString& autocomplete = element->getAttribute(autocompleteString) ;
1418 if (autocomplete == "on")
1419 flags |= WebTextInputFlagAutocompleteOn;
1420 else if (autocomplete == "off")
1421 flags |= WebTextInputFlagAutocompleteOff;
1422
1423 const AtomicString& autocorrect = element->getAttribute(autocorrectString);
1424 if (autocorrect == "on")
1425 flags |= WebTextInputFlagAutocorrectOn;
1426 else if (autocorrect == "off")
1427 flags |= WebTextInputFlagAutocorrectOff;
1428
1429 SpellcheckAttributeState spellcheck = element->spellcheckAttributeState();
1430 if (spellcheck == SpellcheckAttributeTrue)
1431 flags |= WebTextInputFlagSpellcheckOn;
1432 else if (spellcheck == SpellcheckAttributeFalse)
1433 flags |= WebTextInputFlagSpellcheckOff;
1434
1435 if (isHTMLTextFormControlElement(element)) {
1436 HTMLTextFormControlElement* formElement = static_cast<HTMLTextFormContro lElement*>(element);
1437 if (formElement->supportsAutocapitalize()) {
1438 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none"));
1439 DEFINE_STATIC_LOCAL(const AtomicString, characters, ("characters"));
1440 DEFINE_STATIC_LOCAL(const AtomicString, words, ("words"));
1441 DEFINE_STATIC_LOCAL(const AtomicString, sentences, ("sentences"));
1442
1443 const AtomicString& autocapitalize = formElement->autocapitalize();
1444 if (autocapitalize == none)
1445 flags |= WebTextInputFlagAutocapitalizeNone;
1446 else if (autocapitalize == characters)
1447 flags |= WebTextInputFlagAutocapitalizeCharacters;
1448 else if (autocapitalize == words)
1449 flags |= WebTextInputFlagAutocapitalizeWords;
1450 else if (autocapitalize == sentences)
1451 flags |= WebTextInputFlagAutocapitalizeSentences;
1452 else
1453 NOTREACHED();
1454 }
1455 }
1456
1457 return flags;
1458 }
1459
1127 } // namespace blink 1460 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698