Chrome in Mus: Main thread input events work!
This CL plumbs input events from RenderWidgetMusConnection to RenderWidgetInputHandler and plumbs input ACKs back along that same path.
BUG=568864
Review URL: https://codereview.chromium.org/1531473002
Cr-Commit-Position: refs/heads/master@{#368740}
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 8366d6c..a541369 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -177,6 +177,20 @@
type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
}
+content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
+ content::RenderWidget* widget) {
+#if defined(MOJO_SHELL_CLIENT)
+ if (content::MojoShellConnection::Get()) {
+ return content::RenderWidgetMusConnection::GetOrCreate(
+ widget->routing_id());
+ }
+#endif
+ // If we don't have a connection to the Mojo shell, then we want to route IPCs
+ // back to the browser process rather than Mus so we use the |widget| as the
+ // RenderWidgetInputHandlerDelegate.
+ return widget;
+}
+
} // namespace
namespace content {
@@ -448,7 +462,6 @@
can_compose_inline_(true),
popup_type_(popup_type),
pending_window_rect_count_(0),
- input_handler_(this, this),
screen_info_(screen_info),
device_scale_factor_(screen_info_.deviceScaleFactor),
next_output_surface_id_(0),
@@ -517,7 +530,7 @@
scoped_refptr<RenderWidget> widget(
new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
false, hidden, false));
- widget->routing_id_ = routing_id;
+ widget->SetRoutingID(routing_id);
widget->for_oopif_ = true;
// DoInit increments the reference count on |widget|, keeping it alive after
// this function returns.
@@ -558,10 +571,21 @@
OnClose();
}
+void RenderWidget::SetRoutingID(int32_t routing_id) {
+ routing_id_ = routing_id;
+ input_handler_.reset(new RenderWidgetInputHandler(
+ GetRenderWidgetInputHandlerDelegate(this), this));
+}
+
bool RenderWidget::Init(int32_t opener_id) {
- return DoInit(
+ bool success = DoInit(
opener_id, RenderWidget::CreateWebWidget(this),
new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
+ if (success) {
+ SetRoutingID(routing_id_);
+ return true;
+ }
+ return false;
}
bool RenderWidget::DoInit(int32_t opener_id,
@@ -588,6 +612,7 @@
if (is_hidden_)
RenderThreadImpl::current()->WidgetHidden();
}
+
return true;
} else {
// The above Send can fail when the tab is closing.
@@ -1030,7 +1055,7 @@
const ui::LatencyInfo& latency_info) {
if (!input_event)
return;
- input_handler_.HandleInputEvent(*input_event, latency_info);
+ input_handler_->HandleInputEvent(*input_event, latency_info);
}
void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
@@ -1088,6 +1113,13 @@
Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
}
+void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
+ // Nothing to do here. RenderWidget created the |input_handler| and will take
+ // ownership of it. We just verify here that we don't already have an input
+ // handler.
+ DCHECK(!input_handler_);
+}
+
void RenderWidget::UpdateTextInputState(ShowIme show_ime,
ChangeSource change_source) {
TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
@@ -1252,7 +1284,7 @@
FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
DidCommitCompositorFrame());
#endif // defined(VIDEO_HOLE)
- input_handler_.FlushPendingInputEventAck();
+ input_handler_->FlushPendingInputEventAck();
}
void RenderWidget::DidCommitAndDrawCompositorFrame() {
@@ -1521,14 +1553,14 @@
if (!ShouldHandleImeEvent())
return;
ImeEventGuard guard(this);
- input_handler_.set_handling_input_event(true);
+ input_handler_->set_handling_input_event(true);
if (text.length())
webwidget_->confirmComposition(text);
else if (keep_selection)
webwidget_->confirmComposition(WebWidget::KeepSelection);
else
webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
- input_handler_.set_handling_input_event(false);
+ input_handler_->set_handling_input_event(false);
UpdateCompositionInfo(true);
}
@@ -1726,7 +1758,7 @@
// The status has changed. Tell the RenderThread about it and ensure
// throttled acks are released in case frame production ceases.
is_hidden_ = hidden;
- input_handler_.FlushPendingInputEventAck();
+ input_handler_->FlushPendingInputEventAck();
if (is_hidden_)
RenderThreadImpl::current()->WidgetHidden();
@@ -1933,7 +1965,7 @@
const WebPoint& tapped_position,
const WebNode& tapped_node,
bool page_changed) {
- DCHECK(input_handler_.handling_input_event());
+ DCHECK(input_handler_->handling_input_event());
bool should_trigger = !page_changed && tapped_node.isTextNode() &&
!tapped_node.isContentEditable() &&
!tapped_node.isInsideFocusableElementOrARIAWidget();
@@ -1967,8 +1999,8 @@
const blink::WebFloatSize& accumulatedRootOverScroll,
const blink::WebFloatPoint& position,
const blink::WebFloatSize& velocity) {
- input_handler_.DidOverscrollFromBlink(unusedDelta, accumulatedRootOverScroll,
- position, velocity);
+ input_handler_->DidOverscrollFromBlink(unusedDelta, accumulatedRootOverScroll,
+ position, velocity);
}
void RenderWidget::StartCompositor() {
@@ -2009,15 +2041,15 @@
}
void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
- input_handler_.set_handling_input_event(handling_input_event);
+ input_handler_->set_handling_input_event(handling_input_event);
}
bool RenderWidget::SendAckForMouseMoveFromDebugger() {
- return input_handler_.SendAckForMouseMoveFromDebugger();
+ return input_handler_->SendAckForMouseMoveFromDebugger();
}
void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
- input_handler_.IgnoreAckForMouseMoveFromDebugger();
+ input_handler_->IgnoreAckForMouseMoveFromDebugger();
}
void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
@@ -2036,7 +2068,7 @@
// Ignore setTouchAction calls that result from synthetic touch events (eg.
// when blink is emulating touch with mouse).
- if (input_handler_.handling_event_type() != WebInputEvent::TouchStart)
+ if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
return;
// Verify the same values are used by the types so we can cast between them.