OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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/wm/window_cycle_controller.h" | |
6 | |
7 #include <algorithm> | |
flackr
2014/05/07 00:07:55
Don't think this is used.
Nina
2014/05/07 14:55:42
Removed. However, I get a warning from lint if I r
| |
8 | |
9 #include "ash/session/session_state_delegate.h" | |
10 #include "ash/shell.h" | |
11 #include "ash/shell_window_ids.h" | |
flackr
2014/05/07 00:07:55
This isn't used either.
Nina
2014/05/07 14:55:42
Done.
| |
12 #include "ash/wm/mru_window_tracker.h" | |
13 #include "ash/wm/window_cycle_list.h" | |
14 #include "ash/wm/window_util.h" | |
flackr
2014/05/07 00:07:55
or this.
Nina
2014/05/07 14:55:42
Done.
| |
15 #include "ash/wm/workspace_controller.h" | |
flackr
2014/05/07 00:07:55
Possibly not this either.
Nina
2014/05/07 14:55:42
Done.
| |
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 WindowCycleEventFilter::WindowCycleEventFilter() { | |
38 } | |
39 | |
40 WindowCycleEventFilter::~WindowCycleEventFilter() { | |
41 } | |
42 | |
43 void WindowCycleEventFilter::OnKeyEvent(ui::KeyEvent* event) { | |
44 // Views uses VKEY_MENU for both left and right Alt keys. | |
45 if (event->key_code() == ui::VKEY_MENU && | |
46 event->type() == ui::ET_KEY_RELEASED) { | |
47 Shell::GetInstance()->window_cycle_controller()->StopCycling(); | |
48 // Warning: |this| will be deleted from here on. | |
49 } | |
50 } | |
51 | |
52 } // namespace | |
53 | |
54 | |
55 // WindowCycleController, public: | |
56 | |
57 WindowCycleController::WindowCycleController() { | |
58 } | |
59 | |
60 WindowCycleController::~WindowCycleController() { | |
61 StopCycling(); | |
flackr
2014/05/07 00:07:55
With the comment on line 86 fixed, this probably d
Nina
2014/05/07 14:55:42
Done.
| |
62 } | |
63 | |
64 // static | |
65 bool WindowCycleController::CanCycle() { | |
66 // Don't allow window cycling if the screen is locked or a modal dialog is | |
67 // open. | |
68 return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && | |
69 !Shell::GetInstance()->IsSystemModalWindowOpen(); | |
70 } | |
71 | |
72 void WindowCycleController::HandleCycleWindow(Direction direction) { | |
73 if (!CanCycle()) | |
74 return; | |
75 | |
76 if (!IsCycling()) | |
77 StartCycling(); | |
78 | |
79 Step(direction); | |
80 } | |
81 | |
82 void WindowCycleController::StartCycling() { | |
83 window_cycle_list_.reset(new WindowCycleList(ash::Shell::GetInstance()-> | |
84 mru_window_tracker()->BuildMruWindowList())); | |
85 event_handler_.reset(new WindowCycleEventFilter()); | |
flackr
2014/05/07 16:03:45
Sorry, didn't mean to move the event_handler_ cons
| |
86 Shell::GetInstance()->AddPreTargetHandler(event_handler_.get()); | |
flackr
2014/05/07 00:07:55
Add and remove the pretarget handler from the Wind
Nina
2014/05/07 14:55:42
Done.
| |
87 } | |
88 | |
89 ////////////////////////////////////////////////////////////////////////////// | |
90 // WindowCycleController, private: | |
91 | |
92 void WindowCycleController::Step(Direction direction) { | |
93 DCHECK(window_cycle_list_.get()); | |
94 window_cycle_list_->Step(direction); | |
95 } | |
96 | |
97 void WindowCycleController::StopCycling() { | |
98 window_cycle_list_.reset(); | |
99 // Remove our key event filter. | |
100 if (event_handler_) { | |
flackr
2014/05/07 00:07:55
And with the comment on line 86, event_handler_ ca
Nina
2014/05/07 14:55:42
Done.
| |
101 Shell::GetInstance()->RemovePreTargetHandler(event_handler_.get()); | |
102 event_handler_.reset(); | |
103 } | |
104 } | |
105 | |
106 } // namespace ash | |
OLD | NEW |