| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/widget/native_widget_win.h" | 5 #include "ui/views/widget/native_widget_win.h" |
| 6 | 6 |
| 7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 | 1285 |
| 1286 // This message initializes the window so that focus border are shown for | 1286 // This message initializes the window so that focus border are shown for |
| 1287 // windows. | 1287 // windows. |
| 1288 SendMessage( | 1288 SendMessage( |
| 1289 hwnd(), WM_CHANGEUISTATE, MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); | 1289 hwnd(), WM_CHANGEUISTATE, MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); |
| 1290 | 1290 |
| 1291 // Bug 964884: detach the IME attached to this window. | 1291 // Bug 964884: detach the IME attached to this window. |
| 1292 // We should attach IMEs only when we need to input CJK strings. | 1292 // We should attach IMEs only when we need to input CJK strings. |
| 1293 ImmAssociateContextEx(hwnd(), NULL, 0); | 1293 ImmAssociateContextEx(hwnd(), NULL, 0); |
| 1294 | 1294 |
| 1295 if (remove_standard_frame_) |
| 1296 SendFrameChanged(GetNativeView()); |
| 1297 |
| 1295 // We need to allow the delegate to size its contents since the window may not | 1298 // We need to allow the delegate to size its contents since the window may not |
| 1296 // receive a size notification when its initial bounds are specified at window | 1299 // receive a size notification when its initial bounds are specified at window |
| 1297 // creation time. | 1300 // creation time. |
| 1298 ClientAreaSizeChanged(); | 1301 ClientAreaSizeChanged(); |
| 1299 | 1302 |
| 1300 delegate_->OnNativeWidgetCreated(); | 1303 delegate_->OnNativeWidgetCreated(); |
| 1301 | 1304 |
| 1302 // Get access to a modifiable copy of the system menu. | 1305 // Get access to a modifiable copy of the system menu. |
| 1303 GetSystemMenu(hwnd(), false); | 1306 GetSystemMenu(hwnd(), false); |
| 1304 return 0; | 1307 return 0; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 return TRUE; | 1637 return TRUE; |
| 1635 } | 1638 } |
| 1636 | 1639 |
| 1637 return DefWindowProcWithRedrawLock(WM_NCACTIVATE, | 1640 return DefWindowProcWithRedrawLock(WM_NCACTIVATE, |
| 1638 inactive_rendering_disabled || active, 0); | 1641 inactive_rendering_disabled || active, 0); |
| 1639 } | 1642 } |
| 1640 | 1643 |
| 1641 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { | 1644 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { |
| 1642 // We only override the default handling if we need to specify a custom | 1645 // We only override the default handling if we need to specify a custom |
| 1643 // non-client edge width. Note that in most cases "no insets" means no | 1646 // non-client edge width. Note that in most cases "no insets" means no |
| 1644 // custom width, but in fullscreen mode we want a custom width of 0. | 1647 // custom width, but in fullscreen mode or when the NonClientFrameView |
| 1648 // requests it, we want a custom width of 0. |
| 1645 gfx::Insets insets = GetClientAreaInsets(); | 1649 gfx::Insets insets = GetClientAreaInsets(); |
| 1646 if (insets.empty() && !IsFullscreen()) { | 1650 if (insets.empty() && !IsFullscreen() && |
| 1651 !(mode && remove_standard_frame_)) { |
| 1647 SetMsgHandled(FALSE); | 1652 SetMsgHandled(FALSE); |
| 1648 return 0; | 1653 return 0; |
| 1649 } | 1654 } |
| 1650 | 1655 |
| 1651 RECT* client_rect = mode ? | 1656 RECT* client_rect = mode ? |
| 1652 &(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) : | 1657 &(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) : |
| 1653 reinterpret_cast<RECT*>(l_param); | 1658 reinterpret_cast<RECT*>(l_param); |
| 1654 client_rect->left += insets.left(); | 1659 client_rect->left += insets.left(); |
| 1655 client_rect->top += insets.top(); | 1660 client_rect->top += insets.top(); |
| 1656 client_rect->bottom -= insets.bottom(); | 1661 client_rect->bottom -= insets.bottom(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 } | 1726 } |
| 1722 | 1727 |
| 1723 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { | 1728 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { |
| 1724 if (!GetWidget()->non_client_view()) { | 1729 if (!GetWidget()->non_client_view()) { |
| 1725 SetMsgHandled(FALSE); | 1730 SetMsgHandled(FALSE); |
| 1726 return 0; | 1731 return 0; |
| 1727 } | 1732 } |
| 1728 | 1733 |
| 1729 // If the DWM is rendering the window controls, we need to give the DWM's | 1734 // If the DWM is rendering the window controls, we need to give the DWM's |
| 1730 // default window procedure first chance to handle hit testing. | 1735 // default window procedure first chance to handle hit testing. |
| 1731 if (GetWidget()->ShouldUseNativeFrame()) { | 1736 if (!remove_standard_frame_ && GetWidget()->ShouldUseNativeFrame()) { |
| 1732 LRESULT result; | 1737 LRESULT result; |
| 1733 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, | 1738 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, |
| 1734 MAKELPARAM(point.x, point.y), &result)) { | 1739 MAKELPARAM(point.x, point.y), &result)) { |
| 1735 return result; | 1740 return result; |
| 1736 } | 1741 } |
| 1737 } | 1742 } |
| 1738 | 1743 |
| 1739 // First, give the NonClientView a chance to test the point to see if it | 1744 // First, give the NonClientView a chance to test the point to see if it |
| 1740 // provides any of the non-client area. | 1745 // provides any of the non-client area. |
| 1741 POINT temp = point; | 1746 POINT temp = point; |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2087 SetMsgHandled(TRUE); | 2092 SetMsgHandled(TRUE); |
| 2088 return; | 2093 return; |
| 2089 } | 2094 } |
| 2090 | 2095 |
| 2091 SetMsgHandled(FALSE); | 2096 SetMsgHandled(FALSE); |
| 2092 } | 2097 } |
| 2093 | 2098 |
| 2094 void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) { | 2099 void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) { |
| 2095 if (DidClientAreaSizeChange(window_pos)) | 2100 if (DidClientAreaSizeChange(window_pos)) |
| 2096 ClientAreaSizeChanged(); | 2101 ClientAreaSizeChanged(); |
| 2102 if (remove_standard_frame_ && window_pos->flags & SWP_FRAMECHANGED) |
| 2103 UpdateDWMFrame(); |
| 2097 if (window_pos->flags & SWP_SHOWWINDOW) | 2104 if (window_pos->flags & SWP_SHOWWINDOW) |
| 2098 delegate_->OnNativeWidgetVisibilityChanged(true); | 2105 delegate_->OnNativeWidgetVisibilityChanged(true); |
| 2099 else if (window_pos->flags & SWP_HIDEWINDOW) | 2106 else if (window_pos->flags & SWP_HIDEWINDOW) |
| 2100 delegate_->OnNativeWidgetVisibilityChanged(false); | 2107 delegate_->OnNativeWidgetVisibilityChanged(false); |
| 2101 SetMsgHandled(FALSE); | 2108 SetMsgHandled(FALSE); |
| 2102 } | 2109 } |
| 2103 | 2110 |
| 2104 void NativeWidgetWin::OnFinalMessage(HWND window) { | 2111 void NativeWidgetWin::OnFinalMessage(HWND window) { |
| 2105 // We don't destroy props in WM_DESTROY as we may still get messages after | 2112 // We don't destroy props in WM_DESTROY as we may still get messages after |
| 2106 // WM_DESTROY that assume the properties are still valid (such as WM_CLOSE). | 2113 // WM_DESTROY that assume the properties are still valid (such as WM_CLOSE). |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2296 break; | 2303 break; |
| 2297 default: | 2304 default: |
| 2298 NOTREACHED(); | 2305 NOTREACHED(); |
| 2299 } | 2306 } |
| 2300 | 2307 |
| 2301 set_initial_class_style(class_style); | 2308 set_initial_class_style(class_style); |
| 2302 set_window_style(window_style() | style); | 2309 set_window_style(window_style() | style); |
| 2303 set_window_ex_style(window_ex_style() | ex_style); | 2310 set_window_ex_style(window_ex_style() | ex_style); |
| 2304 | 2311 |
| 2305 has_non_client_view_ = Widget::RequiresNonClientView(params.type); | 2312 has_non_client_view_ = Widget::RequiresNonClientView(params.type); |
| 2313 remove_standard_frame_ = params.remove_standard_frame; |
| 2306 } | 2314 } |
| 2307 | 2315 |
| 2308 void NativeWidgetWin::RedrawInvalidRect() { | 2316 void NativeWidgetWin::RedrawInvalidRect() { |
| 2309 if (!use_layered_buffer_) { | 2317 if (!use_layered_buffer_) { |
| 2310 RECT r = { 0, 0, 0, 0 }; | 2318 RECT r = { 0, 0, 0, 0 }; |
| 2311 if (GetUpdateRect(hwnd(), &r, FALSE) && !IsRectEmpty(&r)) { | 2319 if (GetUpdateRect(hwnd(), &r, FALSE) && !IsRectEmpty(&r)) { |
| 2312 RedrawWindow(hwnd(), &r, NULL, | 2320 RedrawWindow(hwnd(), &r, NULL, |
| 2313 RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); | 2321 RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); |
| 2314 } | 2322 } |
| 2315 } | 2323 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2369 GetWindowRect(&r); | 2377 GetWindowRect(&r); |
| 2370 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), | 2378 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), |
| 2371 std::max(0, static_cast<int>(r.bottom - r.top))); | 2379 std::max(0, static_cast<int>(r.bottom - r.top))); |
| 2372 if (compositor_.get()) | 2380 if (compositor_.get()) |
| 2373 compositor_->WidgetSizeChanged(s); | 2381 compositor_->WidgetSizeChanged(s); |
| 2374 delegate_->OnNativeWidgetSizeChanged(s); | 2382 delegate_->OnNativeWidgetSizeChanged(s); |
| 2375 if (use_layered_buffer_) | 2383 if (use_layered_buffer_) |
| 2376 layered_window_contents_.reset(new gfx::CanvasSkia(s, false)); | 2384 layered_window_contents_.reset(new gfx::CanvasSkia(s, false)); |
| 2377 } | 2385 } |
| 2378 | 2386 |
| 2387 void NativeWidgetWin::UpdateDWMFrame() { |
| 2388 MARGINS m = {10, 10, 10, 10}; |
| 2389 DwmExtendFrameIntoClientArea(GetNativeView(), &m); |
| 2390 } |
| 2391 |
| 2379 void NativeWidgetWin::ResetWindowRegion(bool force) { | 2392 void NativeWidgetWin::ResetWindowRegion(bool force) { |
| 2380 // A native frame uses the native window region, and we don't want to mess | 2393 // A native frame uses the native window region, and we don't want to mess |
| 2381 // with it. | 2394 // with it. |
| 2382 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) { | 2395 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) { |
| 2383 if (force) | 2396 if (force) |
| 2384 SetWindowRgn(NULL, TRUE); | 2397 SetWindowRgn(NULL, TRUE); |
| 2385 return; | 2398 return; |
| 2386 } | 2399 } |
| 2387 | 2400 |
| 2388 // Changing the window region is going to force a paint. Only change the | 2401 // Changing the window region is going to force a paint. Only change the |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2608 return (GetKeyState(VK_LBUTTON) & 0x80) || | 2621 return (GetKeyState(VK_LBUTTON) & 0x80) || |
| 2609 (GetKeyState(VK_RBUTTON) & 0x80) || | 2622 (GetKeyState(VK_RBUTTON) & 0x80) || |
| 2610 (GetKeyState(VK_MBUTTON) & 0x80) || | 2623 (GetKeyState(VK_MBUTTON) & 0x80) || |
| 2611 (GetKeyState(VK_XBUTTON1) & 0x80) || | 2624 (GetKeyState(VK_XBUTTON1) & 0x80) || |
| 2612 (GetKeyState(VK_XBUTTON2) & 0x80); | 2625 (GetKeyState(VK_XBUTTON2) & 0x80); |
| 2613 } | 2626 } |
| 2614 | 2627 |
| 2615 } // namespace internal | 2628 } // namespace internal |
| 2616 | 2629 |
| 2617 } // namespace views | 2630 } // namespace views |
| OLD | NEW |