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

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

Issue 2723143002: Add unittests of ArcCustomNotificationView (Closed)
Patch Set: wip Created 3 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_impl.h ('k') | ui/arc/BUILD.gn » ('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_impl.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/controls/native/native_view_host.h"
15 #include "ui/views/widget/widget.h"
16
17 namespace exo {
18
19 namespace {
20
21 class CustomWindowDelegate : public aura::WindowDelegate {
22 public:
23 explicit CustomWindowDelegate(Surface* surface) : surface_(surface) {}
24 ~CustomWindowDelegate() override {}
25
26 // Overridden from aura::WindowDelegate:
27 gfx::Size GetMinimumSize() const override { return gfx::Size(); }
28 gfx::Size GetMaximumSize() const override { return gfx::Size(); }
29 void OnBoundsChanged(const gfx::Rect& old_bounds,
30 const gfx::Rect& new_bounds) override {}
31 gfx::NativeCursor GetCursor(const gfx::Point& point) override {
32 return surface_->GetCursor();
33 }
34 int GetNonClientComponent(const gfx::Point& point) const override {
35 return HTNOWHERE;
36 }
37 bool ShouldDescendIntoChildForEventHandling(
38 aura::Window* child,
39 const gfx::Point& location) override {
40 return true;
41 }
42 bool CanFocus() override { return true; }
43 void OnCaptureLost() override {}
44 void OnPaint(const ui::PaintContext& context) override {}
45 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
46 void OnWindowDestroying(aura::Window* window) override {}
47 void OnWindowDestroyed(aura::Window* window) override { delete this; }
48 void OnWindowTargetVisibilityChanged(bool visible) override {}
49 bool HasHitTestMask() const override { return surface_->HasHitTestMask(); }
50 void GetHitTestMask(gfx::Path* mask) const override {
51 surface_->GetHitTestMask(mask);
52 }
53 void OnKeyEvent(ui::KeyEvent* event) override {
54 // Propagates the key event upto the top-level views Widget so that we can
55 // trigger proper events in the views/ash level there. Event handling for
56 // Surfaces is done in a post event handler in keyboard.cc.
57 views::Widget* widget =
58 views::Widget::GetTopLevelWidgetForNativeView(surface_->window());
59 if (widget)
60 widget->OnKeyEvent(event);
61 }
62
63 private:
64 Surface* const surface_;
65
66 DISALLOW_COPY_AND_ASSIGN(CustomWindowDelegate);
67 };
68
69 } // namespace
70
71 NotificationSurfaceImpl::NotificationSurfaceImpl(
72 NotificationSurfaceManager* manager,
73 Surface* surface,
74 const std::string& notification_id)
75 : manager_(manager),
76 surface_(surface),
77 notification_id_(notification_id),
78 window_(new aura::Window(new CustomWindowDelegate(surface))) {
79 surface_->SetSurfaceDelegate(this);
80 surface_->AddSurfaceObserver(this);
81
82 window_->SetType(aura::client::WINDOW_TYPE_CONTROL);
83 window_->SetName("ExoNotificationSurface");
84 window_->Init(ui::LAYER_NOT_DRAWN);
85 window_->set_owned_by_parent(false);
86
87 // TODO(xiyuan): Fix after Surface no longer has an aura::Window.
88 window_->AddChild(surface_->window());
89 surface_->window()->Show();
90 }
91
92 NotificationSurfaceImpl::~NotificationSurfaceImpl() {
93 if (surface_) {
94 surface_->SetSurfaceDelegate(nullptr);
95 surface_->RemoveSurfaceObserver(this);
96 }
97 if (added_to_manager_)
98 manager_->RemoveSurface(this);
99 }
100
101 gfx::Size NotificationSurfaceImpl::GetSize() const {
102 return surface_->content_size();
103 }
104
105 void NotificationSurfaceImpl::AttachWindow(views::NativeViewHost* nvh) {
106 nvh->Attach(window_.get());
107 }
108
109 aura::Window* NotificationSurfaceImpl::GetWindow() const {
110 return window_.get();
111 }
112
113 const std::string& NotificationSurfaceImpl::GetNotificationId() const {
114 return notification_id_;
115 }
116
117 void NotificationSurfaceImpl::OnSurfaceCommit() {
118 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces();
119 surface_->CommitSurfaceHierarchy();
120
121 gfx::Rect bounds = window_->bounds();
122 if (bounds.size() != surface_->content_size()) {
123 bounds.set_size(surface_->content_size());
124 window_->SetBounds(bounds);
125 }
126
127 // Defer AddSurface until there are contents to show.
128 if (!added_to_manager_ && !surface_->content_size().IsEmpty()) {
129 added_to_manager_ = true;
130 manager_->AddSurface(this);
131 }
132 }
133
134 bool NotificationSurfaceImpl::IsSurfaceSynchronized() const {
135 return false;
136 }
137
138 void NotificationSurfaceImpl::OnSurfaceDestroying(Surface* surface) {
139 window_.reset();
140 surface->RemoveSurfaceObserver(this);
141 surface_ = nullptr;
142 }
143
144 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/notification_surface_impl.h ('k') | ui/arc/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698