Commit a4a6d0e3 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Refactor ShellSurface into base (ShellSurface), XdgShellSurface and ClientControlledShellSurface.

Moved methods that are meaningful for xdg to XdgShellSurface, and ones for remote_shell to ClientControlledShellSurface.

Updated the unit test to use the correct ShellSurface instance.
I found that a few tests used wrong one (that never actually used in real scenario), so I fixed them.
There is one test that was failing because it's testing the scenario that does not exist. I'll
fix it in a follow up CL.

Bug: 773461
Change-Id: I91124da7c6274cd3dabc2e49e2abca1034dadffd
Reviewed-on: https://chromium-review.googlesource.com/770454
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520717}
parent 343c3263
......@@ -10,6 +10,8 @@ source_set("exo") {
sources = [
"buffer.cc",
"buffer.h",
"client_controlled_shell_surface.cc",
"client_controlled_shell_surface.h",
"data_device.cc",
"data_device.h",
"data_device_delegate.h",
......@@ -58,6 +60,8 @@ source_set("exo") {
"touch_delegate.h",
"wm_helper.cc",
"wm_helper.h",
"xdg_shell_surface.cc",
"xdg_shell_surface.h",
]
deps = [
......
This diff is collapsed.
// Copyright 2017 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 COMPONENTS_EXO_CLIENT_CONTROLLED_SHELL_SURFACE_H_
#define COMPONENTS_EXO_CLIENT_CONTROLLED_SHELL_SURFACE_H_
#include <memory>
#include <string>
#include "ash/display/window_tree_host_manager.h"
#include "base/macros.h"
#include "components/exo/shell_surface.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/compositor_lock.h"
#include "ui/display/display_observer.h"
namespace ash {
namespace mojom {
enum class WindowPinType;
}
} // namespace ash
namespace exo {
class Surface;
enum class Orientation { PORTRAIT, LANDSCAPE };
// This class implements shell surface for remote shell protocol. It's
// window state, bounds are controlled by the client rather than window
// manager.
class ClientControlledShellSurface
: public ShellSurface,
public display::DisplayObserver,
public ash::WindowTreeHostManager::Observer,
public ui::CompositorLockClient {
public:
ClientControlledShellSurface(Surface* surface,
bool can_minimize,
int container);
~ClientControlledShellSurface() override;
// Overridden from ShellSurface:
void InitializeWindowState(ash::wm::WindowState* window_state) override;
void AttemptToStartDrag(int component) override;
void UpdateBackdrop() override;
// Pin/unpin the surface. Pinned surface cannot be switched to
// other windows unless its explicitly unpinned.
void SetPinned(ash::mojom::WindowPinType type);
// Sets the surface to be on top of all other windows.
void SetAlwaysOnTop(bool always_on_top);
// Controls the visibility of the system UI when this surface is active.
void SetSystemUiVisibility(bool autohide);
// Set orientation for surface.
void SetOrientation(Orientation orientation);
// Set shadow bounds in surface coordinates. Empty bounds disable the shadow.
void SetShadowBounds(const gfx::Rect& bounds);
void SetScale(double scale);
// Set top inset for surface.
void SetTopInset(int height);
// Overridden from ShellSurface:
void Move() override;
void Resize(int component) override;
float GetScale() const override;
// Overridden from SurfaceDelegate:
void OnSurfaceCommit() override;
// Overridden from views::WidgetDelegate:
void SaveWindowPlacement(const gfx::Rect& bounds,
ui::WindowShowState show_state) override;
bool GetSavedWindowPlacement(const views::Widget* widget,
gfx::Rect* bounds,
ui::WindowShowState* show_state) const override;
// Overridden from aura::WindowObserver:
void OnWindowBoundsChanged(aura::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds,
ui::PropertyChangeReason reason) override;
// Overridden from display::DisplayObserver:
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) override;
// Overridden from ash::WindowTreeHostManager::Observer:
void OnDisplayConfigurationChanged() override;
// Overridden from ui::CompositorLockClient:
void CompositorLockTimedOut() override;
private:
// Lock the compositor if it's not already locked, or extends the
// lock timeout if it's already locked.
// TODO(reveman): Remove this when using configure callbacks for orientation.
// crbug.com/765954
void EnsureCompositorIsLockedForOrientationChange();
int64_t primary_display_id_;
int top_inset_height_ = 0;
int pending_top_inset_height_ = 0;
double scale_ = 1.0;
double pending_scale_ = 1.0;
// TODO(reveman): Use configure callbacks for orientation. crbug.com/765954
Orientation pending_orientation_ = Orientation::LANDSCAPE;
Orientation orientation_ = Orientation::LANDSCAPE;
Orientation expected_orientation_ = Orientation::LANDSCAPE;
std::unique_ptr<ui::CompositorLock> orientation_compositor_lock_;
DISALLOW_COPY_AND_ASSIGN(ClientControlledShellSurface);
};
} // namespace exo
#endif // COMPONENTS_EXO_CLIENT_CONTROLLED_SHELL_SURFACE_H_
......@@ -12,6 +12,7 @@
#include "base/memory/ptr_util.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_argument.h"
#include "components/exo/client_controlled_shell_surface.h"
#include "components/exo/data_device.h"
#include "components/exo/file_helper.h"
#include "components/exo/notification_surface.h"
......@@ -20,6 +21,7 @@
#include "components/exo/shell_surface.h"
#include "components/exo/sub_surface.h"
#include "components/exo/surface.h"
#include "components/exo/xdg_shell_surface.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/coordinate_conversion.h"
......@@ -138,19 +140,34 @@ std::unique_ptr<Buffer> Display::CreateLinuxDMABufBuffer(
std::unique_ptr<ShellSurface> Display::CreateShellSurface(Surface* surface) {
TRACE_EVENT1("exo", "Display::CreateShellSurface", "surface",
surface->AsTracedValue());
if (surface->HasSurfaceDelegate()) {
DLOG(ERROR) << "Surface has already been assigned a role";
return nullptr;
}
return std::make_unique<ShellSurface>(
surface, nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(),
surface, ShellSurface::BoundsMode::SHELL, gfx::Point(),
true /* activatable */, false /* can_minimize */,
ash::kShellWindowId_DefaultContainer);
}
std::unique_ptr<XdgShellSurface> Display::CreateXdgShellSurface(
Surface* surface) {
TRACE_EVENT1("exo", "Display::CreateXdgShellSurface", "surface",
surface->AsTracedValue());
if (surface->HasSurfaceDelegate()) {
DLOG(ERROR) << "Surface has already been assigned a role";
return nullptr;
}
return std::make_unique<XdgShellSurface>(
surface, ShellSurface::BoundsMode::SHELL, gfx::Point(),
true /* activatable */, false /* can_minimize */,
ash::kShellWindowId_DefaultContainer);
}
std::unique_ptr<ShellSurface> Display::CreateRemoteShellSurface(
std::unique_ptr<ClientControlledShellSurface>
Display::CreateClientControlledShellSurface(
Surface* surface,
int container,
double default_device_scale_factor) {
......@@ -165,9 +182,9 @@ std::unique_ptr<ShellSurface> Display::CreateRemoteShellSurface(
// Remote shell surfaces in system modal container cannot be minimized.
bool can_minimize = container != ash::kShellWindowId_SystemModalContainer;
std::unique_ptr<ShellSurface> shell_surface(std::make_unique<ShellSurface>(
surface, nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(),
true /* activatable */, can_minimize, container));
std::unique_ptr<ClientControlledShellSurface> shell_surface(
std::make_unique<ClientControlledShellSurface>(surface, can_minimize,
container));
DCHECK_GE(default_device_scale_factor, 1.0);
shell_surface->SetScale(default_device_scale_factor);
return shell_surface;
......
......@@ -22,6 +22,7 @@
#endif
namespace exo {
class ClientControlledShellSurface;
class DataDevice;
class DataDeviceDelegate;
class FileHelper;
......@@ -31,6 +32,7 @@ class SharedMemory;
class ShellSurface;
class SubSurface;
class Surface;
class XdgShellSurface;
#if defined(USE_OZONE)
class Buffer;
......@@ -67,12 +69,15 @@ class Display {
// Creates a shell surface for an existing surface.
std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface);
// Creates a xdg shell surface for an existing surface.
std::unique_ptr<XdgShellSurface> CreateXdgShellSurface(Surface* surface);
// Creates a remote shell surface for an existing surface using |container|.
// The surface is scaled by 1 / |default_device_scale_factor|.
std::unique_ptr<ShellSurface> CreateRemoteShellSurface(
Surface* surface,
int container,
double default_device_scale_factor);
std::unique_ptr<ClientControlledShellSurface>
CreateClientControlledShellSurface(Surface* surface,
int container,
double default_device_scale_factor);
// Creates a sub-surface for an existing surface. The sub-surface will be
// a child of |parent|.
......
......@@ -5,6 +5,7 @@
#include "components/exo/display.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "components/exo/buffer.h"
#include "components/exo/client_controlled_shell_surface.h"
#include "components/exo/data_device.h"
#include "components/exo/data_device_delegate.h"
#include "components/exo/file_helper.h"
......@@ -114,7 +115,7 @@ TEST_F(DisplayTest, CreateShellSurface) {
EXPECT_TRUE(shell_surface2);
}
TEST_F(DisplayTest, CreateRemoteShellSurface) {
TEST_F(DisplayTest, CreateClientControlledShellSurface) {
std::unique_ptr<Display> display(new Display);
// Create two surfaces.
......@@ -125,16 +126,16 @@ TEST_F(DisplayTest, CreateRemoteShellSurface) {
// Create a remote shell surface for surface1.
std::unique_ptr<ShellSurface> shell_surface1 =
display->CreateRemoteShellSurface(
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 =
display->CreateRemoteShellSurface(surface2.get(),
ash::kShellWindowId_DefaultContainer,
1.0 /* default_scale_factor */);
display->CreateClientControlledShellSurface(
surface2.get(), ash::kShellWindowId_DefaultContainer,
1.0 /* default_scale_factor */);
EXPECT_TRUE(shell_surface2);
}
......
......@@ -201,8 +201,9 @@ TEST_F(PointerTest, OnPointerMotion) {
std::unique_ptr<Surface> child_surface(new Surface);
std::unique_ptr<ShellSurface> child_shell_surface(new ShellSurface(
child_surface.get(), shell_surface.get(), ShellSurface::BoundsMode::FIXED,
gfx::Point(9, 9), true, false, ash::kShellWindowId_DefaultContainer));
child_surface.get(), ShellSurface::BoundsMode::FIXED, gfx::Point(9, 9),
true, false, ash::kShellWindowId_DefaultContainer));
child_shell_surface->SetParent(shell_surface.get());
gfx::Size child_buffer_size(15, 15);
std::unique_ptr<Buffer> child_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(child_buffer_size)));
......@@ -333,8 +334,8 @@ TEST_F(PointerTest, IgnorePointerEventDuringModal) {
// Create surface for modal window.
std::unique_ptr<Surface> surface2(new Surface);
std::unique_ptr<ShellSurface> shell_surface2(new ShellSurface(
surface2.get(), nullptr, ShellSurface::BoundsMode::FIXED, gfx::Point(),
true, false, ash::kShellWindowId_SystemModalContainer));
surface2.get(), ShellSurface::BoundsMode::FIXED, gfx::Point(), true,
false, ash::kShellWindowId_SystemModalContainer));
std::unique_ptr<Buffer> buffer2(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(gfx::Size(5, 5))));
surface2->Attach(buffer2.get());
......
This diff is collapsed.
This diff is collapsed.
......@@ -21,6 +21,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "components/exo/buffer.h"
#include "components/exo/client_controlled_shell_surface.h"
#include "components/exo/display.h"
#include "components/exo/sub_surface.h"
#include "components/exo/surface.h"
......@@ -87,13 +88,10 @@ class ShellSurfaceBoundsModeTest
}
std::unique_ptr<ShellSurface> CreateDefaultShellSurface(Surface* surface) {
if (IsClientBoundsMode()) {
return Display().CreateRemoteShellSurface(
surface, ash::kShellWindowId_DefaultContainer,
WMHelper::GetInstance()->GetDefaultDeviceScaleFactor());
} else {
if (IsClientBoundsMode())
return exo_test_helper()->CreateClientControlledShellSurface(surface);
else
return Display().CreateShellSurface(surface);
}
}
private:
......@@ -280,7 +278,8 @@ TEST_F(ShellSurfaceTest, SetPinned) {
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(new ShellSurface(surface.get()));
auto shell_surface(
exo_test_helper()->CreateClientControlledShellSurface(surface.get()));
shell_surface->SetPinned(ash::mojom::WindowPinType::TRUSTED_PINNED);
EXPECT_TRUE(IsWidgetPinned(shell_surface->GetWidget()));
......@@ -300,7 +299,8 @@ TEST_F(ShellSurfaceTest, SetSystemUiVisibility) {
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(new ShellSurface(surface.get()));
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
......@@ -492,7 +492,8 @@ TEST_F(ShellSurfaceTest, SetTopInset) {
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(new ShellSurface(surface.get()));
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
......@@ -616,9 +617,10 @@ TEST_F(ShellSurfaceTest, ConfigureCallback) {
TEST_F(ShellSurfaceTest, ModalWindowDefaultActive) {
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(),
true, false, ash::kShellWindowId_SystemModalContainer));
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get(),
/*is_modal=*/true);
gfx::Size desktop_size(640, 480);
std::unique_ptr<Buffer> desktop_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(desktop_size)));
......@@ -634,9 +636,8 @@ TEST_F(ShellSurfaceTest, ModalWindowDefaultActive) {
TEST_F(ShellSurfaceTest, UpdateModalWindow) {
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(),
true, false, ash::kShellWindowId_SystemModalContainer));
auto shell_surface = exo_test_helper()->CreateClientControlledShellSurface(
surface.get(), /*is_modal=*/true);
gfx::Size desktop_size(640, 480);
std::unique_ptr<Buffer> desktop_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(desktop_size)));
......@@ -701,9 +702,8 @@ TEST_F(ShellSurfaceTest, UpdateModalWindow) {
TEST_F(ShellSurfaceTest, ModalWindowSetSystemModalBeforeCommit) {
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(),
true, false, ash::kShellWindowId_SystemModalContainer));
auto shell_surface = exo_test_helper()->CreateClientControlledShellSurface(
surface.get(), /*is_modal=*/true);
gfx::Size desktop_size(640, 480);
std::unique_ptr<Buffer> desktop_buffer(
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(desktop_size)));
......@@ -732,9 +732,8 @@ TEST_F(ShellSurfaceTest, SurfaceShadow) {
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(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(),
true, false, ash::kShellWindowId_DefaultContainer));
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
......@@ -776,8 +775,12 @@ TEST_F(ShellSurfaceTest, SurfaceShadow) {
EXPECT_EQ(before, shadow->layer()->bounds());
// 4) Updating the widget's window bounds should not change the shadow bounds.
window->SetBounds(gfx::Rect(10, 10, 100, 100));
EXPECT_EQ(before, shadow->layer()->bounds());
// TODO(oshima): The following scenario only worked with Xdg/ShellSurface,
// which never uses SetShadowBounds. This is broken with correct scenario, and
// will be fixed when the bounds control is delegated to the client.
//
// window->SetBounds(gfx::Rect(10, 10, 100, 100));
// EXPECT_EQ(before, shadow->layer()->bounds());
// 5) This should disable shadow.
shell_surface->SetShadowBounds(gfx::Rect());
......@@ -800,8 +803,8 @@ TEST_F(ShellSurfaceTest, NonSurfaceShadow) {
new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::SHELL, gfx::Point(),
true, false, ash::kShellWindowId_DefaultContainer));
surface.get(), ShellSurface::BoundsMode::SHELL, gfx::Point(), true, false,
ash::kShellWindowId_DefaultContainer));
surface->Attach(buffer.get());
surface->Commit();
......@@ -869,9 +872,8 @@ TEST_F(ShellSurfaceTest, ShadowWithStateChange) {
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(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(),
true, false, ash::kShellWindowId_DefaultContainer));
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
// Postion the widget at 10,10 so that we get non zero offset.
const gfx::Size content_size(100, 100);
......@@ -928,9 +930,8 @@ TEST_F(ShellSurfaceTest, ShadowWithTransform) {
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(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(),
true, false, ash::kShellWindowId_DefaultContainer));
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
// Postion the widget at 10,10 so that we get non zero offset.
const gfx::Size content_size(100, 100);
......@@ -957,9 +958,8 @@ TEST_F(ShellSurfaceTest, ShadowWithTransform) {
TEST_F(ShellSurfaceTest, ShadowStartMaximized) {
std::unique_ptr<Surface> surface(new Surface);
std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(),
true, false, ash::kShellWindowId_DefaultContainer));
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
shell_surface->Maximize();
views::Widget* widget = shell_surface->GetWidget();
aura::Window* window = widget->GetNativeWindow();
......@@ -1034,9 +1034,8 @@ TEST_F(ShellSurfaceTest, CompositorLockInRotation) {
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(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(),
true, false, ash::kShellWindowId_DefaultContainer));
auto shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
ash::Shell* shell = ash::Shell::Get();
shell->tablet_mode_controller()->EnableTabletModeWindowManager(true);
......@@ -1073,9 +1072,8 @@ TEST_F(ShellSurfaceTest, 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(new ShellSurface(
surface.get(), nullptr, ShellSurface::BoundsMode::CLIENT, gfx::Point(),
true, false, ash::kShellWindowId_DefaultContainer));
std::unique_ptr<ShellSurface> shell_surface =
exo_test_helper()->CreateClientControlledShellSurface(surface.get());
surface->Attach(buffer.get());
surface->Commit();
......
......@@ -4,12 +4,17 @@
#include "components/exo/test/exo_test_helper.h"
#include <memory>
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/wm/window_positioner.h"
#include "ash/wm/window_positioning_utils.h"
#include "components/exo/buffer.h"
#include "components/exo/shell_surface.h"
#include "components/exo/client_controlled_shell_surface.h"
#include "components/exo/display.h"
#include "components/exo/surface.h"
#include "components/exo/wm_helper.h"
#include "components/exo/xdg_shell_surface.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
#include "ui/aura/env.h"
#include "ui/compositor/compositor.h"
......@@ -26,9 +31,9 @@ ExoTestWindow::ExoTestWindow(std::unique_ptr<gfx::GpuMemoryBuffer> gpu_buffer,
surface_.reset(new Surface());
int container = is_modal ? ash::kShellWindowId_SystemModalContainer
: ash::kShellWindowId_DefaultContainer;
shell_surface_.reset(new ShellSurface(surface_.get(), nullptr,
ShellSurface::BoundsMode::SHELL,
gfx::Point(), true, false, container));
shell_surface_ = std::make_unique<ShellSurface>(
surface_.get(), ShellSurface::BoundsMode::SHELL, gfx::Point(), true,
false, container);
buffer_.reset(new Buffer(std::move(gpu_buffer)));
surface_->Attach(buffer_.get());
......@@ -75,5 +80,15 @@ ExoTestWindow ExoTestHelper::CreateWindow(int width,
is_modal);
}
std::unique_ptr<ClientControlledShellSurface>
ExoTestHelper::CreateClientControlledShellSurface(Surface* surface,
bool is_modal) {
int container = is_modal ? ash::kShellWindowId_SystemModalContainer
: ash::kShellWindowId_DefaultContainer;
return Display().CreateClientControlledShellSurface(
surface, container,
WMHelper::GetInstance()->GetDefaultDeviceScaleFactor());
}
} // namespace test
} // namespace exo
......@@ -19,6 +19,7 @@ class GpuMemoryBuffer;
namespace exo {
class Buffer;
class ClientControlledShellSurface;
class Surface;
class ShellSurface;
......@@ -54,6 +55,8 @@ class ExoTestHelper {
// Creates window of size (width, height) at center of screen.
ExoTestWindow CreateWindow(int width, int height, bool is_modal);
std::unique_ptr<ClientControlledShellSurface>
CreateClientControlledShellSurface(Surface* surface, bool is_modal = false);
private:
DISALLOW_COPY_AND_ASSIGN(ExoTestHelper);
......
......@@ -54,6 +54,7 @@
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/exo/buffer.h"
#include "components/exo/client_controlled_shell_surface.h"
#include "components/exo/data_device.h"
#include "components/exo/data_device_delegate.h"
#include "components/exo/data_offer.h"
......@@ -81,6 +82,7 @@
#include "components/exo/touch_delegate.h"
#include "components/exo/touch_stylus_delegate.h"
#include "components/exo/wm_helper.h"
#include "components/exo/xdg_shell_surface.h"
#include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom.h"
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/base/class_property.h"
......@@ -1409,7 +1411,7 @@ class WaylandToplevel : public aura::WindowObserver {
public:
WaylandToplevel(wl_resource* resource, wl_resource* surface_resource)
: resource_(resource),
shell_surface_(GetUserDataAs<ShellSurface>(surface_resource)),
shell_surface_(GetUserDataAs<XdgShellSurface>(surface_resource)),
weak_ptr_factory_(this) {
shell_surface_->host_window()->AddObserver(this);
shell_surface_->set_close_callback(
......@@ -1528,7 +1530,7 @@ class WaylandToplevel : public aura::WindowObserver {
}
wl_resource* const resource_;
ShellSurface* shell_surface_;
XdgShellSurface* shell_surface_;
base::WeakPtrFactory<WaylandToplevel> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(WaylandToplevel);
......@@ -1717,7 +1719,7 @@ void xdg_surface_v6_get_popup(wl_client* client,
uint32_t id,
wl_resource* parent_resource,
wl_resource* positioner_resource) {
ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource);
XdgShellSurface* shell_surface = GetUserDataAs<XdgShellSurface>(resource);
if (shell_surface->enabled()) {
wl_resource_post_error(resource, ZXDG_SURFACE_V6_ERROR_ALREADY_CONSTRUCTED,
"surface has already been constructed");
......@@ -1796,7 +1798,7 @@ void xdg_shell_v6_get_xdg_surface(wl_client* client,
uint32_t id,
wl_resource* surface) {
std::unique_ptr<ShellSurface> shell_surface =
GetUserDataAs<Display>(resource)->CreateShellSurface(
GetUserDataAs<Display>(resource)->CreateXdgShellSurface(
GetUserDataAs<Surface>(surface));
if (!shell_surface) {
wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_ROLE,
......@@ -1862,7 +1864,7 @@ void remote_surface_set_window_geometry(wl_client* client,
void remote_surface_set_orientation(wl_client* client,
wl_resource* resource,
int32_t orientation) {
GetUserDataAs<ShellSurface>(resource)->SetOrientation(
GetUserDataAs<ClientControlledShellSurface>(resource)->SetOrientation(
orientation == ZCR_REMOTE_SURFACE_V1_ORIENTATION_PORTRAIT
? Orientation::PORTRAIT
: Orientation::LANDSCAPE);
......@@ -1871,7 +1873,8 @@ void remote_surface_set_orientation(wl_client* client,
void remote_surface_set_scale(wl_client* client,
wl_resource* resource,
wl_fixed_t scale) {
GetUserDataAs<ShellSurface>(resource)->SetScale(wl_fixed_to_double(scale));
GetUserDataAs<ClientControlledShellSurface>(resource)->SetScale(
wl_fixed_to_double(scale));
}
void remote_surface_set_rectangular_shadow_DEPRECATED(wl_client* client,
......@@ -1900,7 +1903,7 @@ void remote_surface_set_title(wl_client* client,
void remote_surface_set_top_inset(wl_client* client,
wl_resource* resource,
int32_t height) {
GetUserDataAs<ShellSurface>(resource)->SetTopInset(height);
GetUserDataAs<ClientControlledShellSurface>(resource)->SetTopInset(height);
}
void remote_surface_activate(wl_client* client,
......@@ -1933,23 +1936,23 @@ void remote_surface_unfullscreen(wl_client* client, wl_resource* resource) {
void remote_surface_pin(wl_client* client,
wl_resource* resource,
int32_t trusted) {
GetUserDataAs<ShellSurface>(resource)->SetPinned(
GetUserDataAs<ClientControlledShellSurface>(resource)->SetPinned(
trusted ? ash::mojom::WindowPinType::TRUSTED_PINNED
: ash::mojom::WindowPinType::PINNED);
}
void remote_surface_unpin(wl_client* client, wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->SetPinned(
GetUserDataAs<ClientControlledShellSurface>(resource)->SetPinned(
ash::mojom::WindowPinType::NONE);
}
void remote_surface_set_system_modal(wl_client* client, wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->SetSystemModal(true);
GetUserDataAs<ClientControlledShellSurface>(resource)->SetSystemModal(true);
}
void remote_surface_unset_system_modal(wl_client* client,
wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->SetSystemModal(false);
GetUserDataAs<ClientControlledShellSurface>(resource)->SetSystemModal(false);
}
void remote_surface_set_rectangular_surface_shadow(wl_client* client,
......@@ -1958,25 +1961,26 @@ void remote_surface_set_rectangular_surface_shadow(wl_client* client,
int32_t y,
int32_t width,
int32_t height) {
ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource);
ClientControlledShellSurface* shell_surface =
GetUserDataAs<ClientControlledShellSurface>(resource);
shell_surface->SetShadowBounds(gfx::Rect(x, y, width, height));
}
void remote_surface_set_systemui_visibility(wl_client* client,
wl_resource* resource,
uint32_t visibility) {
GetUserDataAs<ShellSurface>(resource)->SetSystemUiVisibility(
GetUserDataAs<ClientControlledShellSurface>(resource)->SetSystemUiVisibility(
visibility != ZCR_REMOTE_SURFACE_V1_SYSTEMUI_VISIBILITY_STATE_VISIBLE);
}
void remote_surface_set_always_on_top(wl_client* client,
wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->SetAlwaysOnTop(true);
GetUserDataAs<ClientControlledShellSurface>(resource)->SetAlwaysOnTop(true);
}
void remote_surface_unset_always_on_top(wl_client* client,
wl_resource* resource) {
GetUserDataAs<ShellSurface>(resource)->SetAlwaysOnTop(false);
GetUserDataAs<ClientControlledShellSurface>(resource)->SetAlwaysOnTop(false);
}
void remote_surface_ack_configure(wl_client* client,
......@@ -2087,8 +2091,8 @@ class WaylandRemoteShell : public ash::TabletModeObserver,
Surface* surface,
int container,
double default_device_scale_factor) {
return display_->CreateRemoteShellSurface(surface, container,
default_device_scale_factor);
return display_->CreateClientControlledShellSurface(
surface, container, default_device_scale_factor);
}
std::unique_ptr<NotificationSurface> CreateNotificationSurface(
......
// Copyright 2017 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 "components/exo/xdg_shell_surface.h"
namespace exo {
////////////////////////////////////////////////////////////////////////////////
// XdgShellSurface, public:
XdgShellSurface::XdgShellSurface(Surface* surface,
BoundsMode bounds_mode,
const gfx::Point& origin,
bool activatable,
bool can_minimize,
int container)
: ShellSurface(surface,
bounds_mode,
origin,
activatable,
can_minimize,
container) {}
XdgShellSurface::~XdgShellSurface() {}
void XdgShellSurface::SetBoundsMode(BoundsMode mode) {
TRACE_EVENT1("exo", "XdgShellSurface::SetBoundsMode", "mode",
static_cast<int>(mode));
bounds_mode_ = mode;
}
} // namespace exo
// Copyright 2017 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 COMPONENTS_EXO_XDG_SHELL_SURFACE_H_
#define COMPONENTS_EXO_XDG_SHELL_SURFACE_H_
#include <cstdint>
#include <memory>
#include <string>
#include "ash/display/window_tree_host_manager.h"
#include "ash/wm/window_state_observer.h"
#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "components/exo/shell_surface.h"
#include "components/exo/surface_observer.h"
#include "components/exo/surface_tree_host.h"
#include "ui/aura/window_observer.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/compositor_lock.h"
#include "ui/display/display_observer.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/wm/public/activation_change_observer.h"
namespace ash {
namespace mojom {
enum class WindowPinType;
}
} // namespace ash
namespace exo {
class Surface;
// This class implements shell surface for XDG protocol.
class XdgShellSurface : public ShellSurface {
public:
// The |origin| is in screen coordinates. When bounds are controlled by the
// shell or fixed, it determines the initial position of the shell surface.
// In that case, the position specified as part of the geometry is relative
// to the shell surface.
// TODO(reveman|oshima): Remove bounds_mode.
XdgShellSurface(Surface* surface,
BoundsMode bounds_mode,
const gfx::Point& origin,
bool activatable,
bool can_minimize,
int container);
~XdgShellSurface() override;
// Set bounds mode for surface.
void SetBoundsMode(BoundsMode mode);
private:
DISALLOW_COPY_AND_ASSIGN(XdgShellSurface);
};
} // namespace exo
#endif // COMPONENTS_EXO_XDG_SHELL_SURFACE_H_
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