Index: components/mus/ws/event_dispatcher.cc |
diff --git a/components/mus/ws/event_dispatcher.cc b/components/mus/ws/event_dispatcher.cc |
index 7dce130a2d57038272214239f960ddf0458a1547..30f19da3f9972ff52340607030f67502c86a81c1 100644 |
--- a/components/mus/ws/event_dispatcher.cc |
+++ b/components/mus/ws/event_dispatcher.cc |
@@ -4,8 +4,6 @@ |
#include "components/mus/ws/event_dispatcher.h" |
-#include <set> |
- |
#include "base/time/time.h" |
#include "cc/surfaces/surface_hittest.h" |
#include "components/mus/surfaces/surfaces_state.h" |
@@ -72,21 +70,22 @@ EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) |
root_(nullptr), |
capture_window_(nullptr), |
capture_window_in_nonclient_area_(false), |
+ system_modal_window_(nullptr), |
mouse_button_down_(false), |
mouse_cursor_source_window_(nullptr) {} |
EventDispatcher::~EventDispatcher() { |
- std::set<ServerWindow*> pointer_targets; |
if (capture_window_) { |
- pointer_targets.insert(capture_window_); |
- capture_window_->RemoveObserver(this); |
+ UnobserveWindow(capture_window_); |
capture_window_ = nullptr; |
} |
+ if (system_modal_window_) { |
+ UnobserveWindow(system_modal_window_); |
+ system_modal_window_ = nullptr; |
+ } |
for (const auto& pair : pointer_targets_) { |
- if (pair.second.window && |
- pointer_targets.insert(pair.second.window).second) { |
- pair.second.window->RemoveObserver(this); |
- } |
+ if (pair.second.window) |
+ UnobserveWindow(pair.second.window); |
} |
pointer_targets_.clear(); |
} |
@@ -116,23 +115,23 @@ bool EventDispatcher::SetCaptureWindow(ServerWindow* window, |
return true; |
// A window that is blocked by a modal window cannot gain capture. |
- if (window && window->IsBlockedByModalWindow()) |
+ if (window && ((system_modal_window_ && system_modal_window_->IsDrawn()) || |
+ window->IsBlockedByModalWindow())) { |
return false; |
+ } |
if (capture_window_) { |
// Stop observing old capture window. |pointer_targets_| are cleared on |
// initial setting of a capture window. |
delegate_->OnServerWindowCaptureLost(capture_window_); |
- capture_window_->RemoveObserver(this); |
+ UnobserveWindow(capture_window_); |
} else { |
// Cancel implicit capture to all other windows. |
- std::set<ServerWindow*> unobserved_windows; |
for (const auto& pair : pointer_targets_) { |
ServerWindow* target = pair.second.window; |
if (!target) |
continue; |
- if (unobserved_windows.insert(target).second) |
- target->RemoveObserver(this); |
+ UnobserveWindow(target); |
if (target == window) |
continue; |
@@ -154,7 +153,7 @@ bool EventDispatcher::SetCaptureWindow(ServerWindow* window, |
// Begin tracking the capture window if it is not yet being observed. |
if (window) { |
- window->AddObserver(this); |
+ ObserveWindow(window); |
if (!capture_window_) |
delegate_->SetNativeCapture(); |
} else { |
@@ -168,6 +167,21 @@ bool EventDispatcher::SetCaptureWindow(ServerWindow* window, |
return true; |
} |
+bool EventDispatcher::SetSystemModalWindow(ServerWindow* window) { |
+ DCHECK(window); |
+ |
+ if (window == system_modal_window_) |
+ return true; |
+ |
+ if (system_modal_window_) |
+ return false; |
sky
2016/04/20 20:14:11
nit: spacing is off (run git cl format).
mohsen
2016/04/21 17:58:43
Done.
|
+ |
+ system_modal_window_ = window; |
sky
2016/04/20 20:14:11
I think we should cancel capture here rather than
mohsen
2016/04/21 17:58:43
Done.
|
+ system_modal_window_->SetModal(); |
+ ObserveWindow(system_modal_window_); |
+ return true; |
+} |
+ |
void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { |
if (!mouse_button_down_) { |
gfx::Point location = mouse_pointer_last_location_; |
@@ -309,8 +323,7 @@ void EventDispatcher::StartTrackingPointer( |
int32_t pointer_id, |
const PointerTarget& pointer_target) { |
DCHECK(!IsTrackingPointer(pointer_id)); |
- if (!IsObservingWindow(pointer_target.window)) |
- pointer_target.window->AddObserver(this); |
+ ObserveWindow(pointer_target.window); |
pointer_targets_[pointer_id] = pointer_target; |
} |
@@ -318,8 +331,8 @@ void EventDispatcher::StopTrackingPointer(int32_t pointer_id) { |
DCHECK(IsTrackingPointer(pointer_id)); |
ServerWindow* window = pointer_targets_[pointer_id].window; |
pointer_targets_.erase(pointer_id); |
- if (window && !IsObservingWindow(window)) |
- window->RemoveObserver(this); |
+ if (window) |
+ UnobserveWindow(window); |
} |
void EventDispatcher::UpdateTargetForPointer(int32_t pointer_id, |
@@ -361,7 +374,10 @@ EventDispatcher::PointerTarget EventDispatcher::PointerTargetForEvent( |
gfx::Point location(event.location()); |
ServerWindow* target_window = |
FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); |
- pointer_target.window = target_window->GetModalTarget(); |
+ pointer_target.window = |
+ system_modal_window_ && system_modal_window_->IsDrawn() |
+ ? system_modal_window_ |
+ : target_window->GetModalTarget(); |
pointer_target.is_mouse_event = event.IsMousePointerEvent(); |
pointer_target.in_nonclient_area = |
target_window != pointer_target.window || |
@@ -395,9 +411,8 @@ void EventDispatcher::DispatchToPointerTarget(const PointerTarget& target, |
} |
void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) { |
- window->RemoveObserver(this); |
- |
if (capture_window_ == window) { |
+ UnobserveWindow(window); |
capture_window_ = nullptr; |
mouse_button_down_ = false; |
// A window only cares to be informed that it lost capture if it explicitly |
@@ -410,17 +425,29 @@ void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) { |
} |
for (auto& pair : pointer_targets_) { |
- if (pair.second.window == window) |
+ if (pair.second.window == window) { |
+ UnobserveWindow(window); |
pair.second.window = nullptr; |
+ } |
} |
} |
-bool EventDispatcher::IsObservingWindow(ServerWindow* window) { |
- for (const auto& pair : pointer_targets_) { |
- if (pair.second.window == window) |
- return true; |
+void EventDispatcher::ObserveWindow(ServerWindow* window) { |
+ auto res = observed_windows_.insert(std::make_pair(window, 0u)); |
+ res.first->second++; |
+ if (res.second) |
+ window->AddObserver(this); |
+} |
+ |
+void EventDispatcher::UnobserveWindow(ServerWindow* window) { |
+ auto it = observed_windows_.find(window); |
+ DCHECK(it != observed_windows_.end()); |
+ DCHECK_LT(0u, it->second); |
+ it->second--; |
+ if (!it->second) { |
+ window->RemoveObserver(this); |
+ observed_windows_.erase(it); |
} |
- return false; |
} |
Accelerator* EventDispatcher::FindAccelerator( |
@@ -447,6 +474,11 @@ void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) { |
void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { |
CancelPointerEventsToTarget(window); |
+ if (system_modal_window_ == window) { |
sky
2016/04/20 20:14:11
You have this in the destructor as well. Maybe Res
mohsen
2016/04/21 17:58:42
Done.
|
+ UnobserveWindow(window); |
+ system_modal_window_ = nullptr; |
+ } |
+ |
if (mouse_cursor_source_window_ == window) |
mouse_cursor_source_window_ = nullptr; |
} |