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