Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/wm/core/capture_controller.h" | 5 #include "ui/wm/core/capture_controller.h" |
| 6 | 6 |
| 7 #include "ui/aura/window.h" | 7 #include "ui/aura/window.h" |
| 8 #include "ui/aura/window_event_dispatcher.h" | 8 #include "ui/aura/window_event_dispatcher.h" |
| 9 #include "ui/aura/window_tree_host.h" | 9 #include "ui/aura/window_tree_host.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 void CaptureController::SetCapture(aura::Window* new_capture_window) { | 30 void CaptureController::SetCapture(aura::Window* new_capture_window) { |
| 31 if (capture_window_ == new_capture_window) | 31 if (capture_window_ == new_capture_window) |
| 32 return; | 32 return; |
| 33 | 33 |
| 34 // Make sure window has a root window. | 34 // Make sure window has a root window. |
| 35 DCHECK(!new_capture_window || new_capture_window->GetRootWindow()); | 35 DCHECK(!new_capture_window || new_capture_window->GetRootWindow()); |
| 36 DCHECK(!capture_window_ || capture_window_->GetRootWindow()); | 36 DCHECK(!capture_window_ || capture_window_->GetRootWindow()); |
| 37 | 37 |
| 38 aura::Window* old_capture_window = capture_window_; | 38 aura::Window* old_capture_window = capture_window_; |
| 39 aura::Window* old_capture_root = old_capture_window ? | 39 aura::client::CaptureDelegate* old_capture_delegate = capture_delegate_; |
| 40 old_capture_window->GetRootWindow() : NULL; | |
| 41 | 40 |
| 42 // Copy the list in case it's modified out from under us. | 41 // Copy the list in case it's modified out from under us. |
| 43 RootWindows root_windows(root_windows_); | 42 RootWindows root_windows(root_windows_); |
| 44 | 43 |
| 45 // If we're actually starting capture, then cancel any touches/gestures | 44 // If we're actually starting capture, then cancel any touches/gestures |
| 46 // that aren't already locked to the new window, and transfer any on the | 45 // that aren't already locked to the new window, and transfer any on the |
| 47 // old capture window to the new one. When capture is released we have no | 46 // old capture window to the new one. When capture is released we have no |
| 48 // distinction between the touches/gestures that were in the window all | 47 // distinction between the touches/gestures that were in the window all |
| 49 // along (and so shouldn't be canceled) and those that got moved, so | 48 // along (and so shouldn't be canceled) and those that got moved, so |
| 50 // just leave them all where they are. | 49 // just leave them all where they are. |
| 51 if (new_capture_window) { | 50 if (new_capture_window) { |
| 52 ui::GestureRecognizer::Get()->TransferEventsTo(old_capture_window, | 51 ui::GestureRecognizer::Get()->TransferEventsTo(old_capture_window, |
| 53 new_capture_window); | 52 new_capture_window); |
| 54 } | 53 } |
| 55 | 54 |
| 56 capture_window_ = new_capture_window; | 55 capture_window_ = new_capture_window; |
| 56 aura::Window* capture_root_window = | |
| 57 capture_window_ ? capture_window_->GetRootWindow() : NULL; | |
|
sadrul
2014/12/11 15:11:00
nullptr
| |
| 58 capture_delegate_ = capture_root_window | |
|
sadrul
2014/12/11 15:11:00
Can |capture_delegate| be a local variable instead
| |
| 59 ? capture_root_window->GetHost()->dispatcher() | |
| 60 : NULL; | |
| 57 | 61 |
| 58 for (RootWindows::const_iterator i = root_windows.begin(); | 62 for (RootWindows::const_iterator i = root_windows.begin(); |
| 59 i != root_windows.end(); ++i) { | 63 i != root_windows.end(); ++i) { |
| 60 aura::client::CaptureDelegate* delegate = (*i)->GetHost()->dispatcher(); | 64 aura::client::CaptureDelegate* delegate = (*i)->GetHost()->dispatcher(); |
| 61 delegate->UpdateCapture(old_capture_window, new_capture_window); | 65 delegate->UpdateCapture(old_capture_window, new_capture_window); |
| 62 } | 66 } |
| 63 | 67 |
| 64 aura::Window* capture_root = | 68 if (capture_delegate_ != old_capture_delegate) { |
| 65 capture_window_ ? capture_window_->GetRootWindow() : NULL; | 69 if (old_capture_delegate) |
| 66 if (capture_root != old_capture_root) { | 70 old_capture_delegate->ReleaseNativeCapture(); |
| 67 if (old_capture_root) { | 71 if (capture_delegate_) |
| 68 aura::client::CaptureDelegate* delegate = | 72 capture_delegate_->SetNativeCapture(); |
|
sadrul
2014/12/11 15:11:00
The old code makes much more sense when reading th
pkotwicz
2014/12/11 16:22:49
If a window with capture is reparented to a differ
| |
| 69 old_capture_root->GetHost()->dispatcher(); | |
| 70 delegate->ReleaseNativeCapture(); | |
| 71 } | |
| 72 if (capture_root) { | |
| 73 aura::client::CaptureDelegate* delegate = | |
| 74 capture_root->GetHost()->dispatcher(); | |
| 75 delegate->SetNativeCapture(); | |
| 76 } | |
| 77 } | 73 } |
| 78 } | 74 } |
| 79 | 75 |
| 80 void CaptureController::ReleaseCapture(aura::Window* window) { | 76 void CaptureController::ReleaseCapture(aura::Window* window) { |
| 81 if (capture_window_ != window) | 77 if (capture_window_ != window) |
| 82 return; | 78 return; |
| 83 SetCapture(NULL); | 79 SetCapture(NULL); |
| 84 } | 80 } |
| 85 | 81 |
| 86 aura::Window* CaptureController::GetCaptureWindow() { | 82 aura::Window* CaptureController::GetCaptureWindow() { |
| 87 return capture_window_; | 83 return capture_window_; |
| 88 } | 84 } |
| 89 | 85 |
| 90 aura::Window* CaptureController::GetGlobalCaptureWindow() { | 86 aura::Window* CaptureController::GetGlobalCaptureWindow() { |
| 91 return capture_window_; | 87 return capture_window_; |
| 92 } | 88 } |
| 93 | 89 |
| 94 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
| 95 // CaptureController, private: | 91 // CaptureController, private: |
| 96 | 92 |
| 97 CaptureController::CaptureController() | 93 CaptureController::CaptureController() |
| 98 : capture_window_(NULL) { | 94 : capture_window_(NULL), |
| 95 capture_delegate_(NULL) { | |
| 99 } | 96 } |
| 100 | 97 |
| 101 CaptureController::~CaptureController() { | 98 CaptureController::~CaptureController() { |
| 102 } | 99 } |
| 103 | 100 |
| 104 //////////////////////////////////////////////////////////////////////////////// | 101 //////////////////////////////////////////////////////////////////////////////// |
| 105 // ScopedCaptureClient: | 102 // ScopedCaptureClient: |
| 106 | 103 |
| 107 // static | 104 // static |
| 108 CaptureController* ScopedCaptureClient::capture_controller_ = NULL; | 105 CaptureController* ScopedCaptureClient::capture_controller_ = NULL; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 136 root_window_->RemoveObserver(this); | 133 root_window_->RemoveObserver(this); |
| 137 capture_controller_->Detach(root_window_); | 134 capture_controller_->Detach(root_window_); |
| 138 if (!capture_controller_->is_active()) { | 135 if (!capture_controller_->is_active()) { |
| 139 delete capture_controller_; | 136 delete capture_controller_; |
| 140 capture_controller_ = NULL; | 137 capture_controller_ = NULL; |
| 141 } | 138 } |
| 142 root_window_ = NULL; | 139 root_window_ = NULL; |
| 143 } | 140 } |
| 144 | 141 |
| 145 } // namespace wm | 142 } // namespace wm |
| OLD | NEW |