| 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 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 void RenderWidget::UpdateVisualState() { | 918 void RenderWidget::UpdateVisualState() { |
| 919 GetWebWidget()->updateAllLifecyclePhases(); | 919 GetWebWidget()->updateAllLifecyclePhases(); |
| 920 } | 920 } |
| 921 | 921 |
| 922 void RenderWidget::WillBeginCompositorFrame() { | 922 void RenderWidget::WillBeginCompositorFrame() { |
| 923 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); | 923 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); |
| 924 | 924 |
| 925 // The UpdateTextInputState can result in further layout and possibly | 925 // The UpdateTextInputState can result in further layout and possibly |
| 926 // enable GPU acceleration so they need to be called before any painting | 926 // enable GPU acceleration so they need to be called before any painting |
| 927 // is done. | 927 // is done. |
| 928 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); | 928 UpdateTextInputState(ShowIme::DO_NOT_SHOW); |
| 929 UpdateSelectionBounds(); | 929 UpdateSelectionBounds(); |
| 930 | 930 |
| 931 for (auto& observer : render_frame_proxies_) | 931 for (auto& observer : render_frame_proxies_) |
| 932 observer.WillBeginCompositorFrame(); | 932 observer.WillBeginCompositorFrame(); |
| 933 } | 933 } |
| 934 | 934 |
| 935 std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest( | 935 std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest( |
| 936 std::unique_ptr<cc::CopyOutputRequest> request) { | 936 std::unique_ptr<cc::CopyOutputRequest> request) { |
| 937 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest( | 937 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest( |
| 938 routing_id_, std::move(request)); | 938 routing_id_, std::move(request)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 } | 1010 } |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { | 1013 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { |
| 1014 // Nothing to do here. RenderWidget created the |input_handler| and will take | 1014 // Nothing to do here. RenderWidget created the |input_handler| and will take |
| 1015 // ownership of it. We just verify here that we don't already have an input | 1015 // ownership of it. We just verify here that we don't already have an input |
| 1016 // handler. | 1016 // handler. |
| 1017 DCHECK(!input_handler_); | 1017 DCHECK(!input_handler_); |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 void RenderWidget::UpdateTextInputState(ShowIme show_ime, | 1020 void RenderWidget::UpdateTextInputState(ShowIme show_ime) { |
| 1021 ChangeSource change_source) { | 1021 UpdateTextInputStateInternal(show_ime, false); |
| 1022 } |
| 1023 |
| 1024 void RenderWidget::UpdateTextInputStateInternal(ShowIme show_ime, |
| 1025 bool reply_to_request) { |
| 1022 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); | 1026 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); |
| 1027 |
| 1023 if (ime_event_guard_) { | 1028 if (ime_event_guard_) { |
| 1029 DCHECK(!reply_to_request); |
| 1024 // show_ime should still be effective even if it was set inside the IME | 1030 // show_ime should still be effective even if it was set inside the IME |
| 1025 // event guard. | 1031 // event guard. |
| 1026 if (show_ime == ShowIme::IF_NEEDED) { | 1032 if (show_ime == ShowIme::IF_NEEDED) { |
| 1027 ime_event_guard_->set_show_ime(true); | 1033 ime_event_guard_->set_show_ime(true); |
| 1028 } | 1034 } |
| 1029 return; | 1035 return; |
| 1030 } | 1036 } |
| 1031 | 1037 |
| 1032 ui::TextInputType new_type = GetTextInputType(); | 1038 ui::TextInputType new_type = GetTextInputType(); |
| 1033 if (IsDateTimeInput(new_type)) | 1039 if (IsDateTimeInput(new_type)) |
| 1034 return; // Not considered as a text input field in WebKit/Chromium. | 1040 return; // Not considered as a text input field in WebKit/Chromium. |
| 1035 | 1041 |
| 1036 blink::WebTextInputInfo new_info; | 1042 blink::WebTextInputInfo new_info; |
| 1037 if (GetWebWidget()) | 1043 if (GetWebWidget()) |
| 1038 new_info = GetWebWidget()->textInputInfo(); | 1044 new_info = GetWebWidget()->textInputInfo(); |
| 1039 const ui::TextInputMode new_mode = | 1045 const ui::TextInputMode new_mode = |
| 1040 ConvertWebTextInputMode(new_info.inputMode); | 1046 ConvertWebTextInputMode(new_info.inputMode); |
| 1041 | 1047 |
| 1042 bool new_can_compose_inline = CanComposeInline(); | 1048 bool new_can_compose_inline = CanComposeInline(); |
| 1043 | 1049 |
| 1044 // Only sends text input params if they are changed or if the ime should be | 1050 // Only sends text input params if they are changed or if the ime should be |
| 1045 // shown. | 1051 // shown. |
| 1046 if (show_ime == ShowIme::IF_NEEDED || | 1052 if (show_ime == ShowIme::IF_NEEDED || reply_to_request || |
| 1047 change_source == ChangeSource::FROM_IME || | |
| 1048 text_input_type_ != new_type || text_input_mode_ != new_mode || | 1053 text_input_type_ != new_type || text_input_mode_ != new_mode || |
| 1049 text_input_info_ != new_info || | 1054 text_input_info_ != new_info || |
| 1050 can_compose_inline_ != new_can_compose_inline) { | 1055 can_compose_inline_ != new_can_compose_inline) { |
| 1051 TextInputState params; | 1056 TextInputState params; |
| 1052 params.type = new_type; | 1057 params.type = new_type; |
| 1053 params.mode = new_mode; | 1058 params.mode = new_mode; |
| 1054 params.flags = new_info.flags; | 1059 params.flags = new_info.flags; |
| 1055 params.value = new_info.value.utf8(); | 1060 params.value = new_info.value.utf8(); |
| 1056 params.selection_start = new_info.selectionStart; | 1061 params.selection_start = new_info.selectionStart; |
| 1057 params.selection_end = new_info.selectionEnd; | 1062 params.selection_end = new_info.selectionEnd; |
| 1058 params.composition_start = new_info.compositionStart; | 1063 params.composition_start = new_info.compositionStart; |
| 1059 params.composition_end = new_info.compositionEnd; | 1064 params.composition_end = new_info.compositionEnd; |
| 1060 params.can_compose_inline = new_can_compose_inline; | 1065 params.can_compose_inline = new_can_compose_inline; |
| 1061 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); | 1066 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); |
| 1062 #if defined(OS_ANDROID) || defined(USE_AURA) | 1067 params.reply_to_request = reply_to_request; |
| 1063 params.is_non_ime_change = (change_source == ChangeSource::FROM_NON_IME); | |
| 1064 #endif | |
| 1065 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); | 1068 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); |
| 1066 | 1069 |
| 1067 text_input_info_ = new_info; | 1070 text_input_info_ = new_info; |
| 1068 text_input_type_ = new_type; | 1071 text_input_type_ = new_type; |
| 1069 text_input_mode_ = new_mode; | 1072 text_input_mode_ = new_mode; |
| 1070 can_compose_inline_ = new_can_compose_inline; | 1073 can_compose_inline_ = new_can_compose_inline; |
| 1071 text_input_flags_ = new_info.flags; | 1074 text_input_flags_ = new_info.flags; |
| 1072 } | 1075 } |
| 1073 } | 1076 } |
| 1074 | 1077 |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1706 } | 1709 } |
| 1707 | 1710 |
| 1708 void RenderWidget::OnDragSourceSystemDragEnded() { | 1711 void RenderWidget::OnDragSourceSystemDragEnded() { |
| 1709 if (!GetWebWidget()) | 1712 if (!GetWebWidget()) |
| 1710 return; | 1713 return; |
| 1711 | 1714 |
| 1712 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceSystemDragEnded(); | 1715 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceSystemDragEnded(); |
| 1713 } | 1716 } |
| 1714 | 1717 |
| 1715 void RenderWidget::showImeIfNeeded() { | 1718 void RenderWidget::showImeIfNeeded() { |
| 1716 #if defined(OS_ANDROID) || defined(USE_AURA) | 1719 UpdateTextInputState(ShowIme::IF_NEEDED); |
| 1717 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); | |
| 1718 #endif | |
| 1719 | 1720 |
| 1720 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with | 1721 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with |
| 1721 // virtual keyboard. | 1722 // virtual keyboard. |
| 1722 #if !defined(OS_ANDROID) | 1723 #if !defined(OS_ANDROID) |
| 1723 FocusChangeComplete(); | 1724 FocusChangeComplete(); |
| 1724 #endif | 1725 #endif |
| 1725 } | 1726 } |
| 1726 | 1727 |
| 1727 ui::TextInputType RenderWidget::GetTextInputType() { | 1728 ui::TextInputType RenderWidget::GetTextInputType() { |
| 1728 #if BUILDFLAG(ENABLE_PLUGINS) | 1729 #if BUILDFLAG(ENABLE_PLUGINS) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 rect->y *= GetOriginalDeviceScaleFactor(); | 1781 rect->y *= GetOriginalDeviceScaleFactor(); |
| 1781 rect->width *= GetOriginalDeviceScaleFactor(); | 1782 rect->width *= GetOriginalDeviceScaleFactor(); |
| 1782 rect->height *= GetOriginalDeviceScaleFactor(); | 1783 rect->height *= GetOriginalDeviceScaleFactor(); |
| 1783 } | 1784 } |
| 1784 } | 1785 } |
| 1785 | 1786 |
| 1786 #if defined(OS_ANDROID) | 1787 #if defined(OS_ANDROID) |
| 1787 void RenderWidget::OnRequestTextInputStateUpdate() { | 1788 void RenderWidget::OnRequestTextInputStateUpdate() { |
| 1788 DCHECK(!ime_event_guard_); | 1789 DCHECK(!ime_event_guard_); |
| 1789 UpdateSelectionBounds(); | 1790 UpdateSelectionBounds(); |
| 1790 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); | 1791 UpdateTextInputStateInternal(ShowIme::DO_NOT_SHOW, |
| 1792 true /* reply_to_request */); |
| 1791 } | 1793 } |
| 1792 #endif | 1794 #endif |
| 1793 | 1795 |
| 1794 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request, | 1796 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request, |
| 1795 bool monitor_request) { | 1797 bool monitor_request) { |
| 1796 monitor_composition_info_ = monitor_request; | 1798 monitor_composition_info_ = monitor_request; |
| 1797 if (!immediate_request) | 1799 if (!immediate_request) |
| 1798 return; | 1800 return; |
| 1799 UpdateCompositionInfo(true /* immediate request */); | 1801 UpdateCompositionInfo(true /* immediate request */); |
| 1800 } | 1802 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1867 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; | 1869 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; |
| 1868 } | 1870 } |
| 1869 | 1871 |
| 1870 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { | 1872 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { |
| 1871 if (!ime_event_guard_) | 1873 if (!ime_event_guard_) |
| 1872 ime_event_guard_ = guard; | 1874 ime_event_guard_ = guard; |
| 1873 } | 1875 } |
| 1874 | 1876 |
| 1875 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { | 1877 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { |
| 1876 if (ime_event_guard_ != guard) { | 1878 if (ime_event_guard_ != guard) { |
| 1877 #if defined(OS_ANDROID) | 1879 DCHECK(!ime_event_guard_->reply_to_request()); |
| 1878 // In case a from-IME event (e.g. touch) ends up in not-from-IME event | |
| 1879 // (e.g. long press gesture), we want to treat it as not-from-IME event | |
| 1880 // so that ReplicaInputConnection can make changes to its Editable model. | |
| 1881 // Therefore, we want to mark this text state update as 'from IME' only | |
| 1882 // when all the nested events are all originating from IME. | |
| 1883 ime_event_guard_->set_from_ime( | |
| 1884 ime_event_guard_->from_ime() && guard->from_ime()); | |
| 1885 #endif | |
| 1886 return; | 1880 return; |
| 1887 } | 1881 } |
| 1888 ime_event_guard_ = nullptr; | 1882 ime_event_guard_ = nullptr; |
| 1889 | 1883 |
| 1890 // While handling an ime event, text input state and selection bounds updates | 1884 // While handling an ime event, text input state and selection bounds updates |
| 1891 // are ignored. These must explicitly be updated once finished handling the | 1885 // are ignored. These must explicitly be updated once finished handling the |
| 1892 // ime event. | 1886 // ime event. |
| 1893 UpdateSelectionBounds(); | 1887 UpdateSelectionBounds(); |
| 1894 #if defined(OS_ANDROID) | 1888 #if defined(OS_ANDROID) |
| 1895 UpdateTextInputState( | 1889 UpdateTextInputState(guard->show_ime() ? ShowIme::IF_NEEDED |
| 1896 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, | 1890 : ShowIme::DO_NOT_SHOW); |
| 1897 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); | |
| 1898 #endif | 1891 #endif |
| 1899 } | 1892 } |
| 1900 | 1893 |
| 1901 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { | 1894 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
| 1902 #if BUILDFLAG(ENABLE_PLUGINS) | 1895 #if BUILDFLAG(ENABLE_PLUGINS) |
| 1903 if (focused_pepper_plugin_) { | 1896 if (focused_pepper_plugin_) { |
| 1904 // TODO(kinaba) http://crbug.com/101101 | 1897 // TODO(kinaba) http://crbug.com/101101 |
| 1905 // Current Pepper IME API does not handle selection bounds. So we simply | 1898 // Current Pepper IME API does not handle selection bounds. So we simply |
| 1906 // use the caret position as an empty range for now. It will be updated | 1899 // use the caret position as an empty range for now. It will be updated |
| 1907 // after Pepper API equips features related to surrounding text retrieval. | 1900 // after Pepper API equips features related to surrounding text retrieval. |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2101 } | 2094 } |
| 2102 #endif | 2095 #endif |
| 2103 | 2096 |
| 2104 void RenderWidget::didHandleGestureEvent( | 2097 void RenderWidget::didHandleGestureEvent( |
| 2105 const WebGestureEvent& event, | 2098 const WebGestureEvent& event, |
| 2106 bool event_cancelled) { | 2099 bool event_cancelled) { |
| 2107 #if defined(OS_ANDROID) || defined(USE_AURA) | 2100 #if defined(OS_ANDROID) || defined(USE_AURA) |
| 2108 if (event_cancelled) | 2101 if (event_cancelled) |
| 2109 return; | 2102 return; |
| 2110 if (event.type == WebInputEvent::GestureTap) { | 2103 if (event.type == WebInputEvent::GestureTap) { |
| 2111 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); | 2104 UpdateTextInputState(ShowIme::IF_NEEDED); |
| 2112 } else if (event.type == WebInputEvent::GestureLongPress) { | 2105 } else if (event.type == WebInputEvent::GestureLongPress) { |
| 2113 DCHECK(GetWebWidget()); | 2106 DCHECK(GetWebWidget()); |
| 2114 if (GetWebWidget()->textInputInfo().value.isEmpty()) | 2107 if (GetWebWidget()->textInputInfo().value.isEmpty()) |
| 2115 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); | 2108 UpdateTextInputState(ShowIme::DO_NOT_SHOW); |
| 2116 else | 2109 else |
| 2117 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); | 2110 UpdateTextInputState(ShowIme::IF_NEEDED); |
| 2118 } | 2111 } |
| 2119 // TODO(ananta): Piggyback off existing IPCs to communicate this information, | 2112 // TODO(ananta): Piggyback off existing IPCs to communicate this information, |
| 2120 // crbug/420130. | 2113 // crbug/420130. |
| 2121 #if defined(OS_WIN) | 2114 #if defined(OS_WIN) |
| 2122 if (event.type != blink::WebGestureEvent::GestureTap) | 2115 if (event.type != blink::WebGestureEvent::GestureTap) |
| 2123 return; | 2116 return; |
| 2124 | 2117 |
| 2125 // TODO(estade): hit test the event against focused node to make sure | 2118 // TODO(estade): hit test the event against focused node to make sure |
| 2126 // the tap actually hit the focused node. | 2119 // the tap actually hit the focused node. |
| 2127 blink::WebTextInputType text_input_type = GetWebWidget()->textInputType(); | 2120 blink::WebTextInputType text_input_type = GetWebWidget()->textInputType(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2255 // browser side (https://crbug.com/669219). | 2248 // browser side (https://crbug.com/669219). |
| 2256 // If there is no WebFrameWidget, then there will be no | 2249 // If there is no WebFrameWidget, then there will be no |
| 2257 // InputMethodControllers for a WebLocalFrame. | 2250 // InputMethodControllers for a WebLocalFrame. |
| 2258 return nullptr; | 2251 return nullptr; |
| 2259 } | 2252 } |
| 2260 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | 2253 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
| 2261 ->getActiveWebInputMethodController(); | 2254 ->getActiveWebInputMethodController(); |
| 2262 } | 2255 } |
| 2263 | 2256 |
| 2264 } // namespace content | 2257 } // namespace content |
| OLD | NEW |