summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-28 23:46:20 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-28 23:46:20 +0000
commit68bd9289ad689ff35a4efe5755ea06d9e4230297 (patch)
treed08291c13ede612446b5d3509662498315fe8c32 /ash
parent2f264fc0b3981e9c72965a4d3d18be75c935d133 (diff)
downloadchromium_src-68bd9289ad689ff35a4efe5755ea06d9e4230297.zip
chromium_src-68bd9289ad689ff35a4efe5755ea06d9e4230297.tar.gz
chromium_src-68bd9289ad689ff35a4efe5755ea06d9e4230297.tar.bz2
app_shell: Add support for mouse cursors.
Move ImageCursors from ash/wm/ to ui/base/cursors/ and add a NativeCursorManager implementation for ShellDesktopController to use. BUG=364290 TEST=cursor is visible when running app_shell on a Chrome OS device and changes after mousing over a link Review URL: https://codereview.chromium.org/258893002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266694 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/ash.gyp2
-rw-r--r--ash/display/cursor_window_controller.h2
-rw-r--r--ash/test/cursor_manager_test_api.cc2
-rw-r--r--ash/wm/ash_native_cursor_manager.cc26
-rw-r--r--ash/wm/ash_native_cursor_manager.h8
-rw-r--r--ash/wm/ash_native_cursor_manager_unittest.cc2
-rw-r--r--ash/wm/image_cursors.cc154
-rw-r--r--ash/wm/image_cursors.h56
8 files changed, 23 insertions, 229 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index f437866..4934087 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -566,8 +566,6 @@
'wm/gestures/shelf_gesture_handler.h',
'wm/gestures/tray_gesture_handler.cc',
'wm/gestures/tray_gesture_handler.h',
- 'wm/image_cursors.cc',
- 'wm/image_cursors.h',
'wm/immersive_fullscreen_controller.cc',
'wm/immersive_fullscreen_controller.h',
'wm/immersive_revealed_lock.cc',
diff --git a/ash/display/cursor_window_controller.h b/ash/display/cursor_window_controller.h
index 6e6a709..f51cc4e 100644
--- a/ash/display/cursor_window_controller.h
+++ b/ash/display/cursor_window_controller.h
@@ -10,7 +10,7 @@
#include "ui/gfx/display.h"
namespace ash {
-namespace test{
+namespace test {
class MirrorWindowTestApi;
}
diff --git a/ash/test/cursor_manager_test_api.cc b/ash/test/cursor_manager_test_api.cc
index 4ff7cf7..a8bffe8 100644
--- a/ash/test/cursor_manager_test_api.cc
+++ b/ash/test/cursor_manager_test_api.cc
@@ -7,7 +7,7 @@
#include "ash/shell.h"
#include "ash/test/shell_test_api.h"
#include "ash/wm/ash_native_cursor_manager.h"
-#include "ash/wm/image_cursors.h"
+#include "ui/base/cursor/image_cursors.h"
#include "ui/gfx/display.h"
#include "ui/wm/core/cursor_manager.h"
diff --git a/ash/wm/ash_native_cursor_manager.cc b/ash/wm/ash_native_cursor_manager.cc
index e78eb94..91f1161 100644
--- a/ash/wm/ash_native_cursor_manager.cc
+++ b/ash/wm/ash_native_cursor_manager.cc
@@ -7,12 +7,12 @@
#include "ash/display/cursor_window_controller.h"
#include "ash/display/display_controller.h"
#include "ash/shell.h"
-#include "ash/wm/image_cursors.h"
#include "base/logging.h"
#include "ui/aura/env.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/cursor/cursor.h"
+#include "ui/base/cursor/image_cursors.h"
namespace ash {
namespace {
@@ -54,7 +54,7 @@ void NotifyMouseEventsEnableStateChange(bool enabled) {
AshNativeCursorManager::AshNativeCursorManager()
: native_cursor_enabled_(true),
- image_cursors_(new ImageCursors) {
+ image_cursors_(new ui::ImageCursors) {
}
AshNativeCursorManager::~AshNativeCursorManager() {
@@ -72,7 +72,12 @@ void AshNativeCursorManager::SetNativeCursorEnabled(bool enabled) {
void AshNativeCursorManager::SetDisplay(
const gfx::Display& display,
::wm::NativeCursorManagerDelegate* delegate) {
- if (image_cursors_->SetDisplay(display))
+ DCHECK(display.is_valid());
+ // Use the platform's device scale factor instead of the display's, which
+ // might have been adjusted for the UI scale.
+ const float scale_factor = Shell::GetInstance()->display_manager()->
+ GetDisplayInfo(display.id()).device_scale_factor();
+ if (image_cursors_->SetDisplay(display, scale_factor))
SetCursor(delegate->GetCursor(), delegate);
#if defined(OS_CHROMEOS)
Shell::GetInstance()->display_controller()->cursor_window_controller()->
@@ -83,24 +88,23 @@ void AshNativeCursorManager::SetDisplay(
void AshNativeCursorManager::SetCursor(
gfx::NativeCursor cursor,
::wm::NativeCursorManagerDelegate* delegate) {
- gfx::NativeCursor new_cursor = cursor;
if (native_cursor_enabled_) {
- image_cursors_->SetPlatformCursor(&new_cursor);
+ image_cursors_->SetPlatformCursor(&cursor);
} else {
gfx::NativeCursor invisible_cursor(ui::kCursorNone);
image_cursors_->SetPlatformCursor(&invisible_cursor);
- if (new_cursor == ui::kCursorCustom) {
- new_cursor = invisible_cursor;
+ if (cursor == ui::kCursorCustom) {
+ cursor = invisible_cursor;
} else {
- new_cursor.SetPlatformCursor(invisible_cursor.platform());
+ cursor.SetPlatformCursor(invisible_cursor.platform());
}
}
- new_cursor.set_device_scale_factor(image_cursors_->GetScale());
+ cursor.set_device_scale_factor(image_cursors_->GetScale());
- delegate->CommitCursor(new_cursor);
+ delegate->CommitCursor(cursor);
if (delegate->IsCursorVisible())
- SetCursorOnAllRootWindows(new_cursor);
+ SetCursorOnAllRootWindows(cursor);
}
void AshNativeCursorManager::SetCursorSet(
diff --git a/ash/wm/ash_native_cursor_manager.h b/ash/wm/ash_native_cursor_manager.h
index 80ecc8e..290b701 100644
--- a/ash/wm/ash_native_cursor_manager.h
+++ b/ash/wm/ash_native_cursor_manager.h
@@ -15,14 +15,16 @@
#include "ui/wm/core/native_cursor_manager.h"
#include "ui/wm/core/native_cursor_manager_delegate.h"
+namespace ui {
+class ImageCursors;
+}
+
namespace ash {
namespace test {
class CursorManagerTestApi;
}
-class ImageCursors;
-
// This does the ash-specific setting of cursor details like cursor
// visibility. It communicates back with the CursorManager through the
// NativeCursorManagerDelegate interface, which receives messages about what
@@ -64,7 +66,7 @@ class ASH_EXPORT AshNativeCursorManager
bool native_cursor_enabled_;
- scoped_ptr<ImageCursors> image_cursors_;
+ scoped_ptr<ui::ImageCursors> image_cursors_;
DISALLOW_COPY_AND_ASSIGN(AshNativeCursorManager);
};
diff --git a/ash/wm/ash_native_cursor_manager_unittest.cc b/ash/wm/ash_native_cursor_manager_unittest.cc
index d7e060a..e31d814 100644
--- a/ash/wm/ash_native_cursor_manager_unittest.cc
+++ b/ash/wm/ash_native_cursor_manager_unittest.cc
@@ -9,12 +9,12 @@
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/cursor_manager_test_api.h"
-#include "ash/wm/image_cursors.h"
#include "ui/aura/test/aura_test_utils.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
+#include "ui/base/cursor/image_cursors.h"
#include "ui/gfx/screen.h"
#if defined(OS_WIN)
diff --git a/ash/wm/image_cursors.cc b/ash/wm/image_cursors.cc
deleted file mode 100644
index 2a41375..0000000
--- a/ash/wm/image_cursors.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-// 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 <float.h>
-
-#include "ash/display/display_info.h"
-#include "ash/display/display_manager.h"
-#include "ash/shell.h"
-#include "base/logging.h"
-#include "base/strings/string16.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/base/cursor/cursor_loader.h"
-#include "ui/base/cursor/cursors_aura.h"
-#include "ui/gfx/display.h"
-#include "ui/gfx/point.h"
-
-namespace ash {
-
-const int kImageCursorIds[] = {
- ui::kCursorNull,
- ui::kCursorPointer,
- ui::kCursorNoDrop,
- ui::kCursorNotAllowed,
- ui::kCursorCopy,
- ui::kCursorHand,
- ui::kCursorMove,
- ui::kCursorNorthEastResize,
- ui::kCursorSouthWestResize,
- ui::kCursorSouthEastResize,
- ui::kCursorNorthWestResize,
- ui::kCursorNorthResize,
- ui::kCursorSouthResize,
- ui::kCursorEastResize,
- ui::kCursorWestResize,
- ui::kCursorIBeam,
- ui::kCursorAlias,
- ui::kCursorCell,
- ui::kCursorContextMenu,
- ui::kCursorCross,
- ui::kCursorHelp,
- ui::kCursorVerticalText,
- ui::kCursorZoomIn,
- ui::kCursorZoomOut,
- ui::kCursorRowResize,
- ui::kCursorColumnResize,
- ui::kCursorEastWestResize,
- ui::kCursorNorthSouthResize,
- ui::kCursorNorthEastSouthWestResize,
- ui::kCursorNorthWestSouthEastResize,
- ui::kCursorGrab,
- ui::kCursorGrabbing,
-};
-
-const int kAnimatedCursorIds[] = {
- ui::kCursorWait,
- ui::kCursorProgress
-};
-
-ImageCursors::ImageCursors() : cursor_set_(ui::CURSOR_SET_NORMAL) {
-}
-
-ImageCursors::~ImageCursors() {
-}
-
-float ImageCursors::GetScale() const {
- if (!cursor_loader_) {
- NOTREACHED();
- // Returning default on release build as it's not serious enough to crash
- // even if this ever happens.
- return 1.0f;
- }
- return cursor_loader_->scale();
-}
-
-gfx::Display::Rotation ImageCursors::GetRotation() const {
- if (!cursor_loader_) {
- NOTREACHED();
- // Returning default on release build as it's not serious enough to crash
- // even if this ever happens.
- return gfx::Display::ROTATE_0;
- }
- return cursor_loader_->rotation();
-}
-
-bool ImageCursors::SetDisplay(const gfx::Display& display) {
- DCHECK(display.is_valid());
- // Use the platform's device scale factor instead of display's
- // that might have been adjusted for UI scale.
- float scale_factor = Shell::GetInstance()->display_manager()->
- GetDisplayInfo(display.id()).device_scale_factor();
-
- if (!cursor_loader_) {
- cursor_loader_.reset(ui::CursorLoader::Create());
- } else if (cursor_loader_->rotation() == display.rotation() &&
- cursor_loader_->scale() == scale_factor) {
- return false;
- }
-
- cursor_loader_->set_rotation(display.rotation());
- cursor_loader_->set_scale(scale_factor);
- ReloadCursors();
- return true;
-}
-
-void ImageCursors::ReloadCursors() {
- float device_scale_factor = cursor_loader_->scale();
-
- cursor_loader_->UnloadAll();
-
- for (size_t i = 0; i < arraysize(kImageCursorIds); ++i) {
- int resource_id = -1;
- gfx::Point hot_point;
- bool success = ui::GetCursorDataFor(cursor_set_,
- kImageCursorIds[i],
- device_scale_factor,
- &resource_id,
- &hot_point);
- DCHECK(success);
- cursor_loader_->LoadImageCursor(kImageCursorIds[i], resource_id, hot_point);
- }
- for (size_t i = 0; i < arraysize(kAnimatedCursorIds); ++i) {
- int resource_id = -1;
- gfx::Point hot_point;
- bool success = ui::GetAnimatedCursorDataFor(cursor_set_,
- kAnimatedCursorIds[i],
- device_scale_factor,
- &resource_id,
- &hot_point);
- DCHECK(success);
- cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i],
- resource_id,
- hot_point,
- ui::kAnimatedCursorFrameDelayMs);
- }
-}
-
-void ImageCursors::SetCursorSet(ui::CursorSetType cursor_set) {
- if (cursor_set_ == cursor_set)
- return;
-
- cursor_set_ = cursor_set;
-
- if (cursor_loader_.get())
- ReloadCursors();
-}
-
-void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) {
- cursor_loader_->SetPlatformCursor(cursor);
-}
-
-} // namespace ash
diff --git a/ash/wm/image_cursors.h b/ash/wm/image_cursors.h
deleted file mode 100644
index 1a75f40..0000000
--- a/ash/wm/image_cursors.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// 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.
-
-#ifndef ASH_WM_IMAGE_CURSORS_H_
-#define ASH_WM_IMAGE_CURSORS_H_
-
-#include "ash/ash_export.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/strings/string16.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/gfx/display.h"
-#include "ui/gfx/native_widget_types.h"
-
-namespace ui {
-class CursorLoader;
-}
-
-namespace ash {
-
-// A utility class that provides cursors for NativeCursors for which we have
-// image resources.
-class ASH_EXPORT ImageCursors {
- public:
- ImageCursors();
- ~ImageCursors();
-
- // Returns the scale and rotation of the currently loaded cursor.
- float GetScale() const;
- gfx::Display::Rotation GetRotation() const;
-
- // Sets the display the cursors are loaded for. The device scale factor
- // determines the size of the image to load, and the rotation of the display
- // determines if the image and its host point has to be retated.
- // Returns true if the cursor image is reloaded.
- bool SetDisplay(const gfx::Display& display);
-
- // Sets the type of the mouse cursor icon.
- void SetCursorSet(ui::CursorSetType cursor_set);
-
- // Sets the platform cursor based on the native type of |cursor|.
- void SetPlatformCursor(gfx::NativeCursor* cursor);
-
- private:
- // Reloads the all loaded cursors in the cursor loader.
- void ReloadCursors();
-
- scoped_ptr<ui::CursorLoader> cursor_loader_;
- ui::CursorSetType cursor_set_;
-
- DISALLOW_COPY_AND_ASSIGN(ImageCursors);
-};
-
-} // namespace ash
-
-#endif // ASH_WM_IMAGE_CURSORS_H_