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

Side by Side Diff: ui/platform_window/win/win_window.cc

Issue 405813002: win32: Add a PlatformWindow implementation for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix-move-resize Created 6 years, 5 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 | « ui/platform_window/win/win_window.h ('k') | ui/platform_window/win/win_window.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "ui/platform_window/win/win_window.h"
6
7 #include "ui/events/event.h"
8 #include "ui/events/event_utils.h"
9 #include "ui/gfx/win/msg_util.h"
10 #include "ui/platform_window/platform_window_delegate.h"
11
12 namespace ui {
13
14 namespace {
15
16 gfx::Rect GetWindowBoundsForClientBounds(DWORD style, DWORD ex_style,
17 const gfx::Rect& bounds) {
18 RECT wr;
19 wr.left = bounds.x();
20 wr.top = bounds.y();
21 wr.right = bounds.x() + bounds.width();
22 wr.bottom = bounds.y() + bounds.height();
23 AdjustWindowRectEx(&wr, style, FALSE, ex_style);
24
25 // Make sure to keep the window onscreen, as AdjustWindowRectEx() may have
26 // moved part of it offscreen.
27 gfx::Rect window_bounds(wr.left, wr.top,
28 wr.right - wr.left, wr.bottom - wr.top);
29 window_bounds.set_x(std::max(0, window_bounds.x()));
30 window_bounds.set_y(std::max(0, window_bounds.y()));
31 return window_bounds;
32 }
33
34 } // namespace
35
36 WinWindow::WinWindow(PlatformWindowDelegate* delegate,
37 const gfx::Rect& bounds)
38 : delegate_(delegate) {
39 CHECK(delegate_);
40 gfx::Rect window_bounds = GetWindowBoundsForClientBounds(
41 WS_OVERLAPPEDWINDOW, window_ex_style(), bounds);
42 gfx::WindowImpl::Init(NULL, window_bounds);
43 SetWindowText(hwnd(), L"WinWindow");
44 }
45
46 WinWindow::~WinWindow() {
47 Destroy();
48 }
49
50 void WinWindow::Destroy() {
51 if (IsWindow(hwnd()))
52 DestroyWindow(hwnd());
53 }
54
55 void WinWindow::Show() {
56 ShowWindow(hwnd(), SW_SHOWNORMAL);
57 }
58
59 void WinWindow::Hide() {
60 ShowWindow(hwnd(), SW_HIDE);
61 }
62
63 void WinWindow::Close() {
64 Destroy();
65 }
66
67 void WinWindow::SetBounds(const gfx::Rect& bounds) {
68 gfx::Rect window_bounds = GetWindowBoundsForClientBounds(
69 GetWindowLong(hwnd(), GWL_STYLE),
70 GetWindowLong(hwnd(), GWL_EXSTYLE),
71 bounds);
72 SetWindowPos(hwnd(), NULL, window_bounds.x(), window_bounds.y(),
73 window_bounds.width(), window_bounds.height(),
74 SWP_NOREPOSITION);
75 }
76
77 gfx::Rect WinWindow::GetBounds() {
78 RECT cr;
79 GetClientRect(hwnd(), &cr);
80 return gfx::Rect(cr);
81 }
82
83 void WinWindow::SetCapture() {
84 DCHECK(::GetCapture() != hwnd());
85 ::SetCapture(hwnd());
86 }
87
88 void WinWindow::ReleaseCapture() {
89 if (::GetCapture() == hwnd())
90 ::ReleaseCapture();
91 }
92
93 void WinWindow::ToggleFullscreen() {}
94
95 void WinWindow::Maximize() {}
96
97 void WinWindow::Minimize() {}
98
99 void WinWindow::Restore() {}
100
101 LRESULT WinWindow::OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) {
102 MSG msg = { hwnd(), message, w_param, l_param, 0,
103 { CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param) } };
104 MouseEvent event(msg);
105 if (IsMouseEventFromTouch(message))
106 event.set_flags(event.flags() | EF_FROM_TOUCH);
107 if (!(event.flags() & ui::EF_IS_NON_CLIENT))
108 delegate_->DispatchEvent(&event);
109 SetMsgHandled(event.handled());
110 return 0;
111 }
112
113 LRESULT WinWindow::OnCaptureChanged(UINT message,
114 WPARAM w_param,
115 LPARAM l_param) {
116 delegate_->OnLostCapture();
117 return 0;
118 }
119
120 LRESULT WinWindow::OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param) {
121 MSG msg = { hwnd(), message, w_param, l_param };
122 KeyEvent event(msg, message == WM_CHAR);
123 delegate_->DispatchEvent(&event);
124 SetMsgHandled(event.handled());
125 return 0;
126 }
127
128 LRESULT WinWindow::OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param) {
129 return DefWindowProc(hwnd(), message, w_param, l_param);
130 }
131
132 void WinWindow::OnClose() {
133 delegate_->OnCloseRequest();
134 }
135
136 LRESULT WinWindow::OnCreate(CREATESTRUCT* create_struct) {
137 delegate_->OnAcceleratedWidgetAvailable(hwnd());
138 return 0;
139 }
140
141 void WinWindow::OnDestroy() {
142 delegate_->OnClosed();
143 }
144
145 void WinWindow::OnPaint(HDC) {
146 gfx::Rect damage_rect;
147 RECT update_rect = {0};
148 if (GetUpdateRect(hwnd(), &update_rect, FALSE))
149 damage_rect = gfx::Rect(update_rect);
150 delegate_->OnDamageRect(damage_rect);
151 ValidateRect(hwnd(), NULL);
152 }
153
154 void WinWindow::OnWindowPosChanged(WINDOWPOS* window_pos) {
155 if (!(window_pos->flags & SWP_NOSIZE) ||
156 !(window_pos->flags & SWP_NOMOVE)) {
157 RECT cr;
158 GetClientRect(hwnd(), &cr);
159 delegate_->OnBoundsChanged(
160 gfx::Rect(window_pos->x, window_pos->y,
161 cr.right - cr.left, cr.bottom - cr.top));
162 }
163 }
164
165 } // namespace ui
OLDNEW
« no previous file with comments | « ui/platform_window/win/win_window.h ('k') | ui/platform_window/win/win_window.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698