| 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/example/wm/window_manager_impl.h" | 5 #include "components/mus/example/wm/window_manager_impl.h" |
| 6 | 6 |
| 7 #include "components/mus/example/wm/container.h" | 7 #include "components/mus/example/wm/container.h" |
| 8 #include "components/mus/example/wm/move_loop.h" |
| 8 #include "components/mus/example/wm/window_manager_application.h" | 9 #include "components/mus/example/wm/window_manager_application.h" |
| 9 #include "components/mus/public/cpp/property_type_converters.h" | 10 #include "components/mus/public/cpp/property_type_converters.h" |
| 10 #include "components/mus/public/cpp/types.h" | 11 #include "components/mus/public/cpp/types.h" |
| 11 #include "components/mus/public/cpp/window.h" | 12 #include "components/mus/public/cpp/window.h" |
| 12 #include "components/mus/public/cpp/window_property.h" | 13 #include "components/mus/public/cpp/window_property.h" |
| 13 #include "components/mus/public/cpp/window_tree_connection.h" | 14 #include "components/mus/public/cpp/window_tree_connection.h" |
| 15 #include "ui/mojo/events/input_events.mojom.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 bool IsPointerEvent(const mojo::Event& event) { |
| 20 return event.action == mojo::EVENT_TYPE_POINTER_CANCEL || |
| 21 event.action == mojo::EVENT_TYPE_POINTER_DOWN || |
| 22 event.action == mojo::EVENT_TYPE_POINTER_MOVE || |
| 23 event.action == mojo::EVENT_TYPE_POINTER_UP; |
| 24 } |
| 25 |
| 26 } // namespace |
| 14 | 27 |
| 15 WindowManagerImpl::WindowManagerImpl(WindowManagerApplication* state) | 28 WindowManagerImpl::WindowManagerImpl(WindowManagerApplication* state) |
| 16 : state_(state) {} | 29 : state_(state) {} |
| 17 | 30 |
| 18 WindowManagerImpl::~WindowManagerImpl() {} | 31 WindowManagerImpl::~WindowManagerImpl() { |
| 32 mus::Window* parent = state_->GetWindowForContainer(Container::USER_WINDOWS); |
| 33 if (!parent) |
| 34 return; |
| 35 |
| 36 for (mus::Window* child : parent->children()) |
| 37 child->RemoveObserver(this); |
| 38 } |
| 19 | 39 |
| 20 void WindowManagerImpl::OpenWindow(mus::mojom::WindowTreeClientPtr client) { | 40 void WindowManagerImpl::OpenWindow(mus::mojom::WindowTreeClientPtr client) { |
| 21 mus::Window* root = state_->root(); | 41 mus::Window* root = state_->root(); |
| 22 DCHECK(root); | 42 DCHECK(root); |
| 23 | 43 |
| 24 const int width = (root->bounds().width - 240); | 44 const int width = (root->bounds().width - 240); |
| 25 const int height = (root->bounds().height - 240); | 45 const int height = (root->bounds().height - 240); |
| 26 | 46 |
| 27 mus::Window* child_window = root->connection()->NewWindow(); | 47 mus::Window* child_window = root->connection()->NewWindow(); |
| 28 mojo::Rect bounds; | 48 mojo::Rect bounds; |
| 29 bounds.x = 40 + (state_->window_count() % 4) * 40; | 49 bounds.x = 40 + (state_->window_count() % 4) * 40; |
| 30 bounds.y = 40 + (state_->window_count() % 4) * 40; | 50 bounds.y = 40 + (state_->window_count() % 4) * 40; |
| 31 bounds.width = width; | 51 bounds.width = width; |
| 32 bounds.height = height; | 52 bounds.height = height; |
| 33 child_window->SetBounds(bounds); | 53 child_window->SetBounds(bounds); |
| 34 state_->GetWindowForContainer(Container::USER_WINDOWS) | 54 state_->GetWindowForContainer(Container::USER_WINDOWS) |
| 35 ->AddChild(child_window); | 55 ->AddChild(child_window); |
| 36 child_window->Embed(client.Pass()); | 56 child_window->Embed(client.Pass()); |
| 57 child_window->AddObserver(this); |
| 37 | 58 |
| 38 state_->IncrementWindowCount(); | 59 state_->IncrementWindowCount(); |
| 39 } | 60 } |
| 40 | 61 |
| 41 void WindowManagerImpl::SetPreferredSize( | 62 void WindowManagerImpl::SetPreferredSize( |
| 42 mus::Id window_id, | 63 mus::Id window_id, |
| 43 mojo::SizePtr size, | 64 mojo::SizePtr size, |
| 44 const WindowManagerErrorCodeCallback& callback) { | 65 const WindowManagerErrorCodeCallback& callback) { |
| 45 mus::Window* window = state_->GetWindowById(window_id); | 66 mus::Window* window = state_->GetWindowById(window_id); |
| 46 window->SetSharedProperty<mojo::Size>( | 67 window->SetSharedProperty<mojo::Size>( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 74 displays[0]->id = 2001; | 95 displays[0]->id = 2001; |
| 75 displays[0]->bounds = mojo::Rect::New(); | 96 displays[0]->bounds = mojo::Rect::New(); |
| 76 displays[0]->bounds->y = 0; | 97 displays[0]->bounds->y = 0; |
| 77 displays[0]->bounds->width = state_->root()->bounds().width; | 98 displays[0]->bounds->width = state_->root()->bounds().width; |
| 78 displays[0]->bounds->height = state_->root()->bounds().width; | 99 displays[0]->bounds->height = state_->root()->bounds().width; |
| 79 displays[0]->work_area = displays[0]->bounds.Clone(); | 100 displays[0]->work_area = displays[0]->bounds.Clone(); |
| 80 displays[0]->device_pixel_ratio = | 101 displays[0]->device_pixel_ratio = |
| 81 state_->root()->viewport_metrics().device_pixel_ratio; | 102 state_->root()->viewport_metrics().device_pixel_ratio; |
| 82 callback.Run(displays.Pass()); | 103 callback.Run(displays.Pass()); |
| 83 } | 104 } |
| 105 |
| 106 void WindowManagerImpl::OnWindowDestroyed(mus::Window* window) { |
| 107 window->RemoveObserver(this); |
| 108 } |
| 109 |
| 110 void WindowManagerImpl::OnWindowInputEvent(mus::Window* window, |
| 111 const mojo::EventPtr& event) { |
| 112 if (move_loop_ && IsPointerEvent(*event)) { |
| 113 if (move_loop_->Move(*event) == MoveLoop::DONE) |
| 114 move_loop_.reset(); |
| 115 return; |
| 116 } |
| 117 if (!move_loop_ && event->action == mojo::EVENT_TYPE_POINTER_DOWN) |
| 118 move_loop_ = MoveLoop::Create(window, *event); |
| 119 } |
| OLD | NEW |