| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/ws/display.h" | 5 #include "components/mus/ws/display.h" |
| 6 | 6 |
| 7 #include "base/debug/debugger.h" | 7 #include "base/debug/debugger.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/mus/common/types.h" | 9 #include "components/mus/common/types.h" |
| 10 #include "components/mus/ws/connection_manager.h" | 10 #include "components/mus/ws/connection_manager.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 scoped_ptr<ui::Event> CoalesceEvents(scoped_ptr<ui::Event> first, | 49 scoped_ptr<ui::Event> CoalesceEvents(scoped_ptr<ui::Event> first, |
| 50 scoped_ptr<ui::Event> second) { | 50 scoped_ptr<ui::Event> second) { |
| 51 DCHECK(first->type() == ui::ET_POINTER_MOVED) | 51 DCHECK(first->type() == ui::ET_POINTER_MOVED) |
| 52 << " Non-move events cannot be merged yet."; | 52 << " Non-move events cannot be merged yet."; |
| 53 // For mouse moves, the new event just replaces the old event. | 53 // For mouse moves, the new event just replaces the old event. |
| 54 return second; | 54 return second; |
| 55 } | 55 } |
| 56 | 56 |
| 57 uint32_t next_id = 1; | |
| 58 | |
| 59 } // namespace | 57 } // namespace |
| 60 | 58 |
| 61 class Display::ProcessedEventTarget { | 59 class Display::ProcessedEventTarget { |
| 62 public: | 60 public: |
| 63 ProcessedEventTarget(ServerWindow* window, bool in_nonclient_area) | 61 ProcessedEventTarget(ServerWindow* window, bool in_nonclient_area) |
| 64 : in_nonclient_area_(in_nonclient_area) { | 62 : in_nonclient_area_(in_nonclient_area) { |
| 65 tracker_.Add(window); | 63 tracker_.Add(window); |
| 66 } | 64 } |
| 67 | 65 |
| 68 ~ProcessedEventTarget() {} | 66 ~ProcessedEventTarget() {} |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 DISALLOW_COPY_AND_ASSIGN(ProcessedEventTarget); | 83 DISALLOW_COPY_AND_ASSIGN(ProcessedEventTarget); |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 Display::QueuedEvent::QueuedEvent() {} | 86 Display::QueuedEvent::QueuedEvent() {} |
| 89 Display::QueuedEvent::~QueuedEvent() {} | 87 Display::QueuedEvent::~QueuedEvent() {} |
| 90 | 88 |
| 91 Display::Display(ConnectionManager* connection_manager, | 89 Display::Display(ConnectionManager* connection_manager, |
| 92 mojo::Connector* connector, | 90 mojo::Connector* connector, |
| 93 const scoped_refptr<GpuState>& gpu_state, | 91 const scoped_refptr<GpuState>& gpu_state, |
| 94 const scoped_refptr<SurfacesState>& surfaces_state) | 92 const scoped_refptr<SurfacesState>& surfaces_state) |
| 95 : id_(next_id++), | 93 : id_(connection_manager->display_manager()->GetAndAdvanceNextDisplayId()), |
| 96 connection_manager_(connection_manager), | 94 connection_manager_(connection_manager), |
| 97 event_dispatcher_(this), | 95 event_dispatcher_(this), |
| 98 platform_display_( | 96 platform_display_( |
| 99 PlatformDisplay::Create(connector, gpu_state, surfaces_state)), | 97 PlatformDisplay::Create(connector, gpu_state, surfaces_state)), |
| 100 tree_awaiting_input_ack_(nullptr), | 98 tree_awaiting_input_ack_(nullptr), |
| 101 last_cursor_(0) { | 99 last_cursor_(0) { |
| 102 frame_decoration_values_ = mojom::FrameDecorationValues::New(); | |
| 103 frame_decoration_values_->normal_client_area_insets = mojo::Insets::New(); | |
| 104 frame_decoration_values_->maximized_client_area_insets = mojo::Insets::New(); | |
| 105 frame_decoration_values_->max_title_bar_button_width = 0u; | |
| 106 | |
| 107 platform_display_->Init(this); | 100 platform_display_->Init(this); |
| 108 | 101 |
| 109 connection_manager_->window_manager_factory_registry()->AddObserver(this); | 102 connection_manager_->window_manager_factory_registry()->AddObserver(this); |
| 110 } | 103 } |
| 111 | 104 |
| 112 Display::~Display() { | 105 Display::~Display() { |
| 113 connection_manager_->window_manager_factory_registry()->RemoveObserver(this); | 106 connection_manager_->window_manager_factory_registry()->RemoveObserver(this); |
| 114 | 107 |
| 115 DestroyFocusController(); | 108 DestroyFocusController(); |
| 116 for (ServerWindow* window : windows_needing_frame_destruction_) | 109 for (ServerWindow* window : windows_needing_frame_destruction_) |
| 117 window->RemoveObserver(this); | 110 window->RemoveObserver(this); |
| 118 | 111 |
| 119 // Destroy any trees, which triggers destroying the WindowManagerState. Copy | 112 // Destroy any trees, which triggers destroying the WindowManagerState. Copy |
| 120 // off the WindowManagerStates as destruction mutates | 113 // off the WindowManagerStates as destruction mutates |
| 121 // |window_manager_state_map_|. | 114 // |window_manager_state_map_|. |
| 122 std::set<WindowManagerState*> states; | 115 std::set<WindowManagerState*> states; |
| 123 for (auto& pair : window_manager_state_map_) | 116 for (auto& pair : window_manager_state_map_) |
| 124 states.insert(pair.second.get()); | 117 states.insert(pair.second.get()); |
| 125 for (WindowManagerState* state : states) | 118 for (WindowManagerState* state : states) |
| 126 connection_manager_->DestroyTree(state->tree()); | 119 connection_manager_->DestroyTree(state->tree()); |
| 127 } | 120 } |
| 128 | 121 |
| 129 void Display::Init(scoped_ptr<DisplayBinding> binding) { | 122 void Display::Init(scoped_ptr<DisplayBinding> binding) { |
| 130 init_called_ = true; | 123 init_called_ = true; |
| 131 binding_ = std::move(binding); | 124 binding_ = std::move(binding); |
| 132 display_manager()->AddDisplay(this); | 125 display_manager()->AddDisplay(this); |
| 133 InitWindowManagersIfNecessary(); | 126 InitWindowManagersIfNecessary(); |
| 134 } | 127 } |
| 135 | 128 |
| 136 void Display::SetFrameDecorationValues(mojom::FrameDecorationValuesPtr values) { | 129 DisplayManager* Display::display_manager() { |
| 137 // TODO(sky): this needs to be moved to WindowManagerState. | 130 return connection_manager_->display_manager(); |
| 138 frame_decoration_values_ = values.Clone(); | 131 } |
| 139 connection_manager_->ProcessFrameDecorationValuesChanged(this); | 132 |
| 133 const DisplayManager* Display::display_manager() const { |
| 134 return connection_manager_->display_manager(); |
| 135 } |
| 136 |
| 137 mojom::DisplayPtr Display::ToMojomDisplay() const { |
| 138 mojom::DisplayPtr display_ptr = mojom::Display::New(); |
| 139 display_ptr = mojom::Display::New(); |
| 140 display_ptr->id = id_; |
| 141 display_ptr->bounds = mojo::Rect::New(); |
| 142 // TODO(sky): Display should know it's origin. |
| 143 display_ptr->bounds->x = 0; |
| 144 display_ptr->bounds->y = 0; |
| 145 display_ptr->bounds->width = root_->bounds().size().width(); |
| 146 display_ptr->bounds->height = root_->bounds().size().height(); |
| 147 // TODO(sky): window manager needs an API to set the work area. |
| 148 display_ptr->work_area = display_ptr->bounds.Clone(); |
| 149 display_ptr->device_pixel_ratio = |
| 150 platform_display_->GetViewportMetrics().device_pixel_ratio; |
| 151 display_ptr->rotation = platform_display_->GetRotation(); |
| 152 // TODO(sky): make this real. |
| 153 display_ptr->is_primary = true; |
| 154 // TODO(sky): make this real. |
| 155 display_ptr->touch_support = mojom::TouchSupport::UNKNOWN; |
| 156 display_ptr->frame_decoration_values = mojom::FrameDecorationValues::New(); |
| 157 display_ptr->frame_decoration_values->normal_client_area_insets = |
| 158 mojo::Insets::New(); |
| 159 display_ptr->frame_decoration_values->maximized_client_area_insets = |
| 160 mojo::Insets::New(); |
| 161 return display_ptr; |
| 140 } | 162 } |
| 141 | 163 |
| 142 void Display::SchedulePaint(const ServerWindow* window, | 164 void Display::SchedulePaint(const ServerWindow* window, |
| 143 const gfx::Rect& bounds) { | 165 const gfx::Rect& bounds) { |
| 144 DCHECK(root_->Contains(window)); | 166 DCHECK(root_->Contains(window)); |
| 145 platform_display_->SchedulePaint(window, bounds); | 167 platform_display_->SchedulePaint(window, bounds); |
| 146 } | 168 } |
| 147 | 169 |
| 148 void Display::ScheduleSurfaceDestruction(ServerWindow* window) { | 170 void Display::ScheduleSurfaceDestruction(ServerWindow* window) { |
| 149 if (!platform_display_->IsFramePending()) { | 171 if (!platform_display_->IsFramePending()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 178 } | 200 } |
| 179 return nullptr; | 201 return nullptr; |
| 180 } | 202 } |
| 181 | 203 |
| 182 WindowManagerState* Display::GetFirstWindowManagerState() { | 204 WindowManagerState* Display::GetFirstWindowManagerState() { |
| 183 return window_manager_state_map_.empty() | 205 return window_manager_state_map_.empty() |
| 184 ? nullptr | 206 ? nullptr |
| 185 : window_manager_state_map_.begin()->second.get(); | 207 : window_manager_state_map_.begin()->second.get(); |
| 186 } | 208 } |
| 187 | 209 |
| 188 WindowManagerState* Display::GetWindowManagerStateForUser( | 210 const WindowManagerState* Display::GetWindowManagerStateForUser( |
| 189 const UserId& user_id) { | 211 const UserId& user_id) const { |
| 190 auto iter = window_manager_state_map_.find(user_id); | 212 auto iter = window_manager_state_map_.find(user_id); |
| 191 return iter == window_manager_state_map_.end() ? nullptr : iter->second.get(); | 213 return iter == window_manager_state_map_.end() ? nullptr : iter->second.get(); |
| 192 } | 214 } |
| 193 | 215 |
| 194 void Display::SetCapture(ServerWindow* window, bool in_nonclient_area) { | 216 void Display::SetCapture(ServerWindow* window, bool in_nonclient_area) { |
| 195 ServerWindow* capture_window = event_dispatcher_.capture_window(); | 217 ServerWindow* capture_window = event_dispatcher_.capture_window(); |
| 196 if (capture_window == window) | 218 if (capture_window == window) |
| 197 return; | 219 return; |
| 198 event_dispatcher_.SetCaptureWindow(window, in_nonclient_area); | 220 event_dispatcher_.SetCaptureWindow(window, in_nonclient_area); |
| 199 } | 221 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 // For this case we never create additional WindowManagerStates, so any | 325 // For this case we never create additional WindowManagerStates, so any |
| 304 // id works. | 326 // id works. |
| 305 window_manager_state_map_[mojo::shell::mojom::kRootUserID] = | 327 window_manager_state_map_[mojo::shell::mojom::kRootUserID] = |
| 306 std::move(wms_ptr); | 328 std::move(wms_ptr); |
| 307 wms->tree_ = binding_->CreateWindowTree(wms->root()); | 329 wms->tree_ = binding_->CreateWindowTree(wms->root()); |
| 308 } else { | 330 } else { |
| 309 CreateWindowManagerStatesFromRegistry(); | 331 CreateWindowManagerStatesFromRegistry(); |
| 310 } | 332 } |
| 311 } | 333 } |
| 312 | 334 |
| 313 DisplayManager* Display::display_manager() { | |
| 314 return connection_manager_->display_manager(); | |
| 315 } | |
| 316 | |
| 317 const DisplayManager* Display::display_manager() const { | |
| 318 return connection_manager_->display_manager(); | |
| 319 } | |
| 320 | |
| 321 void Display::OnEventAckTimeout() { | 335 void Display::OnEventAckTimeout() { |
| 322 // TODO(sad): Figure out what we should do. | 336 // TODO(sad): Figure out what we should do. |
| 323 NOTIMPLEMENTED() << "Event ACK timed out."; | 337 NOTIMPLEMENTED() << "Event ACK timed out."; |
| 324 OnEventAck(tree_awaiting_input_ack_); | 338 OnEventAck(tree_awaiting_input_ack_); |
| 325 } | 339 } |
| 326 | 340 |
| 327 void Display::QueueEvent( | 341 void Display::QueueEvent( |
| 328 const ui::Event& event, | 342 const ui::Event& event, |
| 329 scoped_ptr<ProcessedEventTarget> processed_event_target) { | 343 scoped_ptr<ProcessedEventTarget> processed_event_target) { |
| 330 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); | 344 scoped_ptr<QueuedEvent> queued_event(new QueuedEvent); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 focus_controller_.reset(new FocusController(this, root_.get())); | 470 focus_controller_.reset(new FocusController(this, root_.get())); |
| 457 focus_controller_->AddObserver(this); | 471 focus_controller_->AddObserver(this); |
| 458 InitWindowManagersIfNecessary(); | 472 InitWindowManagersIfNecessary(); |
| 459 event_dispatcher_.set_root(root_.get()); | 473 event_dispatcher_.set_root(root_.get()); |
| 460 } else { | 474 } else { |
| 461 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); | 475 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>())); |
| 462 const gfx::Rect wm_bounds(root_->bounds().size()); | 476 const gfx::Rect wm_bounds(root_->bounds().size()); |
| 463 for (auto& pair : window_manager_state_map_) | 477 for (auto& pair : window_manager_state_map_) |
| 464 pair.second->root()->SetBounds(wm_bounds); | 478 pair.second->root()->SetBounds(wm_bounds); |
| 465 } | 479 } |
| 480 // TODO(sky): if bounds changed, then need to update |
| 481 // Display/WindowManagerState appropriately (e.g. notify observers). |
| 466 connection_manager_->ProcessViewportMetricsChanged(this, old_metrics, | 482 connection_manager_->ProcessViewportMetricsChanged(this, old_metrics, |
| 467 new_metrics); | 483 new_metrics); |
| 468 } | 484 } |
| 469 | 485 |
| 470 void Display::OnTopLevelSurfaceChanged(cc::SurfaceId surface_id) { | 486 void Display::OnTopLevelSurfaceChanged(cc::SurfaceId surface_id) { |
| 471 event_dispatcher_.set_surface_id(surface_id); | 487 event_dispatcher_.set_surface_id(surface_id); |
| 472 } | 488 } |
| 473 | 489 |
| 474 void Display::OnCompositorFrameDrawn() { | 490 void Display::OnCompositorFrameDrawn() { |
| 475 std::set<ServerWindow*> windows; | 491 std::set<ServerWindow*> windows; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 if (!state) | 655 if (!state) |
| 640 return; | 656 return; |
| 641 | 657 |
| 642 // DestroyTree() calls back to OnWillDestroyTree() and the WindowManagerState | 658 // DestroyTree() calls back to OnWillDestroyTree() and the WindowManagerState |
| 643 // is destroyed (and removed). | 659 // is destroyed (and removed). |
| 644 connection_manager_->DestroyTree(state->tree()); | 660 connection_manager_->DestroyTree(state->tree()); |
| 645 DCHECK_EQ(0u, window_manager_state_map_.count(id)); | 661 DCHECK_EQ(0u, window_manager_state_map_.count(id)); |
| 646 } | 662 } |
| 647 | 663 |
| 648 void Display::OnWindowManagerFactorySet(WindowManagerFactoryService* service) { | 664 void Display::OnWindowManagerFactorySet(WindowManagerFactoryService* service) { |
| 649 CreateWindowManagerStateFromService(service); | 665 if (!binding_) |
| 666 CreateWindowManagerStateFromService(service); |
| 650 } | 667 } |
| 651 | 668 |
| 652 } // namespace ws | 669 } // namespace ws |
| 653 } // namespace mus | 670 } // namespace mus |
| OLD | NEW |