Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/exo/notification_surface.h" | 5 #include "components/exo/notification_surface_impl.h" |
| 6 | 6 |
| 7 #include "components/exo/notification_surface_manager.h" | 7 #include "components/exo/notification_surface_manager.h" |
| 8 #include "components/exo/surface.h" | 8 #include "components/exo/surface.h" |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/aura/window_delegate.h" | 10 #include "ui/aura/window_delegate.h" |
| 11 #include "ui/base/cursor/cursor.h" | 11 #include "ui/base/cursor/cursor.h" |
| 12 #include "ui/base/hit_test.h" | 12 #include "ui/base/hit_test.h" |
| 13 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 14 #include "ui/views/controls/native/native_view_host.h" | |
| 14 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 15 | 16 |
| 16 namespace exo { | 17 namespace exo { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 class CustomWindowDelegate : public aura::WindowDelegate { | 21 class CustomWindowDelegate : public aura::WindowDelegate { |
| 21 public: | 22 public: |
| 22 explicit CustomWindowDelegate(Surface* surface) : surface_(surface) {} | 23 explicit CustomWindowDelegate(Surface* surface) : surface_(surface) {} |
| 23 ~CustomWindowDelegate() override {} | 24 ~CustomWindowDelegate() override {} |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 } | 61 } |
| 61 | 62 |
| 62 private: | 63 private: |
| 63 Surface* const surface_; | 64 Surface* const surface_; |
| 64 | 65 |
| 65 DISALLOW_COPY_AND_ASSIGN(CustomWindowDelegate); | 66 DISALLOW_COPY_AND_ASSIGN(CustomWindowDelegate); |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 } // namespace | 69 } // namespace |
| 69 | 70 |
| 70 NotificationSurface::NotificationSurface(NotificationSurfaceManager* manager, | 71 NotificationSurfaceImpl::NotificationSurfaceImpl( |
| 71 Surface* surface, | 72 NotificationSurfaceManager* manager, |
| 72 const std::string& notification_id) | 73 Surface* surface, |
| 74 const std::string& notification_id) | |
| 73 : manager_(manager), | 75 : manager_(manager), |
| 74 surface_(surface), | 76 surface_(surface), |
| 75 notification_id_(notification_id), | 77 notification_id_(notification_id), |
| 76 window_(new aura::Window(new CustomWindowDelegate(surface))) { | 78 window_(new aura::Window(new CustomWindowDelegate(surface))) { |
| 77 surface_->SetSurfaceDelegate(this); | 79 surface_->SetSurfaceDelegate(this); |
| 78 surface_->AddSurfaceObserver(this); | 80 surface_->AddSurfaceObserver(this); |
| 79 | 81 |
| 80 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 82 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 81 window_->SetName("ExoNotificationSurface"); | 83 window_->SetName("ExoNotificationSurface"); |
| 82 window_->Init(ui::LAYER_NOT_DRAWN); | 84 window_->Init(ui::LAYER_NOT_DRAWN); |
| 83 window_->set_owned_by_parent(false); | 85 window_->set_owned_by_parent(false); |
| 84 | 86 |
| 85 // TODO(xiyuan): Fix after Surface no longer has an aura::Window. | 87 // TODO(xiyuan): Fix after Surface no longer has an aura::Window. |
| 86 window_->AddChild(surface_->window()); | 88 window_->AddChild(surface_->window()); |
| 87 surface_->window()->Show(); | 89 surface_->window()->Show(); |
| 88 } | 90 } |
| 89 | 91 |
| 90 NotificationSurface::~NotificationSurface() { | 92 NotificationSurfaceImpl::~NotificationSurfaceImpl() { |
| 91 if (surface_) { | 93 if (surface_) { |
| 92 surface_->SetSurfaceDelegate(nullptr); | 94 surface_->SetSurfaceDelegate(nullptr); |
| 93 surface_->RemoveSurfaceObserver(this); | 95 surface_->RemoveSurfaceObserver(this); |
| 94 } | 96 } |
| 95 if (added_to_manager_) | 97 if (added_to_manager_) |
| 96 manager_->RemoveSurface(this); | 98 manager_->RemoveSurface(this); |
| 97 } | 99 } |
| 98 | 100 |
| 99 gfx::Size NotificationSurface::GetSize() const { | 101 gfx::Size NotificationSurfaceImpl::GetSize() const { |
| 100 return surface_->content_size(); | 102 return surface_->content_size(); |
| 101 } | 103 } |
| 102 | 104 |
| 103 void NotificationSurface::OnSurfaceCommit() { | 105 void NotificationSurfaceImpl::AttachWindow(views::NativeViewHost* nvh) { |
|
hidehiko
2017/03/02 15:38:16
Could you avoid non-trivial abbreviation?
| |
| 106 nvh->Attach(window()); | |
| 107 } | |
| 108 | |
| 109 aura::Window* NotificationSurfaceImpl::window() { | |
| 110 return window_.get(); | |
| 111 } | |
| 112 | |
| 113 const std::string& NotificationSurfaceImpl::notification_id() const { | |
| 114 return notification_id_; | |
| 115 } | |
| 116 | |
| 117 void NotificationSurfaceImpl::OnSurfaceCommit() { | |
| 104 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 118 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 105 surface_->CommitSurfaceHierarchy(); | 119 surface_->CommitSurfaceHierarchy(); |
| 106 | 120 |
| 107 gfx::Rect bounds = window_->bounds(); | 121 gfx::Rect bounds = window_->bounds(); |
| 108 if (bounds.size() != surface_->content_size()) { | 122 if (bounds.size() != surface_->content_size()) { |
| 109 bounds.set_size(surface_->content_size()); | 123 bounds.set_size(surface_->content_size()); |
| 110 window_->SetBounds(bounds); | 124 window_->SetBounds(bounds); |
| 111 } | 125 } |
| 112 | 126 |
| 113 // Defer AddSurface until there are contents to show. | 127 // Defer AddSurface until there are contents to show. |
| 114 if (!added_to_manager_ && !surface_->content_size().IsEmpty()) { | 128 if (!added_to_manager_ && !surface_->content_size().IsEmpty()) { |
| 115 added_to_manager_ = true; | 129 added_to_manager_ = true; |
| 116 manager_->AddSurface(this); | 130 manager_->AddSurface(this); |
| 117 } | 131 } |
| 118 } | 132 } |
| 119 | 133 |
| 120 bool NotificationSurface::IsSurfaceSynchronized() const { | 134 bool NotificationSurfaceImpl::IsSurfaceSynchronized() const { |
| 121 return false; | 135 return false; |
| 122 } | 136 } |
| 123 | 137 |
| 124 void NotificationSurface::OnSurfaceDestroying(Surface* surface) { | 138 void NotificationSurfaceImpl::OnSurfaceDestroying(Surface* surface) { |
| 125 window_.reset(); | 139 window_.reset(); |
| 126 surface->RemoveSurfaceObserver(this); | 140 surface->RemoveSurfaceObserver(this); |
| 127 surface_ = nullptr; | 141 surface_ = nullptr; |
| 128 } | 142 } |
| 129 | 143 |
| 130 } // namespace exo | 144 } // namespace exo |
| OLD | NEW |