diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-05-12 15:59:20 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-05-25 06:57:22 +0000 |
commit | f7eaed5286974984ba5f9e3189d8f49d03e99f81 (patch) | |
tree | caed19b2af2024f35449fb0b781d0a25e09d4f8f /chromium/ui/aura | |
parent | 9729c4479fe23554eae6e6dd1f30ff488f470c84 (diff) | |
download | qtwebengine-chromium-f7eaed5286974984ba5f9e3189d8f49d03e99f81.tar.gz |
BASELINE: Update Chromium to 100.0.4896.167
Change-Id: I98cbeb5d7543d966ffe04d8cefded0c493a11333
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/ui/aura')
35 files changed, 271 insertions, 174 deletions
diff --git a/chromium/ui/aura/BUILD.gn b/chromium/ui/aura/BUILD.gn index d3f8da79299..033d8551fed 100644 --- a/chromium/ui/aura/BUILD.gn +++ b/chromium/ui/aura/BUILD.gn @@ -31,6 +31,7 @@ component("aura") { "env_input_state_controller.h", "env_observer.h", "event_injector.h", + "host_frame_rate_throttler.h", "input_state_lookup.h", "layout_manager.h", "null_window_targeter.h", @@ -73,6 +74,7 @@ component("aura") { "env.cc", "env_input_state_controller.cc", "event_injector.cc", + "host_frame_rate_throttler.cc", "input_state_lookup.cc", "layout_manager.cc", "native_window_occlusion_tracker.cc", @@ -343,6 +345,7 @@ test("aura_unittests") { } if (is_fuchsia) { + use_cfv2 = false additional_manifest_fragments = [ "//build/config/fuchsia/test/present_view_capabilities.test-cmx" ] } diff --git a/chromium/ui/aura/client/aura_constants.cc b/chromium/ui/aura/client/aura_constants.cc index 0a51cd79a08..bea5795840b 100644 --- a/chromium/ui/aura/client/aura_constants.cc +++ b/chromium/ui/aura/client/aura_constants.cc @@ -79,6 +79,7 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, kRestoreBoundsKey, nullptr) DEFINE_UI_CLASS_PROPERTY_KEY(ui::WindowShowState, kShowStateKey, ui::SHOW_STATE_DEFAULT) +DEFINE_UI_CLASS_PROPERTY_KEY(bool, kIsRestoringKey, false) DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSkipImeProcessing, false) DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(std::u16string, kTitleKey, nullptr) DEFINE_UI_CLASS_PROPERTY_KEY(int, kTopViewInset, 0) diff --git a/chromium/ui/aura/client/aura_constants.h b/chromium/ui/aura/client/aura_constants.h index b3ed5b0f6e0..932f1685620 100644 --- a/chromium/ui/aura/client/aura_constants.h +++ b/chromium/ui/aura/client/aura_constants.h @@ -160,6 +160,15 @@ AURA_EXPORT extern const WindowProperty<gfx::Rect*>* const kRestoreBoundsKey; AURA_EXPORT extern const WindowProperty<ui::WindowShowState>* const kShowStateKey; +// A property key to indicate if a window is currently being restored. Normally +// restoring a window equals to changing window's state to normal window state. +// This property will be used in ash to decide if we should use window state +// restore stack to decide which window state the window should restore back to, +// and it's not unnecessarily always the normal window state. As an example, +// unminimizing a window will restore the window back to its pre-minimized +// window state. +AURA_EXPORT extern const WindowProperty<bool>* const kIsRestoringKey; + // A property key to store key event dispatch policy. The default value is // false, which means IME receives a key event in PREDISPATCH phace before a // window receives it. If it's true, a window receives a key event before IME. diff --git a/chromium/ui/aura/client/cursor_client.h b/chromium/ui/aura/client/cursor_client.h index 4d7c6361cf2..fc24f0f0799 100644 --- a/chromium/ui/aura/client/cursor_client.h +++ b/chromium/ui/aura/client/cursor_client.h @@ -5,7 +5,6 @@ #ifndef UI_AURA_CLIENT_CURSOR_CLIENT_H_ #define UI_AURA_CLIENT_CURSOR_CLIENT_H_ - #include "ui/aura/aura_export.h" #include "ui/base/cursor/cursor.h" #include "ui/gfx/native_widget_types.h" @@ -14,6 +13,10 @@ namespace display { class Display; } +namespace gfx { +class Size; +} + namespace ui { class KeyEvent; enum class CursorSize; @@ -90,6 +93,9 @@ class AURA_EXPORT CursorClient { // Returns true if the mouse cursor should be hidden on |event|. virtual bool ShouldHideCursorOnKeyEvent(const ui::KeyEvent& event) const = 0; + // Returns the OS cursor size in DIP. + virtual gfx::Size GetSystemCursorSize() const = 0; + protected: virtual ~CursorClient() {} }; diff --git a/chromium/ui/aura/client/cursor_client_observer.h b/chromium/ui/aura/client/cursor_client_observer.h index 27a0ee60dc8..7ee4399266e 100644 --- a/chromium/ui/aura/client/cursor_client_observer.h +++ b/chromium/ui/aura/client/cursor_client_observer.h @@ -12,6 +12,10 @@ namespace display { class Display; } +namespace gfx { +class Size; +} + namespace ui { enum class CursorSize; } @@ -24,6 +28,9 @@ class AURA_EXPORT CursorClientObserver { virtual void OnCursorVisibilityChanged(bool is_visible) {} virtual void OnCursorSizeChanged(ui::CursorSize cursor_size) {} virtual void OnCursorDisplayChanged(const display::Display& display) {} + // System cursor size is the size, in DIP, of the cursor; according + // to OS settings. + virtual void OnSystemCursorSizeChanged(const gfx::Size& system_cursor_size) {} protected: virtual ~CursorClientObserver() {} diff --git a/chromium/ui/aura/client/drag_drop_client_observer.h b/chromium/ui/aura/client/drag_drop_client_observer.h index 1f353d794ae..b55b0cad9f6 100644 --- a/chromium/ui/aura/client/drag_drop_client_observer.h +++ b/chromium/ui/aura/client/drag_drop_client_observer.h @@ -25,8 +25,14 @@ class AURA_EXPORT DragDropClientObserver { // Called when dragging is updated. virtual void OnDragUpdated(const ui::DropTargetEvent& event) {} - // Called when dragging ended. - virtual void OnDragEnded() {} + // Called when dragging completes successfully. + virtual void OnDragCompleted(const ui::DropTargetEvent& event) {} + + // Called when dragging is cancelled. + // + // NOTE: Drag 'n drop cancellations may be processed asynchronously. + // Hence, this hook might be called before the action is actually processed. + virtual void OnDragCancelled() {} #if BUILDFLAG(IS_CHROMEOS_ASH) // Called when the set of currently selected drag operation changes during the diff --git a/chromium/ui/aura/client/drag_drop_delegate.h b/chromium/ui/aura/client/drag_drop_delegate.h index 47b49fdcc92..e19d72d4596 100644 --- a/chromium/ui/aura/client/drag_drop_delegate.h +++ b/chromium/ui/aura/client/drag_drop_delegate.h @@ -39,9 +39,11 @@ struct AURA_EXPORT DragUpdateInfo { // Delegate interface for drag and drop actions on aura::Window. class AURA_EXPORT DragDropDelegate { public: + // Callback emitted by GetDropCallback used to handle deferred drop events. + // Note that it does not contain a location. If implementers need a location, + // they should bind it in GetDropCallback. See crbug.com/1289902. using DropCallback = - base::OnceCallback<void(const ui::DropTargetEvent& event, - std::unique_ptr<ui::OSExchangeData> data, + base::OnceCallback<void(std::unique_ptr<ui::OSExchangeData> data, ui::mojom::DragOperation& output_drag_op)>; // OnDragEntered is invoked when the mouse enters this window during a drag & @@ -73,6 +75,8 @@ class AURA_EXPORT DragDropDelegate { // Invoked during a drag and drop session when the user release the mouse, but // the drop is held because of the DataTransferPolicyController. + // The returned callback may be NullCallback if there's nothing to do and the + // drop event is ignored. virtual DropCallback GetDropCallback(const ui::DropTargetEvent& event) = 0; protected: diff --git a/chromium/ui/aura/cursor/cursors_aura.cc b/chromium/ui/aura/cursor/cursors_aura.cc index f22b71592a2..5510d96e491 100644 --- a/chromium/ui/aura/cursor/cursors_aura.cc +++ b/chromium/ui/aura/cursor/cursors_aura.cc @@ -17,7 +17,7 @@ #include "ui/gfx/image/image_skia.h" #include "ui/resources/grit/ui_resources.h" -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) #include "ui/aura/cursor/cursor_loader.h" #include "ui/base/win/win_cursor.h" #include "ui/gfx/icon_util.h" @@ -164,7 +164,7 @@ const CursorData kLargeCursors[] = { IDR_AURA_CURSOR_BIG_NO_DROP, {10, 10}, {20, 20}}, - {mojom::CursorType::kCopy, IDR_AURA_CURSOR_BIG_COPY, {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, @@ -330,7 +330,7 @@ bool GetCursorDataFor(ui::CursorSize cursor_size, } SkBitmap GetDefaultBitmap(const ui::Cursor& cursor) { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) ui::Cursor cursor_copy = cursor; aura::CursorLoader cursor_loader; cursor_loader.SetPlatformCursor(&cursor_copy); @@ -351,7 +351,7 @@ SkBitmap GetDefaultBitmap(const ui::Cursor& cursor) { } gfx::Point GetDefaultHotspot(const ui::Cursor& cursor) { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) ui::Cursor cursor_copy = cursor; aura::CursorLoader cursor_loader; cursor_loader.SetPlatformCursor(&cursor_copy); diff --git a/chromium/ui/aura/demo/demo_main.cc b/chromium/ui/aura/demo/demo_main.cc index 4b2d29b76a8..9943382a139 100644 --- a/chromium/ui/aura/demo/demo_main.cc +++ b/chromium/ui/aura/demo/demo_main.cc @@ -42,7 +42,7 @@ #include "ui/gl/gl_switches.h" #include "ui/gl/init/gl_factory.h" -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) #include "ui/display/win/dpi.h" #endif @@ -171,7 +171,7 @@ int DemoMain() { #endif gl::init::InitializeGLOneOff(); -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) display::win::SetDefaultDeviceScaleFactor(1.0f); #endif diff --git a/chromium/ui/aura/env.cc b/chromium/ui/aura/env.cc index f458afd57c0..a21cfabf47e 100644 --- a/chromium/ui/aura/env.cc +++ b/chromium/ui/aura/env.cc @@ -7,6 +7,7 @@ #include "base/command_line.h" #include "base/containers/cxx20_erase.h" #include "base/lazy_instance.h" +#include "base/logging.h" #include "base/memory/ptr_util.h" #include "base/memory/raw_ptr.h" #include "base/observer_list_types.h" @@ -23,7 +24,7 @@ #include "ui/events/gestures/gesture_recognizer_impl.h" #include "ui/events/platform/platform_event_source.h" -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) #include "ui/base/win/win_cursor_factory.h" #endif @@ -99,8 +100,9 @@ std::unique_ptr<Env> Env::CreateInstance() { DCHECK(!g_primary_instance); // No make_unique as constructor is private. std::unique_ptr<Env> env(new Env()); + if (!env->Init()) + return {}; g_primary_instance = env.get(); - env->Init(); return env; } @@ -204,12 +206,12 @@ Env::Env() : env_controller_(std::make_unique<EnvInputStateController>(this)), gesture_recognizer_(std::make_unique<ui::GestureRecognizerImpl>()), input_state_lookup_(InputStateLookup::Create()) { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) cursor_factory_ = std::make_unique<ui::WinCursorFactory>(); #endif } -void Env::Init() { +bool Env::Init() { #if defined(USE_OZONE) // The ozone platform can provide its own event source. So initialize the // platform before creating the default event source @@ -219,10 +221,14 @@ void Env::Init() { // Env::CreateInstance() instead of checking flags here. params.single_process = command_line->HasSwitch("single-process") || command_line->HasSwitch("in-process-gpu"); - ui::OzonePlatform::InitializeForUI(params); + if (!ui::OzonePlatform::InitializeForUI(params)) { + LOG(ERROR) << "The platform failed to initialize. Exiting."; + return false; + } #endif if (!ui::PlatformEventSource::GetInstance()) event_source_ = ui::PlatformEventSource::CreateDefault(); + return true; } void Env::NotifyWindowInitialized(Window* window) { diff --git a/chromium/ui/aura/env.h b/chromium/ui/aura/env.h index 8fbc146ed9d..44488da7fa2 100644 --- a/chromium/ui/aura/env.h +++ b/chromium/ui/aura/env.h @@ -24,7 +24,7 @@ class EventObserver; class GestureRecognizer; class PlatformEventSource; -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) class WinCursorFactory; #endif } // namespace ui @@ -147,7 +147,9 @@ class AURA_EXPORT Env : public ui::EventTarget, Env(); - void Init(); + // Returns whether the initialisation was successful. If it was not, + // CreateInstance will return nullptr, and the process will eventually exit. + bool Init(); // Called by the Window when it is initialized. Notifies observers. void NotifyWindowInitialized(Window* window); @@ -184,7 +186,7 @@ class AURA_EXPORT Env : public ui::EventTarget, std::unique_ptr<ui::GestureRecognizer> gesture_recognizer_; -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) std::unique_ptr<ui::WinCursorFactory> cursor_factory_; #endif diff --git a/chromium/ui/aura/env_input_state_controller.cc b/chromium/ui/aura/env_input_state_controller.cc index b8eb0332daa..0f21c8b6b23 100644 --- a/chromium/ui/aura/env_input_state_controller.cc +++ b/chromium/ui/aura/env_input_state_controller.cc @@ -51,7 +51,7 @@ void EnvInputStateController::UpdateStateForTouchEvent( case ui::ET_TOUCH_CANCELLED: if (!event.HasNativeEvent()) break; - FALLTHROUGH; + [[fallthrough]]; case ui::ET_TOUCH_RELEASED: touch_ids_down_ = (touch_ids_down_ | (1 << event.pointer_details().id)) ^ (1 << event.pointer_details().id); diff --git a/chromium/ui/aura/gestures/gesture_recognizer_unittest.cc b/chromium/ui/aura/gestures/gesture_recognizer_unittest.cc index c1e2921056a..96494b7ce73 100644 --- a/chromium/ui/aura/gestures/gesture_recognizer_unittest.cc +++ b/chromium/ui/aura/gestures/gesture_recognizer_unittest.cc @@ -655,7 +655,9 @@ class GestureRecognizerTest : public AuraTestBase { void SetUp() override { AuraTestBase::SetUp(); ui::GestureConfiguration::GetInstance()->set_show_press_delay_in_ms(2); - ui::GestureConfiguration::GetInstance()->set_long_press_time_in_ms(3); + ui::GestureConfiguration::GetInstance()->set_short_press_time( + base::Milliseconds(3)); + ui::GestureConfiguration::GetInstance()->set_long_press_time_in_ms(4); } }; diff --git a/chromium/ui/aura/host_frame_rate_throttler.cc b/chromium/ui/aura/host_frame_rate_throttler.cc new file mode 100644 index 00000000000..9304ea96581 --- /dev/null +++ b/chromium/ui/aura/host_frame_rate_throttler.cc @@ -0,0 +1,55 @@ +// 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/aura/host_frame_rate_throttler.h" + +#include "base/containers/contains.h" +#include "build/build_config.h" +#include "components/viz/common/surfaces/frame_sink_id.h" +#include "components/viz/host/host_frame_sink_manager.h" +#include "ui/aura/env.h" +#include "ui/aura/window_tree_host.h" +#include "ui/compositor/compositor.h" + +namespace aura { + +#if BUILDFLAG(IS_WIN) +constexpr uint8_t kDefaultThrottleFps = 1; +#else +constexpr uint8_t kDefaultThrottleFps = 20; +#endif + +HostFrameRateThrottler& HostFrameRateThrottler::GetInstance() { + static base::NoDestructor<HostFrameRateThrottler> instance; + return *instance; +} + +HostFrameRateThrottler::HostFrameRateThrottler() = default; + +HostFrameRateThrottler::~HostFrameRateThrottler() = default; + +void HostFrameRateThrottler::AddHost(WindowTreeHost* host) { + if (base::Contains(hosts_, host)) + return; + hosts_.insert(host); + UpdateHostFrameSinkManager(); +} + +void HostFrameRateThrottler::RemoveHost(WindowTreeHost* host) { + if (!base::Contains(hosts_, host)) + return; + hosts_.erase(host); + UpdateHostFrameSinkManager(); +} + +void HostFrameRateThrottler::UpdateHostFrameSinkManager() { + std::vector<viz::FrameSinkId> ids; + ids.reserve(hosts_.size()); + for (WindowTreeHost* host : hosts_) + ids.push_back(host->compositor()->frame_sink_id()); + Env::GetInstance()->context_factory()->GetHostFrameSinkManager()->Throttle( + ids, base::Hertz(kDefaultThrottleFps)); +} + +} // namespace aura diff --git a/chromium/ui/aura/host_frame_rate_throttler.h b/chromium/ui/aura/host_frame_rate_throttler.h new file mode 100644 index 00000000000..1dda8683cf8 --- /dev/null +++ b/chromium/ui/aura/host_frame_rate_throttler.h @@ -0,0 +1,40 @@ +// 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. + +#ifndef UI_AURA_HOST_FRAME_RATE_THROTTLER_H_ +#define UI_AURA_HOST_FRAME_RATE_THROTTLER_H_ + +#include "base/containers/flat_set.h" +#include "base/no_destructor.h" +#include "ui/aura/aura_export.h" + +namespace aura { + +class WindowTreeHost; + +// Used to throttle the frame rate of hosts that are occluded. +class AURA_EXPORT HostFrameRateThrottler { + public: + static HostFrameRateThrottler& GetInstance(); + + void AddHost(WindowTreeHost* host); + void RemoveHost(WindowTreeHost* host); + + const base::flat_set<WindowTreeHost*>& hosts() const { return hosts_; } + + private: + friend class base::NoDestructor<HostFrameRateThrottler>; + + HostFrameRateThrottler(); + ~HostFrameRateThrottler(); + + void UpdateHostFrameSinkManager(); + + // Set of hosts that are currently throttled. + base::flat_set<WindowTreeHost*> hosts_; +}; + +} // namespace aura + +#endif // UI_AURA_HOST_FRAME_RATE_THROTTLER_H_ diff --git a/chromium/ui/aura/native_window_occlusion_tracker.cc b/chromium/ui/aura/native_window_occlusion_tracker.cc index f392f501636..4d7091142a5 100644 --- a/chromium/ui/aura/native_window_occlusion_tracker.cc +++ b/chromium/ui/aura/native_window_occlusion_tracker.cc @@ -9,13 +9,13 @@ #include "ui/aura/window_tree_host.h" #include "ui/base/ui_base_features.h" -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) #include "ui/aura/native_window_occlusion_tracker_win.h" -#endif // OS_WIN +#endif // BUILDFLAG(IS_WIN) namespace aura { namespace { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) // Whether IsNativeWindowOcclusionTrackingAlwaysEnabled() should check for // CHROME_HEADLESS. bool g_headless_check_enabled = true; @@ -25,30 +25,30 @@ bool g_headless_check_enabled = true; // static void NativeWindowOcclusionTracker::EnableNativeWindowOcclusionTracking( WindowTreeHost* host) { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) if (host->IsNativeWindowOcclusionEnabled()) { NativeWindowOcclusionTrackerWin::GetOrCreateInstance()->Enable( host->window()); } -#endif // defined(OS_WIN) +#endif // BUILDFLAG(IS_WIN) } // static void NativeWindowOcclusionTracker::DisableNativeWindowOcclusionTracking( WindowTreeHost* host) { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) if (host->IsNativeWindowOcclusionEnabled()) { host->SetNativeWindowOcclusionState(Window::OcclusionState::UNKNOWN, {}); NativeWindowOcclusionTrackerWin::GetOrCreateInstance()->Disable( host->window()); } -#endif // defined(OS_WIN) +#endif // BUILDFLAG(IS_WIN) } // static bool NativeWindowOcclusionTracker::IsNativeWindowOcclusionTrackingAlwaysEnabled( WindowTreeHost* host) { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) // chromedriver uses the environment variable CHROME_HEADLESS. In this case // it expected that native occlusion is not applied. static bool is_headless = getenv("CHROME_HEADLESS") != nullptr; @@ -69,7 +69,7 @@ bool NativeWindowOcclusionTracker::IsNativeWindowOcclusionTrackingAlwaysEnabled( #endif } -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) // static void NativeWindowOcclusionTracker::SetHeadlessCheckEnabled(bool enabled) { g_headless_check_enabled = enabled; diff --git a/chromium/ui/aura/native_window_occlusion_tracker.h b/chromium/ui/aura/native_window_occlusion_tracker.h index ce68640b60d..4e1d6cf3dfb 100644 --- a/chromium/ui/aura/native_window_occlusion_tracker.h +++ b/chromium/ui/aura/native_window_occlusion_tracker.h @@ -39,7 +39,7 @@ class AURA_EXPORT NativeWindowOcclusionTracker { friend class WindowTreeHostWithReleaseTest; friend class WindowTreeHostWithThrottleTest; -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) static void SetHeadlessCheckEnabled(bool enabled); #endif }; diff --git a/chromium/ui/aura/native_window_occlusion_tracker_win.cc b/chromium/ui/aura/native_window_occlusion_tracker_win.cc index 7d660ad6795..de2ceb519bf 100644 --- a/chromium/ui/aura/native_window_occlusion_tracker_win.cc +++ b/chromium/ui/aura/native_window_occlusion_tracker_win.cc @@ -651,10 +651,11 @@ void NativeWindowOcclusionTrackerWin::WindowOcclusionCalculator:: void NativeWindowOcclusionTrackerWin::WindowOcclusionCalculator:: ScheduleOcclusionCalculationIfNeeded() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (!occlusion_update_timer_.IsRunning()) + if (!occlusion_update_timer_.IsRunning()) { occlusion_update_timer_.Start( FROM_HERE, kUpdateOcclusionDelay, this, &WindowOcclusionCalculator::ComputeNativeWindowOcclusionStatus); + } } void NativeWindowOcclusionTrackerWin::WindowOcclusionCalculator:: @@ -681,6 +682,16 @@ void NativeWindowOcclusionTrackerWin::WindowOcclusionCalculator:: DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(global_event_hooks_.empty()); + // This helps with the case where an extension tried to foreground a window, + // but Windows prevented it, and the user clicks on the task bar to bring the + // window forward. See https://crbug.com/1137982. This is the only event I + // could find that always gets sent in this scenario, and isn't too common. + // TODO(crbug.com/1297684): See if we can make handling this event cheaper, + // since we typically don't need it, e.g., by using a longer timer interval + // for starting the occlusion calculation for this event, to batch subsequent + // events. + RegisterGlobalEventHook(EVENT_SYSTEM_CAPTUREEND, EVENT_SYSTEM_CAPTUREEND); + // Detects native window move (drag) and resizing events. RegisterGlobalEventHook(EVENT_SYSTEM_MOVESIZESTART, EVENT_SYSTEM_MOVESIZEEND); diff --git a/chromium/ui/aura/test/ui_controls_ozone.cc b/chromium/ui/aura/test/ui_controls_ozone.cc index c2ed2f738ac..84044506786 100644 --- a/chromium/ui/aura/test/ui_controls_ozone.cc +++ b/chromium/ui/aura/test/ui_controls_ozone.cc @@ -4,7 +4,8 @@ #include "ui/aura/test/ui_controls_ozone.h" -#include "base/ignore_result.h" +#include <tuple> + #include "build/build_config.h" #include "build/chromeos_buildflags.h" #include "ui/events/event_utils.h" @@ -252,7 +253,7 @@ void UIControlsOzone::SendEventToSink(ui::Event* event, } WindowTreeHost* host = optional_host ? optional_host : host_; ui::EventSourceTestApi event_source_test(host->GetEventSource()); - ignore_result(event_source_test.SendEventToSink(event)); + std::ignore = event_source_test.SendEventToSink(event); } void UIControlsOzone::PostKeyEvent(ui::EventType type, diff --git a/chromium/ui/aura/test/ui_controls_ozone.h b/chromium/ui/aura/test/ui_controls_ozone.h index 8fc87dc332c..9e64ff1a736 100644 --- a/chromium/ui/aura/test/ui_controls_ozone.h +++ b/chromium/ui/aura/test/ui_controls_ozone.h @@ -6,7 +6,6 @@ #define UI_AURA_TEST_UI_CONTROLS_OZONE_H_ #include "base/bind.h" -#include "base/location.h" #include "base/logging.h" #include "base/task/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" diff --git a/chromium/ui/aura/window.cc b/chromium/ui/aura/window.cc index 4e3b40dfd5d..b667d59f54d 100644 --- a/chromium/ui/aura/window.cc +++ b/chromium/ui/aura/window.cc @@ -9,7 +9,6 @@ #include <algorithm> #include <utility> -#include "base/auto_reset.h" #include "base/bind.h" #include "base/callback.h" #include "base/callback_helpers.h" @@ -1252,11 +1251,18 @@ bool Window::CleanupGestureState() { // happen through some event handlers for CancelActiveTouches(). if (cleaning_up_gesture_state_) return false; + cleaning_up_gesture_state_ = true; + + // Cancelling active touches may end up destroying this window. We use a + // tracker to detect this. + // TODO(crbug.com/1292271): Add a regression test for this. + WindowTracker tracking_this({this}); - base::AutoReset<bool> in_cleanup(&cleaning_up_gesture_state_, true); bool state_modified = false; Env* env = Env::GetInstance(); state_modified |= env->gesture_recognizer()->CancelActiveTouches(this); + if (!tracking_this.Contains(this)) + return state_modified; state_modified |= env->gesture_recognizer()->CleanupStateForConsumer(this); // Potentially event handlers for CancelActiveTouches() within // CleanupGestureState may change the window hierarchy (or reorder the @@ -1267,6 +1273,7 @@ bool Window::CleanupGestureState() { Window* child = children.Pop(); state_modified |= child->CleanupGestureState(); } + cleaning_up_gesture_state_ = false; return state_modified; } diff --git a/chromium/ui/aura/window.h b/chromium/ui/aura/window.h index cf16e8efd8c..b249126c0cb 100644 --- a/chromium/ui/aura/window.h +++ b/chromium/ui/aura/window.h @@ -14,7 +14,6 @@ #include <vector> #include "base/check.h" -#include "base/compiler_specific.h" #include "base/containers/flat_set.h" #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" @@ -45,7 +44,7 @@ #include "ui/gfx/geometry/rect.h" #include "ui/gfx/native_widget_types.h" -#if defined(OS_APPLE) +#if BUILDFLAG(IS_APPLE) #error "This file must not be included on macOS; Chromium Mac doesn't use Aura." #endif @@ -180,7 +179,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate, int GetId() const; void SetId(int id); - const std::string& GetName() const; + // ui::GestureConsumer: + const std::string& GetName() const override; void SetName(const std::string& name); const std::u16string& GetTitle() const; @@ -262,7 +262,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate, // be individually capturable, and its layer won't be tagged with a valid // |viz::SubtreeCaptureId|. // See https://crbug.com/1143930 for more details. - ScopedWindowCaptureRequest MakeWindowCapturable() WARN_UNUSED_RESULT; + [[nodiscard]] ScopedWindowCaptureRequest MakeWindowCapturable(); const viz::SubtreeCaptureId& subtree_capture_id() const { return subtree_capture_id_; } diff --git a/chromium/ui/aura/window_event_dispatcher.cc b/chromium/ui/aura/window_event_dispatcher.cc index 8e7624e9c74..45817ffaedc 100644 --- a/chromium/ui/aura/window_event_dispatcher.cc +++ b/chromium/ui/aura/window_event_dispatcher.cc @@ -449,7 +449,7 @@ void WindowEventDispatcher::OnOtherRootGotCapture() { // root window, in which case this function will get called whenever those // windows grab mouse capture. Sending mouse exit messages in these cases // causes subtle bugs like (crbug.com/394672). -#if !defined(OS_WIN) +#if !BUILDFLAG(IS_WIN) if (mouse_moved_handler_) { // Dispatch a mouse exit to reset any state associated with hover. This is // important when going from no window having capture to a window having @@ -516,11 +516,6 @@ ui::EventDispatchDetails WindowEventDispatcher::PreDispatchEvent( Window* target_window = static_cast<Window*>(target); CHECK(window()->Contains(target_window)); - if (!(event->flags() & ui::EF_IS_SYNTHESIZED)) { - fraction_of_time_without_user_input_recorder_.RecordEventAtTime( - event->time_stamp()); - } - WindowTracker target_window_tracker; target_window_tracker.Add(target_window); if (!dispatching_held_event_) { diff --git a/chromium/ui/aura/window_event_dispatcher.h b/chromium/ui/aura/window_event_dispatcher.h index e64765a3204..bff3906e43b 100644 --- a/chromium/ui/aura/window_event_dispatcher.h +++ b/chromium/ui/aura/window_event_dispatcher.h @@ -10,7 +10,6 @@ #include <vector> #include "base/callback.h" -#include "base/compiler_specific.h" #include "base/gtest_prod_util.h" #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" @@ -25,7 +24,6 @@ #include "ui/events/event_constants.h" #include "ui/events/event_processor.h" #include "ui/events/event_targeter.h" -#include "ui/events/fraction_of_time_without_user_input_recorder.h" #include "ui/events/gestures/gesture_recognizer.h" #include "ui/events/gestures/gesture_types.h" #include "ui/events/types/event_type.h" @@ -94,10 +92,10 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, // If the |target| is NULL, we will dispatch the event to the root-window. // |event_flags| will be set on the dispatched exit event. // TODO(beng): needed only for WTH::OnCursorVisibilityChanged(). - ui::EventDispatchDetails DispatchMouseExitAtPoint( + [[nodiscard]] ui::EventDispatchDetails DispatchMouseExitAtPoint( Window* target, const gfx::Point& point, - int event_flags = ui::EF_NONE) WARN_UNUSED_RESULT; + int event_flags = ui::EF_NONE); // Gesture Recognition ------------------------------------------------------- @@ -197,13 +195,13 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, // |mouse_moved_handler_|. // The event's location will be converted from |target|coordinate system to // |mouse_moved_handler_| coordinate system. - ui::EventDispatchDetails DispatchMouseEnterOrExit(Window* target, - const ui::MouseEvent& event, - ui::EventType type) - WARN_UNUSED_RESULT; - ui::EventDispatchDetails ProcessGestures( + [[nodiscard]] ui::EventDispatchDetails DispatchMouseEnterOrExit( Window* target, - ui::GestureRecognizer::Gestures gestures) WARN_UNUSED_RESULT; + const ui::MouseEvent& event, + ui::EventType type); + [[nodiscard]] ui::EventDispatchDetails ProcessGestures( + Window* target, + ui::GestureRecognizer::Gestures gestures); // Called when a window becomes invisible, either by being removed // from root window hierarchy, via SetVisible(false) or being destroyed. @@ -266,7 +264,7 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, // ReleaseMouseMoves()/ReleaseTouchMoves() is called. NOTE: because these // methods dispatch events from WindowTreeHost the coordinates are in terms of // the root. - ui::EventDispatchDetails DispatchHeldEvents() WARN_UNUSED_RESULT; + [[nodiscard]] ui::EventDispatchDetails DispatchHeldEvents(); // Posts a task to send synthesized mouse move event if there is no a pending // task. @@ -274,7 +272,7 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, // Creates and dispatches synthesized mouse move event using the current mouse // location. - ui::EventDispatchDetails SynthesizeMouseMoveEvent() WARN_UNUSED_RESULT; + [[nodiscard]] ui::EventDispatchDetails SynthesizeMouseMoveEvent(); // Calls SynthesizeMouseMove() if |window| is currently visible and contains // the mouse cursor. @@ -299,9 +297,6 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor, raw_ptr<Window> event_dispatch_target_ = nullptr; raw_ptr<Window> old_dispatch_target_ = nullptr; - ui::FractionOfTimeWithoutUserInputRecorder - fraction_of_time_without_user_input_recorder_; - bool synthesize_mouse_move_ = false; // Whether a OnWindowTargetTransformChanging() call didn't have its diff --git a/chromium/ui/aura/window_event_dispatcher_unittest.cc b/chromium/ui/aura/window_event_dispatcher_unittest.cc index 336344c98bd..3875abfe3ef 100644 --- a/chromium/ui/aura/window_event_dispatcher_unittest.cc +++ b/chromium/ui/aura/window_event_dispatcher_unittest.cc @@ -699,7 +699,7 @@ std::string EventTypesToString(const EventFilterRecorder::Events& events) { } // namespace -#if defined(OS_WIN) && defined(ARCH_CPU_X86) +#if BUILDFLAG(IS_WIN) && defined(ARCH_CPU_X86) #define MAYBE(x) DISABLED_##x #else #define MAYBE(x) x @@ -1234,7 +1234,7 @@ TEST_F(WindowEventDispatcherTest, DoNotDispatchInShutdown) { window->RemovePreTargetHandler(&recorder); } -#if defined(OS_WIN) && defined(ARCH_CPU_X86) +#if BUILDFLAG(IS_WIN) && defined(ARCH_CPU_X86) #define MAYBE(x) DISABLED_##x #else #define MAYBE(x) x @@ -3106,37 +3106,6 @@ TEST_F(WindowEventDispatcherTest, OnCursorMovedToRootLocationUpdatesHover) { w->RemovePreTargetHandler(&recorder); } -// Tests that we correctly report the fraction of time without user input via -// UMA. -TEST_F(WindowEventDispatcherTest, FractionOfTimeWithoutUserInputRecorded) { - const char* kHistogram = "Event.FractionOfTimeWithoutUserInput"; - base::HistogramTester tester; - - std::unique_ptr<aura::Window> window( - test::CreateTestWindowWithId(1234, root_window())); - - ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), - gfx::Point(10, 10), ui::EventTimeStampFromSeconds(4), 0, - 0); - - // To flush the idle fraction reporter, we need to dispatch two events. The - // first event causes us to record the previous active period, and the second - // flushes the previous active period. - ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), - gfx::Point(10, 10), ui::EventTimeStampFromSeconds(16), - 0, 0); - - ui::MouseEvent mouse3(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), - gfx::Point(10, 10), ui::EventTimeStampFromSeconds(30), - 0, 0); - - DispatchEventUsingWindowDispatcher(&mouse1); - DispatchEventUsingWindowDispatcher(&mouse2); - DispatchEventUsingWindowDispatcher(&mouse3); - - tester.ExpectTotalCount(kHistogram, 1); -} - TEST_F(WindowEventDispatcherTest, TouchEventWithScaledWindow) { WindowEventDispatcher* dispatcher = host()->dispatcher(); diff --git a/chromium/ui/aura/window_occlusion_tracker.cc b/chromium/ui/aura/window_occlusion_tracker.cc index da10b7db357..abb5c7e15e8 100644 --- a/chromium/ui/aura/window_occlusion_tracker.cc +++ b/chromium/ui/aura/window_occlusion_tracker.cc @@ -8,7 +8,6 @@ #include "base/containers/adapters.h" #include "base/containers/contains.h" #include "base/containers/cxx20_erase.h" -#include "base/metrics/histogram_macros.h" #include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkRegion.h" #include "ui/aura/env.h" @@ -982,9 +981,6 @@ void WindowOcclusionTracker::OnOcclusionStateChanged( WindowTreeHost* host, Window::OcclusionState new_state, const SkRegion& occluded_region) { - // TODO: the meaning of this histogram is different if - // `kApplyNativeOccludedRegionToWindowTracker` is true. Remove the histogram. - UMA_HISTOGRAM_ENUMERATION("WindowOcclusionChanged", new_state); Window* root_window = host->window(); auto root_window_state_it = root_windows_.find(root_window); if (root_window_state_it == root_windows_.end()) diff --git a/chromium/ui/aura/window_occlusion_tracker_unittest.cc b/chromium/ui/aura/window_occlusion_tracker_unittest.cc index 04df50dcf27..91099956107 100644 --- a/chromium/ui/aura/window_occlusion_tracker_unittest.cc +++ b/chromium/ui/aura/window_occlusion_tracker_unittest.cc @@ -84,7 +84,7 @@ class WindowOcclusionTrackerTest : public test::AuraTestBase { WindowOcclusionTrackerTest& operator=(const WindowOcclusionTrackerTest&) = delete; -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) void SetUp() override { // Native Window Occlusion calculation runs in the background and can // interfere with the expectations of these tests, so, disable it. diff --git a/chromium/ui/aura/window_targeter.cc b/chromium/ui/aura/window_targeter.cc index c7097fe643b..bf5a844f357 100644 --- a/chromium/ui/aura/window_targeter.cc +++ b/chromium/ui/aura/window_targeter.cc @@ -4,7 +4,8 @@ #include "ui/aura/window_targeter.h" -#include "base/ignore_result.h" +#include <tuple> + #include "build/chromeos_buildflags.h" #include "ui/aura/client/capture_client.h" #include "ui/aura/client/event_client.h" @@ -174,7 +175,7 @@ bool WindowTargeter::ProcessEventIfTargetsDifferentRootWindow( window_tree_host->GetRootTransform(), window_tree_host->GetRootTransformForLocalEventCoordinates()); } - ignore_result(new_root->GetHost()->GetEventSink()->OnEventFromSource(event)); + std::ignore = new_root->GetHost()->GetEventSink()->OnEventFromSource(event); return true; } diff --git a/chromium/ui/aura/window_tree_host.cc b/chromium/ui/aura/window_tree_host.cc index 1be963ce0c5..3c2918c8da4 100644 --- a/chromium/ui/aura/window_tree_host.cc +++ b/chromium/ui/aura/window_tree_host.cc @@ -15,6 +15,7 @@ #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" #include "base/trace_event/trace_event.h" +#include "build/build_config.h" #include "build/chromeos_buildflags.h" #include "components/viz/common/features.h" #include "components/viz/common/surfaces/frame_sink_id.h" @@ -22,6 +23,7 @@ #include "ui/aura/client/capture_client.h" #include "ui/aura/client/cursor_client.h" #include "ui/aura/env.h" +#include "ui/aura/host_frame_rate_throttler.h" #include "ui/aura/native_window_occlusion_tracker.h" #include "ui/aura/scoped_keyboard_hook.h" #include "ui/aura/scoped_simple_keyboard_hook.h" @@ -94,49 +96,6 @@ class ScopedLocalSurfaceIdValidator { }; #endif -// Used to throttle the frame rate of hosts that are occluded. -class HostThrottler { - public: - static HostThrottler& GetInstance() { - static base::NoDestructor<HostThrottler> instance; - return *instance; - } - - void AddHost(WindowTreeHost* host) { - if (base::Contains(hosts_, host)) - return; - hosts_.insert(host); - UpdateHostFrameSinkManager(); - } - - void RemoveHost(WindowTreeHost* host) { - if (!base::Contains(hosts_, host)) - return; - hosts_.erase(host); - UpdateHostFrameSinkManager(); - } - - const base::flat_set<WindowTreeHost*>& hosts() const { return hosts_; } - - private: - friend class base::NoDestructor<HostThrottler>; - - HostThrottler() = default; - ~HostThrottler() = default; - - void UpdateHostFrameSinkManager() { - std::vector<viz::FrameSinkId> ids; - ids.reserve(hosts_.size()); - for (WindowTreeHost* host : hosts_) - ids.push_back(host->compositor()->frame_sink_id()); - Env::GetInstance()->context_factory()->GetHostFrameSinkManager()->Throttle( - ids, base::Seconds(1)); - } - - // Set of hosts that are currently throttled. - base::flat_set<WindowTreeHost*> hosts_; -}; - } // namespace // In order for viz to drop all references to resources used by the browser @@ -152,16 +111,24 @@ class WindowTreeHost::HideHelper { explicit HideHelper(WindowTreeHost* host) : host_(host), compositor_root_layer_( - ccLayerFromUiLayer(host->window()->layer())->parent()), + ccLayerFromUiLayer(host->window()->layer())->mutable_parent()), layer_for_transition_( std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR)) { layer_for_transition_->SetColor(SK_ColorWHITE); aura::Window* host_window = host_->window(); + ui::Layer* host_window_layer = host_window->layer(); + ui::Compositor* compositor = host_->compositor(); // SetRootLayer() resets the `compositor_` member in Layer. If // SetRootLayer() were used, it would mean the existing layer hierarchy // would no longer think it is in a compositor. As this state is temporary, // and purely to release resources, SetRootLayer() is not used. - ccLayerFromUiLayer(host_window->layer())->RemoveFromParent(); + + // We do need to disable ticking of animations since the animation code + // expects that its callers ensure that any ticking animations reference + // element IDs for layers that are currently in the layer tree. + DCHECK_EQ(host_window_layer, compositor->root_layer()); + compositor->DisableAnimations(); + ccLayerFromUiLayer(host_window_layer)->RemoveFromParent(); layer_for_transition_->SetBounds(host_window->bounds()); compositor_root_layer_->AddChild( ccLayerFromUiLayer(layer_for_transition_.get())); @@ -169,7 +136,7 @@ class WindowTreeHost::HideHelper { host_window->layer()->device_scale_factor()); // Request a presentation frame. Once the frame is generated the real root // layer is added back (from the destructor). - host_->compositor()->RequestPresentationTimeForNextFrame(base::BindOnce( + compositor->RequestPresentationTimeForNextFrame(base::BindOnce( &HideHelper::OnFramePresented, weak_ptr_factory_.GetWeakPtr())); } @@ -178,6 +145,8 @@ class WindowTreeHost::HideHelper { compositor_root_layer_->AddChild(ccLayerFromUiLayer(host_window_layer)); host_window_layer->OnDeviceScaleFactorChanged( layer_for_transition_->device_scale_factor()); + DCHECK_EQ(host_window_layer, host_->compositor()->root_layer()); + host_->compositor()->EnableAnimations(); } private: @@ -468,9 +437,9 @@ void WindowTreeHost::SetNativeWindowOcclusionState( if (ShouldThrottleWhenOccluded()) { // Throttling doesn't update the visibility. if (occlusion_state_ == Window::OcclusionState::OCCLUDED) - HostThrottler::GetInstance().AddHost(this); + HostFrameRateThrottler::GetInstance().AddHost(this); else - HostThrottler::GetInstance().RemoveHost(this); + HostFrameRateThrottler::GetInstance().RemoveHost(this); } else { const bool visible = CalculateCompositorVisibilityFromOcclusionState(); // Transitioning to hidden means the compositor state hasn't been updated @@ -545,8 +514,8 @@ WindowTreeHost::WindowTreeHost(std::unique_ptr<Window> window) window_ = new Window(nullptr); auto display = display::Screen::GetScreen()->GetDisplayNearestWindow(window_); device_scale_factor_ = display.device_scale_factor(); -#if defined(OS_WIN) - // The feature state is neccessary but not sufficient for checking if +#if BUILDFLAG(IS_WIN) + // The feature state is necessary but not sufficient for checking if // occlusion is enabled. It may be disabled by other means (e.g., policy). native_window_occlusion_enabled_ = !base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless) && @@ -570,7 +539,7 @@ void WindowTreeHost::UpdateCompositorVisibility(bool visible) { // disabled. For the most part, if ShouldThrottleWhenOccluded() is true, // the handling of occlusion changing is done in // SetNativeWindowOcclusionState(). - HostThrottler::GetInstance().RemoveHost(this); + HostFrameRateThrottler::GetInstance().RemoveHost(this); } if (visible) { @@ -592,8 +561,7 @@ void WindowTreeHost::DestroyCompositor() { if (!compositor_) return; - if (ShouldThrottleWhenOccluded()) - HostThrottler::GetInstance().RemoveHost(this); + HostFrameRateThrottler::GetInstance().RemoveHost(this); // Explicitly delete the HideHelper early as it makes use of `compositor_` // and `window_`. @@ -697,7 +665,11 @@ void WindowTreeHost::OnHostResizedInPixels( display::Display display = display::Screen::GetScreen()->GetDisplayNearestWindow(window()); - device_scale_factor_ = display.device_scale_factor(); + // If we don't have the actual display, don't overwrite the scale factor with + // the default value. See https://crbug.com/1285476 for details. + if (display.is_valid()) + device_scale_factor_ = display.device_scale_factor(); + UpdateRootWindowSizeInPixels(); // Passing |new_size_in_pixels| to set compositor size. It could be different @@ -812,7 +784,7 @@ bool WindowTreeHost::CalculateCompositorVisibilityFromOcclusionState() const { } bool WindowTreeHost::ShouldReleaseResourcesWhenHidden() const { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) if (!base::FeatureList::IsEnabled( features::kApplyNativeOcclusionToCompositor) || !IsNativeWindowOcclusionEnabled()) { @@ -829,7 +801,7 @@ bool WindowTreeHost::ShouldReleaseResourcesWhenHidden() const { } bool WindowTreeHost::ShouldThrottleWhenOccluded() const { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) if (!base::FeatureList::IsEnabled( features::kApplyNativeOcclusionToCompositor) || !IsNativeWindowOcclusionEnabled()) { @@ -859,7 +831,7 @@ void WindowTreeHost::FinishHideTransition() { // static const base::flat_set<WindowTreeHost*>& WindowTreeHost::GetThrottledHostsForTesting() { - return HostThrottler::GetInstance().hosts(); + return HostFrameRateThrottler::GetInstance().hosts(); } void WindowTreeHost::StartReleasingResourcesForHide() { diff --git a/chromium/ui/aura/window_tree_host.h b/chromium/ui/aura/window_tree_host.h index 6ff00ec0298..bd21ea3a142 100644 --- a/chromium/ui/aura/window_tree_host.h +++ b/chromium/ui/aura/window_tree_host.h @@ -182,10 +182,11 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate, // InputMethod shared between multiple WindowTreeHost instances. // // This is used for Ash only. There are 2 reasons: - // 1) ChromeOS virtual keyboard needs to receive ShowVirtualKeyboardIfEnabled - // notification from InputMethod. Multiple InputMethod instances makes it hard - // to register/unregister the observer for that notification. 2) For Ozone, - // there is no native focus state for the root window and WindowTreeHost. See + // 1) ChromeOS virtual keyboard needs to receive + // SetVirtualKeyboardVisibilityIfEnabled() notification from InputMethod. + // Multiple InputMethod instances makes it hard to register/unregister the + // observer for that notification. 2) For Ozone, there is no native focus + // state for the root window and WindowTreeHost. See // DrmWindowHost::CanDispatchEvent, the key events always goes to the primary // WindowTreeHost. And after InputMethod processed the key event and continue // dispatching it, WindowTargeter::FindTargetForEvent may re-dispatch it to a diff --git a/chromium/ui/aura/window_tree_host_platform.cc b/chromium/ui/aura/window_tree_host_platform.cc index e80c9dd023f..ac84fc9ecae 100644 --- a/chromium/ui/aura/window_tree_host_platform.cc +++ b/chromium/ui/aura/window_tree_host_platform.cc @@ -13,6 +13,7 @@ #include "build/build_config.h" #include "ui/aura/client/cursor_client.h" #include "ui/aura/env.h" +#include "ui/aura/host_frame_rate_throttler.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_tree_host_observer.h" @@ -32,7 +33,7 @@ #include "ui/ozone/public/ozone_platform.h" #endif -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) #include "ui/platform_window/win/win_window.h" #endif @@ -71,7 +72,7 @@ void WindowTreeHostPlatform::CreateAndSetPlatformWindow( #if defined(USE_OZONE) platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( this, std::move(properties)); -#elif defined(OS_WIN) +#elif BUILDFLAG(IS_WIN) platform_window_ = std::make_unique<ui::WinWindow>(this, properties.bounds); #else NOTIMPLEMENTED(); @@ -294,4 +295,11 @@ void WindowTreeHostPlatform::OnOcclusionStateChanged( SetNativeWindowOcclusionState(aura_occlusion_state, {}); } +void WindowTreeHostPlatform::SetFrameRateThrottleEnabled(bool enabled) { + if (enabled) + HostFrameRateThrottler::GetInstance().AddHost(this); + else + HostFrameRateThrottler::GetInstance().RemoveHost(this); +} + } // namespace aura diff --git a/chromium/ui/aura/window_tree_host_platform.h b/chromium/ui/aura/window_tree_host_platform.h index 8a4bbc220aa..36262762be8 100644 --- a/chromium/ui/aura/window_tree_host_platform.h +++ b/chromium/ui/aura/window_tree_host_platform.h @@ -84,6 +84,7 @@ class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHost, void OnMouseEnter() override; void OnOcclusionStateChanged( ui::PlatformWindowOcclusionState occlusion_state) override; + void SetFrameRateThrottleEnabled(bool enabled) override; // Overridden from aura::WindowTreeHost: bool CaptureSystemKeyEventsImpl( diff --git a/chromium/ui/aura/window_tree_host_platform_unittest.cc b/chromium/ui/aura/window_tree_host_platform_unittest.cc index 0b1050886c6..5a6ed0885c7 100644 --- a/chromium/ui/aura/window_tree_host_platform_unittest.cc +++ b/chromium/ui/aura/window_tree_host_platform_unittest.cc @@ -22,14 +22,14 @@ class WindowTreeHostPlatformTest : public test::AuraTestBase { // test::AuraTestBase: void SetUp() override { test::AuraTestBase::SetUp(); -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) scoped_feature_list_.InitAndDisableFeature( features::kApplyNativeOcclusionToCompositor); #endif } private: -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) base::test::ScopedFeatureList scoped_feature_list_; #endif }; diff --git a/chromium/ui/aura/window_tree_host_unittest.cc b/chromium/ui/aura/window_tree_host_unittest.cc index 7f6439ccbbb..b24385c85d2 100644 --- a/chromium/ui/aura/window_tree_host_unittest.cc +++ b/chromium/ui/aura/window_tree_host_unittest.cc @@ -26,7 +26,7 @@ #include "ui/events/test/test_event_rewriter.h" #include "ui/platform_window/stub/stub_window.h" -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) #include "ui/aura/native_window_occlusion_tracker_win.h" #endif @@ -197,7 +197,7 @@ class TestWindowTreeHost : public WindowTreeHostPlatform { }; TEST_F(WindowTreeHostTest, LostCaptureDuringTearDown) { -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) base::test::ScopedFeatureList scoped_feature_list; scoped_feature_list.InitAndDisableFeature( features::kApplyNativeOcclusionToCompositor); @@ -205,7 +205,7 @@ TEST_F(WindowTreeHostTest, LostCaptureDuringTearDown) { TestWindowTreeHost host; } -#if defined(OS_WIN) +#if BUILDFLAG(IS_WIN) class WindowTreeHostWithReleaseTest : public test::AuraTestBase { public: // AuraTestBase: @@ -258,7 +258,7 @@ TEST_F(WindowTreeHostWithReleaseTest, ToggleOccluded) { IsNativeWindowOcclusionTrackingAlwaysEnabled(host())); cc::Layer* host_window_cc_layer = ccLayerFromUiLayer(host()->window()->layer()); - cc::Layer* compositor_root_layer = host_window_cc_layer->parent(); + const cc::Layer* compositor_root_layer = host_window_cc_layer->parent(); EXPECT_NE(nullptr, compositor_root_layer); host()->SetNativeWindowOcclusionState(Window::OcclusionState::OCCLUDED, {}); // The compositor shouldn't actually hide immediately, it needs a frame to @@ -281,7 +281,7 @@ TEST_F(WindowTreeHostWithReleaseTest, ShowWhileTransitioningToHidden) { IsNativeWindowOcclusionTrackingAlwaysEnabled(host())); cc::Layer* host_window_cc_layer = ccLayerFromUiLayer(host()->window()->layer()); - cc::Layer* compositor_root_layer = host_window_cc_layer->parent(); + const cc::Layer* compositor_root_layer = host_window_cc_layer->parent(); EXPECT_NE(nullptr, compositor_root_layer); host()->SetNativeWindowOcclusionState(Window::OcclusionState::OCCLUDED, {}); // The compositor shouldn't actually hide immediately, it needs a frame to diff --git a/chromium/ui/aura/window_unittest.cc b/chromium/ui/aura/window_unittest.cc index 2ea0d2bd1d4..2cb88f81dc3 100644 --- a/chromium/ui/aura/window_unittest.cc +++ b/chromium/ui/aura/window_unittest.cc @@ -629,7 +629,7 @@ TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { transform.Scale(2.0, 5.0); host()->SetRootTransform(transform); host()->MoveCursorToLocationInDIP(gfx::Point(10, 10)); -#if !defined(OS_WIN) +#if !BUILDFLAG(IS_WIN) // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD EXPECT_EQ("50,120", QueryLatestMousePositionRequestInHost(host()).ToString()); #endif @@ -709,7 +709,7 @@ TEST_F(WindowTest, MoveCursorToWithComplexTransform) { w1111->MoveCursorTo(gfx::Point(10, 10)); -#if !defined(OS_WIN) +#if !BUILDFLAG(IS_WIN) // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413. EXPECT_EQ("169,80", QueryLatestMousePositionRequestInHost(host()).ToString()); #endif |