diff options
Diffstat (limited to 'chromium/ui/wm')
49 files changed, 1393 insertions, 235 deletions
diff --git a/chromium/ui/wm/BUILD.gn b/chromium/ui/wm/BUILD.gn index d006f7979a8..b3b9eb6a5de 100644 --- a/chromium/ui/wm/BUILD.gn +++ b/chromium/ui/wm/BUILD.gn @@ -6,7 +6,10 @@ import("//build/config/chromeos/ui_mode.gni") import("//build/config/ui.gni") import("//testing/test.gni") +assert(use_aura) + component("wm") { + output_name = "ui_wm" sources = [ "core/accelerator_delegate.h", "core/accelerator_filter.cc", @@ -19,8 +22,16 @@ component("wm") { "core/compound_event_filter.h", "core/coordinate_conversion.cc", "core/coordinate_conversion.h", + "core/cursor_loader.cc", + "core/cursor_loader.h", + "core/cursor_lookup.cc", + "core/cursor_lookup.h", "core/cursor_manager.cc", "core/cursor_manager.h", + "core/cursor_util.cc", + "core/cursor_util.h", + "core/cursors_aura.cc", + "core/cursors_aura.h", "core/default_activation_client.cc", "core/default_activation_client.h", "core/default_screen_position_client.cc", @@ -54,7 +65,6 @@ component("wm") { "core/window_properties.h", "core/window_util.cc", "core/window_util.h", - "core/wm_core_export.h", "core/wm_core_switches.cc", "core/wm_core_switches.h", "core/wm_state.cc", @@ -62,31 +72,32 @@ component("wm") { ] configs += [ "//build/config:precompiled_headers" ] - defines = [ "WM_CORE_IMPLEMENTATION" ] + defines = [ "IS_UI_WM_IMPL" ] - deps = [ + public_deps = [ "//base", "//build:chromeos_buildflags", - "//skia", "//ui/aura", "//ui/base", "//ui/base/cursor", "//ui/base/cursor/mojom:cursor_type", - "//ui/base/ime", "//ui/compositor", - "//ui/compositor_extra", "//ui/display", "//ui/events", - "//ui/events:events_base", - "//ui/events/devices", - "//ui/events/platform", "//ui/gfx", - "//ui/gfx/animation", "//ui/gfx/geometry", - "//ui/resources", "//ui/wm/public", ] + deps = [ + "//skia", + "//ui/base/ime", + "//ui/compositor_extra", + "//ui/events/platform", + "//ui/gfx/animation", + "//ui/resources", + ] + if (is_chromeos_ash) { sources += [ "core/ime_util_chromeos.cc", @@ -131,7 +142,9 @@ test("wm_unittests") { "core/capture_controller_unittest.cc", "core/compound_event_filter_unittest.cc", "core/coordinate_conversion_unittest.cc", + "core/cursor_loader_unittest.cc", "core/cursor_manager_unittest.cc", + "core/cursor_util_unittest.cc", "core/focus_controller_unittest.cc", "core/shadow_controller_unittest.cc", "core/transient_window_manager_unittest.cc", @@ -152,6 +165,7 @@ test("wm_unittests") { "//skia", "//testing/gtest", "//ui/aura:test_support", + "//ui/base", "//ui/base:test_support", "//ui/base/cursor", "//ui/base/cursor/mojom:cursor_type", @@ -161,6 +175,7 @@ test("wm_unittests") { "//ui/events:test_support", "//ui/events/platform", "//ui/gfx", + "//ui/gfx:gfx_skia", "//ui/gfx/animation", "//ui/gfx/geometry", "//ui/gl:test_support", @@ -176,8 +191,10 @@ test("wm_unittests") { } if (is_fuchsia) { - use_cfv2 = false - additional_manifest_fragments = - [ "//build/config/fuchsia/test/present_view_capabilities.test-cmx" ] + use_cfv1 = false + additional_manifest_fragments = [ + "//build/config/fuchsia/test/present_view.shard.test-cml", + "//third_party/fuchsia-sdk/sdk/pkg/vulkan/client.shard.cml", + ] } } diff --git a/chromium/ui/wm/OWNERS b/chromium/ui/wm/OWNERS new file mode 100644 index 00000000000..8657d05e8b2 --- /dev/null +++ b/chromium/ui/wm/OWNERS @@ -0,0 +1,2 @@ +sky@chromium.org +oshima@chromium.org diff --git a/chromium/ui/wm/core/OWNERS b/chromium/ui/wm/core/OWNERS index 5c9931ca569..127c209c06f 100644 --- a/chromium/ui/wm/core/OWNERS +++ b/chromium/ui/wm/core/OWNERS @@ -1 +1,2 @@ +per-file cursor*=file://ui/base/cursor/OWNERS per-file shadow*=estade@chromium.org diff --git a/chromium/ui/wm/core/accelerator_filter.h b/chromium/ui/wm/core/accelerator_filter.h index 5de3e49d58d..b448b0679ae 100644 --- a/chromium/ui/wm/core/accelerator_filter.h +++ b/chromium/ui/wm/core/accelerator_filter.h @@ -7,15 +7,15 @@ #include <memory> +#include "base/component_export.h" #include "ui/events/event_handler.h" -#include "ui/wm/core/wm_core_export.h" namespace wm { class AcceleratorDelegate; // AcceleratorFilter filters key events for AcceleratorControler handling global // keyboard accelerators. -class WM_CORE_EXPORT AcceleratorFilter : public ui::EventHandler { +class COMPONENT_EXPORT(UI_WM) AcceleratorFilter : public ui::EventHandler { public: // AcceleratorFilter doesn't own |accelerator_history|, it's owned by // AcceleratorController. diff --git a/chromium/ui/wm/core/base_focus_rules.h b/chromium/ui/wm/core/base_focus_rules.h index 79aba7f7389..bdc6a3b3dd0 100644 --- a/chromium/ui/wm/core/base_focus_rules.h +++ b/chromium/ui/wm/core/base_focus_rules.h @@ -5,13 +5,14 @@ #ifndef UI_WM_CORE_BASE_FOCUS_RULES_H_ #define UI_WM_CORE_BASE_FOCUS_RULES_H_ +#include "base/component_export.h" #include "ui/wm/core/focus_rules.h" namespace wm { // A set of basic focus and activation rules. Specializations should most likely // subclass this and call up to these methods rather than reimplementing them. -class WM_CORE_EXPORT BaseFocusRules : public FocusRules { +class COMPONENT_EXPORT(UI_WM) BaseFocusRules : public FocusRules { public: BaseFocusRules(const BaseFocusRules&) = delete; BaseFocusRules& operator=(const BaseFocusRules&) = delete; diff --git a/chromium/ui/wm/core/capture_controller.cc b/chromium/ui/wm/core/capture_controller.cc index d5502eb4190..560912a3f90 100644 --- a/chromium/ui/wm/core/capture_controller.cc +++ b/chromium/ui/wm/core/capture_controller.cc @@ -60,18 +60,24 @@ void CaptureController::SetCapture(aura::Window* new_capture_window) { std::map<aura::Window*, aura::client::CaptureDelegate*> delegates = delegates_; + aura::WindowTracker tracker; + if (new_capture_window) + tracker.Add(new_capture_window); + if (old_capture_window) + tracker.Add(old_capture_window); + // If we're starting a new capture, cancel all touches that aren't // targeted to the capturing window. if (new_capture_window) { + aura::Env::GetInstance()->gesture_recognizer()->CancelActiveTouchesExcept( + new_capture_window); // Cancelling touches might cause |new_capture_window| to get deleted. // Track |new_capture_window| and check if it still exists before // committing |capture_window_|. - aura::WindowTracker tracker; - tracker.Add(new_capture_window); - aura::Env::GetInstance()->gesture_recognizer()->CancelActiveTouchesExcept( - new_capture_window); if (!tracker.Contains(new_capture_window)) new_capture_window = nullptr; + if (old_capture_window && !tracker.Contains(old_capture_window)) + old_capture_window = nullptr; } capture_window_ = new_capture_window; @@ -81,8 +87,15 @@ void CaptureController::SetCapture(aura::Window* new_capture_window) { ? nullptr : delegates_[capture_root_window]; - for (const auto& it : delegates) + // With more than one delegate (e.g. multiple displays), an earlier + // UpdateCapture() call could cancel an existing capture and destroy + // |old_capture_window|, causing a later UpdateCapture() call to access + // a dangling pointer, so detect and handle it. + for (const auto& it : delegates) { it.second->UpdateCapture(old_capture_window, new_capture_window); + if (old_capture_window && !tracker.Contains(old_capture_window)) + old_capture_window = nullptr; + } if (capture_delegate_ != old_capture_delegate) { if (old_capture_delegate) diff --git a/chromium/ui/wm/core/capture_controller.h b/chromium/ui/wm/core/capture_controller.h index 358674ef13d..3be249ac1cd 100644 --- a/chromium/ui/wm/core/capture_controller.h +++ b/chromium/ui/wm/core/capture_controller.h @@ -7,11 +7,11 @@ #include <map> +#include "base/component_export.h" #include "base/memory/raw_ptr.h" #include "base/observer_list.h" #include "ui/aura/client/capture_client.h" #include "ui/aura/window_observer.h" -#include "ui/wm/core/wm_core_export.h" namespace aura { namespace client { @@ -22,7 +22,8 @@ class CaptureDelegate; namespace wm { // Internal CaptureClient implementation. See ScopedCaptureClient for details. -class WM_CORE_EXPORT CaptureController : public aura::client::CaptureClient { +class COMPONENT_EXPORT(UI_WM) CaptureController + : public aura::client::CaptureClient { public: CaptureController(); @@ -74,9 +75,10 @@ class WM_CORE_EXPORT CaptureController : public aura::client::CaptureClient { // ScopedCaptureClient is responsible for creating a CaptureClient for a // RootWindow. Specifically it creates a single CaptureController that is shared // among all ScopedCaptureClients and adds the RootWindow to it. -class WM_CORE_EXPORT ScopedCaptureClient : public aura::WindowObserver { +class COMPONENT_EXPORT(UI_WM) ScopedCaptureClient + : public aura::WindowObserver { public: - class WM_CORE_EXPORT TestApi { + class COMPONENT_EXPORT(UI_WM) TestApi { public: explicit TestApi(ScopedCaptureClient* client) : client_(client) {} diff --git a/chromium/ui/wm/core/capture_controller_unittest.cc b/chromium/ui/wm/core/capture_controller_unittest.cc index 05d653f4a00..94b330b9f4a 100644 --- a/chromium/ui/wm/core/capture_controller_unittest.cc +++ b/chromium/ui/wm/core/capture_controller_unittest.cc @@ -14,6 +14,7 @@ #include "ui/aura/test/test_window_delegate.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" +#include "ui/aura/window_tracker.h" #include "ui/events/event.h" #include "ui/events/event_utils.h" #include "ui/events/test/event_generator.h" @@ -28,26 +29,35 @@ namespace { // has been acquired. class TestCaptureDelegate : public aura::client::CaptureDelegate { public: - TestCaptureDelegate() : has_capture_(false) {} + TestCaptureDelegate() = default; TestCaptureDelegate(const TestCaptureDelegate&) = delete; TestCaptureDelegate& operator=(const TestCaptureDelegate&) = delete; - ~TestCaptureDelegate() override {} + ~TestCaptureDelegate() override = default; - bool HasNativeCapture() const { - return has_capture_; - } + bool HasNativeCapture() const { return has_capture_; } + aura::Window* old_capture() { return old_capture_; } + aura::Window* new_capture() { return new_capture_; } + void SetDestroyOldCapture(bool destroy) { destroy_old_capture_ = destroy; } // aura::client::CaptureDelegate: void UpdateCapture(aura::Window* old_capture, - aura::Window* new_capture) override {} + aura::Window* new_capture) override { + old_capture_ = old_capture; + new_capture_ = new_capture; + if (old_capture && destroy_old_capture_) + delete old_capture; + } void OnOtherRootGotCapture() override {} void SetNativeCapture() override { has_capture_ = true; } void ReleaseNativeCapture() override { has_capture_ = false; } private: - bool has_capture_; + bool has_capture_ = false; + aura::Window* old_capture_ = nullptr; + aura::Window* new_capture_ = nullptr; + bool destroy_old_capture_ = false; }; } // namespace @@ -61,26 +71,26 @@ class CaptureControllerTest : public aura::test::AuraTestBase { void SetUp() override { AuraTestBase::SetUp(); - capture_controller_ = std::make_unique<ScopedCaptureClient>(root_window()); + capture_client_ = std::make_unique<ScopedCaptureClient>(root_window()); second_host_ = aura::WindowTreeHost::Create( ui::PlatformWindowInitProperties{gfx::Rect(0, 0, 800, 600)}); second_host_->InitHost(); second_host_->window()->Show(); second_host_->SetBoundsInPixels(gfx::Rect(800, 600)); - second_capture_controller_ = + second_capture_client_ = std::make_unique<ScopedCaptureClient>(second_host_->window()); } void TearDown() override { RunAllPendingInMessageLoop(); - second_capture_controller_.reset(); + second_capture_client_.reset(); // Kill any active compositors before we hit the compositor shutdown paths. second_host_.reset(); - capture_controller_.reset(); + capture_client_.reset(); AuraTestBase::TearDown(); } @@ -105,16 +115,17 @@ class CaptureControllerTest : public aura::test::AuraTestBase { return CaptureController::Get()->GetCaptureWindow(); } - std::unique_ptr<ScopedCaptureClient> capture_controller_; + std::unique_ptr<ScopedCaptureClient> capture_client_; std::unique_ptr<aura::WindowTreeHost> second_host_; - std::unique_ptr<ScopedCaptureClient> second_capture_controller_; + std::unique_ptr<ScopedCaptureClient> second_capture_client_; }; // Makes sure that internal details that are set on mouse down (such as // mouse_pressed_handler()) are cleared when another root window takes capture. TEST_F(CaptureControllerTest, ResetMouseEventHandlerOnCapture) { // Create a window inside the WindowEventDispatcher. - std::unique_ptr<aura::Window> w1(CreateNormalWindow(1, root_window(), NULL)); + std::unique_ptr<aura::Window> w1( + CreateNormalWindow(1, root_window(), nullptr)); // Make a synthesized mouse down event. Ensure that the WindowEventDispatcher // will dispatch further mouse events to |w1|. @@ -126,12 +137,12 @@ TEST_F(CaptureControllerTest, ResetMouseEventHandlerOnCapture) { // Build a window in the second WindowEventDispatcher. std::unique_ptr<aura::Window> w2( - CreateNormalWindow(2, second_host_->window(), NULL)); + CreateNormalWindow(2, second_host_->window(), nullptr)); // The act of having the second window take capture should clear out mouse // pressed handler in the first WindowEventDispatcher. w2->SetCapture(); - EXPECT_EQ(NULL, host()->dispatcher()->mouse_pressed_handler()); + EXPECT_EQ(nullptr, host()->dispatcher()->mouse_pressed_handler()); } // Makes sure that when one window gets capture, it forces the release on the @@ -139,13 +150,14 @@ TEST_F(CaptureControllerTest, ResetMouseEventHandlerOnCapture) { // check on Windows. TEST_F(CaptureControllerTest, ResetOtherWindowCaptureOnCapture) { // Create a window inside the WindowEventDispatcher. - std::unique_ptr<aura::Window> w1(CreateNormalWindow(1, root_window(), NULL)); + std::unique_ptr<aura::Window> w1( + CreateNormalWindow(1, root_window(), nullptr)); w1->SetCapture(); EXPECT_EQ(w1.get(), GetCaptureWindow()); // Build a window in the second WindowEventDispatcher and give it capture. std::unique_ptr<aura::Window> w2( - CreateNormalWindow(2, second_host_->window(), NULL)); + CreateNormalWindow(2, second_host_->window(), nullptr)); w2->SetCapture(); EXPECT_EQ(w2.get(), GetCaptureWindow()); } @@ -154,7 +166,8 @@ TEST_F(CaptureControllerTest, ResetOtherWindowCaptureOnCapture) { // releasing capture. TEST_F(CaptureControllerTest, TouchTargetResetOnCaptureChange) { // Create a window inside the WindowEventDispatcher. - std::unique_ptr<aura::Window> w1(CreateNormalWindow(1, root_window(), NULL)); + std::unique_ptr<aura::Window> w1( + CreateNormalWindow(1, root_window(), nullptr)); ui::test::EventGenerator event_generator1(root_window()); event_generator1.PressTouch(); w1->SetCapture(); @@ -162,7 +175,7 @@ TEST_F(CaptureControllerTest, TouchTargetResetOnCaptureChange) { // Build a window in the second WindowEventDispatcher and give it capture. std::unique_ptr<aura::Window> w2( - CreateNormalWindow(2, second_host_->window(), NULL)); + CreateNormalWindow(2, second_host_->window(), nullptr)); w2->SetCapture(); EXPECT_EQ(w2.get(), GetCaptureWindow()); @@ -177,13 +190,14 @@ TEST_F(CaptureControllerTest, TouchTargetResetOnCaptureChange) { // is reparented to a different root window while it has capture. TEST_F(CaptureControllerTest, ReparentedWhileCaptured) { std::unique_ptr<TestCaptureDelegate> delegate(new TestCaptureDelegate); - ScopedCaptureClient::TestApi(capture_controller_.get()) + ScopedCaptureClient::TestApi(capture_client_.get()) .SetDelegate(delegate.get()); std::unique_ptr<TestCaptureDelegate> delegate2(new TestCaptureDelegate); - ScopedCaptureClient::TestApi(second_capture_controller_.get()) + ScopedCaptureClient::TestApi(second_capture_client_.get()) .SetDelegate(delegate2.get()); - std::unique_ptr<aura::Window> w(CreateNormalWindow(1, root_window(), NULL)); + std::unique_ptr<aura::Window> w( + CreateNormalWindow(1, root_window(), nullptr)); w->SetCapture(); EXPECT_EQ(w.get(), GetCaptureWindow()); EXPECT_TRUE(delegate->HasNativeCapture()); @@ -270,4 +284,57 @@ TEST_F(CaptureControllerTest, GestureResetWithCapture) { DispatchEventUsingWindowDispatcher(&mouse_press); } +TEST_F(CaptureControllerTest, UpdateCaptureDestroysOldCaptureWindow) { + TestCaptureDelegate delegate; + ScopedCaptureClient::TestApi(capture_client_.get()).SetDelegate(&delegate); + TestCaptureDelegate delegate2; + ScopedCaptureClient::TestApi(second_capture_client_.get()) + .SetDelegate(&delegate2); + + // Since delegate iteration order is not deterministic, use this to assert + // that the two scenarios below have opposite order. + aura::Window* first_old_capture = nullptr; + + { + // Create a window inside the WindowEventDispatcher. + std::unique_ptr<aura::Window> capture_window( + CreateNormalWindow(1, root_window(), nullptr)); + ui::test::EventGenerator event_generator(root_window()); + event_generator.PressTouch(); + capture_window->SetCapture(); + + delegate.SetDestroyOldCapture(true); + delegate2.SetDestroyOldCapture(false); + + aura::WindowTracker tracker({capture_window.get()}); + CaptureController::Get()->SetCapture(nullptr); + EXPECT_EQ(delegate.old_capture(), capture_window.get()); + first_old_capture = delegate2.old_capture(); + EXPECT_FALSE(tracker.Contains(capture_window.get())); + if (!tracker.Contains(capture_window.get())) + capture_window.release(); + } + + { + // Create a window inside the WindowEventDispatcher. + std::unique_ptr<aura::Window> capture_window( + CreateNormalWindow(1, root_window(), nullptr)); + ui::test::EventGenerator event_generator(root_window()); + event_generator.PressTouch(); + capture_window->SetCapture(); + + // Change order to account for map traversal order. + delegate.SetDestroyOldCapture(false); + delegate2.SetDestroyOldCapture(true); + + aura::WindowTracker tracker({capture_window.get()}); + CaptureController::Get()->SetCapture(nullptr); + EXPECT_NE(delegate.old_capture(), first_old_capture); + EXPECT_EQ(delegate2.old_capture(), capture_window.get()); + EXPECT_FALSE(tracker.Contains(capture_window.get())); + if (!tracker.Contains(capture_window.get())) + capture_window.release(); + } +} + } // namespace wm diff --git a/chromium/ui/wm/core/compound_event_filter.h b/chromium/ui/wm/core/compound_event_filter.h index b0f127e42b1..22a531b2555 100644 --- a/chromium/ui/wm/core/compound_event_filter.h +++ b/chromium/ui/wm/core/compound_event_filter.h @@ -5,12 +5,12 @@ #ifndef UI_WM_CORE_COMPOUND_EVENT_FILTER_H_ #define UI_WM_CORE_COMPOUND_EVENT_FILTER_H_ +#include "base/component_export.h" #include "base/observer_list.h" #include "base/strings/string_piece.h" #include "ui/events/event.h" #include "ui/events/event_handler.h" #include "ui/gfx/native_widget_types.h" -#include "ui/wm/core/wm_core_export.h" namespace ui { class GestureEvent; @@ -31,7 +31,7 @@ namespace wm { // consumed by any of those filters. If an event is consumed by a filter, the // rest of the filter(s) and CompoundEventFilter will not see the consumed // event. -class WM_CORE_EXPORT CompoundEventFilter : public ui::EventHandler { +class COMPONENT_EXPORT(UI_WM) CompoundEventFilter : public ui::EventHandler { public: CompoundEventFilter(); diff --git a/chromium/ui/wm/core/coordinate_conversion.h b/chromium/ui/wm/core/coordinate_conversion.h index e719999dc3c..363c6f88c65 100644 --- a/chromium/ui/wm/core/coordinate_conversion.h +++ b/chromium/ui/wm/core/coordinate_conversion.h @@ -5,7 +5,7 @@ #ifndef UI_WM_CORE_COORDINATE_CONVERSION_H_ #define UI_WM_CORE_COORDINATE_CONVERSION_H_ -#include "ui/wm/core/wm_core_export.h" +#include "base/component_export.h" namespace aura { class Window; @@ -23,37 +23,41 @@ namespace wm { // Converts the |point| from a given |window|'s coordinates into the screen // coordinates. // TODO: Remove the integer versions of these functions. See crbug.com/773331. -WM_CORE_EXPORT void ConvertPointToScreen(const aura::Window* window, - gfx::Point* point); +COMPONENT_EXPORT(UI_WM) +void ConvertPointToScreen(const aura::Window* window, gfx::Point* point); -WM_CORE_EXPORT void ConvertPointToScreen(const aura::Window* window, - gfx::PointF* point); +COMPONENT_EXPORT(UI_WM) +void ConvertPointToScreen(const aura::Window* window, gfx::PointF* point); // Converts the |point| from the screen coordinates to a given |window|'s // coordinates. -WM_CORE_EXPORT void ConvertPointFromScreen(const aura::Window* window, - gfx::Point* point_in_screen); +COMPONENT_EXPORT(UI_WM) +void ConvertPointFromScreen(const aura::Window* window, + gfx::Point* point_in_screen); -WM_CORE_EXPORT void ConvertPointFromScreen(const aura::Window* window, - gfx::PointF* point_in_screen); +COMPONENT_EXPORT(UI_WM) +void ConvertPointFromScreen(const aura::Window* window, + gfx::PointF* point_in_screen); // Converts |rect| from |window|'s coordinates to the virtual screen // coordinates. // TODO: Change the Rect versions to TranslateRect(To|From)Screen since they // do not handle size changes. -WM_CORE_EXPORT void ConvertRectToScreen(const aura::Window* window, - gfx::Rect* rect); +COMPONENT_EXPORT(UI_WM) +void ConvertRectToScreen(const aura::Window* window, gfx::Rect* rect); -WM_CORE_EXPORT void TranslateRectToScreen(const aura::Window* window, - gfx::RectF* rect); +COMPONENT_EXPORT(UI_WM) +void TranslateRectToScreen(const aura::Window* window, gfx::RectF* rect); // Converts |rect| from virtual screen coordinates to the |window|'s // coordinates. -WM_CORE_EXPORT void ConvertRectFromScreen(const aura::Window* window, - gfx::Rect* rect_in_screen); +COMPONENT_EXPORT(UI_WM) +void ConvertRectFromScreen(const aura::Window* window, + gfx::Rect* rect_in_screen); -WM_CORE_EXPORT void TranslateRectFromScreen(const aura::Window* window, - gfx::RectF* rect_in_screen); +COMPONENT_EXPORT(UI_WM) +void TranslateRectFromScreen(const aura::Window* window, + gfx::RectF* rect_in_screen); } // namespace wm diff --git a/chromium/ui/wm/core/cursor_loader.cc b/chromium/ui/wm/core/cursor_loader.cc new file mode 100644 index 00000000000..0ff466a17e9 --- /dev/null +++ b/chromium/ui/wm/core/cursor_loader.cc @@ -0,0 +1,144 @@ +// Copyright 2021 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 "ui/wm/core/cursor_loader.h" + +#include <map> +#include <vector> + +#include "base/check.h" +#include "base/memory/scoped_refptr.h" +#include "base/time/time.h" +#include "ui/base/cursor/cursor.h" +#include "ui/base/cursor/cursor_factory.h" +#include "ui/base/cursor/cursor_size.h" +#include "ui/base/cursor/mojom/cursor_type.mojom.h" +#include "ui/base/cursor/platform_cursor.h" +#include "ui/gfx/geometry/point.h" +#include "ui/wm/core/cursor_util.h" +#include "ui/wm/core/cursors_aura.h" + +namespace wm { + +namespace { + +using ::ui::mojom::CursorType; + +constexpr CursorType kAnimatedCursorTypes[] = {CursorType::kWait, + CursorType::kProgress}; + +constexpr base::TimeDelta kAnimatedCursorFrameDelay = base::Milliseconds(25); + +} // namespace + +CursorLoader::CursorLoader(bool use_platform_cursors) + : use_platform_cursors_(use_platform_cursors), + factory_(ui::CursorFactory::GetInstance()) { + factory_->AddObserver(this); +} + +CursorLoader::~CursorLoader() { + factory_->RemoveObserver(this); + UnloadCursors(); +} + +void CursorLoader::OnThemeLoaded() { + UnloadCursors(); +} + +void CursorLoader::UnloadCursors() { + image_cursors_.clear(); +} + +bool CursorLoader::SetDisplayData(display::Display::Rotation rotation, + float scale) { + if (rotation_ == rotation && scale_ == scale) + return false; + + rotation_ = rotation; + scale_ = scale; + UnloadCursors(); + if (use_platform_cursors_) + factory_->SetDeviceScaleFactor(scale_); + return true; +} + +void CursorLoader::SetSize(ui::CursorSize size) { + if (size_ == size) + return; + + size_ = size; + UnloadCursors(); +} + +void CursorLoader::SetPlatformCursor(ui::Cursor* cursor) { + DCHECK(cursor); + + // The platform cursor was already set via WebCursor::GetNativeCursor. + if (cursor->type() == CursorType::kCustom) + return; + cursor->set_image_scale_factor(scale()); + cursor->SetPlatformCursor(CursorFromType(cursor->type())); +} + +void CursorLoader::LoadImageCursor(CursorType type, + int resource_id, + const gfx::Point& hot) { + gfx::Point hotspot = hot; + if (base::ranges::count(kAnimatedCursorTypes, type) == 0) { + SkBitmap bitmap; + GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap); + image_cursors_[type] = factory_->CreateImageCursor(type, bitmap, hotspot); + } else { + std::vector<SkBitmap> bitmaps; + GetAnimatedCursorBitmaps(resource_id, scale(), rotation(), &hotspot, + &bitmaps); + image_cursors_[type] = factory_->CreateAnimatedCursor( + type, bitmaps, hotspot, kAnimatedCursorFrameDelay); + } +} + +scoped_refptr<ui::PlatformCursor> CursorLoader::CursorFromType( + CursorType type) { + // An image cursor is loaded for this type. + if (image_cursors_.count(type)) + return image_cursors_[type]; + + // Check if there's a default platform cursor available. + // For the none cursor, we also need to use the platform factory to take + // into account the different ways of creating an invisible cursor. + scoped_refptr<ui::PlatformCursor> cursor; + if (use_platform_cursors_ || type == CursorType::kNone) { + cursor = factory_->GetDefaultCursor(type); + if (cursor) + return cursor; + // The cursor may fail to load if the cursor theme has just been reset. + // We will be notified when the theme is loaded, but at this time we have to + // fall back to the assets. + LOG(WARNING) << "Failed to load a platform cursor of type " << type; + } + + // Loads the default Aura cursor bitmap for the cursor type. Falls back on + // pointer cursor if this fails. + cursor = LoadCursorFromAsset(type); + if (!cursor && type != CursorType::kPointer) { + cursor = CursorFromType(CursorType::kPointer); + image_cursors_[type] = cursor; + } + DCHECK(cursor) << "Failed to load a bitmap for the pointer cursor."; + return cursor; +} + +scoped_refptr<ui::PlatformCursor> CursorLoader::LoadCursorFromAsset( + CursorType type) { + int resource_id; + gfx::Point hotspot; + if (GetCursorDataFor(size(), type, scale(), &resource_id, &hotspot)) { + LoadImageCursor(type, resource_id, hotspot); + return image_cursors_[type]; + } + return nullptr; +} + +} // namespace wm diff --git a/chromium/ui/wm/core/cursor_loader.h b/chromium/ui/wm/core/cursor_loader.h new file mode 100644 index 00000000000..8cdb35a8fba --- /dev/null +++ b/chromium/ui/wm/core/cursor_loader.h @@ -0,0 +1,88 @@ +// 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 UI_WM_CORE_CURSOR_LOADER_H_ +#define UI_WM_CORE_CURSOR_LOADER_H_ + +#include <map> +#include <memory> + +#include "base/component_export.h" +#include "base/memory/raw_ptr.h" +#include "base/memory/scoped_refptr.h" +#include "ui/base/cursor/cursor.h" +#include "ui/base/cursor/cursor_factory.h" +#include "ui/base/cursor/cursor_size.h" +#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" +#include "ui/display/display.h" + +namespace gfx { +class Point; +} + +namespace ui { +class PlatformCursor; +} + +namespace wm { + +class COMPONENT_EXPORT(UI_WM) CursorLoader : public ui::CursorFactoryObserver { + public: + explicit CursorLoader(bool use_platform_cursors = true); + CursorLoader(const CursorLoader&) = delete; + CursorLoader& operator=(const CursorLoader&) = delete; + ~CursorLoader() override; + + // ui::CursorFactoryObserver: + void OnThemeLoaded() override; + + // Returns the rotation and scale of the currently loaded cursor. + display::Display::Rotation rotation() const { return rotation_; } + float scale() const { return scale_; } + + // Sets the rotation and scale the cursors are loaded for. + // Returns true if the cursor image was reloaded. + bool SetDisplayData(display::Display::Rotation rotation, float scale); + + // Returns the size of the currently loaded cursor. + ui::CursorSize size() const { return size_; } + + // Sets the size of the mouse cursor icon. + void SetSize(ui::CursorSize size); + + // Sets the platform cursor based on the type of |cursor|. + void SetPlatformCursor(ui::Cursor* cursor); + + private: + // Resets the cursor cache. + void UnloadCursors(); + void LoadImageCursor(ui::mojom::CursorType id, + int resource_id, + const gfx::Point& hot); + scoped_refptr<ui::PlatformCursor> CursorFromType(ui::mojom::CursorType type); + scoped_refptr<ui::PlatformCursor> LoadCursorFromAsset( + ui::mojom::CursorType type); + + // Whether to use cursors provided by the underlying platform (e.g. X11 + // cursors). If false or in the case of a failure, Chromium assets will be + // used instead. + const bool use_platform_cursors_; + + std::map<ui::mojom::CursorType, scoped_refptr<ui::PlatformCursor>> + image_cursors_; + raw_ptr<ui::CursorFactory> factory_ = nullptr; + + // The current scale of the mouse cursor icon. + float scale_ = 1.0f; + + // The current rotation of the mouse cursor icon. + display::Display::Rotation rotation_ = display::Display::ROTATE_0; + + // The preferred size of the mouse cursor icon. + ui::CursorSize size_ = ui::CursorSize::kNormal; +}; + +} // namespace wm + +#endif // UI_WM_CORE_CURSOR_LOADER_H_ diff --git a/chromium/ui/wm/core/cursor_loader_unittest.cc b/chromium/ui/wm/core/cursor_loader_unittest.cc new file mode 100644 index 00000000000..ab833f3f4ba --- /dev/null +++ b/chromium/ui/wm/core/cursor_loader_unittest.cc @@ -0,0 +1,70 @@ +// Copyright 2020 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 "ui/wm/core/cursor_loader.h" + +#include "base/memory/scoped_refptr.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/aura/test/aura_test_base.h" +#include "ui/base/cursor/cursor.h" +#include "ui/base/cursor/cursor_factory.h" +#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" +#include "ui/base/cursor/platform_cursor.h" +#include "ui/gfx/geometry/point.h" +#include "ui/gfx/skia_util.h" +#include "ui/wm/core/cursor_lookup.h" +#include "ui/wm/core/cursors_aura.h" + +namespace wm { + +namespace { + +using CursorLoaderTest = ::aura::test::AuraTestBase; +using ::ui::mojom::CursorType; + +SkBitmap GetTestBitmap() { + SkBitmap bitmap; + bitmap.allocN32Pixels(10, 10); + return bitmap; +} + +} // namespace + +TEST_F(CursorLoaderTest, InvisibleCursor) { + CursorLoader cursor_loader; + ui::Cursor invisible_cursor(CursorType::kNone); + cursor_loader.SetPlatformCursor(&invisible_cursor); + + EXPECT_EQ( + invisible_cursor.platform(), + ui::CursorFactory::GetInstance()->GetDefaultCursor(CursorType::kNone)); +} + +// TODO(https://crbug.com/1270302): although this is testing `GetCursorBitmap` +// from cursor_lookup.h, that will be replaced by a method of the same name in +// CursorLoader. +TEST_F(CursorLoaderTest, GetCursorData) { + const ui::Cursor invisible_cursor = CursorType::kNone; + EXPECT_TRUE(GetCursorBitmap(invisible_cursor).isNull()); + EXPECT_TRUE(GetCursorHotspot(invisible_cursor).IsOrigin()); + + const ui::Cursor pointer_cursor = CursorType::kPointer; + EXPECT_FALSE(GetCursorBitmap(pointer_cursor).isNull()); + EXPECT_TRUE(gfx::BitmapsAreEqual(GetCursorBitmap(pointer_cursor), + GetDefaultBitmap(pointer_cursor))); + EXPECT_EQ(GetCursorHotspot(pointer_cursor), + GetDefaultHotspot(pointer_cursor)); + + ui::Cursor custom_cursor(CursorType::kCustom); + const SkBitmap kBitmap = GetTestBitmap(); + constexpr gfx::Point kHotspot = gfx::Point(10, 10); + custom_cursor.set_custom_bitmap(kBitmap); + custom_cursor.set_custom_hotspot(kHotspot); + EXPECT_EQ(GetCursorBitmap(custom_cursor).getGenerationID(), + kBitmap.getGenerationID()); + EXPECT_EQ(GetCursorHotspot(custom_cursor), kHotspot); +} + +} // namespace wm diff --git a/chromium/ui/wm/core/cursor_lookup.cc b/chromium/ui/wm/core/cursor_lookup.cc new file mode 100644 index 00000000000..f7c6646dd5f --- /dev/null +++ b/chromium/ui/wm/core/cursor_lookup.cc @@ -0,0 +1,27 @@ +// Copyright 2020 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 "ui/wm/core/cursor_lookup.h" + +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/cursor/cursor.h" +#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" +#include "ui/gfx/geometry/point.h" +#include "ui/wm/core/cursors_aura.h" + +namespace wm { + +SkBitmap GetCursorBitmap(const ui::Cursor& cursor) { + if (cursor.type() == ui::mojom::CursorType::kCustom) + return cursor.custom_bitmap(); + return GetDefaultBitmap(cursor); +} + +gfx::Point GetCursorHotspot(const ui::Cursor& cursor) { + if (cursor.type() == ui::mojom::CursorType::kCustom) + return cursor.custom_hotspot(); + return GetDefaultHotspot(cursor); +} + +} // namespace wm diff --git a/chromium/ui/wm/core/cursor_lookup.h b/chromium/ui/wm/core/cursor_lookup.h new file mode 100644 index 00000000000..4fdc9a5372d --- /dev/null +++ b/chromium/ui/wm/core/cursor_lookup.h @@ -0,0 +1,30 @@ +// Copyright 2020 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 UI_WM_CORE_CURSOR_LOOKUP_H_ +#define UI_WM_CORE_CURSOR_LOOKUP_H_ + +#include "base/component_export.h" + +class SkBitmap; + +namespace gfx { +class Point; +} + +namespace ui { +class Cursor; +} + +namespace wm { + +COMPONENT_EXPORT(UI_WM) +SkBitmap GetCursorBitmap(const ui::Cursor& cursor); + +COMPONENT_EXPORT(UI_WM) +gfx::Point GetCursorHotspot(const ui::Cursor& cursor); + +} // namespace wm + +#endif // UI_WM_CORE_CURSOR_LOOKUP_H_ diff --git a/chromium/ui/wm/core/cursor_manager.h b/chromium/ui/wm/core/cursor_manager.h index 011f2f04d67..3498836f551 100644 --- a/chromium/ui/wm/core/cursor_manager.h +++ b/chromium/ui/wm/core/cursor_manager.h @@ -7,13 +7,13 @@ #include <memory> +#include "base/component_export.h" #include "base/observer_list.h" #include "ui/aura/client/cursor_client.h" #include "ui/display/display.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/native_widget_types.h" #include "ui/wm/core/native_cursor_manager_delegate.h" -#include "ui/wm/core/wm_core_export.h" namespace ui { class KeyEvent; @@ -32,8 +32,9 @@ class NativeCursorManager; // requests to queue any further changes until a later time. It sends changes // to the NativeCursorManager, which communicates back to us when these changes // were made through the NativeCursorManagerDelegate interface. -class WM_CORE_EXPORT CursorManager : public aura::client::CursorClient, - public NativeCursorManagerDelegate { +class COMPONENT_EXPORT(UI_WM) CursorManager + : public aura::client::CursorClient, + public NativeCursorManagerDelegate { public: explicit CursorManager(std::unique_ptr<NativeCursorManager> delegate); diff --git a/chromium/ui/wm/core/cursor_util.cc b/chromium/ui/wm/core/cursor_util.cc new file mode 100644 index 00000000000..5f02a8d4625 --- /dev/null +++ b/chromium/ui/wm/core/cursor_util.cc @@ -0,0 +1,163 @@ +// Copyright 2014 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 "ui/wm/core/cursor_util.h" + +#include "base/check_op.h" +#include "base/notreached.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/geometry/point.h" +#include "ui/gfx/geometry/point_conversions.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gfx/geometry/size_conversions.h" +#include "ui/gfx/geometry/skia_conversions.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/gfx/image/image_skia_rep.h" +#include "ui/gfx/skbitmap_operations.h" + +namespace wm { + +namespace { + +// Converts the SkBitmap to use a different alpha type. Returns true if bitmap +// was modified, otherwise returns false. +bool ConvertSkBitmapAlphaType(SkBitmap* bitmap, SkAlphaType alpha_type) { + if (bitmap->info().alphaType() == alpha_type) { + return false; + } + + // Copy the bitmap into a temporary buffer. This will convert alpha type. + SkImageInfo image_info = + SkImageInfo::MakeN32(bitmap->width(), bitmap->height(), alpha_type); + size_t info_row_bytes = image_info.minRowBytes(); + std::vector<char> buffer(image_info.computeByteSize(info_row_bytes)); + bitmap->readPixels(image_info, &buffer[0], info_row_bytes, 0, 0); + // Read the temporary buffer back into the original bitmap. + bitmap->reset(); + bitmap->allocPixels(image_info); + // this memcpy call assumes bitmap->rowBytes() == info_row_bytes + memcpy(bitmap->getPixels(), &buffer[0], buffer.size()); + + return true; +} + +} // namespace + +void ScaleAndRotateCursorBitmapAndHotpoint(float scale, + display::Display::Rotation rotation, + SkBitmap* bitmap, + gfx::Point* hotpoint) { + // SkBitmapOperations::Rotate() needs the bitmap to have premultiplied alpha, + // so convert bitmap alpha type if we are going to rotate. + bool was_converted = false; + if (rotation != display::Display::ROTATE_0 && + bitmap->info().alphaType() == kUnpremul_SkAlphaType) { + ConvertSkBitmapAlphaType(bitmap, kPremul_SkAlphaType); + was_converted = true; + } + + switch (rotation) { + case display::Display::ROTATE_0: + break; + case display::Display::ROTATE_90: + hotpoint->SetPoint(bitmap->height() - hotpoint->y(), hotpoint->x()); + *bitmap = SkBitmapOperations::Rotate( + *bitmap, SkBitmapOperations::ROTATION_90_CW); + break; + case display::Display::ROTATE_180: + hotpoint->SetPoint( + bitmap->width() - hotpoint->x(), bitmap->height() - hotpoint->y()); + *bitmap = SkBitmapOperations::Rotate( + *bitmap, SkBitmapOperations::ROTATION_180_CW); + break; + case display::Display::ROTATE_270: + hotpoint->SetPoint(hotpoint->y(), bitmap->width() - hotpoint->x()); + *bitmap = SkBitmapOperations::Rotate( + *bitmap, SkBitmapOperations::ROTATION_270_CW); + break; + } + + if (was_converted) { + ConvertSkBitmapAlphaType(bitmap, kUnpremul_SkAlphaType); + } + + if (scale < FLT_EPSILON) { + NOTREACHED() << "Scale must be larger than 0."; + scale = 1.0f; + } + + if (scale == 1.0f) + return; + + gfx::Size scaled_size = gfx::ScaleToFlooredSize( + gfx::Size(bitmap->width(), bitmap->height()), scale); + + // TODO(crbug.com/919866): skia::ImageOperations::Resize() doesn't support + // unpremultiplied alpha bitmaps. + SkBitmap scaled_bitmap; + scaled_bitmap.setInfo( + bitmap->info().makeWH(scaled_size.width(), scaled_size.height())); + if (scaled_bitmap.tryAllocPixels()) { + bitmap->pixmap().scalePixels( + scaled_bitmap.pixmap(), + {SkFilterMode::kLinear, SkMipmapMode::kNearest}); + } + + *bitmap = scaled_bitmap; + *hotpoint = gfx::ScaleToFlooredPoint(*hotpoint, scale); +} + +void GetImageCursorBitmap(int resource_id, + float scale, + display::Display::Rotation rotation, + gfx::Point* hotspot, + SkBitmap* bitmap) { + const gfx::ImageSkia* image = + ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); + const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale); + // TODO(oshima): The cursor should use resource scale factor when + // fractional scale factor is enabled. crbug.com/372212 + (*bitmap) = image_rep.GetBitmap(); + ScaleAndRotateCursorBitmapAndHotpoint( + scale / image_rep.scale(), rotation, bitmap, hotspot); + // |image_rep| is owned by the resource bundle. So we do not need to free it. +} + +void GetAnimatedCursorBitmaps(int resource_id, + float scale, + display::Display::Rotation rotation, + gfx::Point* hotspot, + std::vector<SkBitmap>* bitmaps) { + // TODO(oshima|tdanderson): Support rotation and fractional scale factor. + const gfx::ImageSkia* image = + ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); + const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale); + SkBitmap bitmap = image_rep.GetBitmap(); + + // The image is assumed to be a concatenation of animation frames from left to + // right. Also, each frame is assumed to be square (width == height). + int frame_width = bitmap.height(); + int frame_height = frame_width; + int total_width = bitmap.width(); + DCHECK_EQ(total_width % frame_width, 0); + int frame_count = total_width / frame_width; + DCHECK_GT(frame_count, 0); + + bitmaps->resize(frame_count); + + for (int frame = 0; frame < frame_count; ++frame) { + int x_offset = frame_width * frame; + DCHECK_LE(x_offset + frame_width, total_width); + + SkBitmap cropped = SkBitmapOperations::CreateTiledBitmap( + bitmap, x_offset, 0, frame_width, frame_height); + DCHECK_EQ(frame_width, cropped.width()); + DCHECK_EQ(frame_height, cropped.height()); + + (*bitmaps)[frame] = cropped; + } +} + +} // namespace wm diff --git a/chromium/ui/wm/core/cursor_util.h b/chromium/ui/wm/core/cursor_util.h new file mode 100644 index 00000000000..5bf8350642f --- /dev/null +++ b/chromium/ui/wm/core/cursor_util.h @@ -0,0 +1,44 @@ +// Copyright 2014 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 UI_WM_CORE_CURSOR_UTIL_H_ +#define UI_WM_CORE_CURSOR_UTIL_H_ + +#include <vector> + +#include "base/component_export.h" +#include "ui/display/display.h" + +class SkBitmap; + +namespace gfx { +class Point; +} + +namespace wm { + +// Scale and rotate the cursor's bitmap and hotpoint. +// |bitmap_in_out| and |hotpoint_in_out| are used as +// both input and output. +COMPONENT_EXPORT(UI_WM) +void ScaleAndRotateCursorBitmapAndHotpoint(float scale, + display::Display::Rotation rotation, + SkBitmap* bitmap_in_out, + gfx::Point* hotpoint_in_out); + +// Helpers for CursorLoader. +void GetImageCursorBitmap(int resource_id, + float scale, + display::Display::Rotation rotation, + gfx::Point* hotspot, + SkBitmap* bitmap); +void GetAnimatedCursorBitmaps(int resource_id, + float scale, + display::Display::Rotation rotation, + gfx::Point* hotspot, + std::vector<SkBitmap>* bitmaps); + +} // namespace wm + +#endif // UI_WM_CORE_CURSOR_UTIL_H_ diff --git a/chromium/ui/wm/core/cursor_util_unittest.cc b/chromium/ui/wm/core/cursor_util_unittest.cc new file mode 100644 index 00000000000..02f0241c47b --- /dev/null +++ b/chromium/ui/wm/core/cursor_util_unittest.cc @@ -0,0 +1,70 @@ +// Copyright 2019 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 "ui/wm/core/cursor_util.h" + +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/geometry/point.h" + +namespace wm { +namespace { + +// Parameterized test for cursor bitmaps with premultiplied and unpremultiplied +// alpha. +class CursorUtilTest : public testing::TestWithParam<bool> { + public: + SkColor GetPixelColor() { + return GetParam() ? SkColorSetARGB(128, 255, 0, 0) + : SkColorSetARGB(128, 128, 0, 0); + } + SkImageInfo GetImageInfo() { + return GetParam() ? SkImageInfo::MakeN32(10, 5, kUnpremul_SkAlphaType) + : SkImageInfo::MakeN32(10, 5, kPremul_SkAlphaType); + } +}; + +TEST_P(CursorUtilTest, ScaleAndRotate) { + const SkColor pixel_color = GetPixelColor(); + + SkBitmap bitmap; + bitmap.setInfo(GetImageInfo()); + bitmap.allocPixels(); + bitmap.eraseColor(pixel_color); + + gfx::Point hotpoint(3, 4); + + ScaleAndRotateCursorBitmapAndHotpoint(1.0f, display::Display::ROTATE_0, + &bitmap, &hotpoint); + EXPECT_EQ(10, bitmap.width()); + EXPECT_EQ(5, bitmap.height()); + EXPECT_EQ("3,4", hotpoint.ToString()); + EXPECT_EQ(pixel_color, bitmap.pixmap().getColor(0, 0)); + + ScaleAndRotateCursorBitmapAndHotpoint(1.0f, display::Display::ROTATE_90, + &bitmap, &hotpoint); + EXPECT_EQ(5, bitmap.width()); + EXPECT_EQ(10, bitmap.height()); + EXPECT_EQ("1,3", hotpoint.ToString()); + EXPECT_EQ(pixel_color, bitmap.pixmap().getColor(0, 0)); + + ScaleAndRotateCursorBitmapAndHotpoint(2.0f, display::Display::ROTATE_180, + &bitmap, &hotpoint); + EXPECT_EQ(10, bitmap.width()); + EXPECT_EQ(20, bitmap.height()); + EXPECT_EQ("8,14", hotpoint.ToString()); + EXPECT_EQ(pixel_color, bitmap.pixmap().getColor(0, 0)); + + ScaleAndRotateCursorBitmapAndHotpoint(1.0f, display::Display::ROTATE_270, + &bitmap, &hotpoint); + EXPECT_EQ(20, bitmap.width()); + EXPECT_EQ(10, bitmap.height()); + EXPECT_EQ("14,2", hotpoint.ToString()); + EXPECT_EQ(pixel_color, bitmap.pixmap().getColor(0, 0)); +} + +INSTANTIATE_TEST_SUITE_P(All, CursorUtilTest, testing::Bool()); + +} // namespace +} // namespace wm diff --git a/chromium/ui/wm/core/cursors_aura.cc b/chromium/ui/wm/core/cursors_aura.cc new file mode 100644 index 00000000000..94c9c897937 --- /dev/null +++ b/chromium/ui/wm/core/cursors_aura.cc @@ -0,0 +1,371 @@ +// Copyright (c) 2013 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 "ui/wm/core/cursors_aura.h" + +#include <stddef.h> + +#include "build/build_config.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/cursor/cursor.h" +#include "ui/base/cursor/cursor_size.h" +#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/geometry/point.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/gfx/image/image_skia_rep.h" +#include "ui/resources/grit/ui_resources.h" + +#if BUILDFLAG(IS_WIN) +#include "ui/base/win/win_cursor.h" +#include "ui/gfx/icon_util.h" +#include "ui/wm/core/cursor_loader.h" +#endif + +namespace wm { + +namespace { + +namespace mojom = ::ui::mojom; + +struct HotPoint { + int x; + int y; +}; + +struct CursorData { + mojom::CursorType id; + int resource_id; + HotPoint hot_1x; + HotPoint hot_2x; +}; + +struct CursorSizeData { + const ui::CursorSize id; + const CursorData* cursors; + const int length; +}; + +const CursorData kNormalCursors[] = { + {mojom::CursorType::kNull, IDR_AURA_CURSOR_PTR, {4, 4}, {7, 7}}, + {mojom::CursorType::kPointer, IDR_AURA_CURSOR_PTR, {4, 4}, {7, 7}}, + {mojom::CursorType::kNoDrop, IDR_AURA_CURSOR_NO_DROP, {9, 9}, {18, 18}}, + {mojom::CursorType::kNotAllowed, IDR_AURA_CURSOR_NO_DROP, {9, 9}, {18, 18}}, + {mojom::CursorType::kCopy, IDR_AURA_CURSOR_COPY, {9, 9}, {18, 18}}, + {mojom::CursorType::kHand, IDR_AURA_CURSOR_HAND, {9, 4}, {19, 8}}, + {mojom::CursorType::kMove, IDR_AURA_CURSOR_MOVE, {11, 11}, {23, 23}}, + {mojom::CursorType::kNorthEastResize, + IDR_AURA_CURSOR_NORTH_EAST_RESIZE, + {12, 11}, + {25, 23}}, + {mojom::CursorType::kSouthWestResize, + IDR_AURA_CURSOR_SOUTH_WEST_RESIZE, + {12, 11}, + {25, 23}}, + {mojom::CursorType::kSouthEastResize, + IDR_AURA_CURSOR_SOUTH_EAST_RESIZE, + {11, 11}, + {24, 23}}, + {mojom::CursorType::kNorthWestResize, + IDR_AURA_CURSOR_NORTH_WEST_RESIZE, + {11, 11}, + {24, 23}}, + {mojom::CursorType::kNorthResize, + IDR_AURA_CURSOR_NORTH_RESIZE, + {11, 12}, + {23, 23}}, + {mojom::CursorType::kSouthResize, + IDR_AURA_CURSOR_SOUTH_RESIZE, + {11, 12}, + {23, 23}}, + {mojom::CursorType::kEastResize, + IDR_AURA_CURSOR_EAST_RESIZE, + {12, 11}, + {25, 23}}, + {mojom::CursorType::kWestResize, + IDR_AURA_CURSOR_WEST_RESIZE, + {12, 11}, + {25, 23}}, + {mojom::CursorType::kIBeam, IDR_AURA_CURSOR_IBEAM, {12, 12}, {24, 25}}, + {mojom::CursorType::kAlias, IDR_AURA_CURSOR_ALIAS, {8, 6}, {15, 11}}, + {mojom::CursorType::kCell, IDR_AURA_CURSOR_CELL, {11, 11}, {24, 23}}, + {mojom::CursorType::kContextMenu, + IDR_AURA_CURSOR_CONTEXT_MENU, + {4, 4}, + {8, 9}}, + {mojom::CursorType::kCross, IDR_AURA_CURSOR_CROSSHAIR, {12, 12}, {24, 24}}, + {mojom::CursorType::kHelp, IDR_AURA_CURSOR_HELP, {4, 4}, {8, 9}}, + {mojom::CursorType::kVerticalText, + IDR_AURA_CURSOR_XTERM_HORIZ, + {12, 11}, + {26, 23}}, + {mojom::CursorType::kZoomIn, IDR_AURA_CURSOR_ZOOM_IN, {10, 10}, {20, 20}}, + {mojom::CursorType::kZoomOut, IDR_AURA_CURSOR_ZOOM_OUT, {10, 10}, {20, 20}}, + {mojom::CursorType::kRowResize, + IDR_AURA_CURSOR_ROW_RESIZE, + {11, 12}, + {23, 23}}, + {mojom::CursorType::kColumnResize, + IDR_AURA_CURSOR_COL_RESIZE, + {12, 11}, + {25, 23}}, + {mojom::CursorType::kEastWestNoResize, + IDR_AURA_CURSOR_EAST_WEST_NO_RESIZE, + {12, 11}, + {25, 23}}, + {mojom::CursorType::kEastWestResize, + IDR_AURA_CURSOR_EAST_WEST_RESIZE, + {12, 11}, + {25, 23}}, + {mojom::CursorType::kNorthSouthNoResize, + IDR_AURA_CURSOR_NORTH_SOUTH_NO_RESIZE, + {11, 12}, + {23, 23}}, + {mojom::CursorType::kNorthSouthResize, + IDR_AURA_CURSOR_NORTH_SOUTH_RESIZE, + {11, 12}, + {23, 23}}, + {mojom::CursorType::kNorthEastSouthWestNoResize, + IDR_AURA_CURSOR_NORTH_EAST_SOUTH_WEST_NO_RESIZE, + {12, 11}, + {25, 23}}, + {mojom::CursorType::kNorthEastSouthWestResize, + IDR_AURA_CURSOR_NORTH_EAST_SOUTH_WEST_RESIZE, + {12, 11}, + {25, 23}}, + {mojom::CursorType::kNorthWestSouthEastNoResize, + IDR_AURA_CURSOR_NORTH_WEST_SOUTH_EAST_NO_RESIZE, + {11, 11}, + {24, 23}}, + {mojom::CursorType::kNorthWestSouthEastResize, + IDR_AURA_CURSOR_NORTH_WEST_SOUTH_EAST_RESIZE, + {11, 11}, + {24, 23}}, + {mojom::CursorType::kGrab, IDR_AURA_CURSOR_GRAB, {8, 5}, {16, 10}}, + {mojom::CursorType::kGrabbing, IDR_AURA_CURSOR_GRABBING, {9, 9}, {18, 18}}, + {mojom::CursorType::kWait, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, + {mojom::CursorType::kProgress, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, +}; + +const CursorData kLargeCursors[] = { + // The 2x hotspots should be double of the 1x, even though the cursors are + // shown as same size as 1x (64x64), because in 2x dpi screen, the 1x large + // cursor assets (64x64) are internally enlarged to the double size + // (128x128) + // by ResourceBundleImageSource. + {mojom::CursorType::kNull, IDR_AURA_CURSOR_BIG_PTR, {10, 10}, {20, 20}}, + {mojom::CursorType::kPointer, IDR_AURA_CURSOR_BIG_PTR, {10, 10}, {20, 20}}, + {mojom::CursorType::kNoDrop, + IDR_AURA_CURSOR_BIG_NO_DROP, + {10, 10}, + {20, 20}}, + {mojom::CursorType::kNotAllowed, + IDR_AURA_CURSOR_BIG_NO_DROP, + {10, 10}, + {20, 20}}, + {mojom::CursorType::kCopy, IDR_AURA_CURSOR_BIG_COPY, {21, 11}, {42, 22}}, + {mojom::CursorType::kHand, IDR_AURA_CURSOR_BIG_HAND, {25, 7}, {50, 14}}, + {mojom::CursorType::kMove, IDR_AURA_CURSOR_BIG_MOVE, {32, 31}, {64, 62}}, + {mojom::CursorType::kNorthEastResize, + IDR_AURA_CURSOR_BIG_NORTH_EAST_RESIZE, + {31, 28}, + {62, 56}}, + {mojom::CursorType::kSouthWestResize, + IDR_AURA_CURSOR_BIG_SOUTH_WEST_RESIZE, + {31, 28}, + {62, 56}}, + {mojom::CursorType::kSouthEastResize, + IDR_AURA_CURSOR_BIG_SOUTH_EAST_RESIZE, + {28, 28}, + {56, 56}}, + {mojom::CursorType::kNorthWestResize, + IDR_AURA_CURSOR_BIG_NORTH_WEST_RESIZE, + {28, 28}, + {56, 56}}, + {mojom::CursorType::kNorthResize, + IDR_AURA_CURSOR_BIG_NORTH_RESIZE, + {29, 32}, + {58, 64}}, + {mojom::CursorType::kSouthResize, + IDR_AURA_CURSOR_BIG_SOUTH_RESIZE, + {29, 32}, + {58, 64}}, + {mojom::CursorType::kEastResize, + IDR_AURA_CURSOR_BIG_EAST_RESIZE, + {35, 29}, + {70, 58}}, + {mojom::CursorType::kWestResize, + IDR_AURA_CURSOR_BIG_WEST_RESIZE, + {35, 29}, + {70, 58}}, + {mojom::CursorType::kIBeam, IDR_AURA_CURSOR_BIG_IBEAM, {30, 32}, {60, 64}}, + {mojom::CursorType::kAlias, IDR_AURA_CURSOR_BIG_ALIAS, {19, 11}, {38, 22}}, + {mojom::CursorType::kCell, IDR_AURA_CURSOR_BIG_CELL, {30, 30}, {60, 60}}, + {mojom::CursorType::kContextMenu, + IDR_AURA_CURSOR_BIG_CONTEXT_MENU, + {11, 11}, + {22, 22}}, + {mojom::CursorType::kCross, + IDR_AURA_CURSOR_BIG_CROSSHAIR, + {30, 32}, + {60, 64}}, + {mojom::CursorType::kHelp, IDR_AURA_CURSOR_BIG_HELP, {10, 11}, {20, 22}}, + {mojom::CursorType::kVerticalText, + IDR_AURA_CURSOR_BIG_XTERM_HORIZ, + {32, 30}, + {64, 60}}, + {mojom::CursorType::kZoomIn, + IDR_AURA_CURSOR_BIG_ZOOM_IN, + {25, 26}, + {50, 52}}, + {mojom::CursorType::kZoomOut, + IDR_AURA_CURSOR_BIG_ZOOM_OUT, + {26, 26}, + {52, 52}}, + {mojom::CursorType::kRowResize, + IDR_AURA_CURSOR_BIG_ROW_RESIZE, + {29, 32}, + {58, 64}}, + {mojom::CursorType::kColumnResize, + IDR_AURA_CURSOR_BIG_COL_RESIZE, + {35, 29}, + {70, 58}}, + {mojom::CursorType::kEastWestNoResize, + IDR_AURA_CURSOR_BIG_EAST_WEST_NO_RESIZE, + {35, 29}, + {70, 58}}, + {mojom::CursorType::kEastWestResize, + IDR_AURA_CURSOR_BIG_EAST_WEST_RESIZE, + {35, 29}, + {70, 58}}, + {mojom::CursorType::kNorthSouthNoResize, + IDR_AURA_CURSOR_BIG_NORTH_SOUTH_NO_RESIZE, + {29, 32}, + {58, 64}}, + {mojom::CursorType::kNorthSouthResize, + IDR_AURA_CURSOR_BIG_NORTH_SOUTH_RESIZE, + {29, 32}, + {58, 64}}, + {mojom::CursorType::kNorthEastSouthWestNoResize, + IDR_AURA_CURSOR_BIG_NORTH_EAST_SOUTH_WEST_NO_RESIZE, + {32, 30}, + {64, 60}}, + {mojom::CursorType::kNorthEastSouthWestResize, + IDR_AURA_CURSOR_BIG_NORTH_EAST_SOUTH_WEST_RESIZE, + {32, 30}, + {64, 60}}, + {mojom::CursorType::kNorthWestSouthEastNoResize, + IDR_AURA_CURSOR_BIG_NORTH_WEST_SOUTH_EAST_NO_RESIZE, + {32, 31}, + {64, 62}}, + {mojom::CursorType::kNorthWestSouthEastResize, + IDR_AURA_CURSOR_BIG_NORTH_WEST_SOUTH_EAST_RESIZE, + {32, 31}, + {64, 62}}, + {mojom::CursorType::kGrab, IDR_AURA_CURSOR_BIG_GRAB, {21, 11}, {42, 22}}, + {mojom::CursorType::kGrabbing, + IDR_AURA_CURSOR_BIG_GRABBING, + {20, 12}, + {40, 24}}, + // TODO(https://crbug.com/336867): create IDR_AURA_CURSOR_BIG_THROBBER. +}; + +const CursorSizeData kCursorSizes[] = { + {ui::CursorSize::kNormal, kNormalCursors, std::size(kNormalCursors)}, + {ui::CursorSize::kLarge, kLargeCursors, std::size(kLargeCursors)}, +}; + +const CursorSizeData* GetCursorSizeByType(ui::CursorSize cursor_size) { + for (size_t i = 0; i < std::size(kCursorSizes); ++i) { + if (kCursorSizes[i].id == cursor_size) + return &kCursorSizes[i]; + } + + return NULL; +} + +bool SearchTable(const CursorData* table, + size_t table_length, + mojom::CursorType id, + float scale_factor, + int* resource_id, + gfx::Point* point) { + DCHECK_NE(scale_factor, 0); + + bool resource_2x_available = + ui::ResourceBundle::GetSharedInstance().GetMaxResourceScaleFactor() == + ui::k200Percent; + for (size_t i = 0; i < table_length; ++i) { + if (table[i].id == id) { + *resource_id = table[i].resource_id; + *point = scale_factor == 1.0f || !resource_2x_available + ? gfx::Point(table[i].hot_1x.x, table[i].hot_1x.y) + : gfx::Point(table[i].hot_2x.x, table[i].hot_2x.y); + return true; + } + } + + return false; +} + +} // namespace + +bool GetCursorDataFor(ui::CursorSize cursor_size, + mojom::CursorType id, + float scale_factor, + int* resource_id, + gfx::Point* point) { + const CursorSizeData* cursor_set = GetCursorSizeByType(cursor_size); + if (cursor_set && SearchTable(cursor_set->cursors, cursor_set->length, id, + scale_factor, resource_id, point)) { + return true; + } + + // Falls back to the default cursor set. + cursor_set = GetCursorSizeByType(ui::CursorSize::kNormal); + DCHECK(cursor_set); + return SearchTable(cursor_set->cursors, cursor_set->length, id, scale_factor, + resource_id, point); +} + +SkBitmap GetDefaultBitmap(const ui::Cursor& cursor) { +#if BUILDFLAG(IS_WIN) + ui::Cursor cursor_copy = cursor; + CursorLoader cursor_loader; + cursor_loader.SetPlatformCursor(&cursor_copy); + return IconUtil::CreateSkBitmapFromHICON( + ui::WinCursor::FromPlatformCursor(cursor_copy.platform())->hcursor()); +#else + int resource_id; + gfx::Point hotspot; + if (!GetCursorDataFor(ui::CursorSize::kNormal, cursor.type(), + cursor.image_scale_factor(), &resource_id, &hotspot)) { + return SkBitmap(); + } + return ui::ResourceBundle::GetSharedInstance() + .GetImageSkiaNamed(resource_id) + ->GetRepresentation(cursor.image_scale_factor()) + .GetBitmap(); +#endif +} + +gfx::Point GetDefaultHotspot(const ui::Cursor& cursor) { +#if BUILDFLAG(IS_WIN) + ui::Cursor cursor_copy = cursor; + CursorLoader cursor_loader; + cursor_loader.SetPlatformCursor(&cursor_copy); + return IconUtil::GetHotSpotFromHICON( + ui::WinCursor::FromPlatformCursor(cursor_copy.platform())->hcursor()); +#else + int resource_id; + gfx::Point hotspot; + if (!GetCursorDataFor(ui::CursorSize::kNormal, cursor.type(), + cursor.image_scale_factor(), &resource_id, &hotspot)) { + return gfx::Point(); + } + return hotspot; +#endif +} + +} // namespace wm diff --git a/chromium/ui/wm/core/cursors_aura.h b/chromium/ui/wm/core/cursors_aura.h new file mode 100644 index 00000000000..483dad32e89 --- /dev/null +++ b/chromium/ui/wm/core/cursors_aura.h @@ -0,0 +1,43 @@ +// Copyright (c) 2013 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 UI_WM_CORE_CURSORS_AURA_H_ +#define UI_WM_CORE_CURSORS_AURA_H_ + +#include "base/component_export.h" +#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" + +class SkBitmap; + +namespace gfx { +class Point; +} + +namespace ui { +class Cursor; +enum class CursorSize; +} // namespace ui + +namespace wm { + +// Returns data about |id|, where id is a cursor constant like +// ui::mojom::CursorType::kHelp. The IDR will be placed in |resource_id| and +// the hotspots for the different DPIs will be placed in |hot_1x| and +// |hot_2x|. Returns false if |id| is invalid. +COMPONENT_EXPORT(UI_WM) +bool GetCursorDataFor(ui::CursorSize cursor_size, + ui::mojom::CursorType id, + float scale_factor, + int* resource_id, + gfx::Point* point); + +COMPONENT_EXPORT(UI_WM) +SkBitmap GetDefaultBitmap(const ui::Cursor& cursor); + +COMPONENT_EXPORT(UI_WM) +gfx::Point GetDefaultHotspot(const ui::Cursor& cursor); + +} // namespace wm + +#endif // UI_WM_CORE_CURSORS_AURA_H_ diff --git a/chromium/ui/wm/core/default_activation_client.h b/chromium/ui/wm/core/default_activation_client.h index 2ddeb02adb9..22434e29811 100644 --- a/chromium/ui/wm/core/default_activation_client.h +++ b/chromium/ui/wm/core/default_activation_client.h @@ -7,10 +7,10 @@ #include <vector> +#include "base/component_export.h" #include "base/memory/raw_ptr.h" #include "base/observer_list.h" #include "ui/aura/window_observer.h" -#include "ui/wm/core/wm_core_export.h" #include "ui/wm/public/activation_change_observer.h" #include "ui/wm/public/activation_client.h" @@ -22,8 +22,9 @@ class ActivationChangeObserver; // that just need basic behavior (e.g. activate windows whenever requested, // restack windows at the top when they're activated, etc.). This object deletes // itself when the root window it is associated with is destroyed. -class WM_CORE_EXPORT DefaultActivationClient : public ActivationClient, - public aura::WindowObserver { +class COMPONENT_EXPORT(UI_WM) DefaultActivationClient + : public ActivationClient, + public aura::WindowObserver { public: explicit DefaultActivationClient(aura::Window* root_window); diff --git a/chromium/ui/wm/core/default_screen_position_client.h b/chromium/ui/wm/core/default_screen_position_client.h index 5d643b570ea..a867ff49756 100644 --- a/chromium/ui/wm/core/default_screen_position_client.h +++ b/chromium/ui/wm/core/default_screen_position_client.h @@ -5,15 +5,15 @@ #ifndef UI_WM_CORE_DEFAULT_SCREEN_POSITION_CLIENT_H_ #define UI_WM_CORE_DEFAULT_SCREEN_POSITION_CLIENT_H_ +#include "base/component_export.h" #include "base/memory/raw_ptr.h" #include "ui/aura/client/screen_position_client.h" -#include "ui/wm/core/wm_core_export.h" namespace wm { // Client that always offsets by the toplevel RootWindow of the passed // in child NativeWidgetAura. -class WM_CORE_EXPORT DefaultScreenPositionClient +class COMPONENT_EXPORT(UI_WM) DefaultScreenPositionClient : public aura::client::ScreenPositionClient { public: explicit DefaultScreenPositionClient(aura::Window* root_window); diff --git a/chromium/ui/wm/core/easy_resize_window_targeter.h b/chromium/ui/wm/core/easy_resize_window_targeter.h index 111a0def46e..e21fb2aea1e 100644 --- a/chromium/ui/wm/core/easy_resize_window_targeter.h +++ b/chromium/ui/wm/core/easy_resize_window_targeter.h @@ -5,8 +5,8 @@ #ifndef UI_WM_CORE_EASY_RESIZE_WINDOW_TARGETER_H_ #define UI_WM_CORE_EASY_RESIZE_WINDOW_TARGETER_H_ +#include "base/component_export.h" #include "ui/aura/window_targeter.h" -#include "ui/wm/core/wm_core_export.h" namespace gfx { class Insets; @@ -19,7 +19,8 @@ namespace wm { // windows (top level Widgets that are resizable) to outside their bounds. For // Ash, this correlates to ash::kResizeOutsideBoundsSize. For the interior // resize area, see ash::InstallResizeHandleWindowTargeterForWindow(). -class WM_CORE_EXPORT EasyResizeWindowTargeter : public aura::WindowTargeter { +class COMPONENT_EXPORT(UI_WM) EasyResizeWindowTargeter + : public aura::WindowTargeter { public: // NOTE: the insets must be negative. EasyResizeWindowTargeter(const gfx::Insets& mouse_extend, diff --git a/chromium/ui/wm/core/focus_controller.h b/chromium/ui/wm/core/focus_controller.h index 1caeba49084..8e08c4cdb3e 100644 --- a/chromium/ui/wm/core/focus_controller.h +++ b/chromium/ui/wm/core/focus_controller.h @@ -7,6 +7,7 @@ #include <memory> +#include "base/component_export.h" #include "base/memory/raw_ptr.h" #include "base/observer_list.h" #include "base/scoped_multi_source_observation.h" @@ -15,7 +16,6 @@ #include "ui/aura/client/focus_client.h" #include "ui/aura/window_observer.h" #include "ui/events/event_handler.h" -#include "ui/wm/core/wm_core_export.h" #include "ui/wm/public/activation_change_observer.h" #include "ui/wm/public/activation_client.h" @@ -41,10 +41,11 @@ class FocusRules; // . ActivationReason::WINDOW_DISPOSITION_CHANGED: Window disposition changes // (implemented here in aura::WindowObserver). (The FocusController registers // itself as an observer of the active and focused windows). -class WM_CORE_EXPORT FocusController : public ActivationClient, - public aura::client::FocusClient, - public ui::EventHandler, - public aura::WindowObserver { +class COMPONENT_EXPORT(UI_WM) FocusController : public ActivationClient, + public aura::client::FocusClient + , + public ui::EventHandler, + public aura::WindowObserver { public: // |rules| cannot be NULL. explicit FocusController(FocusRules* rules); diff --git a/chromium/ui/wm/core/focus_controller_unittest.cc b/chromium/ui/wm/core/focus_controller_unittest.cc index f6928187e3b..1bece4960ab 100644 --- a/chromium/ui/wm/core/focus_controller_unittest.cc +++ b/chromium/ui/wm/core/focus_controller_unittest.cc @@ -281,7 +281,8 @@ class DeleteOnActivationChangeObserver : public ActivationChangeObserver, private: raw_ptr<aura::Window> root_; - raw_ptr<aura::Window> window_; + // TODO(crbug.com/1298696): Breaks wm_unittests. + raw_ptr<aura::Window, DegradeToNoOpWhenMTE> window_; const bool delete_on_activating_; const bool delete_window_losing_active_; bool did_delete_; @@ -322,7 +323,8 @@ class DeleteOnLoseFocusChangeObserver private: raw_ptr<aura::Window> root_; - raw_ptr<aura::Window> window_; + // TODO(crbug.com/1298696): Breaks wm_unittests. + raw_ptr<aura::Window, DegradeToNoOpWhenMTE> window_; bool did_delete_; }; @@ -370,7 +372,8 @@ class ScopedTargetFocusNotificationObserver : public FocusNotificationObserver { } private: - raw_ptr<aura::Window> target_; + // TODO(crbug.com/1298696): Breaks wm_unittests. + raw_ptr<aura::Window, DegradeToNoOpWhenMTE> target_; aura::WindowTracker tracker_; }; diff --git a/chromium/ui/wm/core/focus_rules.h b/chromium/ui/wm/core/focus_rules.h index 44644c9c9a6..a30a70e9f5f 100644 --- a/chromium/ui/wm/core/focus_rules.h +++ b/chromium/ui/wm/core/focus_rules.h @@ -5,7 +5,7 @@ #ifndef UI_WM_CORE_FOCUS_RULES_H_ #define UI_WM_CORE_FOCUS_RULES_H_ -#include "ui/wm/core/wm_core_export.h" +#include "base/component_export.h" namespace aura { class Window; @@ -19,7 +19,7 @@ namespace wm { // Implemented by an object that establishes the rules about what can be // focused or activated. -class WM_CORE_EXPORT FocusRules { +class COMPONENT_EXPORT(UI_WM) FocusRules { public: virtual ~FocusRules() {} diff --git a/chromium/ui/wm/core/ime_util_chromeos.h b/chromium/ui/wm/core/ime_util_chromeos.h index eb5faae96f7..d139661ccaa 100644 --- a/chromium/ui/wm/core/ime_util_chromeos.h +++ b/chromium/ui/wm/core/ime_util_chromeos.h @@ -5,8 +5,8 @@ #ifndef UI_WM_CORE_IME_UTIL_CHROMEOS_H_ #define UI_WM_CORE_IME_UTIL_CHROMEOS_H_ +#include "base/component_export.h" #include "ui/aura/window.h" -#include "ui/wm/core/wm_core_export.h" namespace gfx { class Rect; @@ -16,16 +16,18 @@ namespace wm { // A property key to store the restore bounds for a window when moved by the // virtual keyboard. -WM_CORE_EXPORT extern const aura::WindowProperty<gfx::Rect*>* const +COMPONENT_EXPORT(UI_WM) +extern const aura::WindowProperty<gfx::Rect*>* const kVirtualKeyboardRestoreBoundsKey; // Moves |window| to ensure it does not intersect with |rect_in_screen|. -WM_CORE_EXPORT void EnsureWindowNotInRect(aura::Window* window, - const gfx::Rect& rect_in_screen); +COMPONENT_EXPORT(UI_WM) +void EnsureWindowNotInRect(aura::Window* window, + const gfx::Rect& rect_in_screen); // Restores the window bounds when input client loses the focus on the window. -WM_CORE_EXPORT void RestoreWindowBoundsOnClientFocusLost( - aura::Window* top_level_window); +COMPONENT_EXPORT(UI_WM) +void RestoreWindowBoundsOnClientFocusLost(aura::Window* top_level_window); } // namespace wm diff --git a/chromium/ui/wm/core/native_cursor_manager.h b/chromium/ui/wm/core/native_cursor_manager.h index ae427fe95cc..28aa6373731 100644 --- a/chromium/ui/wm/core/native_cursor_manager.h +++ b/chromium/ui/wm/core/native_cursor_manager.h @@ -5,8 +5,8 @@ #ifndef UI_WM_CORE_NATIVE_CURSOR_MANAGER_H_ #define UI_WM_CORE_NATIVE_CURSOR_MANAGER_H_ +#include "base/component_export.h" #include "ui/wm/core/native_cursor_manager_delegate.h" -#include "ui/wm/core/wm_core_export.h" namespace display { class Display; @@ -22,7 +22,7 @@ namespace wm { // requested changes to cursor state. When requested, implementer should tell // the CursorManager of any actual state changes performed through the // delegate. -class WM_CORE_EXPORT NativeCursorManager { +class COMPONENT_EXPORT(UI_WM) NativeCursorManager { public: virtual ~NativeCursorManager() {} diff --git a/chromium/ui/wm/core/native_cursor_manager_delegate.h b/chromium/ui/wm/core/native_cursor_manager_delegate.h index d1a5540fde3..4dfea286d29 100644 --- a/chromium/ui/wm/core/native_cursor_manager_delegate.h +++ b/chromium/ui/wm/core/native_cursor_manager_delegate.h @@ -5,8 +5,8 @@ #ifndef UI_WM_CORE_NATIVE_CURSOR_MANAGER_DELEGATE_H_ #define UI_WM_CORE_NATIVE_CURSOR_MANAGER_DELEGATE_H_ +#include "base/component_export.h" #include "ui/gfx/native_widget_types.h" -#include "ui/wm/core/wm_core_export.h" namespace ui { enum class CursorSize; @@ -17,7 +17,7 @@ namespace wm { // The non-public interface that CursorManager exposes to its users. This // gives accessors to all the current state, and mutators to all the current // state. -class WM_CORE_EXPORT NativeCursorManagerDelegate { +class COMPONENT_EXPORT(UI_WM) NativeCursorManagerDelegate { public: virtual ~NativeCursorManagerDelegate() {} diff --git a/chromium/ui/wm/core/shadow_controller.h b/chromium/ui/wm/core/shadow_controller.h index 7584634aff9..49cb4b3b9bb 100644 --- a/chromium/ui/wm/core/shadow_controller.h +++ b/chromium/ui/wm/core/shadow_controller.h @@ -7,9 +7,9 @@ #include <map> +#include "base/component_export.h" #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" -#include "ui/wm/core/wm_core_export.h" #include "ui/wm/public/activation_change_observer.h" namespace aura { @@ -30,7 +30,8 @@ class ShadowControllerDelegate; // shadows as needed. ShadowController itself is light weight and per // ActivationClient. ShadowController delegates to its implementation class, // which observes all window creation. -class WM_CORE_EXPORT ShadowController : public ActivationChangeObserver { +class COMPONENT_EXPORT(UI_WM) ShadowController + : public ActivationChangeObserver { public: // Returns the shadow for the |window|, or NULL if no shadow exists. static ui::Shadow* GetShadowForWindow(aura::Window* window); diff --git a/chromium/ui/wm/core/shadow_controller_delegate.h b/chromium/ui/wm/core/shadow_controller_delegate.h index e0ce6e236fe..b64eb1bb087 100644 --- a/chromium/ui/wm/core/shadow_controller_delegate.h +++ b/chromium/ui/wm/core/shadow_controller_delegate.h @@ -5,7 +5,7 @@ #ifndef UI_WM_CORE_SHADOW_CONTROLLER_DELEGATE_H_ #define UI_WM_CORE_SHADOW_CONTROLLER_DELEGATE_H_ -#include "ui/wm/core/wm_core_export.h" +#include "base/component_export.h" namespace aura { class Window; @@ -15,7 +15,7 @@ namespace wm { // ShadowControllerDelegate allows a user to modify a shadow on certain windows // differently from the normal use case. -class WM_CORE_EXPORT ShadowControllerDelegate { +class COMPONENT_EXPORT(UI_WM) ShadowControllerDelegate { public: ShadowControllerDelegate() = default; virtual ~ShadowControllerDelegate() = default; @@ -27,4 +27,4 @@ class WM_CORE_EXPORT ShadowControllerDelegate { } // namespace wm -#endif // UI_WM_CORE_SHADOW_CONTROLLER_DELEGATE_H_
\ No newline at end of file +#endif // UI_WM_CORE_SHADOW_CONTROLLER_DELEGATE_H_ diff --git a/chromium/ui/wm/core/shadow_types.h b/chromium/ui/wm/core/shadow_types.h index d57dda9ab66..7ec0e3b0646 100644 --- a/chromium/ui/wm/core/shadow_types.h +++ b/chromium/ui/wm/core/shadow_types.h @@ -5,9 +5,9 @@ #ifndef UI_WM_CORE_SHADOW_TYPES_H_ #define UI_WM_CORE_SHADOW_TYPES_H_ +#include "base/component_export.h" #include "build/chromeos_buildflags.h" #include "ui/aura/window.h" -#include "ui/wm/core/wm_core_export.h" namespace wm { @@ -31,20 +31,22 @@ constexpr int kShadowElevationInactiveWindow = 8; #endif constexpr int kShadowElevationActiveWindow = 24; -WM_CORE_EXPORT void SetShadowElevation(aura::Window* window, int elevation); +COMPONENT_EXPORT(UI_WM) +void SetShadowElevation(aura::Window* window, int elevation); // Returns the default shadow elevaltion value for |window|. -WM_CORE_EXPORT int GetDefaultShadowElevationForWindow( - const aura::Window* window); +COMPONENT_EXPORT(UI_WM) +int GetDefaultShadowElevationForWindow(const aura::Window* window); // Returns the shadow elevation property value for |window|, converting // |kShadowElevationDefault| to the appropriate value. -WM_CORE_EXPORT int GetShadowElevationConvertDefault(const aura::Window* window); +COMPONENT_EXPORT(UI_WM) +int GetShadowElevationConvertDefault(const aura::Window* window); // A property key describing the drop shadow that should be displayed under the // window. A null value is interpreted as using the default. -WM_CORE_EXPORT extern const aura::WindowProperty<int>* const - kShadowElevationKey; +COMPONENT_EXPORT(UI_WM) +extern const aura::WindowProperty<int>* const kShadowElevationKey; } // namespace wm diff --git a/chromium/ui/wm/core/transient_window_controller.h b/chromium/ui/wm/core/transient_window_controller.h index 4ed44e99009..99be3354e69 100644 --- a/chromium/ui/wm/core/transient_window_controller.h +++ b/chromium/ui/wm/core/transient_window_controller.h @@ -5,9 +5,9 @@ #ifndef UI_WM_CORE_TRANSIENT_WINDOW_CONTROLLER_H_ #define UI_WM_CORE_TRANSIENT_WINDOW_CONTROLLER_H_ +#include "base/component_export.h" #include "base/observer_list.h" #include "ui/aura/client/transient_window_client.h" -#include "ui/wm/core/wm_core_export.h" namespace wm { @@ -15,7 +15,7 @@ class TransientWindowManager; // TransientWindowClient implementation. Uses TransientWindowManager to handle // tracking transient per window. -class WM_CORE_EXPORT TransientWindowController +class COMPONENT_EXPORT(UI_WM) TransientWindowController : public aura::client::TransientWindowClient { public: TransientWindowController(); diff --git a/chromium/ui/wm/core/transient_window_manager.h b/chromium/ui/wm/core/transient_window_manager.h index 5089b9dec55..898d67d184a 100644 --- a/chromium/ui/wm/core/transient_window_manager.h +++ b/chromium/ui/wm/core/transient_window_manager.h @@ -7,10 +7,10 @@ #include <vector> +#include "base/component_export.h" #include "base/memory/raw_ptr.h" #include "base/observer_list.h" #include "ui/aura/window_observer.h" -#include "ui/wm/core/wm_core_export.h" namespace wm { @@ -27,7 +27,8 @@ class TransientWindowObserver; // . If a transient parent is hidden, it hides all transient children. // For show operation, please refer to |set_parent_controls_visibility(bool)|. // Transient windows are typically used for popups and menus. -class WM_CORE_EXPORT TransientWindowManager : public aura::WindowObserver { +class COMPONENT_EXPORT(UI_WM) TransientWindowManager + : public aura::WindowObserver { public: using Windows = std::vector<aura::Window*>; diff --git a/chromium/ui/wm/core/transient_window_observer.h b/chromium/ui/wm/core/transient_window_observer.h index d935a808dc8..73a14776b6c 100644 --- a/chromium/ui/wm/core/transient_window_observer.h +++ b/chromium/ui/wm/core/transient_window_observer.h @@ -5,7 +5,7 @@ #ifndef UI_WM_CORE_TRANSIENT_WINDOW_OBSERVER_H_ #define UI_WM_CORE_TRANSIENT_WINDOW_OBSERVER_H_ -#include "ui/wm/core/wm_core_export.h" +#include "base/component_export.h" namespace aura { class Window; @@ -13,7 +13,7 @@ class Window; namespace wm { -class WM_CORE_EXPORT TransientWindowObserver { +class COMPONENT_EXPORT(UI_WM) TransientWindowObserver { public: // Called when a transient child is added to |window|. virtual void OnTransientChildAdded(aura::Window* window, diff --git a/chromium/ui/wm/core/transient_window_stacking_client.h b/chromium/ui/wm/core/transient_window_stacking_client.h index df788fb237f..c4114cb08a5 100644 --- a/chromium/ui/wm/core/transient_window_stacking_client.h +++ b/chromium/ui/wm/core/transient_window_stacking_client.h @@ -5,14 +5,14 @@ #ifndef UI_WM_CORE_TRANSIENT_WINDOW_STACKING_CLIENT_H_ #define UI_WM_CORE_TRANSIENT_WINDOW_STACKING_CLIENT_H_ +#include "base/component_export.h" #include "ui/aura/client/window_stacking_client.h" -#include "ui/wm/core/wm_core_export.h" namespace wm { class TransientWindowManager; -class WM_CORE_EXPORT TransientWindowStackingClient +class COMPONENT_EXPORT(UI_WM) TransientWindowStackingClient : public aura::client::WindowStackingClient { public: TransientWindowStackingClient(); diff --git a/chromium/ui/wm/core/visibility_controller.h b/chromium/ui/wm/core/visibility_controller.h index 96efbf7482b..ec907849c29 100644 --- a/chromium/ui/wm/core/visibility_controller.h +++ b/chromium/ui/wm/core/visibility_controller.h @@ -5,13 +5,13 @@ #ifndef UI_WM_CORE_VISIBILITY_CONTROLLER_H_ #define UI_WM_CORE_VISIBILITY_CONTROLLER_H_ +#include "base/component_export.h" #include "base/memory/raw_ptr.h" #include "ui/aura/client/visibility_client.h" -#include "ui/wm/core/wm_core_export.h" namespace wm { -class WM_CORE_EXPORT VisibilityController +class COMPONENT_EXPORT(UI_WM) VisibilityController : public aura::client::VisibilityClient { public: VisibilityController(); @@ -47,7 +47,7 @@ class WM_CORE_EXPORT VisibilityController // // previous state. // } // -class WM_CORE_EXPORT SuspendChildWindowVisibilityAnimations { +class COMPONENT_EXPORT(UI_WM) SuspendChildWindowVisibilityAnimations { public: // Suspend visibility animations of child windows. explicit SuspendChildWindowVisibilityAnimations(aura::Window* window); @@ -74,13 +74,14 @@ class WM_CORE_EXPORT SuspendChildWindowVisibilityAnimations { // whose animation is already enabled either by this function, or // via SetChildWindowVisibilityChangesAnimatedbelow below is allowed and // the animation stays enabled. -void WM_CORE_EXPORT SetWindowVisibilityChangesAnimated(aura::Window* window); +COMPONENT_EXPORT(UI_WM) +void SetWindowVisibilityChangesAnimated(aura::Window* window); // Enable visibility change animation for all children of the |window|. // Typically applied to a container whose child windows should be animated // when their visibility changes. -void WM_CORE_EXPORT -SetChildWindowVisibilityChangesAnimated(aura::Window* window); +COMPONENT_EXPORT(UI_WM) +void SetChildWindowVisibilityChangesAnimated(aura::Window* window); } // namespace wm diff --git a/chromium/ui/wm/core/window_animations.cc b/chromium/ui/wm/core/window_animations.cc index 93d514c80cd..203cfea1224 100644 --- a/chromium/ui/wm/core/window_animations.cc +++ b/chromium/ui/wm/core/window_animations.cc @@ -123,7 +123,6 @@ class HidingWindowAnimationObserverBase : public aura::WindowObserver { AnimationHost* animation_host = GetAnimationHost(window_); if (animation_host) animation_host->OnWindowHidingAnimationCompleted(); - window_->RemoveObserver(this); } delete this; } diff --git a/chromium/ui/wm/core/window_animations.h b/chromium/ui/wm/core/window_animations.h index 7580e2a2c58..436abd40dee 100644 --- a/chromium/ui/wm/core/window_animations.h +++ b/chromium/ui/wm/core/window_animations.h @@ -5,10 +5,10 @@ #ifndef UI_WM_CORE_WINDOW_ANIMATIONS_H_ #define UI_WM_CORE_WINDOW_ANIMATIONS_H_ +#include "base/component_export.h" #include "base/memory/raw_ptr.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/wm/core/window_properties.h" -#include "ui/wm/core/wm_core_export.h" namespace aura { class Window; @@ -41,35 +41,39 @@ enum WindowAnimationType { // These two methods use int for type rather than WindowVisibilityAnimationType // since downstream libraries can extend the set of animations. -WM_CORE_EXPORT void SetWindowVisibilityAnimationType(aura::Window* window, - int type); -WM_CORE_EXPORT int GetWindowVisibilityAnimationType(aura::Window* window); +COMPONENT_EXPORT(UI_WM) +void SetWindowVisibilityAnimationType(aura::Window* window, int type); +COMPONENT_EXPORT(UI_WM) +int GetWindowVisibilityAnimationType(aura::Window* window); -WM_CORE_EXPORT void SetWindowVisibilityAnimationTransition( +COMPONENT_EXPORT(UI_WM) +void SetWindowVisibilityAnimationTransition( aura::Window* window, WindowVisibilityAnimationTransition transition); -WM_CORE_EXPORT bool HasWindowVisibilityAnimationTransition( +COMPONENT_EXPORT(UI_WM) +bool HasWindowVisibilityAnimationTransition( aura::Window* window, WindowVisibilityAnimationTransition transition); -WM_CORE_EXPORT void SetWindowVisibilityAnimationDuration( - aura::Window* window, - const base::TimeDelta& duration); +COMPONENT_EXPORT(UI_WM) +void SetWindowVisibilityAnimationDuration(aura::Window* window, + const base::TimeDelta& duration); -WM_CORE_EXPORT base::TimeDelta GetWindowVisibilityAnimationDuration( +COMPONENT_EXPORT(UI_WM) +base::TimeDelta GetWindowVisibilityAnimationDuration( const aura::Window& window); -WM_CORE_EXPORT void SetWindowVisibilityAnimationVerticalPosition( - aura::Window* window, - float position); +COMPONENT_EXPORT(UI_WM) +void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window, + float position); class ImplicitHidingWindowAnimationObserver; // A wrapper of ui::ScopedLayerAnimationSettings for implicit hiding animations. // Use this to ensure that the hiding animation is visible even after // the window is deleted or deactivated, instead of using // ui::ScopedLayerAnimationSettings directly. -class WM_CORE_EXPORT ScopedHidingAnimationSettings { +class COMPONENT_EXPORT(UI_WM) ScopedHidingAnimationSettings { public: explicit ScopedHidingAnimationSettings(aura::Window* window); @@ -90,15 +94,15 @@ class WM_CORE_EXPORT ScopedHidingAnimationSettings { }; // Returns false if the |window| didn't animate. -WM_CORE_EXPORT bool AnimateOnChildWindowVisibilityChanged(aura::Window* window, - bool visible); -WM_CORE_EXPORT bool AnimateWindow(aura::Window* window, - WindowAnimationType type); +COMPONENT_EXPORT(UI_WM) +bool AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible); +COMPONENT_EXPORT(UI_WM) +bool AnimateWindow(aura::Window* window, WindowAnimationType type); // Returns true if window animations are disabled for |window|. Window // animations are enabled by default. If |window| is nullptr, this just checks // if the global flag disabling window animations is present. -WM_CORE_EXPORT bool WindowAnimationsDisabled(aura::Window* window); +COMPONENT_EXPORT(UI_WM) bool WindowAnimationsDisabled(aura::Window* window); } // namespace wm diff --git a/chromium/ui/wm/core/window_modality_controller.h b/chromium/ui/wm/core/window_modality_controller.h index 2d1c7240edc..437b954f4c6 100644 --- a/chromium/ui/wm/core/window_modality_controller.h +++ b/chromium/ui/wm/core/window_modality_controller.h @@ -7,12 +7,12 @@ #include <vector> +#include "base/component_export.h" #include "base/memory/raw_ptr.h" #include "base/strings/string_piece.h" #include "ui/aura/env_observer.h" #include "ui/aura/window_observer.h" #include "ui/events/event_handler.h" -#include "ui/wm/core/wm_core_export.h" namespace aura { class Env; @@ -26,20 +26,22 @@ class LocatedEvent; namespace wm { // Sets the modal parent for the child. -WM_CORE_EXPORT void SetModalParent(aura::Window* child, aura::Window* parent); +COMPONENT_EXPORT(UI_WM) +void SetModalParent(aura::Window* child, aura::Window* parent); // Returns the modal transient child of |window|, or NULL if |window| does not // have any modal transient children. -WM_CORE_EXPORT aura::Window* GetModalTransient(aura::Window* window); -WM_CORE_EXPORT const aura::Window* GetModalTransient( - const aura::Window* window); +COMPONENT_EXPORT(UI_WM) aura::Window* GetModalTransient(aura::Window* window); +COMPONENT_EXPORT(UI_WM) +const aura::Window* GetModalTransient(const aura::Window* window); // WindowModalityController is an event filter that consumes events sent to // windows that are the transient parents of window-modal windows. This filter // must be added to the CompoundEventFilter so that activation works properly. -class WM_CORE_EXPORT WindowModalityController : public ui::EventHandler, - public aura::EnvObserver, - public aura::WindowObserver { +class COMPONENT_EXPORT(UI_WM) WindowModalityController + : public ui::EventHandler, + public aura::EnvObserver, + public aura::WindowObserver { public: explicit WindowModalityController(ui::EventTarget* event_target, aura::Env* env = nullptr); diff --git a/chromium/ui/wm/core/window_properties.cc b/chromium/ui/wm/core/window_properties.cc index 506dd0c0cc4..73896945bec 100644 --- a/chromium/ui/wm/core/window_properties.cc +++ b/chromium/ui/wm/core/window_properties.cc @@ -6,10 +6,10 @@ #include "ui/wm/core/window_animations.h" -DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(WM_CORE_EXPORT, +DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(COMPONENT_EXPORT(UI_WM), wm::WindowVisibilityAnimationTransition) -DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(WM_CORE_EXPORT, float) +DEFINE_EXPORTED_UI_CLASS_PROPERTY_TYPE(COMPONENT_EXPORT(UI_WM), float) namespace wm { diff --git a/chromium/ui/wm/core/window_properties.h b/chromium/ui/wm/core/window_properties.h index ae131fc3ae9..62caea0f724 100644 --- a/chromium/ui/wm/core/window_properties.h +++ b/chromium/ui/wm/core/window_properties.h @@ -5,9 +5,9 @@ #ifndef UI_WM_CORE_WINDOW_PROPERTIES_H_ #define UI_WM_CORE_WINDOW_PROPERTIES_H_ +#include "base/component_export.h" #include "base/time/time.h" #include "ui/base/class_property.h" -#include "ui/wm/core/wm_core_export.h" namespace wm { @@ -24,28 +24,30 @@ enum WindowVisibilityAnimationTransition { // Property to tell if the container uses screen coordinates for the child // windows. -WM_CORE_EXPORT extern const ui::ClassProperty<bool>* const - kUsesScreenCoordinatesKey; +COMPONENT_EXPORT(UI_WM) +extern const ui::ClassProperty<bool>* const kUsesScreenCoordinatesKey; -WM_CORE_EXPORT extern const ui::ClassProperty<base::TimeDelta>* const +COMPONENT_EXPORT(UI_WM) +extern const ui::ClassProperty<base::TimeDelta>* const kWindowVisibilityAnimationDurationKey; -WM_CORE_EXPORT extern const ui::ClassProperty< - WindowVisibilityAnimationTransition>* const +COMPONENT_EXPORT(UI_WM) +extern const ui::ClassProperty<WindowVisibilityAnimationTransition>* const kWindowVisibilityAnimationTransitionKey; -WM_CORE_EXPORT extern const ui::ClassProperty<int>* const - kWindowVisibilityAnimationTypeKey; +COMPONENT_EXPORT(UI_WM) +extern const ui::ClassProperty<int>* const kWindowVisibilityAnimationTypeKey; // Used if the animation-type is WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL. -WM_CORE_EXPORT extern const ui::ClassProperty<float>* const +COMPONENT_EXPORT(UI_WM) +extern const ui::ClassProperty<float>* const kWindowVisibilityAnimationVerticalPositionKey; } // namespace wm // These need to be declared here for jumbo builds. -DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(WM_CORE_EXPORT, +DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(COMPONENT_EXPORT(UI_WM), wm::WindowVisibilityAnimationTransition) -DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(WM_CORE_EXPORT, float) +DECLARE_EXPORTED_UI_CLASS_PROPERTY_TYPE(COMPONENT_EXPORT(UI_WM), float) #endif // UI_WM_CORE_WINDOW_PROPERTIES_H_ diff --git a/chromium/ui/wm/core/window_util.cc b/chromium/ui/wm/core/window_util.cc index b3899607628..939d4579f91 100644 --- a/chromium/ui/wm/core/window_util.cc +++ b/chromium/ui/wm/core/window_util.cc @@ -119,8 +119,10 @@ void SetWindowState(aura::Window* window, ui::WindowShowState state) { } void Restore(aura::Window* window) { + window->SetProperty(aura::client::kIsRestoringKey, true); window->SetProperty(aura::client::kShowStateKey, window->GetProperty(aura::client::kRestoreShowStateKey)); + window->ClearProperty(aura::client::kIsRestoringKey); } void Unminimize(aura::Window* window) { diff --git a/chromium/ui/wm/core/window_util.h b/chromium/ui/wm/core/window_util.h index 33b0b964489..c33a30c47db 100644 --- a/chromium/ui/wm/core/window_util.h +++ b/chromium/ui/wm/core/window_util.h @@ -10,8 +10,8 @@ #include <vector> #include "base/callback_forward.h" +#include "base/component_export.h" #include "ui/base/ui_base_types.h" -#include "ui/wm/core/wm_core_export.h" namespace aura { class Window; @@ -25,41 +25,43 @@ class LayerTreeOwner; namespace wm { -WM_CORE_EXPORT void ActivateWindow(aura::Window* window); -WM_CORE_EXPORT void DeactivateWindow(aura::Window* window); -WM_CORE_EXPORT bool IsActiveWindow(const aura::Window* window); -WM_CORE_EXPORT bool CanActivateWindow(const aura::Window* window); -WM_CORE_EXPORT void SetWindowFullscreen(aura::Window* window, bool fullscreen); +COMPONENT_EXPORT(UI_WM) void ActivateWindow(aura::Window* window); +COMPONENT_EXPORT(UI_WM) void DeactivateWindow(aura::Window* window); +COMPONENT_EXPORT(UI_WM) bool IsActiveWindow(const aura::Window* window); +COMPONENT_EXPORT(UI_WM) bool CanActivateWindow(const aura::Window* window); +COMPONENT_EXPORT(UI_WM) +void SetWindowFullscreen(aura::Window* window, bool fullscreen); // Returns true if |window|'s show state is |state|. -WM_CORE_EXPORT bool WindowStateIs(const aura::Window* window, - ui::WindowShowState state); +COMPONENT_EXPORT(UI_WM) +bool WindowStateIs(const aura::Window* window, ui::WindowShowState state); // Sets the window state to |state|. -WM_CORE_EXPORT void SetWindowState(aura::Window* window, - ui::WindowShowState state); +COMPONENT_EXPORT(UI_WM) +void SetWindowState(aura::Window* window, ui::WindowShowState state); // Restores the window state from the current state to its previous applicable // state. As an example, if the current state is minimized, Restore() will // change the window's sate to its applicable pre-minimized state, which is the // same as calling Unminimize() function. -WM_CORE_EXPORT void Restore(aura::Window* window); +COMPONENT_EXPORT(UI_WM) void Restore(aura::Window* window); // Changes a window's state to its pre-minimized state. -WM_CORE_EXPORT void Unminimize(aura::Window* window); +COMPONENT_EXPORT(UI_WM) void Unminimize(aura::Window* window); // Retrieves the activatable window for |window|. If |window| is activatable, // this will just return it, otherwise it will climb the parent/transient parent // chain looking for a window that is activatable, per the ActivationClient. // If you're looking for a function to get the activatable "top level" window, // this is probably the function you're looking for. -WM_CORE_EXPORT aura::Window* GetActivatableWindow(aura::Window* window); +COMPONENT_EXPORT(UI_WM) +aura::Window* GetActivatableWindow(aura::Window* window); // Retrieves the toplevel window for |window|. The ActivationClient makes this // determination. -WM_CORE_EXPORT aura::Window* GetToplevelWindow(aura::Window* window); -WM_CORE_EXPORT const aura::Window* GetToplevelWindow( - const aura::Window* window); +COMPONENT_EXPORT(UI_WM) aura::Window* GetToplevelWindow(aura::Window* window); +COMPONENT_EXPORT(UI_WM) +const aura::Window* GetToplevelWindow(const aura::Window* window); // Returns the existing Layer for |root| (and all its descendants) and creates // a new layer for |root| and all its descendants. This is intended for @@ -67,8 +69,8 @@ WM_CORE_EXPORT const aura::Window* GetToplevelWindow( // // As a result of this |root| has freshly created layers, meaning the layers // have not yet been painted to. -WM_CORE_EXPORT std::unique_ptr<ui::LayerTreeOwner> RecreateLayers( - ui::LayerOwner* root); +COMPONENT_EXPORT(UI_WM) +std::unique_ptr<ui::LayerTreeOwner> RecreateLayers(ui::LayerOwner* root); using MapLayerFunc = base::RepeatingCallback<std::unique_ptr<ui::Layer>(ui::LayerOwner*)>; @@ -77,38 +79,42 @@ using MapLayerFunc = // layer tree. The recursion stops at the level when |map_func| returns nullptr // on the owner's layer. MapLayers might return nullptr when |map_func| returns // nullptr on the root layer's owner. -WM_CORE_EXPORT std::unique_ptr<ui::LayerTreeOwner> RecreateLayersWithClosure( +COMPONENT_EXPORT(UI_WM) +std::unique_ptr<ui::LayerTreeOwner> RecreateLayersWithClosure( ui::LayerOwner* root, const MapLayerFunc& map_func); // Returns a layer tree that mirrors |root|. Used for live window previews. If // |sync_bounds| is true, the bounds of all mirror layers except the root are // synchronized. See |sync_bounds_with_source_| in ui::Layer. -WM_CORE_EXPORT std::unique_ptr<ui::LayerTreeOwner> MirrorLayers( - ui::LayerOwner* root, - bool sync_bounds); +COMPONENT_EXPORT(UI_WM) +std::unique_ptr<ui::LayerTreeOwner> MirrorLayers(ui::LayerOwner* root, + bool sync_bounds); // Convenience functions that get the TransientWindowManager for the window and // redirect appropriately. These are preferable to calling functions on // TransientWindowManager as they handle the appropriate null checks. -WM_CORE_EXPORT aura::Window* GetTransientParent(aura::Window* window); -WM_CORE_EXPORT const aura::Window* GetTransientParent( +COMPONENT_EXPORT(UI_WM) aura::Window* GetTransientParent(aura::Window* window); +COMPONENT_EXPORT(UI_WM) +const aura::Window* GetTransientParent(const aura::Window* window); +COMPONENT_EXPORT(UI_WM) +const std::vector<aura::Window*>& GetTransientChildren( const aura::Window* window); -WM_CORE_EXPORT const std::vector<aura::Window*>& GetTransientChildren( - const aura::Window* window); -WM_CORE_EXPORT void AddTransientChild(aura::Window* parent, - aura::Window* child); -WM_CORE_EXPORT void RemoveTransientChild(aura::Window* parent, - aura::Window* child); -WM_CORE_EXPORT aura::Window* GetTransientRoot(aura::Window* window); +COMPONENT_EXPORT(UI_WM) +void AddTransientChild(aura::Window* parent, aura::Window* child); +COMPONENT_EXPORT(UI_WM) +void RemoveTransientChild(aura::Window* parent, aura::Window* child); +COMPONENT_EXPORT(UI_WM) aura::Window* GetTransientRoot(aura::Window* window); // Returns true if |window| has |ancestor| as a transient ancestor. A transient // ancestor is found by following the transient parent chain of the window. -WM_CORE_EXPORT bool HasTransientAncestor(const aura::Window* window, - const aura::Window* ancestor); +COMPONENT_EXPORT(UI_WM) +bool HasTransientAncestor(const aura::Window* window, + const aura::Window* ancestor); // Snap the window's layer to physical pixel boundary. -WM_CORE_EXPORT void SnapWindowToPixelBoundary(aura::Window* window); +COMPONENT_EXPORT(UI_WM) void SnapWindowToPixelBoundary(aura::Window* window); + } // namespace wm #endif // UI_WM_CORE_WINDOW_UTIL_H_ diff --git a/chromium/ui/wm/core/wm_core_export.h b/chromium/ui/wm/core/wm_core_export.h deleted file mode 100644 index c033ddc9bab..00000000000 --- a/chromium/ui/wm/core/wm_core_export.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 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 UI_WM_CORE_WM_CORE_EXPORT_H_ -#define UI_WM_CORE_WM_CORE_EXPORT_H_ - -// Defines WM_CORE_EXPORT so that functionality implemented by the WM module -// can be exported to consumers. - -#if defined(COMPONENT_BUILD) -#if defined(WIN32) - -#if defined(WM_CORE_IMPLEMENTATION) -#define WM_CORE_EXPORT __declspec(dllexport) -#else -#define WM_CORE_EXPORT __declspec(dllimport) -#endif // defined(WM_CORE_IMPLEMENTATION) - -#else // defined(WIN32) -#if defined(WM_CORE_IMPLEMENTATION) -#define WM_CORE_EXPORT __attribute__((visibility("default"))) -#else -#define WM_CORE_EXPORT -#endif -#endif - -#else // defined(COMPONENT_BUILD) -#define WM_CORE_EXPORT -#endif - -#endif // UI_WM_CORE_WM_CORE_EXPORT_H_ diff --git a/chromium/ui/wm/core/wm_core_switches.h b/chromium/ui/wm/core/wm_core_switches.h index dd480256eef..3a9ddf430ad 100644 --- a/chromium/ui/wm/core/wm_core_switches.h +++ b/chromium/ui/wm/core/wm_core_switches.h @@ -5,8 +5,8 @@ #ifndef UI_WM_CORE_WM_CORE_SWITCHES_H_ #define UI_WM_CORE_WM_CORE_SWITCHES_H_ +#include "base/component_export.h" #include "build/build_config.h" -#include "ui/wm/core/wm_core_export.h" namespace wm { namespace switches { @@ -16,7 +16,7 @@ namespace switches { // see chromeos::LoginUtil::GetOffTheRecordCommandLine().) // Please keep alphabetized. -WM_CORE_EXPORT extern const char kWindowAnimationsDisabled[]; +COMPONENT_EXPORT(UI_WM) extern const char kWindowAnimationsDisabled[]; } // namespace switches } // namespace wm diff --git a/chromium/ui/wm/core/wm_state.h b/chromium/ui/wm/core/wm_state.h index a0f182a1200..3686b03c98e 100644 --- a/chromium/ui/wm/core/wm_state.h +++ b/chromium/ui/wm/core/wm_state.h @@ -7,7 +7,7 @@ #include <memory> -#include "ui/wm/core/wm_core_export.h" +#include "base/component_export.h" namespace wm { @@ -16,7 +16,7 @@ class TransientWindowController; class TransientWindowStackingClient; // Installs state needed by the window manager. -class WM_CORE_EXPORT WMState { +class COMPONENT_EXPORT(UI_WM) WMState { public: WMState(); diff --git a/chromium/ui/wm/public/BUILD.gn b/chromium/ui/wm/public/BUILD.gn index b4ae9394e3a..16ae5979629 100644 --- a/chromium/ui/wm/public/BUILD.gn +++ b/chromium/ui/wm/public/BUILD.gn @@ -2,6 +2,10 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//build/config/ui.gni") + +assert(use_aura) + component("public") { output_name = "wm_public" |