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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 234 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
235 text_input_flags_(0), | 235 text_input_flags_(0), |
236 can_compose_inline_(true), | 236 can_compose_inline_(true), |
237 popup_type_(popup_type), | 237 popup_type_(popup_type), |
238 pending_window_rect_count_(0), | 238 pending_window_rect_count_(0), |
239 screen_info_(screen_info), | 239 screen_info_(screen_info), |
240 device_scale_factor_(screen_info_.deviceScaleFactor), | 240 device_scale_factor_(screen_info_.deviceScaleFactor), |
241 next_output_surface_id_(0), | 241 next_output_surface_id_(0), |
242 #if defined(OS_ANDROID) | 242 #if defined(OS_ANDROID) |
243 text_field_is_dirty_(false), | 243 text_field_is_dirty_(false), |
| 244 ime_thread_disabled_due_to_error_(false), |
244 #endif | 245 #endif |
245 popup_origin_scale_for_emulation_(0.f), | 246 popup_origin_scale_for_emulation_(0.f), |
246 frame_swap_message_queue_(new FrameSwapMessageQueue()), | 247 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
247 resizing_mode_selector_(new ResizingModeSelector()), | 248 resizing_mode_selector_(new ResizingModeSelector()), |
248 has_host_context_menu_location_(false) { | 249 has_host_context_menu_location_(false) { |
249 if (!swapped_out) | 250 if (!swapped_out) |
250 RenderProcess::current()->AddRefProcess(); | 251 RenderProcess::current()->AddRefProcess(); |
251 DCHECK(RenderThread::Get()); | 252 DCHECK(RenderThread::Get()); |
252 device_color_profile_.push_back('0'); | 253 device_color_profile_.push_back('0'); |
253 #if defined(OS_ANDROID) | 254 #if defined(OS_ANDROID) |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) | 471 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) |
471 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) | 472 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) |
472 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 473 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
473 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 474 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
474 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) | 475 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
475 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace) | 476 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace) |
476 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, | 477 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, |
477 OnWaitNextFrameForTests) | 478 OnWaitNextFrameForTests) |
478 #if defined(OS_ANDROID) | 479 #if defined(OS_ANDROID) |
479 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) | 480 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) |
| 481 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, |
| 482 OnRequestTextInputStateUpdate) |
| 483 IPC_MESSAGE_HANDLER(InputMsg_DisableImeThread, |
| 484 OnDisableImeThread) |
480 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) | 485 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) |
481 #endif | 486 #endif |
482 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) | 487 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) |
483 IPC_MESSAGE_UNHANDLED(handled = false) | 488 IPC_MESSAGE_UNHANDLED(handled = false) |
484 IPC_END_MESSAGE_MAP() | 489 IPC_END_MESSAGE_MAP() |
485 return handled; | 490 return handled; |
486 } | 491 } |
487 | 492 |
488 bool RenderWidget::Send(IPC::Message* message) { | 493 bool RenderWidget::Send(IPC::Message* message) { |
489 // Don't send any messages after the browser has told us to close, and filter | 494 // Don't send any messages after the browser has told us to close, and filter |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 blink::WebTextInputInfo new_info; | 1002 blink::WebTextInputInfo new_info; |
998 if (webwidget_) | 1003 if (webwidget_) |
999 new_info = webwidget_->textInputInfo(); | 1004 new_info = webwidget_->textInputInfo(); |
1000 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); | 1005 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); |
1001 | 1006 |
1002 bool new_can_compose_inline = CanComposeInline(); | 1007 bool new_can_compose_inline = CanComposeInline(); |
1003 | 1008 |
1004 // Only sends text input params if they are changed or if the ime should be | 1009 // Only sends text input params if they are changed or if the ime should be |
1005 // shown. | 1010 // shown. |
1006 if (show_ime == ShowIme::IF_NEEDED || | 1011 if (show_ime == ShowIme::IF_NEEDED || |
| 1012 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || |
1007 (text_input_type_ != new_type || text_input_mode_ != new_mode || | 1013 (text_input_type_ != new_type || text_input_mode_ != new_mode || |
1008 text_input_info_ != new_info || | 1014 text_input_info_ != new_info || |
1009 can_compose_inline_ != new_can_compose_inline) | 1015 can_compose_inline_ != new_can_compose_inline) |
1010 #if defined(OS_ANDROID) | 1016 #if defined(OS_ANDROID) |
1011 || text_field_is_dirty_ | 1017 || text_field_is_dirty_ |
1012 #endif | 1018 #endif |
1013 ) { | 1019 ) { |
1014 ViewHostMsg_TextInputState_Params params; | 1020 ViewHostMsg_TextInputState_Params params; |
1015 params.type = new_type; | 1021 params.type = new_type; |
1016 params.mode = new_mode; | 1022 params.mode = new_mode; |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 | 1606 |
1601 #if defined(OS_ANDROID) | 1607 #if defined(OS_ANDROID) |
1602 void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) { | 1608 void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) { |
1603 text_input_info_history_.push_back(info); | 1609 text_input_info_history_.push_back(info); |
1604 } | 1610 } |
1605 | 1611 |
1606 void RenderWidget::OnImeEventAck() { | 1612 void RenderWidget::OnImeEventAck() { |
1607 DCHECK_GE(text_input_info_history_.size(), 1u); | 1613 DCHECK_GE(text_input_info_history_.size(), 1u); |
1608 text_input_info_history_.pop_front(); | 1614 text_input_info_history_.pop_front(); |
1609 } | 1615 } |
| 1616 |
| 1617 void RenderWidget::OnRequestTextInputStateUpdate() { |
| 1618 DCHECK(!ime_event_guard_); |
| 1619 UpdateSelectionBounds(); |
| 1620 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); |
| 1621 } |
| 1622 |
| 1623 void RenderWidget::OnDisableImeThread() { |
| 1624 ime_thread_disabled_due_to_error_ = true; |
| 1625 } |
1610 #endif | 1626 #endif |
1611 | 1627 |
1612 bool RenderWidget::ShouldHandleImeEvent() { | 1628 bool RenderWidget::ShouldHandleImeEvent() { |
1613 #if defined(OS_ANDROID) | 1629 #if defined(OS_ANDROID) |
1614 if (!webwidget_) | 1630 if (!webwidget_) |
1615 return false; | 1631 return false; |
| 1632 if (IsUsingImeThread()) |
| 1633 return true; |
1616 | 1634 |
1617 // We cannot handle IME events if there is any chance that the event we are | 1635 // We cannot handle IME events if there is any chance that the event we are |
1618 // receiving here from the browser is based on the state that is different | 1636 // receiving here from the browser is based on the state that is different |
1619 // from our current one as indicated by |text_input_info_|. | 1637 // from our current one as indicated by |text_input_info_|. |
1620 // The states the browser might be in are: | 1638 // The states the browser might be in are: |
1621 // text_input_info_history_[0] - current state ack'd by browser | 1639 // text_input_info_history_[0] - current state ack'd by browser |
1622 // text_input_info_history_[1...N] - pending state changes | 1640 // text_input_info_history_[1...N] - pending state changes |
1623 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) { | 1641 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) { |
1624 if (text_input_info_history_[i] != text_input_info_) | 1642 if (text_input_info_history_[i] != text_input_info_) |
1625 return false; | 1643 return false; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1698 } | 1716 } |
1699 | 1717 |
1700 void RenderWidget::set_next_paint_is_resize_ack() { | 1718 void RenderWidget::set_next_paint_is_resize_ack() { |
1701 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; | 1719 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
1702 } | 1720 } |
1703 | 1721 |
1704 void RenderWidget::set_next_paint_is_repaint_ack() { | 1722 void RenderWidget::set_next_paint_is_repaint_ack() { |
1705 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; | 1723 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; |
1706 } | 1724 } |
1707 | 1725 |
| 1726 bool RenderWidget::IsUsingImeThread() { |
| 1727 #if defined(OS_ANDROID) |
| 1728 return !ime_thread_disabled_due_to_error_ && |
| 1729 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1730 switches::kEnableImeThread) && |
| 1731 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1732 switches::kDisableImeThread); |
| 1733 #else |
| 1734 return false; |
| 1735 #endif |
| 1736 } |
| 1737 |
1708 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { | 1738 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { |
1709 if (!ime_event_guard_) | 1739 if (!ime_event_guard_) |
1710 ime_event_guard_ = guard; | 1740 ime_event_guard_ = guard; |
1711 } | 1741 } |
1712 | 1742 |
1713 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { | 1743 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { |
1714 if (ime_event_guard_ != guard) { | 1744 if (ime_event_guard_ != guard) { |
1715 #if defined(OS_ANDROID) | 1745 #if defined(OS_ANDROID) |
1716 // In case a from-IME event (e.g. touch) ends up in not-from-IME event | 1746 // In case a from-IME event (e.g. touch) ends up in not-from-IME event |
1717 // (e.g. long press gesture), we want to treat it as not-from-IME event | 1747 // (e.g. long press gesture), we want to treat it as not-from-IME event |
1718 // so that AdapterInputConnection can make changes to its Editable model. | 1748 // so that ReplicaInputConnection can make changes to its Editable model. |
1719 // Therefore, we want to mark this text state update as 'from IME' only | 1749 // Therefore, we want to mark this text state update as 'from IME' only |
1720 // when all the nested events are all originating from IME. | 1750 // when all the nested events are all originating from IME. |
1721 ime_event_guard_->set_from_ime( | 1751 ime_event_guard_->set_from_ime( |
1722 ime_event_guard_->from_ime() && guard->from_ime()); | 1752 ime_event_guard_->from_ime() && guard->from_ime()); |
1723 #endif | 1753 #endif |
1724 return; | 1754 return; |
1725 } | 1755 } |
1726 ime_event_guard_ = nullptr; | 1756 ime_event_guard_ = nullptr; |
1727 | 1757 |
1728 // While handling an ime event, text input state and selection bounds updates | 1758 // While handling an ime event, text input state and selection bounds updates |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart) | 2023 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart) |
1994 return; | 2024 return; |
1995 | 2025 |
1996 content::TouchAction content_touch_action = | 2026 content::TouchAction content_touch_action = |
1997 static_cast<content::TouchAction>(web_touch_action); | 2027 static_cast<content::TouchAction>(web_touch_action); |
1998 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action)); | 2028 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action)); |
1999 } | 2029 } |
2000 | 2030 |
2001 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() { | 2031 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() { |
2002 #if defined(OS_ANDROID) | 2032 #if defined(OS_ANDROID) |
2003 text_field_is_dirty_ = true; | 2033 if (!IsUsingImeThread()) |
| 2034 text_field_is_dirty_ = true; |
2004 #endif | 2035 #endif |
2005 } | 2036 } |
2006 | 2037 |
2007 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 2038 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
2008 RenderWidget::CreateGraphicsContext3D(GpuChannelHost* gpu_channel_host) { | 2039 RenderWidget::CreateGraphicsContext3D(GpuChannelHost* gpu_channel_host) { |
2009 // Explicitly disable antialiasing for the compositor. As of the time of | 2040 // Explicitly disable antialiasing for the compositor. As of the time of |
2010 // this writing, the only platform that supported antialiasing for the | 2041 // this writing, the only platform that supported antialiasing for the |
2011 // compositor was Mac OS X, because the on-screen OpenGL context creation | 2042 // compositor was Mac OS X, because the on-screen OpenGL context creation |
2012 // code paths on Windows and Linux didn't yet have multisampling support. | 2043 // code paths on Windows and Linux didn't yet have multisampling support. |
2013 // Mac OS X essentially always behaves as though it's rendering offscreen. | 2044 // Mac OS X essentially always behaves as though it's rendering offscreen. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2087 video_hole_frames_.RemoveObserver(frame); | 2118 video_hole_frames_.RemoveObserver(frame); |
2088 } | 2119 } |
2089 #endif // defined(VIDEO_HOLE) | 2120 #endif // defined(VIDEO_HOLE) |
2090 | 2121 |
2091 void RenderWidget::OnWaitNextFrameForTests(int routing_id) { | 2122 void RenderWidget::OnWaitNextFrameForTests(int routing_id) { |
2092 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id), | 2123 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id), |
2093 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); | 2124 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); |
2094 } | 2125 } |
2095 | 2126 |
2096 } // namespace content | 2127 } // namespace content |
OLD | NEW |