| 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 "ash/wm/window_modality_controller.h" | 5 #include "ash/wm/window_modality_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/wm/window_properties.h" | |
| 10 #include "ash/wm/window_util.h" | |
| 11 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
| 12 #include "ui/aura/client/capture_client.h" | 10 #include "ui/aura/client/capture_client.h" |
| 13 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
| 14 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
| 15 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_property.h" |
| 16 #include "ui/base/events/event.h" | 15 #include "ui/base/events/event.h" |
| 17 #include "ui/base/ui_base_types.h" | 16 #include "ui/base/ui_base_types.h" |
| 18 #include "ui/views/corewm/window_animations.h" | 17 #include "ui/views/corewm/window_animations.h" |
| 18 #include "ui/views/corewm/window_util.h" |
| 19 | 19 |
| 20 namespace ash { | 20 namespace ash { |
| 21 | 21 |
| 22 namespace wm { | 22 // Transient child's modal parent. |
| 23 extern const aura::WindowProperty<aura::Window*>* const kModalParentKey; |
| 24 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kModalParentKey, NULL); |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 bool HasAncestor(aura::Window* window, aura::Window* ancestor) { | 28 bool HasAncestor(aura::Window* window, aura::Window* ancestor) { |
| 27 if (!window) | 29 if (!window) |
| 28 return false; | 30 return false; |
| 29 if (window == ancestor) | 31 if (window == ancestor) |
| 30 return true; | 32 return true; |
| 31 return HasAncestor(window->parent(), ancestor); | 33 return HasAncestor(window->parent(), ancestor); |
| 32 } | 34 } |
| 33 | 35 |
| 34 bool TransientChildIsWindowModal(aura::Window* window) { | 36 bool TransientChildIsWindowModal(aura::Window* window) { |
| 35 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW; | 37 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW; |
| 36 } | 38 } |
| 37 | 39 |
| 38 bool TransientChildIsChildModal(aura::Window* window) { | 40 bool TransientChildIsChildModal(aura::Window* window) { |
| 39 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_CHILD; | 41 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_CHILD; |
| 40 } | 42 } |
| 41 | 43 |
| 42 aura::Window* GetModalParent(aura::Window* window) { | 44 aura::Window* GetModalParent(aura::Window* window) { |
| 43 return window->GetProperty(ash::internal::kModalParentKey); | 45 return window->GetProperty(kModalParentKey); |
| 44 } | 46 } |
| 45 | 47 |
| 46 bool IsModalTransientChild(aura::Window* transient, aura::Window* original) { | 48 bool IsModalTransientChild(aura::Window* transient, aura::Window* original) { |
| 47 return transient->IsVisible() && | 49 return transient->IsVisible() && |
| 48 (TransientChildIsWindowModal(transient) || | 50 (TransientChildIsWindowModal(transient) || |
| 49 (TransientChildIsChildModal(transient) && | 51 (TransientChildIsChildModal(transient) && |
| 50 (HasAncestor(original, GetModalParent(transient))))); | 52 (HasAncestor(original, GetModalParent(transient))))); |
| 51 } | 53 } |
| 52 | 54 |
| 53 aura::Window* GetModalTransientChild( | 55 aura::Window* GetModalTransientChild( |
| 54 aura::Window* activatable, | 56 aura::Window* activatable, |
| 55 aura::Window* original) { | 57 aura::Window* original) { |
| 56 aura::Window::Windows::const_iterator it; | 58 aura::Window::Windows::const_iterator it; |
| 57 for (it = activatable->transient_children().begin(); | 59 for (it = activatable->transient_children().begin(); |
| 58 it != activatable->transient_children().end(); | 60 it != activatable->transient_children().end(); |
| 59 ++it) { | 61 ++it) { |
| 60 aura::Window* transient = *it; | 62 aura::Window* transient = *it; |
| 61 if (IsModalTransientChild(transient, original)) { | 63 if (IsModalTransientChild(transient, original)) { |
| 62 return transient->transient_children().empty() ? | 64 return transient->transient_children().empty() ? |
| 63 transient : GetModalTransientChild(transient, original); | 65 transient : GetModalTransientChild(transient, original); |
| 64 } | 66 } |
| 65 } | 67 } |
| 66 return NULL; | 68 return NULL; |
| 67 } | 69 } |
| 68 | 70 |
| 69 } // namespace | 71 } // namespace |
| 70 | 72 |
| 71 void SetModalParent(aura::Window* child, aura::Window* parent) { | 73 void SetModalParent(aura::Window* child, aura::Window* parent) { |
| 72 child->SetProperty(ash::internal::kModalParentKey, parent); | 74 child->SetProperty(kModalParentKey, parent); |
| 73 } | 75 } |
| 74 | 76 |
| 75 aura::Window* GetModalTransient(aura::Window* window) { | 77 aura::Window* GetModalTransient(aura::Window* window) { |
| 76 if (!window) | 78 if (!window) |
| 77 return NULL; | 79 return NULL; |
| 78 | 80 |
| 79 // We always want to check the for the transient child of the activatable | 81 // We always want to check the for the transient child of the activatable |
| 80 // window. | 82 // window. |
| 81 aura::Window* activatable = wm::GetActivatableWindow(window); | 83 aura::Window* activatable = views::corewm::GetActivatableWindow(window); |
| 82 if (!activatable) | 84 if (!activatable) |
| 83 return NULL; | 85 return NULL; |
| 84 | 86 |
| 85 return GetModalTransientChild(activatable, window); | 87 return GetModalTransientChild(activatable, window); |
| 86 } | 88 } |
| 87 | 89 |
| 88 } // namespace wm | |
| 89 | |
| 90 namespace internal { | 90 namespace internal { |
| 91 | 91 |
| 92 //////////////////////////////////////////////////////////////////////////////// | 92 //////////////////////////////////////////////////////////////////////////////// |
| 93 // WindowModalityController, public: | 93 // WindowModalityController, public: |
| 94 | 94 |
| 95 WindowModalityController::WindowModalityController() { | 95 WindowModalityController::WindowModalityController() { |
| 96 aura::Env::GetInstance()->AddObserver(this); | 96 aura::Env::GetInstance()->AddObserver(this); |
| 97 } | 97 } |
| 98 | 98 |
| 99 WindowModalityController::~WindowModalityController() { | 99 WindowModalityController::~WindowModalityController() { |
| 100 aura::Env::GetInstance()->RemoveObserver(this); | 100 aura::Env::GetInstance()->RemoveObserver(this); |
| 101 for (size_t i = 0; i < windows_.size(); ++i) | 101 for (size_t i = 0; i < windows_.size(); ++i) |
| 102 windows_[i]->RemoveObserver(this); | 102 windows_[i]->RemoveObserver(this); |
| 103 } | 103 } |
| 104 | 104 |
| 105 //////////////////////////////////////////////////////////////////////////////// | 105 //////////////////////////////////////////////////////////////////////////////// |
| 106 // WindowModalityController, aura::EventFilter implementation: | 106 // WindowModalityController, aura::EventFilter implementation: |
| 107 | 107 |
| 108 ui::EventResult WindowModalityController::OnKeyEvent(ui::KeyEvent* event) { | 108 ui::EventResult WindowModalityController::OnKeyEvent(ui::KeyEvent* event) { |
| 109 aura::Window* target = static_cast<aura::Window*>(event->target()); | 109 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 110 return wm::GetModalTransient(target) ? ui::ER_CONSUMED : | 110 return GetModalTransient(target) ? ui::ER_CONSUMED : ui::ER_UNHANDLED; |
| 111 ui::ER_UNHANDLED; | |
| 112 } | 111 } |
| 113 | 112 |
| 114 ui::EventResult WindowModalityController::OnMouseEvent(ui::MouseEvent* event) { | 113 ui::EventResult WindowModalityController::OnMouseEvent(ui::MouseEvent* event) { |
| 115 aura::Window* target = static_cast<aura::Window*>(event->target()); | 114 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 116 return ProcessLocatedEvent(target, event) ? ui::ER_CONSUMED : | 115 return ProcessLocatedEvent(target, event) ? ui::ER_CONSUMED : |
| 117 ui::ER_UNHANDLED; | 116 ui::ER_UNHANDLED; |
| 118 } | 117 } |
| 119 | 118 |
| 120 ui::EventResult WindowModalityController::OnTouchEvent(ui::TouchEvent* event) { | 119 ui::EventResult WindowModalityController::OnTouchEvent(ui::TouchEvent* event) { |
| 121 aura::Window* target = static_cast<aura::Window*>(event->target()); | 120 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 141 } | 140 } |
| 142 } | 141 } |
| 143 | 142 |
| 144 void WindowModalityController::OnWindowDestroyed(aura::Window* window) { | 143 void WindowModalityController::OnWindowDestroyed(aura::Window* window) { |
| 145 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); | 144 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); |
| 146 window->RemoveObserver(this); | 145 window->RemoveObserver(this); |
| 147 } | 146 } |
| 148 | 147 |
| 149 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target, | 148 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target, |
| 150 ui::LocatedEvent* event) { | 149 ui::LocatedEvent* event) { |
| 151 aura::Window* modal_transient_child = wm::GetModalTransient(target); | 150 aura::Window* modal_transient_child = GetModalTransient(target); |
| 152 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED || | 151 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED || |
| 153 event->type() == ui::ET_TOUCH_PRESSED)) { | 152 event->type() == ui::ET_TOUCH_PRESSED)) { |
| 154 views::corewm::AnimateWindow(modal_transient_child, | 153 views::corewm::AnimateWindow(modal_transient_child, |
| 155 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); | 154 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 156 } | 155 } |
| 157 return !!modal_transient_child; | 156 return !!modal_transient_child; |
| 158 } | 157 } |
| 159 | 158 |
| 160 } // namespace internal | 159 } // namespace internal |
| 161 } // namespace ash | 160 } // namespace ash |
| OLD | NEW |