| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/display/cursor_window_controller.h" | 5 #include "ash/display/cursor_window_controller.h" |
| 6 | 6 |
| 7 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/display/mirror_window_controller.h" | 8 #include "ash/display/mirror_window_controller.h" |
| 9 #include "ash/display/window_tree_host_manager.h" | 9 #include "ash/display/window_tree_host_manager.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 14 #include "ui/aura/window_delegate.h" | 14 #include "ui/aura/window_delegate.h" |
| 15 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
| 16 #include "ui/base/cursor/cursors_aura.h" | 16 #include "ui/base/cursor/cursors_aura.h" |
| 17 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/compositor/dip_util.h" | 19 #include "ui/compositor/dip_util.h" |
| 20 #include "ui/compositor/paint_recorder.h" | 20 #include "ui/compositor/paint_recorder.h" |
| 21 #include "ui/display/display.h" |
| 22 #include "ui/display/screen.h" |
| 21 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/display.h" | |
| 23 #include "ui/gfx/geometry/dip_util.h" | 24 #include "ui/gfx/geometry/dip_util.h" |
| 24 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
| 25 #include "ui/gfx/image/image_skia_operations.h" | 26 #include "ui/gfx/image/image_skia_operations.h" |
| 26 #include "ui/gfx/screen.h" | |
| 27 | 27 |
| 28 namespace ash { | 28 namespace ash { |
| 29 | 29 |
| 30 class CursorWindowDelegate : public aura::WindowDelegate { | 30 class CursorWindowDelegate : public aura::WindowDelegate { |
| 31 public: | 31 public: |
| 32 CursorWindowDelegate() {} | 32 CursorWindowDelegate() {} |
| 33 ~CursorWindowDelegate() override {} | 33 ~CursorWindowDelegate() override {} |
| 34 | 34 |
| 35 // aura::WindowDelegate overrides: | 35 // aura::WindowDelegate overrides: |
| 36 gfx::Size GetMinimumSize() const override { return size_; } | 36 gfx::Size GetMinimumSize() const override { return size_; } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 if (is_cursor_compositing_enabled_ != enabled) { | 95 if (is_cursor_compositing_enabled_ != enabled) { |
| 96 is_cursor_compositing_enabled_ = enabled; | 96 is_cursor_compositing_enabled_ = enabled; |
| 97 if (display_.is_valid()) | 97 if (display_.is_valid()) |
| 98 UpdateCursorImage(); | 98 UpdateCursorImage(); |
| 99 UpdateContainer(); | 99 UpdateContainer(); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 void CursorWindowController::UpdateContainer() { | 103 void CursorWindowController::UpdateContainer() { |
| 104 if (is_cursor_compositing_enabled_) { | 104 if (is_cursor_compositing_enabled_) { |
| 105 gfx::Screen* screen = gfx::Screen::GetScreen(); | 105 display::Screen* screen = display::Screen::GetScreen(); |
| 106 gfx::Display display = screen->GetDisplayNearestPoint( | 106 display::Display display = |
| 107 screen->GetCursorScreenPoint()); | 107 screen->GetDisplayNearestPoint(screen->GetCursorScreenPoint()); |
| 108 DCHECK(display.is_valid()); | 108 DCHECK(display.is_valid()); |
| 109 if (display.is_valid()) | 109 if (display.is_valid()) |
| 110 SetDisplay(display); | 110 SetDisplay(display); |
| 111 } else { | 111 } else { |
| 112 aura::Window* mirror_window = Shell::GetInstance() | 112 aura::Window* mirror_window = Shell::GetInstance() |
| 113 ->window_tree_host_manager() | 113 ->window_tree_host_manager() |
| 114 ->mirror_window_controller() | 114 ->mirror_window_controller() |
| 115 ->GetWindow(); | 115 ->GetWindow(); |
| 116 if (mirror_window) | 116 if (mirror_window) |
| 117 display_ = gfx::Screen::GetScreen()->GetPrimaryDisplay(); | 117 display_ = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 118 SetContainer(mirror_window); | 118 SetContainer(mirror_window); |
| 119 } | 119 } |
| 120 // Updates the hot point based on the current display. | 120 // Updates the hot point based on the current display. |
| 121 UpdateCursorImage(); | 121 UpdateCursorImage(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void CursorWindowController::SetDisplay(const gfx::Display& display) { | 124 void CursorWindowController::SetDisplay(const display::Display& display) { |
| 125 if (!is_cursor_compositing_enabled_) | 125 if (!is_cursor_compositing_enabled_) |
| 126 return; | 126 return; |
| 127 | 127 |
| 128 // TODO(oshima): Do not updatethe composition cursor when crossing | 128 // TODO(oshima): Do not updatethe composition cursor when crossing |
| 129 // display in unified desktop mode for now. crbug.com/517222. | 129 // display in unified desktop mode for now. crbug.com/517222. |
| 130 if (Shell::GetInstance()->display_manager()->IsInUnifiedMode() && | 130 if (Shell::GetInstance()->display_manager()->IsInUnifiedMode() && |
| 131 display.id() != DisplayManager::kUnifiedDisplayId) { | 131 display.id() != DisplayManager::kUnifiedDisplayId) { |
| 132 return; | 132 return; |
| 133 } | 133 } |
| 134 | 134 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 // TODO(hshi): support custom cursor set. | 227 // TODO(hshi): support custom cursor set. |
| 228 if (!ui::GetCursorDataFor(cursor_set_, cursor_type_, cursor_scale, | 228 if (!ui::GetCursorDataFor(cursor_set_, cursor_type_, cursor_scale, |
| 229 &resource_id, &hot_point_)) { | 229 &resource_id, &hot_point_)) { |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 const gfx::ImageSkia* image = | 232 const gfx::ImageSkia* image = |
| 233 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); | 233 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
| 234 if (!is_cursor_compositing_enabled_) { | 234 if (!is_cursor_compositing_enabled_) { |
| 235 gfx::ImageSkia rotated = *image; | 235 gfx::ImageSkia rotated = *image; |
| 236 switch (display_.rotation()) { | 236 switch (display_.rotation()) { |
| 237 case gfx::Display::ROTATE_0: | 237 case display::Display::ROTATE_0: |
| 238 break; | 238 break; |
| 239 case gfx::Display::ROTATE_90: | 239 case display::Display::ROTATE_90: |
| 240 rotated = gfx::ImageSkiaOperations::CreateRotatedImage( | 240 rotated = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 241 *image, SkBitmapOperations::ROTATION_90_CW); | 241 *image, SkBitmapOperations::ROTATION_90_CW); |
| 242 hot_point_.SetPoint( | 242 hot_point_.SetPoint( |
| 243 rotated.width() - hot_point_.y(), | 243 rotated.width() - hot_point_.y(), |
| 244 hot_point_.x()); | 244 hot_point_.x()); |
| 245 break; | 245 break; |
| 246 case gfx::Display::ROTATE_180: | 246 case display::Display::ROTATE_180: |
| 247 rotated = gfx::ImageSkiaOperations::CreateRotatedImage( | 247 rotated = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 248 *image, SkBitmapOperations::ROTATION_180_CW); | 248 *image, SkBitmapOperations::ROTATION_180_CW); |
| 249 hot_point_.SetPoint( | 249 hot_point_.SetPoint( |
| 250 rotated.height() - hot_point_.x(), | 250 rotated.height() - hot_point_.x(), |
| 251 rotated.width() - hot_point_.y()); | 251 rotated.width() - hot_point_.y()); |
| 252 break; | 252 break; |
| 253 case gfx::Display::ROTATE_270: | 253 case display::Display::ROTATE_270: |
| 254 rotated = gfx::ImageSkiaOperations::CreateRotatedImage( | 254 rotated = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 255 *image, SkBitmapOperations::ROTATION_270_CW); | 255 *image, SkBitmapOperations::ROTATION_270_CW); |
| 256 hot_point_.SetPoint( | 256 hot_point_.SetPoint( |
| 257 hot_point_.y(), | 257 hot_point_.y(), |
| 258 rotated.height() - hot_point_.x()); | 258 rotated.height() - hot_point_.x()); |
| 259 break; | 259 break; |
| 260 } | 260 } |
| 261 // Note that mirror window's scale factor is always 1.0f, therefore we | 261 // Note that mirror window's scale factor is always 1.0f, therefore we |
| 262 // need to take 2x's image and paint as if it's 1x image. | 262 // need to take 2x's image and paint as if it's 1x image. |
| 263 const gfx::ImageSkiaRep& image_rep = | 263 const gfx::ImageSkiaRep& image_rep = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 288 cursor_window_->Show(); | 288 cursor_window_->Show(); |
| 289 else | 289 else |
| 290 cursor_window_->Hide(); | 290 cursor_window_->Hide(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 const gfx::ImageSkia& CursorWindowController::GetCursorImageForTest() const { | 293 const gfx::ImageSkia& CursorWindowController::GetCursorImageForTest() const { |
| 294 return delegate_->cursor_image(); | 294 return delegate_->cursor_image(); |
| 295 } | 295 } |
| 296 | 296 |
| 297 } // namespace ash | 297 } // namespace ash |
| OLD | NEW |