| 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/cursor_factory_evdev_dri.h" | 5 #include "ui/ozone/platform/dri/cursor_factory_evdev_dri.h" |
| 6 | 6 |
| 7 #include "ui/gfx/geometry/point_conversions.h" | 7 #include "ui/gfx/geometry/point_conversions.h" |
| 8 #include "ui/ozone/platform/dri/dri_surface_factory.h" | 8 #include "ui/ozone/platform/dri/dri_surface_factory.h" |
| 9 | 9 |
| 10 namespace ui { | 10 namespace ui { |
| 11 | 11 |
| 12 CursorFactoryEvdevDri::CursorFactoryEvdevDri(DriSurfaceFactory* dri) | 12 CursorFactoryEvdevDri::CursorFactoryEvdevDri(DriSurfaceFactory* dri) |
| 13 : dri_(dri) { | 13 : dri_(dri) { |
| 14 // TODO(dnicoara) Assume the first widget since at this point there are no | 14 // TODO(dnicoara) Assume the first widget since at this point there are no |
| 15 // widgets initialized. | 15 // widgets initialized. |
| 16 cursor_window_ = DriSurfaceFactory::kDefaultWidgetHandle; | 16 cursor_window_ = DriSurfaceFactory::kDefaultWidgetHandle; |
| 17 cursor_bounds_ = gfx::RectF(0, 0, 2560, 1700); // TODO(spang): Argh! | 17 cursor_location_ = gfx::PointF(2560 / 2, 1700 / 2); // TODO(spang): Argh! |
| 18 cursor_location_ = | |
| 19 gfx::PointF(cursor_bounds_.width() / 2, cursor_bounds_.height() / 2); | |
| 20 | 18 |
| 21 // The DRI cursor is invisible unless explicitly set. Therefore, set the | 19 // The DRI cursor is invisible unless explicitly set. Therefore, set the |
| 22 // pointer cursor on initialization. | 20 // pointer cursor on initialization. |
| 23 // TODO(spang): Move this to DRI window initialization. | 21 // TODO(spang): Move this to DRI window initialization. |
| 24 SetCursor(cursor_window_, GetDefaultCursor(kCursorPointer)); | 22 SetCursor(cursor_window_, GetDefaultCursor(kCursorPointer)); |
| 25 } | 23 } |
| 26 | 24 |
| 27 CursorFactoryEvdevDri::~CursorFactoryEvdevDri() {} | 25 CursorFactoryEvdevDri::~CursorFactoryEvdevDri() {} |
| 28 | 26 |
| 29 void CursorFactoryEvdevDri::SetBitmapCursor( | 27 void CursorFactoryEvdevDri::SetBitmapCursor( |
| 30 gfx::AcceleratedWidget widget, | 28 gfx::AcceleratedWidget widget, |
| 31 scoped_refptr<BitmapCursorOzone> cursor) { | 29 scoped_refptr<BitmapCursorOzone> cursor) { |
| 32 if (cursor_ == cursor) | 30 if (cursor_ == cursor) |
| 33 return; | 31 return; |
| 32 |
| 34 cursor_ = cursor; | 33 cursor_ = cursor; |
| 35 if (cursor_) | 34 if (cursor_) |
| 36 dri_->SetHardwareCursor( | 35 dri_->SetHardwareCursor( |
| 37 cursor_window_, cursor_->bitmap(), bitmap_location()); | 36 cursor_window_, cursor_->bitmap(), bitmap_location()); |
| 38 else | 37 else |
| 39 dri_->UnsetHardwareCursor(cursor_window_); | 38 dri_->UnsetHardwareCursor(cursor_window_); |
| 40 } | 39 } |
| 41 | 40 |
| 42 void CursorFactoryEvdevDri::MoveCursorTo(gfx::AcceleratedWidget widget, | 41 void CursorFactoryEvdevDri::MoveCursorTo(gfx::AcceleratedWidget widget, |
| 43 const gfx::PointF& location) { | 42 const gfx::PointF& location) { |
| 43 if (widget != cursor_window_) |
| 44 dri_->UnsetHardwareCursor(cursor_window_); |
| 45 |
| 44 cursor_window_ = widget; | 46 cursor_window_ = widget; |
| 45 cursor_location_ = location; | 47 cursor_location_ = location; |
| 46 cursor_location_.SetToMax( | 48 |
| 47 gfx::PointF(cursor_bounds_.x(), cursor_bounds_.y())); | 49 gfx::Size size = dri_->GetWidgetSize(cursor_window_); |
| 48 cursor_location_.SetToMin( | 50 cursor_location_.SetToMax(gfx::PointF(0, 0)); |
| 49 gfx::PointF(cursor_bounds_.right(), cursor_bounds_.bottom())); | 51 cursor_location_.SetToMin(gfx::PointF(size.width(), size.height())); |
| 52 |
| 50 if (cursor_) | 53 if (cursor_) |
| 51 dri_->MoveHardwareCursor(cursor_window_, bitmap_location()); | 54 dri_->MoveHardwareCursor(cursor_window_, bitmap_location()); |
| 52 } | 55 } |
| 53 | 56 |
| 54 void CursorFactoryEvdevDri::MoveCursor(const gfx::Vector2dF& delta) { | 57 void CursorFactoryEvdevDri::MoveCursor(const gfx::Vector2dF& delta) { |
| 55 MoveCursorTo(cursor_window_, cursor_location_ + delta); | 58 MoveCursorTo(cursor_window_, cursor_location_ + delta); |
| 56 } | 59 } |
| 57 | 60 |
| 58 gfx::AcceleratedWidget CursorFactoryEvdevDri::window() { | 61 gfx::AcceleratedWidget CursorFactoryEvdevDri::window() { |
| 59 return cursor_window_; | 62 return cursor_window_; |
| 60 } | 63 } |
| 61 | 64 |
| 62 gfx::PointF CursorFactoryEvdevDri::location() { return cursor_location_; } | 65 gfx::PointF CursorFactoryEvdevDri::location() { return cursor_location_; } |
| 63 | 66 |
| 64 gfx::Point CursorFactoryEvdevDri::bitmap_location() { | 67 gfx::Point CursorFactoryEvdevDri::bitmap_location() { |
| 65 return gfx::ToFlooredPoint(cursor_location_) - | 68 return gfx::ToFlooredPoint(cursor_location_) - |
| 66 cursor_->hotspot().OffsetFromOrigin(); | 69 cursor_->hotspot().OffsetFromOrigin(); |
| 67 } | 70 } |
| 68 | 71 |
| 69 } // namespace ui | 72 } // namespace ui |
| OLD | NEW |