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

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: rebase Created 6 years, 6 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
« no previous file with comments | « mojo/aura/window_tree_host_mojo.h ('k') | mojo/common/common_type_converters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/public/cpp/geometry/geometry_type_converters.h" 9 #include "mojo/services/public/cpp/geometry/geometry_type_converters.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
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
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_ = bounds; 138 bounds_ = bounds.To<gfx::Rect>();
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
« no previous file with comments | « mojo/aura/window_tree_host_mojo.h ('k') | mojo/common/common_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698