| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/modal_window_controller.h" | 5 #include "services/ui/ws/modal_window_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "services/ui/ws/event_dispatcher.h" | 9 #include "services/ui/ws/event_dispatcher.h" |
| 10 #include "services/ui/ws/server_window.h" | 10 #include "services/ui/ws/server_window.h" |
| 11 #include "services/ui/ws/server_window_drawn_tracker.h" | 11 #include "services/ui/ws/server_window_drawn_tracker.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 namespace ws { | 14 namespace ws { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const ServerWindow* GetModalChildForWindowAncestor(const ServerWindow* window) { | 17 const ServerWindow* GetModalChildForWindowAncestor(const ServerWindow* window) { |
| 18 for (const ServerWindow* ancestor = window; ancestor; | 18 for (const ServerWindow* ancestor = window; ancestor; |
| 19 ancestor = ancestor->parent()) { | 19 ancestor = ancestor->parent()) { |
| 20 for (auto* transient_child : ancestor->transient_children()) { | 20 for (auto* transient_child : ancestor->transient_children()) { |
| 21 if (transient_child->is_modal() && transient_child->IsDrawn()) | 21 if (transient_child->modal_type() != MODAL_TYPE_NONE && |
| 22 transient_child->IsDrawn()) |
| 22 return transient_child; | 23 return transient_child; |
| 23 } | 24 } |
| 24 } | 25 } |
| 25 return nullptr; | 26 return nullptr; |
| 26 } | 27 } |
| 27 | 28 |
| 28 const ServerWindow* GetWindowModalTargetForWindow(const ServerWindow* window) { | 29 const ServerWindow* GetWindowModalTargetForWindow(const ServerWindow* window) { |
| 29 const ServerWindow* modal_window = GetModalChildForWindowAncestor(window); | 30 const ServerWindow* modal_window = GetModalChildForWindowAncestor(window); |
| 30 if (!modal_window) | 31 if (!modal_window) |
| 31 return window; | 32 return window; |
| 32 return GetWindowModalTargetForWindow(modal_window); | 33 return GetWindowModalTargetForWindow(modal_window); |
| 33 } | 34 } |
| 34 | 35 |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 ModalWindowController::ModalWindowController(EventDispatcher* event_dispatcher) | 38 ModalWindowController::ModalWindowController(EventDispatcher* event_dispatcher) |
| 38 : event_dispatcher_(event_dispatcher) {} | 39 : event_dispatcher_(event_dispatcher) {} |
| 39 | 40 |
| 40 ModalWindowController::~ModalWindowController() { | 41 ModalWindowController::~ModalWindowController() { |
| 41 for (auto it = system_modal_windows_.begin(); | 42 for (auto it = system_modal_windows_.begin(); |
| 42 it != system_modal_windows_.end(); it++) { | 43 it != system_modal_windows_.end(); it++) { |
| 43 (*it)->RemoveObserver(this); | 44 (*it)->RemoveObserver(this); |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| 47 void ModalWindowController::AddSystemModalWindow(ServerWindow* window) { | 48 void ModalWindowController::AddSystemModalWindow(ServerWindow* window) { |
| 48 DCHECK(window); | 49 DCHECK(window); |
| 49 DCHECK(!base::ContainsValue(system_modal_windows_, window)); | 50 DCHECK(!base::ContainsValue(system_modal_windows_, window)); |
| 50 | 51 |
| 51 window->SetModal(); | 52 window->SetModalType(ui::MODAL_TYPE_SYSTEM); |
| 52 system_modal_windows_.push_back(window); | 53 system_modal_windows_.push_back(window); |
| 53 window_drawn_trackers_.insert(make_pair( | 54 window_drawn_trackers_.insert(make_pair( |
| 54 window, base::MakeUnique<ServerWindowDrawnTracker>(window, this))); | 55 window, base::MakeUnique<ServerWindowDrawnTracker>(window, this))); |
| 55 window->AddObserver(this); | 56 window->AddObserver(this); |
| 56 | 57 |
| 57 event_dispatcher_->ReleaseCaptureBlockedByModalWindow(window); | 58 event_dispatcher_->ReleaseCaptureBlockedByModalWindow(window); |
| 58 } | 59 } |
| 59 | 60 |
| 60 bool ModalWindowController::IsWindowBlockedBy( | 61 bool ModalWindowController::IsWindowBlockedBy( |
| 61 const ServerWindow* window, | 62 const ServerWindow* window, |
| 62 const ServerWindow* modal_window) const { | 63 const ServerWindow* modal_window) const { |
| 63 DCHECK(window); | 64 DCHECK(window); |
| 64 DCHECK(modal_window); | 65 DCHECK(modal_window); |
| 65 if (!modal_window->is_modal() || !modal_window->IsDrawn()) | 66 if (modal_window->modal_type() == MODAL_TYPE_NONE || |
| 67 !modal_window->IsDrawn()) { |
| 66 return false; | 68 return false; |
| 69 } |
| 67 | 70 |
| 68 if (modal_window->transient_parent() && | 71 if (modal_window->transient_parent() && |
| 69 !modal_window->transient_parent()->Contains(window)) { | 72 !modal_window->transient_parent()->Contains(window)) { |
| 70 return false; | 73 return false; |
| 71 } | 74 } |
| 72 | 75 |
| 73 return true; | 76 return true; |
| 74 } | 77 } |
| 75 | 78 |
| 76 bool ModalWindowController::IsWindowBlocked(const ServerWindow* window) const { | 79 bool ModalWindowController::IsWindowBlocked(const ServerWindow* window) const { |
| 77 DCHECK(window); | 80 DCHECK(window); |
| 78 return GetActiveSystemModalWindow() || GetModalChildForWindowAncestor(window); | 81 return GetActiveSystemModalWindow() || GetModalChildForWindowAncestor(window); |
| 79 } | 82 } |
| 80 | 83 |
| 81 const ServerWindow* ModalWindowController::GetTargetForWindow( | 84 const ServerWindow* ModalWindowController::GetTargetForWindow( |
| 82 const ServerWindow* window) const { | 85 const ServerWindow* window) const { |
| 86 // TODO(moshayedi): crbug.com/697127. Handle windows which are modal to |
| 87 // children of their transient parent. |
| 83 ServerWindow* system_modal_window = GetActiveSystemModalWindow(); | 88 ServerWindow* system_modal_window = GetActiveSystemModalWindow(); |
| 84 if (system_modal_window) | 89 if (system_modal_window) |
| 85 return system_modal_window; | 90 return system_modal_window; |
| 86 return window ? GetWindowModalTargetForWindow(window) : nullptr; | 91 return window ? GetWindowModalTargetForWindow(window) : nullptr; |
| 87 } | 92 } |
| 88 | 93 |
| 89 ServerWindow* ModalWindowController::GetActiveSystemModalWindow() const { | 94 ServerWindow* ModalWindowController::GetActiveSystemModalWindow() const { |
| 90 for (auto it = system_modal_windows_.rbegin(); | 95 for (auto it = system_modal_windows_.rbegin(); |
| 91 it != system_modal_windows_.rend(); it++) { | 96 it != system_modal_windows_.rend(); it++) { |
| 92 ServerWindow* modal = *it; | 97 ServerWindow* modal = *it; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 114 // Move the most recently shown window to the end of the list. | 119 // Move the most recently shown window to the end of the list. |
| 115 auto it = std::find(system_modal_windows_.begin(), | 120 auto it = std::find(system_modal_windows_.begin(), |
| 116 system_modal_windows_.end(), window); | 121 system_modal_windows_.end(), window); |
| 117 DCHECK(it != system_modal_windows_.end()); | 122 DCHECK(it != system_modal_windows_.end()); |
| 118 system_modal_windows_.splice(system_modal_windows_.end(), | 123 system_modal_windows_.splice(system_modal_windows_.end(), |
| 119 system_modal_windows_, it); | 124 system_modal_windows_, it); |
| 120 } | 125 } |
| 121 | 126 |
| 122 } // namespace ws | 127 } // namespace ws |
| 123 } // namespace ui | 128 } // namespace ui |
| OLD | NEW |