| 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 |
| 16 gfx::Rect GetWindowBoundsForClientBounds(DWORD style, DWORD ex_style, | 18 gfx::Rect GetWindowBoundsForClientBounds(DWORD style, DWORD ex_style, |
| 17 const gfx::Rect& bounds) { | 19 const gfx::Rect& bounds) { |
| 18 RECT wr; | 20 RECT wr; |
| 19 wr.left = bounds.x(); | 21 wr.left = bounds.x(); |
| 20 wr.top = bounds.y(); | 22 wr.top = bounds.y(); |
| 21 wr.right = bounds.x() + bounds.width(); | 23 wr.right = bounds.x() + bounds.width(); |
| 22 wr.bottom = bounds.y() + bounds.height(); | 24 wr.bottom = bounds.y() + bounds.height(); |
| 23 AdjustWindowRectEx(&wr, style, FALSE, ex_style); | 25 AdjustWindowRectEx(&wr, style, FALSE, ex_style); |
| 24 | 26 |
| 25 // Make sure to keep the window onscreen, as AdjustWindowRectEx() may have | 27 // Make sure to keep the window onscreen, as AdjustWindowRectEx() may have |
| 26 // moved part of it offscreen. | 28 // moved part of it offscreen. |
| 27 gfx::Rect window_bounds(wr.left, wr.top, | 29 gfx::Rect window_bounds(wr.left, wr.top, |
| 28 wr.right - wr.left, wr.bottom - wr.top); | 30 wr.right - wr.left, wr.bottom - wr.top); |
| 29 window_bounds.set_x(std::max(0, window_bounds.x())); | 31 window_bounds.set_x(std::max(0, window_bounds.x())); |
| 30 window_bounds.set_y(std::max(0, window_bounds.y())); | 32 window_bounds.set_y(std::max(0, window_bounds.y())); |
| 31 return window_bounds; | 33 return window_bounds; |
| 32 } | 34 } |
| 33 | 35 |
| 34 } // namespace | 36 } // namespace |
| 35 | 37 |
| 36 WinWindow::WinWindow(PlatformWindowDelegate* delegate, | 38 WinWindow::WinWindow(PlatformWindowDelegate* delegate, |
| 37 const gfx::Rect& bounds) | 39 const gfx::Rect& bounds) |
| 38 : delegate_(delegate) { | 40 : delegate_(delegate) { |
| 39 CHECK(delegate_); | 41 CHECK(delegate_); |
| 42 if (use_popup_as_root_window_for_test) |
| 43 set_window_style(WS_POPUP); |
| 40 gfx::Rect window_bounds = GetWindowBoundsForClientBounds( | 44 gfx::Rect window_bounds = GetWindowBoundsForClientBounds( |
| 41 WS_OVERLAPPEDWINDOW, window_ex_style(), bounds); | 45 WS_OVERLAPPEDWINDOW, window_ex_style(), bounds); |
| 42 gfx::WindowImpl::Init(NULL, window_bounds); | 46 gfx::WindowImpl::Init(NULL, window_bounds); |
| 43 SetWindowText(hwnd(), L"WinWindow"); | 47 SetWindowText(hwnd(), L"WinWindow"); |
| 44 } | 48 } |
| 45 | 49 |
| 46 WinWindow::~WinWindow() { | 50 WinWindow::~WinWindow() { |
| 47 Destroy(); | 51 Destroy(); |
| 48 } | 52 } |
| 49 | 53 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 123 |
| 120 LRESULT WinWindow::OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param) { | 124 LRESULT WinWindow::OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param) { |
| 121 MSG msg = { hwnd(), message, w_param, l_param }; | 125 MSG msg = { hwnd(), message, w_param, l_param }; |
| 122 KeyEvent event(msg, message == WM_CHAR); | 126 KeyEvent event(msg, message == WM_CHAR); |
| 123 delegate_->DispatchEvent(&event); | 127 delegate_->DispatchEvent(&event); |
| 124 SetMsgHandled(event.handled()); | 128 SetMsgHandled(event.handled()); |
| 125 return 0; | 129 return 0; |
| 126 } | 130 } |
| 127 | 131 |
| 128 LRESULT WinWindow::OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param) { | 132 LRESULT WinWindow::OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param) { |
| 133 delegate_->OnActivationChanged(!!w_param); |
| 129 return DefWindowProc(hwnd(), message, w_param, l_param); | 134 return DefWindowProc(hwnd(), message, w_param, l_param); |
| 130 } | 135 } |
| 131 | 136 |
| 132 void WinWindow::OnClose() { | 137 void WinWindow::OnClose() { |
| 133 delegate_->OnCloseRequest(); | 138 delegate_->OnCloseRequest(); |
| 134 } | 139 } |
| 135 | 140 |
| 136 LRESULT WinWindow::OnCreate(CREATESTRUCT* create_struct) { | 141 LRESULT WinWindow::OnCreate(CREATESTRUCT* create_struct) { |
| 137 delegate_->OnAcceleratedWidgetAvailable(hwnd()); | 142 delegate_->OnAcceleratedWidgetAvailable(hwnd()); |
| 138 return 0; | 143 return 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 155 if (!(window_pos->flags & SWP_NOSIZE) || | 160 if (!(window_pos->flags & SWP_NOSIZE) || |
| 156 !(window_pos->flags & SWP_NOMOVE)) { | 161 !(window_pos->flags & SWP_NOMOVE)) { |
| 157 RECT cr; | 162 RECT cr; |
| 158 GetClientRect(hwnd(), &cr); | 163 GetClientRect(hwnd(), &cr); |
| 159 delegate_->OnBoundsChanged( | 164 delegate_->OnBoundsChanged( |
| 160 gfx::Rect(window_pos->x, window_pos->y, | 165 gfx::Rect(window_pos->x, window_pos->y, |
| 161 cr.right - cr.left, cr.bottom - cr.top)); | 166 cr.right - cr.left, cr.bottom - cr.top)); |
| 162 } | 167 } |
| 163 } | 168 } |
| 164 | 169 |
| 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 |
| 165 } // namespace ui | 178 } // namespace ui |
| OLD | NEW |