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

Unified Diff: mojo/services/native_viewport/native_viewport_win.cc

Issue 51373002: NativeViewport (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nl Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « mojo/services/native_viewport/native_viewport_stub.cc ('k') | mojo/services/native_viewport/native_viewport_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698