OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/events/event_rewriter_controller.h" | 5 #include "chrome/browser/chromeos/events/event_rewriter_controller.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ui/aura/env.h" | |
8 #include "ui/aura/window_tree_host.h" | 9 #include "ui/aura/window_tree_host.h" |
9 #include "ui/events/event_source.h" | 10 #include "ui/events/event_source.h" |
10 | 11 |
11 namespace chromeos { | 12 namespace chromeos { |
12 | 13 |
13 EventRewriterController::EventRewriterController() : initialized_(false) { | 14 EventRewriterController::EventRewriterController() : initialized_(false) { |
14 } | 15 } |
15 | 16 |
16 EventRewriterController::~EventRewriterController() { | 17 EventRewriterController::~EventRewriterController() { |
18 aura::Env::GetInstance()->RemoveObserver(this); | |
17 // Remove the rewriters from every root window EventSource and destroy them. | 19 // Remove the rewriters from every root window EventSource and destroy them. |
18 for (EventRewriters::iterator rewriter_iter = rewriters_.begin(); | 20 for (EventRewriters::iterator rewriter_iter = rewriters_.begin(); |
19 rewriter_iter != rewriters_.end(); | 21 rewriter_iter != rewriters_.end(); |
20 ++rewriter_iter) { | 22 ++rewriter_iter) { |
21 aura::Window::Windows windows = ash::Shell::GetAllRootWindows(); | 23 aura::Window::Windows windows = ash::Shell::GetAllRootWindows(); |
22 for (aura::Window::Windows::iterator window_iter = windows.begin(); | 24 for (aura::Window::Windows::iterator window_iter = windows.begin(); |
23 window_iter != windows.end(); | 25 window_iter != windows.end(); |
24 ++window_iter) { | 26 ++window_iter) { |
25 (*window_iter)->GetHost()->GetEventSource()->RemoveEventRewriter( | 27 (*window_iter)->GetHost()->GetEventSource()->RemoveEventRewriter( |
26 *rewriter_iter); | 28 *rewriter_iter); |
(...skipping 11 matching lines...) Expand all Loading... | |
38 void EventRewriterController::Init() { | 40 void EventRewriterController::Init() { |
39 DCHECK(!initialized_); | 41 DCHECK(!initialized_); |
40 initialized_ = true; | 42 initialized_ = true; |
41 // Add the rewriters to each existing root window EventSource. | 43 // Add the rewriters to each existing root window EventSource. |
42 aura::Window::Windows windows = ash::Shell::GetAllRootWindows(); | 44 aura::Window::Windows windows = ash::Shell::GetAllRootWindows(); |
43 for (aura::Window::Windows::iterator it = windows.begin(); | 45 for (aura::Window::Windows::iterator it = windows.begin(); |
44 it != windows.end(); | 46 it != windows.end(); |
45 ++it) { | 47 ++it) { |
46 AddToEventSource((*it)->GetHost()->GetEventSource()); | 48 AddToEventSource((*it)->GetHost()->GetEventSource()); |
47 } | 49 } |
50 // Add the controller as an observer for new root windows. | |
51 aura::Env::GetInstance()->AddObserver(this); | |
Daniel Erat
2014/05/13 15:27:31
can you do this in the c'tor instead? the add/remo
| |
48 } | 52 } |
49 | 53 |
50 void EventRewriterController::OnHostInitialized(aura::WindowTreeHost* host) { | 54 void EventRewriterController::OnHostInitialized(aura::WindowTreeHost* host) { |
51 if (initialized_) | 55 if (initialized_) |
52 AddToEventSource(host->GetEventSource()); | 56 AddToEventSource(host->GetEventSource()); |
53 } | 57 } |
54 | 58 |
55 void EventRewriterController::AddToEventSource(ui::EventSource* source) { | 59 void EventRewriterController::AddToEventSource(ui::EventSource* source) { |
56 DCHECK(source); | 60 DCHECK(source); |
57 for (EventRewriters::iterator it = rewriters_.begin(); it != rewriters_.end(); | 61 for (EventRewriters::iterator it = rewriters_.begin(); it != rewriters_.end(); |
58 ++it) { | 62 ++it) { |
59 source->AddEventRewriter(*it); | 63 source->AddEventRewriter(*it); |
60 } | 64 } |
61 } | 65 } |
62 | 66 |
63 } // namespace chromeos | 67 } // namespace chromeos |
OLD | NEW |