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/focus_cycler.h" | 5 #include "ash/focus_cycler.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/mru_window_tracker.h" | 8 #include "ash/wm/mru_window_tracker.h" |
9 #include "ash/wm/widget_finder.h" | 9 #include "ash/wm/widget_finder.h" |
10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
11 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
12 #include "ash/wm_window.h" | |
13 #include "ui/views/accessible_pane_view.h" | 12 #include "ui/views/accessible_pane_view.h" |
14 #include "ui/views/focus/focus_search.h" | 13 #include "ui/views/focus/focus_search.h" |
15 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
16 #include "ui/wm/public/activation_client.h" | 15 #include "ui/wm/public/activation_client.h" |
17 | 16 |
18 namespace ash { | 17 namespace ash { |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 bool HasFocusableWindow() { | 21 bool HasFocusableWindow() { |
(...skipping 10 matching lines...) Expand all Loading... |
33 widgets_.push_back(widget); | 32 widgets_.push_back(widget); |
34 } | 33 } |
35 | 34 |
36 void FocusCycler::RemoveWidget(views::Widget* widget) { | 35 void FocusCycler::RemoveWidget(views::Widget* widget) { |
37 auto iter = std::find(widgets_.begin(), widgets_.end(), widget); | 36 auto iter = std::find(widgets_.begin(), widgets_.end(), widget); |
38 if (iter != widgets_.end()) | 37 if (iter != widgets_.end()) |
39 widgets_.erase(iter); | 38 widgets_.erase(iter); |
40 } | 39 } |
41 | 40 |
42 void FocusCycler::RotateFocus(Direction direction) { | 41 void FocusCycler::RotateFocus(Direction direction) { |
43 WmWindow* window = WmWindow::Get(wm::GetActiveWindow()); | 42 aura::Window* window = wm::GetActiveWindow(); |
44 if (window) { | 43 if (window) { |
45 views::Widget* widget = GetInternalWidgetForWindow(window->aura_window()); | 44 views::Widget* widget = GetInternalWidgetForWindow(window); |
46 // First try to rotate focus within the active widget. If that succeeds, | 45 // First try to rotate focus within the active widget. If that succeeds, |
47 // we're done. | 46 // we're done. |
48 if (widget && | 47 if (widget && |
49 widget->GetFocusManager()->RotatePaneFocus( | 48 widget->GetFocusManager()->RotatePaneFocus( |
50 direction == BACKWARD ? views::FocusManager::kBackward | 49 direction == BACKWARD ? views::FocusManager::kBackward |
51 : views::FocusManager::kForward, | 50 : views::FocusManager::kForward, |
52 views::FocusManager::kNoWrap)) { | 51 views::FocusManager::kNoWrap)) { |
53 return; | 52 return; |
54 } | 53 } |
55 } | 54 } |
(...skipping 22 matching lines...) Expand all Loading... |
78 // Ensure that we don't loop more than once. | 77 // Ensure that we don't loop more than once. |
79 if (index == start_index) | 78 if (index == start_index) |
80 break; | 79 break; |
81 | 80 |
82 if (index == browser_index) { | 81 if (index == browser_index) { |
83 // Activate the most recently active browser window. | 82 // Activate the most recently active browser window. |
84 MruWindowTracker::WindowList mru_windows( | 83 MruWindowTracker::WindowList mru_windows( |
85 Shell::Get()->mru_window_tracker()->BuildMruWindowList()); | 84 Shell::Get()->mru_window_tracker()->BuildMruWindowList()); |
86 if (mru_windows.empty()) | 85 if (mru_windows.empty()) |
87 break; | 86 break; |
88 WmWindow* window = mru_windows.front(); | 87 auto* window = mru_windows.front(); |
89 window->GetWindowState()->Activate(); | 88 wm::GetWindowState(window)->Activate(); |
90 views::Widget* widget = GetInternalWidgetForWindow(window->aura_window()); | 89 views::Widget* widget = GetInternalWidgetForWindow(window); |
91 if (!widget) | 90 if (!widget) |
92 break; | 91 break; |
93 views::FocusManager* focus_manager = widget->GetFocusManager(); | 92 views::FocusManager* focus_manager = widget->GetFocusManager(); |
94 focus_manager->ClearFocus(); | 93 focus_manager->ClearFocus(); |
95 focus_manager->RotatePaneFocus(direction == BACKWARD | 94 focus_manager->RotatePaneFocus(direction == BACKWARD |
96 ? views::FocusManager::kBackward | 95 ? views::FocusManager::kBackward |
97 : views::FocusManager::kForward, | 96 : views::FocusManager::kForward, |
98 views::FocusManager::kWrap); | 97 views::FocusManager::kWrap); |
99 break; | 98 break; |
100 } else { | 99 } else { |
101 if (FocusWidget(widgets_[index])) | 100 if (FocusWidget(widgets_[index])) |
102 break; | 101 break; |
103 } | 102 } |
104 } | 103 } |
105 } | 104 } |
106 | 105 |
107 bool FocusCycler::FocusWidget(views::Widget* widget) { | 106 bool FocusCycler::FocusWidget(views::Widget* widget) { |
108 // Note: It is not necessary to set the focus directly to the pane since that | 107 // Note: It is not necessary to set the focus directly to the pane since that |
109 // will be taken care of by the widget activation. | 108 // will be taken care of by the widget activation. |
110 widget_activating_ = widget; | 109 widget_activating_ = widget; |
111 widget->Activate(); | 110 widget->Activate(); |
112 widget_activating_ = NULL; | 111 widget_activating_ = NULL; |
113 return widget->IsActive(); | 112 return widget->IsActive(); |
114 } | 113 } |
115 | 114 |
116 } // namespace ash | 115 } // namespace ash |
OLD | NEW |