Chromium Code Reviews| Index: ash/wm/mushrome_ash_native_cursor_manager.cc |
| diff --git a/ash/wm/ash_native_cursor_manager.cc b/ash/wm/mushrome_ash_native_cursor_manager.cc |
| similarity index 53% |
| copy from ash/wm/ash_native_cursor_manager.cc |
| copy to ash/wm/mushrome_ash_native_cursor_manager.cc |
| index 45a3ef82f59b4d8ffeabbd7e72ab466b331897da..4bf9624910f84928b040e4ed057c865559d08392 100644 |
| --- a/ash/wm/ash_native_cursor_manager.cc |
| +++ b/ash/wm/mushrome_ash_native_cursor_manager.cc |
| @@ -1,28 +1,48 @@ |
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Copyright 2017 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/ash_native_cursor_manager.h" |
| +#include "ash/wm/mushrome_ash_native_cursor_manager.h" |
| #include "ash/display/cursor_window_controller.h" |
| #include "ash/display/window_tree_host_manager.h" |
| #include "ash/shell.h" |
| -#include "base/logging.h" |
| +#include "ash/shell_port.h" |
| #include "ui/aura/env.h" |
| +#include "ui/aura/mus/window_port_mus.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" |
| #include "ui/base/layout.h" |
| +#include "ui/wm/core/cursor_manager.h" |
| + |
| +#if defined(USE_OZONE) |
| +#include "ui/base/cursor/ozone/cursor_data_factory_ozone.h" |
| +#endif |
| namespace ash { |
| namespace { |
| +// We want to forward these things to the window tree client. |
| + |
| void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { |
| - aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
| - for (aura::Window::Windows::iterator iter = root_windows.begin(); |
| - iter != root_windows.end(); ++iter) |
| - (*iter)->GetHost()->SetCursor(cursor); |
| + ui::CursorData mojo_cursor; |
| + if (cursor.platform()) { |
| +#if defined(USE_OZONE) |
| + mojo_cursor = ui::CursorDataFactoryOzone::GetCursorData(cursor.platform()); |
| +#else |
| + NOTIMPLEMENTED() |
| + << "Can't pass native platform cursors on non-ozone platforms"; |
| + mojo_cursor = ui::CursorData(ui::CursorType::kPointer); |
| +#endif |
| + } else { |
| + mojo_cursor = ui::CursorData(cursor.native_type()); |
| + } |
| + |
| + // As the window manager, tell mus to use |mojo_cursor| everywhere. We do |
| + // this instead of trying to set per-window because otherwise we run into the |
| + // event targeting issue. |
| + ShellPort::Get()->SetGlobalOverrideCursor(mojo_cursor); |
| Shell::Get() |
| ->window_tree_host_manager() |
| @@ -31,6 +51,13 @@ void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { |
| } |
| void NotifyCursorVisibilityChange(bool visible) { |
| + // Communicate the cursor visibility state to the mus server. |
| + if (visible) |
| + ShellPort::Get()->ShowCursor(); |
| + else |
| + ShellPort::Get()->HideCursor(); |
| + |
| + // Communicate the cursor visibility change to our local root window objects. |
| aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
| for (aura::Window::Windows::iterator iter = root_windows.begin(); |
| iter != root_windows.end(); ++iter) |
| @@ -52,19 +79,37 @@ void NotifyMouseEventsEnableStateChange(bool enabled) { |
| } // namespace |
| -AshNativeCursorManager::AshNativeCursorManager() |
| - : native_cursor_enabled_(true), image_cursors_(new ui::ImageCursors) {} |
| +MushromeAshNativeCursorManager::MushromeAshNativeCursorManager() { |
| +#if defined(USE_OZONE) |
| + // If we're in a mus client, we aren't going to have all of ozone initialized |
| + // even though we're in an ozone build. All the hard coded USE_OZONE ifdefs |
| + // that handle cursor code expect that there will be a CursorFactoryOzone |
| + // instance. Partially initialize the ozone cursor internals here, like we |
| + // partially initialize other ozone subsystems in |
| + // ChromeBrowserMainExtraPartsViews. |
| + cursor_factory_ozone_ = base::MakeUnique<ui::CursorDataFactoryOzone>(); |
| + image_cursors_ = base::MakeUnique<ui::ImageCursors>(); |
| +#endif |
| +} |
| -AshNativeCursorManager::~AshNativeCursorManager() {} |
| +MushromeAshNativeCursorManager::~MushromeAshNativeCursorManager() {} |
|
James Cook
2017/06/12 20:17:24
nit: = default
|
| -void AshNativeCursorManager::SetNativeCursorEnabled(bool enabled) { |
| +void MushromeAshNativeCursorManager::SetNativeCursorEnabled(bool enabled) { |
| native_cursor_enabled_ = enabled; |
| ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); |
| SetCursor(cursor_manager->GetCursor(), cursor_manager); |
| } |
| -void AshNativeCursorManager::SetDisplay( |
| +float MushromeAshNativeCursorManager::GetScale() const { |
| + return image_cursors_->GetScale(); |
| +} |
| + |
| +display::Display::Rotation MushromeAshNativeCursorManager::GetRotation() const { |
| + return image_cursors_->GetRotation(); |
| +} |
| + |
| +void MushromeAshNativeCursorManager::SetDisplay( |
| const display::Display& display, |
| ::wm::NativeCursorManagerDelegate* delegate) { |
| DCHECK(display.is_valid()); |
| @@ -87,20 +132,22 @@ void AshNativeCursorManager::SetDisplay( |
| ->SetDisplay(display); |
| } |
| -void AshNativeCursorManager::SetCursor( |
| +void MushromeAshNativeCursorManager::SetCursor( |
| gfx::NativeCursor cursor, |
| ::wm::NativeCursorManagerDelegate* delegate) { |
| - if (native_cursor_enabled_) { |
| - image_cursors_->SetPlatformCursor(&cursor); |
| - } else { |
| - gfx::NativeCursor invisible_cursor(ui::CursorType::kNone); |
| - image_cursors_->SetPlatformCursor(&invisible_cursor); |
| - if (cursor == ui::CursorType::kCustom) { |
| - // Fall back to the default pointer cursor for now. (crbug.com/476078) |
| - // TODO(oshima): support custom cursor. |
| - cursor = ui::CursorType::kPointer; |
| + if (image_cursors_) { |
| + if (native_cursor_enabled_) { |
| + image_cursors_->SetPlatformCursor(&cursor); |
| } else { |
| - cursor.SetPlatformCursor(invisible_cursor.platform()); |
| + gfx::NativeCursor invisible_cursor(ui::CursorType::kNone); |
| + image_cursors_->SetPlatformCursor(&invisible_cursor); |
| + if (cursor == ui::CursorType::kCustom) { |
| + // Fall back to the default pointer cursor for now. (crbug.com/476078) |
| + // TODO(oshima): support custom cursor. |
| + cursor = ui::CursorType::kPointer; |
| + } else { |
| + cursor.SetPlatformCursor(invisible_cursor.platform()); |
| + } |
| } |
| } |
| cursor.set_device_scale_factor(image_cursors_->GetScale()); |
| @@ -111,23 +158,7 @@ void AshNativeCursorManager::SetCursor( |
| SetCursorOnAllRootWindows(cursor); |
| } |
| -void AshNativeCursorManager::SetCursorSet( |
| - ui::CursorSetType cursor_set, |
| - ::wm::NativeCursorManagerDelegate* delegate) { |
| - image_cursors_->SetCursorSet(cursor_set); |
| - delegate->CommitCursorSet(cursor_set); |
| - |
| - // Sets the cursor to reflect the scale change immediately. |
| - if (delegate->IsCursorVisible()) |
| - SetCursor(delegate->GetCursor(), delegate); |
| - |
| - Shell::Get() |
| - ->window_tree_host_manager() |
| - ->cursor_window_controller() |
| - ->SetCursorSet(cursor_set); |
| -} |
| - |
| -void AshNativeCursorManager::SetVisibility( |
| +void MushromeAshNativeCursorManager::SetVisibility( |
| bool visible, |
| ::wm::NativeCursorManagerDelegate* delegate) { |
| delegate->CommitVisibility(visible); |
| @@ -143,7 +174,15 @@ void AshNativeCursorManager::SetVisibility( |
| NotifyCursorVisibilityChange(visible); |
| } |
| -void AshNativeCursorManager::SetMouseEventsEnabled( |
| +void MushromeAshNativeCursorManager::SetCursorSet( |
| + ui::CursorSetType cursor_set, |
| + ::wm::NativeCursorManagerDelegate* delegate) { |
| + // We can't just hand this off to ImageCursors like we do in the classic ash |
| + // case. We need to collaborate with the mus server to fully implement this. |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void MushromeAshNativeCursorManager::SetMouseEventsEnabled( |
| bool enabled, |
| ::wm::NativeCursorManagerDelegate* delegate) { |
| delegate->CommitMouseEventsEnabled(enabled); |
| @@ -156,6 +195,7 @@ void AshNativeCursorManager::SetMouseEventsEnabled( |
| } |
| SetVisibility(delegate->IsCursorVisible(), delegate); |
| + |
| NotifyMouseEventsEnableStateChange(enabled); |
| } |