OLD | NEW |
---|---|
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 "remoting/host/chromeos/mouse_cursor_monitor_aura.h" | 5 #include "remoting/host/chromeos/mouse_cursor_monitor_aura.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 callback_ = callback; | 29 callback_ = callback; |
30 mode_ = mode; | 30 mode_ = mode; |
31 } | 31 } |
32 | 32 |
33 void MouseCursorMonitorAura::Capture() { | 33 void MouseCursorMonitorAura::Capture() { |
34 // Check if the cursor is different. | 34 // Check if the cursor is different. |
35 gfx::NativeCursor cursor = | 35 gfx::NativeCursor cursor = |
36 ash::Shell::GetPrimaryRootWindow()->GetHost()->last_cursor(); | 36 ash::Shell::GetPrimaryRootWindow()->GetHost()->last_cursor(); |
37 | 37 |
38 if (cursor != last_cursor_) { | 38 if (cursor != last_cursor_) { |
39 last_cursor_ = cursor; | |
39 NotifyCursorChanged(cursor); | 40 NotifyCursorChanged(cursor); |
40 } | 41 } |
41 | 42 |
42 // Check if we need to update the location. | 43 // Check if we need to update the location. |
43 if (mode_ == SHAPE_AND_POSITION) { | 44 if (mode_ == SHAPE_AND_POSITION) { |
44 gfx::Point position = aura::Env::GetInstance()->last_mouse_location(); | 45 gfx::Point position = aura::Env::GetInstance()->last_mouse_location(); |
45 if (position != last_mouse_location_) { | 46 if (position != last_mouse_location_) { |
46 last_mouse_location_ = position; | 47 last_mouse_location_ = position; |
47 callback_->OnMouseCursorPosition( | 48 callback_->OnMouseCursorPosition( |
48 INSIDE, webrtc::DesktopVector(position.x(), position.y())); | 49 INSIDE, webrtc::DesktopVector(position.x(), position.y())); |
49 } | 50 } |
50 } | 51 } |
51 } | 52 } |
52 | 53 |
54 namespace { | |
Sergey Ulanov
2015/01/06 18:52:10
nit: move this before MouseCursorMonitorAura const
kelvinp
2015/01/06 22:04:14
Done.
| |
55 | |
56 webrtc::MouseCursor* CreateEmptyMouseCursor() { | |
Sergey Ulanov
2015/01/06 18:52:10
Use scoped_ptr<> for the result or add a comment t
Wez
2015/01/06 23:24:25
Not for this CL: Let's add a CreateEmpty() creator
| |
57 return new webrtc::MouseCursor( | |
58 new webrtc::BasicDesktopFrame(webrtc::DesktopSize(0, 0)), | |
59 webrtc::DesktopVector(0, 0)); | |
60 } | |
61 | |
62 } // namespace | |
63 | |
53 void MouseCursorMonitorAura::NotifyCursorChanged(const ui::Cursor& cursor) { | 64 void MouseCursorMonitorAura::NotifyCursorChanged(const ui::Cursor& cursor) { |
54 scoped_ptr<SkBitmap> cursor_bitmap(new SkBitmap()); | 65 scoped_ptr<SkBitmap> cursor_bitmap(new SkBitmap()); |
55 gfx::Point cursor_hotspot; | 66 gfx::Point cursor_hotspot; |
67 | |
68 if (cursor.native_type() == ui::kCursorNone) { | |
69 callback_->OnMouseCursor(CreateEmptyMouseCursor()); | |
70 return; | |
71 } | |
72 | |
56 if (!ui::GetCursorBitmap(cursor, cursor_bitmap.get(), &cursor_hotspot)) { | 73 if (!ui::GetCursorBitmap(cursor, cursor_bitmap.get(), &cursor_hotspot)) { |
57 LOG(ERROR) << "Failed to load bitmap for cursor type:" | 74 LOG(ERROR) << "Failed to load bitmap for cursor type:" |
58 << cursor.native_type(); | 75 << cursor.native_type(); |
76 callback_->OnMouseCursor(CreateEmptyMouseCursor()); | |
59 return; | 77 return; |
60 } | 78 } |
61 | 79 |
62 last_cursor_ = cursor; | |
63 | |
64 // There is a bug (crbug.com/436993) in aura::GetCursorBitmap() such that it | 80 // There is a bug (crbug.com/436993) in aura::GetCursorBitmap() such that it |
65 // it would return a scale-factor-100 bitmap with a scale-factor-200 hotspot. | 81 // it would return a scale-factor-100 bitmap with a scale-factor-200 hotspot. |
66 // This causes the hotspot to go out of range. As a result, we would need to | 82 // This causes the hotspot to go out of range. As a result, we would need to |
67 // manually downscale the hotspot. | 83 // manually downscale the hotspot. |
68 float scale_factor = cursor.device_scale_factor(); | 84 float scale_factor = cursor.device_scale_factor(); |
69 cursor_hotspot.SetPoint(cursor_hotspot.x() / scale_factor, | 85 cursor_hotspot.SetPoint(cursor_hotspot.x() / scale_factor, |
70 cursor_hotspot.y() / scale_factor); | 86 cursor_hotspot.y() / scale_factor); |
71 | 87 |
72 if (cursor_hotspot.x() >= cursor_bitmap->width() || | 88 if (cursor_hotspot.x() >= cursor_bitmap->width() || |
73 cursor_hotspot.y() >= cursor_bitmap->height()) { | 89 cursor_hotspot.y() >= cursor_bitmap->height()) { |
74 LOG(WARNING) << "Cursor hotspot is out of bounds for type: " | 90 LOG(WARNING) << "Cursor hotspot is out of bounds for type: " |
75 << cursor.native_type() << ". Setting to (0,0) instead"; | 91 << cursor.native_type() << ". Setting to (0,0) instead"; |
76 cursor_hotspot.SetPoint(0, 0); | 92 cursor_hotspot.SetPoint(0, 0); |
77 } | 93 } |
78 | 94 |
79 scoped_ptr<webrtc::DesktopFrame> image( | 95 scoped_ptr<webrtc::DesktopFrame> image( |
80 SkiaBitmapDesktopFrame::Create(cursor_bitmap.Pass())); | 96 SkiaBitmapDesktopFrame::Create(cursor_bitmap.Pass())); |
81 scoped_ptr<webrtc::MouseCursor> cursor_shape(new webrtc::MouseCursor( | 97 scoped_ptr<webrtc::MouseCursor> cursor_shape(new webrtc::MouseCursor( |
82 image.release(), | 98 image.release(), |
83 webrtc::DesktopVector(cursor_hotspot.x(), cursor_hotspot.y()))); | 99 webrtc::DesktopVector(cursor_hotspot.x(), cursor_hotspot.y()))); |
84 | 100 |
85 callback_->OnMouseCursor(cursor_shape.release()); | 101 callback_->OnMouseCursor(cursor_shape.release()); |
86 } | 102 } |
87 | 103 |
88 } // namespace remoting | 104 } // namespace remoting |
OLD | NEW |