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 "ui/ozone/platform/dri/dri_cursor.h" | 5 #include "ui/ozone/platform/dri/dri_cursor.h" |
6 | 6 |
7 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" | 7 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" |
8 #include "ui/gfx/geometry/point.h" | 8 #include "ui/gfx/geometry/point.h" |
9 #include "ui/gfx/geometry/point_conversions.h" | 9 #include "ui/gfx/geometry/point_conversions.h" |
10 #include "ui/gfx/geometry/point_f.h" | 10 #include "ui/gfx/geometry/point_f.h" |
11 #include "ui/ozone/platform/dri/dri_surface_factory.h" | 11 #include "ui/ozone/platform/dri/dri_surface_factory.h" |
12 #include "ui/ozone/platform/dri/dri_window.h" | |
13 #include "ui/ozone/platform/dri/dri_window_manager.h" | |
12 #include "ui/ozone/platform/dri/hardware_cursor_delegate.h" | 14 #include "ui/ozone/platform/dri/hardware_cursor_delegate.h" |
13 | 15 |
14 namespace ui { | 16 namespace ui { |
15 | 17 |
16 DriCursor::DriCursor(HardwareCursorDelegate* hardware) : hardware_(hardware) { | 18 DriCursor::DriCursor(HardwareCursorDelegate* hardware, |
17 // TODO(dnicoara) Assume the first widget since at this point there are no | 19 DriWindowManager* window_manager) |
18 // widgets initialized. | 20 : hardware_(hardware), |
19 cursor_window_ = DriSurfaceFactory::kDefaultWidgetHandle; | 21 window_manager_(window_manager), |
20 cursor_location_ = gfx::PointF(2560 / 2, 1700 / 2); // TODO(spang): Argh! | 22 cursor_window_(DriSurfaceFactory::kDefaultWidgetHandle) { |
21 } | 23 } |
22 | 24 |
23 DriCursor::~DriCursor() { | 25 DriCursor::~DriCursor() { |
24 } | 26 } |
25 | 27 |
26 void DriCursor::SetCursor(gfx::AcceleratedWidget widget, | 28 void DriCursor::SetCursor(gfx::AcceleratedWidget widget, |
27 PlatformCursor platform_cursor) { | 29 PlatformCursor platform_cursor) { |
30 DCHECK_NE(widget, gfx::kNullAcceleratedWidget); | |
28 scoped_refptr<BitmapCursorOzone> cursor = | 31 scoped_refptr<BitmapCursorOzone> cursor = |
29 BitmapCursorFactoryOzone::GetBitmapCursor(platform_cursor); | 32 BitmapCursorFactoryOzone::GetBitmapCursor(platform_cursor); |
30 if (cursor_ == cursor || cursor_window_ != widget) | 33 if (cursor_ == cursor || cursor_window_ != widget) |
31 return; | 34 return; |
32 | 35 |
33 cursor_ = cursor; | 36 cursor_ = cursor; |
34 ShowCursor(); | 37 ShowCursor(); |
35 } | 38 } |
36 | 39 |
37 void DriCursor::ShowCursor() { | 40 void DriCursor::ShowCursor() { |
41 DCHECK_NE(cursor_window_, gfx::kNullAcceleratedWidget); | |
38 if (cursor_.get()) | 42 if (cursor_.get()) |
39 hardware_->SetHardwareCursor(cursor_window_, | 43 hardware_->SetHardwareCursor(cursor_window_, |
40 cursor_->bitmaps(), | 44 cursor_->bitmaps(), |
41 bitmap_location(), | 45 bitmap_location(), |
42 cursor_->frame_delay_ms()); | 46 cursor_->frame_delay_ms()); |
43 else | 47 else |
44 HideCursor(); | 48 HideCursor(); |
45 } | 49 } |
46 | 50 |
47 void DriCursor::HideCursor() { | 51 void DriCursor::HideCursor() { |
52 DCHECK_NE(cursor_window_, gfx::kNullAcceleratedWidget); | |
48 hardware_->SetHardwareCursor( | 53 hardware_->SetHardwareCursor( |
49 cursor_window_, std::vector<SkBitmap>(), gfx::Point(), 0); | 54 cursor_window_, std::vector<SkBitmap>(), gfx::Point(), 0); |
50 } | 55 } |
51 | 56 |
52 void DriCursor::MoveCursorTo(gfx::AcceleratedWidget widget, | 57 void DriCursor::MoveCursorTo(gfx::AcceleratedWidget widget, |
53 const gfx::PointF& location) { | 58 const gfx::PointF& location) { |
54 if (widget != cursor_window_) | 59 if (widget != cursor_window_ && cursor_window_ != gfx::kNullAcceleratedWidget) |
55 HideCursor(); | 60 HideCursor(); |
56 | 61 |
57 cursor_window_ = widget; | 62 cursor_window_ = widget; |
58 cursor_location_ = location; | 63 cursor_location_ = location; |
59 | 64 |
60 gfx::Size size = gfx::Size(2560, 1700); // TODO(spang): Fix. | 65 DriWindow* window = window_manager_->GetWindow(widget); |
66 if (cursor_window_ == gfx::kNullAcceleratedWidget || !window) | |
spang
2014/09/15 18:23:34
Shouldn't this just be
if (!window)
| |
67 return; | |
68 | |
69 const gfx::Size& size = window->GetBounds().size(); | |
61 cursor_location_.SetToMax(gfx::PointF(0, 0)); | 70 cursor_location_.SetToMax(gfx::PointF(0, 0)); |
62 cursor_location_.SetToMin(gfx::PointF(size.width(), size.height())); | 71 cursor_location_.SetToMin(gfx::PointF(size.width(), size.height())); |
63 | 72 |
64 if (cursor_.get()) | 73 if (cursor_.get()) |
65 hardware_->MoveHardwareCursor(cursor_window_, bitmap_location()); | 74 hardware_->MoveHardwareCursor(cursor_window_, bitmap_location()); |
66 } | 75 } |
67 | 76 |
68 void DriCursor::MoveCursor(const gfx::Vector2dF& delta) { | 77 void DriCursor::MoveCursor(const gfx::Vector2dF& delta) { |
69 MoveCursorTo(cursor_window_, cursor_location_ + delta); | 78 MoveCursorTo(cursor_window_, cursor_location_ + delta); |
70 } | 79 } |
71 | 80 |
72 gfx::AcceleratedWidget DriCursor::GetCursorWindow() { | 81 gfx::AcceleratedWidget DriCursor::GetCursorWindow() { |
73 return cursor_window_; | 82 return cursor_window_; |
74 } | 83 } |
75 | 84 |
76 bool DriCursor::IsCursorVisible() { | 85 bool DriCursor::IsCursorVisible() { |
77 return cursor_.get(); | 86 return cursor_.get(); |
78 } | 87 } |
79 | 88 |
80 gfx::PointF DriCursor::location() { | 89 gfx::PointF DriCursor::location() { |
81 return cursor_location_; | 90 return cursor_location_; |
82 } | 91 } |
83 | 92 |
84 gfx::Point DriCursor::bitmap_location() { | 93 gfx::Point DriCursor::bitmap_location() { |
85 return gfx::ToFlooredPoint(cursor_location_) - | 94 return gfx::ToFlooredPoint(cursor_location_) - |
86 cursor_->hotspot().OffsetFromOrigin(); | 95 cursor_->hotspot().OffsetFromOrigin(); |
87 } | 96 } |
88 | 97 |
89 } // namespace ui | 98 } // namespace ui |
OLD | NEW |