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

Side by Side Diff: content/renderer/input/target_frame_for_input_impl.cc

Issue 2951053005: Add Mojo API for Blink hit testing (Closed)
Patch Set: Address Rob's comments Created 3 years, 4 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/input/target_frame_for_input_impl.h"
6
7 #include "base/bind.h"
8 #include "base/debug/stack_trace.h"
9 #include "base/logging.h"
10 #include "content/renderer/render_widget.h"
11
12 namespace content {
13
14 TargetFrameForInputImpl::TargetFrameForInputImpl(
15 base::WeakPtr<RenderFrameImpl> render_frame,
16 viz::mojom::TargetFrameForInputDelegateRequest request)
17 : binding_(this),
18 render_frame_(render_frame),
19 input_event_queue_(render_frame->GetRenderWidget()->GetInputEventQueue()),
20 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
21 weak_ptr_factory_(this)
22
23 {
24 weak_this_ = weak_ptr_factory_.GetWeakPtr();
25 // If we have created an input event queue move the mojo request over to the
26 // compositor thread.
27 if (RenderThreadImpl::current()->compositor_task_runner() &&
28 input_event_queue_) {
29 // Mojo channel bound on compositor thread.
30 RenderThreadImpl::current()->compositor_task_runner()->PostTask(
31 FROM_HERE, base::BindOnce(&TargetFrameForInputImpl::BindNow,
32 base::Unretained(this), std::move(request)));
33 } else {
34 // Mojo channel bound on main thread.
35 BindNow(std::move(request));
36 }
37 }
38
39 TargetFrameForInputImpl::~TargetFrameForInputImpl() {}
40
41 // static
42 void TargetFrameForInputImpl::CreateMojoService(
43 base::WeakPtr<RenderFrameImpl> render_frame,
44 viz::mojom::TargetFrameForInputDelegateRequest request) {
45 DCHECK(render_frame);
46
47 // Owns itself. Will be deleted when message pipe is destroyed.
48 new TargetFrameForInputImpl(render_frame, std::move(request));
49 }
50
51 void TargetFrameForInputImpl::RunOnMainThread(base::OnceClosure closure) {
52 if (input_event_queue_) {
53 input_event_queue_->QueueClosure(std::move(closure));
54 } else {
55 std::move(closure).Run();
56 }
57 }
58
59 void TargetFrameForInputImpl::HitTestFrameAt(const gfx::Point& point,
60 HitTestFrameAtCallback callback) {
61 if (!main_thread_task_runner_->BelongsToCurrentThread()) {
62 RunOnMainThread(
63 base::BindOnce(&TargetFrameForInputImpl::HitTestOnMainThread,
64 weak_this_, point, std::move(callback)));
65 return;
66 }
67 if (!render_frame_)
68 return;
69 HitTestOnMainThread(point, std::move(callback));
70 }
71
72 void TargetFrameForInputImpl::HitTestOnMainThread(
73 const gfx::Point& point,
74 HitTestFrameAtCallback callback) {
75 std::move(callback).Run(
76 render_frame_->GetRenderWidget()->HitTestFrameAt(point));
77 }
78
79 void TargetFrameForInputImpl::Release() {
80 if (!main_thread_task_runner_->BelongsToCurrentThread()) {
81 // Close the binding on the compositor thread first before telling the main
82 // thread to delete this object.
83 binding_.Close();
84 main_thread_task_runner_->PostTask(
85 FROM_HERE, base::Bind(&TargetFrameForInputImpl::Release, weak_this_));
86 return;
87 }
88 delete this;
89 }
90
91 void TargetFrameForInputImpl::BindNow(
92 viz::mojom::TargetFrameForInputDelegateRequest request) {
93 binding_.Bind(std::move(request));
94 binding_.set_connection_error_handler(
95 base::Bind(&TargetFrameForInputImpl::Release, base::Unretained(this)));
96 }
97
98 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/input/target_frame_for_input_impl.h ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698