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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 can_compose_inline_(true), | 173 can_compose_inline_(true), |
| 174 popup_type_(popup_type), | 174 popup_type_(popup_type), |
| 175 pending_window_rect_count_(0), | 175 pending_window_rect_count_(0), |
| 176 suppress_next_char_events_(false), | 176 suppress_next_char_events_(false), |
| 177 is_accelerated_compositing_active_(false), | 177 is_accelerated_compositing_active_(false), |
| 178 animation_update_pending_(false), | 178 animation_update_pending_(false), |
| 179 invalidation_task_posted_(false), | 179 invalidation_task_posted_(false), |
| 180 screen_info_(screen_info), | 180 screen_info_(screen_info), |
| 181 device_scale_factor_(screen_info_.deviceScaleFactor), | 181 device_scale_factor_(screen_info_.deviceScaleFactor), |
| 182 is_threaded_compositing_enabled_(false), | 182 is_threaded_compositing_enabled_(false), |
| 183 strict_ime_processing_(false), | |
| 184 outstanding_ime_acknowledgements_(0), | |
| 183 weak_ptr_factory_(this) { | 185 weak_ptr_factory_(this) { |
| 184 if (!swapped_out) | 186 if (!swapped_out) |
| 185 RenderProcess::current()->AddRefProcess(); | 187 RenderProcess::current()->AddRefProcess(); |
| 186 DCHECK(RenderThread::Get()); | 188 DCHECK(RenderThread::Get()); |
| 187 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch( | 189 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 188 switches::kDisableGpuVsync); | 190 switches::kDisableGpuVsync); |
| 189 is_threaded_compositing_enabled_ = | 191 is_threaded_compositing_enabled_ = |
| 190 CommandLine::ForCurrentProcess()->HasSwitch( | 192 CommandLine::ForCurrentProcess()->HasSwitch( |
| 191 switches::kEnableThreadedCompositing); | 193 switches::kEnableThreadedCompositing); |
| 194 strict_ime_processing_ = | |
| 195 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 196 switches::kEnableStrictImeProcessing); | |
| 192 | 197 |
| 193 RenderProcessVisibilityManager::GetInstance()->WidgetVisibilityChanged(true); | 198 RenderProcessVisibilityManager::GetInstance()->WidgetVisibilityChanged(true); |
| 194 } | 199 } |
| 195 | 200 |
| 196 RenderWidget::~RenderWidget() { | 201 RenderWidget::~RenderWidget() { |
| 197 DCHECK(!webwidget_) << "Leaking our WebWidget!"; | 202 DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
| 198 STLDeleteElements(&updates_pending_swap_); | 203 STLDeleteElements(&updates_pending_swap_); |
| 199 if (current_paint_buf_) { | 204 if (current_paint_buf_) { |
| 200 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); | 205 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 201 current_paint_buf_ = NULL; | 206 current_paint_buf_ = NULL; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize) | 338 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize) |
| 334 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) | 339 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) |
| 335 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted) | 340 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted) |
| 336 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 341 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
| 337 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 342 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
| 338 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) | 343 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
| 339 #if defined(OS_ANDROID) | 344 #if defined(OS_ANDROID) |
| 340 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged) | 345 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged) |
| 341 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) | 346 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) |
| 342 #endif | 347 #endif |
| 348 IPC_MESSAGE_HANDLER(ViewMsg_AcknowledgeImeEvent, OnImeAcknowledgeImeEvent) | |
|
aurimas (slooooooooow)
2013/07/08 16:04:49
This Android specific so it should be moved to the
nyquist
2013/07/09 07:47:36
Done.
| |
| 343 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot) | 349 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot) |
| 344 IPC_MESSAGE_HANDLER(ViewMsg_SetBrowserRenderingStats, | 350 IPC_MESSAGE_HANDLER(ViewMsg_SetBrowserRenderingStats, |
| 345 OnSetBrowserRenderingStats) | 351 OnSetBrowserRenderingStats) |
| 346 IPC_MESSAGE_UNHANDLED(handled = false) | 352 IPC_MESSAGE_UNHANDLED(handled = false) |
| 347 IPC_END_MESSAGE_MAP() | 353 IPC_END_MESSAGE_MAP() |
| 348 return handled; | 354 return handled; |
| 349 } | 355 } |
| 350 | 356 |
| 351 bool RenderWidget::Send(IPC::Message* message) { | 357 bool RenderWidget::Send(IPC::Message* message) { |
| 352 // Don't send any messages after the browser has told us to close, and filter | 358 // Don't send any messages after the browser has told us to close, and filter |
| (...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1517 void RenderWidget::willBeginCompositorFrame() { | 1523 void RenderWidget::willBeginCompositorFrame() { |
| 1518 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); | 1524 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); |
| 1519 | 1525 |
| 1520 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy().get()); | 1526 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy().get()); |
| 1521 | 1527 |
| 1522 // The following two can result in further layout and possibly | 1528 // The following two can result in further layout and possibly |
| 1523 // enable GPU acceleration so they need to be called before any painting | 1529 // enable GPU acceleration so they need to be called before any painting |
| 1524 // is done. | 1530 // is done. |
| 1525 UpdateTextInputType(); | 1531 UpdateTextInputType(); |
| 1526 #if defined(OS_ANDROID) | 1532 #if defined(OS_ANDROID) |
| 1527 UpdateTextInputState(DO_NOT_SHOW_IME); | 1533 if (!has_strict_ime_processing()) |
| 1534 UpdateTextInputState(DO_NOT_SHOW_IME); | |
| 1528 #endif | 1535 #endif |
| 1529 UpdateSelectionBounds(); | 1536 UpdateSelectionBounds(); |
| 1530 | 1537 |
| 1531 WillInitiatePaint(); | 1538 WillInitiatePaint(); |
| 1532 } | 1539 } |
| 1533 | 1540 |
| 1534 void RenderWidget::didBecomeReadyForAdditionalInput() { | 1541 void RenderWidget::didBecomeReadyForAdditionalInput() { |
| 1535 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput"); | 1542 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput"); |
| 1536 if (pending_input_event_ack_) | 1543 if (pending_input_event_ack_) |
| 1537 Send(pending_input_event_ack_.release()); | 1544 Send(pending_input_event_ack_.release()); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1763 Send(new ViewHostMsg_ImeCompositionRangeChanged( | 1770 Send(new ViewHostMsg_ImeCompositionRangeChanged( |
| 1764 routing_id(), composition_range_, composition_character_bounds_)); | 1771 routing_id(), composition_range_, composition_character_bounds_)); |
| 1765 } | 1772 } |
| 1766 | 1773 |
| 1767 void RenderWidget::OnImeSetComposition( | 1774 void RenderWidget::OnImeSetComposition( |
| 1768 const string16& text, | 1775 const string16& text, |
| 1769 const std::vector<WebCompositionUnderline>& underlines, | 1776 const std::vector<WebCompositionUnderline>& underlines, |
| 1770 int selection_start, int selection_end) { | 1777 int selection_start, int selection_end) { |
| 1771 if (!webwidget_) | 1778 if (!webwidget_) |
| 1772 return; | 1779 return; |
| 1780 if (HasOutstandingImeEventAcknowledgements()) | |
| 1781 return; | |
|
kochi
2013/07/08 04:28:43
Can you add #if defined(OS_ANDROID) around this?
nyquist
2013/07/09 07:47:36
Done.
| |
| 1773 ImeEventGuard guard(this); | 1782 ImeEventGuard guard(this); |
| 1774 if (!webwidget_->setComposition( | 1783 if (!webwidget_->setComposition( |
| 1775 text, WebVector<WebCompositionUnderline>(underlines), | 1784 text, WebVector<WebCompositionUnderline>(underlines), |
| 1776 selection_start, selection_end)) { | 1785 selection_start, selection_end)) { |
| 1777 // If we failed to set the composition text, then we need to let the browser | 1786 // If we failed to set the composition text, then we need to let the browser |
| 1778 // process to cancel the input method's ongoing composition session, to make | 1787 // process to cancel the input method's ongoing composition session, to make |
| 1779 // sure we are in a consistent state. | 1788 // sure we are in a consistent state. |
| 1780 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); | 1789 Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 1781 } | 1790 } |
| 1782 UpdateCompositionInfo(true); | 1791 UpdateCompositionInfo(true); |
| 1783 } | 1792 } |
| 1784 | 1793 |
| 1785 void RenderWidget::OnImeConfirmComposition( | 1794 void RenderWidget::OnImeConfirmComposition( |
| 1786 const string16& text, const ui::Range& replacement_range) { | 1795 const string16& text, const ui::Range& replacement_range) { |
| 1787 if (!webwidget_) | 1796 if (!webwidget_) |
| 1788 return; | 1797 return; |
| 1798 if (HasOutstandingImeEventAcknowledgements()) | |
| 1799 return; | |
|
kochi
2013/07/08 04:28:43
Ditto.
nyquist
2013/07/09 07:47:36
Done.
| |
| 1789 ImeEventGuard guard(this); | 1800 ImeEventGuard guard(this); |
| 1790 handling_input_event_ = true; | 1801 handling_input_event_ = true; |
| 1791 webwidget_->confirmComposition(text); | 1802 webwidget_->confirmComposition(text); |
| 1792 handling_input_event_ = false; | 1803 handling_input_event_ = false; |
| 1793 UpdateCompositionInfo(true); | 1804 UpdateCompositionInfo(true); |
| 1794 } | 1805 } |
| 1795 | 1806 |
| 1796 // This message causes the renderer to render an image of the | 1807 // This message causes the renderer to render an image of the |
| 1797 // desired_size, regardless of whether the tab is hidden or not. | 1808 // desired_size, regardless of whether the tab is hidden or not. |
| 1798 void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle, | 1809 void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1955 } | 1966 } |
| 1956 | 1967 |
| 1957 #if defined(OS_ANDROID) | 1968 #if defined(OS_ANDROID) |
| 1958 void RenderWidget::OnImeBatchStateChanged(bool is_begin) { | 1969 void RenderWidget::OnImeBatchStateChanged(bool is_begin) { |
| 1959 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin)); | 1970 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin)); |
| 1960 } | 1971 } |
| 1961 | 1972 |
| 1962 void RenderWidget::OnShowImeIfNeeded() { | 1973 void RenderWidget::OnShowImeIfNeeded() { |
| 1963 UpdateTextInputState(SHOW_IME_IF_NEEDED); | 1974 UpdateTextInputState(SHOW_IME_IF_NEEDED); |
| 1964 } | 1975 } |
| 1965 #endif | 1976 #endif |
|
kochi
2013/07/08 04:28:43
Can you move this line below the following added s
nyquist
2013/07/09 07:47:36
Done.
| |
| 1966 | 1977 |
| 1978 void RenderWidget::IncrementOutstandingImeEventAcknowledgements() { | |
| 1979 if (has_strict_ime_processing()) | |
| 1980 outstanding_ime_acknowledgements_++; | |
|
kochi
2013/07/08 04:28:43
I thought we use pre-increment style in general, e
nyquist
2013/07/09 07:47:36
Done.
| |
| 1981 } | |
| 1982 | |
| 1983 void RenderWidget::OnImeAcknowledgeImeEvent() { | |
| 1984 if (has_strict_ime_processing()) { | |
| 1985 outstanding_ime_acknowledgements_--; | |
|
kochi
2013/07/08 04:28:43
Ditto.
nyquist
2013/07/09 07:47:36
Done.
| |
| 1986 DCHECK(outstanding_ime_acknowledgements_ >= 0); | |
| 1987 } | |
| 1988 } | |
| 1989 | |
| 1990 bool RenderWidget::HasOutstandingImeEventAcknowledgements() { | |
| 1991 return has_strict_ime_processing() && outstanding_ime_acknowledgements_ > 0; | |
| 1992 } | |
| 1993 | |
| 1967 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { | 1994 void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { |
| 1968 if (device_scale_factor_ == device_scale_factor) | 1995 if (device_scale_factor_ == device_scale_factor) |
| 1969 return; | 1996 return; |
| 1970 | 1997 |
| 1971 device_scale_factor_ = device_scale_factor; | 1998 device_scale_factor_ = device_scale_factor; |
| 1972 | 1999 |
| 1973 if (!is_accelerated_compositing_active_) { | 2000 if (!is_accelerated_compositing_active_) { |
| 1974 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); | 2001 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
| 1975 } else { | 2002 } else { |
| 1976 scheduleComposite(); | 2003 scheduleComposite(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2069 } | 2096 } |
| 2070 | 2097 |
| 2071 void RenderWidget::FinishHandlingImeEvent() { | 2098 void RenderWidget::FinishHandlingImeEvent() { |
| 2072 DCHECK(handling_ime_event_); | 2099 DCHECK(handling_ime_event_); |
| 2073 handling_ime_event_ = false; | 2100 handling_ime_event_ = false; |
| 2074 // While handling an ime event, text input state and selection bounds updates | 2101 // While handling an ime event, text input state and selection bounds updates |
| 2075 // are ignored. These must explicitly be updated once finished handling the | 2102 // are ignored. These must explicitly be updated once finished handling the |
| 2076 // ime event. | 2103 // ime event. |
| 2077 UpdateSelectionBounds(); | 2104 UpdateSelectionBounds(); |
| 2078 #if defined(OS_ANDROID) | 2105 #if defined(OS_ANDROID) |
| 2079 UpdateTextInputState(DO_NOT_SHOW_IME); | 2106 if (!has_strict_ime_processing()) |
| 2107 UpdateTextInputState(DO_NOT_SHOW_IME); | |
| 2080 #endif | 2108 #endif |
| 2081 } | 2109 } |
| 2082 | 2110 |
| 2083 void RenderWidget::UpdateTextInputType() { | 2111 void RenderWidget::UpdateTextInputType() { |
| 2084 if (!input_method_is_active_) | 2112 if (!input_method_is_active_) |
| 2085 return; | 2113 return; |
| 2086 | 2114 |
| 2087 ui::TextInputType new_type = GetTextInputType(); | 2115 ui::TextInputType new_type = GetTextInputType(); |
| 2088 if (IsDateTimeInput(new_type)) | 2116 if (IsDateTimeInput(new_type)) |
| 2089 return; // Not considered as a text input field in WebKit/Chromium. | 2117 return; // Not considered as a text input field in WebKit/Chromium. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2124 || can_compose_inline_ != new_can_compose_inline)) { | 2152 || can_compose_inline_ != new_can_compose_inline)) { |
| 2125 ViewHostMsg_TextInputState_Params p; | 2153 ViewHostMsg_TextInputState_Params p; |
| 2126 p.type = new_type; | 2154 p.type = new_type; |
| 2127 p.value = new_info.value.utf8(); | 2155 p.value = new_info.value.utf8(); |
| 2128 p.selection_start = new_info.selectionStart; | 2156 p.selection_start = new_info.selectionStart; |
| 2129 p.selection_end = new_info.selectionEnd; | 2157 p.selection_end = new_info.selectionEnd; |
| 2130 p.composition_start = new_info.compositionStart; | 2158 p.composition_start = new_info.compositionStart; |
| 2131 p.composition_end = new_info.compositionEnd; | 2159 p.composition_end = new_info.compositionEnd; |
| 2132 p.can_compose_inline = new_can_compose_inline; | 2160 p.can_compose_inline = new_can_compose_inline; |
| 2133 p.show_ime_if_needed = show_ime_if_needed; | 2161 p.show_ime_if_needed = show_ime_if_needed; |
| 2162 IncrementOutstandingImeEventAcknowledgements(); | |
| 2134 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p)); | 2163 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p)); |
| 2135 | 2164 |
| 2136 text_input_info_ = new_info; | 2165 text_input_info_ = new_info; |
| 2137 text_input_type_ = new_type; | 2166 text_input_type_ = new_type; |
| 2138 can_compose_inline_ = new_can_compose_inline; | 2167 can_compose_inline_ = new_can_compose_inline; |
| 2139 } | 2168 } |
| 2140 } | 2169 } |
| 2141 #endif | 2170 #endif |
| 2142 | 2171 |
| 2143 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { | 2172 void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2408 | 2437 |
| 2409 if (!context->InitializeWithDefaultBufferSizes( | 2438 if (!context->InitializeWithDefaultBufferSizes( |
| 2410 attributes, | 2439 attributes, |
| 2411 false /* bind generates resources */, | 2440 false /* bind generates resources */, |
| 2412 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE) ) | 2441 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE) ) |
| 2413 return NULL; | 2442 return NULL; |
| 2414 return context.release(); | 2443 return context.release(); |
| 2415 } | 2444 } |
| 2416 | 2445 |
| 2417 } // namespace content | 2446 } // namespace content |
| OLD | NEW |