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

Side by Side Diff: mojo/services/native_viewport/native_viewport_impl.cc

Issue 685013002: Refactors event dispatching of NativeViewport into its own interface (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cleanup Created 6 years, 1 month 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/services/native_viewport/native_viewport_impl.h" 5 #include "mojo/services/native_viewport/native_viewport_impl.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 size_, 86 size_,
87 child_surface_id.To<cc::SurfaceId>())); 87 child_surface_id.To<cc::SurfaceId>()));
88 if (widget_id_) 88 if (widget_id_)
89 viewport_surface_->SetWidgetId(widget_id_); 89 viewport_surface_->SetWidgetId(widget_id_);
90 } 90 }
91 child_surface_id_ = child_surface_id.To<cc::SurfaceId>(); 91 child_surface_id_ = child_surface_id.To<cc::SurfaceId>();
92 if (viewport_surface_) 92 if (viewport_surface_)
93 viewport_surface_->SetChildId(child_surface_id_); 93 viewport_surface_->SetChildId(child_surface_id_);
94 } 94 }
95 95
96 void NativeViewportImpl::SetEventDispatcher(
97 NativeViewportEventDispatcherPtr dispatcher) {
98 event_dispatcher_ = dispatcher.Pass();
99 }
100
96 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { 101 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) {
97 if (size_ == bounds.size()) 102 if (size_ == bounds.size())
98 return; 103 return;
99 104
100 size_ = bounds.size(); 105 size_ = bounds.size();
101 106
102 // Wait for the accelerated widget before telling the client of the bounds. 107 // Wait for the accelerated widget before telling the client of the bounds.
103 if (create_callback_.is_null()) 108 if (create_callback_.is_null())
104 ProcessOnBoundsChanged(); 109 ProcessOnBoundsChanged();
105 } 110 }
106 111
107 void NativeViewportImpl::OnAcceleratedWidgetAvailable( 112 void NativeViewportImpl::OnAcceleratedWidgetAvailable(
108 gfx::AcceleratedWidget widget) { 113 gfx::AcceleratedWidget widget) {
109 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); 114 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget));
110 // TODO(jamesr): Remove once everything is converted to surfaces. 115 // TODO(jamesr): Remove once everything is converted to surfaces.
111 create_callback_.Run(widget_id_); 116 create_callback_.Run(widget_id_);
112 create_callback_.reset(); 117 create_callback_.reset();
113 // Immediately tell the client of the size. The size may be wrong, if so we'll 118 // Immediately tell the client of the size. The size may be wrong, if so we'll
114 // get the right one in the next OnBoundsChanged() call. 119 // get the right one in the next OnBoundsChanged() call.
115 ProcessOnBoundsChanged(); 120 ProcessOnBoundsChanged();
116 if (viewport_surface_) 121 if (viewport_surface_)
117 viewport_surface_->SetWidgetId(widget_id_); 122 viewport_surface_->SetWidgetId(widget_id_);
118 } 123 }
119 124
120 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { 125 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) {
126 if (!event_dispatcher_.get())
127 return false;
128
121 // Must not return early before updating capture. 129 // Must not return early before updating capture.
122 switch (ui_event->type()) { 130 switch (ui_event->type()) {
123 case ui::ET_MOUSE_PRESSED: 131 case ui::ET_MOUSE_PRESSED:
124 case ui::ET_TOUCH_PRESSED: 132 case ui::ET_TOUCH_PRESSED:
125 platform_viewport_->SetCapture(); 133 platform_viewport_->SetCapture();
126 break; 134 break;
127 case ui::ET_MOUSE_RELEASED: 135 case ui::ET_MOUSE_RELEASED:
128 case ui::ET_TOUCH_RELEASED: 136 case ui::ET_TOUCH_RELEASED:
129 platform_viewport_->ReleaseCapture(); 137 platform_viewport_->ReleaseCapture();
130 break; 138 break;
131 default: 139 default:
132 break; 140 break;
133 } 141 }
134 142
135 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) 143 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event))
136 return false; 144 return false;
137 145
138 client()->OnEvent( 146 event_dispatcher_->OnEvent(
139 Event::From(*ui_event), 147 Event::From(*ui_event),
140 base::Bind(&NativeViewportImpl::AckEvent, weak_factory_.GetWeakPtr())); 148 base::Bind(&NativeViewportImpl::AckEvent, weak_factory_.GetWeakPtr()));
141 waiting_for_event_ack_ = true; 149 waiting_for_event_ack_ = true;
142 return false; 150 return false;
143 } 151 }
144 152
145 void NativeViewportImpl::OnDestroyed() { 153 void NativeViewportImpl::OnDestroyed() {
146 client()->OnDestroyed(); 154 client()->OnDestroyed();
147 } 155 }
148 156
149 void NativeViewportImpl::AckEvent() { 157 void NativeViewportImpl::AckEvent() {
150 waiting_for_event_ack_ = false; 158 waiting_for_event_ack_ = false;
151 } 159 }
152 160
153 void NativeViewportImpl::ProcessOnBoundsChanged() { 161 void NativeViewportImpl::ProcessOnBoundsChanged() {
154 client()->OnSizeChanged(Size::From(size_)); 162 client()->OnSizeChanged(Size::From(size_));
155 if (viewport_surface_) 163 if (viewport_surface_)
156 viewport_surface_->SetSize(size_); 164 viewport_surface_->SetSize(size_);
157 } 165 }
158 166
159 } // namespace mojo 167 } // namespace mojo
160 168
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698