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/ash_focus_rules.h" | 5 #include "ash/wm/ash_focus_rules.h" |
6 | 6 |
7 #include "ash/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_port.h" | 9 #include "ash/shell_port.h" |
10 #include "ash/wm/container_finder.h" | 10 #include "ash/wm/container_finder.h" |
11 #include "ash/wm/focus_rules.h" | 11 #include "ash/wm/focus_rules.h" |
12 #include "ash/wm/mru_window_tracker.h" | 12 #include "ash/wm/mru_window_tracker.h" |
13 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
14 #include "ash/wm/window_state_aura.h" | 14 #include "ash/wm/window_state_aura.h" |
15 #include "ash/wm_window.h" | 15 #include "ash/wm_window.h" |
| 16 #include "ui/aura/client/aura_constants.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/events/event.h" |
17 | 19 |
18 namespace ash { | 20 namespace ash { |
19 namespace wm { | 21 namespace wm { |
20 namespace { | 22 namespace { |
21 | 23 |
22 bool BelongsToContainerWithEqualOrGreaterId(const aura::Window* window, | 24 bool BelongsToContainerWithEqualOrGreaterId(const aura::Window* window, |
23 int container_id) { | 25 int container_id) { |
24 for (; window; window = window->parent()) { | 26 for (; window; window = window->parent()) { |
25 if (window->id() >= container_id) | 27 if (window->id() >= container_id) |
26 return true; | 28 return true; |
27 } | 29 } |
28 return false; | 30 return false; |
29 } | 31 } |
30 | 32 |
31 } // namespace | 33 } // namespace |
32 | 34 |
| 35 // static |
| 36 void AshFocusRules::SetActivateOnPointer(aura::Window* window, |
| 37 bool activate_on_pointer) { |
| 38 DCHECK(window); |
| 39 window->SetProperty(aura::client::kActivateOnPointerKey, activate_on_pointer); |
| 40 } |
| 41 |
33 //////////////////////////////////////////////////////////////////////////////// | 42 //////////////////////////////////////////////////////////////////////////////// |
34 // AshFocusRules, public: | 43 // AshFocusRules, public: |
35 | 44 |
36 AshFocusRules::AshFocusRules() {} | 45 AshFocusRules::AshFocusRules() = default; |
37 | 46 |
38 AshFocusRules::~AshFocusRules() {} | 47 AshFocusRules::~AshFocusRules() = default; |
39 | |
40 bool AshFocusRules::IsWindowConsideredActivatable(aura::Window* window) const { | |
41 return ash::IsWindowConsideredActivatable(WmWindow::Get(window)); | |
42 } | |
43 | 48 |
44 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
45 // AshFocusRules, ::wm::FocusRules: | 50 // AshFocusRules, ::wm::FocusRules: |
46 | 51 |
47 bool AshFocusRules::IsToplevelWindow(aura::Window* window) const { | 52 bool AshFocusRules::IsToplevelWindow(aura::Window* window) const { |
48 return ash::IsToplevelWindow(WmWindow::Get(window)); | 53 return ash::IsToplevelWindow(WmWindow::Get(window)); |
49 } | 54 } |
50 | 55 |
51 bool AshFocusRules::SupportsChildActivation(aura::Window* window) const { | 56 bool AshFocusRules::SupportsChildActivation(aura::Window* window) const { |
52 return ash::IsActivatableShellWindowId(window->id()); | 57 return ash::IsActivatableShellWindowId(window->id()); |
(...skipping 13 matching lines...) Expand all Loading... |
66 return false; | 71 return false; |
67 | 72 |
68 if (ShellPort::Get()->IsSystemModalWindowOpen()) { | 73 if (ShellPort::Get()->IsSystemModalWindowOpen()) { |
69 return BelongsToContainerWithEqualOrGreaterId( | 74 return BelongsToContainerWithEqualOrGreaterId( |
70 window, kShellWindowId_SystemModalContainer); | 75 window, kShellWindowId_SystemModalContainer); |
71 } | 76 } |
72 | 77 |
73 return true; | 78 return true; |
74 } | 79 } |
75 | 80 |
| 81 bool AshFocusRules::CanFocusWindow(aura::Window* window, |
| 82 ui::Event* event) const { |
| 83 if (!window) |
| 84 return true; |
| 85 |
| 86 if (event && (event->IsMouseEvent() || event->IsGestureEvent()) && |
| 87 !window->GetProperty(aura::client::kActivateOnPointerKey)) { |
| 88 return false; |
| 89 } |
| 90 |
| 91 return BaseFocusRules::CanFocusWindow(window, event); |
| 92 } |
| 93 |
76 aura::Window* AshFocusRules::GetNextActivatableWindow( | 94 aura::Window* AshFocusRules::GetNextActivatableWindow( |
77 aura::Window* ignore) const { | 95 aura::Window* ignore) const { |
78 DCHECK(ignore); | 96 DCHECK(ignore); |
79 | 97 |
80 // Start from the container of the most-recently-used window. If the list of | 98 // Start from the container of the most-recently-used window. If the list of |
81 // MRU windows is empty, then start from the container of the window that just | 99 // MRU windows is empty, then start from the container of the window that just |
82 // lost focus |ignore|. | 100 // lost focus |ignore|. |
83 MruWindowTracker* mru = Shell::Get()->mru_window_tracker(); | 101 MruWindowTracker* mru = Shell::Get()->mru_window_tracker(); |
84 std::vector<WmWindow*> windows = mru->BuildMruWindowList(); | 102 std::vector<WmWindow*> windows = mru->BuildMruWindowList(); |
85 aura::Window* starting_window = | 103 aura::Window* starting_window = |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 aura::Window* container, | 152 aura::Window* container, |
135 aura::Window* ignore) const { | 153 aura::Window* ignore) const { |
136 for (aura::Window::Windows::const_reverse_iterator i = | 154 for (aura::Window::Windows::const_reverse_iterator i = |
137 container->children().rbegin(); | 155 container->children().rbegin(); |
138 i != container->children().rend(); ++i) { | 156 i != container->children().rend(); ++i) { |
139 WindowState* window_state = GetWindowState(*i); | 157 WindowState* window_state = GetWindowState(*i); |
140 if (*i != ignore && window_state->CanActivate() && | 158 if (*i != ignore && window_state->CanActivate() && |
141 !window_state->IsMinimized()) | 159 !window_state->IsMinimized()) |
142 return *i; | 160 return *i; |
143 } | 161 } |
144 return NULL; | 162 return nullptr; |
145 } | 163 } |
146 | 164 |
147 } // namespace wm | 165 } // namespace wm |
148 } // namespace ash | 166 } // namespace ash |
OLD | NEW |