Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 890 | 890 |
| 891 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { | 891 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { |
| 892 // Nothing to do here. RenderWidget created the |input_handler| and will take | 892 // Nothing to do here. RenderWidget created the |input_handler| and will take |
| 893 // ownership of it. We just verify here that we don't already have an input | 893 // ownership of it. We just verify here that we don't already have an input |
| 894 // handler. | 894 // handler. |
| 895 DCHECK(!input_handler_); | 895 DCHECK(!input_handler_); |
| 896 } | 896 } |
| 897 | 897 |
| 898 void RenderWidget::UpdateTextInputState(ShowIme show_ime, | 898 void RenderWidget::UpdateTextInputState(ShowIme show_ime, |
| 899 ChangeSource change_source) { | 899 ChangeSource change_source) { |
| 900 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); | 900 UpdateTextInputStateInternal(show_ime, change_source, false); |
| 901 if (ime_event_guard_) { | |
| 902 // show_ime should still be effective even if it was set inside the IME | |
| 903 // event guard. | |
| 904 if (show_ime == ShowIme::IF_NEEDED) { | |
| 905 ime_event_guard_->set_show_ime(true); | |
| 906 } | |
| 907 return; | |
| 908 } | |
| 909 | |
| 910 ui::TextInputType new_type = GetTextInputType(); | |
| 911 if (IsDateTimeInput(new_type)) | |
| 912 return; // Not considered as a text input field in WebKit/Chromium. | |
| 913 | |
| 914 blink::WebTextInputInfo new_info; | |
| 915 if (GetWebWidget()) | |
| 916 new_info = GetWebWidget()->textInputInfo(); | |
| 917 const ui::TextInputMode new_mode = | |
| 918 ConvertWebTextInputMode(new_info.inputMode); | |
| 919 | |
| 920 bool new_can_compose_inline = CanComposeInline(); | |
| 921 | |
| 922 // Only sends text input params if they are changed or if the ime should be | |
| 923 // shown. | |
| 924 if (show_ime == ShowIme::IF_NEEDED || | |
| 925 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || | |
| 926 (text_input_type_ != new_type || text_input_mode_ != new_mode || | |
| 927 text_input_info_ != new_info || | |
| 928 can_compose_inline_ != new_can_compose_inline) | |
| 929 #if defined(OS_ANDROID) | |
| 930 || text_field_is_dirty_ | |
| 931 #endif | |
| 932 ) { | |
| 933 TextInputState params; | |
| 934 params.type = new_type; | |
| 935 params.mode = new_mode; | |
| 936 params.flags = new_info.flags; | |
| 937 params.value = new_info.value.utf8(); | |
| 938 params.selection_start = new_info.selectionStart; | |
| 939 params.selection_end = new_info.selectionEnd; | |
| 940 params.composition_start = new_info.compositionStart; | |
| 941 params.composition_end = new_info.compositionEnd; | |
| 942 params.can_compose_inline = new_can_compose_inline; | |
| 943 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); | |
| 944 #if defined(USE_AURA) | |
| 945 params.is_non_ime_change = true; | |
| 946 #endif | |
| 947 #if defined(OS_ANDROID) | |
| 948 params.is_non_ime_change = | |
| 949 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_; | |
| 950 params.batch_edit = ime_in_batch_edit_; | |
| 951 if (params.is_non_ime_change) | |
| 952 OnImeEventSentForAck(new_info); | |
| 953 text_field_is_dirty_ = false; | |
| 954 #endif | |
| 955 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); | |
| 956 | |
| 957 text_input_info_ = new_info; | |
| 958 text_input_type_ = new_type; | |
| 959 text_input_mode_ = new_mode; | |
| 960 can_compose_inline_ = new_can_compose_inline; | |
| 961 text_input_flags_ = new_info.flags; | |
| 962 } | |
| 963 } | 901 } |
| 964 | 902 |
| 965 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) { | 903 bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) { |
| 966 if (owner_delegate_) | 904 if (owner_delegate_) |
| 967 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event); | 905 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event); |
| 968 | 906 |
| 969 return false; | 907 return false; |
| 970 } | 908 } |
| 971 | 909 |
| 972 bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) { | 910 bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) { |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1610 } | 1548 } |
| 1611 | 1549 |
| 1612 void RenderWidget::OnImeBatchEdit(bool begin) { | 1550 void RenderWidget::OnImeBatchEdit(bool begin) { |
| 1613 if (begin) { | 1551 if (begin) { |
| 1614 ime_in_batch_edit_ = true; | 1552 ime_in_batch_edit_ = true; |
| 1615 return; | 1553 return; |
| 1616 } | 1554 } |
| 1617 if (!ime_in_batch_edit_) | 1555 if (!ime_in_batch_edit_) |
| 1618 return; | 1556 return; |
| 1619 ime_in_batch_edit_ = false; | 1557 ime_in_batch_edit_ = false; |
| 1558 | |
| 1620 DCHECK(!ime_event_guard_); | 1559 DCHECK(!ime_event_guard_); |
| 1621 UpdateSelectionBounds(); | 1560 UpdateSelectionBounds(); |
| 1622 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); | 1561 |
| 1562 // Make sure that we do the state update here because the previous state | |
| 1563 // updates in batch edit got ignored. | |
| 1564 ForceUpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); | |
| 1623 } | 1565 } |
| 1624 #endif | 1566 #endif |
| 1625 | 1567 |
| 1568 void RenderWidget::ForceUpdateTextInputState(ShowIme show_ime, | |
| 1569 ChangeSource change_source) { | |
| 1570 UpdateTextInputStateInternal(show_ime, change_source, true); | |
| 1571 } | |
| 1572 | |
| 1573 void RenderWidget::UpdateTextInputStateInternal(ShowIme show_ime, | |
|
aelias_OOO_until_Jul13
2016/11/01 23:37:30
Could you move this above RenderWidget::UpdateText
| |
| 1574 ChangeSource change_source, | |
| 1575 bool force_update) { | |
|
aelias_OOO_until_Jul13
2016/11/01 23:37:30
I don't think we should add this argument. It's m
| |
| 1576 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); | |
| 1577 if (ime_event_guard_) { | |
| 1578 // show_ime should still be effective even if it was set inside the IME | |
| 1579 // event guard. | |
| 1580 if (show_ime == ShowIme::IF_NEEDED) { | |
| 1581 ime_event_guard_->set_show_ime(true); | |
| 1582 } | |
| 1583 return; | |
| 1584 } | |
| 1585 | |
| 1586 ui::TextInputType new_type = GetTextInputType(); | |
| 1587 if (IsDateTimeInput(new_type)) | |
| 1588 return; // Not considered as a text input field in WebKit/Chromium. | |
| 1589 | |
| 1590 blink::WebTextInputInfo new_info; | |
| 1591 if (GetWebWidget()) | |
| 1592 new_info = GetWebWidget()->textInputInfo(); | |
| 1593 const ui::TextInputMode new_mode = | |
| 1594 ConvertWebTextInputMode(new_info.inputMode); | |
| 1595 | |
| 1596 bool new_can_compose_inline = CanComposeInline(); | |
| 1597 | |
| 1598 // Only sends text input params if they are changed or if the ime should be | |
| 1599 // shown. | |
| 1600 if (show_ime == ShowIme::IF_NEEDED || | |
| 1601 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || | |
| 1602 (text_input_type_ != new_type || text_input_mode_ != new_mode || | |
| 1603 text_input_info_ != new_info || | |
| 1604 can_compose_inline_ != new_can_compose_inline || force_update) | |
| 1605 #if defined(OS_ANDROID) | |
| 1606 || text_field_is_dirty_ | |
| 1607 #endif | |
| 1608 ) { | |
| 1609 TextInputState params; | |
|
aelias_OOO_until_Jul13
2016/11/01 23:37:30
Please put an early return like in your previous p
| |
| 1610 params.type = new_type; | |
| 1611 params.mode = new_mode; | |
| 1612 params.flags = new_info.flags; | |
| 1613 params.value = new_info.value.utf8(); | |
| 1614 params.selection_start = new_info.selectionStart; | |
| 1615 params.selection_end = new_info.selectionEnd; | |
| 1616 params.composition_start = new_info.compositionStart; | |
| 1617 params.composition_end = new_info.compositionEnd; | |
| 1618 params.can_compose_inline = new_can_compose_inline; | |
| 1619 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); | |
| 1620 #if defined(USE_AURA) | |
| 1621 params.is_non_ime_change = true; | |
| 1622 #endif | |
| 1623 #if defined(OS_ANDROID) | |
| 1624 params.is_non_ime_change = | |
| 1625 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_; | |
| 1626 params.batch_edit = ime_in_batch_edit_; | |
| 1627 if (params.is_non_ime_change) | |
| 1628 OnImeEventSentForAck(new_info); | |
| 1629 text_field_is_dirty_ = false; | |
| 1630 #endif | |
| 1631 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); | |
| 1632 | |
| 1633 text_input_info_ = new_info; | |
| 1634 text_input_type_ = new_type; | |
| 1635 text_input_mode_ = new_mode; | |
| 1636 can_compose_inline_ = new_can_compose_inline; | |
| 1637 text_input_flags_ = new_info.flags; | |
| 1638 } | |
| 1639 } | |
| 1640 | |
| 1626 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request, | 1641 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request, |
| 1627 bool monitor_request) { | 1642 bool monitor_request) { |
| 1628 monitor_composition_info_ = monitor_request; | 1643 monitor_composition_info_ = monitor_request; |
| 1629 if (!immediate_request) | 1644 if (!immediate_request) |
| 1630 return; | 1645 return; |
| 1631 UpdateCompositionInfo(true /* immediate request */); | 1646 UpdateCompositionInfo(true /* immediate request */); |
| 1632 } | 1647 } |
| 1633 | 1648 |
| 1634 bool RenderWidget::ShouldHandleImeEvent() { | 1649 bool RenderWidget::ShouldHandleImeEvent() { |
| 1635 #if defined(OS_ANDROID) | 1650 #if defined(OS_ANDROID) |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2088 bool RenderWidget::isPointerLocked() { | 2103 bool RenderWidget::isPointerLocked() { |
| 2089 return mouse_lock_dispatcher_->IsMouseLockedTo( | 2104 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2090 webwidget_mouse_lock_target_.get()); | 2105 webwidget_mouse_lock_target_.get()); |
| 2091 } | 2106 } |
| 2092 | 2107 |
| 2093 blink::WebWidget* RenderWidget::GetWebWidget() const { | 2108 blink::WebWidget* RenderWidget::GetWebWidget() const { |
| 2094 return webwidget_internal_; | 2109 return webwidget_internal_; |
| 2095 } | 2110 } |
| 2096 | 2111 |
| 2097 } // namespace content | 2112 } // namespace content |
| OLD | NEW |