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() : initialized_(false) { | |
sadrul
2014/04/23 19:32:53
Initialize operational_
| |
14 } | |
15 | |
16 EventRewriterController::~EventRewriterController() { | |
17 Shutdown(); | |
18 } | |
19 | |
20 void EventRewriterController::AddEventRewriter( | |
21 scoped_ptr<ui::EventRewriter> rewriter) { | |
22 DCHECK(!initialized_); | |
23 rewriters_.push_back(rewriter.release()); | |
24 } | |
25 | |
26 void EventRewriterController::Init() { | |
27 DCHECK(!initialized_); | |
28 initialized_ = 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 operational_ = true; | |
37 } | |
38 | |
39 void EventRewriterController::Shutdown() { | |
40 operational_ = false; | |
sadrul
2014/04/23 19:32:53
It's unclear to me why we need both operational_ a
kpschoedel
2014/04/23 21:33:15
I'll change to one. I had separate states to enfor
| |
41 // Remove the rewriters from every root window EventSource and destroy them. | |
42 for (EventRewriters::iterator rewriter_iter = rewriters_.begin(); | |
43 rewriter_iter != rewriters_.end(); | |
44 ++rewriter_iter) { | |
45 aura::Window::Windows windows = ash::Shell::GetAllRootWindows(); | |
46 for (aura::Window::Windows::iterator window_iter = windows.begin(); | |
47 window_iter != windows.end(); | |
48 ++window_iter) { | |
49 (*window_iter)->GetHost()->GetEventSource()->RemoveEventRewriter( | |
50 *rewriter_iter); | |
51 } | |
52 } | |
53 rewriters_.clear(); | |
54 } | |
55 | |
56 void EventRewriterController::OnHostInitialized(aura::WindowTreeHost* host) { | |
57 if (operational_) | |
58 AddToEventSource(host->GetEventSource()); | |
59 } | |
60 | |
61 void EventRewriterController::AddToEventSource(ui::EventSource* source) { | |
62 DCHECK(source); | |
63 for (EventRewriters::iterator it = rewriters_.begin(); it != rewriters_.end(); | |
64 ++it) { | |
65 source->AddEventRewriter(*it); | |
66 } | |
67 } | |
68 | |
69 } // namespace chromeos | |
OLD | NEW |