| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ash/wm/image_cursors.h" | 5 #include "ui/base/cursor/image_cursors.h" |
| 6 | 6 |
| 7 #include <float.h> | 7 #include <float.h> |
| 8 | 8 |
| 9 #include "ash/display/display_info.h" | |
| 10 #include "ash/display/display_manager.h" | |
| 11 #include "ash/shell.h" | |
| 12 #include "base/logging.h" | 9 #include "base/logging.h" |
| 13 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 14 #include "ui/base/cursor/cursor.h" | 11 #include "ui/base/cursor/cursor.h" |
| 15 #include "ui/base/cursor/cursor_loader.h" | 12 #include "ui/base/cursor/cursor_loader.h" |
| 16 #include "ui/base/cursor/cursors_aura.h" | 13 #include "ui/base/cursor/cursors_aura.h" |
| 17 #include "ui/gfx/display.h" | 14 #include "ui/gfx/display.h" |
| 18 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
| 19 | 16 |
| 20 namespace ash { | 17 namespace ui { |
| 18 |
| 19 namespace { |
| 21 | 20 |
| 22 const int kImageCursorIds[] = { | 21 const int kImageCursorIds[] = { |
| 23 ui::kCursorNull, | 22 kCursorNull, |
| 24 ui::kCursorPointer, | 23 kCursorPointer, |
| 25 ui::kCursorNoDrop, | 24 kCursorNoDrop, |
| 26 ui::kCursorNotAllowed, | 25 kCursorNotAllowed, |
| 27 ui::kCursorCopy, | 26 kCursorCopy, |
| 28 ui::kCursorHand, | 27 kCursorHand, |
| 29 ui::kCursorMove, | 28 kCursorMove, |
| 30 ui::kCursorNorthEastResize, | 29 kCursorNorthEastResize, |
| 31 ui::kCursorSouthWestResize, | 30 kCursorSouthWestResize, |
| 32 ui::kCursorSouthEastResize, | 31 kCursorSouthEastResize, |
| 33 ui::kCursorNorthWestResize, | 32 kCursorNorthWestResize, |
| 34 ui::kCursorNorthResize, | 33 kCursorNorthResize, |
| 35 ui::kCursorSouthResize, | 34 kCursorSouthResize, |
| 36 ui::kCursorEastResize, | 35 kCursorEastResize, |
| 37 ui::kCursorWestResize, | 36 kCursorWestResize, |
| 38 ui::kCursorIBeam, | 37 kCursorIBeam, |
| 39 ui::kCursorAlias, | 38 kCursorAlias, |
| 40 ui::kCursorCell, | 39 kCursorCell, |
| 41 ui::kCursorContextMenu, | 40 kCursorContextMenu, |
| 42 ui::kCursorCross, | 41 kCursorCross, |
| 43 ui::kCursorHelp, | 42 kCursorHelp, |
| 44 ui::kCursorVerticalText, | 43 kCursorVerticalText, |
| 45 ui::kCursorZoomIn, | 44 kCursorZoomIn, |
| 46 ui::kCursorZoomOut, | 45 kCursorZoomOut, |
| 47 ui::kCursorRowResize, | 46 kCursorRowResize, |
| 48 ui::kCursorColumnResize, | 47 kCursorColumnResize, |
| 49 ui::kCursorEastWestResize, | 48 kCursorEastWestResize, |
| 50 ui::kCursorNorthSouthResize, | 49 kCursorNorthSouthResize, |
| 51 ui::kCursorNorthEastSouthWestResize, | 50 kCursorNorthEastSouthWestResize, |
| 52 ui::kCursorNorthWestSouthEastResize, | 51 kCursorNorthWestSouthEastResize, |
| 53 ui::kCursorGrab, | 52 kCursorGrab, |
| 54 ui::kCursorGrabbing, | 53 kCursorGrabbing, |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 const int kAnimatedCursorIds[] = { | 56 const int kAnimatedCursorIds[] = { |
| 58 ui::kCursorWait, | 57 kCursorWait, |
| 59 ui::kCursorProgress | 58 kCursorProgress |
| 60 }; | 59 }; |
| 61 | 60 |
| 62 ImageCursors::ImageCursors() : cursor_set_(ui::CURSOR_SET_NORMAL) { | 61 } // namespace |
| 62 |
| 63 ImageCursors::ImageCursors() : cursor_set_(CURSOR_SET_NORMAL) { |
| 63 } | 64 } |
| 64 | 65 |
| 65 ImageCursors::~ImageCursors() { | 66 ImageCursors::~ImageCursors() { |
| 66 } | 67 } |
| 67 | 68 |
| 68 float ImageCursors::GetScale() const { | 69 float ImageCursors::GetScale() const { |
| 69 if (!cursor_loader_) { | 70 if (!cursor_loader_) { |
| 70 NOTREACHED(); | 71 NOTREACHED(); |
| 71 // Returning default on release build as it's not serious enough to crash | 72 // Returning default on release build as it's not serious enough to crash |
| 72 // even if this ever happens. | 73 // even if this ever happens. |
| 73 return 1.0f; | 74 return 1.0f; |
| 74 } | 75 } |
| 75 return cursor_loader_->scale(); | 76 return cursor_loader_->scale(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 gfx::Display::Rotation ImageCursors::GetRotation() const { | 79 gfx::Display::Rotation ImageCursors::GetRotation() const { |
| 79 if (!cursor_loader_) { | 80 if (!cursor_loader_) { |
| 80 NOTREACHED(); | 81 NOTREACHED(); |
| 81 // Returning default on release build as it's not serious enough to crash | 82 // Returning default on release build as it's not serious enough to crash |
| 82 // even if this ever happens. | 83 // even if this ever happens. |
| 83 return gfx::Display::ROTATE_0; | 84 return gfx::Display::ROTATE_0; |
| 84 } | 85 } |
| 85 return cursor_loader_->rotation(); | 86 return cursor_loader_->rotation(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 bool ImageCursors::SetDisplay(const gfx::Display& display) { | 89 bool ImageCursors::SetDisplay(const gfx::Display& display, |
| 89 DCHECK(display.is_valid()); | 90 float scale_factor) { |
| 90 // Use the platform's device scale factor instead of display's | |
| 91 // that might have been adjusted for UI scale. | |
| 92 float scale_factor = Shell::GetInstance()->display_manager()-> | |
| 93 GetDisplayInfo(display.id()).device_scale_factor(); | |
| 94 | |
| 95 if (!cursor_loader_) { | 91 if (!cursor_loader_) { |
| 96 cursor_loader_.reset(ui::CursorLoader::Create()); | 92 cursor_loader_.reset(CursorLoader::Create()); |
| 97 } else if (cursor_loader_->rotation() == display.rotation() && | 93 } else if (cursor_loader_->rotation() == display.rotation() && |
| 98 cursor_loader_->scale() == scale_factor) { | 94 cursor_loader_->scale() == scale_factor) { |
| 99 return false; | 95 return false; |
| 100 } | 96 } |
| 101 | 97 |
| 102 cursor_loader_->set_rotation(display.rotation()); | 98 cursor_loader_->set_rotation(display.rotation()); |
| 103 cursor_loader_->set_scale(scale_factor); | 99 cursor_loader_->set_scale(scale_factor); |
| 104 ReloadCursors(); | 100 ReloadCursors(); |
| 105 return true; | 101 return true; |
| 106 } | 102 } |
| 107 | 103 |
| 108 void ImageCursors::ReloadCursors() { | 104 void ImageCursors::ReloadCursors() { |
| 109 float device_scale_factor = cursor_loader_->scale(); | 105 float device_scale_factor = cursor_loader_->scale(); |
| 110 | 106 |
| 111 cursor_loader_->UnloadAll(); | 107 cursor_loader_->UnloadAll(); |
| 112 | 108 |
| 113 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) { | 109 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) { |
| 114 int resource_id = -1; | 110 int resource_id = -1; |
| 115 gfx::Point hot_point; | 111 gfx::Point hot_point; |
| 116 bool success = ui::GetCursorDataFor(cursor_set_, | 112 bool success = GetCursorDataFor(cursor_set_, |
| 117 kImageCursorIds[i], | 113 kImageCursorIds[i], |
| 118 device_scale_factor, | 114 device_scale_factor, |
| 119 &resource_id, | 115 &resource_id, |
| 120 &hot_point); | 116 &hot_point); |
| 121 DCHECK(success); | 117 DCHECK(success); |
| 122 cursor_loader_->LoadImageCursor(kImageCursorIds[i], resource_id, hot_point); | 118 cursor_loader_->LoadImageCursor(kImageCursorIds[i], resource_id, hot_point); |
| 123 } | 119 } |
| 124 for (size_t i = 0; i < arraysize(kAnimatedCursorIds); ++i) { | 120 for (size_t i = 0; i < arraysize(kAnimatedCursorIds); ++i) { |
| 125 int resource_id = -1; | 121 int resource_id = -1; |
| 126 gfx::Point hot_point; | 122 gfx::Point hot_point; |
| 127 bool success = ui::GetAnimatedCursorDataFor(cursor_set_, | 123 bool success = GetAnimatedCursorDataFor(cursor_set_, |
| 128 kAnimatedCursorIds[i], | 124 kAnimatedCursorIds[i], |
| 129 device_scale_factor, | 125 device_scale_factor, |
| 130 &resource_id, | 126 &resource_id, |
| 131 &hot_point); | 127 &hot_point); |
| 132 DCHECK(success); | 128 DCHECK(success); |
| 133 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i], | 129 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i], |
| 134 resource_id, | 130 resource_id, |
| 135 hot_point, | 131 hot_point, |
| 136 ui::kAnimatedCursorFrameDelayMs); | 132 kAnimatedCursorFrameDelayMs); |
| 137 } | 133 } |
| 138 } | 134 } |
| 139 | 135 |
| 140 void ImageCursors::SetCursorSet(ui::CursorSetType cursor_set) { | 136 void ImageCursors::SetCursorSet(CursorSetType cursor_set) { |
| 141 if (cursor_set_ == cursor_set) | 137 if (cursor_set_ == cursor_set) |
| 142 return; | 138 return; |
| 143 | 139 |
| 144 cursor_set_ = cursor_set; | 140 cursor_set_ = cursor_set; |
| 145 | 141 |
| 146 if (cursor_loader_.get()) | 142 if (cursor_loader_.get()) |
| 147 ReloadCursors(); | 143 ReloadCursors(); |
| 148 } | 144 } |
| 149 | 145 |
| 150 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { | 146 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { |
| 151 cursor_loader_->SetPlatformCursor(cursor); | 147 cursor_loader_->SetPlatformCursor(cursor); |
| 152 } | 148 } |
| 153 | 149 |
| 154 } // namespace ash | 150 } // namespace ui |
| OLD | NEW |