| Index: mojo/services/native_viewport/native_viewport_win.cc
|
| diff --git a/mojo/services/native_viewport/native_viewport_win.cc b/mojo/services/native_viewport/native_viewport_win.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8951e53179df880aa24bf322336333507a1ee9bd
|
| --- /dev/null
|
| +++ b/mojo/services/native_viewport/native_viewport_win.cc
|
| @@ -0,0 +1,80 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "mojo/services/native_viewport/native_viewport.h"
|
| +#include "ui/events/event.h"
|
| +#include "ui/gfx/win/window_impl.h"
|
| +
|
| +namespace mojo {
|
| +namespace services {
|
| +
|
| +class NativeViewportWin : public gfx::WindowImpl,
|
| + public NativeViewport {
|
| + public:
|
| + explicit NativeViewportWin(NativeViewportDelegate* delegate)
|
| + : delegate_(delegate) {
|
| + Init(NULL, gfx::Rect(10, 10, 500, 500));
|
| + ShowWindow(hwnd(), SW_SHOWNORMAL);
|
| + SetWindowText(hwnd(), L"native_viewport::NativeViewportWin!");
|
| + }
|
| + virtual ~NativeViewportWin() {
|
| + if (IsWindow(hwnd()))
|
| + DestroyWindow(hwnd());
|
| + }
|
| +
|
| + private:
|
| + // Overridden from NativeViewport:
|
| + virtual void Close() OVERRIDE {
|
| + DestroyWindow(hwnd());
|
| + }
|
| +
|
| + BEGIN_MSG_MAP_EX(NativeViewportWin)
|
| + MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
|
| +
|
| + MSG_WM_PAINT(OnPaint)
|
| + MSG_WM_SIZE(OnSize)
|
| + MSG_WM_DESTROY(OnDestroy)
|
| + END_MSG_MAP()
|
| +
|
| + LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) {
|
| + MSG msg = { hwnd(), message, w_param, l_param, 0,
|
| + { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } };
|
| + ui::MouseEvent event(msg);
|
| + bool handled = delegate_->OnEvent(&event);
|
| + SetMsgHandled(handled);
|
| + return 0;
|
| + }
|
| + void OnPaint(HDC) {
|
| + RECT cr;
|
| + GetClientRect(hwnd(), &cr);
|
| +
|
| + PAINTSTRUCT ps;
|
| + HDC dc = BeginPaint(hwnd(), &ps);
|
| + HBRUSH red_brush = CreateSolidBrush(RGB(255, 0, 0));
|
| + HGDIOBJ old_object = SelectObject(dc, red_brush);
|
| + Rectangle(dc, cr.left, cr.top, cr.right, cr.bottom);
|
| + SelectObject(dc, old_object);
|
| + DeleteObject(red_brush);
|
| + EndPaint(hwnd(), &ps);
|
| + }
|
| + void OnSize(UINT param, const CSize& size) {
|
| + delegate_->OnResized(gfx::Size(size.cx, size.cy));
|
| + }
|
| + void OnDestroy() {
|
| + delegate_->OnDestroyed();
|
| + }
|
| +
|
| + NativeViewportDelegate* delegate_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(NativeViewportWin);
|
| +};
|
| +
|
| +// static
|
| +scoped_ptr<NativeViewport> NativeViewport::Create(
|
| + NativeViewportDelegate* delegate) {
|
| + return scoped_ptr<NativeViewport>(new NativeViewportWin(delegate)).Pass();
|
| +}
|
| +
|
| +} // namespace services
|
| +} // namespace mojo
|
|
|