Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/window_manager_state.h" | 5 #include "components/mus/ws/window_manager_state.h" |
| 6 | 6 |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "components/mus/ws/accelerator.h" | 8 #include "components/mus/ws/accelerator.h" |
| 9 #include "components/mus/ws/display_manager.h" | 9 #include "components/mus/ws/display_manager.h" |
| 10 #include "components/mus/ws/platform_display.h" | 10 #include "components/mus/ws/platform_display.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 if (tree_awaiting_input_ack_ != tree) | 158 if (tree_awaiting_input_ack_ != tree) |
| 159 return; | 159 return; |
| 160 // The WindowTree is dying. So it's not going to ack the event. | 160 // The WindowTree is dying. So it's not going to ack the event. |
| 161 // If the dying tree matches the root |tree_| marked as handled so we don't | 161 // If the dying tree matches the root |tree_| marked as handled so we don't |
| 162 // notify it of accelerators. | 162 // notify it of accelerators. |
| 163 OnEventAck(tree_awaiting_input_ack_, tree == tree_ | 163 OnEventAck(tree_awaiting_input_ack_, tree == tree_ |
| 164 ? mojom::EventResult::HANDLED | 164 ? mojom::EventResult::HANDLED |
| 165 : mojom::EventResult::UNHANDLED); | 165 : mojom::EventResult::UNHANDLED); |
| 166 } | 166 } |
| 167 | 167 |
| 168 mojo::ScopedSharedBufferHandle WindowManagerState::GetCursorLocationMemory() { | |
| 169 if (!cursor_location_memory_) { | |
| 170 // Create our shared memory segment to share the cursor state with our | |
| 171 // window clients. | |
| 172 MojoResult result = mojo::CreateSharedBuffer(nullptr, | |
| 173 sizeof(base::subtle::Atomic64), | |
| 174 &cursor_location_handle_); | |
| 175 if (result != MOJO_RESULT_OK) | |
| 176 return mojo::ScopedSharedBufferHandle(); | |
| 177 DCHECK(cursor_location_handle_.is_valid()); | |
| 178 | |
| 179 result = mojo::MapBuffer(cursor_location_handle_.get(), 0, | |
| 180 sizeof(base::subtle::Atomic64), | |
| 181 reinterpret_cast<void**>(&cursor_location_memory_), | |
| 182 MOJO_MAP_BUFFER_FLAG_NONE); | |
| 183 if (result != MOJO_RESULT_OK) | |
| 184 return mojo::ScopedSharedBufferHandle(); | |
| 185 DCHECK(cursor_location_memory_); | |
| 186 | |
| 187 base::subtle::NoBarrier_Store(cursor_location_memory_, | |
| 188 current_cursor_location_); | |
| 189 } | |
| 190 | |
| 191 mojo::ScopedSharedBufferHandle duped; | |
| 192 MojoResult result = mojo::DuplicateBuffer(cursor_location_handle_.get(), | |
|
sky
2016/04/20 23:46:36
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONL
| |
| 193 nullptr, &duped); | |
| 194 if (result != MOJO_RESULT_OK) | |
| 195 return mojo::ScopedSharedBufferHandle(); | |
| 196 DCHECK(duped.is_valid()); | |
| 197 return duped; | |
| 198 } | |
| 199 | |
| 168 WindowManagerState::WindowManagerState(Display* display, | 200 WindowManagerState::WindowManagerState(Display* display, |
| 169 PlatformDisplay* platform_display, | 201 PlatformDisplay* platform_display, |
| 170 cc::SurfaceId surface_id, | 202 cc::SurfaceId surface_id, |
| 171 bool is_user_id_valid, | 203 bool is_user_id_valid, |
| 172 const UserId& user_id) | 204 const UserId& user_id) |
| 173 : display_(display), | 205 : display_(display), |
| 174 platform_display_(platform_display), | 206 platform_display_(platform_display), |
| 175 is_user_id_valid_(is_user_id_valid), | 207 is_user_id_valid_(is_user_id_valid), |
| 176 user_id_(user_id), | 208 user_id_(user_id), |
| 177 event_dispatcher_(this) { | 209 event_dispatcher_(this), |
| 210 current_cursor_location_(0), | |
| 211 cursor_location_memory_(nullptr) { | |
| 178 frame_decoration_values_ = mojom::FrameDecorationValues::New(); | 212 frame_decoration_values_ = mojom::FrameDecorationValues::New(); |
| 179 frame_decoration_values_->normal_client_area_insets = mojo::Insets::New(); | 213 frame_decoration_values_->normal_client_area_insets = mojo::Insets::New(); |
| 180 frame_decoration_values_->maximized_client_area_insets = mojo::Insets::New(); | 214 frame_decoration_values_->maximized_client_area_insets = mojo::Insets::New(); |
| 181 frame_decoration_values_->max_title_bar_button_width = 0u; | 215 frame_decoration_values_->max_title_bar_button_width = 0u; |
| 182 | 216 |
| 183 root_.reset(window_server()->CreateServerWindow( | 217 root_.reset(window_server()->CreateServerWindow( |
| 184 window_server()->display_manager()->GetAndAdvanceNextRootId(), | 218 window_server()->display_manager()->GetAndAdvanceNextRootId(), |
| 185 ServerWindow::Properties())); | 219 ServerWindow::Properties())); |
| 186 // Our root is always a child of the Display's root. Do this | 220 // Our root is always a child of the Display's root. Do this |
| 187 // before the WindowTree has been created so that the client doesn't get | 221 // before the WindowTree has been created so that the client doesn't get |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 | 389 |
| 356 void WindowManagerState::ReleaseNativeCapture() { | 390 void WindowManagerState::ReleaseNativeCapture() { |
| 357 platform_display_->ReleaseCapture(); | 391 platform_display_->ReleaseCapture(); |
| 358 } | 392 } |
| 359 | 393 |
| 360 void WindowManagerState::OnServerWindowCaptureLost(ServerWindow* window) { | 394 void WindowManagerState::OnServerWindowCaptureLost(ServerWindow* window) { |
| 361 DCHECK(window); | 395 DCHECK(window); |
| 362 window_server()->ProcessLostCapture(window); | 396 window_server()->ProcessLostCapture(window); |
| 363 } | 397 } |
| 364 | 398 |
| 399 void WindowManagerState::OnMouseCursorLocationChanged( | |
| 400 const gfx::Point& point) { | |
| 401 current_cursor_location_ = | |
| 402 (static_cast<base::subtle::Atomic64>(point.x()) << 32) | point.y(); | |
| 403 if (cursor_location_memory_) { | |
| 404 base::subtle::NoBarrier_Store(cursor_location_memory_, | |
| 405 current_cursor_location_); | |
| 406 } | |
| 407 } | |
| 408 | |
| 365 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, | 409 void WindowManagerState::DispatchInputEventToWindow(ServerWindow* target, |
| 366 bool in_nonclient_area, | 410 bool in_nonclient_area, |
| 367 const ui::Event& event, | 411 const ui::Event& event, |
| 368 Accelerator* accelerator) { | 412 Accelerator* accelerator) { |
| 369 DCHECK(IsActive()); | 413 DCHECK(IsActive()); |
| 370 // TODO(sky): this needs to see if another wms has capture and if so forward | 414 // TODO(sky): this needs to see if another wms has capture and if so forward |
| 371 // to it. | 415 // to it. |
| 372 if (event_ack_timer_.IsRunning()) { | 416 if (event_ack_timer_.IsRunning()) { |
| 373 scoped_ptr<ProcessedEventTarget> processed_event_target( | 417 scoped_ptr<ProcessedEventTarget> processed_event_target( |
| 374 new ProcessedEventTarget(target, in_nonclient_area, accelerator)); | 418 new ProcessedEventTarget(target, in_nonclient_area, accelerator)); |
| 375 QueueEvent(event, std::move(processed_event_target)); | 419 QueueEvent(event, std::move(processed_event_target)); |
| 376 return; | 420 return; |
| 377 } | 421 } |
| 378 | 422 |
| 379 base::WeakPtr<Accelerator> weak_accelerator; | 423 base::WeakPtr<Accelerator> weak_accelerator; |
| 380 if (accelerator) | 424 if (accelerator) |
| 381 weak_accelerator = accelerator->GetWeakPtr(); | 425 weak_accelerator = accelerator->GetWeakPtr(); |
| 382 DispatchInputEventToWindowImpl(target, in_nonclient_area, event, | 426 DispatchInputEventToWindowImpl(target, in_nonclient_area, event, |
| 383 weak_accelerator); | 427 weak_accelerator); |
| 384 } | 428 } |
| 385 | 429 |
| 386 } // namespace ws | 430 } // namespace ws |
| 387 } // namespace mus | 431 } // namespace mus |
| OLD | NEW |