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
3 // found in the LICENSE file.
5 #include "ash/wm/capture_controller.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/root_window.h"
14 ////////////////////////////////////////////////////////////////////////////////
15 // CaptureController, public:
17 CaptureController::CaptureController()
18 : capture_window_(NULL
) {
21 CaptureController::~CaptureController() {
24 ////////////////////////////////////////////////////////////////////////////////
25 // CaptureController, client::CaptureClient implementation:
27 void CaptureController::SetCapture(aura::Window
* new_capture_window
) {
28 if (capture_window_
== new_capture_window
)
30 // Make sure window has a root window.
31 DCHECK(!new_capture_window
|| new_capture_window
->GetRootWindow());
32 DCHECK(!capture_window_
|| capture_window_
->GetRootWindow());
34 aura::Window
* old_capture_window
= capture_window_
;
35 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
37 // If we're actually starting capture, then cancel any touches/gestures
38 // that aren't already locked to the new window, and transfer any on the
39 // old capture window to the new one. When capture is released we have no
40 // distinction between the touches/gestures that were in the window all
41 // along (and so shouldn't be canceled) and those that got moved, so
42 // just leave them all where they are.
43 if (new_capture_window
) {
44 for (Shell::RootWindowList::iterator iter
= root_windows
.begin();
45 iter
!= root_windows
.end(); ++iter
) {
46 aura::RootWindow
* root_window
= *iter
;
47 root_window
->gesture_recognizer()->
48 TransferEventsTo(old_capture_window
, new_capture_window
);
52 capture_window_
= new_capture_window
;
54 for (Shell::RootWindowList::iterator iter
= root_windows
.begin();
55 iter
!= root_windows
.end(); ++iter
) {
56 aura::RootWindow
* root_window
= *iter
;
57 root_window
->UpdateCapture(old_capture_window
, new_capture_window
);
63 void CaptureController::ReleaseCapture(aura::Window
* window
) {
64 if (capture_window_
!= window
)
69 aura::Window
* CaptureController::GetCaptureWindow() {
70 return capture_window_
;
73 } // namespace internal