Index: ash/wm/image_cursors.cc |
diff --git a/ash/wm/image_cursors.cc b/ash/wm/image_cursors.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..24c000ab7c93cc7e1b8f9cc3e673abcc588861e5 |
--- /dev/null |
+++ b/ash/wm/image_cursors.cc |
@@ -0,0 +1,143 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/wm/image_cursors.h" |
+ |
+#include "base/logging.h" |
+#include "ui/base/cursor/cursor_loader.h" |
+#include "ui/base/cursor/cursor.h" |
+#include "ui/gfx/point.h" |
+#include "grit/ui_resources.h" |
+ |
+namespace { |
+ |
+const int kAnimatedCursorFrameDelayMs = 25; |
+ |
+struct CursorData { |
+ int id; |
+ int resource_id; |
+ gfx::Point hot_1x; |
+ 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
|
+}; |
+ |
+// The cursor's hot points are defined in chromeos cursor images at: |
+// http://folder/kuscher/projects/Chrome_OS/Pointers/focuspoint |
+const CursorData kImageCursors[] = { |
+ {ui::kCursorNull, IDR_AURA_CURSOR_PTR, |
+ gfx::Point(4, 4), gfx::Point(8, 9)}, |
+ {ui::kCursorPointer, IDR_AURA_CURSOR_PTR, |
+ gfx::Point(4, 4), gfx::Point(8, 9)}, |
+ {ui::kCursorNoDrop, IDR_AURA_CURSOR_NO_DROP, |
+ gfx::Point(4, 4), gfx::Point(8, 9)}, |
+ {ui::kCursorNotAllowed, IDR_AURA_CURSOR_NO_DROP, |
+ gfx::Point(4, 4), gfx::Point(8, 9)}, |
+ {ui::kCursorCopy, IDR_AURA_CURSOR_COPY, |
+ gfx::Point(4, 4), gfx::Point(8, 9)}, |
+ {ui::kCursorHand, IDR_AURA_CURSOR_HAND, |
+ gfx::Point(9, 4), gfx::Point(19, 8)}, |
+ {ui::kCursorMove, IDR_AURA_CURSOR_MOVE, |
+ gfx::Point(11, 11), gfx::Point(23, 23)}, |
+ {ui::kCursorNorthEastResize, IDR_AURA_CURSOR_NORTH_EAST_RESIZE, |
+ gfx::Point(12, 11), gfx::Point(25, 23)}, |
+ {ui::kCursorSouthWestResize, IDR_AURA_CURSOR_SOUTH_WEST_RESIZE, |
+ gfx::Point(12, 11), gfx::Point(25, 23)}, |
+ {ui::kCursorSouthEastResize, IDR_AURA_CURSOR_SOUTH_EAST_RESIZE, |
+ gfx::Point(11, 11), gfx::Point(24, 23)}, |
+ {ui::kCursorNorthWestResize, IDR_AURA_CURSOR_NORTH_WEST_RESIZE, |
+ gfx::Point(11, 11), gfx::Point(24, 23)}, |
+ {ui::kCursorNorthResize, IDR_AURA_CURSOR_NORTH_RESIZE, |
+ gfx::Point(11, 12), gfx::Point(23, 23)}, |
+ {ui::kCursorSouthResize, IDR_AURA_CURSOR_SOUTH_RESIZE, |
+ gfx::Point(11, 12), gfx::Point(23, 23)}, |
+ {ui::kCursorEastResize, IDR_AURA_CURSOR_EAST_RESIZE, |
+ gfx::Point(12, 11), gfx::Point(25, 23)}, |
+ {ui::kCursorWestResize, IDR_AURA_CURSOR_WEST_RESIZE, |
+ gfx::Point(12, 11), gfx::Point(25, 23)}, |
+ {ui::kCursorIBeam, IDR_AURA_CURSOR_IBEAM, |
+ gfx::Point(12, 12), gfx::Point(24, 25)}, |
+ {ui::kCursorAlias, IDR_AURA_CURSOR_ALIAS, |
+ gfx::Point(8, 6), gfx::Point(15, 11)}, |
+ {ui::kCursorCell, IDR_AURA_CURSOR_CELL, |
+ gfx::Point(11, 11), gfx::Point(24, 23)}, |
+ {ui::kCursorContextMenu, IDR_AURA_CURSOR_CONTEXT_MENU, |
+ gfx::Point(4, 4), gfx::Point(8, 9)}, |
+ {ui::kCursorCross, IDR_AURA_CURSOR_CROSSHAIR, |
+ gfx::Point(12, 12), gfx::Point(25, 23)}, |
+ {ui::kCursorHelp, IDR_AURA_CURSOR_HELP, |
+ gfx::Point(4, 4), gfx::Point(8, 9)}, |
+ {ui::kCursorVerticalText, IDR_AURA_CURSOR_XTERM_HORIZ, |
+ gfx::Point(12, 11), gfx::Point(26, 23)}, |
+ {ui::kCursorZoomIn, IDR_AURA_CURSOR_ZOOM_IN, |
+ gfx::Point(10, 10), gfx::Point(20, 20)}, |
+ {ui::kCursorZoomOut, IDR_AURA_CURSOR_ZOOM_OUT, |
+ gfx::Point(10, 10), gfx::Point(20, 20)}, |
+ {ui::kCursorRowResize, IDR_AURA_CURSOR_ROW_RESIZE, |
+ gfx::Point(11, 12), gfx::Point(23, 23)}, |
+ {ui::kCursorColumnResize, IDR_AURA_CURSOR_COL_RESIZE, |
+ gfx::Point(12, 11), gfx::Point(25, 23)}, |
+ {ui::kCursorEastWestResize, IDR_AURA_CURSOR_EAST_WEST_RESIZE, |
+ gfx::Point(12, 11), gfx::Point(25, 23)}, |
+ {ui::kCursorNorthSouthResize, IDR_AURA_CURSOR_NORTH_SOUTH_RESIZE, |
+ gfx::Point(11, 12), gfx::Point(23, 23)}, |
+ {ui::kCursorNorthEastSouthWestResize, |
+ IDR_AURA_CURSOR_NORTH_EAST_SOUTH_WEST_RESIZE, |
+ gfx::Point(12, 11), gfx::Point(25, 23)}, |
+ {ui::kCursorNorthWestSouthEastResize, |
+ IDR_AURA_CURSOR_NORTH_WEST_SOUTH_EAST_RESIZE, |
+ gfx::Point(11, 11), gfx::Point(24, 23)}, |
+ {ui::kCursorGrab, IDR_AURA_CURSOR_GRAB, |
+ gfx::Point(8, 5), gfx::Point(16, 10)}, |
+ {ui::kCursorGrabbing, IDR_AURA_CURSOR_GRABBING, |
+ gfx::Point(9, 9), gfx::Point(18, 18)}, |
+}; |
+ |
+const CursorData kAnimatedCursors[] = { |
+ {ui::kCursorWait, IDR_THROBBER, gfx::Point(7, 7), gfx::Point(14, 14)}, |
+ {ui::kCursorProgress, IDR_THROBBER, gfx::Point(7, 7), gfx::Point(14, 14)}, |
+}; |
+ |
+} // namespace |
+ |
+namespace ash { |
+ |
+ImageCursors::ImageCursors() |
+ : cursor_loader_(ui::CursorLoader::Create()) { |
+} |
+ |
+ImageCursors::~ImageCursors() { |
+} |
+ |
+float ImageCursors::GetDeviceScaleFactor() const { |
+ return cursor_loader_->device_scale_factor(); |
+} |
+ |
+void ImageCursors::SetDeviceScaleFactor(float device_scale_factor) { |
+ if (GetDeviceScaleFactor() == device_scale_factor) |
+ return; |
+ |
+ cursor_loader_->UnloadAll(); |
+ cursor_loader_->set_device_scale_factor(device_scale_factor); |
+ |
+ for (size_t i = 0; i < arraysize(kImageCursors); ++i) { |
+ const gfx::Point& hot = device_scale_factor == 1.0f ? |
+ kImageCursors[i].hot_1x : kImageCursors[i].hot_2x; |
+ cursor_loader_->LoadImageCursor(kImageCursors[i].id, |
+ kImageCursors[i].resource_id, |
+ hot); |
+ } |
+ for (size_t i = 0; i < arraysize(kAnimatedCursors); ++i) { |
+ const gfx::Point& hot = device_scale_factor == 1.0f ? |
+ kAnimatedCursors[i].hot_1x : kAnimatedCursors[i].hot_2x; |
+ cursor_loader_->LoadAnimatedCursor(kAnimatedCursors[i].id, |
+ kAnimatedCursors[i].resource_id, |
+ hot, |
+ kAnimatedCursorFrameDelayMs); |
+ } |
+} |
+ |
+void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { |
+ cursor_loader_->SetPlatformCursor(cursor); |
+} |
+ |
+} // namespace ash |