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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) | 470 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) |
471 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) | 471 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) |
472 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 472 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
473 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 473 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
474 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) | 474 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
475 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace) | 475 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace) |
476 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, | 476 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, |
477 OnWaitNextFrameForTests) | 477 OnWaitNextFrameForTests) |
478 #if defined(OS_ANDROID) | 478 #if defined(OS_ANDROID) |
479 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) | 479 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) |
| 480 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, |
| 481 OnRequestTextInputStateUpdate) |
480 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) | 482 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) |
481 #endif | 483 #endif |
482 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) | 484 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) |
483 IPC_MESSAGE_UNHANDLED(handled = false) | 485 IPC_MESSAGE_UNHANDLED(handled = false) |
484 IPC_END_MESSAGE_MAP() | 486 IPC_END_MESSAGE_MAP() |
485 return handled; | 487 return handled; |
486 } | 488 } |
487 | 489 |
488 bool RenderWidget::Send(IPC::Message* message) { | 490 bool RenderWidget::Send(IPC::Message* message) { |
489 // Don't send any messages after the browser has told us to close, and filter | 491 // Don't send any messages after the browser has told us to close, and filter |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 blink::WebTextInputInfo new_info; | 987 blink::WebTextInputInfo new_info; |
986 if (webwidget_) | 988 if (webwidget_) |
987 new_info = webwidget_->textInputInfo(); | 989 new_info = webwidget_->textInputInfo(); |
988 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); | 990 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); |
989 | 991 |
990 bool new_can_compose_inline = CanComposeInline(); | 992 bool new_can_compose_inline = CanComposeInline(); |
991 | 993 |
992 // Only sends text input params if they are changed or if the ime should be | 994 // Only sends text input params if they are changed or if the ime should be |
993 // shown. | 995 // shown. |
994 if (show_ime == ShowIme::IF_NEEDED || | 996 if (show_ime == ShowIme::IF_NEEDED || |
| 997 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) || |
995 (text_input_type_ != new_type || text_input_mode_ != new_mode || | 998 (text_input_type_ != new_type || text_input_mode_ != new_mode || |
996 text_input_info_ != new_info || | 999 text_input_info_ != new_info || |
997 can_compose_inline_ != new_can_compose_inline) | 1000 can_compose_inline_ != new_can_compose_inline) |
998 #if defined(OS_ANDROID) | 1001 #if defined(OS_ANDROID) |
999 || text_field_is_dirty_ | 1002 || text_field_is_dirty_ |
1000 #endif | 1003 #endif |
1001 ) { | 1004 ) { |
1002 ViewHostMsg_TextInputState_Params params; | 1005 ViewHostMsg_TextInputState_Params params; |
1003 params.type = new_type; | 1006 params.type = new_type; |
1004 params.mode = new_mode; | 1007 params.mode = new_mode; |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 | 1591 |
1589 #if defined(OS_ANDROID) | 1592 #if defined(OS_ANDROID) |
1590 void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) { | 1593 void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) { |
1591 text_input_info_history_.push_back(info); | 1594 text_input_info_history_.push_back(info); |
1592 } | 1595 } |
1593 | 1596 |
1594 void RenderWidget::OnImeEventAck() { | 1597 void RenderWidget::OnImeEventAck() { |
1595 DCHECK_GE(text_input_info_history_.size(), 1u); | 1598 DCHECK_GE(text_input_info_history_.size(), 1u); |
1596 text_input_info_history_.pop_front(); | 1599 text_input_info_history_.pop_front(); |
1597 } | 1600 } |
| 1601 |
| 1602 void RenderWidget::OnRequestTextInputStateUpdate() { |
| 1603 DCHECK(!ime_event_guard_); |
| 1604 UpdateSelectionBounds(); |
| 1605 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME); |
| 1606 } |
1598 #endif | 1607 #endif |
1599 | 1608 |
1600 bool RenderWidget::ShouldHandleImeEvent() { | 1609 bool RenderWidget::ShouldHandleImeEvent() { |
1601 #if defined(OS_ANDROID) | 1610 #if defined(OS_ANDROID) |
1602 if (!webwidget_) | 1611 if (!webwidget_) |
1603 return false; | 1612 return false; |
| 1613 if (IsUsingImeThread()) |
| 1614 return true; |
1604 | 1615 |
1605 // We cannot handle IME events if there is any chance that the event we are | 1616 // We cannot handle IME events if there is any chance that the event we are |
1606 // receiving here from the browser is based on the state that is different | 1617 // receiving here from the browser is based on the state that is different |
1607 // from our current one as indicated by |text_input_info_|. | 1618 // from our current one as indicated by |text_input_info_|. |
1608 // The states the browser might be in are: | 1619 // The states the browser might be in are: |
1609 // text_input_info_history_[0] - current state ack'd by browser | 1620 // text_input_info_history_[0] - current state ack'd by browser |
1610 // text_input_info_history_[1...N] - pending state changes | 1621 // text_input_info_history_[1...N] - pending state changes |
1611 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) { | 1622 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) { |
1612 if (text_input_info_history_[i] != text_input_info_) | 1623 if (text_input_info_history_[i] != text_input_info_) |
1613 return false; | 1624 return false; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 } | 1697 } |
1687 | 1698 |
1688 void RenderWidget::set_next_paint_is_resize_ack() { | 1699 void RenderWidget::set_next_paint_is_resize_ack() { |
1689 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; | 1700 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
1690 } | 1701 } |
1691 | 1702 |
1692 void RenderWidget::set_next_paint_is_repaint_ack() { | 1703 void RenderWidget::set_next_paint_is_repaint_ack() { |
1693 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; | 1704 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; |
1694 } | 1705 } |
1695 | 1706 |
| 1707 bool RenderWidget::IsUsingImeThread() { |
| 1708 #if defined(OS_ANDROID) |
| 1709 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1710 switches::kEnableImeThread) && |
| 1711 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1712 switches::kDisableImeThread); |
| 1713 #else |
| 1714 return false; |
| 1715 #endif |
| 1716 } |
| 1717 |
1696 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { | 1718 void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { |
1697 if (!ime_event_guard_) | 1719 if (!ime_event_guard_) |
1698 ime_event_guard_ = guard; | 1720 ime_event_guard_ = guard; |
1699 } | 1721 } |
1700 | 1722 |
1701 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { | 1723 void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { |
1702 if (ime_event_guard_ != guard) { | 1724 if (ime_event_guard_ != guard) { |
1703 #if defined(OS_ANDROID) | 1725 #if defined(OS_ANDROID) |
1704 // In case a from-IME event (e.g. touch) ends up in not-from-IME event | 1726 // In case a from-IME event (e.g. touch) ends up in not-from-IME event |
1705 // (e.g. long press gesture), we want to treat it as not-from-IME event | 1727 // (e.g. long press gesture), we want to treat it as not-from-IME event |
1706 // so that AdapterInputConnection can make changes to its Editable model. | 1728 // so that ReplicaInputConnection can make changes to its Editable model. |
1707 // Therefore, we want to mark this text state update as 'from IME' only | 1729 // Therefore, we want to mark this text state update as 'from IME' only |
1708 // when all the nested events are all originating from IME. | 1730 // when all the nested events are all originating from IME. |
1709 ime_event_guard_->set_from_ime( | 1731 ime_event_guard_->set_from_ime( |
1710 ime_event_guard_->from_ime() && guard->from_ime()); | 1732 ime_event_guard_->from_ime() && guard->from_ime()); |
1711 #endif | 1733 #endif |
1712 return; | 1734 return; |
1713 } | 1735 } |
1714 ime_event_guard_ = nullptr; | 1736 ime_event_guard_ = nullptr; |
1715 | 1737 |
1716 // While handling an ime event, text input state and selection bounds updates | 1738 // 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... |
1981 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart) | 2003 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart) |
1982 return; | 2004 return; |
1983 | 2005 |
1984 content::TouchAction content_touch_action = | 2006 content::TouchAction content_touch_action = |
1985 static_cast<content::TouchAction>(web_touch_action); | 2007 static_cast<content::TouchAction>(web_touch_action); |
1986 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action)); | 2008 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action)); |
1987 } | 2009 } |
1988 | 2010 |
1989 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() { | 2011 void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() { |
1990 #if defined(OS_ANDROID) | 2012 #if defined(OS_ANDROID) |
1991 text_field_is_dirty_ = true; | 2013 if (!IsUsingImeThread()) |
| 2014 text_field_is_dirty_ = true; |
1992 #endif | 2015 #endif |
1993 } | 2016 } |
1994 | 2017 |
1995 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 2018 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
1996 RenderWidget::CreateGraphicsContext3D(GpuChannelHost* gpu_channel_host) { | 2019 RenderWidget::CreateGraphicsContext3D(GpuChannelHost* gpu_channel_host) { |
1997 // Explicitly disable antialiasing for the compositor. As of the time of | 2020 // Explicitly disable antialiasing for the compositor. As of the time of |
1998 // this writing, the only platform that supported antialiasing for the | 2021 // this writing, the only platform that supported antialiasing for the |
1999 // compositor was Mac OS X, because the on-screen OpenGL context creation | 2022 // compositor was Mac OS X, because the on-screen OpenGL context creation |
2000 // code paths on Windows and Linux didn't yet have multisampling support. | 2023 // code paths on Windows and Linux didn't yet have multisampling support. |
2001 // Mac OS X essentially always behaves as though it's rendering offscreen. | 2024 // 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... |
2075 video_hole_frames_.RemoveObserver(frame); | 2098 video_hole_frames_.RemoveObserver(frame); |
2076 } | 2099 } |
2077 #endif // defined(VIDEO_HOLE) | 2100 #endif // defined(VIDEO_HOLE) |
2078 | 2101 |
2079 void RenderWidget::OnWaitNextFrameForTests(int routing_id) { | 2102 void RenderWidget::OnWaitNextFrameForTests(int routing_id) { |
2080 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id), | 2103 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id), |
2081 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); | 2104 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); |
2082 } | 2105 } |
2083 | 2106 |
2084 } // namespace content | 2107 } // namespace content |
OLD | NEW |