| 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/root_window.h" | 5 #include "ui/aura/root_window.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 RootWindow* RootWindow::instance_ = NULL; | 79 RootWindow* RootWindow::instance_ = NULL; |
| 80 bool RootWindow::use_fullscreen_host_window_ = false; | 80 bool RootWindow::use_fullscreen_host_window_ = false; |
| 81 bool RootWindow::hide_host_cursor_ = false; | 81 bool RootWindow::hide_host_cursor_ = false; |
| 82 | 82 |
| 83 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
| 84 // RootWindow, public: | 84 // RootWindow, public: |
| 85 | 85 |
| 86 // static | 86 RootWindow::RootWindow() |
| 87 RootWindow* RootWindow::GetInstance() { | 87 : Window(NULL), |
| 88 if (!instance_) { | 88 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), |
| 89 instance_ = new RootWindow; | 89 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
| 90 instance_->Init(); | 90 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), |
| 91 } | 91 mouse_button_flags_(0), |
| 92 return instance_; | 92 last_cursor_(kCursorNull), |
| 93 cursor_shown_(true), |
| 94 ALLOW_THIS_IN_INITIALIZER_LIST(screen_(new ScreenAura(this))), |
| 95 capture_window_(NULL), |
| 96 mouse_pressed_handler_(NULL), |
| 97 mouse_moved_handler_(NULL), |
| 98 focused_window_(NULL), |
| 99 touch_event_handler_(NULL), |
| 100 gesture_handler_(NULL), |
| 101 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 102 gesture_recognizer_(GestureRecognizer::Create(this))), |
| 103 synthesize_mouse_move_(false), |
| 104 waiting_on_compositing_end_(false), |
| 105 draw_on_compositing_end_(false) { |
| 106 SetName("RootWindow"); |
| 107 gfx::Screen::SetInstance(screen_); |
| 108 last_mouse_location_ = host_->QueryMouseLocation(); |
| 109 |
| 110 ui::Compositor::Initialize(false); |
| 111 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), |
| 112 host_->GetSize())); |
| 113 DCHECK(compositor_.get()); |
| 114 compositor_->AddObserver(this); |
| 115 Init(); |
| 93 } | 116 } |
| 94 | 117 |
| 95 // static | 118 RootWindow::~RootWindow() { |
| 96 void RootWindow::DeleteInstance() { | 119 compositor_->RemoveObserver(this); |
| 97 delete instance_; | 120 // Make sure to destroy the compositor before terminating so that state is |
| 98 instance_ = NULL; | 121 // cleared and we don't hit asserts. |
| 122 compositor_.reset(); |
| 123 |
| 124 // Tear down in reverse. Frees any references held by the host. |
| 125 host_.reset(NULL); |
| 126 |
| 127 // An observer may have been added by an animation on the RootWindow. |
| 128 layer()->GetAnimator()->RemoveObserver(this); |
| 129 ui::Compositor::Terminate(); |
| 130 if (instance_ == this) |
| 131 instance_ = NULL; |
| 99 } | 132 } |
| 100 | 133 |
| 101 void RootWindow::ShowRootWindow() { | 134 void RootWindow::ShowRootWindow() { |
| 102 host_->Show(); | 135 host_->Show(); |
| 103 } | 136 } |
| 104 | 137 |
| 105 void RootWindow::SetHostSize(const gfx::Size& size) { | 138 void RootWindow::SetHostSize(const gfx::Size& size) { |
| 106 host_->SetSize(size); | 139 host_->SetSize(size); |
| 107 // Requery the location to constrain it within the new root window size. | 140 // Requery the location to constrain it within the new root window size. |
| 108 last_mouse_location_ = host_->QueryMouseLocation(); | 141 last_mouse_location_ = host_->QueryMouseLocation(); |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 waiting_on_compositing_end_ = false; | 479 waiting_on_compositing_end_ = false; |
| 447 if (draw_on_compositing_end_) { | 480 if (draw_on_compositing_end_) { |
| 448 draw_on_compositing_end_ = false; | 481 draw_on_compositing_end_ = false; |
| 449 Draw(); | 482 Draw(); |
| 450 } | 483 } |
| 451 } | 484 } |
| 452 | 485 |
| 453 //////////////////////////////////////////////////////////////////////////////// | 486 //////////////////////////////////////////////////////////////////////////////// |
| 454 // RootWindow, private: | 487 // RootWindow, private: |
| 455 | 488 |
| 456 RootWindow::RootWindow() | |
| 457 : Window(NULL), | |
| 458 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), | |
| 459 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | |
| 460 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), | |
| 461 mouse_button_flags_(0), | |
| 462 last_cursor_(kCursorNull), | |
| 463 cursor_shown_(true), | |
| 464 ALLOW_THIS_IN_INITIALIZER_LIST(screen_(new ScreenAura(this))), | |
| 465 capture_window_(NULL), | |
| 466 mouse_pressed_handler_(NULL), | |
| 467 mouse_moved_handler_(NULL), | |
| 468 focused_window_(NULL), | |
| 469 touch_event_handler_(NULL), | |
| 470 gesture_handler_(NULL), | |
| 471 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 472 gesture_recognizer_(GestureRecognizer::Create(this))), | |
| 473 synthesize_mouse_move_(false), | |
| 474 waiting_on_compositing_end_(false), | |
| 475 draw_on_compositing_end_(false) { | |
| 476 SetName("RootWindow"); | |
| 477 gfx::Screen::SetInstance(screen_); | |
| 478 last_mouse_location_ = host_->QueryMouseLocation(); | |
| 479 | |
| 480 ui::Compositor::Initialize(false); | |
| 481 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), | |
| 482 host_->GetSize())); | |
| 483 DCHECK(compositor_.get()); | |
| 484 compositor_->AddObserver(this); | |
| 485 } | |
| 486 | |
| 487 RootWindow::~RootWindow() { | |
| 488 compositor_->RemoveObserver(this); | |
| 489 // Make sure to destroy the compositor before terminating so that state is | |
| 490 // cleared and we don't hit asserts. | |
| 491 compositor_.reset(); | |
| 492 | |
| 493 // Tear down in reverse. Frees any references held by the host. | |
| 494 host_.reset(NULL); | |
| 495 | |
| 496 // An observer may have been added by an animation on the RootWindow. | |
| 497 layer()->GetAnimator()->RemoveObserver(this); | |
| 498 ui::Compositor::Terminate(); | |
| 499 if (instance_ == this) | |
| 500 instance_ = NULL; | |
| 501 } | |
| 502 | |
| 503 void RootWindow::HandleMouseCaptureChanged(Window* old_capture_window) { | 489 void RootWindow::HandleMouseCaptureChanged(Window* old_capture_window) { |
| 504 if (capture_window_) | 490 if (capture_window_) |
| 505 host_->SetCapture(); | 491 host_->SetCapture(); |
| 506 else | 492 else |
| 507 host_->ReleaseCapture(); | 493 host_->ReleaseCapture(); |
| 508 | 494 |
| 509 if (old_capture_window && old_capture_window->delegate()) { | 495 if (old_capture_window && old_capture_window->delegate()) { |
| 510 // Send a capture changed event with bogus location data. | 496 // Send a capture changed event with bogus location data. |
| 511 MouseEvent event( | 497 MouseEvent event( |
| 512 ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), gfx::Point(), 0); | 498 ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), gfx::Point(), 0); |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 // is currently broken. See/ crbug.com/107931. | 825 // is currently broken. See/ crbug.com/107931. |
| 840 MouseEvent event(ui::ET_MOUSE_MOVED, | 826 MouseEvent event(ui::ET_MOUSE_MOVED, |
| 841 orig_mouse_location, | 827 orig_mouse_location, |
| 842 orig_mouse_location, | 828 orig_mouse_location, |
| 843 ui::EF_IS_SYNTHESIZED); | 829 ui::EF_IS_SYNTHESIZED); |
| 844 DispatchMouseEvent(&event); | 830 DispatchMouseEvent(&event); |
| 845 #endif | 831 #endif |
| 846 } | 832 } |
| 847 | 833 |
| 848 } // namespace aura | 834 } // namespace aura |
| OLD | NEW |