Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / events / ozone / chromeos / cursor_controller.cc
blobc407765f1fe1d6f19bff25264486eb0d18e0d3ea
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
3 // found in the LICENSE file.
5 #include "ui/events/ozone/chromeos/cursor_controller.h"
7 namespace ui {
9 namespace {
11 void TransformCursorMove(gfx::Display::Rotation rotation,
12 float scale,
13 gfx::Vector2dF* delta) {
14 float dx;
15 float dy;
17 switch (rotation) {
18 case gfx::Display::ROTATE_90:
19 dx = -delta->y();
20 dy = delta->x();
21 break;
22 case gfx::Display::ROTATE_180:
23 dx = -delta->x();
24 dy = -delta->y();
25 break;
26 case gfx::Display::ROTATE_270:
27 dx = delta->y();
28 dy = -delta->x();
29 break;
30 default: // gfx::Display::ROTATE_0
31 dx = delta->x();
32 dy = delta->y();
33 break;
36 delta->set_x(dx * scale);
37 delta->set_y(dy * scale);
40 } // namespace
42 // static
43 CursorController* CursorController::GetInstance() {
44 return Singleton<CursorController>::get();
47 void CursorController::SetCursorConfigForWindow(gfx::AcceleratedWidget widget,
48 gfx::Display::Rotation rotation,
49 float scale) {
50 base::AutoLock lock(window_to_cursor_configuration_map_lock_);
51 PerWindowCursorConfiguration config = {rotation, scale};
52 window_to_cursor_configuration_map_[widget] = config;
55 void CursorController::ClearCursorConfigForWindow(
56 gfx::AcceleratedWidget widget) {
57 window_to_cursor_configuration_map_.erase(widget);
60 void CursorController::ApplyCursorConfigForWindow(gfx::AcceleratedWidget widget,
61 gfx::Vector2dF* delta) const {
62 base::AutoLock lock(window_to_cursor_configuration_map_lock_);
63 auto it = window_to_cursor_configuration_map_.find(widget);
64 if (it != window_to_cursor_configuration_map_.end())
65 TransformCursorMove(it->second.rotation, it->second.scale, delta);
68 CursorController::CursorController() {
71 CursorController::~CursorController() {
74 } // namespace ui