OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/platform_window/win/win_window.h" | 5 #include "ui/platform_window/win/win_window.h" |
6 | 6 |
7 #include "ui/events/event.h" | 7 #include "ui/events/event.h" |
8 #include "ui/events/event_utils.h" | 8 #include "ui/events/event_utils.h" |
9 #include "ui/gfx/win/msg_util.h" | 9 #include "ui/gfx/win/msg_util.h" |
10 #include "ui/platform_window/platform_window_delegate.h" | 10 #include "ui/platform_window/platform_window_delegate.h" |
11 | 11 |
12 namespace ui { | 12 namespace ui { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 bool use_popup_as_root_window_for_test = false; | |
17 | |
18 gfx::Rect GetWindowBoundsForClientBounds(DWORD style, DWORD ex_style, | 16 gfx::Rect GetWindowBoundsForClientBounds(DWORD style, DWORD ex_style, |
19 const gfx::Rect& bounds) { | 17 const gfx::Rect& bounds) { |
20 RECT wr; | 18 RECT wr; |
21 wr.left = bounds.x(); | 19 wr.left = bounds.x(); |
22 wr.top = bounds.y(); | 20 wr.top = bounds.y(); |
23 wr.right = bounds.x() + bounds.width(); | 21 wr.right = bounds.x() + bounds.width(); |
24 wr.bottom = bounds.y() + bounds.height(); | 22 wr.bottom = bounds.y() + bounds.height(); |
25 AdjustWindowRectEx(&wr, style, FALSE, ex_style); | 23 AdjustWindowRectEx(&wr, style, FALSE, ex_style); |
26 | 24 |
27 // Make sure to keep the window onscreen, as AdjustWindowRectEx() may have | 25 // Make sure to keep the window onscreen, as AdjustWindowRectEx() may have |
28 // moved part of it offscreen. | 26 // moved part of it offscreen. |
29 gfx::Rect window_bounds(wr.left, wr.top, | 27 gfx::Rect window_bounds(wr.left, wr.top, |
30 wr.right - wr.left, wr.bottom - wr.top); | 28 wr.right - wr.left, wr.bottom - wr.top); |
31 window_bounds.set_x(std::max(0, window_bounds.x())); | 29 window_bounds.set_x(std::max(0, window_bounds.x())); |
32 window_bounds.set_y(std::max(0, window_bounds.y())); | 30 window_bounds.set_y(std::max(0, window_bounds.y())); |
33 return window_bounds; | 31 return window_bounds; |
34 } | 32 } |
35 | 33 |
36 } // namespace | 34 } // namespace |
37 | 35 |
38 WinWindow::WinWindow(PlatformWindowDelegate* delegate, | 36 WinWindow::WinWindow(PlatformWindowDelegate* delegate, |
39 const gfx::Rect& bounds) | 37 const gfx::Rect& bounds) |
40 : delegate_(delegate) { | 38 : delegate_(delegate) { |
41 CHECK(delegate_); | 39 CHECK(delegate_); |
42 if (use_popup_as_root_window_for_test) | |
43 set_window_style(WS_POPUP); | |
44 gfx::Rect window_bounds = GetWindowBoundsForClientBounds( | 40 gfx::Rect window_bounds = GetWindowBoundsForClientBounds( |
45 WS_OVERLAPPEDWINDOW, window_ex_style(), bounds); | 41 WS_OVERLAPPEDWINDOW, window_ex_style(), bounds); |
46 gfx::WindowImpl::Init(NULL, window_bounds); | 42 gfx::WindowImpl::Init(NULL, window_bounds); |
47 SetWindowText(hwnd(), L"WinWindow"); | 43 SetWindowText(hwnd(), L"WinWindow"); |
48 } | 44 } |
49 | 45 |
50 WinWindow::~WinWindow() { | 46 WinWindow::~WinWindow() { |
51 Destroy(); | 47 Destroy(); |
52 } | 48 } |
53 | 49 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 119 |
124 LRESULT WinWindow::OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param) { | 120 LRESULT WinWindow::OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param) { |
125 MSG msg = { hwnd(), message, w_param, l_param }; | 121 MSG msg = { hwnd(), message, w_param, l_param }; |
126 KeyEvent event(msg, message == WM_CHAR); | 122 KeyEvent event(msg, message == WM_CHAR); |
127 delegate_->DispatchEvent(&event); | 123 delegate_->DispatchEvent(&event); |
128 SetMsgHandled(event.handled()); | 124 SetMsgHandled(event.handled()); |
129 return 0; | 125 return 0; |
130 } | 126 } |
131 | 127 |
132 LRESULT WinWindow::OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param) { | 128 LRESULT WinWindow::OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param) { |
133 delegate_->OnActivationChanged(!!w_param); | |
134 return DefWindowProc(hwnd(), message, w_param, l_param); | 129 return DefWindowProc(hwnd(), message, w_param, l_param); |
135 } | 130 } |
136 | 131 |
137 void WinWindow::OnClose() { | 132 void WinWindow::OnClose() { |
138 delegate_->OnCloseRequest(); | 133 delegate_->OnCloseRequest(); |
139 } | 134 } |
140 | 135 |
141 LRESULT WinWindow::OnCreate(CREATESTRUCT* create_struct) { | 136 LRESULT WinWindow::OnCreate(CREATESTRUCT* create_struct) { |
142 delegate_->OnAcceleratedWidgetAvailable(hwnd()); | 137 delegate_->OnAcceleratedWidgetAvailable(hwnd()); |
143 return 0; | 138 return 0; |
(...skipping 16 matching lines...) Expand all Loading... |
160 if (!(window_pos->flags & SWP_NOSIZE) || | 155 if (!(window_pos->flags & SWP_NOSIZE) || |
161 !(window_pos->flags & SWP_NOMOVE)) { | 156 !(window_pos->flags & SWP_NOMOVE)) { |
162 RECT cr; | 157 RECT cr; |
163 GetClientRect(hwnd(), &cr); | 158 GetClientRect(hwnd(), &cr); |
164 delegate_->OnBoundsChanged( | 159 delegate_->OnBoundsChanged( |
165 gfx::Rect(window_pos->x, window_pos->y, | 160 gfx::Rect(window_pos->x, window_pos->y, |
166 cr.right - cr.left, cr.bottom - cr.top)); | 161 cr.right - cr.left, cr.bottom - cr.top)); |
167 } | 162 } |
168 } | 163 } |
169 | 164 |
170 namespace test { | |
171 | |
172 // static | |
173 void SetUsePopupAsRootWindowForTest(bool use) { | |
174 use_popup_as_root_window_for_test = use; | |
175 } | |
176 | |
177 } // namespace test | |
178 } // namespace ui | 165 } // namespace ui |
OLD | NEW |