OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/services/native_viewport/native_viewport_controller.h" |
| 6 |
| 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/stringprintf.h" |
| 9 #include "mojo/services/native_viewport/native_viewport.h" |
| 10 #include "ui/events/event.h" |
| 11 |
| 12 namespace mojo { |
| 13 namespace services { |
| 14 |
| 15 NativeViewportController::NativeViewportController(Handle pipe) |
| 16 : pipe_(pipe) { |
| 17 native_viewport_ = NativeViewport::Create(this); |
| 18 } |
| 19 NativeViewportController::~NativeViewportController() { |
| 20 } |
| 21 |
| 22 void NativeViewportController::Close() { |
| 23 DCHECK(native_viewport_); |
| 24 native_viewport_->Close(); |
| 25 } |
| 26 |
| 27 bool NativeViewportController::OnEvent(ui::Event* event) { |
| 28 ui::LocatedEvent* located = static_cast<ui::LocatedEvent*>(event); |
| 29 SendString(base::StringPrintf("Event @ %d,%d", |
| 30 located->location().x(), |
| 31 located->location().y())); |
| 32 return false; |
| 33 } |
| 34 |
| 35 void NativeViewportController::OnResized(const gfx::Size& size) { |
| 36 SendString(base::StringPrintf("Sized to: %d x %d", |
| 37 size.width(), |
| 38 size.height())); |
| 39 } |
| 40 |
| 41 void NativeViewportController::OnDestroyed() { |
| 42 base::MessageLoop::current()->Quit(); |
| 43 } |
| 44 |
| 45 void NativeViewportController::SendString(const std::string& string) { |
| 46 WriteMessage(pipe_, string.c_str(), string.size()+1, NULL, 0, |
| 47 MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 48 } |
| 49 |
| 50 } // namespace services |
| 51 } // namespace mojo |
OLD | NEW |