#include "ui/aura/scoped_window_capture_request.h"
#include "ui/aura/window.h"
namespace aura {
ScopedWindowCaptureRequest::ScopedWindowCaptureRequest(
ScopedWindowCaptureRequest&& other)
: window_(other.DetachFromCurrentWindow(false)) {
if (window_)
AttachToCurrentWindow(false);
}
ScopedWindowCaptureRequest& ScopedWindowCaptureRequest::operator=(
ScopedWindowCaptureRequest&& rhs) {
DetachFromCurrentWindow(true);
window_ = rhs.DetachFromCurrentWindow(false);
if (window_)
AttachToCurrentWindow(false);
return *this;
}
ScopedWindowCaptureRequest::~ScopedWindowCaptureRequest() {
DetachFromCurrentWindow(true);
}
viz::SubtreeCaptureId ScopedWindowCaptureRequest::GetCaptureId() const {
return window_ ? window_->subtree_capture_id() : viz::SubtreeCaptureId();
}
void ScopedWindowCaptureRequest::OnWindowDestroying(Window* window) {
DetachFromCurrentWindow(false);
}
ScopedWindowCaptureRequest::ScopedWindowCaptureRequest(Window* window)
: window_(window) {
AttachToCurrentWindow(true);
}
void ScopedWindowCaptureRequest::AttachToCurrentWindow(
bool increment_requests) {
DCHECK(window_);
DCHECK(!window_->IsRootWindow());
if (increment_requests)
window_->OnScopedWindowCaptureRequestAdded();
window_->AddObserver(this);
}
Window* ScopedWindowCaptureRequest::DetachFromCurrentWindow(
bool decrement_requests) {
Window* result = window_;
if (window_) {
window_->RemoveObserver(this);
if (decrement_requests)
window_->OnScopedWindowCaptureRequestRemoved();
window_ = nullptr;
}
return result;
}
}