| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 122 |
| 119 LRESULT WinWindow::OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param) { | 123 LRESULT WinWindow::OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param) { |
| 120 MSG msg = { hwnd(), message, w_param, l_param }; | 124 MSG msg = { hwnd(), message, w_param, l_param }; |
| 121 KeyEvent event(msg, message == WM_CHAR); | 125 KeyEvent event(msg, message == WM_CHAR); |
| 122 delegate_->DispatchEvent(&event); | 126 delegate_->DispatchEvent(&event); |
| 123 SetMsgHandled(event.handled()); | 127 SetMsgHandled(event.handled()); |
| 124 return 0; | 128 return 0; |
| 125 } | 129 } |
| 126 | 130 |
| 127 LRESULT WinWindow::OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param) { | 131 LRESULT WinWindow::OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param) { |
| 132 delegate_->OnActivationChanged(!!w_param); |
| 128 return DefWindowProc(hwnd(), message, w_param, l_param); | 133 return DefWindowProc(hwnd(), message, w_param, l_param); |
| 129 } | 134 } |
| 130 | 135 |
| 131 void WinWindow::OnClose() { | 136 void WinWindow::OnClose() { |
| 132 delegate_->OnCloseRequest(); | 137 delegate_->OnCloseRequest(); |
| 133 } | 138 } |
| 134 | 139 |
| 135 LRESULT WinWindow::OnCreate(CREATESTRUCT* create_struct) { | 140 LRESULT WinWindow::OnCreate(CREATESTRUCT* create_struct) { |
| 136 delegate_->OnAcceleratedWidgetAvailable(hwnd()); | 141 delegate_->OnAcceleratedWidgetAvailable(hwnd()); |
| 137 return 0; | 142 return 0; |
| 138 } | 143 } |
| 139 | 144 |
| 140 void WinWindow::OnDestroy() { | 145 void WinWindow::OnDestroy() { |
| 141 delegate_->OnClosed(); | 146 delegate_->OnClosed(); |
| 142 } | 147 } |
| 143 | 148 |
| 144 void WinWindow::OnPaint(HDC) { | 149 void WinWindow::OnPaint(HDC) { |
| 145 gfx::Rect damage_rect; | 150 gfx::Rect damage_rect; |
| 146 RECT update_rect = {0}; | 151 RECT update_rect = {0}; |
| 147 if (GetUpdateRect(hwnd(), &update_rect, FALSE)) | 152 if (GetUpdateRect(hwnd(), &update_rect, FALSE)) |
| 148 damage_rect = gfx::Rect(update_rect); | 153 damage_rect = gfx::Rect(update_rect); |
| 149 delegate_->OnDamageRect(damage_rect); | 154 delegate_->OnDamageRect(damage_rect); |
| 155 ValidateRect(hwnd(), NULL); |
| 150 } | 156 } |
| 151 | 157 |
| 152 void WinWindow::OnWindowPosChanged(WINDOWPOS* window_pos) { | 158 void WinWindow::OnWindowPosChanged(WINDOWPOS* window_pos) { |
| 153 if (!(window_pos->flags & SWP_NOSIZE) || | 159 if (!(window_pos->flags & SWP_NOSIZE) || |
| 154 !(window_pos->flags & SWP_NOMOVE)) { | 160 !(window_pos->flags & SWP_NOMOVE)) { |
| 155 RECT cr; | 161 RECT cr; |
| 156 GetClientRect(hwnd(), &cr); | 162 GetClientRect(hwnd(), &cr); |
| 157 delegate_->OnBoundsChanged( | 163 delegate_->OnBoundsChanged( |
| 158 gfx::Rect(window_pos->x, window_pos->y, | 164 gfx::Rect(window_pos->x, window_pos->y, |
| 159 cr.right - cr.left, cr.bottom - cr.top)); | 165 cr.right - cr.left, cr.bottom - cr.top)); |
| 160 } | 166 } |
| 161 } | 167 } |
| 162 | 168 |
| 169 namespace test { |
| 170 |
| 171 // static |
| 172 void SetUsePopupAsRootWindowForTest(bool use) { |
| 173 use_popup_as_root_window_for_test = use; |
| 174 } |
| 175 |
| 176 } // namespace test |
| 177 |
| 163 } // namespace ui | 178 } // namespace ui |
| OLD | NEW |