Chromium Code Reviews| 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_widget_(gfx::kNullAcceleratedWidget), |
| 23 cursor_window_(NULL) { | |
| 21 } | 24 } |
| 22 | 25 |
| 23 DriCursor::~DriCursor() { | 26 DriCursor::~DriCursor() { |
| 24 } | 27 } |
| 25 | 28 |
| 26 void DriCursor::SetCursor(gfx::AcceleratedWidget widget, | 29 void DriCursor::SetCursor(gfx::AcceleratedWidget widget, |
| 27 PlatformCursor platform_cursor) { | 30 PlatformCursor platform_cursor) { |
| 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_widget_ != 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_widget_, gfx::kNullAcceleratedWidget); | |
| 38 if (cursor_.get()) | 42 if (cursor_.get()) |
| 39 hardware_->SetHardwareCursor(cursor_window_, | 43 hardware_->SetHardwareCursor(cursor_widget_, |
| 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_widget_, gfx::kNullAcceleratedWidget); | |
| 48 hardware_->SetHardwareCursor( | 53 hardware_->SetHardwareCursor( |
| 49 cursor_window_, std::vector<SkBitmap>(), gfx::Point(), 0); | 54 cursor_widget_, 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 DCHECK_NE(widget, gfx::kNullAcceleratedWidget); |
| 55 HideCursor(); | 60 if (widget != cursor_widget_) { |
| 61 if (cursor_widget_ != gfx::kNullAcceleratedWidget) | |
|
spang
2014/09/12 19:28:39
Can you move this into HideCursor and lose the DCH
dnicoara
2014/09/12 20:24:17
I'd prefer to keep this in here since it is only n
| |
| 62 HideCursor(); | |
| 56 | 63 |
| 57 cursor_window_ = widget; | 64 cursor_widget_ = widget; |
|
spang
2014/09/12 19:28:39
There's no reason for these assignments to be done
dnicoara
2014/09/12 20:24:17
I felt like cursor_widget_ and cursor_window_ shou
| |
| 65 cursor_window_ = window_manager_->GetWindow(widget); | |
|
spang
2014/09/12 19:28:39
How do you ensure this ptr doesn't become dangling
dnicoara
2014/09/12 20:24:17
Setting/moving the cursor on an invalid widget is
spang
2014/09/12 21:05:47
What if you delete the window under the cursor, wh
dnicoara
2014/09/12 21:24:52
Can't happen at the same time since all the change
| |
| 66 } | |
| 67 | |
| 58 cursor_location_ = location; | 68 cursor_location_ = location; |
| 59 | 69 |
| 60 gfx::Size size = gfx::Size(2560, 1700); // TODO(spang): Fix. | 70 const gfx::Size& size = cursor_window_->GetBounds().size(); |
|
spang
2014/09/12 19:28:39
gfx::Size size =
| |
| 61 cursor_location_.SetToMax(gfx::PointF(0, 0)); | 71 cursor_location_.SetToMax(gfx::PointF(0, 0)); |
| 62 cursor_location_.SetToMin(gfx::PointF(size.width(), size.height())); | 72 cursor_location_.SetToMin(gfx::PointF(size.width(), size.height())); |
| 63 | 73 |
| 64 if (cursor_.get()) | 74 if (cursor_.get()) |
| 65 hardware_->MoveHardwareCursor(cursor_window_, bitmap_location()); | 75 hardware_->MoveHardwareCursor(cursor_widget_, bitmap_location()); |
| 66 } | 76 } |
| 67 | 77 |
| 68 void DriCursor::MoveCursor(const gfx::Vector2dF& delta) { | 78 void DriCursor::MoveCursor(const gfx::Vector2dF& delta) { |
| 69 MoveCursorTo(cursor_window_, cursor_location_ + delta); | 79 MoveCursorTo(cursor_widget_, cursor_location_ + delta); |
| 70 } | 80 } |
| 71 | 81 |
| 72 gfx::AcceleratedWidget DriCursor::GetCursorWindow() { | 82 gfx::AcceleratedWidget DriCursor::GetCursorWindow() { |
| 73 return cursor_window_; | 83 return cursor_widget_; |
| 74 } | 84 } |
| 75 | 85 |
| 76 bool DriCursor::IsCursorVisible() { | 86 bool DriCursor::IsCursorVisible() { |
| 77 return cursor_.get(); | 87 return cursor_.get(); |
| 78 } | 88 } |
| 79 | 89 |
| 80 gfx::PointF DriCursor::location() { | 90 gfx::PointF DriCursor::location() { |
| 81 return cursor_location_; | 91 return cursor_location_; |
| 82 } | 92 } |
| 83 | 93 |
| 84 gfx::Point DriCursor::bitmap_location() { | 94 gfx::Point DriCursor::bitmap_location() { |
| 85 return gfx::ToFlooredPoint(cursor_location_) - | 95 return gfx::ToFlooredPoint(cursor_location_) - |
| 86 cursor_->hotspot().OffsetFromOrigin(); | 96 cursor_->hotspot().OffsetFromOrigin(); |
| 87 } | 97 } |
| 88 | 98 |
| 89 } // namespace ui | 99 } // namespace ui |
| OLD | NEW |