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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "public/web/WebAutofillClient.h" | 56 #include "public/web/WebAutofillClient.h" |
57 #include "public/web/WebPlugin.h" | 57 #include "public/web/WebPlugin.h" |
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/WebDevToolsAgentImpl.h" | 64 #include "web/WebDevToolsAgentImpl.h" |
65 #include "web/WebInputEventConversion.h" | 65 #include "web/WebInputEventConversion.h" |
| 66 #include "web/WebInputMethodControllerImpl.h" |
66 #include "web/WebLocalFrameImpl.h" | 67 #include "web/WebLocalFrameImpl.h" |
67 #include "web/WebPluginContainerImpl.h" | 68 #include "web/WebPluginContainerImpl.h" |
68 #include "web/WebRemoteFrameImpl.h" | 69 #include "web/WebRemoteFrameImpl.h" |
69 #include "web/WebViewFrameWidget.h" | 70 #include "web/WebViewFrameWidget.h" |
70 #include "wtf/AutoReset.h" | 71 #include "wtf/AutoReset.h" |
71 #include "wtf/PtrUtil.h" | 72 #include "wtf/PtrUtil.h" |
72 #include <memory> | 73 #include <memory> |
73 | 74 |
74 namespace blink { | 75 namespace blink { |
75 | 76 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 389 |
389 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) { | 390 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) { |
390 if (m_baseBackgroundColor == color) | 391 if (m_baseBackgroundColor == color) |
391 return; | 392 return; |
392 | 393 |
393 m_baseBackgroundColor = color; | 394 m_baseBackgroundColor = color; |
394 | 395 |
395 m_localRoot->frameView()->setBaseBackgroundColor(color); | 396 m_localRoot->frameView()->setBaseBackgroundColor(color); |
396 } | 397 } |
397 | 398 |
| 399 WebInputMethodControllerImpl* |
| 400 WebFrameWidgetImpl::getActiveWebInputMethodController() const { |
| 401 return WebInputMethodControllerImpl::fromFrame( |
| 402 focusedLocalFrameAvailableForIme()); |
| 403 } |
| 404 |
398 void WebFrameWidgetImpl::scheduleAnimation() { | 405 void WebFrameWidgetImpl::scheduleAnimation() { |
399 if (m_layerTreeView) { | 406 if (m_layerTreeView) { |
400 m_layerTreeView->setNeedsBeginFrame(); | 407 m_layerTreeView->setNeedsBeginFrame(); |
401 return; | 408 return; |
402 } | 409 } |
403 if (m_client) | 410 if (m_client) |
404 m_client->scheduleAnimation(); | 411 m_client->scheduleAnimation(); |
405 } | 412 } |
406 | 413 |
407 CompositorProxyClient* WebFrameWidgetImpl::createCompositorProxyClient() { | 414 CompositorProxyClient* WebFrameWidgetImpl::createCompositorProxyClient() { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 if (autofillClient) | 483 if (autofillClient) |
477 autofillClient->setIgnoreTextChanges(false); | 484 autofillClient->setIgnoreTextChanges(false); |
478 } | 485 } |
479 m_imeAcceptEvents = false; | 486 m_imeAcceptEvents = false; |
480 } | 487 } |
481 } | 488 } |
482 } | 489 } |
483 | 490 |
484 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | 491 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This |
485 // code needs to be refactored (http://crbug.com/629721). | 492 // code needs to be refactored (http://crbug.com/629721). |
486 bool WebFrameWidgetImpl::setComposition( | |
487 const WebString& text, | |
488 const WebVector<WebCompositionUnderline>& underlines, | |
489 int selectionStart, | |
490 int selectionEnd) { | |
491 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
492 if (!focused) | |
493 return false; | |
494 | |
495 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
496 return plugin->setComposition(text, underlines, selectionStart, | |
497 selectionEnd); | |
498 | |
499 // The input focus has been moved to another WebWidget object. | |
500 // We should use this |editor| object only to complete the ongoing | |
501 // composition. | |
502 InputMethodController& inputMethodController = | |
503 focused->inputMethodController(); | |
504 if (!focused->editor().canEdit() && !inputMethodController.hasComposition()) | |
505 return false; | |
506 | |
507 // We should verify the parent node of this IME composition node are | |
508 // editable because JavaScript may delete a parent node of the composition | |
509 // node. In this case, WebKit crashes while deleting texts from the parent | |
510 // node, which doesn't exist any longer. | |
511 const EphemeralRange range = | |
512 inputMethodController.compositionEphemeralRange(); | |
513 if (range.isNotNull()) { | |
514 Node* node = range.startPosition().computeContainerNode(); | |
515 focused->document()->updateStyleAndLayoutTree(); | |
516 if (!node || !hasEditableStyle(*node)) | |
517 return false; | |
518 } | |
519 | |
520 // A keypress event is canceled. If an ongoing composition exists, then the | |
521 // keydown event should have arisen from a handled key (e.g., backspace). | |
522 // In this case we ignore the cancellation and continue; otherwise (no | |
523 // ongoing composition) we exit and signal success only for attempts to | |
524 // clear the composition. | |
525 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition()) | |
526 return text.isEmpty(); | |
527 | |
528 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create( | |
529 focused->document(), UserGestureToken::NewGesture)); | |
530 | |
531 // When the range of composition underlines overlap with the range between | |
532 // selectionStart and selectionEnd, WebKit somehow won't paint the selection | |
533 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp). | |
534 // But the selection range actually takes effect. | |
535 inputMethodController.setComposition( | |
536 String(text), CompositionUnderlineVectorBuilder(underlines), | |
537 selectionStart, selectionEnd); | |
538 | |
539 return text.isEmpty() || inputMethodController.hasComposition(); | |
540 } | |
541 | |
542 // TODO(ekaramad):These methods are almost duplicated in WebViewImpl as well. | |
543 // This code needs to be refactored (http://crbug.com/629721). | |
544 bool WebFrameWidgetImpl::commitText(const WebString& text, | |
545 int relativeCaretPosition) { | |
546 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
547 if (!focused) | |
548 return false; | |
549 | |
550 UserGestureIndicator gestureIndicator(DocumentUserGestureToken::create( | |
551 focused->document(), UserGestureToken::NewGesture)); | |
552 | |
553 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
554 return plugin->commitText(text, relativeCaretPosition); | |
555 | |
556 return focused->inputMethodController().commitText(text, | |
557 relativeCaretPosition); | |
558 } | |
559 | |
560 bool WebFrameWidgetImpl::finishComposingText( | |
561 ConfirmCompositionBehavior selectionBehavior) { | |
562 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
563 if (!focused) | |
564 return false; | |
565 | |
566 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
567 return plugin->finishComposingText(selectionBehavior); | |
568 | |
569 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | |
570 // needs to be audited. See http://crbug.com/590369 for more details. | |
571 focused->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | |
572 | |
573 return focused->inputMethodController().finishComposingText( | |
574 selectionBehavior == KeepSelection | |
575 ? InputMethodController::KeepSelection | |
576 : InputMethodController::DoNotKeepSelection); | |
577 } | |
578 | |
579 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | |
580 // code needs to be refactored (http://crbug.com/629721). | |
581 WebRange WebFrameWidgetImpl::compositionRange() { | 493 WebRange WebFrameWidgetImpl::compositionRange() { |
582 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | 494 LocalFrame* focused = focusedLocalFrameAvailableForIme(); |
583 if (!focused) | 495 if (!focused) |
584 return WebRange(); | 496 return WebRange(); |
585 | 497 |
586 const EphemeralRange range = | 498 const EphemeralRange range = |
587 focused->inputMethodController().compositionEphemeralRange(); | 499 focused->inputMethodController().compositionEphemeralRange(); |
588 if (range.isNull()) | 500 if (range.isNull()) |
589 return WebRange(); | 501 return WebRange(); |
590 | 502 |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 return nullptr; | 1123 return nullptr; |
1212 } | 1124 } |
1213 | 1125 |
1214 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const { | 1126 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const { |
1215 if (!m_imeAcceptEvents) | 1127 if (!m_imeAcceptEvents) |
1216 return nullptr; | 1128 return nullptr; |
1217 return focusedLocalFrameInWidget(); | 1129 return focusedLocalFrameInWidget(); |
1218 } | 1130 } |
1219 | 1131 |
1220 } // namespace blink | 1132 } // namespace blink |
OLD | NEW |