Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/aura/env.h" | 5 #include "ui/aura/env.h" |
| 6 #include "ui/aura/env_observer.h" | 6 #include "ui/aura/env_observer.h" |
| 7 #include "ui/aura/single_monitor_manager.h" | 7 #include "ui/aura/single_monitor_manager.h" |
| 8 #include "ui/aura/root_window_host.h" | 8 #include "ui/aura/root_window_host.h" |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/gfx/compositor/compositor.h" | 10 #include "ui/gfx/compositor/compositor.h" |
| 11 | 11 |
| 12 #if defined(USE_X11) | 12 #if defined(USE_X11) |
| 13 #include "ui/aura/monitor_change_observer_x11.h" | 13 #include "ui/aura/monitor_change_observer_x11.h" |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 namespace aura { | 16 namespace aura { |
| 17 | 17 |
| 18 // static | 18 // static |
| 19 Env* Env::instance_ = NULL; | 19 Env* Env::instance_ = NULL; |
| 20 | 20 |
| 21 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
| 22 // Env, public: | 22 // Env, public: |
| 23 | 23 |
| 24 Env::Env() | 24 Env::Env() |
| 25 : mouse_button_flags_(0), | 25 : mouse_button_flags_(0), |
| 26 stacking_client_(NULL), | 26 stacking_client_(NULL) { |
| 27 monitor_manager_(new internal::SingleMonitorManager) | |
| 28 #if defined(USE_X11) | |
| 29 , monitor_change_observer_(new MonitorChangeObserverX11()) | |
| 30 #endif | |
| 31 { | |
| 32 #if !defined(OS_MACOSX) | |
| 33 dispatcher_.reset(CreateDispatcher()); | |
| 34 #endif | |
| 35 ui::Compositor::Initialize(false); | |
| 36 } | 27 } |
| 37 | 28 |
| 38 Env::~Env() { | 29 Env::~Env() { |
| 39 ui::Compositor::Terminate(); | 30 ui::Compositor::Terminate(); |
| 40 } | 31 } |
| 41 | 32 |
| 42 // static | 33 // static |
| 43 Env* Env::GetInstance() { | 34 Env* Env::GetInstance() { |
| 44 if (!instance_) | 35 if (!instance_) { |
| 45 instance_ = new Env; | 36 instance_ = new Env; |
| 37 instance_->Init(); | |
|
oshima
2012/03/24 18:19:39
Ben, I had to move init code out of constructor to
| |
| 38 } | |
| 46 return instance_; | 39 return instance_; |
| 47 } | 40 } |
| 48 | 41 |
| 49 // static | 42 // static |
| 50 void Env::DeleteInstance() { | 43 void Env::DeleteInstance() { |
| 51 delete instance_; | 44 delete instance_; |
| 52 instance_ = NULL; | 45 instance_ = NULL; |
| 53 } | 46 } |
| 54 | 47 |
| 55 void Env::AddObserver(EnvObserver* observer) { | 48 void Env::AddObserver(EnvObserver* observer) { |
| 56 observers_.AddObserver(observer); | 49 observers_.AddObserver(observer); |
| 57 } | 50 } |
| 58 | 51 |
| 59 void Env::RemoveObserver(EnvObserver* observer) { | 52 void Env::RemoveObserver(EnvObserver* observer) { |
| 60 observers_.RemoveObserver(observer); | 53 observers_.RemoveObserver(observer); |
| 61 } | 54 } |
| 62 | 55 |
| 63 void Env::SetMonitorManager(MonitorManager* monitor_manager) { | 56 void Env::SetMonitorManager(MonitorManager* monitor_manager) { |
| 64 monitor_manager_.reset(monitor_manager); | 57 monitor_manager_.reset(monitor_manager); |
| 58 #if defined(USE_X11) | |
| 59 // Update the monitor manager with latest info. | |
| 60 monitor_change_observer_->NotifyMonitorChange(); | |
| 61 #endif | |
| 65 } | 62 } |
| 66 | 63 |
| 67 #if !defined(OS_MACOSX) | 64 #if !defined(OS_MACOSX) |
| 68 MessageLoop::Dispatcher* Env::GetDispatcher() { | 65 MessageLoop::Dispatcher* Env::GetDispatcher() { |
| 69 return dispatcher_.get(); | 66 return dispatcher_.get(); |
| 70 } | 67 } |
| 71 #endif | 68 #endif |
| 72 | 69 |
| 73 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
| 74 // Env, private: | 71 // Env, private: |
| 75 | 72 |
| 73 void Env::Init() { | |
| 74 #if !defined(OS_MACOSX) | |
| 75 dispatcher_.reset(CreateDispatcher()); | |
| 76 #endif | |
| 77 #if defined(USE_X11) | |
| 78 monitor_change_observer_.reset(new internal::MonitorChangeObserverX11); | |
| 79 #endif | |
| 80 SetMonitorManager(new internal::SingleMonitorManager); | |
| 81 ui::Compositor::Initialize(false); | |
| 82 } | |
| 83 | |
| 76 void Env::NotifyWindowInitialized(Window* window) { | 84 void Env::NotifyWindowInitialized(Window* window) { |
| 77 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWindowInitialized(window)); | 85 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWindowInitialized(window)); |
| 78 } | 86 } |
| 79 | 87 |
| 80 } // namespace aura | 88 } // namespace aura |
| OLD | NEW |