| 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 "ash/wm/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 ash { |
| 21 | 18 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 ui::kCursorNorthWestSouthEastResize, | 49 ui::kCursorNorthWestSouthEastResize, |
| 53 ui::kCursorGrab, | 50 ui::kCursorGrab, |
| 54 ui::kCursorGrabbing, | 51 ui::kCursorGrabbing, |
| 55 }; | 52 }; |
| 56 | 53 |
| 57 const int kAnimatedCursorIds[] = { | 54 const int kAnimatedCursorIds[] = { |
| 58 ui::kCursorWait, | 55 ui::kCursorWait, |
| 59 ui::kCursorProgress | 56 ui::kCursorProgress |
| 60 }; | 57 }; |
| 61 | 58 |
| 62 ImageCursors::ImageCursors() : cursor_set_(ui::CURSOR_SET_NORMAL) { | 59 ImageCursors::ImageCursors() : scale_(1.f), cursor_set_(ui::CURSOR_SET_NORMAL) { |
| 63 } | 60 } |
| 64 | 61 |
| 65 ImageCursors::~ImageCursors() { | 62 ImageCursors::~ImageCursors() { |
| 66 } | 63 } |
| 67 | 64 |
| 68 float ImageCursors::GetScale() const { | 65 gfx::Display ImageCursors::GetDisplay() const { |
| 69 if (!cursor_loader_) { | 66 if (!cursor_loader_) { |
| 70 NOTREACHED(); | 67 NOTREACHED(); |
| 71 // Returning default on release build as it's not serious enough to crash | 68 // Returning default on release build as it's not serious enough to crash |
| 72 // even if this ever happens. | 69 // even if this ever happens. |
| 73 return 1.0f; | 70 return gfx::Display(); |
| 74 } | 71 } |
| 75 return cursor_loader_->scale(); | 72 return cursor_loader_->display(); |
| 76 } | |
| 77 | |
| 78 gfx::Display::Rotation ImageCursors::GetRotation() const { | |
| 79 if (!cursor_loader_) { | |
| 80 NOTREACHED(); | |
| 81 // Returning default on release build as it's not serious enough to crash | |
| 82 // even if this ever happens. | |
| 83 return gfx::Display::ROTATE_0; | |
| 84 } | |
| 85 return cursor_loader_->rotation(); | |
| 86 } | 73 } |
| 87 | 74 |
| 88 bool ImageCursors::SetDisplay(const gfx::Display& display) { | 75 bool ImageCursors::SetDisplay(const gfx::Display& display) { |
| 89 DCHECK(display.is_valid()); | 76 float device_scale_factor = display.device_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_) { | 77 if (!cursor_loader_) { |
| 96 cursor_loader_.reset(ui::CursorLoader::Create()); | 78 cursor_loader_.reset(ui::CursorLoader::Create()); |
| 97 } else if (cursor_loader_->rotation() == display.rotation() && | 79 cursor_loader_->set_scale(scale_); |
| 98 cursor_loader_->scale() == scale_factor) { | 80 } else if (cursor_loader_->display().rotation() == display.rotation() && |
| 81 cursor_loader_->display().device_scale_factor() == |
| 82 device_scale_factor) { |
| 99 return false; | 83 return false; |
| 100 } | 84 } |
| 101 | 85 |
| 102 cursor_loader_->set_rotation(display.rotation()); | 86 cursor_loader_->set_display(display); |
| 103 cursor_loader_->set_scale(scale_factor); | |
| 104 ReloadCursors(); | 87 ReloadCursors(); |
| 105 return true; | 88 return true; |
| 106 } | 89 } |
| 107 | 90 |
| 108 void ImageCursors::ReloadCursors() { | 91 void ImageCursors::ReloadCursors() { |
| 109 float device_scale_factor = cursor_loader_->scale(); | 92 const gfx::Display& display = cursor_loader_->display(); |
| 93 float device_scale_factor = display.device_scale_factor(); |
| 110 | 94 |
| 111 cursor_loader_->UnloadAll(); | 95 cursor_loader_->UnloadAll(); |
| 112 | 96 |
| 113 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) { | 97 for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) { |
| 114 int resource_id = -1; | 98 int resource_id = -1; |
| 115 gfx::Point hot_point; | 99 gfx::Point hot_point; |
| 116 bool success = ui::GetCursorDataFor(cursor_set_, | 100 bool success = ui::GetCursorDataFor(cursor_set_, |
| 117 kImageCursorIds[i], | 101 kImageCursorIds[i], |
| 118 device_scale_factor, | 102 device_scale_factor, |
| 119 &resource_id, | 103 &resource_id, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 130 &resource_id, | 114 &resource_id, |
| 131 &hot_point); | 115 &hot_point); |
| 132 DCHECK(success); | 116 DCHECK(success); |
| 133 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i], | 117 cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i], |
| 134 resource_id, | 118 resource_id, |
| 135 hot_point, | 119 hot_point, |
| 136 ui::kAnimatedCursorFrameDelayMs); | 120 ui::kAnimatedCursorFrameDelayMs); |
| 137 } | 121 } |
| 138 } | 122 } |
| 139 | 123 |
| 124 void ImageCursors::SetScale(float scale) { |
| 125 if (scale < FLT_EPSILON) { |
| 126 NOTREACHED() << "Scale must be bigger than 0."; |
| 127 scale = 1.0f; |
| 128 } |
| 129 |
| 130 scale_ = scale; |
| 131 |
| 132 if (cursor_loader_.get()) { |
| 133 cursor_loader_->set_scale(scale); |
| 134 ReloadCursors(); |
| 135 } |
| 136 } |
| 137 |
| 140 void ImageCursors::SetCursorSet(ui::CursorSetType cursor_set) { | 138 void ImageCursors::SetCursorSet(ui::CursorSetType cursor_set) { |
| 141 if (cursor_set_ == cursor_set) | 139 if (cursor_set_ == cursor_set) |
| 142 return; | 140 return; |
| 143 | 141 |
| 144 cursor_set_ = cursor_set; | 142 cursor_set_ = cursor_set; |
| 145 | 143 |
| 146 if (cursor_loader_.get()) | 144 if (cursor_loader_.get()) |
| 147 ReloadCursors(); | 145 ReloadCursors(); |
| 148 } | 146 } |
| 149 | 147 |
| 150 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { | 148 void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { |
| 151 cursor_loader_->SetPlatformCursor(cursor); | 149 cursor_loader_->SetPlatformCursor(cursor); |
| 152 } | 150 } |
| 153 | 151 |
| 154 } // namespace ash | 152 } // namespace ash |
| OLD | NEW |