Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #include "ash/wm/image_cursors.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "ui/base/cursor/cursor_loader.h" | |
| 9 #include "ui/base/cursor/cursor.h" | |
| 10 #include "ui/gfx/point.h" | |
| 11 #include "grit/ui_resources.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const int kAnimatedCursorFrameDelayMs = 25; | |
| 16 | |
| 17 struct CursorData { | |
| 18 int id; | |
| 19 int resource_id; | |
| 20 gfx::Point hot_1x; | |
| 21 gfx::Point hot_2x; | |
|
oshima
2012/09/07 23:08:20
this unfortunately will cause a lot of static rein
mazda
2012/09/08 00:27:02
Oh, I see. Replaced gfx::Point with a local struct
| |
| 22 }; | |
| 23 | |
| 24 // The cursor's hot points are defined in chromeos cursor images at: | |
| 25 // http://folder/kuscher/projects/Chrome_OS/Pointers/focuspoint | |
| 26 const CursorData kImageCursors[] = { | |
| 27 {ui::kCursorNull, IDR_AURA_CURSOR_PTR, | |
| 28 gfx::Point(4, 4), gfx::Point(8, 9)}, | |
| 29 {ui::kCursorPointer, IDR_AURA_CURSOR_PTR, | |
| 30 gfx::Point(4, 4), gfx::Point(8, 9)}, | |
| 31 {ui::kCursorNoDrop, IDR_AURA_CURSOR_NO_DROP, | |
| 32 gfx::Point(4, 4), gfx::Point(8, 9)}, | |
| 33 {ui::kCursorNotAllowed, IDR_AURA_CURSOR_NO_DROP, | |
| 34 gfx::Point(4, 4), gfx::Point(8, 9)}, | |
| 35 {ui::kCursorCopy, IDR_AURA_CURSOR_COPY, | |
| 36 gfx::Point(4, 4), gfx::Point(8, 9)}, | |
| 37 {ui::kCursorHand, IDR_AURA_CURSOR_HAND, | |
| 38 gfx::Point(9, 4), gfx::Point(19, 8)}, | |
| 39 {ui::kCursorMove, IDR_AURA_CURSOR_MOVE, | |
| 40 gfx::Point(11, 11), gfx::Point(23, 23)}, | |
| 41 {ui::kCursorNorthEastResize, IDR_AURA_CURSOR_NORTH_EAST_RESIZE, | |
| 42 gfx::Point(12, 11), gfx::Point(25, 23)}, | |
| 43 {ui::kCursorSouthWestResize, IDR_AURA_CURSOR_SOUTH_WEST_RESIZE, | |
| 44 gfx::Point(12, 11), gfx::Point(25, 23)}, | |
| 45 {ui::kCursorSouthEastResize, IDR_AURA_CURSOR_SOUTH_EAST_RESIZE, | |
| 46 gfx::Point(11, 11), gfx::Point(24, 23)}, | |
| 47 {ui::kCursorNorthWestResize, IDR_AURA_CURSOR_NORTH_WEST_RESIZE, | |
| 48 gfx::Point(11, 11), gfx::Point(24, 23)}, | |
| 49 {ui::kCursorNorthResize, IDR_AURA_CURSOR_NORTH_RESIZE, | |
| 50 gfx::Point(11, 12), gfx::Point(23, 23)}, | |
| 51 {ui::kCursorSouthResize, IDR_AURA_CURSOR_SOUTH_RESIZE, | |
| 52 gfx::Point(11, 12), gfx::Point(23, 23)}, | |
| 53 {ui::kCursorEastResize, IDR_AURA_CURSOR_EAST_RESIZE, | |
| 54 gfx::Point(12, 11), gfx::Point(25, 23)}, | |
| 55 {ui::kCursorWestResize, IDR_AURA_CURSOR_WEST_RESIZE, | |
| 56 gfx::Point(12, 11), gfx::Point(25, 23)}, | |
| 57 {ui::kCursorIBeam, IDR_AURA_CURSOR_IBEAM, | |
| 58 gfx::Point(12, 12), gfx::Point(24, 25)}, | |
| 59 {ui::kCursorAlias, IDR_AURA_CURSOR_ALIAS, | |
| 60 gfx::Point(8, 6), gfx::Point(15, 11)}, | |
| 61 {ui::kCursorCell, IDR_AURA_CURSOR_CELL, | |
| 62 gfx::Point(11, 11), gfx::Point(24, 23)}, | |
| 63 {ui::kCursorContextMenu, IDR_AURA_CURSOR_CONTEXT_MENU, | |
| 64 gfx::Point(4, 4), gfx::Point(8, 9)}, | |
| 65 {ui::kCursorCross, IDR_AURA_CURSOR_CROSSHAIR, | |
| 66 gfx::Point(12, 12), gfx::Point(25, 23)}, | |
| 67 {ui::kCursorHelp, IDR_AURA_CURSOR_HELP, | |
| 68 gfx::Point(4, 4), gfx::Point(8, 9)}, | |
| 69 {ui::kCursorVerticalText, IDR_AURA_CURSOR_XTERM_HORIZ, | |
| 70 gfx::Point(12, 11), gfx::Point(26, 23)}, | |
| 71 {ui::kCursorZoomIn, IDR_AURA_CURSOR_ZOOM_IN, | |
| 72 gfx::Point(10, 10), gfx::Point(20, 20)}, | |
| 73 {ui::kCursorZoomOut, IDR_AURA_CURSOR_ZOOM_OUT, | |
| 74 gfx::Point(10, 10), gfx::Point(20, 20)}, | |
| 75 {ui::kCursorRowResize, IDR_AURA_CURSOR_ROW_RESIZE, | |
| 76 gfx::Point(11, 12), gfx::Point(23, 23)}, | |
| 77 {ui::kCursorColumnResize, IDR_AURA_CURSOR_COL_RESIZE, | |
| 78 gfx::Point(12, 11), gfx::Point(25, 23)}, | |
| 79 {ui::kCursorEastWestResize, IDR_AURA_CURSOR_EAST_WEST_RESIZE, | |
| 80 gfx::Point(12, 11), gfx::Point(25, 23)}, | |
| 81 {ui::kCursorNorthSouthResize, IDR_AURA_CURSOR_NORTH_SOUTH_RESIZE, | |
| 82 gfx::Point(11, 12), gfx::Point(23, 23)}, | |
| 83 {ui::kCursorNorthEastSouthWestResize, | |
| 84 IDR_AURA_CURSOR_NORTH_EAST_SOUTH_WEST_RESIZE, | |
| 85 gfx::Point(12, 11), gfx::Point(25, 23)}, | |
| 86 {ui::kCursorNorthWestSouthEastResize, | |
| 87 IDR_AURA_CURSOR_NORTH_WEST_SOUTH_EAST_RESIZE, | |
| 88 gfx::Point(11, 11), gfx::Point(24, 23)}, | |
| 89 {ui::kCursorGrab, IDR_AURA_CURSOR_GRAB, | |
| 90 gfx::Point(8, 5), gfx::Point(16, 10)}, | |
| 91 {ui::kCursorGrabbing, IDR_AURA_CURSOR_GRABBING, | |
| 92 gfx::Point(9, 9), gfx::Point(18, 18)}, | |
| 93 }; | |
| 94 | |
| 95 const CursorData kAnimatedCursors[] = { | |
| 96 {ui::kCursorWait, IDR_THROBBER, gfx::Point(7, 7), gfx::Point(14, 14)}, | |
| 97 {ui::kCursorProgress, IDR_THROBBER, gfx::Point(7, 7), gfx::Point(14, 14)}, | |
| 98 }; | |
| 99 | |
| 100 } // namespace | |
| 101 | |
| 102 namespace ash { | |
| 103 | |
| 104 ImageCursors::ImageCursors() | |
| 105 : cursor_loader_(ui::CursorLoader::Create()) { | |
| 106 } | |
| 107 | |
| 108 ImageCursors::~ImageCursors() { | |
| 109 } | |
| 110 | |
| 111 float ImageCursors::GetDeviceScaleFactor() const { | |
| 112 return cursor_loader_->device_scale_factor(); | |
| 113 } | |
| 114 | |
| 115 void ImageCursors::SetDeviceScaleFactor(float device_scale_factor) { | |
| 116 if (GetDeviceScaleFactor() == device_scale_factor) | |
| 117 return; | |
| 118 | |
| 119 cursor_loader_->UnloadAll(); | |
| 120 cursor_loader_->set_device_scale_factor(device_scale_factor); | |
| 121 | |
| 122 for (size_t i = 0; i < arraysize(kImageCursors); ++i) { | |
| 123 const gfx::Point& hot = device_scale_factor == 1.0f ? | |
| 124 kImageCursors[i].hot_1x : kImageCursors[i].hot_2x; | |
| 125 cursor_loader_->LoadImageCursor(kImageCursors[i].id, | |
| 126 kImageCursors[i].resource_id, | |
| 127 hot); | |
| 128 } | |
| 129 for (size_t i = 0; i < arraysize(kAnimatedCursors); ++i) { | |
| 130 const gfx::Point& hot = device_scale_factor == 1.0f ? | |
| 131 kAnimatedCursors[i].hot_1x : kAnimatedCursors[i].hot_2x; | |
| 132 cursor_loader_->LoadAnimatedCursor(kAnimatedCursors[i].id, | |
| 133 kAnimatedCursors[i].resource_id, | |
| 134 hot, | |
| 135 kAnimatedCursorFrameDelayMs); | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { | |
| 140 cursor_loader_->SetPlatformCursor(cursor); | |
| 141 } | |
| 142 | |
| 143 } // namespace ash | |
| OLD | NEW |