OLD | NEW |
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #include "public/web/WebRange.h" | 58 #include "public/web/WebRange.h" |
59 #include "public/web/WebWidgetClient.h" | 59 #include "public/web/WebWidgetClient.h" |
60 #include "web/CompositionUnderlineVectorBuilder.h" | 60 #include "web/CompositionUnderlineVectorBuilder.h" |
61 #include "web/CompositorMutatorImpl.h" | 61 #include "web/CompositorMutatorImpl.h" |
62 #include "web/CompositorProxyClientImpl.h" | 62 #include "web/CompositorProxyClientImpl.h" |
63 #include "web/ContextMenuAllowedScope.h" | 63 #include "web/ContextMenuAllowedScope.h" |
64 #include "web/InspectorOverlay.h" | 64 #include "web/InspectorOverlay.h" |
65 #include "web/PageOverlay.h" | 65 #include "web/PageOverlay.h" |
66 #include "web/WebDevToolsAgentImpl.h" | 66 #include "web/WebDevToolsAgentImpl.h" |
67 #include "web/WebInputEventConversion.h" | 67 #include "web/WebInputEventConversion.h" |
| 68 #include "web/WebInputMethodControllerImpl.h" |
68 #include "web/WebLocalFrameImpl.h" | 69 #include "web/WebLocalFrameImpl.h" |
69 #include "web/WebPluginContainerImpl.h" | 70 #include "web/WebPluginContainerImpl.h" |
70 #include "web/WebRemoteFrameImpl.h" | 71 #include "web/WebRemoteFrameImpl.h" |
71 #include "web/WebViewFrameWidget.h" | 72 #include "web/WebViewFrameWidget.h" |
72 #include "wtf/AutoReset.h" | 73 #include "wtf/AutoReset.h" |
73 #include "wtf/PtrUtil.h" | 74 #include "wtf/PtrUtil.h" |
74 #include <memory> | 75 #include <memory> |
75 | 76 |
76 namespace blink { | 77 namespace blink { |
77 | 78 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 404 |
404 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) { | 405 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) { |
405 if (m_baseBackgroundColor == color) | 406 if (m_baseBackgroundColor == color) |
406 return; | 407 return; |
407 | 408 |
408 m_baseBackgroundColor = color; | 409 m_baseBackgroundColor = color; |
409 | 410 |
410 m_localRoot->frameView()->setBaseBackgroundColor(color); | 411 m_localRoot->frameView()->setBaseBackgroundColor(color); |
411 } | 412 } |
412 | 413 |
| 414 WebInputMethodControllerImpl* |
| 415 WebFrameWidgetImpl::getActiveWebInputMethodController() const { |
| 416 return WebInputMethodControllerImpl::fromFrame( |
| 417 focusedLocalFrameAvailableForIme()); |
| 418 } |
| 419 |
413 void WebFrameWidgetImpl::scheduleAnimation() { | 420 void WebFrameWidgetImpl::scheduleAnimation() { |
414 if (m_layerTreeView) { | 421 if (m_layerTreeView) { |
415 m_layerTreeView->setNeedsBeginFrame(); | 422 m_layerTreeView->setNeedsBeginFrame(); |
416 return; | 423 return; |
417 } | 424 } |
418 if (m_client) | 425 if (m_client) |
419 m_client->scheduleAnimation(); | 426 m_client->scheduleAnimation(); |
420 } | 427 } |
421 | 428 |
422 CompositorProxyClient* WebFrameWidgetImpl::createCompositorProxyClient() { | 429 CompositorProxyClient* WebFrameWidgetImpl::createCompositorProxyClient() { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 if (autofillClient) | 498 if (autofillClient) |
492 autofillClient->setIgnoreTextChanges(false); | 499 autofillClient->setIgnoreTextChanges(false); |
493 } | 500 } |
494 m_imeAcceptEvents = false; | 501 m_imeAcceptEvents = false; |
495 } | 502 } |
496 } | 503 } |
497 } | 504 } |
498 | 505 |
499 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | 506 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This |
500 // code needs to be refactored (http://crbug.com/629721). | 507 // code needs to be refactored (http://crbug.com/629721). |
501 bool WebFrameWidgetImpl::setComposition( | |
502 const WebString& text, | |
503 const WebVector<WebCompositionUnderline>& underlines, | |
504 int selectionStart, | |
505 int selectionEnd) { | |
506 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
507 if (!focused) | |
508 return false; | |
509 | |
510 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
511 return plugin->setComposition(text, underlines, selectionStart, | |
512 selectionEnd); | |
513 | |
514 // The input focus has been moved to another WebWidget object. | |
515 // We should use this |editor| object only to complete the ongoing | |
516 // composition. | |
517 InputMethodController& inputMethodController = | |
518 focused->inputMethodController(); | |
519 if (!focused->editor().canEdit() && !inputMethodController.hasComposition()) | |
520 return false; | |
521 | |
522 // We should verify the parent node of this IME composition node are | |
523 // editable because JavaScript may delete a parent node of the composition | |
524 // node. In this case, WebKit crashes while deleting texts from the parent | |
525 // node, which doesn't exist any longer. | |
526 const EphemeralRange range = | |
527 inputMethodController.compositionEphemeralRange(); | |
528 if (range.isNotNull()) { | |
529 Node* node = range.startPosition().computeContainerNode(); | |
530 focused->document()->updateStyleAndLayoutTree(); | |
531 if (!node || !hasEditableStyle(*node)) | |
532 return false; | |
533 } | |
534 | |
535 // A keypress event is canceled. If an ongoing composition exists, then the | |
536 // keydown event should have arisen from a handled key (e.g., backspace). | |
537 // In this case we ignore the cancellation and continue; otherwise (no | |
538 // ongoing composition) we exit and signal success only for attempts to | |
539 // clear the composition. | |
540 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition()) | |
541 return text.isEmpty(); | |
542 | |
543 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create( | |
544 focused->document(), UserGestureToken::NewGesture)); | |
545 | |
546 // When the range of composition underlines overlap with the range between | |
547 // selectionStart and selectionEnd, WebKit somehow won't paint the selection | |
548 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp). | |
549 // But the selection range actually takes effect. | |
550 inputMethodController.setComposition( | |
551 String(text), CompositionUnderlineVectorBuilder(underlines), | |
552 selectionStart, selectionEnd); | |
553 | |
554 return text.isEmpty() || inputMethodController.hasComposition(); | |
555 } | |
556 | |
557 // TODO(ekaramad):These methods are almost duplicated in WebViewImpl as well. | |
558 // This code needs to be refactored (http://crbug.com/629721). | |
559 bool WebFrameWidgetImpl::commitText(const WebString& text, | |
560 int relativeCaretPosition) { | |
561 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
562 if (!focused) | |
563 return false; | |
564 | |
565 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create( | |
566 focused->document(), UserGestureToken::NewGesture)); | |
567 | |
568 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
569 return plugin->commitText(text, relativeCaretPosition); | |
570 | |
571 return focused->inputMethodController().commitText(text, | |
572 relativeCaretPosition); | |
573 } | |
574 | |
575 bool WebFrameWidgetImpl::finishComposingText( | |
576 ConfirmCompositionBehavior selectionBehavior) { | |
577 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
578 if (!focused) | |
579 return false; | |
580 | |
581 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
582 return plugin->finishComposingText(selectionBehavior); | |
583 | |
584 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | |
585 // needs to be audited. See http://crbug.com/590369 for more details. | |
586 focused->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | |
587 | |
588 return focused->inputMethodController().finishComposingText( | |
589 selectionBehavior == KeepSelection | |
590 ? InputMethodController::KeepSelection | |
591 : InputMethodController::DoNotKeepSelection); | |
592 } | |
593 | |
594 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | |
595 // code needs to be refactored (http://crbug.com/629721). | |
596 WebRange WebFrameWidgetImpl::compositionRange() { | 508 WebRange WebFrameWidgetImpl::compositionRange() { |
597 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | 509 LocalFrame* focused = focusedLocalFrameAvailableForIme(); |
598 if (!focused) | 510 if (!focused) |
599 return WebRange(); | 511 return WebRange(); |
600 | 512 |
601 const EphemeralRange range = | 513 const EphemeralRange range = |
602 focused->inputMethodController().compositionEphemeralRange(); | 514 focused->inputMethodController().compositionEphemeralRange(); |
603 if (range.isNull()) | 515 if (range.isNull()) |
604 return WebRange(); | 516 return WebRange(); |
605 | 517 |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 return nullptr; | 1146 return nullptr; |
1235 } | 1147 } |
1236 | 1148 |
1237 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const { | 1149 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const { |
1238 if (!m_imeAcceptEvents) | 1150 if (!m_imeAcceptEvents) |
1239 return nullptr; | 1151 return nullptr; |
1240 return focusedLocalFrameInWidget(); | 1152 return focusedLocalFrameInWidget(); |
1241 } | 1153 } |
1242 | 1154 |
1243 } // namespace blink | 1155 } // namespace blink |
OLD | NEW |