| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "mojo/aura/window_tree_host_mojo.h" | 5 #include "mojo/aura/window_tree_host_mojo.h" |
| 6 | 6 |
| 7 #include "mojo/aura/context_factory_mojo.h" | 7 #include "mojo/aura/context_factory_mojo.h" |
| 8 #include "mojo/geometry/geometry_type_converters.h" | 8 #include "mojo/geometry/geometry_type_converters.h" |
| 9 #include "mojo/public/c/gles2/gles2.h" | 9 #include "mojo/public/c/gles2/gles2.h" |
| 10 #include "mojo/public/cpp/bindings/allocation_scope.h" | |
| 11 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 12 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
| 14 #include "ui/compositor/compositor.h" | 13 #include "ui/compositor/compositor.h" |
| 15 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 16 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
| 17 #include "ui/gfx/geometry/insets.h" | 16 #include "ui/gfx/geometry/insets.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 19 | 18 |
| 20 namespace mojo { | 19 namespace mojo { |
| 21 | 20 |
| 22 // static | 21 // static |
| 23 mojo::ContextFactoryMojo* WindowTreeHostMojo::context_factory_ = NULL; | 22 mojo::ContextFactoryMojo* WindowTreeHostMojo::context_factory_ = NULL; |
| 24 | 23 |
| 25 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
| 26 // WindowTreeHostMojo, public: | 25 // WindowTreeHostMojo, public: |
| 27 | 26 |
| 28 WindowTreeHostMojo::WindowTreeHostMojo( | 27 WindowTreeHostMojo::WindowTreeHostMojo( |
| 29 NativeViewportPtr viewport, | 28 NativeViewportPtr viewport, |
| 30 const gfx::Rect& bounds, | 29 const gfx::Rect& bounds, |
| 31 const base::Callback<void()>& compositor_created_callback) | 30 const base::Callback<void()>& compositor_created_callback) |
| 32 : native_viewport_(viewport.Pass()), | 31 : native_viewport_(viewport.Pass()), |
| 33 compositor_created_callback_(compositor_created_callback), | 32 compositor_created_callback_(compositor_created_callback), |
| 34 bounds_(bounds) { | 33 bounds_(bounds) { |
| 35 native_viewport_.set_client(this); | 34 native_viewport_.set_client(this); |
| 36 | 35 native_viewport_->Create(Rect::From(bounds)); |
| 37 AllocationScope scope; | |
| 38 native_viewport_->Create(bounds); | |
| 39 | 36 |
| 40 ScopedMessagePipeHandle gles2_handle, gles2_client_handle; | 37 ScopedMessagePipeHandle gles2_handle, gles2_client_handle; |
| 41 CreateMessagePipe(&gles2_handle, &gles2_client_handle); | 38 CreateMessagePipe(&gles2_handle, &gles2_client_handle); |
| 42 | 39 |
| 43 // The ContextFactory must exist before any Compositors are created. | 40 // The ContextFactory must exist before any Compositors are created. |
| 44 if (context_factory_) { | 41 if (context_factory_) { |
| 45 ui::ContextFactory::SetInstance(NULL); | 42 ui::ContextFactory::SetInstance(NULL); |
| 46 delete context_factory_; | 43 delete context_factory_; |
| 47 context_factory_ = NULL; | 44 context_factory_ = NULL; |
| 48 } | 45 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 79 void WindowTreeHostMojo::Hide() { | 76 void WindowTreeHostMojo::Hide() { |
| 80 native_viewport_->Hide(); | 77 native_viewport_->Hide(); |
| 81 window()->Hide(); | 78 window()->Hide(); |
| 82 } | 79 } |
| 83 | 80 |
| 84 gfx::Rect WindowTreeHostMojo::GetBounds() const { | 81 gfx::Rect WindowTreeHostMojo::GetBounds() const { |
| 85 return bounds_; | 82 return bounds_; |
| 86 } | 83 } |
| 87 | 84 |
| 88 void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { | 85 void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { |
| 89 AllocationScope scope; | 86 native_viewport_->SetBounds(Rect::From(bounds)); |
| 90 native_viewport_->SetBounds(bounds); | |
| 91 } | 87 } |
| 92 | 88 |
| 93 gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const { | 89 gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const { |
| 94 return gfx::Point(0, 0); | 90 return gfx::Point(0, 0); |
| 95 } | 91 } |
| 96 | 92 |
| 97 void WindowTreeHostMojo::SetCapture() { | 93 void WindowTreeHostMojo::SetCapture() { |
| 98 NOTIMPLEMENTED(); | 94 NOTIMPLEMENTED(); |
| 99 } | 95 } |
| 100 | 96 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 131 } | 127 } |
| 132 | 128 |
| 133 //////////////////////////////////////////////////////////////////////////////// | 129 //////////////////////////////////////////////////////////////////////////////// |
| 134 // WindowTreeHostMojo, NativeViewportClient implementation: | 130 // WindowTreeHostMojo, NativeViewportClient implementation: |
| 135 | 131 |
| 136 void WindowTreeHostMojo::OnCreated() { | 132 void WindowTreeHostMojo::OnCreated() { |
| 137 CreateCompositor(GetAcceleratedWidget()); | 133 CreateCompositor(GetAcceleratedWidget()); |
| 138 compositor_created_callback_.Run(); | 134 compositor_created_callback_.Run(); |
| 139 } | 135 } |
| 140 | 136 |
| 141 void WindowTreeHostMojo::OnBoundsChanged(const Rect& bounds) { | 137 void WindowTreeHostMojo::OnBoundsChanged(RectPtr bounds) { |
| 142 bounds_ = gfx::Rect(bounds.position().x(), bounds.position().y(), | 138 bounds_ = gfx::Rect(bounds->position->x, bounds->position->y, |
| 143 bounds.size().width(), bounds.size().height()); | 139 bounds->size->width, bounds->size->height); |
| 144 window()->SetBounds(gfx::Rect(bounds_.size())); | 140 window()->SetBounds(gfx::Rect(bounds_.size())); |
| 145 OnHostResized(bounds_.size()); | 141 OnHostResized(bounds_.size()); |
| 146 } | 142 } |
| 147 | 143 |
| 148 void WindowTreeHostMojo::OnDestroyed() { | 144 void WindowTreeHostMojo::OnDestroyed() { |
| 149 base::MessageLoop::current()->Quit(); | 145 base::MessageLoop::current()->Quit(); |
| 150 } | 146 } |
| 151 | 147 |
| 152 void WindowTreeHostMojo::OnEvent(const Event& event, | 148 void WindowTreeHostMojo::OnEvent(EventPtr event, |
| 153 const mojo::Callback<void()>& callback) { | 149 const mojo::Callback<void()>& callback) { |
| 154 switch (event.action()) { | 150 switch (event->action) { |
| 155 case ui::ET_MOUSE_PRESSED: | 151 case ui::ET_MOUSE_PRESSED: |
| 156 case ui::ET_MOUSE_DRAGGED: | 152 case ui::ET_MOUSE_DRAGGED: |
| 157 case ui::ET_MOUSE_RELEASED: | 153 case ui::ET_MOUSE_RELEASED: |
| 158 case ui::ET_MOUSE_MOVED: | 154 case ui::ET_MOUSE_MOVED: |
| 159 case ui::ET_MOUSE_ENTERED: | 155 case ui::ET_MOUSE_ENTERED: |
| 160 case ui::ET_MOUSE_EXITED: { | 156 case ui::ET_MOUSE_EXITED: { |
| 161 gfx::Point location(event.location().x(), event.location().y()); | 157 gfx::Point location(event->location->x, event->location->y); |
| 162 ui::MouseEvent ev(static_cast<ui::EventType>(event.action()), location, | 158 ui::MouseEvent ev(static_cast<ui::EventType>(event->action), location, |
| 163 location, event.flags(), 0); | 159 location, event->flags, 0); |
| 164 SendEventToProcessor(&ev); | 160 SendEventToProcessor(&ev); |
| 165 break; | 161 break; |
| 166 } | 162 } |
| 167 case ui::ET_KEY_PRESSED: | 163 case ui::ET_KEY_PRESSED: |
| 168 case ui::ET_KEY_RELEASED: { | 164 case ui::ET_KEY_RELEASED: { |
| 169 ui::KeyEvent ev( | 165 ui::KeyEvent ev( |
| 170 static_cast<ui::EventType>(event.action()), | 166 static_cast<ui::EventType>(event->action), |
| 171 static_cast<ui::KeyboardCode>(event.key_data().key_code()), | 167 static_cast<ui::KeyboardCode>(event->key_data->key_code), |
| 172 event.flags(), event.key_data().is_char()); | 168 event->flags, event->key_data->is_char); |
| 173 SendEventToProcessor(&ev); | 169 SendEventToProcessor(&ev); |
| 174 break; | 170 break; |
| 175 } | 171 } |
| 176 // TODO(beng): touch, etc. | 172 // TODO(beng): touch, etc. |
| 177 } | 173 } |
| 178 callback.Run(); | 174 callback.Run(); |
| 179 }; | 175 }; |
| 180 | 176 |
| 181 } // namespace mojo | 177 } // namespace mojo |
| OLD | NEW |