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

Unified Diff: mojo/services/window_manager/capture_controller.cc

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 9 months 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: mojo/services/window_manager/capture_controller.cc
diff --git a/mojo/services/window_manager/capture_controller.cc b/mojo/services/window_manager/capture_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ad6891c163ad1e4e91cdcdbf7fdea86b3ee6c63a
--- /dev/null
+++ b/mojo/services/window_manager/capture_controller.cc
@@ -0,0 +1,103 @@
+// 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 "mojo/services/window_manager/capture_controller.h"
+
+#include "mojo/services/window_manager/capture_controller_observer.h"
+#include "third_party/mojo_services/src/view_manager/public/cpp/view_property.h"
+#include "third_party/mojo_services/src/view_manager/public/cpp/view_tracker.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(capture_view_, old_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* new_capture,
+ mojo::View* old_capture) {
+ mojo::ViewTracker view_tracker;
+ if (new_capture)
+ view_tracker.Add(new_capture);
+ if (old_capture)
+ view_tracker.Add(old_capture);
+
+ FOR_EACH_OBSERVER(
+ CaptureControllerObserver, capture_controller_observers_,
+ OnCaptureChanged(view_tracker.Contains(new_capture) ? new_capture
+ : nullptr));
+}
+
+void CaptureController::OnViewDestroying(mojo::View* view) {
+ if (view == capture_view_) {
+ view->RemoveObserver(this);
+ NotifyCaptureChange(nullptr, view);
+ 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
« no previous file with comments | « mojo/services/window_manager/capture_controller.h ('k') | mojo/services/window_manager/capture_controller_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698