Skip to content

Commit 87e9510

Browse files
Toshiki KikuchiCommit Bot
Toshiki Kikuchi
authored and
Commit Bot
committed
exo: Add toast shell for ARC++ toasts
This CL introduces a new shell type for ARC++ toasts in remote-shell. Since the purpose of toasts is a notification for users and the toast appears and disappears quickly without any user interaction, so toasts are supposed to be shown over Chrome OS's virtual keyboard. ARC++ side CL: ag/11272597 design overview: go/vk-overlays-toasts BUG=b:109717200 TEST=ToastSurfaceTest Change-Id: I3cec22a031a7046ff63770ff308b6d0695c313e5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2167792 Commit-Queue: Toshiki Kikuchi <toshikikikuchi@chromium.org> Reviewed-by: Mitsuru Oshima <oshima@chromium.org> Reviewed-by: Yuichiro Hanada <yhanada@chromium.org> Cr-Commit-Position: refs/heads/master@{#786617}
1 parent f6ff7f6 commit 87e9510

18 files changed

+372
-10
lines changed

chrome/browser/exo_parts.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "chrome/common/chrome_switches.h"
2121
#include "components/exo/file_helper.h"
2222
#include "components/exo/server/wayland_server_controller.h"
23+
#include "components/exo/toast_surface_manager.h"
2324
#include "components/user_manager/user_manager.h"
2425
#include "content/public/browser/browser_thread.h"
2526
#include "content/public/common/drop_data.h"
@@ -125,7 +126,7 @@ ExoParts::ExoParts() {
125126
wayland_server_ = exo::WaylandServerController::CreateIfNecessary(
126127
std::make_unique<ChromeFileHelper>(),
127128
std::make_unique<ash::ArcNotificationSurfaceManagerImpl>(),
128-
std::make_unique<ash::ArcInputMethodSurfaceManager>());
129+
std::make_unique<ash::ArcInputMethodSurfaceManager>(), nullptr);
129130
ash::Shell::Get()->TrackInputMethodBounds(
130131
ash::ArcInputMethodBoundsTracker::Get());
131132
}

components/exo/BUILD.gn

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ static_library("exo") {
138138
"shell_surface_base.h",
139139
"text_input.cc",
140140
"text_input.h",
141+
"toast_surface.cc",
142+
"toast_surface.h",
143+
"toast_surface_manager.h",
141144
"wm_helper_chromeos.cc",
142145
"wm_helper_chromeos.h",
143146
"xdg_shell_surface.cc",
@@ -258,6 +261,7 @@ source_set("unit_tests") {
258261
"sub_surface_unittest.cc",
259262
"surface_unittest.cc",
260263
"text_input_unittest.cc",
264+
"toast_surface_unittest.cc",
261265
"touch_unittest.cc",
262266
"xdg_shell_surface_unittest.cc",
263267
]

components/exo/client_controlled_shell_surface.cc

+18
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,24 @@ void ClientControlledShellSurface::SetBounds(int64_t display_id,
349349
SetGeometry(bounds);
350350
}
351351

352+
void ClientControlledShellSurface::SetBoundsOrigin(const gfx::Point& origin) {
353+
TRACE_EVENT1("exo", "ClientControlledShellSurface::SetBoundsOrigin", "origin",
354+
origin.ToString());
355+
356+
pending_geometry_.set_origin(origin);
357+
}
358+
359+
void ClientControlledShellSurface::SetBoundsSize(const gfx::Size& size) {
360+
TRACE_EVENT1("exo", "ClientControlledShellSurface::SetBoundsSize", "size",
361+
size.ToString());
362+
363+
if (size.IsEmpty()) {
364+
DLOG(WARNING) << "Bounds size must be non-empty";
365+
return;
366+
}
367+
368+
pending_geometry_.set_size(size);
369+
}
352370
void ClientControlledShellSurface::SetMaximized() {
353371
TRACE_EVENT0("exo", "ClientControlledShellSurface::SetMaximized");
354372
pending_window_state_ = ash::WindowStateType::kMaximized;

components/exo/client_controlled_shell_surface.h

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class ClientControlledShellSurface : public ShellSurfaceBase,
6363
// Set bounds in root window coordinates relative to the given display.
6464
void SetBounds(int64_t display_id, const gfx::Rect& bounds);
6565

66+
// Set origin of bounds for surface while preserving the size.
67+
void SetBoundsOrigin(const gfx::Point& origin);
68+
69+
// Set size of bounds for surface while preserving the origin.
70+
void SetBoundsSize(const gfx::Size& size);
71+
6672
// Called when the client was maximized.
6773
void SetMaximized();
6874

components/exo/display.cc

+24
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include "components/exo/client_controlled_shell_surface.h"
4141
#include "components/exo/input_method_surface.h"
4242
#include "components/exo/shell_surface.h"
43+
#include "components/exo/toast_surface.h"
44+
#include "components/exo/toast_surface_manager.h"
4345
#include "components/exo/xdg_shell_surface.h"
4446
#endif
4547

@@ -60,9 +62,11 @@ Display::Display()
6062
Display::Display(
6163
std::unique_ptr<NotificationSurfaceManager> notification_surface_manager,
6264
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager,
65+
std::unique_ptr<ToastSurfaceManager> toast_surface_manager,
6366
std::unique_ptr<FileHelper> file_helper)
6467
: notification_surface_manager_(std::move(notification_surface_manager)),
6568
input_method_surface_manager_(std::move(input_method_surface_manager)),
69+
toast_surface_manager_(std::move(toast_surface_manager)),
6670
file_helper_(std::move(file_helper)),
6771
client_native_pixmap_factory_(
6872
gfx::CreateClientNativePixmapFactoryDmabuf()) {}
@@ -212,6 +216,26 @@ std::unique_ptr<InputMethodSurface> Display::CreateInputMethodSurface(
212216
input_method_surface_manager_.get(), surface,
213217
default_device_scale_factor);
214218
}
219+
220+
std::unique_ptr<ToastSurface> Display::CreateToastSurface(
221+
Surface* surface,
222+
double default_device_scale_factor) {
223+
TRACE_EVENT1("exo", "Display::CreateToastSurface", "surface",
224+
surface->AsTracedValue());
225+
226+
if (!toast_surface_manager_) {
227+
DLOG(ERROR) << "Toast surface cannot be registered";
228+
return nullptr;
229+
}
230+
231+
if (surface->HasSurfaceDelegate()) {
232+
DLOG(ERROR) << "Surface has already been assigned a role";
233+
return nullptr;
234+
}
235+
236+
return std::make_unique<ToastSurface>(toast_surface_manager_.get(), surface,
237+
default_device_scale_factor);
238+
}
215239
#endif // defined(OS_CHROMEOS)
216240

217241
std::unique_ptr<SubSurface> Display::CreateSubSurface(Surface* surface,

components/exo/display.h

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Surface;
4040
#if defined(OS_CHROMEOS)
4141
class InputMethodSurface;
4242
class ShellSurface;
43+
class ToastSurface;
44+
class ToastSurfaceManager;
4345
class XdgShellSurface;
4446
#endif
4547

@@ -58,6 +60,7 @@ class Display {
5860
Display(
5961
std::unique_ptr<NotificationSurfaceManager> notification_surface_manager,
6062
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager,
63+
std::unique_ptr<ToastSurfaceManager> toast_surface_manager,
6164
std::unique_ptr<FileHelper> file_helper);
6265
#endif // defined(OS_CHROMEOS)
6366

@@ -103,6 +106,11 @@ class Display {
103106
std::unique_ptr<InputMethodSurface> CreateInputMethodSurface(
104107
Surface* surface,
105108
double default_device_scale_factor);
109+
110+
// Creates a toast surface for a surface.
111+
std::unique_ptr<ToastSurface> CreateToastSurface(
112+
Surface* surface,
113+
double default_device_scale_factor);
106114
#endif // defined(OS_CHROMEOS)
107115

108116
// Creates a sub-surface for an existing surface. The sub-surface will be
@@ -126,6 +134,7 @@ class Display {
126134
#if defined(OS_CHROMEOS)
127135
std::unique_ptr<NotificationSurfaceManager> notification_surface_manager_;
128136
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager_;
137+
std::unique_ptr<ToastSurfaceManager> toast_surface_manager_;
129138
#endif // defined(OS_CHROMEOS)
130139

131140
std::unique_ptr<FileHelper> file_helper_;

components/exo/display_unittest.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "components/exo/sub_surface.h"
1919
#include "components/exo/surface.h"
2020
#include "components/exo/test/exo_test_base.h"
21+
#include "components/exo/toast_surface_manager.h"
2122
#include "testing/gtest/include/gtest/gtest.h"
2223

2324
#if defined(USE_OZONE)
@@ -241,7 +242,8 @@ class TestFileHelper : public FileHelper {
241242

242243
TEST_F(DisplayTest, CreateDataDevice) {
243244
TestDataDeviceDelegate device_delegate;
244-
Display display(nullptr, nullptr, std::make_unique<TestFileHelper>());
245+
Display display(nullptr, nullptr, nullptr,
246+
std::make_unique<TestFileHelper>());
245247

246248
std::unique_ptr<DataDevice> device =
247249
display.CreateDataDevice(&device_delegate);

components/exo/server/wayland_server_controller.cc

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "components/exo/file_helper.h"
1414
#include "components/exo/input_method_surface_manager.h"
1515
#include "components/exo/notification_surface_manager.h"
16+
#include "components/exo/toast_surface_manager.h"
1617
#include "components/exo/wayland/server.h"
1718
#include "components/exo/wayland/wayland_watcher.h"
1819
#include "components/exo/wm_helper.h"
@@ -25,10 +26,12 @@ std::unique_ptr<WaylandServerController>
2526
WaylandServerController::CreateIfNecessary(
2627
std::unique_ptr<FileHelper> file_helper,
2728
std::unique_ptr<NotificationSurfaceManager> notification_surface_manager,
28-
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager) {
29+
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager,
30+
std::unique_ptr<ToastSurfaceManager> toast_surface_manager) {
2931
return std::make_unique<WaylandServerController>(
3032
std::move(file_helper), std::move(notification_surface_manager),
31-
std::move(input_method_surface_manager));
33+
std::move(input_method_surface_manager),
34+
std::move(toast_surface_manager));
3235
}
3336

3437
WaylandServerController::~WaylandServerController() {
@@ -37,11 +40,13 @@ WaylandServerController::~WaylandServerController() {
3740
WaylandServerController::WaylandServerController(
3841
std::unique_ptr<FileHelper> file_helper,
3942
std::unique_ptr<NotificationSurfaceManager> notification_surface_manager,
40-
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager)
43+
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager,
44+
std::unique_ptr<ToastSurfaceManager> toast_surface_manager)
4145
: wm_helper_(std::make_unique<WMHelperChromeOS>()),
4246
display_(
4347
std::make_unique<Display>(std::move(notification_surface_manager),
4448
std::move(input_method_surface_manager),
49+
std::move(toast_surface_manager),
4550
std::move(file_helper))),
4651

4752
wayland_server_(wayland::Server::Create(display_.get())) {

components/exo/server/wayland_server_controller.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class FileHelper;
2121
class WMHelper;
2222
class NotificationSurfaceManager;
2323
class InputMethodSurfaceManager;
24+
class ToastSurfaceManager;
2425

2526
class WaylandServerController {
2627
public:
@@ -32,7 +33,8 @@ class WaylandServerController {
3233
static std::unique_ptr<WaylandServerController> CreateIfNecessary(
3334
std::unique_ptr<FileHelper> file_helper,
3435
std::unique_ptr<NotificationSurfaceManager> notification_surface_manager,
35-
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager);
36+
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager,
37+
std::unique_ptr<ToastSurfaceManager> toast_surface_manager);
3638

3739
~WaylandServerController();
3840

@@ -43,7 +45,8 @@ class WaylandServerController {
4345
WaylandServerController(
4446
std::unique_ptr<FileHelper> file_helper,
4547
std::unique_ptr<NotificationSurfaceManager> notification_surface_manager,
46-
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager);
48+
std::unique_ptr<InputMethodSurfaceManager> input_method_surface_manager,
49+
std::unique_ptr<ToastSurfaceManager> toast_surface_manager);
4750

4851
private:
4952
std::unique_ptr<WMHelper> wm_helper_;

components/exo/test/exo_test_helper.cc

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "components/exo/display.h"
1616
#include "components/exo/input_method_surface.h"
1717
#include "components/exo/surface.h"
18+
#include "components/exo/toast_surface.h"
1819
#include "components/exo/wm_helper.h"
1920
#include "components/exo/xdg_shell_surface.h"
2021
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
@@ -191,5 +192,21 @@ std::unique_ptr<InputMethodSurface> ExoTestHelper::CreateInputMethodSurface(
191192
return shell_surface;
192193
}
193194

195+
std::unique_ptr<ToastSurface> ExoTestHelper::CreateToastSurface(
196+
Surface* surface,
197+
ToastSurfaceManager* surface_manager) {
198+
auto shell_surface = std::make_unique<ToastSurface>(
199+
surface_manager, surface,
200+
WMHelper::GetInstance()->GetDefaultDeviceScaleFactor());
201+
202+
shell_surface->set_state_changed_callback(base::BindRepeating(
203+
&HandleWindowStateRequest, base::Unretained(shell_surface.get())));
204+
205+
shell_surface->set_bounds_changed_callback(
206+
base::BindRepeating(&HandleBoundsChangedRequest, shell_surface.get()));
207+
208+
return shell_surface;
209+
}
210+
194211
} // namespace test
195212
} // namespace exo

components/exo/test/exo_test_helper.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class InputMethodSurface;
2525
class InputMethodSurfaceManager;
2626
class Surface;
2727
class ShellSurface;
28+
class ToastSurface;
29+
class ToastSurfaceManager;
2830

2931
namespace test {
3032

@@ -63,6 +65,9 @@ class ExoTestHelper {
6365
std::unique_ptr<InputMethodSurface> CreateInputMethodSurface(
6466
Surface* surface,
6567
InputMethodSurfaceManager* surface_manager);
68+
std::unique_ptr<ToastSurface> CreateToastSurface(
69+
Surface* surface,
70+
ToastSurfaceManager* surface_manager);
6671

6772
private:
6873
DISALLOW_COPY_AND_ASSIGN(ExoTestHelper);

components/exo/toast_surface.cc

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "components/exo/toast_surface.h"
6+
7+
#include "ash/public/cpp/shell_window_ids.h"
8+
#include "components/exo/toast_surface_manager.h"
9+
#include "components/exo/wm_helper.h"
10+
#include "ui/base/class_property.h"
11+
#include "ui/gfx/geometry/dip_util.h"
12+
#include "ui/gfx/geometry/rect.h"
13+
#include "ui/views/accessibility/view_accessibility.h"
14+
15+
namespace exo {
16+
17+
ToastSurface::ToastSurface(ToastSurfaceManager* manager,
18+
Surface* surface,
19+
double default_device_scale_factor)
20+
: ClientControlledShellSurface(surface,
21+
false /* can_minimize */,
22+
ash::kShellWindowId_OverlayContainer),
23+
manager_(manager) {
24+
SetScale(default_device_scale_factor);
25+
SetActivatable(false);
26+
DisableMovement();
27+
host_window()->SetName("ExoToastSurface");
28+
}
29+
30+
ToastSurface::~ToastSurface() {
31+
if (added_to_manager_)
32+
manager_->RemoveSurface(this);
33+
}
34+
35+
void ToastSurface::OnSurfaceCommit() {
36+
ClientControlledShellSurface::OnSurfaceCommit();
37+
38+
if (!added_to_manager_) {
39+
added_to_manager_ = true;
40+
manager_->AddSurface(this);
41+
}
42+
}
43+
44+
} // namespace exo

components/exo/toast_surface.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef COMPONENTS_EXO_TOAST_SURFACE_H_
6+
#define COMPONENTS_EXO_TOAST_SURFACE_H_
7+
8+
#include "base/macros.h"
9+
#include "components/exo/client_controlled_shell_surface.h"
10+
#include "components/exo/surface_delegate.h"
11+
#include "components/exo/surface_observer.h"
12+
13+
namespace exo {
14+
15+
class ToastSurfaceManager;
16+
17+
// Handles toast surface role of a given surface.
18+
class ToastSurface : public ClientControlledShellSurface {
19+
public:
20+
ToastSurface(ToastSurfaceManager* manager,
21+
Surface* surface,
22+
double default_device_scale_factor);
23+
~ToastSurface() override;
24+
25+
// Overridden from SurfaceDelegate:
26+
void OnSurfaceCommit() override;
27+
28+
private:
29+
ToastSurfaceManager* const manager_;
30+
bool added_to_manager_ = false;
31+
32+
DISALLOW_COPY_AND_ASSIGN(ToastSurface);
33+
};
34+
35+
} // namespace exo
36+
37+
#endif // COMPONENTS_EXO_TOAST_SURFACE_H_
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef COMPONENTS_EXO_TOAST_SURFACE_MANAGER_H_
6+
#define COMPONENTS_EXO_TOAST_SURFACE_MANAGER_H_
7+
8+
namespace exo {
9+
10+
class ToastSurface;
11+
12+
class ToastSurfaceManager {
13+
public:
14+
virtual ~ToastSurfaceManager() = default;
15+
16+
// Adds an ToastSurface to the manager.
17+
virtual void AddSurface(ToastSurface* surface) = 0;
18+
19+
// Removes an ToastSurface from the manager.
20+
virtual void RemoveSurface(ToastSurface* surface) = 0;
21+
};
22+
23+
} // namespace exo
24+
25+
#endif // COMPONENTS_EXO_TOAST_SURFACE_MANAGER_H_

0 commit comments

Comments
 (0)