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

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: Address suggestions. Created 4 years, 12 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
« 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
(...skipping 23 matching lines...) Expand all
34 // single process with only one RenderWidgetHost. 34 // single process with only one RenderWidgetHost.
35 uint32_t surface_id_namespace = 35 uint32_t surface_id_namespace =
36 root_view->SurfaceIdNamespaceAtPoint(point, transformed_point); 36 root_view->SurfaceIdNamespaceAtPoint(point, transformed_point);
37 const SurfaceIdNamespaceOwnerMap::iterator iter = 37 const SurfaceIdNamespaceOwnerMap::iterator iter =
38 owner_map_.find(surface_id_namespace); 38 owner_map_.find(surface_id_namespace);
39 // If the point hit a Surface whose namspace is no longer in the map, then 39 // 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 40 // it likely means the RenderWidgetHostView has been destroyed but its
41 // parent frame has not sent a new compositor frame since that happened. 41 // parent frame has not sent a new compositor frame since that happened.
42 if (iter == owner_map_.end()) 42 if (iter == owner_map_.end())
43 return root_view; 43 return root_view;
44 return iter->second; 44 return iter->second.get();
45 } 45 }
46 46
47 void RenderWidgetHostInputEventRouter::RouteMouseEvent( 47 void RenderWidgetHostInputEventRouter::RouteMouseEvent(
48 RenderWidgetHostViewBase* root_view, 48 RenderWidgetHostViewBase* root_view,
49 blink::WebMouseEvent* event) { 49 blink::WebMouseEvent* event) {
50 gfx::Point transformed_point; 50 gfx::Point transformed_point;
51 RenderWidgetHostViewBase* target = FindEventTarget( 51 RenderWidgetHostViewBase* target = FindEventTarget(
52 root_view, gfx::Point(event->x, event->y), &transformed_point); 52 root_view, gfx::Point(event->x, event->y), &transformed_point);
53 if (!target)
54 return;
55
53 event->x = transformed_point.x(); 56 event->x = transformed_point.x();
54 event->y = transformed_point.y(); 57 event->y = transformed_point.y();
55 58
56 target->ProcessMouseEvent(*event); 59 target->ProcessMouseEvent(*event);
57 } 60 }
58 61
59 void RenderWidgetHostInputEventRouter::RouteMouseWheelEvent( 62 void RenderWidgetHostInputEventRouter::RouteMouseWheelEvent(
60 RenderWidgetHostViewBase* root_view, 63 RenderWidgetHostViewBase* root_view,
61 blink::WebMouseWheelEvent* event) { 64 blink::WebMouseWheelEvent* event) {
62 gfx::Point transformed_point; 65 gfx::Point transformed_point;
63 RenderWidgetHostViewBase* target = FindEventTarget( 66 RenderWidgetHostViewBase* target = FindEventTarget(
64 root_view, gfx::Point(event->x, event->y), &transformed_point); 67 root_view, gfx::Point(event->x, event->y), &transformed_point);
68 if (!target)
69 return;
70
65 event->x = transformed_point.x(); 71 event->x = transformed_point.x();
66 event->y = transformed_point.y(); 72 event->y = transformed_point.y();
67 73
68 target->ProcessMouseWheelEvent(*event); 74 target->ProcessMouseWheelEvent(*event);
69 } 75 }
70 76
71 void RenderWidgetHostInputEventRouter::RouteTouchEvent( 77 void RenderWidgetHostInputEventRouter::RouteTouchEvent(
72 RenderWidgetHostViewBase* root_view, 78 RenderWidgetHostViewBase* root_view,
73 blink::WebTouchEvent* event, 79 blink::WebTouchEvent* event,
74 const ui::LatencyInfo& latency) { 80 const ui::LatencyInfo& latency) {
75 switch (event->type) { 81 switch (event->type) {
76 case blink::WebInputEvent::TouchStart: { 82 case blink::WebInputEvent::TouchStart: {
77 if (!active_touches_) { 83 if (!active_touches_) {
78 // Since this is the first touch, it defines the target for the rest 84 // Since this is the first touch, it defines the target for the rest
79 // of this sequence. 85 // of this sequence.
80 DCHECK(!current_touch_target_); 86 DCHECK(!current_touch_target_);
81 gfx::Point transformed_point; 87 gfx::Point transformed_point;
82 gfx::Point original_point(event->touches[0].position.x, 88 gfx::Point original_point(event->touches[0].position.x,
83 event->touches[0].position.y); 89 event->touches[0].position.y);
84 current_touch_target_ = 90 current_touch_target_ =
85 FindEventTarget(root_view, original_point, &transformed_point); 91 FindEventTarget(root_view, original_point, &transformed_point);
86 } 92 }
87 ++active_touches_; 93 ++active_touches_;
88 current_touch_target_->ProcessTouchEvent(*event, latency); 94 if (current_touch_target_)
95 current_touch_target_->ProcessTouchEvent(*event, latency);
89 break; 96 break;
90 } 97 }
91 case blink::WebInputEvent::TouchMove: 98 case blink::WebInputEvent::TouchMove:
92 DCHECK(current_touch_target_); 99 if (current_touch_target_)
93 current_touch_target_->ProcessTouchEvent(*event, latency); 100 current_touch_target_->ProcessTouchEvent(*event, latency);
94 break; 101 break;
95 case blink::WebInputEvent::TouchEnd: 102 case blink::WebInputEvent::TouchEnd:
96 case blink::WebInputEvent::TouchCancel: 103 case blink::WebInputEvent::TouchCancel:
97 DCHECK(active_touches_); 104 DCHECK(active_touches_);
98 DCHECK(current_touch_target_); 105 if (current_touch_target_)
99 current_touch_target_->ProcessTouchEvent(*event, latency); 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_ = nullptr;
103 break; 110 break;
104 default: 111 default:
105 NOTREACHED(); 112 NOTREACHED();
106 } 113 }
107 } 114 }
108 115
109 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner( 116 void RenderWidgetHostInputEventRouter::AddSurfaceIdNamespaceOwner(
110 uint32_t id, 117 uint32_t id,
111 RenderWidgetHostViewBase* owner) { 118 RenderWidgetHostViewBase* owner) {
112 DCHECK(owner_map_.find(id) == owner_map_.end()); 119 DCHECK(owner_map_.find(id) == owner_map_.end());
113 owner_map_.insert(std::make_pair(id, owner)); 120 owner_map_.insert(std::make_pair(id, owner->GetWeakPtr()));
114 } 121 }
115 122
116 void RenderWidgetHostInputEventRouter::RemoveSurfaceIdNamespaceOwner( 123 void RenderWidgetHostInputEventRouter::RemoveSurfaceIdNamespaceOwner(
117 uint32_t id) { 124 uint32_t id) {
118 owner_map_.erase(id); 125 owner_map_.erase(id);
119 } 126 }
120 127
121 } // namespace content 128 } // 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