OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/focus_cycler.h" | |
6 | |
7 #include "ash/accelerators/accelerator_controller.h" | |
8 #include "ash/shell.h" | |
9 #include "ash/shell_delegate.h" | |
10 #include "ui/views/widget/widget.h" | |
11 #include "ui/views/focus/focus_search.h" | |
12 #include "ui/aura/window.h" | |
13 #include "ui/aura/client/activation_client.h" | |
14 | |
15 #include "ui/views/accessible_pane_view.h" | |
16 | |
17 namespace ash { | |
18 | |
19 FocusCycler::FocusCycler() | |
20 : ctrl_forward_key_(ui::VKEY_F2, false, true, false), | |
21 ctrl_back_key_(ui::VKEY_F1, false, true, false) { | |
22 } | |
23 | |
24 FocusCycler::~FocusCycler() { | |
25 } | |
26 | |
27 void FocusCycler::AddWidget(views::Widget* widget) { | |
28 widgets_.push_back(widget); | |
29 | |
30 widget->GetFocusManager()->RegisterAccelerator(ctrl_forward_key_, this); | |
31 widget->GetFocusManager()->RegisterAccelerator(ctrl_back_key_, this); | |
32 } | |
33 | |
34 bool FocusCycler::AcceleratorPressed(const ui::Accelerator& accelerator) { | |
35 switch (accelerator.key_code()) { | |
36 case ui::VKEY_F1: | |
37 RotateFocus(false); | |
38 return true; | |
39 case ui::VKEY_F2: | |
40 RotateFocus(true); | |
41 return true; | |
42 default: | |
43 return false; | |
44 } | |
45 } | |
46 | |
47 bool FocusCycler::CanHandleAccelerators() const { | |
sky
2012/01/31 16:38:15
Make order match that of header.
Zachary Kuznia
2012/01/31 17:57:42
Done.
| |
48 return true; | |
49 } | |
50 | |
51 void FocusCycler::RotateFocus(bool forwards) { | |
52 int index = 0; | |
53 int count = static_cast<int>(widgets_.size()); | |
54 int browser_index = count; | |
55 | |
56 for (; index < count; ++index) { | |
57 if (widgets_[index]->IsActive()) | |
58 break; | |
59 } | |
60 | |
61 count = count + 1; | |
62 | |
63 if (forwards) | |
64 index = (index + 1) % count; | |
65 else | |
66 index = ((index - 1) + count) % count; | |
67 | |
68 if (index == browser_index) { | |
69 // Activate the browser window. | |
70 const std::vector<aura::Window*>& windows = | |
71 Shell::GetInstance()->delegate()->GetCycleWindowList( | |
72 ShellDelegate::SOURCE_LAUNCHER, ShellDelegate::ORDER_MRU); | |
73 if (!windows.empty()) { | |
74 aura::client::GetActivationClient()->ActivateWindow(windows[0]); | |
75 return; | |
sky
2012/01/31 16:38:15
remove the early return here and 85.
Zachary Kuznia
2012/01/31 17:57:42
Changed to break to exit the loop. The loop is ad
| |
76 } | |
77 | |
78 } else { | |
79 views::Widget* widget = widgets_[index]; | |
80 | |
81 views::AccessiblePaneView* view = | |
82 static_cast<views::AccessiblePaneView*>(widget->GetContentsView()); | |
83 if (view->SetPaneFocusAndFocusDefault()) { | |
84 widget->Activate(); | |
85 return; | |
86 } | |
87 } | |
88 } | |
89 | |
90 } // namespace ash | |
OLD | NEW |