Chromium Code Reviews| 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 mouse click is enabled or not. | |
| 24 DEFINE_UI_CLASS_PROPERTY_KEY(bool, kActivateOnClickKey, 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::SetActivateOnClick(aura::Window* window, | |
| 39 bool activate_on_click) { | |
| 40 DCHECK(window); | |
| 41 window->SetProperty(kActivateOnClickKey, activate_on_click); | |
| 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::IsWindowConsideredActivatableForEvent( | |
| 84 aura::Window* window, | |
| 85 ui::Event* event) const { | |
| 86 if (!window) | |
| 87 return true; | |
| 88 | |
| 89 if (event->IsMouseEvent()) | |
|
oshima
2017/04/11 20:54:40
don't we need to filter other events such as touch
Qiang(Joe) Xu
2017/04/12 19:00:02
Touch event should be handled on OnGestureEvent. F
| |
| 90 return window->GetProperty(kActivateOnClickKey); | |
| 91 | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 76 aura::Window* AshFocusRules::GetNextActivatableWindow( | 95 aura::Window* AshFocusRules::GetNextActivatableWindow( |
| 77 aura::Window* ignore) const { | 96 aura::Window* ignore) const { |
| 78 DCHECK(ignore); | 97 DCHECK(ignore); |
| 79 | 98 |
| 80 // Start from the container of the most-recently-used window. If the list of | 99 // 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 | 100 // MRU windows is empty, then start from the container of the window that just |
| 82 // lost focus |ignore|. | 101 // lost focus |ignore|. |
| 83 MruWindowTracker* mru = Shell::Get()->mru_window_tracker(); | 102 MruWindowTracker* mru = Shell::Get()->mru_window_tracker(); |
| 84 std::vector<WmWindow*> windows = mru->BuildMruWindowList(); | 103 std::vector<WmWindow*> windows = mru->BuildMruWindowList(); |
| 85 aura::Window* starting_window = | 104 aura::Window* starting_window = |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 aura::Window* container, | 153 aura::Window* container, |
| 135 aura::Window* ignore) const { | 154 aura::Window* ignore) const { |
| 136 for (aura::Window::Windows::const_reverse_iterator i = | 155 for (aura::Window::Windows::const_reverse_iterator i = |
| 137 container->children().rbegin(); | 156 container->children().rbegin(); |
| 138 i != container->children().rend(); ++i) { | 157 i != container->children().rend(); ++i) { |
| 139 WindowState* window_state = GetWindowState(*i); | 158 WindowState* window_state = GetWindowState(*i); |
| 140 if (*i != ignore && window_state->CanActivate() && | 159 if (*i != ignore && window_state->CanActivate() && |
| 141 !window_state->IsMinimized()) | 160 !window_state->IsMinimized()) |
| 142 return *i; | 161 return *i; |
| 143 } | 162 } |
| 144 return NULL; | 163 return nullptr; |
| 145 } | 164 } |
| 146 | 165 |
| 147 } // namespace wm | 166 } // namespace wm |
| 148 } // namespace ash | 167 } // namespace ash |
| OLD | NEW |