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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 owner_delegate_(nullptr), | 354 owner_delegate_(nullptr), |
| 355 next_paint_flags_(0), | 355 next_paint_flags_(0), |
| 356 auto_resize_mode_(false), | 356 auto_resize_mode_(false), |
| 357 need_update_rect_for_auto_resize_(false), | 357 need_update_rect_for_auto_resize_(false), |
| 358 did_show_(false), | 358 did_show_(false), |
| 359 is_hidden_(hidden), | 359 is_hidden_(hidden), |
| 360 compositor_never_visible_(never_visible), | 360 compositor_never_visible_(never_visible), |
| 361 is_fullscreen_granted_(false), | 361 is_fullscreen_granted_(false), |
| 362 display_mode_(blink::WebDisplayModeUndefined), | 362 display_mode_(blink::WebDisplayModeUndefined), |
| 363 ime_event_guard_(nullptr), | 363 ime_event_guard_(nullptr), |
| 364 ime_requested_update_(false), | |
| 364 closing_(false), | 365 closing_(false), |
| 365 host_closing_(false), | 366 host_closing_(false), |
| 366 is_swapped_out_(swapped_out), | 367 is_swapped_out_(swapped_out), |
| 367 for_oopif_(false), | 368 for_oopif_(false), |
| 368 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 369 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 369 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 370 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
| 370 text_input_flags_(0), | 371 text_input_flags_(0), |
| 371 can_compose_inline_(true), | 372 can_compose_inline_(true), |
| 372 composition_range_(gfx::Range::InvalidRange()), | 373 composition_range_(gfx::Range::InvalidRange()), |
| 373 popup_type_(popup_type), | 374 popup_type_(popup_type), |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 917 void RenderWidget::UpdateVisualState() { | 918 void RenderWidget::UpdateVisualState() { |
| 918 GetWebWidget()->updateAllLifecyclePhases(); | 919 GetWebWidget()->updateAllLifecyclePhases(); |
| 919 } | 920 } |
| 920 | 921 |
| 921 void RenderWidget::WillBeginCompositorFrame() { | 922 void RenderWidget::WillBeginCompositorFrame() { |
| 922 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); | 923 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); |
| 923 | 924 |
| 924 // The UpdateTextInputState can result in further layout and possibly | 925 // The UpdateTextInputState can result in further layout and possibly |
| 925 // 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 |
| 926 // is done. | 927 // is done. |
| 927 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); | 928 UpdateTextInputState(ShowIme::DO_NOT_SHOW); |
| 928 UpdateSelectionBounds(); | 929 UpdateSelectionBounds(); |
| 929 | 930 |
| 930 for (auto& observer : render_frame_proxies_) | 931 for (auto& observer : render_frame_proxies_) |
| 931 observer.WillBeginCompositorFrame(); | 932 observer.WillBeginCompositorFrame(); |
| 932 } | 933 } |
| 933 | 934 |
| 934 std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest( | 935 std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest( |
| 935 std::unique_ptr<cc::CopyOutputRequest> request) { | 936 std::unique_ptr<cc::CopyOutputRequest> request) { |
| 936 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest( | 937 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest( |
| 937 routing_id_, std::move(request)); | 938 routing_id_, std::move(request)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1009 } | 1010 } |
| 1010 } | 1011 } |
| 1011 | 1012 |
| 1012 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { | 1013 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { |
| 1013 // 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 |
| 1014 // 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 |
| 1015 // handler. | 1016 // handler. |
| 1016 DCHECK(!input_handler_); | 1017 DCHECK(!input_handler_); |
| 1017 } | 1018 } |
| 1018 | 1019 |
| 1019 void RenderWidget::UpdateTextInputState(ShowIme show_ime, | 1020 void RenderWidget::UpdateTextInputState(ShowIme show_ime) { |
| 1020 ChangeSource change_source) { | |
| 1021 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); | 1021 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); |
| 1022 bool update_requested = ime_requested_update_; | |
|
aelias_OOO_until_Jul13
2017/01/04 00:59:51
I don't think we should use a member variable to e
Changwan Ryu
2017/01/04 06:43:46
Sounds like a good idea. Changed it to UpdateTextI
| |
| 1023 ime_requested_update_ = false; | |
| 1024 | |
| 1022 if (ime_event_guard_) { | 1025 if (ime_event_guard_) { |
| 1026 DCHECK(!update_requested); | |
| 1023 // show_ime should still be effective even if it was set inside the IME | 1027 // show_ime should still be effective even if it was set inside the IME |
| 1024 // event guard. | 1028 // event guard. |
| 1025 if (show_ime == ShowIme::IF_NEEDED) { | 1029 if (show_ime == ShowIme::IF_NEEDED) { |
| 1026 ime_event_guard_->set_show_ime(true); | 1030 ime_event_guard_->set_show_ime(true); |
| 1027 } | 1031 } |
| 1028 return; | 1032 return; |
| 1029 } | 1033 } |
| 1030 | 1034 |
| 1031 ui::TextInputType new_type = GetTextInputType(); | 1035 ui::TextInputType new_type = GetTextInputType(); |
| 1032 if (IsDateTimeInput(new_type)) | 1036 if (IsDateTimeInput(new_type)) |
| 1033 return; // Not considered as a text input field in WebKit/Chromium. | 1037 return; // Not considered as a text input field in WebKit/Chromium. |
| 1034 | 1038 |
| 1035 blink::WebTextInputInfo new_info; | 1039 blink::WebTextInputInfo new_info; |
| 1036 if (GetWebWidget()) | 1040 if (GetWebWidget()) |
| 1037 new_info = GetWebWidget()->textInputInfo(); | 1041 new_info = GetWebWidget()->textInputInfo(); |
| 1038 const ui::TextInputMode new_mode = | 1042 const ui::TextInputMode new_mode = |
| 1039 ConvertWebTextInputMode(new_info.inputMode); | 1043 ConvertWebTextInputMode(new_info.inputMode); |
| 1040 | 1044 |
| 1041 bool new_can_compose_inline = CanComposeInline(); | 1045 bool new_can_compose_inline = CanComposeInline(); |
| 1042 | 1046 |
| 1043 // Only sends text input params if they are changed or if the ime should be | 1047 // Only sends text input params if they are changed or if the ime should be |
| 1044 // shown. | 1048 // shown. |
| 1045 if (show_ime == ShowIme::IF_NEEDED || | 1049 if (show_ime == ShowIme::IF_NEEDED || update_requested || |
| 1046 change_source == ChangeSource::FROM_IME || | |
| 1047 text_input_type_ != new_type || text_input_mode_ != new_mode || | 1050 text_input_type_ != new_type || text_input_mode_ != new_mode || |
| 1048 text_input_info_ != new_info || | 1051 text_input_info_ != new_info || |
| 1049 can_compose_inline_ != new_can_compose_inline) { | 1052 can_compose_inline_ != new_can_compose_inline) { |
| 1050 TextInputState params; | 1053 TextInputState params; |
| 1051 params.type = new_type; | 1054 params.type = new_type; |
| 1052 params.mode = new_mode; | 1055 params.mode = new_mode; |
| 1053 params.flags = new_info.flags; | 1056 params.flags = new_info.flags; |
| 1054 params.value = new_info.value.utf8(); | 1057 params.value = new_info.value.utf8(); |
| 1055 params.selection_start = new_info.selectionStart; | 1058 params.selection_start = new_info.selectionStart; |
| 1056 params.selection_end = new_info.selectionEnd; | 1059 params.selection_end = new_info.selectionEnd; |
| 1057 params.composition_start = new_info.compositionStart; | 1060 params.composition_start = new_info.compositionStart; |
| 1058 params.composition_end = new_info.compositionEnd; | 1061 params.composition_end = new_info.compositionEnd; |
| 1059 params.can_compose_inline = new_can_compose_inline; | 1062 params.can_compose_inline = new_can_compose_inline; |
| 1060 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); | 1063 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED); |
| 1061 #if defined(OS_ANDROID) || defined(USE_AURA) | 1064 #if defined(OS_ANDROID) || defined(USE_AURA) |
|
aelias_OOO_until_Jul13
2017/01/04 00:59:50
Please remove "#if defined(OS_ANDROID) || defined(
Changwan Ryu
2017/01/04 06:43:46
Done.
| |
| 1062 params.is_non_ime_change = (change_source == ChangeSource::FROM_NON_IME); | 1065 params.update_requested = update_requested; |
|
aelias_OOO_until_Jul13
2017/01/04 00:59:50
I'd prefer name "params.reply_to_request"
Changwan Ryu
2017/01/04 06:43:46
Changed.
| |
| 1063 #endif | 1066 #endif |
| 1064 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); | 1067 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); |
| 1065 | 1068 |
| 1066 text_input_info_ = new_info; | 1069 text_input_info_ = new_info; |
| 1067 text_input_type_ = new_type; | 1070 text_input_type_ = new_type; |
| 1068 text_input_mode_ = new_mode; | 1071 text_input_mode_ = new_mode; |
| 1069 can_compose_inline_ = new_can_compose_inline; | 1072 can_compose_inline_ = new_can_compose_inline; |
| 1070 text_input_flags_ = new_info.flags; | 1073 text_input_flags_ = new_info.flags; |
| 1071 } | 1074 } |
| 1072 } | 1075 } |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1705 } | 1708 } |
| 1706 | 1709 |
| 1707 void RenderWidget::OnDragSourceSystemDragEnded() { | 1710 void RenderWidget::OnDragSourceSystemDragEnded() { |
| 1708 if (!GetWebWidget()) | 1711 if (!GetWebWidget()) |
| 1709 return; | 1712 return; |
| 1710 | 1713 |
| 1711 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceSystemDragEnded(); | 1714 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceSystemDragEnded(); |
| 1712 } | 1715 } |
| 1713 | 1716 |
| 1714 void RenderWidget::showImeIfNeeded() { | 1717 void RenderWidget::showImeIfNeeded() { |
| 1715 #if defined(OS_ANDROID) || defined(USE_AURA) | 1718 #if defined(OS_ANDROID) || defined(USE_AURA) |
|
aelias_OOO_until_Jul13
2017/01/04 00:59:51
Can this #if be removed as well?
Changwan Ryu
2017/01/04 06:43:46
Done. MacOSX does not seem to use it.
| |
| 1716 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); | 1719 UpdateTextInputState(ShowIme::IF_NEEDED); |
| 1717 #endif | 1720 #endif |
| 1718 | 1721 |
| 1719 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with | 1722 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with |
| 1720 // virtual keyboard. | 1723 // virtual keyboard. |
| 1721 #if !defined(OS_ANDROID) | 1724 #if !defined(OS_ANDROID) |
| 1722 FocusChangeComplete(); | 1725 FocusChangeComplete(); |
| 1723 #endif | 1726 #endif |
| 1724 } | 1727 } |
| 1725 | 1728 |
| 1726 ui::TextInputType RenderWidget::GetTextInputType() { | 1729 ui::TextInputType RenderWidget::GetTextInputType() { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1779 rect->y *= GetOriginalDeviceScaleFactor(); | 1782 rect->y *= GetOriginalDeviceScaleFactor(); |
| 1780 rect->width *= GetOriginalDeviceScaleFactor(); | 1783 rect->width *= GetOriginalDeviceScaleFactor(); |
| 1781 rect->height *= GetOriginalDeviceScaleFactor(); | 1784 rect->height *= GetOriginalDeviceScaleFactor(); |
| 1782 } | 1785 } |
| 1783 } | 1786 } |
| 1784 | 1787 |
| 1785 #if defined(OS_ANDROID) | 1788 #if defined(OS_ANDROID) |
| 1786 void RenderWidget::OnRequestTextInputStateUpdate() { | 1789 void RenderWidget::OnRequestTextInputStateUpdate() { |
| 1787 DCHECK(!ime_event_guard_); | 1790 DCHECK(!ime_event_guard_); |
| 1788 UpdateSelectionBounds(); | 1791 UpdateSelectionBounds(); |
| 1789 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); | 1792 ime_requested_update_ = true; |
| 1793 UpdateTextInputState(ShowIme::DO_NOT_SHOW); | |
| 1790 } | 1794 } |
| 1791 #endif | 1795 #endif |
| 1792 | 1796 |
| 1793 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request, | 1797 void RenderWidget::OnRequestCompositionUpdate(bool immediate_request, |
| 1794 bool monitor_request) { | 1798 bool monitor_request) { |
| 1795 monitor_composition_info_ = monitor_request; | 1799 monitor_composition_info_ = monitor_request; |
| 1796 if (!immediate_request) | 1800 if (!immediate_request) |
| 1797 return; | 1801 return; |
| 1798 UpdateCompositionInfo(true /* immediate request */); | 1802 UpdateCompositionInfo(true /* immediate request */); |
| 1799 } | 1803 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1853 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; | 1857 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; |
| 1854 } | 1858 } |
| 1855 | 1859 |
| 1856 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { | 1860 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { |
| 1857 if (!ime_event_guard_) | 1861 if (!ime_event_guard_) |
| 1858 ime_event_guard_ = guard; | 1862 ime_event_guard_ = guard; |
| 1859 } | 1863 } |
| 1860 | 1864 |
| 1861 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { | 1865 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { |
| 1862 if (ime_event_guard_ != guard) { | 1866 if (ime_event_guard_ != guard) { |
| 1863 #if defined(OS_ANDROID) | 1867 DCHECK(!ime_event_guard_->update_requested()); |
| 1864 // In case a from-IME event (e.g. touch) ends up in not-from-IME event | |
| 1865 // (e.g. long press gesture), we want to treat it as not-from-IME event | |
| 1866 // so that ReplicaInputConnection can make changes to its Editable model. | |
| 1867 // Therefore, we want to mark this text state update as 'from IME' only | |
| 1868 // when all the nested events are all originating from IME. | |
| 1869 ime_event_guard_->set_from_ime( | |
| 1870 ime_event_guard_->from_ime() && guard->from_ime()); | |
| 1871 #endif | |
| 1872 return; | 1868 return; |
| 1873 } | 1869 } |
| 1874 ime_event_guard_ = nullptr; | 1870 ime_event_guard_ = nullptr; |
| 1875 | 1871 |
| 1876 // While handling an ime event, text input state and selection bounds updates | 1872 // While handling an ime event, text input state and selection bounds updates |
| 1877 // are ignored. These must explicitly be updated once finished handling the | 1873 // are ignored. These must explicitly be updated once finished handling the |
| 1878 // ime event. | 1874 // ime event. |
| 1879 UpdateSelectionBounds(); | 1875 UpdateSelectionBounds(); |
| 1880 #if defined(OS_ANDROID) | 1876 #if defined(OS_ANDROID) |
|
aelias_OOO_until_Jul13
2017/01/04 00:59:50
Maybe for another patch, but why is this #if OS(AN
Changwan Ryu
2017/01/04 06:43:46
Filed crbug.com/678163 .
| |
| 1881 UpdateTextInputState( | 1877 UpdateTextInputState(guard->show_ime() ? ShowIme::IF_NEEDED |
| 1882 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME, | 1878 : ShowIme::DO_NOT_SHOW); |
| 1883 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME); | |
| 1884 #endif | 1879 #endif |
| 1885 } | 1880 } |
| 1886 | 1881 |
| 1887 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { | 1882 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
| 1888 #if BUILDFLAG(ENABLE_PLUGINS) | 1883 #if BUILDFLAG(ENABLE_PLUGINS) |
| 1889 if (focused_pepper_plugin_) { | 1884 if (focused_pepper_plugin_) { |
| 1890 // TODO(kinaba) http://crbug.com/101101 | 1885 // TODO(kinaba) http://crbug.com/101101 |
| 1891 // Current Pepper IME API does not handle selection bounds. So we simply | 1886 // Current Pepper IME API does not handle selection bounds. So we simply |
| 1892 // use the caret position as an empty range for now. It will be updated | 1887 // use the caret position as an empty range for now. It will be updated |
| 1893 // after Pepper API equips features related to surrounding text retrieval. | 1888 // after Pepper API equips features related to surrounding text retrieval. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2088 } | 2083 } |
| 2089 #endif | 2084 #endif |
| 2090 | 2085 |
| 2091 void RenderWidget::didHandleGestureEvent( | 2086 void RenderWidget::didHandleGestureEvent( |
| 2092 const WebGestureEvent& event, | 2087 const WebGestureEvent& event, |
| 2093 bool event_cancelled) { | 2088 bool event_cancelled) { |
| 2094 #if defined(OS_ANDROID) || defined(USE_AURA) | 2089 #if defined(OS_ANDROID) || defined(USE_AURA) |
| 2095 if (event_cancelled) | 2090 if (event_cancelled) |
| 2096 return; | 2091 return; |
| 2097 if (event.type == WebInputEvent::GestureTap) { | 2092 if (event.type == WebInputEvent::GestureTap) { |
| 2098 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); | 2093 UpdateTextInputState(ShowIme::IF_NEEDED); |
| 2099 } else if (event.type == WebInputEvent::GestureLongPress) { | 2094 } else if (event.type == WebInputEvent::GestureLongPress) { |
| 2100 DCHECK(GetWebWidget()); | 2095 DCHECK(GetWebWidget()); |
| 2101 if (GetWebWidget()->textInputInfo().value.isEmpty()) | 2096 if (GetWebWidget()->textInputInfo().value.isEmpty()) |
| 2102 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME); | 2097 UpdateTextInputState(ShowIme::DO_NOT_SHOW); |
| 2103 else | 2098 else |
| 2104 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); | 2099 UpdateTextInputState(ShowIme::IF_NEEDED); |
| 2105 } | 2100 } |
| 2106 // TODO(ananta): Piggyback off existing IPCs to communicate this information, | 2101 // TODO(ananta): Piggyback off existing IPCs to communicate this information, |
| 2107 // crbug/420130. | 2102 // crbug/420130. |
| 2108 #if defined(OS_WIN) | 2103 #if defined(OS_WIN) |
| 2109 if (event.type != blink::WebGestureEvent::GestureTap) | 2104 if (event.type != blink::WebGestureEvent::GestureTap) |
| 2110 return; | 2105 return; |
| 2111 | 2106 |
| 2112 // TODO(estade): hit test the event against focused node to make sure | 2107 // TODO(estade): hit test the event against focused node to make sure |
| 2113 // the tap actually hit the focused node. | 2108 // the tap actually hit the focused node. |
| 2114 blink::WebTextInputType text_input_type = GetWebWidget()->textInputType(); | 2109 blink::WebTextInputType text_input_type = GetWebWidget()->textInputType(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2242 // browser side (https://crbug.com/669219). | 2237 // browser side (https://crbug.com/669219). |
| 2243 // If there is no WebFrameWidget, then there will be no | 2238 // If there is no WebFrameWidget, then there will be no |
| 2244 // InputMethodControllers for a WebLocalFrame. | 2239 // InputMethodControllers for a WebLocalFrame. |
| 2245 return nullptr; | 2240 return nullptr; |
| 2246 } | 2241 } |
| 2247 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | 2242 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
| 2248 ->getActiveWebInputMethodController(); | 2243 ->getActiveWebInputMethodController(); |
| 2249 } | 2244 } |
| 2250 | 2245 |
| 2251 } // namespace content | 2246 } // namespace content |
| OLD | NEW |