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

Side by Side Diff: components/exo/pointer.cc

Issue 2778913002: exo: Clean up cursor code (Closed)
Patch Set: Rebase Created 3 years, 8 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 | « no previous file | components/exo/shell_surface.cc » ('j') | 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 "components/exo/pointer.h" 5 #include "components/exo/pointer.h"
6 6
7 #include "ash/public/cpp/shell_window_ids.h" 7 #include "ash/public/cpp/shell_window_ids.h"
8 #include "cc/output/copy_output_request.h" 8 #include "cc/output/copy_output_request.h"
9 #include "cc/output/copy_output_result.h" 9 #include "cc/output/copy_output_result.h"
10 #include "components/exo/pointer_delegate.h" 10 #include "components/exo/pointer_delegate.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // Update hotspot. 112 // Update hotspot.
113 if (hotspot != hotspot_) { 113 if (hotspot != hotspot_) {
114 hotspot_ = hotspot; 114 hotspot_ = hotspot;
115 cursor_changed = true; 115 cursor_changed = true;
116 } 116 }
117 117
118 // Early out if cursor did not change. 118 // Early out if cursor did not change.
119 if (!cursor_changed) 119 if (!cursor_changed)
120 return; 120 return;
121 121
122 // If |surface_| is set then ascynchrounsly capture a snapshot of cursor, 122 // If |surface_| is set then asynchronously capture a snapshot of cursor,
123 // otherwise cancel pending capture and immediately set the cursor to "none". 123 // otherwise cancel pending capture and immediately set the cursor to "none".
124 if (surface_) { 124 if (surface_) {
125 CaptureCursor(); 125 CaptureCursor();
126 } else { 126 } else {
127 cursor_capture_weak_ptr_factory_.InvalidateWeakPtrs(); 127 cursor_capture_weak_ptr_factory_.InvalidateWeakPtrs();
128 cursor_ = ui::kCursorNone; 128 cursor_ = ui::kCursorNone;
129 UpdateCursor(); 129 UpdateCursor();
130 } 130 }
131 } 131 }
132 132
(...skipping 26 matching lines...) Expand all
159 delegate_->OnPointerEnter(target, event->location_f(), 159 delegate_->OnPointerEnter(target, event->location_f(),
160 event->button_flags()); 160 event->button_flags());
161 location_ = event->location_f(); 161 location_ = event->location_f();
162 focus_ = target; 162 focus_ = target;
163 focus_->AddSurfaceObserver(this); 163 focus_->AddSurfaceObserver(this);
164 focus_->RegisterCursorProvider(this); 164 focus_->RegisterCursorProvider(this);
165 } 165 }
166 delegate_->OnPointerFrame(); 166 delegate_->OnPointerFrame();
167 } 167 }
168 168
169 if (focus_ && event->IsMouseEvent() && event->type() != ui::ET_MOUSE_EXITED) { 169 if (!focus_)
170 return;
171
172 if (event->IsMouseEvent() && event->type() != ui::ET_MOUSE_EXITED) {
170 // Generate motion event if location changed. We need to check location 173 // Generate motion event if location changed. We need to check location
171 // here as mouse movement can generate both "moved" and "entered" events 174 // here as mouse movement can generate both "moved" and "entered" events
172 // but OnPointerMotion should only be called if location changed since 175 // but OnPointerMotion should only be called if location changed since
173 // OnPointerEnter was called. 176 // OnPointerEnter was called.
174 if (!SameLocation(event, location_)) { 177 if (!SameLocation(event, location_)) {
175 location_ = event->location_f(); 178 location_ = event->location_f();
176 delegate_->OnPointerMotion(event->time_stamp(), location_); 179 delegate_->OnPointerMotion(event->time_stamp(), location_);
177 delegate_->OnPointerFrame(); 180 delegate_->OnPointerFrame();
178 } 181 }
179 } 182 }
180 183
181 switch (event->type()) { 184 switch (event->type()) {
182 case ui::ET_MOUSE_PRESSED: 185 case ui::ET_MOUSE_PRESSED:
183 case ui::ET_MOUSE_RELEASED: 186 case ui::ET_MOUSE_RELEASED: {
184 if (focus_) { 187 delegate_->OnPointerButton(event->time_stamp(),
185 delegate_->OnPointerButton(event->time_stamp(), 188 event->changed_button_flags(),
186 event->changed_button_flags(), 189 event->type() == ui::ET_MOUSE_PRESSED);
187 event->type() == ui::ET_MOUSE_PRESSED); 190 delegate_->OnPointerFrame();
188 delegate_->OnPointerFrame();
189 }
190 break; 191 break;
191 case ui::ET_SCROLL: 192 }
192 if (focus_) { 193 case ui::ET_SCROLL: {
193 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event); 194 ui::ScrollEvent* scroll_event = static_cast<ui::ScrollEvent*>(event);
194 delegate_->OnPointerScroll( 195 delegate_->OnPointerScroll(
195 event->time_stamp(), 196 event->time_stamp(),
196 gfx::Vector2dF(scroll_event->x_offset(), scroll_event->y_offset()), 197 gfx::Vector2dF(scroll_event->x_offset(), scroll_event->y_offset()),
197 false); 198 false);
198 delegate_->OnPointerFrame(); 199 delegate_->OnPointerFrame();
199 }
200 break; 200 break;
201 case ui::ET_MOUSEWHEEL: 201 }
202 if (focus_) { 202 case ui::ET_MOUSEWHEEL: {
203 delegate_->OnPointerScroll( 203 delegate_->OnPointerScroll(
204 event->time_stamp(), 204 event->time_stamp(),
205 static_cast<ui::MouseWheelEvent*>(event)->offset(), true); 205 static_cast<ui::MouseWheelEvent*>(event)->offset(), true);
206 delegate_->OnPointerFrame(); 206 delegate_->OnPointerFrame();
207 }
208 break; 207 break;
209 case ui::ET_SCROLL_FLING_START: 208 }
210 if (focus_) { 209 case ui::ET_SCROLL_FLING_START: {
211 delegate_->OnPointerScrollStop(event->time_stamp()); 210 delegate_->OnPointerScrollStop(event->time_stamp());
212 delegate_->OnPointerFrame(); 211 delegate_->OnPointerFrame();
213 }
214 break; 212 break;
215 case ui::ET_SCROLL_FLING_CANCEL: 213 }
216 if (focus_) { 214 case ui::ET_SCROLL_FLING_CANCEL: {
217 delegate_->OnPointerScrollCancel(event->time_stamp()); 215 delegate_->OnPointerScrollCancel(event->time_stamp());
218 delegate_->OnPointerFrame(); 216 delegate_->OnPointerFrame();
219 }
220 break; 217 break;
218 }
221 case ui::ET_MOUSE_MOVED: 219 case ui::ET_MOUSE_MOVED:
222 case ui::ET_MOUSE_DRAGGED: 220 case ui::ET_MOUSE_DRAGGED:
223 case ui::ET_MOUSE_ENTERED: 221 case ui::ET_MOUSE_ENTERED:
224 case ui::ET_MOUSE_EXITED: 222 case ui::ET_MOUSE_EXITED:
225 case ui::ET_MOUSE_CAPTURE_CHANGED: 223 case ui::ET_MOUSE_CAPTURE_CHANGED:
226 break; 224 break;
227 default: 225 default:
228 NOTREACHED(); 226 NOTREACHED();
229 break; 227 break;
230 } 228 }
231 229
232 if (focus_) 230 UpdateCursorScale();
233 UpdateCursorScale();
234 } 231 }
235 232
236 void Pointer::OnScrollEvent(ui::ScrollEvent* event) { 233 void Pointer::OnScrollEvent(ui::ScrollEvent* event) {
237 OnMouseEvent(event); 234 OnMouseEvent(event);
238 } 235 }
239 236
237 ////////////////////////////////////////////////////////////////////////////////
238 // WMHelper::CursorObserver overrides:
239
240 void Pointer::OnCursorSetChanged(ui::CursorSetType cursor_set) { 240 void Pointer::OnCursorSetChanged(ui::CursorSetType cursor_set) {
241 if (focus_) 241 if (focus_)
242 UpdateCursorScale(); 242 UpdateCursorScale();
243 } 243 }
244 244
245 //////////////////////////////////////////////////////////////////////////////// 245 ////////////////////////////////////////////////////////////////////////////////
246 // SurfaceDelegate overrides: 246 // SurfaceDelegate overrides:
247 247
248 void Pointer::OnSurfaceCommit() { 248 void Pointer::OnSurfaceCommit() {
249 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); 249 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
315 if (scale != cursor_scale_) { 315 if (scale != cursor_scale_) {
316 cursor_scale_ = scale; 316 cursor_scale_ = scale;
317 if (surface_) 317 if (surface_)
318 CaptureCursor(); 318 CaptureCursor();
319 } 319 }
320 } 320 }
321 321
322 void Pointer::CaptureCursor() { 322 void Pointer::CaptureCursor() {
323 DCHECK(surface_); 323 DCHECK(surface_);
324 DCHECK(focus_);
324 325
325 // Set UI scale before submitting capture request. 326 // Set UI scale before submitting capture request.
326 surface_->window()->layer()->SetTransform( 327 surface_->window()->layer()->SetTransform(
327 gfx::GetScaleTransform(gfx::Point(), cursor_scale_)); 328 gfx::GetScaleTransform(gfx::Point(), cursor_scale_));
328 329
329 float primary_device_scale_factor = 330 float primary_device_scale_factor =
330 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); 331 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor();
331 332
332 std::unique_ptr<cc::CopyOutputRequest> request = 333 std::unique_ptr<cc::CopyOutputRequest> request =
333 cc::CopyOutputRequest::CreateBitmapRequest( 334 cc::CopyOutputRequest::CreateBitmapRequest(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 void Pointer::UpdateCursor() { 378 void Pointer::UpdateCursor() {
378 DCHECK(focus_); 379 DCHECK(focus_);
379 380
380 aura::client::CursorClient* cursor_client = 381 aura::client::CursorClient* cursor_client =
381 aura::client::GetCursorClient(focus_->window()->GetRootWindow()); 382 aura::client::GetCursorClient(focus_->window()->GetRootWindow());
382 if (cursor_client) 383 if (cursor_client)
383 cursor_client->SetCursor(cursor_); 384 cursor_client->SetCursor(cursor_);
384 } 385 }
385 386
386 } // namespace exo 387 } // namespace exo
OLDNEW
« no previous file with comments | « no previous file | components/exo/shell_surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698