Commit bdffcf67 authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

Fix remote window occlusion tracking

- Add a kClientWindowHasContent property to pass the info
  from client to Window Service;
- DesktopWindowTreeHostMus sets the property based on layer type
  and opacity of Widget::InitParams;
- Check kClientWindowHasContent property as part of the remote
  window has-content check for occlusion tracking;

Bug: 908629
Change-Id: I23c582d7135d50b70ba0776cb0368da59fe5d8c7
Reviewed-on: https://chromium-review.googlesource.com/c/1354439Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612773}
parent c99e9055
...@@ -81,6 +81,11 @@ interface WindowManager { ...@@ -81,6 +81,11 @@ interface WindowManager {
// The modal parent of a child modal window. Type: window Id. // The modal parent of a child modal window. Type: window Id.
const string kChildModalParent_Property = "prop:child-modal-parent"; const string kChildModalParent_Property = "prop:child-modal-parent";
// If true, the window is considered as has-content and occludes windows
// behind it.
const string kClientWindowHasContent_Property =
"prop:client-window-has-content";
// Whether the window is trying to draw attention to itself (e.g. pulsing its // Whether the window is trying to draw attention to itself (e.g. pulsing its
// shelf icon). Type: bool. // shelf icon). Type: bool.
const string kDrawAttention_Property = "prop:draw-attention"; const string kDrawAttention_Property = "prop:draw-attention";
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "services/ws/window_service_observer.h" #include "services/ws/window_service_observer.h"
#include "services/ws/window_tree.h" #include "services/ws/window_tree.h"
#include "services/ws/window_tree_factory.h" #include "services/ws/window_tree_factory.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/window_occlusion_tracker.h" #include "ui/aura/window_occlusion_tracker.h"
#include "ui/base/mojo/clipboard_host.h" #include "ui/base/mojo/clipboard_host.h"
...@@ -33,6 +34,16 @@ ...@@ -33,6 +34,16 @@
namespace ws { namespace ws {
namespace {
// Returns true if |window| has remote client and marked as has-content.
bool IsRemoteOpaqueWindow(const aura::Window* window) {
return WindowService::HasRemoteClient(window) &&
window->GetProperty(aura::client::kClientWindowHasContent);
}
} // namespace
WindowService::WindowService( WindowService::WindowService(
WindowServiceDelegate* delegate, WindowServiceDelegate* delegate,
std::unique_ptr<GpuInterfaceProvider> gpu_interface_provider, std::unique_ptr<GpuInterfaceProvider> gpu_interface_provider,
...@@ -64,10 +75,9 @@ WindowService::WindowService( ...@@ -64,10 +75,9 @@ WindowService::WindowService(
mojom::WindowManager::kShadowElevation_Property, mojom::WindowManager::kShadowElevation_Property,
aura::PropertyConverter::CreateAcceptAnyValueCallback()); aura::PropertyConverter::CreateAcceptAnyValueCallback());
// Extends WindowOcclusionTracker to treat windows with remote client as // Extends WindowOcclusionTracker to check whether remote window has content.
// has-content.
env_->GetWindowOcclusionTracker()->set_window_has_content_callback( env_->GetWindowOcclusionTracker()->set_window_has_content_callback(
base::BindRepeating(&WindowService::HasRemoteClient)); base::BindRepeating(&IsRemoteOpaqueWindow));
} }
WindowService::~WindowService() { WindowService::~WindowService() {
......
...@@ -2189,6 +2189,7 @@ TEST(WindowTreeTest, OcclusionStateChange) { ...@@ -2189,6 +2189,7 @@ TEST(WindowTreeTest, OcclusionStateChange) {
aura::Window* top_level2 = aura::Window* top_level2 =
setup.window_tree_test_helper()->NewTopLevelWindow(); setup.window_tree_test_helper()->NewTopLevelWindow();
ASSERT_TRUE(top_level2); ASSERT_TRUE(top_level2);
top_level2->SetProperty(aura::client::kClientWindowHasContent, true);
top_level2->SetBounds(gfx::Rect(0, 0, 15, 15)); top_level2->SetBounds(gfx::Rect(0, 0, 15, 15));
top_level2->Show(); top_level2->Show();
......
...@@ -45,6 +45,7 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::ImageSkia, kAppIconKey, nullptr); ...@@ -45,6 +45,7 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::ImageSkia, kAppIconKey, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(int, kAppType, 0); DEFINE_UI_CLASS_PROPERTY_KEY(int, kAppType, 0);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::SizeF, kAspectRatio, nullptr); DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::SizeF, kAspectRatio, nullptr);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::ImageSkia, kAvatarIconKey, nullptr); DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::ImageSkia, kAvatarIconKey, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kClientWindowHasContent, false);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kConstrainedWindowKey, false); DEFINE_UI_CLASS_PROPERTY_KEY(bool, kConstrainedWindowKey, false);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kCreatedByUserGesture, false); DEFINE_UI_CLASS_PROPERTY_KEY(bool, kCreatedByUserGesture, false);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kDrawAttentionKey, false); DEFINE_UI_CLASS_PROPERTY_KEY(bool, kDrawAttentionKey, false);
......
...@@ -62,6 +62,13 @@ AURA_EXPORT extern const WindowProperty<gfx::SizeF*>* const kAspectRatio; ...@@ -62,6 +62,13 @@ AURA_EXPORT extern const WindowProperty<gfx::SizeF*>* const kAspectRatio;
// frame to indicate the owner of the window when needed. // frame to indicate the owner of the window when needed.
AURA_EXPORT extern const WindowProperty<gfx::ImageSkia*>* const kAvatarIconKey; AURA_EXPORT extern const WindowProperty<gfx::ImageSkia*>* const kAvatarIconKey;
// A property key to indicate if a client window has content. The value is
// based on whether the window has a drawn layer (i.e. layer type !=
// LAYER_NOT_DRAWN) and is opaque. It is passed to the Window Service side for
// the occlusion tracker to process since the info is only available at the
// client side.
AURA_EXPORT extern const WindowProperty<bool>* const kClientWindowHasContent;
// A property key to store if a window is a constrained window or not. // A property key to store if a window is a constrained window or not.
AURA_EXPORT extern const WindowProperty<bool>* const kConstrainedWindowKey; AURA_EXPORT extern const WindowProperty<bool>* const kConstrainedWindowKey;
......
...@@ -108,6 +108,10 @@ PropertyConverter::PropertyConverter() { ...@@ -108,6 +108,10 @@ PropertyConverter::PropertyConverter() {
RegisterWindowPtrProperty( RegisterWindowPtrProperty(
client::kChildModalParentKey, client::kChildModalParentKey,
ws::mojom::WindowManager::kChildModalParent_Property); ws::mojom::WindowManager::kChildModalParent_Property);
RegisterPrimitiveProperty(
client::kClientWindowHasContent,
ws::mojom::WindowManager::kClientWindowHasContent_Property,
CreateAcceptAnyValueCallback());
} }
PropertyConverter::~PropertyConverter() {} PropertyConverter::~PropertyConverter() {}
......
...@@ -504,6 +504,13 @@ void DesktopWindowTreeHostMus::Init(const Widget::InitParams& params) { ...@@ -504,6 +504,13 @@ void DesktopWindowTreeHostMus::Init(const Widget::InitParams& params) {
window()->SetEventTargetingPolicy(ws::mojom::EventTargetingPolicy::NONE); window()->SetEventTargetingPolicy(ws::mojom::EventTargetingPolicy::NONE);
else else
aura::WindowPortMus::Get(content_window())->SetCanAcceptDrops(true); aura::WindowPortMus::Get(content_window())->SetCanAcceptDrops(true);
// Sets the has-content info for the occlusion tracker that runs on the Window
// Service side.
content_window()->SetProperty(
aura::client::kClientWindowHasContent,
params.layer_type != ui::LAYER_NOT_DRAWN &&
params.opacity == views::Widget::InitParams::OPAQUE_WINDOW);
} }
void DesktopWindowTreeHostMus::OnNativeWidgetCreated( void DesktopWindowTreeHostMus::OnNativeWidgetCreated(
......
...@@ -416,6 +416,43 @@ TEST_F(DesktopWindowTreeHostMusTest, CreateFullscreenWidget) { ...@@ -416,6 +416,43 @@ TEST_F(DesktopWindowTreeHostMusTest, CreateFullscreenWidget) {
} }
} }
TEST_F(DesktopWindowTreeHostMusTest, ClientWindowHasContent) {
// Opaque window has content.
{
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
Widget widget;
widget.Init(params);
EXPECT_TRUE(widget.GetNativeWindow()->GetProperty(
aura::client::kClientWindowHasContent));
}
// Translucent window does not have content.
{
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
Widget widget;
widget.Init(params);
EXPECT_FALSE(widget.GetNativeWindow()->GetProperty(
aura::client::kClientWindowHasContent));
}
// Window with LAYER_NOT_DRAWN does not have content.
{
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.layer_type = ui::LAYER_NOT_DRAWN;
Widget widget;
widget.Init(params);
EXPECT_FALSE(widget.GetNativeWindow()->GetProperty(
aura::client::kClientWindowHasContent));
}
}
// DesktopWindowTreeHostMusTest with --force-device-scale-factor=2. // DesktopWindowTreeHostMusTest with --force-device-scale-factor=2.
class DesktopWindowTreeHostMusTestHighDPI class DesktopWindowTreeHostMusTestHighDPI
: public DesktopWindowTreeHostMusTest { : public DesktopWindowTreeHostMusTest {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment