| 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 "ash/wm/focus_rules.h" | 5 #include "ash/wm/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_delegate.h" | 9 #include "ash/shell_delegate.h" |
| 10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/wm/public/activation_delegate.h" |
| 12 | 13 |
| 13 namespace ash { | 14 namespace ash { |
| 14 | 15 |
| 15 bool IsToplevelWindow(aura::Window* window) { | 16 bool IsToplevelWindow(aura::Window* window) { |
| 16 DCHECK(window); | 17 DCHECK(window); |
| 17 // The window must in a valid hierarchy. | 18 // The window must in a valid hierarchy. |
| 18 if (!window->GetRootWindow()) | 19 if (!window->GetRootWindow()) |
| 19 return false; | 20 return false; |
| 20 | 21 |
| 21 // The window must exist within a container that supports activation. | 22 // The window must exist within a container that supports activation. |
| 22 // The window cannot be blocked by a modal transient. | 23 // The window cannot be blocked by a modal transient. |
| 23 return IsActivatableShellWindowId(window->parent()->id()); | 24 return IsActivatableShellWindowId(window->parent()->id()); |
| 24 } | 25 } |
| 25 | 26 |
| 26 bool IsWindowConsideredActivatable(aura::Window* window) { | 27 bool IsWindowConsideredActivatable(aura::Window* window) { |
| 27 DCHECK(window); | 28 DCHECK(window); |
| 28 // Only toplevel windows can be activated. | 29 // Only toplevel windows can be activated. |
| 29 if (!IsToplevelWindow(window)) | 30 if (!IsToplevelWindow(window)) |
| 30 return false; | 31 return false; |
| 31 | 32 |
| 32 // The window must be visible. | 33 if (!IsWindowConsideredVisibleForActivation(window)) |
| 33 return IsWindowConsideredVisibleForActivation(window); | 34 return false; |
| 35 |
| 36 if (::wm::GetActivationDelegate(window) && |
| 37 !::wm::GetActivationDelegate(window)->ShouldActivate()) { |
| 38 return false; |
| 39 } |
| 40 |
| 41 return window->CanFocus(); |
| 34 } | 42 } |
| 35 | 43 |
| 36 bool IsWindowConsideredVisibleForActivation(aura::Window* window) { | 44 bool IsWindowConsideredVisibleForActivation(aura::Window* window) { |
| 37 DCHECK(window); | 45 DCHECK(window); |
| 38 // If the |window| doesn't belong to the current active user and also doesn't | 46 // If the |window| doesn't belong to the current active user and also doesn't |
| 39 // show for the current active user, then it should not be activated. | 47 // show for the current active user, then it should not be activated. |
| 40 if (!Shell::Get()->shell_delegate()->CanShowWindowForUser(window)) | 48 if (!Shell::Get()->shell_delegate()->CanShowWindowForUser(window)) |
| 41 return false; | 49 return false; |
| 42 | 50 |
| 43 if (window->IsVisible()) | 51 if (window->IsVisible()) |
| 44 return true; | 52 return true; |
| 45 | 53 |
| 46 // Minimized windows are hidden in their minimized state, but they can always | 54 // Minimized windows are hidden in their minimized state, but they can always |
| 47 // be activated. | 55 // be activated. |
| 48 if (wm::GetWindowState(window)->IsMinimized()) | 56 if (wm::GetWindowState(window)->IsMinimized()) |
| 49 return true; | 57 return true; |
| 50 | 58 |
| 51 if (!window->TargetVisibility()) | 59 if (!window->TargetVisibility()) |
| 52 return false; | 60 return false; |
| 53 | 61 |
| 54 const int parent_shell_window_id = window->parent()->id(); | 62 const int parent_shell_window_id = window->parent()->id(); |
| 55 return parent_shell_window_id == kShellWindowId_DefaultContainer || | 63 return parent_shell_window_id == kShellWindowId_DefaultContainer || |
| 56 parent_shell_window_id == kShellWindowId_LockScreenContainer; | 64 parent_shell_window_id == kShellWindowId_LockScreenContainer; |
| 57 } | 65 } |
| 58 | 66 |
| 59 } // namespace ash | 67 } // namespace ash |
| OLD | NEW |