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 RootWindow::RootWindow() | 86 // static |
87 : Window(NULL), | 87 RootWindow* RootWindow::GetInstance() { |
88 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), | 88 if (!instance_) { |
89 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | 89 instance_ = new RootWindow; |
90 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), | 90 instance_->Init(); |
91 mouse_button_flags_(0), | 91 } |
92 last_cursor_(kCursorNull), | 92 return instance_; |
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(); | |
116 } | 93 } |
117 | 94 |
118 RootWindow::~RootWindow() { | 95 // static |
119 compositor_->RemoveObserver(this); | 96 void RootWindow::DeleteInstance() { |
120 // Make sure to destroy the compositor before terminating so that state is | 97 delete instance_; |
121 // cleared and we don't hit asserts. | 98 instance_ = NULL; |
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; | |
132 } | 99 } |
133 | 100 |
134 void RootWindow::ShowRootWindow() { | 101 void RootWindow::ShowRootWindow() { |
135 host_->Show(); | 102 host_->Show(); |
136 } | 103 } |
137 | 104 |
138 void RootWindow::SetHostSize(const gfx::Size& size) { | 105 void RootWindow::SetHostSize(const gfx::Size& size) { |
139 host_->SetSize(size); | 106 host_->SetSize(size); |
140 // Requery the location to constrain it within the new root window size. | 107 // Requery the location to constrain it within the new root window size. |
141 last_mouse_location_ = host_->QueryMouseLocation(); | 108 last_mouse_location_ = host_->QueryMouseLocation(); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 waiting_on_compositing_end_ = false; | 438 waiting_on_compositing_end_ = false; |
472 if (draw_on_compositing_end_) { | 439 if (draw_on_compositing_end_) { |
473 draw_on_compositing_end_ = false; | 440 draw_on_compositing_end_ = false; |
474 Draw(); | 441 Draw(); |
475 } | 442 } |
476 } | 443 } |
477 | 444 |
478 //////////////////////////////////////////////////////////////////////////////// | 445 //////////////////////////////////////////////////////////////////////////////// |
479 // RootWindow, private: | 446 // RootWindow, private: |
480 | 447 |
| 448 RootWindow::RootWindow() |
| 449 : Window(NULL), |
| 450 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), |
| 451 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
| 452 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), |
| 453 mouse_button_flags_(0), |
| 454 last_cursor_(kCursorNull), |
| 455 cursor_shown_(true), |
| 456 ALLOW_THIS_IN_INITIALIZER_LIST(screen_(new ScreenAura(this))), |
| 457 capture_window_(NULL), |
| 458 mouse_pressed_handler_(NULL), |
| 459 mouse_moved_handler_(NULL), |
| 460 focused_window_(NULL), |
| 461 touch_event_handler_(NULL), |
| 462 gesture_handler_(NULL), |
| 463 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 464 gesture_recognizer_(GestureRecognizer::Create(this))), |
| 465 synthesize_mouse_move_(false), |
| 466 waiting_on_compositing_end_(false), |
| 467 draw_on_compositing_end_(false) { |
| 468 SetName("RootWindow"); |
| 469 gfx::Screen::SetInstance(screen_); |
| 470 last_mouse_location_ = host_->QueryMouseLocation(); |
| 471 |
| 472 ui::Compositor::Initialize(false); |
| 473 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), |
| 474 host_->GetSize())); |
| 475 DCHECK(compositor_.get()); |
| 476 compositor_->AddObserver(this); |
| 477 } |
| 478 |
| 479 RootWindow::~RootWindow() { |
| 480 compositor_->RemoveObserver(this); |
| 481 // Make sure to destroy the compositor before terminating so that state is |
| 482 // cleared and we don't hit asserts. |
| 483 compositor_.reset(); |
| 484 |
| 485 // Tear down in reverse. Frees any references held by the host. |
| 486 host_.reset(NULL); |
| 487 |
| 488 // An observer may have been added by an animation on the RootWindow. |
| 489 layer()->GetAnimator()->RemoveObserver(this); |
| 490 ui::Compositor::Terminate(); |
| 491 if (instance_ == this) |
| 492 instance_ = NULL; |
| 493 } |
| 494 |
481 void RootWindow::HandleMouseCaptureChanged(Window* old_capture_window) { | 495 void RootWindow::HandleMouseCaptureChanged(Window* old_capture_window) { |
482 if (capture_window_) | 496 if (capture_window_) |
483 host_->SetCapture(); | 497 host_->SetCapture(); |
484 else | 498 else |
485 host_->ReleaseCapture(); | 499 host_->ReleaseCapture(); |
486 | 500 |
487 if (old_capture_window && old_capture_window->delegate()) { | 501 if (old_capture_window && old_capture_window->delegate()) { |
488 // Send a capture changed event with bogus location data. | 502 // Send a capture changed event with bogus location data. |
489 MouseEvent event( | 503 MouseEvent event( |
490 ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), gfx::Point(), 0); | 504 ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), gfx::Point(), 0); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 // is currently broken. See/ crbug.com/107931. | 831 // is currently broken. See/ crbug.com/107931. |
818 MouseEvent event(ui::ET_MOUSE_MOVED, | 832 MouseEvent event(ui::ET_MOUSE_MOVED, |
819 orig_mouse_location, | 833 orig_mouse_location, |
820 orig_mouse_location, | 834 orig_mouse_location, |
821 ui::EF_IS_SYNTHESIZED); | 835 ui::EF_IS_SYNTHESIZED); |
822 DispatchMouseEvent(&event); | 836 DispatchMouseEvent(&event); |
823 #endif | 837 #endif |
824 } | 838 } |
825 | 839 |
826 } // namespace aura | 840 } // namespace aura |
OLD | NEW |