Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: mojo/aura/window_tree_host_mojo.cc

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/public/c/gles2/gles2.h" 8 #include "mojo/public/c/gles2/gles2.h"
9 #include "mojo/public/cpp/bindings/allocation_scope.h"
10 #include "mojo/services/native_viewport/geometry_conversions.h" 9 #include "mojo/services/native_viewport/geometry_conversions.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_->SetClient(this); 34 native_viewport_->SetClient(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 29 matching lines...) Expand all
78 void WindowTreeHostMojo::Hide() { 75 void WindowTreeHostMojo::Hide() {
79 native_viewport_->Hide(); 76 native_viewport_->Hide();
80 window()->Hide(); 77 window()->Hide();
81 } 78 }
82 79
83 gfx::Rect WindowTreeHostMojo::GetBounds() const { 80 gfx::Rect WindowTreeHostMojo::GetBounds() const {
84 return bounds_; 81 return bounds_;
85 } 82 }
86 83
87 void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { 84 void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) {
88 AllocationScope scope; 85 native_viewport_->SetBounds(Rect::From(bounds));
89 native_viewport_->SetBounds(bounds);
90 } 86 }
91 87
92 gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const { 88 gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const {
93 return gfx::Point(0, 0); 89 return gfx::Point(0, 0);
94 } 90 }
95 91
96 void WindowTreeHostMojo::SetCapture() { 92 void WindowTreeHostMojo::SetCapture() {
97 NOTIMPLEMENTED(); 93 NOTIMPLEMENTED();
98 } 94 }
99 95
(...skipping 30 matching lines...) Expand all
130 } 126 }
131 127
132 //////////////////////////////////////////////////////////////////////////////// 128 ////////////////////////////////////////////////////////////////////////////////
133 // WindowTreeHostMojo, NativeViewportClient implementation: 129 // WindowTreeHostMojo, NativeViewportClient implementation:
134 130
135 void WindowTreeHostMojo::OnCreated() { 131 void WindowTreeHostMojo::OnCreated() {
136 CreateCompositor(GetAcceleratedWidget()); 132 CreateCompositor(GetAcceleratedWidget());
137 compositor_created_callback_.Run(); 133 compositor_created_callback_.Run();
138 } 134 }
139 135
140 void WindowTreeHostMojo::OnBoundsChanged(const Rect& bounds) { 136 void WindowTreeHostMojo::OnBoundsChanged(RectPtr bounds) {
141 bounds_ = gfx::Rect(bounds.position().x(), bounds.position().y(), 137 bounds_ = gfx::Rect(bounds->position->x, bounds->position->y,
142 bounds.size().width(), bounds.size().height()); 138 bounds->size->width, bounds->size->height);
143 window()->SetBounds(gfx::Rect(bounds_.size())); 139 window()->SetBounds(gfx::Rect(bounds_.size()));
144 OnHostResized(bounds_.size()); 140 OnHostResized(bounds_.size());
145 } 141 }
146 142
147 void WindowTreeHostMojo::OnDestroyed() { 143 void WindowTreeHostMojo::OnDestroyed() {
148 base::MessageLoop::current()->Quit(); 144 base::MessageLoop::current()->Quit();
149 } 145 }
150 146
151 void WindowTreeHostMojo::OnEvent(const Event& event, 147 void WindowTreeHostMojo::OnEvent(EventPtr event,
152 const mojo::Callback<void()>& callback) { 148 const mojo::Callback<void()>& callback) {
153 switch (event.action()) { 149 switch (event->action) {
154 case ui::ET_MOUSE_PRESSED: 150 case ui::ET_MOUSE_PRESSED:
155 case ui::ET_MOUSE_DRAGGED: 151 case ui::ET_MOUSE_DRAGGED:
156 case ui::ET_MOUSE_RELEASED: 152 case ui::ET_MOUSE_RELEASED:
157 case ui::ET_MOUSE_MOVED: 153 case ui::ET_MOUSE_MOVED:
158 case ui::ET_MOUSE_ENTERED: 154 case ui::ET_MOUSE_ENTERED:
159 case ui::ET_MOUSE_EXITED: { 155 case ui::ET_MOUSE_EXITED: {
160 gfx::Point location(event.location().x(), event.location().y()); 156 gfx::Point location(event->location->x, event->location->y);
161 ui::MouseEvent ev(static_cast<ui::EventType>(event.action()), location, 157 ui::MouseEvent ev(static_cast<ui::EventType>(event->action), location,
162 location, event.flags(), 0); 158 location, event->flags, 0);
163 SendEventToProcessor(&ev); 159 SendEventToProcessor(&ev);
164 break; 160 break;
165 } 161 }
166 case ui::ET_KEY_PRESSED: 162 case ui::ET_KEY_PRESSED:
167 case ui::ET_KEY_RELEASED: { 163 case ui::ET_KEY_RELEASED: {
168 ui::KeyEvent ev( 164 ui::KeyEvent ev(
169 static_cast<ui::EventType>(event.action()), 165 static_cast<ui::EventType>(event->action),
170 static_cast<ui::KeyboardCode>(event.key_data().key_code()), 166 static_cast<ui::KeyboardCode>(event->key_data->key_code),
171 event.flags(), event.key_data().is_char()); 167 event->flags, event->key_data->is_char);
172 SendEventToProcessor(&ev); 168 SendEventToProcessor(&ev);
173 break; 169 break;
174 } 170 }
175 // TODO(beng): touch, etc. 171 // TODO(beng): touch, etc.
176 } 172 }
177 callback.Run(); 173 callback.Run();
178 }; 174 };
179 175
180 } // namespace mojo 176 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698