Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 if (manager_) | |
|
reveman
2016/06/23 16:34:53
nit: remove if statement after changing Display::C
xiyuan
2016/06/23 17:46:09
Done.
| |
| 93 manager_->AddSurface(this); | |
| 94 } | |
| 95 | |
| 96 NotificationSurface::~NotificationSurface() { | |
| 97 if (surface_) { | |
| 98 surface_->SetSurfaceDelegate(nullptr); | |
| 99 surface_->RemoveSurfaceObserver(this); | |
| 100 } | |
| 101 if (manager_) | |
|
reveman
2016/06/23 16:34:53
nit: remove if statement after changing Display::C
xiyuan
2016/06/23 17:46:09
Done.
| |
| 102 manager_->RemoveSurface(this); | |
| 103 } | |
| 104 | |
| 105 gfx::Size NotificationSurface::GetSize() const { | |
| 106 return surface_->content_size(); | |
| 107 } | |
| 108 | |
| 109 void NotificationSurface::OnSurfaceCommit() { | |
| 110 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | |
| 111 surface_->CommitSurfaceHierarchy(); | |
| 112 | |
| 113 gfx::Rect bounds = window_->bounds(); | |
| 114 if (bounds.size() != surface_->content_size()) { | |
| 115 bounds.set_size(surface_->content_size()); | |
| 116 window_->SetBounds(bounds); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 bool NotificationSurface::IsSurfaceSynchronized() const { | |
| 121 return false; | |
| 122 } | |
| 123 | |
| 124 void NotificationSurface::OnSurfaceDestroying(Surface* surface) { | |
| 125 window_.reset(); | |
| 126 surface->RemoveSurfaceObserver(this); | |
| 127 surface_ = nullptr; | |
| 128 } | |
| 129 | |
| 130 } // namespace exo | |
| OLD | NEW |