| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/wm/core/capture_controller.h" | 5 #include "ui/wm/core/capture_controller.h" |
| 6 | 6 |
| 7 #include "ui/aura/client/capture_client_observer.h" | 7 #include "ui/aura/client/capture_client_observer.h" |
| 8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
| 9 #include "ui/aura/window_event_dispatcher.h" | 9 #include "ui/aura/window_event_dispatcher.h" |
| 10 #include "ui/aura/window_tracker.h" | 10 #include "ui/aura/window_tracker.h" |
| 11 #include "ui/aura/window_tree_host.h" | 11 #include "ui/aura/window_tree_host.h" |
| 12 | 12 |
| 13 namespace wm { | 13 namespace wm { |
| 14 | 14 |
| 15 // static |
| 16 CaptureController* CaptureController::instance_ = nullptr; |
| 17 |
| 15 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 16 // CaptureController, public: | 19 // CaptureController, public: |
| 17 | 20 |
| 21 CaptureController::CaptureController() |
| 22 : capture_window_(nullptr), capture_delegate_(nullptr) { |
| 23 DCHECK(!instance_); |
| 24 instance_ = this; |
| 25 } |
| 26 |
| 27 CaptureController::~CaptureController() { |
| 28 DCHECK_EQ(instance_, this); |
| 29 instance_ = nullptr; |
| 30 } |
| 31 |
| 18 void CaptureController::Attach(aura::Window* root) { | 32 void CaptureController::Attach(aura::Window* root) { |
| 19 DCHECK_EQ(0u, delegates_.count(root)); | 33 DCHECK_EQ(0u, delegates_.count(root)); |
| 20 delegates_[root] = root->GetHost()->dispatcher(); | 34 delegates_[root] = root->GetHost()->dispatcher(); |
| 21 aura::client::SetCaptureClient(root, this); | 35 aura::client::SetCaptureClient(root, this); |
| 22 } | 36 } |
| 23 | 37 |
| 24 void CaptureController::Detach(aura::Window* root) { | 38 void CaptureController::Detach(aura::Window* root) { |
| 25 delegates_.erase(root); | 39 delegates_.erase(root); |
| 26 aura::client::SetCaptureClient(root, nullptr); | 40 aura::client::SetCaptureClient(root, nullptr); |
| 27 } | 41 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 aura::client::CaptureClientObserver* observer) { | 110 aura::client::CaptureClientObserver* observer) { |
| 97 observers_.AddObserver(observer); | 111 observers_.AddObserver(observer); |
| 98 } | 112 } |
| 99 | 113 |
| 100 void CaptureController::RemoveObserver( | 114 void CaptureController::RemoveObserver( |
| 101 aura::client::CaptureClientObserver* observer) { | 115 aura::client::CaptureClientObserver* observer) { |
| 102 observers_.RemoveObserver(observer); | 116 observers_.RemoveObserver(observer); |
| 103 } | 117 } |
| 104 | 118 |
| 105 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
| 106 // CaptureController, private: | |
| 107 | |
| 108 CaptureController::CaptureController() | |
| 109 : capture_window_(nullptr), | |
| 110 capture_delegate_(nullptr) { | |
| 111 } | |
| 112 | |
| 113 CaptureController::~CaptureController() { | |
| 114 } | |
| 115 | |
| 116 //////////////////////////////////////////////////////////////////////////////// | |
| 117 // ScopedCaptureClient: | 120 // ScopedCaptureClient: |
| 118 | 121 |
| 119 // static | |
| 120 CaptureController* ScopedCaptureClient::capture_controller_ = nullptr; | |
| 121 | |
| 122 ScopedCaptureClient::ScopedCaptureClient(aura::Window* root) | 122 ScopedCaptureClient::ScopedCaptureClient(aura::Window* root) |
| 123 : root_window_(root) { | 123 : root_window_(root) { |
| 124 root->AddObserver(this); | 124 root->AddObserver(this); |
| 125 if (!capture_controller_) | 125 CaptureController::Get()->Attach(root); |
| 126 capture_controller_ = new CaptureController; | |
| 127 capture_controller_->Attach(root); | |
| 128 } | 126 } |
| 129 | 127 |
| 130 ScopedCaptureClient::~ScopedCaptureClient() { | 128 ScopedCaptureClient::~ScopedCaptureClient() { |
| 131 Shutdown(); | 129 Shutdown(); |
| 132 } | 130 } |
| 133 | 131 |
| 134 // static | |
| 135 bool ScopedCaptureClient::IsActive() { | |
| 136 return capture_controller_ && capture_controller_->is_active(); | |
| 137 } | |
| 138 | |
| 139 void ScopedCaptureClient::OnWindowDestroyed(aura::Window* window) { | 132 void ScopedCaptureClient::OnWindowDestroyed(aura::Window* window) { |
| 140 DCHECK_EQ(window, root_window_); | 133 DCHECK_EQ(window, root_window_); |
| 141 Shutdown(); | 134 Shutdown(); |
| 142 } | 135 } |
| 143 | 136 |
| 144 void ScopedCaptureClient::Shutdown() { | 137 void ScopedCaptureClient::Shutdown() { |
| 145 if (!root_window_) | 138 if (!root_window_) |
| 146 return; | 139 return; |
| 147 | 140 |
| 148 root_window_->RemoveObserver(this); | 141 root_window_->RemoveObserver(this); |
| 149 capture_controller_->Detach(root_window_); | 142 CaptureController::Get()->Detach(root_window_); |
| 150 if (!capture_controller_->is_active()) { | |
| 151 delete capture_controller_; | |
| 152 capture_controller_ = nullptr; | |
| 153 } | |
| 154 root_window_ = nullptr; | 143 root_window_ = nullptr; |
| 155 } | 144 } |
| 156 | 145 |
| 157 /////////////////////////////////////////////////////////////////////////////// | 146 /////////////////////////////////////////////////////////////////////////////// |
| 158 // CaptureController::TestApi | 147 // CaptureController::TestApi |
| 159 | 148 |
| 160 void ScopedCaptureClient::TestApi::SetDelegate( | 149 void ScopedCaptureClient::TestApi::SetDelegate( |
| 161 aura::client::CaptureDelegate* delegate) { | 150 aura::client::CaptureDelegate* delegate) { |
| 162 client_->capture_controller_->delegates_[client_->root_window_] = delegate; | 151 CaptureController::Get()->delegates_[client_->root_window_] = delegate; |
| 163 } | 152 } |
| 164 | 153 |
| 165 } // namespace wm | 154 } // namespace wm |
| OLD | NEW |