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

Unified Diff: services/window_manager/capture_controller.cc

Issue 805123003: Adds capture to the mojo window_manager. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Cleanup Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: services/window_manager/capture_controller.cc
diff --git a/services/window_manager/capture_controller.cc b/services/window_manager/capture_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a3743ee99f84820ba7e180330e3ffba973edf713
--- /dev/null
+++ b/services/window_manager/capture_controller.cc
@@ -0,0 +1,105 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/window_manager/capture_controller.h"
+
+#include "mojo/services/view_manager/public/cpp/view_property.h"
+#include "mojo/services/view_manager/public/cpp/view_tracker.h"
+#include "services/window_manager/capture_controller_observer.h"
+
+DECLARE_VIEW_PROPERTY_TYPE(window_manager::CaptureController*);
+
+namespace window_manager {
+
+namespace {
+DEFINE_VIEW_PROPERTY_KEY(CaptureController*,
+ kRootViewCaptureController,
+ nullptr);
+} // namespace
+
+CaptureController::CaptureController()
+ : capture_view_(nullptr) {}
+
+CaptureController::~CaptureController() {}
+
+void CaptureController::AddObserver(CaptureControllerObserver* observer) {
+ capture_controller_observers_.AddObserver(observer);
+}
+
+void CaptureController::RemoveObserver(CaptureControllerObserver* observer) {
+ capture_controller_observers_.RemoveObserver(observer);
+}
+
+void CaptureController::SetCapture(mojo::View* view) {
+ if (capture_view_ == view)
+ return;
+
+ if (capture_view_)
+ capture_view_->RemoveObserver(this);
+
+ mojo::View* old_capture_view = capture_view_;
+ capture_view_ = view;
+
+ if (capture_view_)
+ capture_view_->AddObserver(this);
+
+ NotifyCaptureChange(old_capture_view, capture_view_);
+}
+
+void CaptureController::ReleaseCapture(mojo::View* view) {
+ if (capture_view_ != view)
+ return;
+ SetCapture(nullptr);
+}
+
+mojo::View* CaptureController::GetCapture() {
+ return capture_view_;
+}
+
+void CaptureController::NotifyCaptureChange(mojo::View* old_capture,
sky 2014/12/16 03:44:19 How about swapping order so it's consistant with O
+ mojo::View* new_capture) {
+ mojo::ViewTracker view_tracker;
+ if (old_capture)
+ view_tracker.Add(old_capture);
+ if (new_capture)
+ view_tracker.Add(new_capture);
+
+ FOR_EACH_OBSERVER(
+ CaptureControllerObserver,
+ capture_controller_observers_,
+ OnCaptureChanged(
+ view_tracker.Contains(new_capture) ? new_capture : nullptr,
+ view_tracker.Contains(old_capture) ? old_capture : nullptr));
+}
+
+void CaptureController::OnViewDestroying(mojo::View* view) {
+ if (view == capture_view_) {
+ view->RemoveObserver(this);
+ NotifyCaptureChange(view, nullptr);
+ capture_view_ = nullptr;
+ }
+}
+
+void SetCaptureController(mojo::View* root_view,
+ CaptureController* capture_controller) {
+ DCHECK_EQ(root_view->GetRoot(), root_view);
+ root_view->SetLocalProperty(kRootViewCaptureController, capture_controller);
+}
+
+CaptureController* GetCaptureController(mojo::View* root_view) {
+ if (root_view)
+ DCHECK_EQ(root_view->GetRoot(), root_view);
+ return root_view ?
+ root_view->GetLocalProperty(kRootViewCaptureController) : nullptr;
+}
+
+mojo::View* GetCaptureView(mojo::View* view) {
+ mojo::View* root = view->GetRoot();
+ if (!root)
+ return nullptr;
+ CaptureController* controller = GetCaptureController(root);
+ return controller ? controller->GetCapture() : nullptr;
+}
+
+} // namespace window_manager

Powered by Google App Engine
This is Rietveld 408576698