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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 DCHECK_NE(cursor_window_, gfx::kNullAcceleratedWidget); | 54 DCHECK_NE(cursor_window_, gfx::kNullAcceleratedWidget); |
55 sender_->SetHardwareCursor(cursor_window_, std::vector<SkBitmap>(), | 55 sender_->SetHardwareCursor(cursor_window_, std::vector<SkBitmap>(), |
56 gfx::Point(), 0); | 56 gfx::Point(), 0); |
57 } | 57 } |
58 | 58 |
59 void DriCursor::MoveCursorTo(gfx::AcceleratedWidget widget, | 59 void DriCursor::MoveCursorTo(gfx::AcceleratedWidget widget, |
60 const gfx::PointF& location) { | 60 const gfx::PointF& location) { |
61 if (widget != cursor_window_ && cursor_window_ != gfx::kNullAcceleratedWidget) | 61 if (widget != cursor_window_ && cursor_window_ != gfx::kNullAcceleratedWidget) |
62 HideCursor(); | 62 HideCursor(); |
63 | 63 |
| 64 DriWindow* window = window_manager_->GetWindow(widget); |
| 65 |
64 cursor_window_ = widget; | 66 cursor_window_ = widget; |
65 cursor_location_ = location; | 67 cursor_location_ = location; |
| 68 cursor_display_bounds_ = window->GetBounds(); |
66 | 69 |
67 if (cursor_window_ == gfx::kNullAcceleratedWidget) | 70 const gfx::Size& size = cursor_display_bounds_.size(); |
68 return; | |
69 | |
70 DriWindow* window = window_manager_->GetWindow(cursor_window_); | |
71 const gfx::Size& size = window->GetBounds().size(); | |
72 cursor_location_.SetToMax(gfx::PointF(0, 0)); | 71 cursor_location_.SetToMax(gfx::PointF(0, 0)); |
73 // Right and bottom edges are exclusive. | 72 // Right and bottom edges are exclusive. |
74 cursor_location_.SetToMin(gfx::PointF(size.width() - 1, size.height() - 1)); | 73 cursor_location_.SetToMin(gfx::PointF(size.width() - 1, size.height() - 1)); |
75 | 74 |
76 if (cursor_.get()) | 75 if (cursor_.get()) |
77 sender_->MoveHardwareCursor(cursor_window_, bitmap_location()); | 76 sender_->MoveHardwareCursor(cursor_window_, bitmap_location()); |
78 } | 77 } |
79 | 78 |
80 void DriCursor::MoveCursorTo(const gfx::PointF& location) { | 79 void DriCursor::MoveCursorTo(const gfx::PointF& location) { |
81 DriWindow* window = | 80 DriWindow* window = |
82 window_manager_->GetWindowAt(gfx::ToFlooredPoint(location)); | 81 window_manager_->GetWindowAt(gfx::ToFlooredPoint(location)); |
83 if (!window) | 82 if (!window) |
84 return; | 83 return; |
85 | 84 |
86 MoveCursorTo(window->GetAcceleratedWidget(), | 85 MoveCursorTo(window->GetAcceleratedWidget(), |
87 location - window->GetBounds().OffsetFromOrigin()); | 86 location - window->GetBounds().OffsetFromOrigin()); |
88 } | 87 } |
89 | 88 |
90 void DriCursor::MoveCursor(const gfx::Vector2dF& delta) { | 89 void DriCursor::MoveCursor(const gfx::Vector2dF& delta) { |
| 90 if (cursor_window_ == gfx::kNullAcceleratedWidget) |
| 91 return; |
| 92 |
91 #if defined(OS_CHROMEOS) | 93 #if defined(OS_CHROMEOS) |
92 gfx::Vector2dF transformed_delta = delta; | 94 gfx::Vector2dF transformed_delta = delta; |
93 ui::CursorController::GetInstance()->ApplyCursorConfigForWindow( | 95 ui::CursorController::GetInstance()->ApplyCursorConfigForWindow( |
94 cursor_window_, &transformed_delta); | 96 cursor_window_, &transformed_delta); |
95 MoveCursorTo(cursor_window_, cursor_location_ + transformed_delta); | 97 MoveCursorTo(cursor_window_, cursor_location_ + transformed_delta); |
96 #else | 98 #else |
97 MoveCursorTo(cursor_window_, cursor_location_ + delta); | 99 MoveCursorTo(cursor_window_, cursor_location_ + delta); |
98 #endif | 100 #endif |
99 } | 101 } |
100 | 102 |
101 gfx::Rect DriCursor::GetCursorDisplayBounds() { | 103 gfx::Rect DriCursor::GetCursorDisplayBounds() { |
102 if (cursor_window_ == gfx::kNullAcceleratedWidget) | 104 return cursor_display_bounds_; |
103 return gfx::Rect(); | |
104 | |
105 DriWindow* window = window_manager_->GetWindow(cursor_window_); | |
106 return window->GetBounds(); | |
107 } | 105 } |
108 | 106 |
109 gfx::AcceleratedWidget DriCursor::GetCursorWindow() { | 107 gfx::AcceleratedWidget DriCursor::GetCursorWindow() { |
110 return cursor_window_; | 108 return cursor_window_; |
111 } | 109 } |
112 | 110 |
113 bool DriCursor::IsCursorVisible() { | 111 bool DriCursor::IsCursorVisible() { |
114 return cursor_.get(); | 112 return cursor_.get(); |
115 } | 113 } |
116 | 114 |
117 gfx::PointF DriCursor::location() { | 115 gfx::PointF DriCursor::location() { |
118 return cursor_location_; | 116 return cursor_location_; |
119 } | 117 } |
120 | 118 |
121 gfx::Point DriCursor::bitmap_location() { | 119 gfx::Point DriCursor::bitmap_location() { |
122 return gfx::ToFlooredPoint(cursor_location_) - | 120 return gfx::ToFlooredPoint(cursor_location_) - |
123 cursor_->hotspot().OffsetFromOrigin(); | 121 cursor_->hotspot().OffsetFromOrigin(); |
124 } | 122 } |
125 | 123 |
126 } // namespace ui | 124 } // namespace ui |
OLD | NEW |