Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Side by Side Diff: ash/common/focus_cycler.cc

Issue 2075923002: mash: Convert FocusCycler to wm common types and move to //ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/focus_cycler.h ('k') | ash/common/wm_shell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/focus_cycler.h"
6 6
7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/wm/mru_window_tracker.h" 7 #include "ash/common/wm/mru_window_tracker.h"
9 #include "ash/common/wm/window_state.h" 8 #include "ash/common/wm/window_state.h"
10 #include "ash/shell.h" 9 #include "ash/common/wm_shell.h"
11 #include "ash/wm/window_state_aura.h" 10 #include "ash/common/wm_window.h"
12 #include "ash/wm/window_util.h"
13 #include "ui/aura/window.h"
14 #include "ui/views/accessible_pane_view.h" 11 #include "ui/views/accessible_pane_view.h"
15 #include "ui/views/focus/focus_search.h" 12 #include "ui/views/focus/focus_search.h"
16 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
17 #include "ui/wm/public/activation_client.h" 14 #include "ui/wm/public/activation_client.h"
18 15
19 namespace ash { 16 namespace ash {
20 17
21 namespace { 18 namespace {
22 19
23 bool HasFocusableWindow() { 20 bool HasFocusableWindow() {
24 return !ash::Shell::GetInstance()-> 21 return !WmShell::Get()->GetMruWindowTracker()->BuildMruWindowList().empty();
25 mru_window_tracker()->BuildMruWindowList().empty();
26 } 22 }
27 23
28 } // namespace 24 } // namespace
29 25
30 FocusCycler::FocusCycler() : widget_activating_(NULL) { 26 FocusCycler::FocusCycler() : widget_activating_(nullptr) {}
31 }
32 27
33 FocusCycler::~FocusCycler() { 28 FocusCycler::~FocusCycler() {}
34 }
35 29
36 void FocusCycler::AddWidget(views::Widget* widget) { 30 void FocusCycler::AddWidget(views::Widget* widget) {
37 widgets_.push_back(widget); 31 widgets_.push_back(widget);
38 } 32 }
39 33
40 void FocusCycler::RemoveWidget(views::Widget* widget) { 34 void FocusCycler::RemoveWidget(views::Widget* widget) {
41 auto iter = std::find(widgets_.begin(), widgets_.end(), widget); 35 auto iter = std::find(widgets_.begin(), widgets_.end(), widget);
42 if (iter != widgets_.end()) 36 if (iter != widgets_.end())
43 widgets_.erase(iter); 37 widgets_.erase(iter);
44 } 38 }
45 39
46 void FocusCycler::RotateFocus(Direction direction) { 40 void FocusCycler::RotateFocus(Direction direction) {
47 aura::Window* window = ash::wm::GetActiveWindow(); 41 WmWindow* window = WmShell::Get()->GetActiveWindow();
48 if (window) { 42 if (window) {
49 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 43 views::Widget* widget = window->GetInternalWidget();
50 // First try to rotate focus within the active widget. If that succeeds, 44 // First try to rotate focus within the active widget. If that succeeds,
51 // we're done. 45 // we're done.
52 if (widget && widget->GetFocusManager()->RotatePaneFocus( 46 if (widget &&
53 direction == BACKWARD ? 47 widget->GetFocusManager()->RotatePaneFocus(
54 views::FocusManager::kBackward : views::FocusManager::kForward, 48 direction == BACKWARD ? views::FocusManager::kBackward
49 : views::FocusManager::kForward,
55 views::FocusManager::kNoWrap)) { 50 views::FocusManager::kNoWrap)) {
56 return; 51 return;
57 } 52 }
58 } 53 }
59 54
60 const bool has_window = HasFocusableWindow(); 55 const bool has_window = HasFocusableWindow();
61 int index = 0; 56 int index = 0;
62 int count = static_cast<int>(widgets_.size()); 57 int count = static_cast<int>(widgets_.size());
63 int browser_index = has_window ? count : -1; 58 int browser_index = has_window ? count : -1;
64 59
(...skipping 13 matching lines...) Expand all
78 else 73 else
79 index = ((index - 1) + count) % count; 74 index = ((index - 1) + count) % count;
80 75
81 // Ensure that we don't loop more than once. 76 // Ensure that we don't loop more than once.
82 if (index == start_index) 77 if (index == start_index)
83 break; 78 break;
84 79
85 if (index == browser_index) { 80 if (index == browser_index) {
86 // Activate the most recently active browser window. 81 // Activate the most recently active browser window.
87 MruWindowTracker::WindowList mru_windows( 82 MruWindowTracker::WindowList mru_windows(
88 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList()); 83 WmShell::Get()->GetMruWindowTracker()->BuildMruWindowList());
89 if (mru_windows.empty()) 84 if (mru_windows.empty())
90 break; 85 break;
91 WmWindow* window = mru_windows.front(); 86 WmWindow* window = mru_windows.front();
92 window->GetWindowState()->Activate(); 87 window->GetWindowState()->Activate();
93 views::Widget* widget = views::Widget::GetWidgetForNativeWindow( 88 views::Widget* widget = window->GetInternalWidget();
94 WmWindowAura::GetAuraWindow(window));
95 if (!widget) 89 if (!widget)
96 break; 90 break;
97 views::FocusManager* focus_manager = widget->GetFocusManager(); 91 views::FocusManager* focus_manager = widget->GetFocusManager();
98 focus_manager->ClearFocus(); 92 focus_manager->ClearFocus();
99 focus_manager->RotatePaneFocus( 93 focus_manager->RotatePaneFocus(direction == BACKWARD
100 direction == BACKWARD ? 94 ? views::FocusManager::kBackward
101 views::FocusManager::kBackward : views::FocusManager::kForward, 95 : views::FocusManager::kForward,
102 views::FocusManager::kWrap); 96 views::FocusManager::kWrap);
103 break; 97 break;
104 } else { 98 } else {
105 if (FocusWidget(widgets_[index])) 99 if (FocusWidget(widgets_[index]))
106 break; 100 break;
107 } 101 }
108 } 102 }
109 } 103 }
110 104
111 bool FocusCycler::FocusWidget(views::Widget* widget) { 105 bool FocusCycler::FocusWidget(views::Widget* widget) {
112 // Note: It is not necessary to set the focus directly to the pane since that 106 // Note: It is not necessary to set the focus directly to the pane since that
113 // will be taken care of by the widget activation. 107 // will be taken care of by the widget activation.
114 widget_activating_ = widget; 108 widget_activating_ = widget;
115 widget->Activate(); 109 widget->Activate();
116 widget_activating_ = NULL; 110 widget_activating_ = NULL;
117 return widget->IsActive(); 111 return widget->IsActive();
118 } 112 }
119 113
120 } // namespace ash 114 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/focus_cycler.h ('k') | ash/common/wm_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698