| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "public/web/WebAutofillClient.h" | 57 #include "public/web/WebAutofillClient.h" |
| 58 #include "public/web/WebPlugin.h" | 58 #include "public/web/WebPlugin.h" |
| 59 #include "public/web/WebRange.h" | 59 #include "public/web/WebRange.h" |
| 60 #include "public/web/WebWidgetClient.h" | 60 #include "public/web/WebWidgetClient.h" |
| 61 #include "web/CompositionUnderlineVectorBuilder.h" | 61 #include "web/CompositionUnderlineVectorBuilder.h" |
| 62 #include "web/CompositorMutatorImpl.h" | 62 #include "web/CompositorMutatorImpl.h" |
| 63 #include "web/CompositorProxyClientImpl.h" | 63 #include "web/CompositorProxyClientImpl.h" |
| 64 #include "web/ContextMenuAllowedScope.h" | 64 #include "web/ContextMenuAllowedScope.h" |
| 65 #include "web/WebDevToolsAgentImpl.h" | 65 #include "web/WebDevToolsAgentImpl.h" |
| 66 #include "web/WebInputEventConversion.h" | 66 #include "web/WebInputEventConversion.h" |
| 67 #include "web/WebInputMethodControllerImpl.h" |
| 67 #include "web/WebLocalFrameImpl.h" | 68 #include "web/WebLocalFrameImpl.h" |
| 68 #include "web/WebPluginContainerImpl.h" | 69 #include "web/WebPluginContainerImpl.h" |
| 69 #include "web/WebRemoteFrameImpl.h" | 70 #include "web/WebRemoteFrameImpl.h" |
| 70 #include "web/WebViewFrameWidget.h" | 71 #include "web/WebViewFrameWidget.h" |
| 71 #include "wtf/AutoReset.h" | 72 #include "wtf/AutoReset.h" |
| 72 #include "wtf/PtrUtil.h" | 73 #include "wtf/PtrUtil.h" |
| 73 #include <memory> | 74 #include <memory> |
| 74 | 75 |
| 75 namespace blink { | 76 namespace blink { |
| 76 | 77 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) | 401 void WebFrameWidgetImpl::setBaseBackgroundColor(WebColor color) |
| 401 { | 402 { |
| 402 if (m_baseBackgroundColor == color) | 403 if (m_baseBackgroundColor == color) |
| 403 return; | 404 return; |
| 404 | 405 |
| 405 m_baseBackgroundColor = color; | 406 m_baseBackgroundColor = color; |
| 406 | 407 |
| 407 m_localRoot->frameView()->setBaseBackgroundColor(color); | 408 m_localRoot->frameView()->setBaseBackgroundColor(color); |
| 408 } | 409 } |
| 409 | 410 |
| 411 WebInputMethodControllerImpl* WebFrameWidgetImpl::getActiveWebInputMethodControl
ler() const |
| 412 { |
| 413 return WebInputMethodControllerImpl::fromFrame(focusedLocalFrameAvailableFor
Ime()); |
| 414 } |
| 415 |
| 410 void WebFrameWidgetImpl::scheduleAnimation() | 416 void WebFrameWidgetImpl::scheduleAnimation() |
| 411 { | 417 { |
| 412 if (m_layerTreeView) { | 418 if (m_layerTreeView) { |
| 413 m_layerTreeView->setNeedsBeginFrame(); | 419 m_layerTreeView->setNeedsBeginFrame(); |
| 414 return; | 420 return; |
| 415 } | 421 } |
| 416 if (m_client) | 422 if (m_client) |
| 417 m_client->scheduleAnimation(); | 423 m_client->scheduleAnimation(); |
| 418 } | 424 } |
| 419 | 425 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 } | 499 } |
| 494 | 500 |
| 495 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | 501 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This |
| 496 // code needs to be refactored (http://crbug.com/629721). | 502 // code needs to be refactored (http://crbug.com/629721). |
| 497 bool WebFrameWidgetImpl::setComposition( | 503 bool WebFrameWidgetImpl::setComposition( |
| 498 const WebString& text, | 504 const WebString& text, |
| 499 const WebVector<WebCompositionUnderline>& underlines, | 505 const WebVector<WebCompositionUnderline>& underlines, |
| 500 int selectionStart, | 506 int selectionStart, |
| 501 int selectionEnd) | 507 int selectionEnd) |
| 502 { | 508 { |
| 503 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | 509 if (!getActiveWebInputMethodController()) |
| 504 if (!focused) | |
| 505 return false; | 510 return false; |
| 506 | 511 return getActiveWebInputMethodController()->setComposition(text, underlines,
selectionStart, selectionEnd); |
| 507 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
| 508 return plugin->setComposition(text, underlines, selectionStart, selectio
nEnd); | |
| 509 | |
| 510 // The input focus has been moved to another WebWidget object. | |
| 511 // We should use this |editor| object only to complete the ongoing | |
| 512 // composition. | |
| 513 InputMethodController& inputMethodController = focused->inputMethodControlle
r(); | |
| 514 if (!focused->editor().canEdit() && !inputMethodController.hasComposition()) | |
| 515 return false; | |
| 516 | |
| 517 // We should verify the parent node of this IME composition node are | |
| 518 // editable because JavaScript may delete a parent node of the composition | |
| 519 // node. In this case, WebKit crashes while deleting texts from the parent | |
| 520 // node, which doesn't exist any longer. | |
| 521 const EphemeralRange range = inputMethodController.compositionEphemeralRange
(); | |
| 522 if (range.isNotNull()) { | |
| 523 Node* node = range.startPosition().computeContainerNode(); | |
| 524 focused->document()->updateStyleAndLayoutTree(); | |
| 525 if (!node || !hasEditableStyle(*node)) | |
| 526 return false; | |
| 527 } | |
| 528 | |
| 529 // A keypress event is canceled. If an ongoing composition exists, then the | |
| 530 // keydown event should have arisen from a handled key (e.g., backspace). | |
| 531 // In this case we ignore the cancellation and continue; otherwise (no | |
| 532 // ongoing composition) we exit and signal success only for attempts to | |
| 533 // clear the composition. | |
| 534 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition()) | |
| 535 return text.isEmpty(); | |
| 536 | |
| 537 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | |
| 538 | |
| 539 // When the range of composition underlines overlap with the range between | |
| 540 // selectionStart and selectionEnd, WebKit somehow won't paint the selection | |
| 541 // at all (see InlineTextBox::paint() function in InlineTextBox.cpp). | |
| 542 // But the selection range actually takes effect. | |
| 543 inputMethodController.setComposition(String(text), | |
| 544 CompositionUnderlineVectorBuilder(underlines), | |
| 545 selectionStart, selectionEnd); | |
| 546 | |
| 547 return text.isEmpty() || inputMethodController.hasComposition(); | |
| 548 } | 512 } |
| 549 | 513 |
| 550 // TODO(ekaramad):These methods are almost duplicated in WebViewImpl as well. | 514 // TODO(ekaramad):These methods are almost duplicated in WebViewImpl as well. |
| 551 // This code needs to be refactored (http://crbug.com/629721). | 515 // This code needs to be refactored (http://crbug.com/629721). |
| 552 bool WebFrameWidgetImpl::commitText(const WebString& text, int relativeCaretPosi
tion) | 516 bool WebFrameWidgetImpl::commitText(const WebString& text, int relativeCaretPosi
tion) |
| 553 { | 517 { |
| 554 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 518 if (!getActiveWebInputMethodController()) |
| 555 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | |
| 556 if (!focused) | |
| 557 return false; | 519 return false; |
| 558 | 520 return getActiveWebInputMethodController()->commitText(text, relativeCaretPo
sition); |
| 559 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
| 560 return plugin->commitText(text, relativeCaretPosition); | |
| 561 | |
| 562 return focused->inputMethodController().commitText(text, relativeCaretPositi
on); | |
| 563 } | 521 } |
| 564 | 522 |
| 523 // TODO(ekaramad):These methods are almost duplicated in WebViewImpl as well. |
| 524 // This code needs to be refactored (http://crbug.com/629721). |
| 565 bool WebFrameWidgetImpl::finishComposingText(ConfirmCompositionBehavior selectio
nBehavior) | 525 bool WebFrameWidgetImpl::finishComposingText(ConfirmCompositionBehavior selectio
nBehavior) |
| 566 { | 526 { |
| 567 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | 527 if (!getActiveWebInputMethodController()) |
| 568 if (!focused) | |
| 569 return false; | 528 return false; |
| 570 | 529 return getActiveWebInputMethodController()->finishComposingText(selectionBeh
avior); |
| 571 if (WebPlugin* plugin = focusedPluginIfInputMethodSupported(focused)) | |
| 572 return plugin->finishComposingText(selectionBehavior); | |
| 573 | |
| 574 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | |
| 575 // needs to be audited. See http://crbug.com/590369 for more details. | |
| 576 focused->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 577 | |
| 578 return focused->inputMethodController().finishComposingText(selectionBehavio
r == KeepSelection ? InputMethodController::KeepSelection : InputMethodControlle
r::DoNotKeepSelection); | |
| 579 } | 530 } |
| 580 | 531 |
| 581 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This | 532 // TODO(ekaramad):This method is almost duplicated in WebViewImpl as well. This |
| 582 // code needs to be refactored (http://crbug.com/629721). | 533 // code needs to be refactored (http://crbug.com/629721). |
| 583 WebRange WebFrameWidgetImpl::compositionRange() | 534 WebRange WebFrameWidgetImpl::compositionRange() |
| 584 { | 535 { |
| 585 LocalFrame* focused = focusedLocalFrameAvailableForIme(); | 536 LocalFrame* focused = focusedLocalFrameAvailableForIme(); |
| 586 if (!focused) | 537 if (!focused) |
| 587 return WebRange(); | 538 return WebRange(); |
| 588 | 539 |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 } | 1429 } |
| 1479 | 1430 |
| 1480 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const | 1431 LocalFrame* WebFrameWidgetImpl::focusedLocalFrameAvailableForIme() const |
| 1481 { | 1432 { |
| 1482 if (!m_imeAcceptEvents) | 1433 if (!m_imeAcceptEvents) |
| 1483 return nullptr; | 1434 return nullptr; |
| 1484 return focusedLocalFrameInWidget(); | 1435 return focusedLocalFrameInWidget(); |
| 1485 } | 1436 } |
| 1486 | 1437 |
| 1487 } // namespace blink | 1438 } // namespace blink |
| OLD | NEW |