Commit 3e165790 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Introduce ShellSurfaceBase

Separated window state change methods into ShellSurface and ClientControlledShellSurface

Bug: 809488
Change-Id: Ifec29e7a7ce2df0dd3b3c4a606479682d9f60dc2
Reviewed-on: https://chromium-review.googlesource.com/814835
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523233}
parent 8a0e9ba9
......@@ -47,6 +47,8 @@ source_set("exo") {
"shared_memory.h",
"shell_surface.cc",
"shell_surface.h",
"shell_surface_base.cc",
"shell_surface_base.h",
"sub_surface.cc",
"sub_surface.h",
"surface.cc",
......
......@@ -26,9 +26,6 @@
#include "ui/display/screen.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/coordinate_conversion.h"
////#include "ui/wm/core/shadow.h"
//#include "ui/wm/core/shadow_controller.h"
//#include "ui/wm/core/shadow_types.h"
#include "ui/wm/core/window_util.h"
namespace exo {
......@@ -70,11 +67,7 @@ Orientation SizeToOrientation(const gfx::Size& size) {
ClientControlledShellSurface::ClientControlledShellSurface(Surface* surface,
bool can_minimize,
int container)
: ShellSurface(surface,
gfx::Point(),
true,
can_minimize,
container),
: ShellSurfaceBase(surface, gfx::Point(), true, can_minimize, container),
primary_display_id_(
display::Screen::GetScreen()->GetPrimaryDisplay().id()) {
WMHelper::GetInstance()->AddDisplayConfigurationObserver(this);
......@@ -86,6 +79,55 @@ ClientControlledShellSurface::~ClientControlledShellSurface() {
display::Screen::GetScreen()->RemoveObserver(this);
}
void ClientControlledShellSurface::SetMaximized() {
TRACE_EVENT0("exo", "ClientControlledShellSurface::SetMaximized");
if (!widget_)
CreateShellSurfaceWidget(ui::SHOW_STATE_MAXIMIZED);
// Note: This will ask client to configure its surface even if already
// maximized.
ScopedConfigure scoped_configure(this, true);
widget_->Maximize();
}
void ClientControlledShellSurface::SetMinimized() {
TRACE_EVENT0("exo", "ClientControlledShellSurface::SetMinimized");
if (!widget_)
CreateShellSurfaceWidget(ui::SHOW_STATE_MINIMIZED);
// Note: This will ask client to configure its surface even if already
// minimized.
ScopedConfigure scoped_configure(this, true);
widget_->Minimize();
}
void ClientControlledShellSurface::SetRestored() {
TRACE_EVENT0("exo", "ClientControlledShellSurface::SetRestored");
if (!widget_)
return;
// Note: This will ask client to configure its surface even if not already
// maximized or minimized.
ScopedConfigure scoped_configure(this, true);
widget_->Restore();
}
void ClientControlledShellSurface::SetFullscreen(bool fullscreen) {
TRACE_EVENT1("exo", "ClientControlledShellSurface::SetFullscreen",
"fullscreen", fullscreen);
if (!widget_)
CreateShellSurfaceWidget(ui::SHOW_STATE_FULLSCREEN);
// Note: This will ask client to configure its surface even if fullscreen
// state doesn't change.
ScopedConfigure scoped_configure(this, true);
widget_->SetFullscreen(fullscreen);
}
void ClientControlledShellSurface::SetPinned(ash::mojom::WindowPinType type) {
TRACE_EVENT1("exo", "ClientControlledShellSurface::SetPinned", "type",
static_cast<int>(type));
......@@ -160,7 +202,7 @@ void ClientControlledShellSurface::SetTopInset(int height) {
// SurfaceDelegate overrides:
void ClientControlledShellSurface::OnSurfaceCommit() {
ShellSurface::OnSurfaceCommit();
ShellSurfaceBase::OnSurfaceCommit();
if (widget_) {
// Apply new top inset height.
if (pending_top_inset_height_ != top_inset_height_) {
......@@ -280,7 +322,7 @@ void ClientControlledShellSurface::CompositorLockTimedOut() {
void ClientControlledShellSurface::SetWidgetBounds(const gfx::Rect& bounds) {
if (!resizer_) {
ShellSurface::SetWidgetBounds(bounds);
ShellSurfaceBase::SetWidgetBounds(bounds);
return;
}
......
......@@ -10,7 +10,7 @@
#include "ash/display/window_tree_host_manager.h"
#include "base/macros.h"
#include "components/exo/shell_surface.h"
#include "components/exo/shell_surface_base.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/compositor_lock.h"
#include "ui/display/display_observer.h"
......@@ -31,7 +31,7 @@ enum class Orientation { PORTRAIT, LANDSCAPE };
// position specified as part of the geometry is relative to the origin of
// the screen coordinate system.
class ClientControlledShellSurface
: public ShellSurface,
: public ShellSurfaceBase,
public display::DisplayObserver,
public ash::WindowTreeHostManager::Observer,
public ui::CompositorLockClient {
......@@ -41,6 +41,18 @@ class ClientControlledShellSurface
int container);
~ClientControlledShellSurface() override;
// Called when the client was maximized.
void SetMaximized();
// Called when the client was minimized.
void SetMinimized();
// Called when the client was restored.
void SetRestored();
// Called when the client chagned the fullscreen state.
void SetFullscreen(bool fullscreen);
// Pin/unpin the surface. Pinned surface cannot be switched to
// other windows unless its explicitly unpinned.
void SetPinned(ash::mojom::WindowPinType type);
......
......@@ -8,11 +8,14 @@
#include "ash/public/interfaces/window_pin_type.mojom.h"
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/shell_test_api.h"
#include "ash/system/tray/system_tray.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_positioning_utils.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/workspace_controller_test_api.h"
#include "components/exo/buffer.h"
#include "components/exo/display.h"
#include "components/exo/pointer.h"
......@@ -33,6 +36,12 @@ namespace exo {
namespace {
using ClientControlledShellSurfaceTest = test::ExoTestBase;
bool HasBackdrop() {
ash::WorkspaceController* wc =
ash::ShellTestApi(ash::Shell::Get()).workspace_controller();
return !!ash::WorkspaceControllerTestApi(wc).GetBackdropWindow();
}
bool IsWidgetPinned(views::Widget* widget) {
ash::mojom::WindowPinType type =
widget->GetNativeWindow()->GetProperty(ash::kWindowPinTypeKey);
......@@ -384,7 +393,7 @@ TEST_F(ClientControlledShellSurfaceTest, ShadowStartMaximized) {
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
shell_surface->Maximize();
shell_surface->SetMaximized();
views::Widget* widget = shell_surface->GetWidget();
aura::Window* window = widget->GetNativeWindow();
......@@ -417,7 +426,7 @@ TEST_F(ClientControlledShellSurfaceTest, CompositorLockInRotation) {
shell->tablet_mode_controller()->EnableTabletModeWindowManager(true);
// Start in maximized.
shell_surface->Maximize();
shell_surface->SetMaximized();
surface->Attach(buffer.get());
surface->Commit();
......@@ -449,7 +458,7 @@ TEST_F(ClientControlledShellSurfaceTest, KeyboardNavigationWithSystemTray) {
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface());
std::unique_ptr<ShellSurface> shell_surface =
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
......@@ -480,4 +489,171 @@ TEST_F(ClientControlledShellSurfaceTest, KeyboardNavigationWithSystemTray) {
system_tray->GetSystemBubble()->bubble_view()->GetWidget()->IsActive());
}
TEST_F(ClientControlledShellSurfaceTest, Maximize) {
gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface(
exo_test_helper()->CreateClientControlledShellSurface(surface.get()));
surface->Attach(buffer.get());
surface->Commit();
EXPECT_FALSE(HasBackdrop());
shell_surface->SetMaximized();
EXPECT_TRUE(HasBackdrop());
surface->Commit();
EXPECT_TRUE(HasBackdrop());
EXPECT_TRUE(shell_surface->GetWidget()->IsMaximized());
// Toggle maximize.
ash::wm::WMEvent maximize_event(ash::wm::WM_EVENT_TOGGLE_MAXIMIZE);
aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
ash::wm::GetWindowState(window)->OnWMEvent(&maximize_event);
EXPECT_FALSE(shell_surface->GetWidget()->IsMaximized());
EXPECT_FALSE(HasBackdrop());
ash::wm::GetWindowState(window)->OnWMEvent(&maximize_event);
EXPECT_TRUE(shell_surface->GetWidget()->IsMaximized());
EXPECT_TRUE(HasBackdrop());
}
TEST_F(ClientControlledShellSurfaceTest, Restore) {
gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface(
exo_test_helper()->CreateClientControlledShellSurface(surface.get()));
surface->Attach(buffer.get());
surface->Commit();
EXPECT_FALSE(HasBackdrop());
// Note: Remove contents to avoid issues with maximize animations in tests.
shell_surface->SetMaximized();
EXPECT_TRUE(HasBackdrop());
shell_surface->SetRestored();
EXPECT_FALSE(HasBackdrop());
}
TEST_F(ClientControlledShellSurfaceTest, SetFullscreen) {
gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface(
exo_test_helper()->CreateClientControlledShellSurface(surface.get()));
shell_surface->SetFullscreen(true);
surface->Attach(buffer.get());
surface->Commit();
EXPECT_TRUE(HasBackdrop());
shell_surface->SetFullscreen(false);
surface->Commit();
EXPECT_FALSE(HasBackdrop());
EXPECT_NE(CurrentContext()->bounds().ToString(),
shell_surface->GetWidget()->GetWindowBoundsInScreen().ToString());
}
TEST_F(ClientControlledShellSurfaceTest, ToggleFullscreen) {
gfx::Size buffer_size(256, 256);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface(
exo_test_helper()->CreateClientControlledShellSurface(surface.get()));
surface->Attach(buffer.get());
surface->Commit();
EXPECT_FALSE(HasBackdrop());
shell_surface->SetMaximized();
EXPECT_TRUE(HasBackdrop());
ash::wm::WMEvent event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN);
aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
// Enter fullscreen mode.
ash::wm::GetWindowState(window)->OnWMEvent(&event);
EXPECT_TRUE(HasBackdrop());
// Leave fullscreen mode.
ash::wm::GetWindowState(window)->OnWMEvent(&event);
EXPECT_TRUE(HasBackdrop());
}
TEST_F(ClientControlledShellSurfaceTest,
DefaultDeviceScaleFactorForcedScaleFactor) {
double scale = 1.5;
display::Display::SetForceDeviceScaleFactor(scale);
int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::Display::SetInternalDisplayId(display_id);
gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface(
exo_test_helper()->CreateClientControlledShellSurface(surface.get()));
surface->Attach(buffer.get());
surface->Commit();
gfx::Transform transform;
transform.Scale(1.0 / scale, 1.0 / scale);
EXPECT_EQ(
transform.ToString(),
shell_surface->host_window()->layer()->GetTargetTransform().ToString());
}
TEST_F(ClientControlledShellSurfaceTest,
DefaultDeviceScaleFactorFromDisplayManager) {
int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::Display::SetInternalDisplayId(display_id);
gfx::Size size(1920, 1080);
display::DisplayManager* display_manager =
ash::Shell::Get()->display_manager();
double scale = 1.25;
display::ManagedDisplayMode mode(size, 60.f, false /* overscan */,
true /*native*/, 1.0, scale);
mode.set_is_default(true);
display::ManagedDisplayInfo::ManagedDisplayModeList mode_list;
mode_list.push_back(mode);
display::ManagedDisplayInfo native_display_info(display_id, "test", false);
native_display_info.SetManagedDisplayModes(mode_list);
native_display_info.SetBounds(gfx::Rect(size));
native_display_info.set_device_scale_factor(scale);
std::vector<display::ManagedDisplayInfo> display_info_list;
display_info_list.push_back(native_display_info);
display_manager->OnNativeDisplaysChanged(display_info_list);
display_manager->UpdateInternalManagedDisplayModeListForTest();
gfx::Size buffer_size(64, 64);
std::unique_ptr<Buffer> buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
auto shell_surface(
exo_test_helper()->CreateClientControlledShellSurface(surface.get()));
surface->Attach(buffer.get());
surface->Commit();
gfx::Transform transform;
transform.Scale(1.0 / scale, 1.0 / scale);
EXPECT_EQ(
transform.ToString(),
shell_surface->host_window()->layer()->GetTargetTransform().ToString());
}
} // namespace exo
......@@ -125,14 +125,14 @@ TEST_F(DisplayTest, CreateClientControlledShellSurface) {
ASSERT_TRUE(surface2);
// Create a remote shell surface for surface1.
std::unique_ptr<ShellSurface> shell_surface1 =
std::unique_ptr<ShellSurfaceBase> shell_surface1 =
display->CreateClientControlledShellSurface(
surface1.get(), ash::kShellWindowId_SystemModalContainer,
2.0 /* default_scale_factor */);
EXPECT_TRUE(shell_surface1);
// Create a remote shell surface for surface2.
std::unique_ptr<ShellSurface> shell_surface2 =
std::unique_ptr<ShellSurfaceBase> shell_surface2 =
display->CreateClientControlledShellSurface(
surface2.get(), ash::kShellWindowId_DefaultContainer,
1.0 /* default_scale_factor */);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -1870,7 +1870,7 @@ void remote_surface_destroy(wl_client* client, wl_resource* resource) {
void remote_surface_set_app_id(wl_client* client,
wl_resource* resource,
const char* app_id) {
GetUserDataAs<ShellSurface>(resource)->SetApplicationId(app_id);
GetUserDataAs<ShellSurfaceBase>(resource)->SetApplicationId(app_id);
}
void remote_surface_set_window_geometry(wl_client* client,
......@@ -1879,7 +1879,7 @@ void remote_surface_set_window_geometry(wl_client* client,
int32_t y,
int32_t width,
int32_t height) {
GetUserDataAs<ShellSurface>(resource)->SetGeometry(
GetUserDataAs<ShellSurfaceBase>(resource)->SetGeometry(
gfx::Rect(x, y, width, height));
}
......@@ -1918,7 +1918,7 @@ void remote_surface_set_rectangular_shadow_background_opacity_DEPRECATED(
void remote_surface_set_title(wl_client* client,
wl_resource* resource,
const char* title) {
GetUserDataAs<ShellSurface>(resource)->SetTitle(
GetUserDataAs<ShellSurfaceBase>(resource)->SetTitle(
base::string16(base::UTF8ToUTF16(title)));
}
......@@ -1931,28 +1931,28 @@ void remote_surface_set_top_inset(wl_client* client,
void remote_surface_activate(wl_client* client,
wl_resource* resource,
uint32_t serial) {
ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource);
ShellSurfaceBase* shell_surface = GetUserDataAs<ShellSurfaceBase>(resource);
shell_surface->Activate();
}
void remote_surface_maximize(wl_client* client, wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->Maximize();
GetUserDataAs<ClientControlledShellSurface>(resource)->SetMaximized();
}
void remote_surface_minimize(wl_client* client, wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->Minimize();
GetUserDataAs<ClientControlledShellSurface>(resource)->SetMinimized();
}
void remote_surface_restore(wl_client* client, wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->Restore();
GetUserDataAs<ClientControlledShellSurface>(resource)->SetRestored();
}
void remote_surface_fullscreen(wl_client* client, wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->SetFullscreen(true);
GetUserDataAs<ClientControlledShellSurface>(resource)->SetFullscreen(true);
}
void remote_surface_unfullscreen(wl_client* client, wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->SetFullscreen(false);
GetUserDataAs<ClientControlledShellSurface>(resource)->SetFullscreen(false);
}
void remote_surface_pin(wl_client* client,
......@@ -2008,18 +2008,18 @@ void remote_surface_unset_always_on_top(wl_client* client,
void remote_surface_ack_configure(wl_client* client,
wl_resource* resource,
uint32_t serial) {
GetUserDataAs<ShellSurface>(resource)->AcknowledgeConfigure(serial);
GetUserDataAs<ShellSurfaceBase>(resource)->AcknowledgeConfigure(serial);
}
void remote_surface_move(wl_client* client, wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->Move();
GetUserDataAs<ClientControlledShellSurface>(resource)->Move();
}
void remote_surface_set_window_type(wl_client* client,
wl_resource* resource,
uint32_t type) {
if (type == ZCR_REMOTE_SURFACE_V1_WINDOW_TYPE_SYSTEM_UI) {
auto* widget = GetUserDataAs<ShellSurface>(resource)->GetWidget();
auto* widget = GetUserDataAs<ShellSurfaceBase>(resource)->GetWidget();
if (widget) {
widget->GetNativeWindow()->SetProperty(ash::kShowInOverviewKey, false);
......@@ -2109,7 +2109,7 @@ class WaylandRemoteShell : public ash::TabletModeObserver,
display::Screen::GetScreen()->RemoveObserver(this);
}
std::unique_ptr<ShellSurface> CreateShellSurface(
std::unique_ptr<ClientControlledShellSurface> CreateShellSurface(
Surface* surface,
int container,
double default_device_scale_factor) {
......@@ -2344,9 +2344,10 @@ void remote_shell_get_remote_surface(wl_client* client,
? GetDefaultDeviceScaleFactor()
: 1.0;
std::unique_ptr<ShellSurface> shell_surface = shell->CreateShellSurface(
GetUserDataAs<Surface>(surface), RemoteSurfaceContainer(container),
default_scale_factor);
std::unique_ptr<ClientControlledShellSurface> shell_surface =
shell->CreateShellSurface(GetUserDataAs<Surface>(surface),
RemoteSurfaceContainer(container),
default_scale_factor);
if (!shell_surface) {
wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V1_ERROR_ROLE,
"surface has already been assigned a role");
......
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