Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: components/exo/notification_surface.cc

Issue 2065133002: exo: Implement notification surface support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notification-wayland-protocol
Patch Set: fix compile Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/notification_surface.h ('k') | components/exo/notification_surface_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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/notification_surface.h"
6
7 #include "components/exo/notification_surface_manager.h"
8 #include "components/exo/surface.h"
9 #include "ui/aura/window.h"
10 #include "ui/aura/window_delegate.h"
11 #include "ui/base/cursor/cursor.h"
12 #include "ui/base/hit_test.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace exo {
17
18 namespace {
19
20 class CustomWindowDelegate : public aura::WindowDelegate {
21 public:
22 explicit CustomWindowDelegate(Surface* surface) : surface_(surface) {}
23 ~CustomWindowDelegate() override {}
24
25 // Overridden from aura::WindowDelegate:
26 gfx::Size GetMinimumSize() const override { return gfx::Size(); }
27 gfx::Size GetMaximumSize() const override { return gfx::Size(); }
28 void OnBoundsChanged(const gfx::Rect& old_bounds,
29 const gfx::Rect& new_bounds) override {}
30 gfx::NativeCursor GetCursor(const gfx::Point& point) override {
31 // If surface has a cursor provider then return 'none' as cursor providers
32 // are responsible for drawing cursors. Use default cursor if no cursor
33 // provider is registered.
34 return surface_->HasCursorProvider() ? ui::kCursorNone : ui::kCursorNull;
35 }
36 int GetNonClientComponent(const gfx::Point& point) const override {
37 return HTNOWHERE;
38 }
39 bool ShouldDescendIntoChildForEventHandling(
40 aura::Window* child,
41 const gfx::Point& location) override {
42 return true;
43 }
44 bool CanFocus() override { return true; }
45 void OnCaptureLost() override {}
46 void OnPaint(const ui::PaintContext& context) override {}
47 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
48 void OnWindowDestroying(aura::Window* window) override {}
49 void OnWindowDestroyed(aura::Window* window) override { delete this; }
50 void OnWindowTargetVisibilityChanged(bool visible) override {}
51 bool HasHitTestMask() const override { return surface_->HasHitTestMask(); }
52 void GetHitTestMask(gfx::Path* mask) const override {
53 surface_->GetHitTestMask(mask);
54 }
55 void OnKeyEvent(ui::KeyEvent* event) override {
56 // Propagates the key event upto the top-level views Widget so that we can
57 // trigger proper events in the views/ash level there. Event handling for
58 // Surfaces is done in a post event handler in keyboard.cc.
59 views::Widget* widget =
60 views::Widget::GetTopLevelWidgetForNativeView(surface_->window());
61 if (widget)
62 widget->OnKeyEvent(event);
63 }
64
65 private:
66 Surface* const surface_;
67
68 DISALLOW_COPY_AND_ASSIGN(CustomWindowDelegate);
69 };
70
71 } // namespace
72
73 NotificationSurface::NotificationSurface(NotificationSurfaceManager* manager,
74 Surface* surface,
75 const std::string& notification_id)
76 : manager_(manager),
77 surface_(surface),
78 notification_id_(notification_id),
79 window_(new aura::Window(new CustomWindowDelegate(surface))) {
80 surface_->SetSurfaceDelegate(this);
81 surface_->AddSurfaceObserver(this);
82
83 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
84 window_->SetName("ExoNotificationSurface");
85 window_->Init(ui::LAYER_NOT_DRAWN);
86 window_->set_owned_by_parent(false);
87
88 // TODO(xiyuan): Fix after Surface no longer has an auar::Window.
89 window_->AddChild(surface_->window());
90 surface_->window()->Show();
91
92 manager_->AddSurface(this);
93 }
94
95 NotificationSurface::~NotificationSurface() {
96 if (surface_) {
97 surface_->SetSurfaceDelegate(nullptr);
98 surface_->RemoveSurfaceObserver(this);
99 }
100 manager_->RemoveSurface(this);
101 }
102
103 gfx::Size NotificationSurface::GetSize() const {
104 return surface_->content_size();
105 }
106
107 void NotificationSurface::OnSurfaceCommit() {
108 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces();
109 surface_->CommitSurfaceHierarchy();
110
111 gfx::Rect bounds = window_->bounds();
112 if (bounds.size() != surface_->content_size()) {
113 bounds.set_size(surface_->content_size());
114 window_->SetBounds(bounds);
115 }
116 }
117
118 bool NotificationSurface::IsSurfaceSynchronized() const {
119 return false;
120 }
121
122 void NotificationSurface::OnSurfaceDestroying(Surface* surface) {
123 window_.reset();
124 surface->RemoveSurfaceObserver(this);
125 surface_ = nullptr;
126 }
127
128 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/notification_surface.h ('k') | components/exo/notification_surface_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698