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

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

Issue 2833163002: Change ui cursor identifiers to an enum class. (Closed)
Patch Set: OK, it can't be explicit for mac. Created 3 years, 7 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 | « ash/wm/window_manager_unittest.cc ('k') | 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 return event->location_f() == location; 44 return event->location_f() == location;
45 } 45 }
46 46
47 } // namespace 47 } // namespace
48 48
49 //////////////////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////////////////
50 // Pointer, public: 50 // Pointer, public:
51 51
52 Pointer::Pointer(PointerDelegate* delegate) 52 Pointer::Pointer(PointerDelegate* delegate)
53 : delegate_(delegate), 53 : delegate_(delegate),
54 cursor_(ui::kCursorNull), 54 cursor_(ui::CursorType::kNull),
55 cursor_capture_source_id_(base::UnguessableToken::Create()), 55 cursor_capture_source_id_(base::UnguessableToken::Create()),
56 cursor_capture_weak_ptr_factory_(this) { 56 cursor_capture_weak_ptr_factory_(this) {
57 auto* helper = WMHelper::GetInstance(); 57 auto* helper = WMHelper::GetInstance();
58 helper->AddPreTargetHandler(this); 58 helper->AddPreTargetHandler(this);
59 helper->AddCursorObserver(this); 59 helper->AddCursorObserver(this);
60 } 60 }
61 61
62 Pointer::~Pointer() { 62 Pointer::~Pointer() {
63 delegate_->OnPointerDestroying(this); 63 delegate_->OnPointerDestroying(this);
64 if (surface_) 64 if (surface_)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 asynchronously 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::CursorType::kNone;
129 UpdateCursor(); 129 UpdateCursor();
130 } 130 }
131 } 131 }
132 132
133 gfx::NativeCursor Pointer::GetCursor() { 133 gfx::NativeCursor Pointer::GetCursor() {
134 return cursor_; 134 return cursor_;
135 } 135 }
136 136
137 //////////////////////////////////////////////////////////////////////////////// 137 ////////////////////////////////////////////////////////////////////////////////
138 // ui::EventHandler overrides: 138 // ui::EventHandler overrides:
139 139
140 void Pointer::OnMouseEvent(ui::MouseEvent* event) { 140 void Pointer::OnMouseEvent(ui::MouseEvent* event) {
141 Surface* target = GetEffectiveTargetForEvent(event); 141 Surface* target = GetEffectiveTargetForEvent(event);
142 142
143 // If target is different than the current pointer focus then we need to 143 // If target is different than the current pointer focus then we need to
144 // generate enter and leave events. 144 // generate enter and leave events.
145 if (target != focus_) { 145 if (target != focus_) {
146 // First generate a leave event if we currently have a target in focus. 146 // First generate a leave event if we currently have a target in focus.
147 if (focus_) { 147 if (focus_) {
148 delegate_->OnPointerLeave(focus_); 148 delegate_->OnPointerLeave(focus_);
149 focus_->RemoveSurfaceObserver(this); 149 focus_->RemoveSurfaceObserver(this);
150 // Require SetCursor() to be called and cursor to be re-defined in 150 // Require SetCursor() to be called and cursor to be re-defined in
151 // response to each OnPointerEnter() call. 151 // response to each OnPointerEnter() call.
152 focus_->UnregisterCursorProvider(this); 152 focus_->UnregisterCursorProvider(this);
153 focus_ = nullptr; 153 focus_ = nullptr;
154 cursor_ = ui::kCursorNull; 154 cursor_ = ui::CursorType::kNull;
155 cursor_capture_weak_ptr_factory_.InvalidateWeakPtrs(); 155 cursor_capture_weak_ptr_factory_.InvalidateWeakPtrs();
156 } 156 }
157 // Second generate an enter event if focus moved to a new target. 157 // Second generate an enter event if focus moved to a new target.
158 if (target) { 158 if (target) {
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);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 cursor_scale_ * primary_device_scale_factor))); 341 cursor_scale_ * primary_device_scale_factor)));
342 request->set_source(cursor_capture_source_id_); 342 request->set_source(cursor_capture_source_id_);
343 surface_->window()->layer()->RequestCopyOfOutput(std::move(request)); 343 surface_->window()->layer()->RequestCopyOfOutput(std::move(request));
344 } 344 }
345 345
346 void Pointer::OnCursorCaptured(const gfx::Point& hotspot, 346 void Pointer::OnCursorCaptured(const gfx::Point& hotspot,
347 std::unique_ptr<cc::CopyOutputResult> result) { 347 std::unique_ptr<cc::CopyOutputResult> result) {
348 if (!focus_) 348 if (!focus_)
349 return; 349 return;
350 350
351 cursor_ = ui::kCursorNone; 351 cursor_ = ui::CursorType::kNone;
352 if (!result->IsEmpty()) { 352 if (!result->IsEmpty()) {
353 DCHECK(result->HasBitmap()); 353 DCHECK(result->HasBitmap());
354 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap(); 354 std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap();
355 355
356 ui::PlatformCursor platform_cursor; 356 ui::PlatformCursor platform_cursor;
357 #if defined(USE_OZONE) 357 #if defined(USE_OZONE)
358 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers 358 // TODO(reveman): Add interface for creating cursors from GpuMemoryBuffers
359 // and use that here instead of the current bitmap API. crbug.com/686600 359 // and use that here instead of the current bitmap API. crbug.com/686600
360 platform_cursor = ui::CursorFactoryOzone::GetInstance()->CreateImageCursor( 360 platform_cursor = ui::CursorFactoryOzone::GetInstance()->CreateImageCursor(
361 *bitmap.get(), hotspot, cursor_scale_); 361 *bitmap.get(), hotspot, cursor_scale_);
362 #elif defined(USE_X11) 362 #elif defined(USE_X11)
363 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap.get(), hotspot); 363 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap.get(), hotspot);
364 platform_cursor = ui::CreateReffedCustomXCursor(image); 364 platform_cursor = ui::CreateReffedCustomXCursor(image);
365 #endif 365 #endif
366 cursor_ = ui::kCursorCustom; 366 cursor_ = ui::CursorType::kCustom;
367 cursor_.SetPlatformCursor(platform_cursor); 367 cursor_.SetPlatformCursor(platform_cursor);
368 #if defined(USE_OZONE) 368 #if defined(USE_OZONE)
369 ui::CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor); 369 ui::CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor);
370 #elif defined(USE_X11) 370 #elif defined(USE_X11)
371 ui::UnrefCustomXCursor(platform_cursor); 371 ui::UnrefCustomXCursor(platform_cursor);
372 #endif 372 #endif
373 } 373 }
374 374
375 UpdateCursor(); 375 UpdateCursor();
376 } 376 }
377 377
378 void Pointer::UpdateCursor() { 378 void Pointer::UpdateCursor() {
379 DCHECK(focus_); 379 DCHECK(focus_);
380 380
381 aura::Window* root_window = focus_->window()->GetRootWindow(); 381 aura::Window* root_window = focus_->window()->GetRootWindow();
382 if (!root_window) 382 if (!root_window)
383 return; 383 return;
384 384
385 aura::client::CursorClient* cursor_client = 385 aura::client::CursorClient* cursor_client =
386 aura::client::GetCursorClient(root_window); 386 aura::client::GetCursorClient(root_window);
387 if (cursor_client) 387 if (cursor_client)
388 cursor_client->SetCursor(cursor_); 388 cursor_client->SetCursor(cursor_);
389 } 389 }
390 390
391 } // namespace exo 391 } // namespace exo
OLDNEW
« no previous file with comments | « ash/wm/window_manager_unittest.cc ('k') | components/exo/shell_surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698