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

Side by Side Diff: content/browser/renderer_host/render_widget_host_input_event_router.cc

Issue 1545683002: Use WeakPtr to RenderWidgetHostViewBase in InputEventRouter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_input_event_router.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/browser/renderer_host/render_widget_host_input_event_router.h" 5 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
6 6
7 #include "cc/surfaces/surface_manager.h" 7 #include "cc/surfaces/surface_manager.h"
8 #include "content/browser/renderer_host/render_widget_host_view_base.h" 8 #include "content/browser/renderer_host/render_widget_host_view_base.h"
9 #include "third_party/WebKit/public/web/WebInputEvent.h" 9 #include "third_party/WebKit/public/web/WebInputEvent.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter() 13 RenderWidgetHostInputEventRouter::RenderWidgetHostInputEventRouter()
14 : current_touch_target_(nullptr), active_touches_(0) {} 14 : has_current_touch_target_(false), active_touches_(0) {}
15 15
16 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() { 16 RenderWidgetHostInputEventRouter::~RenderWidgetHostInputEventRouter() {
17 owner_map_.clear(); 17 owner_map_.clear();
18 } 18 }
19 19
20 RenderWidgetHostViewBase* RenderWidgetHostInputEventRouter::FindEventTarget( 20 RenderWidgetHostInputEventRouter::WeakTarget
nasko 2015/12/22 18:16:33 Why does this method need to return the WeakTarget
wjmaclean 2015/12/22 18:39:55 It doesn't have to return the WeakPtr ... I'll cha
21 RenderWidgetHostInputEventRouter::FindEventTarget(
21 RenderWidgetHostViewBase* root_view, 22 RenderWidgetHostViewBase* root_view,
22 const gfx::Point& point, 23 const gfx::Point& point,
23 gfx::Point* transformed_point) { 24 gfx::Point* transformed_point) {
24 // Short circuit if owner_map has only one RenderWidgetHostView, no need for 25 // Short circuit if owner_map has only one RenderWidgetHostView, no need for
25 // hit testing. 26 // hit testing.
26 if (owner_map_.size() <= 1) { 27 if (owner_map_.size() <= 1) {
27 *transformed_point = point; 28 *transformed_point = point;
28 return root_view; 29 return root_view->GetWeakPtr();
29 } 30 }
30 31
31 // The conversion of point to transform_point is done over the course of the 32 // The conversion of point to transform_point is done over the course of the
32 // hit testing, and reflect transformations that would normally be applied in 33 // hit testing, and reflect transformations that would normally be applied in
33 // the renderer process if the event was being routed between frames within a 34 // the renderer process if the event was being routed between frames within a
34 // single process with only one RenderWidgetHost. 35 // single process with only one RenderWidgetHost.
35 uint32_t surface_id_namespace = 36 uint32_t surface_id_namespace =
36 root_view->SurfaceIdNamespaceAtPoint(point, transformed_point); 37 root_view->SurfaceIdNamespaceAtPoint(point, transformed_point);
37 const SurfaceIdNamespaceOwnerMap::iterator iter = 38 const SurfaceIdNamespaceOwnerMap::iterator iter =
38 owner_map_.find(surface_id_namespace); 39 owner_map_.find(surface_id_namespace);
39 // If the point hit a Surface whose namspace is no longer in the map, then 40 // If the point hit a Surface whose namspace is no longer in the map, then
40 // it likely means the RenderWidgetHostView has been destroyed but its 41 // it likely means the RenderWidgetHostView has been destroyed but its
41 // parent frame has not sent a new compositor frame since that happened. 42 // parent frame has not sent a new compositor frame since that happened.
42 if (iter == owner_map_.end()) 43 if (iter == owner_map_.end())
43 return root_view; 44 return root_view->GetWeakPtr();
44 return iter->second; 45 return iter->second;
45 } 46 }
46 47
47 void RenderWidgetHostInputEventRouter::RouteMouseEvent( 48 void RenderWidgetHostInputEventRouter::RouteMouseEvent(
48 RenderWidgetHostViewBase* root_view, 49 RenderWidgetHostViewBase* root_view,
49 blink::WebMouseEvent* event) { 50 blink::WebMouseEvent* event) {
50 gfx::Point transformed_point; 51 gfx::Point transformed_point;
51 RenderWidgetHostViewBase* target = FindEventTarget( 52 WeakTarget target = FindEventTarget(root_view, gfx::Point(event->x, event->y),
52 root_view, gfx::Point(event->x, event->y), &transformed_point); 53 &transformed_point);
53 event->x = transformed_point.x(); 54 event->x = transformed_point.x();
54 event->y = transformed_point.y(); 55 event->y = transformed_point.y();
55 56
56 target->ProcessMouseEvent(*event); 57 if (target)
nasko 2015/12/22 18:16:33 Let'd use early returns - if (!target) return, rig
wjmaclean 2015/12/22 18:39:55 Done.
58 target->ProcessMouseEvent(*event);
57 } 59 }
58 60
59 void RenderWidgetHostInputEventRouter::RouteMouseWheelEvent( 61 void RenderWidgetHostInputEventRouter::RouteMouseWheelEvent(
60 RenderWidgetHostViewBase* root_view, 62 RenderWidgetHostViewBase* root_view,
61 blink::WebMouseWheelEvent* event) { 63 blink::WebMouseWheelEvent* event) {
62 gfx::Point transformed_point; 64 gfx::Point transformed_point;
63 RenderWidgetHostViewBase* target = FindEventTarget( 65 WeakTarget target = FindEventTarget(root_view, gfx::Point(event->x, event->y),
64 root_view, gfx::Point(event->x, event->y), &transformed_point); 66 &transformed_point);
65 event->x = transformed_point.x(); 67 event->x = transformed_point.x();
66 event->y = transformed_point.y(); 68 event->y = transformed_point.y();
67 69
68 target->ProcessMouseWheelEvent(*event); 70 if (target)
nasko 2015/12/22 18:16:33 Same as above, early return.
wjmaclean 2015/12/22 18:39:55 Done.
71 target->ProcessMouseWheelEvent(*event);
69 } 72 }
70 73
71 void RenderWidgetHostInputEventRouter::RouteTouchEvent( 74 void RenderWidgetHostInputEventRouter::RouteTouchEvent(
72 RenderWidgetHostViewBase* root_view, 75 RenderWidgetHostViewBase* root_view,
73 blink::WebTouchEvent* event, 76 blink::WebTouchEvent* event,
74 const ui::LatencyInfo& latency) { 77 const ui::LatencyInfo& latency) {
75 switch (event->type) { 78 switch (event->type) {
76 case blink::WebInputEvent::TouchStart: { 79 case blink::WebInputEvent::TouchStart: {
77 if (!active_touches_) { 80 if (!active_touches_) {
78 // Since this is the first touch, it defines the target for the rest 81 // Since this is the first touch, it defines the target for the rest
79 // of this sequence. 82 // of this sequence.
80 DCHECK(!current_touch_target_); 83 DCHECK(!current_touch_target_);
81 gfx::Point transformed_point; 84 gfx::Point transformed_point;
82 gfx::Point original_point(event->touches[0].position.x, 85 gfx::Point original_point(event->touches[0].position.x,
83 event->touches[0].position.y); 86 event->touches[0].position.y);
84 current_touch_target_ = 87 current_touch_target_ =
85 FindEventTarget(root_view, original_point, &transformed_point); 88 FindEventTarget(root_view, original_point, &transformed_point);
nasko 2015/12/22 18:16:33 You could just call ->GetWeakPtr() here, since it
wjmaclean 2015/12/22 18:39:55 I don't understand? You mean call it on current_to
89 has_current_touch_target_ = true;
Fady Samuel 2015/12/22 18:06:43 Is this flag necessary? It seems you only use it f
86 } 90 }
87 ++active_touches_; 91 ++active_touches_;
88 current_touch_target_->ProcessTouchEvent(*event, latency); 92 if (current_touch_target_.get())
93 current_touch_target_->ProcessTouchEvent(*event, latency);
89 break; 94 break;
90 } 95 }
91 case blink::WebInputEvent::TouchMove: 96 case blink::WebInputEvent::TouchMove:
92 DCHECK(current_touch_target_); 97 DCHECK(has_current_touch_target_);
93 current_touch_target_->ProcessTouchEvent(*event, latency); 98 if (current_touch_target_.get())
99 current_touch_target_->ProcessTouchEvent(*event, latency);
94 break; 100 break;
95 case blink::WebInputEvent::TouchEnd: 101 case blink::WebInputEvent::TouchEnd:
96 case blink::WebInputEvent::TouchCancel: 102 case blink::WebInputEvent::TouchCancel:
97 DCHECK(active_touches_); 103 DCHECK(active_touches_);
98 DCHECK(current_touch_target_); 104 DCHECK(has_current_touch_target_);
99 current_touch_target_->ProcessTouchEvent(*event, latency); 105 if (current_touch_target_.get())
106 current_touch_target_->ProcessTouchEvent(*event, latency);
100 --active_touches_; 107 --active_touches_;
101 if (!active_touches_) 108 if (!active_touches_) {
102 current_touch_target_ = nullptr; 109 current_touch_target_ = WeakTarget();
110 has_current_touch_target_ = false;
111 }
103 break; 112 break;
104 default: 113 default:
105 NOTREACHED(); 114 NOTREACHED();
106 } 115 }
107 } 116 }
108 117
109 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner( 118 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner(
110 uint32_t id, 119 uint32_t id,
111 RenderWidgetHostViewBase* owner) { 120 RenderWidgetHostViewBase* owner) {
112 DCHECK(owner_map_.find(id) == owner_map_.end()); 121 DCHECK(owner_map_.find(id) == owner_map_.end());
113 owner_map_.insert(std::make_pair(id, owner)); 122 owner_map_.insert(std::make_pair(id, owner->GetWeakPtr()));
114 } 123 }
115 124
116 void RenderWidgetHostInputEventRouter::RemoveSurfaceIdNamespaceOwner( 125 void RenderWidgetHostInputEventRouter::RemoveSurfaceIdNamespaceOwner(
117 uint32_t id) { 126 uint32_t id) {
118 owner_map_.erase(id); 127 owner_map_.erase(id);
119 } 128 }
120 129
121 } // namespace content 130 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_input_event_router.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698