| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/desktop.h" | 5 #include "ui/aura/desktop.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 14 matching lines...) Expand all Loading... |
| 25 #include "ui/aura/window_delegate.h" | 25 #include "ui/aura/window_delegate.h" |
| 26 #include "ui/base/hit_test.h" | 26 #include "ui/base/hit_test.h" |
| 27 #include "ui/gfx/compositor/compositor.h" | 27 #include "ui/gfx/compositor/compositor.h" |
| 28 #include "ui/gfx/compositor/layer.h" | 28 #include "ui/gfx/compositor/layer.h" |
| 29 #include "ui/gfx/compositor/layer_animator.h" | 29 #include "ui/gfx/compositor/layer_animator.h" |
| 30 | 30 |
| 31 #ifdef USE_WEBKIT_COMPOSITOR | 31 #ifdef USE_WEBKIT_COMPOSITOR |
| 32 #include "ui/gfx/compositor/compositor_cc.h" | 32 #include "ui/gfx/compositor/compositor_cc.h" |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 #if defined(USE_X11) |
| 36 #include "base/message_pump_x.h" |
| 37 #endif |
| 38 |
| 35 using std::string; | 39 using std::string; |
| 36 using std::vector; | 40 using std::vector; |
| 37 | 41 |
| 38 namespace aura { | 42 namespace aura { |
| 39 | 43 |
| 40 namespace { | 44 namespace { |
| 41 | 45 |
| 42 // Default bounds for the host window. | 46 // Default bounds for the host window. |
| 43 static const int kDefaultHostWindowX = 200; | 47 static const int kDefaultHostWindowX = 200; |
| 44 static const int kDefaultHostWindowY = 200; | 48 static const int kDefaultHostWindowY = 200; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 filters->push_back(window->event_filter()); | 98 filters->push_back(window->event_filter()); |
| 95 window = window->parent(); | 99 window = window->parent(); |
| 96 } | 100 } |
| 97 } | 101 } |
| 98 | 102 |
| 99 } // namespace | 103 } // namespace |
| 100 | 104 |
| 101 Desktop* Desktop::instance_ = NULL; | 105 Desktop* Desktop::instance_ = NULL; |
| 102 bool Desktop::use_fullscreen_host_window_ = false; | 106 bool Desktop::use_fullscreen_host_window_ = false; |
| 103 | 107 |
| 104 Desktop::Desktop() | 108 //////////////////////////////////////////////////////////////////////////////// |
| 105 : Window(NULL), | 109 // Desktop, public: |
| 106 host_(aura::DesktopHost::Create(GetInitialHostWindowBounds())), | |
| 107 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 108 stacking_client_(new DefaultStackingClient(this))), | |
| 109 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | |
| 110 active_window_(NULL), | |
| 111 mouse_button_flags_(0), | |
| 112 last_cursor_(kCursorNull), | |
| 113 in_destructor_(false), | |
| 114 screen_(new ScreenAura), | |
| 115 capture_window_(NULL), | |
| 116 mouse_pressed_handler_(NULL), | |
| 117 mouse_moved_handler_(NULL), | |
| 118 focused_window_(NULL), | |
| 119 touch_event_handler_(NULL) { | |
| 120 set_name("RootWindow"); | |
| 121 gfx::Screen::SetInstance(screen_); | |
| 122 host_->SetDesktop(this); | |
| 123 last_mouse_location_ = host_->QueryMouseLocation(); | |
| 124 | |
| 125 if (ui::Compositor::compositor_factory()) { | |
| 126 compositor_ = (*ui::Compositor::compositor_factory())(this); | |
| 127 } else { | |
| 128 #ifdef USE_WEBKIT_COMPOSITOR | |
| 129 ui::CompositorCC::Initialize(false); | |
| 130 #endif | |
| 131 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), | |
| 132 host_->GetSize()); | |
| 133 } | |
| 134 DCHECK(compositor_.get()); | |
| 135 } | |
| 136 | |
| 137 Desktop::~Desktop() { | |
| 138 in_destructor_ = true; | |
| 139 #ifdef USE_WEBKIT_COMPOSITOR | |
| 140 if (!ui::Compositor::compositor_factory()) | |
| 141 ui::CompositorCC::Terminate(); | |
| 142 #endif | |
| 143 if (instance_ == this) | |
| 144 instance_ = NULL; | |
| 145 } | |
| 146 | 110 |
| 147 // static | 111 // static |
| 148 Desktop* Desktop::GetInstance() { | 112 Desktop* Desktop::GetInstance() { |
| 149 if (!instance_) { | 113 if (!instance_) { |
| 150 instance_ = new Desktop; | 114 instance_ = new Desktop; |
| 151 instance_->Init(); | 115 instance_->Init(); |
| 152 } | 116 } |
| 153 return instance_; | 117 return instance_; |
| 154 } | 118 } |
| 155 | 119 |
| 156 // static | 120 // static |
| 157 void Desktop::DeleteInstanceForTesting() { | 121 void Desktop::DeleteInstance() { |
| 158 delete instance_; | 122 delete instance_; |
| 159 instance_ = NULL; | 123 instance_ = NULL; |
| 160 } | 124 } |
| 161 | 125 |
| 162 void Desktop::SetStackingClient(StackingClient* stacking_client) { | 126 void Desktop::SetStackingClient(StackingClient* stacking_client) { |
| 163 stacking_client_.reset(stacking_client); | 127 stacking_client_.reset(stacking_client); |
| 164 } | 128 } |
| 165 | 129 |
| 166 void Desktop::ShowDesktop() { | 130 void Desktop::ShowDesktop() { |
| 167 host_->Show(); | 131 host_->Show(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 181 | 145 |
| 182 void Desktop::SetCursor(gfx::NativeCursor cursor) { | 146 void Desktop::SetCursor(gfx::NativeCursor cursor) { |
| 183 last_cursor_ = cursor; | 147 last_cursor_ = cursor; |
| 184 // A lot of code seems to depend on NULL cursors actually showing an arrow, | 148 // A lot of code seems to depend on NULL cursors actually showing an arrow, |
| 185 // so just pass everything along to the host. | 149 // so just pass everything along to the host. |
| 186 host_->SetCursor(cursor); | 150 host_->SetCursor(cursor); |
| 187 } | 151 } |
| 188 | 152 |
| 189 void Desktop::Run() { | 153 void Desktop::Run() { |
| 190 ShowDesktop(); | 154 ShowDesktop(); |
| 191 MessageLoopForUI::current()->RunWithDispatcher(host_.get()); | 155 MessageLoopForUI::current()->Run(); |
| 192 } | 156 } |
| 193 | 157 |
| 194 void Desktop::Draw() { | 158 void Desktop::Draw() { |
| 195 compositor_->Draw(false); | 159 compositor_->Draw(false); |
| 196 } | 160 } |
| 197 | 161 |
| 198 bool Desktop::DispatchMouseEvent(MouseEvent* event) { | 162 bool Desktop::DispatchMouseEvent(MouseEvent* event) { |
| 199 static const int kMouseButtonFlagMask = | 163 static const int kMouseButtonFlagMask = |
| 200 ui::EF_LEFT_BUTTON_DOWN | | 164 ui::EF_LEFT_BUTTON_DOWN | |
| 201 ui::EF_MIDDLE_BUTTON_DOWN | | 165 ui::EF_MIDDLE_BUTTON_DOWN | |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 if (!layer()->GetAnimator()->is_animating()) | 383 if (!layer()->GetAnimator()->is_animating()) |
| 420 OnHostResized(host_->GetSize()); | 384 OnHostResized(host_->GetSize()); |
| 421 } | 385 } |
| 422 | 386 |
| 423 #if !defined(NDEBUG) | 387 #if !defined(NDEBUG) |
| 424 void Desktop::ToggleFullScreen() { | 388 void Desktop::ToggleFullScreen() { |
| 425 host_->ToggleFullScreen(); | 389 host_->ToggleFullScreen(); |
| 426 } | 390 } |
| 427 #endif | 391 #endif |
| 428 | 392 |
| 393 //////////////////////////////////////////////////////////////////////////////// |
| 394 // Desktop, private: |
| 395 |
| 396 Desktop::Desktop() |
| 397 : Window(NULL), |
| 398 host_(aura::DesktopHost::Create(GetInitialHostWindowBounds())), |
| 399 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 400 stacking_client_(new DefaultStackingClient(this))), |
| 401 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
| 402 active_window_(NULL), |
| 403 mouse_button_flags_(0), |
| 404 last_cursor_(kCursorNull), |
| 405 in_destructor_(false), |
| 406 screen_(new ScreenAura), |
| 407 capture_window_(NULL), |
| 408 mouse_pressed_handler_(NULL), |
| 409 mouse_moved_handler_(NULL), |
| 410 focused_window_(NULL), |
| 411 touch_event_handler_(NULL) { |
| 412 set_name("RootWindow"); |
| 413 gfx::Screen::SetInstance(screen_); |
| 414 host_->SetDesktop(this); |
| 415 last_mouse_location_ = host_->QueryMouseLocation(); |
| 416 |
| 417 if (ui::Compositor::compositor_factory()) { |
| 418 compositor_ = (*ui::Compositor::compositor_factory())(this); |
| 419 } else { |
| 420 #ifdef USE_WEBKIT_COMPOSITOR |
| 421 ui::CompositorCC::Initialize(false); |
| 422 #endif |
| 423 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), |
| 424 host_->GetSize()); |
| 425 } |
| 426 DCHECK(compositor_.get()); |
| 427 #if defined(USE_X11) |
| 428 base::MessagePumpX::SetDefaultDispatcher(host_.get()); |
| 429 #endif |
| 430 } |
| 431 |
| 432 Desktop::~Desktop() { |
| 433 #if defined(USE_X11) |
| 434 base::MessagePumpX::SetDefaultDispatcher(NULL); |
| 435 #endif |
| 436 |
| 437 in_destructor_ = true; |
| 438 #ifdef USE_WEBKIT_COMPOSITOR |
| 439 if (!ui::Compositor::compositor_factory()) |
| 440 ui::CompositorCC::Terminate(); |
| 441 #endif |
| 442 if (instance_ == this) |
| 443 instance_ = NULL; |
| 444 } |
| 445 |
| 429 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { | 446 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { |
| 430 if (target == mouse_moved_handler_) | 447 if (target == mouse_moved_handler_) |
| 431 return; | 448 return; |
| 432 | 449 |
| 433 // Send an exited event. | 450 // Send an exited event. |
| 434 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { | 451 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { |
| 435 MouseEvent translated_event(event, this, mouse_moved_handler_, | 452 MouseEvent translated_event(event, this, mouse_moved_handler_, |
| 436 ui::ET_MOUSE_EXITED, event.flags()); | 453 ui::ET_MOUSE_EXITED, event.flags()); |
| 437 ProcessMouseEvent(mouse_moved_handler_, &translated_event); | 454 ProcessMouseEvent(mouse_moved_handler_, &translated_event); |
| 438 } | 455 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { | 602 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { |
| 586 bounds.set_size(gfx::Size(parsed_width, parsed_height)); | 603 bounds.set_size(gfx::Size(parsed_width, parsed_height)); |
| 587 } else if (use_fullscreen_host_window_) { | 604 } else if (use_fullscreen_host_window_) { |
| 588 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); | 605 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); |
| 589 } | 606 } |
| 590 | 607 |
| 591 return bounds; | 608 return bounds; |
| 592 } | 609 } |
| 593 | 610 |
| 594 } // namespace aura | 611 } // namespace aura |
| OLD | NEW |