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

Side by Side Diff: mojo/services/native_viewport/native_viewport_win.cc

Issue 51373002: NativeViewport (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month 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
(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.h"
6 #include "mojo/services/native_viewport/native_viewport_delegate.h"
7 #include "ui/events/event.h"
8 #include "ui/gfx/win/window_impl.h"
9
10 namespace mojo {
11 namespace services {
12
13 class NativeViewportWin : public gfx::WindowImpl,
14 public NativeViewport {
15 public:
16 explicit NativeViewportWin(NativeViewportDelegate* delegate)
17 : delegate_(delegate) {
18 Init(NULL, gfx::Rect(10, 10, 500, 500));
19 ShowWindow(hwnd(), SW_SHOWNORMAL);
20 SetWindowText(hwnd(), L"native_viewport::NativeViewportWin!");
21 }
22 virtual ~NativeViewportWin() {
23 DestroyWindow(hwnd());
24 }
25
26 private:
27 BEGIN_MSG_MAP_EX(NativeViewportWin)
28 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
29
30 MSG_WM_PAINT(OnPaint)
31 MSG_WM_SIZE(OnSize)
32 END_MSG_MAP()
33
34 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) {
35 MSG msg = { hwnd(), message, w_param, l_param, 0,
36 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } };
37 ui::MouseEvent event(msg);
38 bool handled = delegate_->OnEvent(&event);
39 SetMsgHandled(handled);
40 return 0;
41 }
42 void OnPaint(HDC) {
43 RECT cr;
44 GetClientRect(hwnd(), &cr);
45
46 PAINTSTRUCT ps;
47 HDC dc = BeginPaint(hwnd(), &ps);
48 HBRUSH red_brush = CreateSolidBrush(RGB(255, 0, 0));
49 HGDIOBJ old_object = SelectObject(dc, red_brush);
50 Rectangle(dc, cr.left, cr.top, cr.right, cr.bottom);
51 SelectObject(dc, old_object);
52 DeleteObject(red_brush);
53 EndPaint(hwnd(), &ps);
54 }
55 void OnSize(UINT param, const CSize& size) {
56 delegate_->OnResized(gfx::Size(size.cx, size.cy));
57 }
58
59 NativeViewportDelegate* delegate_;
60
61 DISALLOW_COPY_AND_ASSIGN(NativeViewportWin);
62 };
63
64 // static
65 NativeViewport* NativeViewport::CreateNativeViewport(
66 NativeViewportDelegate* delegate) {
67 return new NativeViewportWin(delegate);
68 }
69
70 } // namespace services
71 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698