diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 21:05:04 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 21:05:04 +0000 |
commit | be8857a9da76bd9428f78f62feffa92bc2918023 (patch) | |
tree | f48642693658270ff1214761f3ecd5f6b55c24e0 /ui/aura | |
parent | ee847afb8a3c6cb9efba2c625a8a56083df81afb (diff) | |
download | chromium_src-be8857a9da76bd9428f78f62feffa92bc2918023.zip chromium_src-be8857a9da76bd9428f78f62feffa92bc2918023.tar.gz chromium_src-be8857a9da76bd9428f78f62feffa92bc2918023.tar.bz2 |
Revert 124461 - Remove the singleton instance get/delete methods from RootWindow (yay)
http://crbug.com/112131
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9535025
TBR=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9564023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124479 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/demo/demo_main.cc | 4 | ||||
-rw-r--r-- | ui/aura/root_window.cc | 102 | ||||
-rw-r--r-- | ui/aura/root_window.h | 7 | ||||
-rw-r--r-- | ui/aura/root_window_host_linux.cc | 8 | ||||
-rw-r--r-- | ui/aura/root_window_host_linux.h | 6 | ||||
-rw-r--r-- | ui/aura/test/aura_test_base.cc | 19 | ||||
-rw-r--r-- | ui/aura/test/aura_test_base.h | 4 |
7 files changed, 90 insertions, 60 deletions
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc index d6eccc2..48f2e8d 100644 --- a/ui/aura/demo/demo_main.cc +++ b/ui/aura/demo/demo_main.cc @@ -88,7 +88,7 @@ int main(int argc, char** argv) { MessageLoop message_loop(MessageLoop::TYPE_UI); ui::CompositorTestSupport::Initialize(); - scoped_ptr<aura::RootWindow> root_window(new aura::RootWindow); + aura::RootWindow::GetInstance(); // Create a hierarchy of test windows. DemoWindowDelegate window_delegate1(SK_ColorBLUE); @@ -115,7 +115,7 @@ int main(int argc, char** argv) { window3.Show(); window3.SetParent(&window2); - root_window->ShowRootWindow(); + aura::RootWindow::GetInstance()->ShowRootWindow(); MessageLoopForUI::current()->Run(); ui::CompositorTestSupport::Terminate(); diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index 3c3ece6..aaec097 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -83,52 +83,19 @@ bool RootWindow::hide_host_cursor_ = false; //////////////////////////////////////////////////////////////////////////////// // RootWindow, public: -RootWindow::RootWindow() - : Window(NULL), - host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), - ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), - ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), - mouse_button_flags_(0), - last_cursor_(kCursorNull), - cursor_shown_(true), - ALLOW_THIS_IN_INITIALIZER_LIST(screen_(new ScreenAura(this))), - capture_window_(NULL), - mouse_pressed_handler_(NULL), - mouse_moved_handler_(NULL), - focused_window_(NULL), - touch_event_handler_(NULL), - gesture_handler_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST( - gesture_recognizer_(GestureRecognizer::Create(this))), - synthesize_mouse_move_(false), - waiting_on_compositing_end_(false), - draw_on_compositing_end_(false) { - SetName("RootWindow"); - gfx::Screen::SetInstance(screen_); - last_mouse_location_ = host_->QueryMouseLocation(); - - ui::Compositor::Initialize(false); - compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), - host_->GetSize())); - DCHECK(compositor_.get()); - compositor_->AddObserver(this); - Init(); +// static +RootWindow* RootWindow::GetInstance() { + if (!instance_) { + instance_ = new RootWindow; + instance_->Init(); + } + return instance_; } -RootWindow::~RootWindow() { - compositor_->RemoveObserver(this); - // Make sure to destroy the compositor before terminating so that state is - // cleared and we don't hit asserts. - compositor_.reset(); - - // Tear down in reverse. Frees any references held by the host. - host_.reset(NULL); - - // An observer may have been added by an animation on the RootWindow. - layer()->GetAnimator()->RemoveObserver(this); - ui::Compositor::Terminate(); - if (instance_ == this) - instance_ = NULL; +// static +void RootWindow::DeleteInstance() { + delete instance_; + instance_ = NULL; } void RootWindow::ShowRootWindow() { @@ -478,6 +445,53 @@ void RootWindow::OnCompositingEnded(ui::Compositor*) { //////////////////////////////////////////////////////////////////////////////// // RootWindow, private: +RootWindow::RootWindow() + : Window(NULL), + host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), + ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), + mouse_button_flags_(0), + last_cursor_(kCursorNull), + cursor_shown_(true), + ALLOW_THIS_IN_INITIALIZER_LIST(screen_(new ScreenAura(this))), + capture_window_(NULL), + mouse_pressed_handler_(NULL), + mouse_moved_handler_(NULL), + focused_window_(NULL), + touch_event_handler_(NULL), + gesture_handler_(NULL), + ALLOW_THIS_IN_INITIALIZER_LIST( + gesture_recognizer_(GestureRecognizer::Create(this))), + synthesize_mouse_move_(false), + waiting_on_compositing_end_(false), + draw_on_compositing_end_(false) { + SetName("RootWindow"); + gfx::Screen::SetInstance(screen_); + last_mouse_location_ = host_->QueryMouseLocation(); + + ui::Compositor::Initialize(false); + compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), + host_->GetSize())); + DCHECK(compositor_.get()); + compositor_->AddObserver(this); +} + +RootWindow::~RootWindow() { + compositor_->RemoveObserver(this); + // Make sure to destroy the compositor before terminating so that state is + // cleared and we don't hit asserts. + compositor_.reset(); + + // Tear down in reverse. Frees any references held by the host. + host_.reset(NULL); + + // An observer may have been added by an animation on the RootWindow. + layer()->GetAnimator()->RemoveObserver(this); + ui::Compositor::Terminate(); + if (instance_ == this) + instance_ = NULL; +} + void RootWindow::HandleMouseCaptureChanged(Window* old_capture_window) { if (capture_window_) host_->SetCapture(); diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h index 983ec87..b04857d 100644 --- a/ui/aura/root_window.h +++ b/ui/aura/root_window.h @@ -50,8 +50,8 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, public internal::FocusManager, public ui::LayerAnimationObserver { public: - RootWindow(); - virtual ~RootWindow(); + static RootWindow* GetInstance(); + static void DeleteInstance(); static void set_use_fullscreen_host_window(bool use_fullscreen) { use_fullscreen_host_window_ = use_fullscreen; @@ -197,6 +197,9 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, private: friend class Window; + RootWindow(); + virtual ~RootWindow(); + // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, // sending exited and entered events as its value changes. void HandleMouseMoved(const MouseEvent& event, Window* target); diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc index a6c4e5a..342e114 100644 --- a/ui/aura/root_window_host_linux.cc +++ b/ui/aura/root_window_host_linux.cc @@ -305,6 +305,8 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) if (base::MessagePumpForUI::HasXInput2()) ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); + MessageLoopForUI::current()->AddDestructionObserver(this); + // Initialize invisible cursor. char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; XColor black; @@ -326,6 +328,8 @@ RootWindowHostLinux::~RootWindowHostLinux() { ui::GetXCursor(ui::kCursorClearXCursorCache); XFreeCursor(xdisplay_, invisible_cursor_); + + MessageLoopForUI::current()->RemoveDestructionObserver(this); } base::MessagePumpDispatcher::DispatchStatus RootWindowHostLinux::Dispatch( @@ -620,6 +624,10 @@ void RootWindowHostLinux::PostNativeEvent( XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); } +void RootWindowHostLinux::WillDestroyCurrentMessageLoop() { + aura::RootWindow::DeleteInstance(); +} + bool RootWindowHostLinux::IsWindowManagerPresent() { // Per ICCCM 2.8, "Manager Selections", window managers should take ownership // of WM_Sn selections (where n is a screen number). diff --git a/ui/aura/root_window_host_linux.h b/ui/aura/root_window_host_linux.h index 2ad9fe7..0d05b7b 100644 --- a/ui/aura/root_window_host_linux.h +++ b/ui/aura/root_window_host_linux.h @@ -17,7 +17,8 @@ namespace aura { -class RootWindowHostLinux : public RootWindowHost { +class RootWindowHostLinux : public RootWindowHost, + public MessageLoop::DestructionObserver { public: explicit RootWindowHostLinux(const gfx::Rect& bounds); virtual ~RootWindowHostLinux(); @@ -44,6 +45,9 @@ class RootWindowHostLinux : public RootWindowHost { virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; + // MessageLoop::DestructionObserver Overrides. + virtual void WillDestroyCurrentMessageLoop() OVERRIDE; + // Returns true if there's an X window manager present... in most cases. Some // window managers (notably, ion3) don't implement enough of ICCCM for us to // detect that they're there. diff --git a/ui/aura/test/aura_test_base.cc b/ui/aura/test/aura_test_base.cc index a7399a8..5747b38 100644 --- a/ui/aura/test/aura_test_base.cc +++ b/ui/aura/test/aura_test_base.cc @@ -10,33 +10,34 @@ namespace aura { namespace test { -AuraTestBase::AuraTestBase() { +AuraTestBase::AuraTestBase() : root_window_(RootWindow::GetInstance()) { + helper_.InitRootWindow(root_window_); } AuraTestBase::~AuraTestBase() { + // Flush the message loop because we have pending release tasks + // and these tasks if un-executed would upset Valgrind. + helper_.RunAllPendingInMessageLoop(root_window_); + + // Ensure that we don't use the previously-allocated static RootWindow object + // later -- on Linux, it holds a reference to our message loop's X connection. + RootWindow::DeleteInstance(); } void AuraTestBase::SetUp() { testing::Test::SetUp(); - root_window_.reset(new aura::RootWindow); - helper_.InitRootWindow(root_window()); helper_.SetUp(); stacking_client_.reset(new TestStackingClient(root_window())); } void AuraTestBase::TearDown() { - // Flush the message loop because we have pending release tasks - // and these tasks if un-executed would upset Valgrind. - RunAllPendingInMessageLoop(); - stacking_client_.reset(); helper_.TearDown(); - root_window_.reset(); testing::Test::TearDown(); } void AuraTestBase::RunAllPendingInMessageLoop() { - helper_.RunAllPendingInMessageLoop(root_window()); + helper_.RunAllPendingInMessageLoop(root_window_); } } // namespace test diff --git a/ui/aura/test/aura_test_base.h b/ui/aura/test/aura_test_base.h index 14bd3f9..7b2a134 100644 --- a/ui/aura/test/aura_test_base.h +++ b/ui/aura/test/aura_test_base.h @@ -30,11 +30,11 @@ class AuraTestBase : public testing::Test { protected: void RunAllPendingInMessageLoop(); - RootWindow* root_window() { return root_window_.get(); } + RootWindow* root_window() { return root_window_; } private: AuraTestHelper helper_; - scoped_ptr<RootWindow> root_window_; + RootWindow* root_window_; scoped_ptr<TestStackingClient> stacking_client_; DISALLOW_COPY_AND_ASSIGN(AuraTestBase); |