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_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
11 #include "ui/aura/client/capture_client.h" | 11 #include "ui/aura/client/capture_client.h" |
12 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
13 #include "ui/aura/event.h" | |
14 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
15 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/base/event.h" |
16 #include "ui/base/ui_base_types.h" | 16 #include "ui/base/ui_base_types.h" |
17 | 17 |
18 namespace ash { | 18 namespace ash { |
19 | 19 |
20 namespace wm { | 20 namespace wm { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 bool TransientChildIsWindowModal(aura::Window* window) { | 24 bool TransientChildIsWindowModal(aura::Window* window) { |
25 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW; | 25 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 WindowModalityController::~WindowModalityController() { | 68 WindowModalityController::~WindowModalityController() { |
69 aura::Env::GetInstance()->RemoveObserver(this); | 69 aura::Env::GetInstance()->RemoveObserver(this); |
70 for (size_t i = 0; i < windows_.size(); ++i) | 70 for (size_t i = 0; i < windows_.size(); ++i) |
71 windows_[i]->RemoveObserver(this); | 71 windows_[i]->RemoveObserver(this); |
72 } | 72 } |
73 | 73 |
74 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
75 // WindowModalityController, aura::EventFilter implementation: | 75 // WindowModalityController, aura::EventFilter implementation: |
76 | 76 |
77 bool WindowModalityController::PreHandleKeyEvent(aura::Window* target, | 77 bool WindowModalityController::PreHandleKeyEvent(aura::Window* target, |
78 aura::KeyEvent* event) { | 78 ui::KeyEvent* event) { |
79 return !!wm::GetWindowModalTransient(target); | 79 return !!wm::GetWindowModalTransient(target); |
80 } | 80 } |
81 | 81 |
82 bool WindowModalityController::PreHandleMouseEvent(aura::Window* target, | 82 bool WindowModalityController::PreHandleMouseEvent(aura::Window* target, |
83 aura::MouseEvent* event) { | 83 ui::MouseEvent* event) { |
84 return ProcessLocatedEvent(target, event); | 84 return ProcessLocatedEvent(target, event); |
85 } | 85 } |
86 | 86 |
87 ui::TouchStatus WindowModalityController::PreHandleTouchEvent( | 87 ui::TouchStatus WindowModalityController::PreHandleTouchEvent( |
88 aura::Window* target, | 88 aura::Window* target, |
89 aura::TouchEvent* event) { | 89 ui::TouchEventImpl* event) { |
90 return ProcessLocatedEvent(target, event) ? ui::TOUCH_STATUS_CONTINUE : | 90 return ProcessLocatedEvent(target, event) ? ui::TOUCH_STATUS_CONTINUE : |
91 ui::TOUCH_STATUS_UNKNOWN; | 91 ui::TOUCH_STATUS_UNKNOWN; |
92 } | 92 } |
93 | 93 |
94 ui::GestureStatus WindowModalityController::PreHandleGestureEvent( | 94 ui::GestureStatus WindowModalityController::PreHandleGestureEvent( |
95 aura::Window* target, | 95 aura::Window* target, |
96 aura::GestureEvent* event) { | 96 ui::GestureEventImpl* event) { |
97 // TODO: make gestures work with modals. | 97 // TODO: make gestures work with modals. |
98 return ui::GESTURE_STATUS_UNKNOWN; | 98 return ui::GESTURE_STATUS_UNKNOWN; |
99 } | 99 } |
100 | 100 |
101 void WindowModalityController::OnWindowInitialized(aura::Window* window) { | 101 void WindowModalityController::OnWindowInitialized(aura::Window* window) { |
102 windows_.push_back(window); | 102 windows_.push_back(window); |
103 window->AddObserver(this); | 103 window->AddObserver(this); |
104 } | 104 } |
105 | 105 |
106 void WindowModalityController::OnWindowVisibilityChanged( | 106 void WindowModalityController::OnWindowVisibilityChanged( |
107 aura::Window* window, | 107 aura::Window* window, |
108 bool visible) { | 108 bool visible) { |
109 if (visible && window->GetProperty(aura::client::kModalKey) == | 109 if (visible && window->GetProperty(aura::client::kModalKey) == |
110 ui::MODAL_TYPE_WINDOW) { | 110 ui::MODAL_TYPE_WINDOW) { |
111 // Make sure no other window has capture, otherwise |window| won't get mouse | 111 // Make sure no other window has capture, otherwise |window| won't get mouse |
112 // events. | 112 // events. |
113 aura::Window* capture_window = aura::client::GetCaptureWindow(window); | 113 aura::Window* capture_window = aura::client::GetCaptureWindow(window); |
114 if (capture_window) | 114 if (capture_window) |
115 capture_window->ReleaseCapture(); | 115 capture_window->ReleaseCapture(); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 void WindowModalityController::OnWindowDestroyed(aura::Window* window) { | 119 void WindowModalityController::OnWindowDestroyed(aura::Window* window) { |
120 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); | 120 windows_.erase(std::find(windows_.begin(), windows_.end(), window)); |
121 window->RemoveObserver(this); | 121 window->RemoveObserver(this); |
122 } | 122 } |
123 | 123 |
124 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target, | 124 bool WindowModalityController::ProcessLocatedEvent(aura::Window* target, |
125 aura::LocatedEvent* event) { | 125 ui::LocatedEvent* event) { |
126 aura::Window* modal_transient_child = wm::GetWindowModalTransient(target); | 126 aura::Window* modal_transient_child = wm::GetWindowModalTransient(target); |
127 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED || | 127 if (modal_transient_child && (event->type() == ui::ET_MOUSE_PRESSED || |
128 event->type() == ui::ET_TOUCH_PRESSED)) { | 128 event->type() == ui::ET_TOUCH_PRESSED)) { |
129 wm::ActivateWindow(modal_transient_child); | 129 wm::ActivateWindow(modal_transient_child); |
130 } | 130 } |
131 return !!modal_transient_child; | 131 return !!modal_transient_child; |
132 } | 132 } |
133 | 133 |
134 } // namespace internal | 134 } // namespace internal |
135 } // namespace ash | 135 } // namespace ash |
OLD | NEW |