Commit 1b90a669 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Chromium LUCI CQ

capture mode: Update mouse cursor when display rotates.

Bug: 1153877
Change-Id: I4140a53d43aac2e2eae377c9108ce27b9b3d5597
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566301
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832519}
parent c3339032
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/capture_mode/capture_mode_util.h" #include "ash/capture_mode/capture_mode_util.h"
#include "ash/capture_mode/capture_window_observer.h" #include "ash/capture_mode/capture_window_observer.h"
#include "ash/display/mouse_cursor_event_filter.h" #include "ash/display/mouse_cursor_event_filter.h"
#include "ash/display/screen_orientation_controller.h"
#include "ash/magnifier/magnifier_glass.h" #include "ash/magnifier/magnifier_glass.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
...@@ -257,7 +258,8 @@ class CaptureModeSession::CursorSetter { ...@@ -257,7 +258,8 @@ class CaptureModeSession::CursorSetter {
: cursor_manager_(Shell::Get()->cursor_manager()), : cursor_manager_(Shell::Get()->cursor_manager()),
original_cursor_(cursor_manager_->GetCursor()), original_cursor_(cursor_manager_->GetCursor()),
original_cursor_visible_(cursor_manager_->IsCursorVisible()), original_cursor_visible_(cursor_manager_->IsCursorVisible()),
original_cursor_locked_(cursor_manager_->IsCursorLocked()) {} original_cursor_locked_(cursor_manager_->IsCursorLocked()),
current_orientation_(GetCurrentScreenOrientation()) {}
CursorSetter(const CursorSetter&) = delete; CursorSetter(const CursorSetter&) = delete;
CursorSetter& operator=(const CursorSetter&) = delete; CursorSetter& operator=(const CursorSetter&) = delete;
...@@ -275,16 +277,19 @@ class CaptureModeSession::CursorSetter { ...@@ -275,16 +277,19 @@ class CaptureModeSession::CursorSetter {
const CaptureModeType capture_type = CaptureModeController::Get()->type(); const CaptureModeType capture_type = CaptureModeController::Get()->type();
// For custom cursor, update the cursor if we need to change between image // For custom cursor, update the cursor if we need to change between image
// capture and video capture. // capture and video capture or the screen orientation changes.
const OrientationLockType orientation = GetCurrentScreenOrientation();
const bool is_cursor_changed = const bool is_cursor_changed =
current_cursor_type != new_cursor_type || current_cursor_type != new_cursor_type ||
(current_cursor_type == ui::mojom::CursorType::kCustom && (current_cursor_type == ui::mojom::CursorType::kCustom &&
custom_cursor_capture_type_ != capture_type); (custom_cursor_capture_type_ != capture_type ||
current_orientation_ != orientation));
const bool is_cursor_visibility_changed = const bool is_cursor_visibility_changed =
cursor_manager_->IsCursorVisible() != cursor_manager_->IsCursorVisible() !=
(new_cursor_type != ui::mojom::CursorType::kNone); (new_cursor_type != ui::mojom::CursorType::kNone);
if (new_cursor_type == ui::mojom::CursorType::kCustom) if (new_cursor_type == ui::mojom::CursorType::kCustom)
custom_cursor_capture_type_ = capture_type; custom_cursor_capture_type_ = capture_type;
current_orientation_ = orientation;
if (!is_cursor_changed && !is_cursor_visibility_changed) if (!is_cursor_changed && !is_cursor_visibility_changed)
return; return;
...@@ -353,6 +358,10 @@ class CaptureModeSession::CursorSetter { ...@@ -353,6 +358,10 @@ class CaptureModeSession::CursorSetter {
// cursor. // cursor.
CaptureModeType custom_cursor_capture_type_ = CaptureModeType::kImage; CaptureModeType custom_cursor_capture_type_ = CaptureModeType::kImage;
// Records the current screen orientation. If screen orientation changes, we
// will need to update the cursor if we're using custom cursor.
OrientationLockType current_orientation_;
// True if the cursor has reset back to its original cursor. It's to prevent // True if the cursor has reset back to its original cursor. It's to prevent
// Reset() from setting the cursor to |original_cursor_| more than once. // Reset() from setting the cursor to |original_cursor_| more than once.
bool was_cursor_reset_to_original_ = true; bool was_cursor_reset_to_original_ = true;
...@@ -391,9 +400,11 @@ CaptureModeSession::CaptureModeSession(CaptureModeController* controller) ...@@ -391,9 +400,11 @@ CaptureModeSession::CaptureModeSession(CaptureModeController* controller)
TabletModeController::Get()->AddObserver(this); TabletModeController::Get()->AddObserver(this);
current_root_->AddObserver(this); current_root_->AddObserver(this);
display::Screen::GetScreen()->AddObserver(this);
} }
CaptureModeSession::~CaptureModeSession() { CaptureModeSession::~CaptureModeSession() {
display::Screen::GetScreen()->RemoveObserver(this);
current_root_->RemoveObserver(this); current_root_->RemoveObserver(this);
TabletModeController::Get()->RemoveObserver(this); TabletModeController::Get()->RemoveObserver(this);
Shell::Get()->RemovePreTargetHandler(this); Shell::Get()->RemovePreTargetHandler(this);
...@@ -561,6 +572,15 @@ void CaptureModeSession::OnWindowDestroying(aura::Window* window) { ...@@ -561,6 +572,15 @@ void CaptureModeSession::OnWindowDestroying(aura::Window* window) {
MaybeChangeRoot(Shell::GetPrimaryRootWindow()); MaybeChangeRoot(Shell::GetPrimaryRootWindow());
} }
void CaptureModeSession::OnDisplayMetricsChanged(
const display::Display& display,
uint32_t metrics) {
if (metrics & display::DisplayObserver::DISPLAY_METRIC_ROTATION) {
UpdateCursor(display::Screen::GetScreen()->GetCursorScreenPoint(),
/*is_touch=*/false);
}
}
gfx::Rect CaptureModeSession::GetSelectedWindowBounds() const { gfx::Rect CaptureModeSession::GetSelectedWindowBounds() const {
auto* window = GetSelectedWindow(); auto* window = GetSelectedWindow();
return window ? window->bounds() : gfx::Rect(); return window ? window->bounds() : gfx::Rect();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/compositor/layer_delegate.h" #include "ui/compositor/layer_delegate.h"
#include "ui/compositor/layer_owner.h" #include "ui/compositor/layer_owner.h"
#include "ui/display/display_observer.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_handler.h" #include "ui/events/event_handler.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
...@@ -44,7 +45,8 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner, ...@@ -44,7 +45,8 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
public ui::LayerDelegate, public ui::LayerDelegate,
public ui::EventHandler, public ui::EventHandler,
public TabletModeObserver, public TabletModeObserver,
public aura::WindowObserver { public aura::WindowObserver,
public display::DisplayObserver {
public: public:
// Creates the bar widget on a calculated root window. // Creates the bar widget on a calculated root window.
explicit CaptureModeSession(CaptureModeController* controller); explicit CaptureModeSession(CaptureModeController* controller);
...@@ -95,6 +97,10 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner, ...@@ -95,6 +97,10 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
// aura::WindowObserver: // aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override; void OnWindowDestroying(aura::Window* window) override;
// display::DisplayObserver:
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t metrics) override;
private: private:
friend class CaptureModeSessionTestApi; friend class CaptureModeSessionTestApi;
class CursorSetter; class CursorSetter;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ash/capture_mode/capture_mode_util.h" #include "ash/capture_mode/capture_mode_util.h"
#include "ash/capture_mode/stop_recording_button_tray.h" #include "ash/capture_mode/stop_recording_button_tray.h"
#include "ash/display/cursor_window_controller.h" #include "ash/display/cursor_window_controller.h"
#include "ash/display/screen_orientation_controller_test_api.h"
#include "ash/display/window_tree_host_manager.h" #include "ash/display/window_tree_host_manager.h"
#include "ash/magnifier/magnifier_glass.h" #include "ash/magnifier/magnifier_glass.h"
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
...@@ -1202,6 +1203,37 @@ TEST_F(CaptureModeTest, WindowCursorStates) { ...@@ -1202,6 +1203,37 @@ TEST_F(CaptureModeTest, WindowCursorStates) {
EXPECT_EQ(original_cursor_type, cursor_manager->GetCursor().type()); EXPECT_EQ(original_cursor_type, cursor_manager->GetCursor().type());
} }
TEST_F(CaptureModeTest, CursorUpdatedOnDisplayRotation) {
using ui::mojom::CursorType;
UpdateDisplay("600x400");
const int64_t display_id =
display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::Display::SetInternalDisplayId(display_id);
ScreenOrientationControllerTestApi orientation_test_api(
Shell::Get()->screen_orientation_controller());
auto* event_generator = GetEventGenerator();
auto* cursor_manager = Shell::Get()->cursor_manager();
CaptureModeController* controller = StartCaptureSession(
CaptureModeSource::kFullscreen, CaptureModeType::kImage);
event_generator->MoveMouseTo(gfx::Point(175, 175));
EXPECT_TRUE(cursor_manager->IsCursorVisible());
// Use image capture icon as the mouse cursor icon in image capture mode.
const ui::Cursor landscape_cursor = cursor_manager->GetCursor();
EXPECT_EQ(CursorType::kCustom, landscape_cursor.type());
CaptureModeSessionTestApi test_api(controller->capture_mode_session());
EXPECT_TRUE(test_api.IsUsingCustomCursor(CaptureModeType::kImage));
// Rotate the screen.
orientation_test_api.SetDisplayRotation(
display::Display::ROTATE_270, display::Display::RotationSource::ACTIVE);
const ui::Cursor portrait_cursor = cursor_manager->GetCursor();
EXPECT_TRUE(test_api.IsUsingCustomCursor(CaptureModeType::kImage));
EXPECT_NE(landscape_cursor, portrait_cursor);
}
// Tests that in Region mode, cursor compositing is used instead of the system // Tests that in Region mode, cursor compositing is used instead of the system
// cursor when the cursor is being dragged. // cursor when the cursor is being dragged.
TEST_F(CaptureModeTest, RegionDragCursorCompositing) { TEST_F(CaptureModeTest, RegionDragCursorCompositing) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment