| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/events/ozone/chromeos/cursor_controller.h" | 5 #include "ui/events/ozone/chromeos/cursor_controller.h" |
| 6 | 6 |
| 7 namespace ui { | 7 namespace ui { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 void TransformCursorMove(gfx::Display::Rotation rotation, | 11 void TransformCursorMove(display::Display::Rotation rotation, |
| 12 float scale, | 12 float scale, |
| 13 gfx::Vector2dF* delta) { | 13 gfx::Vector2dF* delta) { |
| 14 float dx; | 14 float dx; |
| 15 float dy; | 15 float dy; |
| 16 | 16 |
| 17 switch (rotation) { | 17 switch (rotation) { |
| 18 case gfx::Display::ROTATE_90: | 18 case display::Display::ROTATE_90: |
| 19 dx = -delta->y(); | 19 dx = -delta->y(); |
| 20 dy = delta->x(); | 20 dy = delta->x(); |
| 21 break; | 21 break; |
| 22 case gfx::Display::ROTATE_180: | 22 case display::Display::ROTATE_180: |
| 23 dx = -delta->x(); | 23 dx = -delta->x(); |
| 24 dy = -delta->y(); | 24 dy = -delta->y(); |
| 25 break; | 25 break; |
| 26 case gfx::Display::ROTATE_270: | 26 case display::Display::ROTATE_270: |
| 27 dx = delta->y(); | 27 dx = delta->y(); |
| 28 dy = -delta->x(); | 28 dy = -delta->x(); |
| 29 break; | 29 break; |
| 30 default: // gfx::Display::ROTATE_0 | 30 default: // display::Display::ROTATE_0 |
| 31 dx = delta->x(); | 31 dx = delta->x(); |
| 32 dy = delta->y(); | 32 dy = delta->y(); |
| 33 break; | 33 break; |
| 34 } | 34 } |
| 35 | 35 |
| 36 delta->set_x(dx * scale); | 36 delta->set_x(dx * scale); |
| 37 delta->set_y(dy * scale); | 37 delta->set_y(dy * scale); |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 // static | 42 // static |
| 43 CursorController* CursorController::GetInstance() { | 43 CursorController* CursorController::GetInstance() { |
| 44 return base::Singleton<CursorController>::get(); | 44 return base::Singleton<CursorController>::get(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void CursorController::SetCursorConfigForWindow(gfx::AcceleratedWidget widget, | 47 void CursorController::SetCursorConfigForWindow( |
| 48 gfx::Display::Rotation rotation, | 48 gfx::AcceleratedWidget widget, |
| 49 float scale) { | 49 display::Display::Rotation rotation, |
| 50 float scale) { |
| 50 base::AutoLock lock(window_to_cursor_configuration_map_lock_); | 51 base::AutoLock lock(window_to_cursor_configuration_map_lock_); |
| 51 PerWindowCursorConfiguration config = {rotation, scale}; | 52 PerWindowCursorConfiguration config = {rotation, scale}; |
| 52 window_to_cursor_configuration_map_[widget] = config; | 53 window_to_cursor_configuration_map_[widget] = config; |
| 53 } | 54 } |
| 54 | 55 |
| 55 void CursorController::ClearCursorConfigForWindow( | 56 void CursorController::ClearCursorConfigForWindow( |
| 56 gfx::AcceleratedWidget widget) { | 57 gfx::AcceleratedWidget widget) { |
| 57 window_to_cursor_configuration_map_.erase(widget); | 58 window_to_cursor_configuration_map_.erase(widget); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void CursorController::ApplyCursorConfigForWindow(gfx::AcceleratedWidget widget, | 61 void CursorController::ApplyCursorConfigForWindow(gfx::AcceleratedWidget widget, |
| 61 gfx::Vector2dF* delta) const { | 62 gfx::Vector2dF* delta) const { |
| 62 base::AutoLock lock(window_to_cursor_configuration_map_lock_); | 63 base::AutoLock lock(window_to_cursor_configuration_map_lock_); |
| 63 auto it = window_to_cursor_configuration_map_.find(widget); | 64 auto it = window_to_cursor_configuration_map_.find(widget); |
| 64 if (it != window_to_cursor_configuration_map_.end()) | 65 if (it != window_to_cursor_configuration_map_.end()) |
| 65 TransformCursorMove(it->second.rotation, it->second.scale, delta); | 66 TransformCursorMove(it->second.rotation, it->second.scale, delta); |
| 66 } | 67 } |
| 67 | 68 |
| 68 CursorController::CursorController() { | 69 CursorController::CursorController() { |
| 69 } | 70 } |
| 70 | 71 |
| 71 CursorController::~CursorController() { | 72 CursorController::~CursorController() { |
| 72 } | 73 } |
| 73 | 74 |
| 74 } // namespace ui | 75 } // namespace ui |
| OLD | NEW |