OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
tdanderson
2014/05/01 21:58:33
This header will also need to be updated (same for
Nina
2014/05/02 13:27:33
Done.
| |
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/wm/window_cycle_controller.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "ash/session/session_state_delegate.h" | |
10 #include "ash/shell.h" | |
11 #include "ash/shell_window_ids.h" | |
12 #include "ash/wm/mru_window_tracker.h" | |
13 #include "ash/wm/window_cycle_list.h" | |
14 #include "ash/wm/window_util.h" | |
15 #include "ash/wm/workspace_controller.h" | |
16 #include "ui/events/event.h" | |
17 #include "ui/events/event_handler.h" | |
18 | |
19 namespace ash { | |
20 | |
21 namespace { | |
22 | |
23 // Filter to watch for the termination of a keyboard gesture to cycle through | |
24 // multiple windows. | |
25 class WindowCycleEventFilter : public ui::EventHandler { | |
26 public: | |
27 WindowCycleEventFilter(); | |
28 virtual ~WindowCycleEventFilter(); | |
29 | |
30 // Overridden from ui::EventHandler: | |
31 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | |
32 | |
33 private: | |
34 DISALLOW_COPY_AND_ASSIGN(WindowCycleEventFilter); | |
35 }; | |
36 | |
37 // Watch for all keyboard events by filtering the root window. | |
tdanderson
2014/05/01 21:58:33
I don't see what value this comment adds, so I sug
Nina
2014/05/02 13:27:33
I think it slipped from a deleted function. Remove
| |
38 WindowCycleEventFilter::WindowCycleEventFilter() { | |
39 } | |
40 | |
41 WindowCycleEventFilter::~WindowCycleEventFilter() { | |
42 } | |
43 | |
44 void WindowCycleEventFilter::OnKeyEvent(ui::KeyEvent* event) { | |
45 // Views uses VKEY_MENU for both left and right Alt keys. | |
46 if (event->key_code() == ui::VKEY_MENU && | |
47 event->type() == ui::ET_KEY_RELEASED) { | |
48 Shell::GetInstance()->window_cycle_controller()->AltKeyReleased(); | |
49 // Warning: |this| will be deleted from here on. | |
50 } | |
51 } | |
52 | |
53 } // namespace | |
54 | |
55 | |
56 // WindowCycleController, public: | |
57 | |
58 WindowCycleController::WindowCycleController() { | |
59 } | |
60 | |
61 WindowCycleController::~WindowCycleController() { | |
62 StopCycling(); | |
63 } | |
64 | |
65 // static | |
66 bool WindowCycleController::CanCycle() { | |
67 // Don't allow window cycling if the screen is locked or a modal dialog is | |
68 // open. | |
69 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && | |
70 !Shell::GetInstance()->IsSystemModalWindowOpen(); | |
71 } | |
72 | |
73 void WindowCycleController::HandleCycleWindow(Direction direction) { | |
74 if (!CanCycle()) | |
75 return; | |
76 | |
77 // If this is the start of an alt-tab cycle through multiple windows, | |
78 // listen for the alt key being released to stop cycling. | |
79 if (!IsCycling()) | |
80 StartCycling(); | |
81 | |
82 Step(direction); | |
83 } | |
84 | |
85 void WindowCycleController::AltKeyReleased() { | |
tdanderson
2014/05/01 21:58:33
Since all AltKeyReleased() does is call StopCyclin
Nina
2014/05/02 13:27:34
Good catch. Done.
| |
86 StopCycling(); | |
87 } | |
88 | |
89 ////////////////////////////////////////////////////////////////////////////// | |
90 // WindowCycleController, private: | |
91 | |
92 void WindowCycleController::StartCycling() { | |
93 window_cycle_list_.reset(new WindowCycleList(ash::Shell::GetInstance()-> | |
94 mru_window_tracker()->BuildMruWindowList())); | |
95 event_handler_.reset(new WindowCycleEventFilter()); | |
96 Shell::GetInstance()->AddPreTargetHandler(event_handler_.get()); | |
97 } | |
98 | |
99 void WindowCycleController::Step(Direction direction) { | |
100 DCHECK(window_cycle_list_.get()); | |
101 window_cycle_list_->Step(direction); | |
102 } | |
103 | |
104 void WindowCycleController::StopCycling() { | |
105 window_cycle_list_.reset(); | |
106 // Remove our key event filter. | |
107 if (event_handler_) { | |
108 Shell::GetInstance()->RemovePreTargetHandler(event_handler_.get()); | |
109 event_handler_.reset(); | |
110 } | |
111 } | |
112 | |
113 } // namespace ash | |
OLD | NEW |