Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: content/renderer/render_widget.cc

Issue 1388283002: Fix OSK flickering issue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: switched to ime guard approach Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 next_paint_flags_(0), 491 next_paint_flags_(0),
492 auto_resize_mode_(false), 492 auto_resize_mode_(false),
493 need_update_rect_for_auto_resize_(false), 493 need_update_rect_for_auto_resize_(false),
494 did_show_(false), 494 did_show_(false),
495 is_hidden_(hidden), 495 is_hidden_(hidden),
496 compositor_never_visible_(never_visible), 496 compositor_never_visible_(never_visible),
497 is_fullscreen_granted_(false), 497 is_fullscreen_granted_(false),
498 display_mode_(blink::WebDisplayModeUndefined), 498 display_mode_(blink::WebDisplayModeUndefined),
499 handling_input_event_(false), 499 handling_input_event_(false),
500 handling_event_overscroll_(nullptr), 500 handling_event_overscroll_(nullptr),
501 handling_ime_event_(false), 501 handling_ime_events_count_(0),
502 pending_show_ime_if_needed_(false),
502 handling_event_type_(WebInputEvent::Undefined), 503 handling_event_type_(WebInputEvent::Undefined),
503 ignore_ack_for_mouse_move_from_debugger_(false), 504 ignore_ack_for_mouse_move_from_debugger_(false),
504 closing_(false), 505 closing_(false),
505 host_closing_(false), 506 host_closing_(false),
506 is_swapped_out_(swapped_out), 507 is_swapped_out_(swapped_out),
507 for_oopif_(false), 508 for_oopif_(false),
508 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 509 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
509 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), 510 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
510 text_input_flags_(0), 511 text_input_flags_(0),
511 can_compose_inline_(true), 512 can_compose_inline_(true),
512 popup_type_(popup_type), 513 popup_type_(popup_type),
513 pending_window_rect_count_(0), 514 pending_window_rect_count_(0),
514 suppress_next_char_events_(false), 515 suppress_next_char_events_(false),
515 screen_info_(screen_info), 516 screen_info_(screen_info),
516 device_scale_factor_(screen_info_.deviceScaleFactor), 517 device_scale_factor_(screen_info_.deviceScaleFactor),
517 next_output_surface_id_(0), 518 next_output_surface_id_(0),
518 #if defined(OS_ANDROID) 519 #if defined(OS_ANDROID)
519 text_field_is_dirty_(false), 520 text_field_is_dirty_(false),
521 pending_update_from_non_ime_(false),
520 #endif 522 #endif
521 popup_origin_scale_for_emulation_(0.f), 523 popup_origin_scale_for_emulation_(0.f),
522 frame_swap_message_queue_(new FrameSwapMessageQueue()), 524 frame_swap_message_queue_(new FrameSwapMessageQueue()),
523 resizing_mode_selector_(new ResizingModeSelector()), 525 resizing_mode_selector_(new ResizingModeSelector()),
524 context_menu_source_type_(ui::MENU_SOURCE_MOUSE), 526 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
525 has_host_context_menu_location_(false) { 527 has_host_context_menu_location_(false) {
526 if (!swapped_out) 528 if (!swapped_out)
527 RenderProcess::current()->AddRefProcess(); 529 RenderProcess::current()->AddRefProcess();
528 DCHECK(RenderThread::Get()); 530 DCHECK(RenderThread::Get());
529 device_color_profile_.push_back('0'); 531 device_color_profile_.push_back('0');
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter( 1064 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1063 &handling_event_type_, input_event->type); 1065 &handling_event_type_, input_event->type);
1064 1066
1065 // Calls into |didOverscroll()| while handling this event will populate 1067 // Calls into |didOverscroll()| while handling this event will populate
1066 // |event_overscroll|, which in turn will be bundled with the event ack. 1068 // |event_overscroll|, which in turn will be bundled with the event ack.
1067 scoped_ptr<DidOverscrollParams> event_overscroll; 1069 scoped_ptr<DidOverscrollParams> event_overscroll;
1068 base::AutoReset<scoped_ptr<DidOverscrollParams>*> 1070 base::AutoReset<scoped_ptr<DidOverscrollParams>*>
1069 handling_event_overscroll_resetter(&handling_event_overscroll_, 1071 handling_event_overscroll_resetter(&handling_event_overscroll_,
1070 &event_overscroll); 1072 &event_overscroll);
1071 1073
1072 #if defined(OS_ANDROID) 1074 const bool is_keyboard_event =
1073 // On Android, when a key is pressed or sent from the Keyboard using IME, 1075 WebInputEvent::isKeyboardEventType(input_event->type);
1074 // |AdapterInputConnection| generates input key events to make sure all JS 1076
1075 // listeners that monitor KeyUp and KeyDown events receive the proper key 1077 // For non-keyboard events, we want the change source to be FROM_NON_IME.
1076 // code. Since this input key event comes from IME, we need to set the 1078 ImeEventGuard guard(this, !is_keyboard_event);
1077 // IME event guard here to make sure it does not interfere with other IME
1078 // events.
1079 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1080 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1081 const WebKeyboardEvent& key_event =
1082 *static_cast<const WebKeyboardEvent*>(input_event);
1083 // Some keys are special and it's essential that no events get blocked.
1084 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
1085 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1086 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1087 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1088 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1089 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
1090 ime_event_guard_maybe.reset(new ImeEventGuard(this));
1091 }
1092 #endif
1093 1079
1094 base::TimeTicks start_time; 1080 base::TimeTicks start_time;
1095 if (base::TimeTicks::IsHighResolution()) 1081 if (base::TimeTicks::IsHighResolution())
1096 start_time = base::TimeTicks::Now(); 1082 start_time = base::TimeTicks::Now();
1097 1083
1098 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent", 1084 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
1099 "event", WebInputEventTraits::GetName(input_event->type)); 1085 "event", WebInputEventTraits::GetName(input_event->type));
1100 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); 1086 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
1101 TRACE_EVENT_WITH_FLOW1("input,benchmark", 1087 TRACE_EVENT_WITH_FLOW1("input,benchmark",
1102 "LatencyInfo.Flow", 1088 "LatencyInfo.Flow",
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
1872 return type == ui::TEXT_INPUT_TYPE_DATE || 1858 return type == ui::TEXT_INPUT_TYPE_DATE ||
1873 type == ui::TEXT_INPUT_TYPE_DATE_TIME || 1859 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1874 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL || 1860 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1875 type == ui::TEXT_INPUT_TYPE_MONTH || 1861 type == ui::TEXT_INPUT_TYPE_MONTH ||
1876 type == ui::TEXT_INPUT_TYPE_TIME || 1862 type == ui::TEXT_INPUT_TYPE_TIME ||
1877 type == ui::TEXT_INPUT_TYPE_WEEK; 1863 type == ui::TEXT_INPUT_TYPE_WEEK;
1878 } 1864 }
1879 1865
1880 1866
1881 void RenderWidget::StartHandlingImeEvent() { 1867 void RenderWidget::StartHandlingImeEvent() {
1882 DCHECK(!handling_ime_event_); 1868 ++handling_ime_events_count_;
1883 handling_ime_event_ = true;
1884 } 1869 }
1885 1870
1886 void RenderWidget::FinishHandlingImeEvent() { 1871 void RenderWidget::FinishHandlingImeEvent(bool from_non_ime) {
1887 DCHECK(handling_ime_event_); 1872 --handling_ime_events_count_;
1888 handling_ime_event_ = false; 1873 CHECK_GE(handling_ime_events_count_, 0);
1874 #if defined(OS_ANDROID)
1875 // From non-IME source should take precedence because AdapterInputConnection
1876 // makes real changes only when it's not originating from IME.
1877 pending_update_from_non_ime_ |= from_non_ime;
1878 #endif
1879 if (handling_ime_events_count_ > 0)
1880 return;
1881
1889 // While handling an ime event, text input state and selection bounds updates 1882 // While handling an ime event, text input state and selection bounds updates
1890 // are ignored. These must explicitly be updated once finished handling the 1883 // are ignored. These must explicitly be updated once finished handling the
1891 // ime event. 1884 // ime event.
1892 UpdateSelectionBounds(); 1885 UpdateSelectionBounds();
1893 #if defined(OS_ANDROID) 1886 #if defined(OS_ANDROID)
1894 UpdateTextInputState(NO_SHOW_IME, FROM_IME); 1887 UpdateTextInputState(NO_SHOW_IME,
1888 pending_update_from_non_ime_ ? FROM_NON_IME : FROM_IME);
1889 pending_update_from_non_ime_ = false;
1895 #endif 1890 #endif
1896 } 1891 }
1897 1892
1898 void RenderWidget::UpdateTextInputState(ShowIme show_ime, 1893 void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1899 ChangeSource change_source) { 1894 ChangeSource change_source) {
1900 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); 1895 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1901 if (handling_ime_event_) 1896 if (handling_ime_events_count_ > 0) {
1897 if (show_ime == SHOW_IME_IF_NEEDED)
1898 pending_show_ime_if_needed_ = true;
1899
1902 return; 1900 return;
1901 }
1902
1903 if (pending_show_ime_if_needed_) {
1904 show_ime = SHOW_IME_IF_NEEDED;
1905 pending_show_ime_if_needed_ = false;
1906 }
1907
1903 ui::TextInputType new_type = GetTextInputType(); 1908 ui::TextInputType new_type = GetTextInputType();
1904 if (IsDateTimeInput(new_type)) 1909 if (IsDateTimeInput(new_type))
1905 return; // Not considered as a text input field in WebKit/Chromium. 1910 return; // Not considered as a text input field in WebKit/Chromium.
1906 1911
1907 blink::WebTextInputInfo new_info; 1912 blink::WebTextInputInfo new_info;
1908 if (webwidget_) 1913 if (webwidget_)
1909 new_info = webwidget_->textInputInfo(); 1914 new_info = webwidget_->textInputInfo();
1910 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); 1915 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1911 1916
1912 bool new_can_compose_inline = CanComposeInline(); 1917 bool new_can_compose_inline = CanComposeInline();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 WebRect anchor_webrect; 1963 WebRect anchor_webrect;
1959 webwidget_->selectionBounds(focus_webrect, anchor_webrect); 1964 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1960 *focus = focus_webrect; 1965 *focus = focus_webrect;
1961 *anchor = anchor_webrect; 1966 *anchor = anchor_webrect;
1962 } 1967 }
1963 1968
1964 void RenderWidget::UpdateSelectionBounds() { 1969 void RenderWidget::UpdateSelectionBounds() {
1965 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); 1970 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
1966 if (!webwidget_) 1971 if (!webwidget_)
1967 return; 1972 return;
1968 if (handling_ime_event_) 1973 if (handling_ime_events_count_ > 0)
1969 return; 1974 return;
1970 1975
1971 #if defined(USE_AURA) 1976 #if defined(USE_AURA)
1972 // TODO(mohsen): For now, always send explicit selection IPC notifications for 1977 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1973 // Aura beucause composited selection updates are not working for webview tags 1978 // Aura beucause composited selection updates are not working for webview tags
1974 // which regresses IME inside webview. Remove this when composited selection 1979 // which regresses IME inside webview. Remove this when composited selection
1975 // updates are fixed for webviews. See, http://crbug.com/510568. 1980 // updates are fixed for webviews. See, http://crbug.com/510568.
1976 bool send_ipc = true; 1981 bool send_ipc = true;
1977 #else 1982 #else
1978 // With composited selection updates, the selection bounds will be reported 1983 // With composited selection updates, the selection bounds will be reported
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { 2402 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2398 video_hole_frames_.AddObserver(frame); 2403 video_hole_frames_.AddObserver(frame);
2399 } 2404 }
2400 2405
2401 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { 2406 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2402 video_hole_frames_.RemoveObserver(frame); 2407 video_hole_frames_.RemoveObserver(frame);
2403 } 2408 }
2404 #endif // defined(VIDEO_HOLE) 2409 #endif // defined(VIDEO_HOLE)
2405 2410
2406 } // namespace content 2411 } // namespace content
OLDNEW
« content/renderer/render_widget.h ('K') | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698