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

cros: Forward VK bounds adjustment to embedding side

Support embedded windows in EnsureWindowNotInRect and
RestoreWindowBoundsOnClientFocusLost in ime_util_chromeos by
using a window property to forward the bounds adjustment
to the embedding side top level window.

Bug: 948015
Change-Id: I08e2afa3f566667d8c92bd3c04412404af55df5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1558575Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649335}
parent bad4a053
...@@ -94,6 +94,12 @@ interface WindowManager { ...@@ -94,6 +94,12 @@ interface WindowManager {
// shelf icon). Type: bool. // shelf icon). Type: bool.
const string kDrawAttention_Property = "prop:draw-attention"; const string kDrawAttention_Property = "prop:draw-attention";
// The bounds in screen coordinates that an embedded window wants to be moved
// out of. Maps to aura::client::kEmbeddedWindowEnsureNotInRect.
// Type: gfx::Rect.
const string kEmbeddedWindowEnsureNotInRect =
"prop:embedded-window-ensure-not-in-rect";
// Used to explicitly control whether a window appears in the most recently // Used to explicitly control whether a window appears in the most recently
// used list of windows. Maps to aura::client::kExcludeFromMruKey. Type: bool. // used list of windows. Maps to aura::client::kExcludeFromMruKey. Type: bool.
const string kExcludeFromMru_Property = "prop:exclude_from_mru"; const string kExcludeFromMru_Property = "prop:exclude_from_mru";
......
...@@ -16,6 +16,11 @@ source_set("remote_view_host") { ...@@ -16,6 +16,11 @@ source_set("remote_view_host") {
"//ui/aura", "//ui/aura",
"//ui/views", "//ui/views",
] ]
deps = []
if (is_chromeos) {
deps += [ "//ui/wm" ]
}
} }
source_set("tests") { source_set("tests") {
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#if defined(OS_CHROMEOS)
#include "ui/wm/core/ime_util_chromeos.h"
#endif
namespace ws { namespace ws {
ServerRemoteViewHost::ServerRemoteViewHost(WindowService* window_service) ServerRemoteViewHost::ServerRemoteViewHost(WindowService* window_service)
...@@ -23,6 +27,11 @@ ServerRemoteViewHost::ServerRemoteViewHost(WindowService* window_service) ...@@ -23,6 +27,11 @@ ServerRemoteViewHost::ServerRemoteViewHost(WindowService* window_service)
embedding_root_->SetName("ServerRemoteViewHostWindow"); embedding_root_->SetName("ServerRemoteViewHostWindow");
embedding_root_->SetType(aura::client::WINDOW_TYPE_CONTROL); embedding_root_->SetType(aura::client::WINDOW_TYPE_CONTROL);
embedding_root_->Init(ui::LAYER_NOT_DRAWN); embedding_root_->Init(ui::LAYER_NOT_DRAWN);
#if defined(OS_CHROMEOS)
helper_ =
std::make_unique<wm::EnsureWindowNotInRectHelper>(embedding_root_.get());
#endif
} }
ServerRemoteViewHost::~ServerRemoteViewHost() = default; ServerRemoteViewHost::~ServerRemoteViewHost() = default;
......
...@@ -16,6 +16,10 @@ namespace aura { ...@@ -16,6 +16,10 @@ namespace aura {
class Window; class Window;
} }
namespace wm {
class EnsureWindowNotInRectHelper;
}
namespace ws { namespace ws {
class WindowService; class WindowService;
...@@ -65,7 +69,11 @@ class ServerRemoteViewHost : public views::NativeViewHost { ...@@ -65,7 +69,11 @@ class ServerRemoteViewHost : public views::NativeViewHost {
base::UnguessableToken embed_token_; base::UnguessableToken embed_token_;
int embed_flags_ = 0; int embed_flags_ = 0;
EmbedCallback embed_callback_; EmbedCallback embed_callback_;
const std::unique_ptr<aura::Window> embedding_root_; const std::unique_ptr<aura::Window> embedding_root_;
#if defined(OS_CHROMEOS)
std::unique_ptr<wm::EnsureWindowNotInRectHelper> helper_;
#endif
DISALLOW_COPY_AND_ASSIGN(ServerRemoteViewHost); DISALLOW_COPY_AND_ASSIGN(ServerRemoteViewHost);
}; };
......
...@@ -53,6 +53,9 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kWindowLayerDrawn, false) ...@@ -53,6 +53,9 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kWindowLayerDrawn, 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)
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect,
kEmbeddedWindowEnsureNotInRect,
nullptr)
DEFINE_UI_CLASS_PROPERTY_KEY(FocusClient*, kFocusClientKey, nullptr) DEFINE_UI_CLASS_PROPERTY_KEY(FocusClient*, kFocusClientKey, nullptr)
DEFINE_UI_CLASS_PROPERTY_KEY(bool, DEFINE_UI_CLASS_PROPERTY_KEY(bool,
kGestureDragFromClientAreaTopMovesWindow, kGestureDragFromClientAreaTopMovesWindow,
......
...@@ -88,6 +88,12 @@ AURA_EXPORT extern const WindowProperty<bool>* const kCreatedByUserGesture; ...@@ -88,6 +88,12 @@ AURA_EXPORT extern const WindowProperty<bool>* const kCreatedByUserGesture;
// attention. // attention.
AURA_EXPORT extern const WindowProperty<bool>* const kDrawAttentionKey; AURA_EXPORT extern const WindowProperty<bool>* const kDrawAttentionKey;
// A property key to store a bounds in screen coordinates that an embedded
// window wants to be moved out of. This is only used in MUS to move the
// embedding top-level window at the other side.
AURA_EXPORT extern const WindowProperty<gfx::Rect*>* const
kEmbeddedWindowEnsureNotInRect;
// A property key to store the focus client on the window. // A property key to store the focus client on the window.
AURA_EXPORT extern const WindowProperty<FocusClient*>* const kFocusClientKey; AURA_EXPORT extern const WindowProperty<FocusClient*>* const kFocusClientKey;
......
...@@ -84,6 +84,9 @@ PropertyConverter::PropertyConverter() { ...@@ -84,6 +84,9 @@ PropertyConverter::PropertyConverter() {
RegisterPrimitiveProperty(client::kDrawAttentionKey, RegisterPrimitiveProperty(client::kDrawAttentionKey,
ws::mojom::WindowManager::kDrawAttention_Property, ws::mojom::WindowManager::kDrawAttention_Property,
CreateAcceptAnyValueCallback()); CreateAcceptAnyValueCallback());
RegisterRectProperty(
client::kEmbeddedWindowEnsureNotInRect,
ws::mojom::WindowManager::kEmbeddedWindowEnsureNotInRect);
RegisterPrimitiveProperty(client::kResizeBehaviorKey, RegisterPrimitiveProperty(client::kResizeBehaviorKey,
ws::mojom::WindowManager::kResizeBehavior_Property, ws::mojom::WindowManager::kResizeBehavior_Property,
base::Bind(&ValidateResizeBehaviour)); base::Bind(&ValidateResizeBehaviour));
......
...@@ -13,6 +13,11 @@ source_set("remote_view_host") { ...@@ -13,6 +13,11 @@ source_set("remote_view_host") {
"//ui/aura", "//ui/aura",
"//ui/views", "//ui/views",
] ]
deps = []
if (is_chromeos) {
deps += [ "//ui/wm" ]
}
} }
source_set("remote_view_provider") { source_set("remote_view_provider") {
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/mus/window_port_mus.h" #include "ui/aura/mus/window_port_mus.h"
#if defined(OS_CHROMEOS)
#include "ui/wm/core/ime_util_chromeos.h"
#endif
namespace views { namespace views {
RemoteViewHost::RemoteViewHost() RemoteViewHost::RemoteViewHost()
...@@ -21,6 +25,11 @@ RemoteViewHost::RemoteViewHost() ...@@ -21,6 +25,11 @@ RemoteViewHost::RemoteViewHost()
embedding_root_->SetName("RemoteViewHostWindow"); embedding_root_->SetName("RemoteViewHostWindow");
embedding_root_->SetType(aura::client::WINDOW_TYPE_CONTROL); embedding_root_->SetType(aura::client::WINDOW_TYPE_CONTROL);
embedding_root_->Init(ui::LAYER_NOT_DRAWN); embedding_root_->Init(ui::LAYER_NOT_DRAWN);
#if defined(OS_CHROMEOS)
helper_ =
std::make_unique<wm::EnsureWindowNotInRectHelper>(embedding_root_.get());
#endif
} }
RemoteViewHost::~RemoteViewHost() = default; RemoteViewHost::~RemoteViewHost() = default;
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/native/native_view_host.h"
namespace wm {
class EnsureWindowNotInRectHelper;
}
namespace views { namespace views {
// A view at the embedder side to embed an aura::Window from another window // A view at the embedder side to embed an aura::Window from another window
...@@ -52,6 +56,10 @@ class RemoteViewHost : public views::NativeViewHost { ...@@ -52,6 +56,10 @@ class RemoteViewHost : public views::NativeViewHost {
EmbedCallback embed_callback_; EmbedCallback embed_callback_;
const std::unique_ptr<aura::Window> embedding_root_; const std::unique_ptr<aura::Window> embedding_root_;
#if defined(OS_CHROMEOS)
std::unique_ptr<wm::EnsureWindowNotInRectHelper> helper_;
#endif
base::WeakPtrFactory<RemoteViewHost> weak_ptr_factory_{this}; base::WeakPtrFactory<RemoteViewHost> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(RemoteViewHost); DISALLOW_COPY_AND_ASSIGN(RemoteViewHost);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ui/wm/core/ime_util_chromeos.h" #include "ui/wm/core/ime_util_chromeos.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/mus/window_mus.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
...@@ -59,10 +60,12 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, ...@@ -59,10 +60,12 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect,
nullptr) nullptr)
void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) { void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) {
window->GetRootWindow()->ClearProperty(
aura::client::kEmbeddedWindowEnsureNotInRect);
// Get restore bounds of the window // Get restore bounds of the window
gfx::Rect* vk_restore_bounds = gfx::Rect* vk_restore_bounds =
window->GetProperty(kVirtualKeyboardRestoreBoundsKey); window->GetProperty(kVirtualKeyboardRestoreBoundsKey);
if (!vk_restore_bounds) if (!vk_restore_bounds)
return; return;
...@@ -77,6 +80,16 @@ void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) { ...@@ -77,6 +80,16 @@ void RestoreWindowBoundsOnClientFocusLost(aura::Window* window) {
void EnsureWindowNotInRect(aura::Window* window, void EnsureWindowNotInRect(aura::Window* window,
const gfx::Rect& rect_in_screen) { const gfx::Rect& rect_in_screen) {
// If |window| is embedded, the move should happen at the embedding side.
if (auto* window_mus = aura::WindowMus::Get(window->GetRootWindow())) {
if (window_mus->window_mus_type() == aura::WindowMusType::EMBED) {
window->GetRootWindow()->SetProperty(
aura::client::kEmbeddedWindowEnsureNotInRect,
new gfx::Rect(rect_in_screen));
return;
}
}
gfx::Rect original_window_bounds = window->GetBoundsInScreen(); gfx::Rect original_window_bounds = window->GetBoundsInScreen();
if (window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey)) { if (window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey)) {
original_window_bounds = original_window_bounds =
...@@ -95,4 +108,37 @@ void EnsureWindowNotInRect(aura::Window* window, ...@@ -95,4 +108,37 @@ void EnsureWindowNotInRect(aura::Window* window,
MoveWindowToEnsureCaretNotInRect(window, rect_in_screen); MoveWindowToEnsureCaretNotInRect(window, rect_in_screen);
} }
EnsureWindowNotInRectHelper::EnsureWindowNotInRectHelper(
aura::Window* embedding_root)
: embedding_root_(embedding_root) {
embedding_root_->AddObserver(this);
}
EnsureWindowNotInRectHelper::~EnsureWindowNotInRectHelper() {
if (embedding_root_)
embedding_root_->RemoveObserver(this);
}
void EnsureWindowNotInRectHelper::OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) {
DCHECK_EQ(embedding_root_, window);
if (key != aura::client::kEmbeddedWindowEnsureNotInRect)
return;
aura::Window* top_level = embedding_root_->GetToplevelWindow();
gfx::Rect* rect_in_screen = embedding_root_->GetProperty(
aura::client::kEmbeddedWindowEnsureNotInRect);
if (rect_in_screen)
EnsureWindowNotInRect(top_level, *rect_in_screen);
else
RestoreWindowBoundsOnClientFocusLost(top_level);
}
void EnsureWindowNotInRectHelper::OnWindowDestroyed(aura::Window* window) {
DCHECK_EQ(embedding_root_, window);
embedding_root_ = nullptr;
}
} // namespace wm } // namespace wm
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define UI_WM_CORE_IME_UTIL_CHROMEOS_H_ #define UI_WM_CORE_IME_UTIL_CHROMEOS_H_
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/wm/core/wm_core_export.h" #include "ui/wm/core/wm_core_export.h"
namespace gfx { namespace gfx {
...@@ -19,8 +20,11 @@ namespace wm { ...@@ -19,8 +20,11 @@ namespace wm {
WM_CORE_EXPORT extern const aura::WindowProperty<gfx::Rect*>* const WM_CORE_EXPORT extern const aura::WindowProperty<gfx::Rect*>* const
kVirtualKeyboardRestoreBoundsKey; kVirtualKeyboardRestoreBoundsKey;
// Moves the window, if needed, to ensure it does not intersect with // Moves |window| to ensure it does not intersect with |rect_in_screen| if it
// |rect_in_screen|. // does not belong to an embedded window tree. Otherwise, sets |rect_in_screen|
// in kEmbeddedWindowEnsureNotInRect window property on the root window of the
// embedded tree so that the embedding side could forward the call to the
// relevant top level window. See also EnsureWindowNotInRectHelper.
WM_CORE_EXPORT void EnsureWindowNotInRect(aura::Window* window, WM_CORE_EXPORT void EnsureWindowNotInRect(aura::Window* window,
const gfx::Rect& rect_in_screen); const gfx::Rect& rect_in_screen);
...@@ -28,6 +32,25 @@ WM_CORE_EXPORT void EnsureWindowNotInRect(aura::Window* window, ...@@ -28,6 +32,25 @@ WM_CORE_EXPORT void EnsureWindowNotInRect(aura::Window* window,
WM_CORE_EXPORT void RestoreWindowBoundsOnClientFocusLost( WM_CORE_EXPORT void RestoreWindowBoundsOnClientFocusLost(
aura::Window* top_level_window); aura::Window* top_level_window);
// Helper to call EnsureWindowNotInRect/RestoreWindowBoundsOnClientFocusLost
// on the top-level window of an embedding root when its
// kEmbeddedWindowEnsureNotInRect window property changes.
class WM_CORE_EXPORT EnsureWindowNotInRectHelper : public aura::WindowObserver {
public:
explicit EnsureWindowNotInRectHelper(aura::Window* embedding_root);
~EnsureWindowNotInRectHelper() override;
private:
// aura::WindowObsever:
void OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) override;
void OnWindowDestroyed(aura::Window* window) override;
aura::Window* embedding_root_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(EnsureWindowNotInRectHelper);
};
} // namespace wm } // namespace wm
#endif // UI_WM_CORE_IME_UTIL_CHROMEOS_H_ #endif // UI_WM_CORE_IME_UTIL_CHROMEOS_H_
...@@ -6,7 +6,11 @@ ...@@ -6,7 +6,11 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/mus/embed_root.h"
#include "ui/aura/mus/embed_root_delegate.h"
#include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/mus/window_tree_client_test_api.h"
#include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_windows.h" #include "ui/aura/test/test_windows.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
...@@ -148,4 +152,76 @@ TEST_F(ImeUtilChromeosTest, MoveUpThenRestore) { ...@@ -148,4 +152,76 @@ TEST_F(ImeUtilChromeosTest, MoveUpThenRestore) {
EXPECT_EQ(original_bounds, window->GetBoundsInScreen()); EXPECT_EQ(original_bounds, window->GetBoundsInScreen());
} }
// Tests that setting/clearing kEmbeddedWindowEnsureNotInRect window property
// triggers the relevant top level to be moved/restored.
TEST_F(ImeUtilChromeosTest, EnsureWindowNotInRectHelper) {
const gfx::Rect original_bounds(10, 10, 100, 100);
aura::Window* top_level = aura::test::CreateTestWindow(
SK_ColorWHITE, 1, original_bounds, root_window());
aura::Window* embedding_root = aura::test::CreateTestWindowWithBounds(
gfx::Rect(original_bounds.size()), top_level);
EnsureWindowNotInRectHelper helper(embedding_root);
gfx::Rect occluded_rect(50, 50, 200, 200);
embedding_root->SetProperty(aura::client::kEmbeddedWindowEnsureNotInRect,
new gfx::Rect(occluded_rect));
EXPECT_EQ(gfx::Rect(10, 0, 100, 100), top_level->bounds());
embedding_root->ClearProperty(aura::client::kEmbeddedWindowEnsureNotInRect);
EXPECT_EQ(original_bounds, top_level->bounds());
}
class TestEmbedRootDelegate : public aura::EmbedRootDelegate {
public:
TestEmbedRootDelegate() = default;
~TestEmbedRootDelegate() override = default;
// EmbedRootDelegate:
void OnEmbedTokenAvailable(const base::UnguessableToken& token) override {}
void OnEmbed(aura::Window* window) override {}
void OnUnembed() override {}
private:
DISALLOW_COPY_AND_ASSIGN(TestEmbedRootDelegate);
};
class ImeUtilChromeosEmbeddedTest : public ImeUtilChromeosTest {
public:
ImeUtilChromeosEmbeddedTest() = default;
~ImeUtilChromeosEmbeddedTest() override = default;
// ImeUtilChromeosTest:
void SetUp() override {
EnableMusWithTestWindowTree();
ImeUtilChromeosTest::SetUp();
}
private:
DISALLOW_COPY_AND_ASSIGN(ImeUtilChromeosEmbeddedTest);
};
// Tests that EnsureWindowNotInRect on an embedded window sets the
// kEmbeddedWindowEnsureNotInRect property on the embedded root window and
// RestoreWindowBoundsOnClientFocusLost resets the property.
TEST_F(ImeUtilChromeosEmbeddedTest, EnsureWindowNotInRect) {
// Simulates embedding and create an embedded root.
TestEmbedRootDelegate embed_root_delegate;
std::unique_ptr<aura::EmbedRoot> embed_root =
window_tree_client_impl()->CreateEmbedRoot(&embed_root_delegate);
aura::WindowTreeClientTestApi(window_tree_client_impl())
.CallOnEmbedFromToken(embed_root.get());
ASSERT_TRUE(embed_root->window());
// EnsureWindowNotInRect on embedded window sets the property.
gfx::Rect occluded_rect(50, 50, 200, 200);
EnsureWindowNotInRect(embed_root->window(), occluded_rect);
EXPECT_EQ(occluded_rect, *embed_root->window()->GetProperty(
aura::client::kEmbeddedWindowEnsureNotInRect));
// RestoreWindowBoundsOnClientFocusLost clears the property.
RestoreWindowBoundsOnClientFocusLost(embed_root->window());
EXPECT_EQ(nullptr, embed_root->window()->GetProperty(
aura::client::kEmbeddedWindowEnsureNotInRect));
}
} // namespace wm } // namespace wm
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