| 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/ash_constants.h" | 7 #include "ash/ash_constants.h" |
| 8 #include "ash/ash_switches.h" | |
| 9 #include "ash/display/mirror_window_controller.h" | 8 #include "ash/display/mirror_window_controller.h" |
| 10 #include "ash/display/window_tree_host_manager.h" | 9 #include "ash/display/window_tree_host_manager.h" |
| 11 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| 12 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
| 13 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 14 #include "base/command_line.h" | |
| 15 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 16 #include "ui/aura/window_delegate.h" | 14 #include "ui/aura/window_delegate.h" |
| 17 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
| 18 #include "ui/base/cursor/cursors_aura.h" | 16 #include "ui/base/cursor/cursors_aura.h" |
| 19 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/compositor/dip_util.h" | 19 #include "ui/compositor/dip_util.h" |
| 22 #include "ui/compositor/paint_recorder.h" | 20 #include "ui/compositor/paint_recorder.h" |
| 23 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
| 24 #include "ui/display/manager/display_manager.h" | 22 #include "ui/display/manager/display_manager.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 }; | 86 }; |
| 89 | 87 |
| 90 CursorWindowController::CursorWindowController() | 88 CursorWindowController::CursorWindowController() |
| 91 : is_cursor_compositing_enabled_(false), | 89 : is_cursor_compositing_enabled_(false), |
| 92 container_(NULL), | 90 container_(NULL), |
| 93 cursor_type_(ui::kCursorNone), | 91 cursor_type_(ui::kCursorNone), |
| 94 visible_(true), | 92 visible_(true), |
| 95 cursor_set_(ui::CURSOR_SET_NORMAL), | 93 cursor_set_(ui::CURSOR_SET_NORMAL), |
| 96 large_cursor_size_in_dip_(ash::kDefaultLargeCursorSize), | 94 large_cursor_size_in_dip_(ash::kDefaultLargeCursorSize), |
| 97 delegate_(new CursorWindowDelegate()) { | 95 delegate_(new CursorWindowDelegate()) { |
| 98 enable_adjustable_large_cursor_ = | |
| 99 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 100 ash::switches::kAshAdjustableLargeCursor); | |
| 101 } | 96 } |
| 102 | 97 |
| 103 CursorWindowController::~CursorWindowController() { | 98 CursorWindowController::~CursorWindowController() { |
| 104 SetContainer(NULL); | 99 SetContainer(NULL); |
| 105 } | 100 } |
| 106 | 101 |
| 107 void CursorWindowController::SetLargeCursorSizeInDip( | 102 void CursorWindowController::SetLargeCursorSizeInDip( |
| 108 int large_cursor_size_in_dip) { | 103 int large_cursor_size_in_dip) { |
| 109 large_cursor_size_in_dip = | 104 large_cursor_size_in_dip = |
| 110 std::min(large_cursor_size_in_dip, kMaxLargeCursorSize); | 105 std::min(large_cursor_size_in_dip, kMaxLargeCursorSize); |
| 111 large_cursor_size_in_dip = | 106 large_cursor_size_in_dip = |
| 112 std::max(large_cursor_size_in_dip, kMinLargeCursorSize); | 107 std::max(large_cursor_size_in_dip, kMinLargeCursorSize); |
| 113 | 108 |
| 114 if (large_cursor_size_in_dip_ == large_cursor_size_in_dip) | 109 if (large_cursor_size_in_dip_ == large_cursor_size_in_dip) |
| 115 return; | 110 return; |
| 116 | 111 |
| 117 large_cursor_size_in_dip_ = large_cursor_size_in_dip; | 112 large_cursor_size_in_dip_ = large_cursor_size_in_dip; |
| 118 | 113 |
| 119 if (enable_adjustable_large_cursor_ && display_.is_valid()) | 114 if (display_.is_valid()) |
| 120 UpdateCursorImage(); | 115 UpdateCursorImage(); |
| 121 } | 116 } |
| 122 | 117 |
| 123 void CursorWindowController::SetCursorCompositingEnabled(bool enabled) { | 118 void CursorWindowController::SetCursorCompositingEnabled(bool enabled) { |
| 124 if (is_cursor_compositing_enabled_ != enabled) { | 119 if (is_cursor_compositing_enabled_ != enabled) { |
| 125 is_cursor_compositing_enabled_ = enabled; | 120 is_cursor_compositing_enabled_ = enabled; |
| 126 if (display_.is_valid()) | 121 if (display_.is_valid()) |
| 127 UpdateCursorImage(); | 122 UpdateCursorImage(); |
| 128 UpdateContainer(); | 123 UpdateContainer(); |
| 129 } | 124 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 delegate_->SetCursorImage( | 284 delegate_->SetCursorImage( |
| 290 image_rep.pixel_size(), | 285 image_rep.pixel_size(), |
| 291 gfx::ImageSkia::CreateFrom1xBitmap(image_rep.sk_bitmap())); | 286 gfx::ImageSkia::CreateFrom1xBitmap(image_rep.sk_bitmap())); |
| 292 } else { | 287 } else { |
| 293 gfx::ImageSkia resized = *image; | 288 gfx::ImageSkia resized = *image; |
| 294 | 289 |
| 295 // Rescale cursor size. This is used with the combination of accessibility | 290 // Rescale cursor size. This is used with the combination of accessibility |
| 296 // large cursor. We don't need to care about the case where cursor | 291 // large cursor. We don't need to care about the case where cursor |
| 297 // compositing is disabled as we always use cursor compositing if | 292 // compositing is disabled as we always use cursor compositing if |
| 298 // accessibility large cursor is enabled. | 293 // accessibility large cursor is enabled. |
| 299 if (enable_adjustable_large_cursor_ && | 294 if (cursor_set_ == ui::CursorSetType::CURSOR_SET_LARGE && |
| 300 cursor_set_ == ui::CursorSetType::CURSOR_SET_LARGE && | |
| 301 large_cursor_size_in_dip_ != image->size().width()) { | 295 large_cursor_size_in_dip_ != image->size().width()) { |
| 302 float rescale = static_cast<float>(large_cursor_size_in_dip_) / | 296 float rescale = static_cast<float>(large_cursor_size_in_dip_) / |
| 303 static_cast<float>(image->size().width()); | 297 static_cast<float>(image->size().width()); |
| 304 resized = gfx::ImageSkiaOperations::CreateResizedImage( | 298 resized = gfx::ImageSkiaOperations::CreateResizedImage( |
| 305 *image, skia::ImageOperations::ResizeMethod::RESIZE_GOOD, | 299 *image, skia::ImageOperations::ResizeMethod::RESIZE_GOOD, |
| 306 gfx::ScaleToCeiledSize(image->size(), rescale)); | 300 gfx::ScaleToCeiledSize(image->size(), rescale)); |
| 307 hot_point_ = gfx::ScaleToCeiledPoint(hot_point_, rescale); | 301 hot_point_ = gfx::ScaleToCeiledPoint(hot_point_, rescale); |
| 308 } | 302 } |
| 309 | 303 |
| 310 const gfx::ImageSkiaRep& image_rep = | 304 const gfx::ImageSkiaRep& image_rep = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 331 cursor_window_->Show(); | 325 cursor_window_->Show(); |
| 332 else | 326 else |
| 333 cursor_window_->Hide(); | 327 cursor_window_->Hide(); |
| 334 } | 328 } |
| 335 | 329 |
| 336 const gfx::ImageSkia& CursorWindowController::GetCursorImageForTest() const { | 330 const gfx::ImageSkia& CursorWindowController::GetCursorImageForTest() const { |
| 337 return delegate_->cursor_image(); | 331 return delegate_->cursor_image(); |
| 338 } | 332 } |
| 339 | 333 |
| 340 } // namespace ash | 334 } // namespace ash |
| OLD | NEW |