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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 next_paint_flags_(0), | 492 next_paint_flags_(0), |
| 493 auto_resize_mode_(false), | 493 auto_resize_mode_(false), |
| 494 need_update_rect_for_auto_resize_(false), | 494 need_update_rect_for_auto_resize_(false), |
| 495 did_show_(false), | 495 did_show_(false), |
| 496 is_hidden_(hidden), | 496 is_hidden_(hidden), |
| 497 compositor_never_visible_(never_visible), | 497 compositor_never_visible_(never_visible), |
| 498 is_fullscreen_granted_(false), | 498 is_fullscreen_granted_(false), |
| 499 display_mode_(blink::WebDisplayModeUndefined), | 499 display_mode_(blink::WebDisplayModeUndefined), |
| 500 handling_input_event_(false), | 500 handling_input_event_(false), |
| 501 handling_event_overscroll_(nullptr), | 501 handling_event_overscroll_(nullptr), |
| 502 handling_ime_event_(false), | 502 ime_event_guard_(nullptr), |
| 503 handling_event_type_(WebInputEvent::Undefined), | 503 handling_event_type_(WebInputEvent::Undefined), |
| 504 ignore_ack_for_mouse_move_from_debugger_(false), | 504 ignore_ack_for_mouse_move_from_debugger_(false), |
| 505 closing_(false), | 505 closing_(false), |
| 506 host_closing_(false), | 506 host_closing_(false), |
| 507 is_swapped_out_(swapped_out), | 507 is_swapped_out_(swapped_out), |
| 508 for_oopif_(false), | 508 for_oopif_(false), |
| 509 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 509 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 510 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 510 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
| 511 text_input_flags_(0), | 511 text_input_flags_(0), |
| 512 can_compose_inline_(true), | 512 can_compose_inline_(true), |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1077 &handling_event_type_, input_event->type); | 1077 &handling_event_type_, input_event->type); |
| 1078 | 1078 |
| 1079 // Calls into |didOverscroll()| while handling this event will populate | 1079 // Calls into |didOverscroll()| while handling this event will populate |
| 1080 // |event_overscroll|, which in turn will be bundled with the event ack. | 1080 // |event_overscroll|, which in turn will be bundled with the event ack. |
| 1081 scoped_ptr<DidOverscrollParams> event_overscroll; | 1081 scoped_ptr<DidOverscrollParams> event_overscroll; |
| 1082 base::AutoReset<scoped_ptr<DidOverscrollParams>*> | 1082 base::AutoReset<scoped_ptr<DidOverscrollParams>*> |
| 1083 handling_event_overscroll_resetter(&handling_event_overscroll_, | 1083 handling_event_overscroll_resetter(&handling_event_overscroll_, |
| 1084 &event_overscroll); | 1084 &event_overscroll); |
| 1085 | 1085 |
| 1086 #if defined(OS_ANDROID) | 1086 #if defined(OS_ANDROID) |
| 1087 // On Android, when a key is pressed or sent from the Keyboard using IME, | 1087 const bool is_keyboard_event = |
| 1088 // |AdapterInputConnection| generates input key events to make sure all JS | 1088 WebInputEvent::isKeyboardEventType(input_event->type); |
| 1089 // listeners that monitor KeyUp and KeyDown events receive the proper key | 1089 |
| 1090 // code. Since this input key event comes from IME, we need to set the | 1090 // For non-keyboard events, we want the change source to be FROM_NON_IME. |
| 1091 // IME event guard here to make sure it does not interfere with other IME | 1091 ImeEventGuard guard(this, false, is_keyboard_event); |
| 1092 // events. | |
| 1093 scoped_ptr<ImeEventGuard> ime_event_guard_maybe; | |
| 1094 if (WebInputEvent::isKeyboardEventType(input_event->type)) { | |
| 1095 const WebKeyboardEvent& key_event = | |
| 1096 *static_cast<const WebKeyboardEvent*>(input_event); | |
| 1097 // Some keys are special and it's essential that no events get blocked. | |
| 1098 if (key_event.nativeKeyCode != AKEYCODE_TAB && | |
| 1099 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER && | |
| 1100 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT && | |
| 1101 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT && | |
| 1102 key_event.nativeKeyCode != AKEYCODE_DPAD_UP && | |
| 1103 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN) | |
| 1104 ime_event_guard_maybe.reset(new ImeEventGuard(this)); | |
| 1105 } | |
| 1106 #endif | 1092 #endif |
| 1107 | 1093 |
| 1108 base::TimeTicks start_time; | 1094 base::TimeTicks start_time; |
| 1109 if (base::TimeTicks::IsHighResolution()) | 1095 if (base::TimeTicks::IsHighResolution()) |
| 1110 start_time = base::TimeTicks::Now(); | 1096 start_time = base::TimeTicks::Now(); |
| 1111 | 1097 |
| 1112 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent", | 1098 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent", |
| 1113 "event", WebInputEventTraits::GetName(input_event->type)); | 1099 "event", WebInputEventTraits::GetName(input_event->type)); |
| 1114 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); | 1100 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); |
| 1115 TRACE_EVENT_WITH_FLOW1("input,benchmark", | 1101 TRACE_EVENT_WITH_FLOW1("input,benchmark", |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1884 | 1870 |
| 1885 static bool IsDateTimeInput(ui::TextInputType type) { | 1871 static bool IsDateTimeInput(ui::TextInputType type) { |
| 1886 return type == ui::TEXT_INPUT_TYPE_DATE || | 1872 return type == ui::TEXT_INPUT_TYPE_DATE || |
| 1887 type == ui::TEXT_INPUT_TYPE_DATE_TIME || | 1873 type == ui::TEXT_INPUT_TYPE_DATE_TIME || |
| 1888 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL || | 1874 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL || |
| 1889 type == ui::TEXT_INPUT_TYPE_MONTH || | 1875 type == ui::TEXT_INPUT_TYPE_MONTH || |
| 1890 type == ui::TEXT_INPUT_TYPE_TIME || | 1876 type == ui::TEXT_INPUT_TYPE_TIME || |
| 1891 type == ui::TEXT_INPUT_TYPE_WEEK; | 1877 type == ui::TEXT_INPUT_TYPE_WEEK; |
| 1892 } | 1878 } |
| 1893 | 1879 |
| 1894 | 1880 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { |
| 1895 void RenderWidget::StartHandlingImeEvent() { | 1881 if (!ime_event_guard_) |
| 1896 DCHECK(!handling_ime_event_); | 1882 ime_event_guard_ = guard; |
| 1897 handling_ime_event_ = true; | |
| 1898 } | 1883 } |
| 1899 | 1884 |
| 1900 void RenderWidget::FinishHandlingImeEvent() { | 1885 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { |
| 1901 DCHECK(handling_ime_event_); | 1886 if (ime_event_guard_ != guard) { |
| 1902 handling_ime_event_ = false; | 1887 #if defined(OS_ANDROID) |
| 1888 // AdapterInputConnection make real changes only when it's not originating | |
| 1889 // from IME. We want non-keyboard events (e.g., long-press events) to be | |
| 1890 // treated as NOT originating from IME, when we finish handling these | |
| 1891 // events. | |
| 1892 ime_event_guard_->set_from_ime( | |
| 1893 ime_event_guard_->from_ime() & guard->from_ime()); | |
|
no sievers
2015/10/30 00:05:52
'&' -> '&&'
no sievers
2015/10/30 00:05:52
nit: i found the previous reverse logic a bit easi
Changwan Ryu
2015/10/30 01:15:53
Modified the comment to make it more readable. Tha
Changwan Ryu
2015/10/30 01:15:53
Done.
| |
| 1894 #endif | |
| 1895 return; | |
| 1896 } | |
| 1897 ime_event_guard_ = nullptr; | |
| 1898 | |
| 1903 // While handling an ime event, text input state and selection bounds updates | 1899 // While handling an ime event, text input state and selection bounds updates |
| 1904 // are ignored. These must explicitly be updated once finished handling the | 1900 // are ignored. These must explicitly be updated once finished handling the |
| 1905 // ime event. | 1901 // ime event. |
| 1906 UpdateSelectionBounds(); | 1902 UpdateSelectionBounds(); |
| 1907 #if defined(OS_ANDROID) | 1903 #if defined(OS_ANDROID) |
| 1908 UpdateTextInputState(NO_SHOW_IME, FROM_IME); | 1904 UpdateTextInputState( |
| 1905 guard->show_ime() ? SHOW_IME_IF_NEEDED : NO_SHOW_IME, | |
| 1906 guard->from_ime() ? FROM_IME : FROM_NON_IME); | |
| 1909 #endif | 1907 #endif |
| 1910 } | 1908 } |
| 1911 | 1909 |
| 1912 void RenderWidget::UpdateTextInputState(ShowIme show_ime, | 1910 void RenderWidget::UpdateTextInputState(ShowIme show_ime, |
| 1913 ChangeSource change_source) { | 1911 ChangeSource change_source) { |
| 1914 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); | 1912 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); |
| 1915 if (handling_ime_event_) | 1913 if (ime_event_guard_) { |
| 1914 // show_ime should still be effective even if it was set inside the IME | |
| 1915 // event guard. | |
| 1916 if (show_ime == SHOW_IME_IF_NEEDED) { | |
| 1917 ime_event_guard_->set_show_ime(true); | |
| 1918 } | |
| 1916 return; | 1919 return; |
| 1920 } | |
| 1921 | |
| 1917 ui::TextInputType new_type = GetTextInputType(); | 1922 ui::TextInputType new_type = GetTextInputType(); |
| 1918 if (IsDateTimeInput(new_type)) | 1923 if (IsDateTimeInput(new_type)) |
| 1919 return; // Not considered as a text input field in WebKit/Chromium. | 1924 return; // Not considered as a text input field in WebKit/Chromium. |
| 1920 | 1925 |
| 1921 blink::WebTextInputInfo new_info; | 1926 blink::WebTextInputInfo new_info; |
| 1922 if (webwidget_) | 1927 if (webwidget_) |
| 1923 new_info = webwidget_->textInputInfo(); | 1928 new_info = webwidget_->textInputInfo(); |
| 1924 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); | 1929 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); |
| 1925 | 1930 |
| 1926 bool new_can_compose_inline = CanComposeInline(); | 1931 bool new_can_compose_inline = CanComposeInline(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1972 WebRect anchor_webrect; | 1977 WebRect anchor_webrect; |
| 1973 webwidget_->selectionBounds(focus_webrect, anchor_webrect); | 1978 webwidget_->selectionBounds(focus_webrect, anchor_webrect); |
| 1974 *focus = focus_webrect; | 1979 *focus = focus_webrect; |
| 1975 *anchor = anchor_webrect; | 1980 *anchor = anchor_webrect; |
| 1976 } | 1981 } |
| 1977 | 1982 |
| 1978 void RenderWidget::UpdateSelectionBounds() { | 1983 void RenderWidget::UpdateSelectionBounds() { |
| 1979 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); | 1984 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); |
| 1980 if (!webwidget_) | 1985 if (!webwidget_) |
| 1981 return; | 1986 return; |
| 1982 if (handling_ime_event_) | 1987 if (ime_event_guard_) |
| 1983 return; | 1988 return; |
| 1984 | 1989 |
| 1985 #if defined(USE_AURA) | 1990 #if defined(USE_AURA) |
| 1986 // TODO(mohsen): For now, always send explicit selection IPC notifications for | 1991 // TODO(mohsen): For now, always send explicit selection IPC notifications for |
| 1987 // Aura beucause composited selection updates are not working for webview tags | 1992 // Aura beucause composited selection updates are not working for webview tags |
| 1988 // which regresses IME inside webview. Remove this when composited selection | 1993 // which regresses IME inside webview. Remove this when composited selection |
| 1989 // updates are fixed for webviews. See, http://crbug.com/510568. | 1994 // updates are fixed for webviews. See, http://crbug.com/510568. |
| 1990 bool send_ipc = true; | 1995 bool send_ipc = true; |
| 1991 #else | 1996 #else |
| 1992 // With composited selection updates, the selection bounds will be reported | 1997 // With composited selection updates, the selection bounds will be reported |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2411 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2416 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2412 video_hole_frames_.AddObserver(frame); | 2417 video_hole_frames_.AddObserver(frame); |
| 2413 } | 2418 } |
| 2414 | 2419 |
| 2415 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2420 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2416 video_hole_frames_.RemoveObserver(frame); | 2421 video_hole_frames_.RemoveObserver(frame); |
| 2417 } | 2422 } |
| 2418 #endif // defined(VIDEO_HOLE) | 2423 #endif // defined(VIDEO_HOLE) |
| 2419 | 2424 |
| 2420 } // namespace content | 2425 } // namespace content |
| OLD | NEW |