Home | History | Annotate | Download | only in wm
      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.
      4 
      5 #include "ash/wm/capture_controller.h"
      6 
      7 #include "ash/shell.h"
      8 #include "ui/aura/window.h"
      9 #include "ui/aura/root_window.h"
     10 
     11 namespace ash {
     12 namespace internal {
     13 
     14 ////////////////////////////////////////////////////////////////////////////////
     15 // CaptureController, public:
     16 
     17 CaptureController::CaptureController()
     18     : capture_window_(NULL) {
     19 }
     20 
     21 CaptureController::~CaptureController() {
     22 }
     23 
     24 ////////////////////////////////////////////////////////////////////////////////
     25 // CaptureController, client::CaptureClient implementation:
     26 
     27 void CaptureController::SetCapture(aura::Window* new_capture_window) {
     28   if (capture_window_ == new_capture_window)
     29     return;
     30   // Make sure window has a root window.
     31   DCHECK(!new_capture_window || new_capture_window->GetRootWindow());
     32   DCHECK(!capture_window_ || capture_window_->GetRootWindow());
     33 
     34   aura::Window* old_capture_window = capture_window_;
     35   Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
     36 
     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);
     49     }
     50   }
     51 
     52   capture_window_ = new_capture_window;
     53 
     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);
     58   }
     59 
     60   return;
     61 }
     62 
     63 void CaptureController::ReleaseCapture(aura::Window* window) {
     64   if (capture_window_ != window)
     65     return;
     66   SetCapture(NULL);
     67 }
     68 
     69 aura::Window* CaptureController::GetCaptureWindow() {
     70   return capture_window_;
     71 }
     72 
     73 }  // namespace internal
     74 }  // namespace ash
     75