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 "chrome/browser/chromeos/events/event_rewriter_controller.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ui/aura/window_tree_host.h" | |
9 #include "ui/events/event_source.h" | |
10 | |
11 namespace chromeos { | |
12 | |
13 EventRewriterController::EventRewriterController() : operational_(false) { | |
14 } | |
15 | |
16 EventRewriterController::~EventRewriterController() { | |
17 Shutdown(); | |
18 } | |
19 | |
20 void EventRewriterController::AddEventRewriter( | |
21 scoped_ptr<ui::EventRewriter> rewriter) { | |
22 DCHECK(!operational_); | |
23 rewriters_.push_back(rewriter.release()); | |
24 } | |
25 | |
26 void EventRewriterController::Init() { | |
27 DCHECK(!operational_); | |
28 operational_ = true; | |
29 // Add the rewriters to each existing root window EventSource. | |
30 aura::Window::Windows windows = ash::Shell::GetAllRootWindows(); | |
31 for (aura::Window::Windows::iterator it = windows.begin(); | |
32 it != windows.end(); | |
33 ++it) { | |
34 AddToEventSource((*it)->GetHost()->GetEventSource()); | |
35 } | |
36 } | |
37 | |
38 void EventRewriterController::Shutdown() { | |
39 operational_ = false; | |
Daniel Erat
2014/04/28 16:51:55
is calling AddEventWriter() and Init() again allow
kpschoedel
2014/04/28 17:23:48
Done.
| |
40 // Remove the rewriters from every root window EventSource and destroy them. | |
41 for (EventRewriters::iterator rewriter_iter = rewriters_.begin(); | |
42 rewriter_iter != rewriters_.end(); | |
43 ++rewriter_iter) { | |
44 aura::Window::Windows windows = ash::Shell::GetAllRootWindows(); | |
45 for (aura::Window::Windows::iterator window_iter = windows.begin(); | |
46 window_iter != windows.end(); | |
47 ++window_iter) { | |
48 (*window_iter)->GetHost()->GetEventSource()->RemoveEventRewriter( | |
49 *rewriter_iter); | |
50 } | |
51 } | |
52 rewriters_.clear(); | |
53 } | |
54 | |
55 void EventRewriterController::OnHostInitialized(aura::WindowTreeHost* host) { | |
56 if (operational_) | |
57 AddToEventSource(host->GetEventSource()); | |
58 } | |
59 | |
60 void EventRewriterController::AddToEventSource(ui::EventSource* source) { | |
61 DCHECK(source); | |
62 for (EventRewriters::iterator it = rewriters_.begin(); it != rewriters_.end(); | |
63 ++it) { | |
64 source->AddEventRewriter(*it); | |
65 } | |
66 } | |
67 | |
68 } // namespace chromeos | |
OLD | NEW |