| 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 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 | 1278 |
| 1279 // This message initializes the window so that focus border are shown for | 1279 // This message initializes the window so that focus border are shown for |
| 1280 // windows. | 1280 // windows. |
| 1281 SendMessage( | 1281 SendMessage( |
| 1282 hwnd(), WM_CHANGEUISTATE, MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); | 1282 hwnd(), WM_CHANGEUISTATE, MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); |
| 1283 | 1283 |
| 1284 // Bug 964884: detach the IME attached to this window. | 1284 // Bug 964884: detach the IME attached to this window. |
| 1285 // We should attach IMEs only when we need to input CJK strings. | 1285 // We should attach IMEs only when we need to input CJK strings. |
| 1286 ImmAssociateContextEx(hwnd(), NULL, 0); | 1286 ImmAssociateContextEx(hwnd(), NULL, 0); |
| 1287 | 1287 |
| 1288 if (remove_standard_frame_) |
| 1289 SendFrameChanged(GetNativeView()); |
| 1290 |
| 1288 // We need to allow the delegate to size its contents since the window may not | 1291 // We need to allow the delegate to size its contents since the window may not |
| 1289 // receive a size notification when its initial bounds are specified at window | 1292 // receive a size notification when its initial bounds are specified at window |
| 1290 // creation time. | 1293 // creation time. |
| 1291 ClientAreaSizeChanged(); | 1294 ClientAreaSizeChanged(); |
| 1292 | 1295 |
| 1293 delegate_->OnNativeWidgetCreated(); | 1296 delegate_->OnNativeWidgetCreated(); |
| 1294 | 1297 |
| 1295 // Get access to a modifiable copy of the system menu. | 1298 // Get access to a modifiable copy of the system menu. |
| 1296 GetSystemMenu(hwnd(), false); | 1299 GetSystemMenu(hwnd(), false); |
| 1297 return 0; | 1300 return 0; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 return TRUE; | 1630 return TRUE; |
| 1628 } | 1631 } |
| 1629 | 1632 |
| 1630 return DefWindowProcWithRedrawLock(WM_NCACTIVATE, | 1633 return DefWindowProcWithRedrawLock(WM_NCACTIVATE, |
| 1631 inactive_rendering_disabled || active, 0); | 1634 inactive_rendering_disabled || active, 0); |
| 1632 } | 1635 } |
| 1633 | 1636 |
| 1634 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { | 1637 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { |
| 1635 // We only override the default handling if we need to specify a custom | 1638 // We only override the default handling if we need to specify a custom |
| 1636 // non-client edge width. Note that in most cases "no insets" means no | 1639 // non-client edge width. Note that in most cases "no insets" means no |
| 1637 // custom width, but in fullscreen mode we want a custom width of 0. | 1640 // custom width, but in fullscreen mode or when the NonClientFrameView |
| 1641 // requests it, we want a custom width of 0. |
| 1638 gfx::Insets insets = GetClientAreaInsets(); | 1642 gfx::Insets insets = GetClientAreaInsets(); |
| 1639 if (insets.empty() && !IsFullscreen()) { | 1643 if (insets.empty() && !IsFullscreen() && |
| 1644 !(mode && remove_standard_frame_)) { |
| 1640 SetMsgHandled(FALSE); | 1645 SetMsgHandled(FALSE); |
| 1641 return 0; | 1646 return 0; |
| 1642 } | 1647 } |
| 1643 | 1648 |
| 1644 RECT* client_rect = mode ? | 1649 RECT* client_rect = mode ? |
| 1645 &(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) : | 1650 &(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) : |
| 1646 reinterpret_cast<RECT*>(l_param); | 1651 reinterpret_cast<RECT*>(l_param); |
| 1647 client_rect->left += insets.left(); | 1652 client_rect->left += insets.left(); |
| 1648 client_rect->top += insets.top(); | 1653 client_rect->top += insets.top(); |
| 1649 client_rect->bottom -= insets.bottom(); | 1654 client_rect->bottom -= insets.bottom(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 } | 1719 } |
| 1715 | 1720 |
| 1716 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { | 1721 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { |
| 1717 if (!GetWidget()->non_client_view()) { | 1722 if (!GetWidget()->non_client_view()) { |
| 1718 SetMsgHandled(FALSE); | 1723 SetMsgHandled(FALSE); |
| 1719 return 0; | 1724 return 0; |
| 1720 } | 1725 } |
| 1721 | 1726 |
| 1722 // If the DWM is rendering the window controls, we need to give the DWM's | 1727 // If the DWM is rendering the window controls, we need to give the DWM's |
| 1723 // default window procedure first chance to handle hit testing. | 1728 // default window procedure first chance to handle hit testing. |
| 1724 if (GetWidget()->ShouldUseNativeFrame()) { | 1729 if (!remove_standard_frame_ && GetWidget()->ShouldUseNativeFrame()) { |
| 1725 LRESULT result; | 1730 LRESULT result; |
| 1726 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, | 1731 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, |
| 1727 MAKELPARAM(point.x, point.y), &result)) { | 1732 MAKELPARAM(point.x, point.y), &result)) { |
| 1728 return result; | 1733 return result; |
| 1729 } | 1734 } |
| 1730 } | 1735 } |
| 1731 | 1736 |
| 1732 // First, give the NonClientView a chance to test the point to see if it | 1737 // First, give the NonClientView a chance to test the point to see if it |
| 1733 // provides any of the non-client area. | 1738 // provides any of the non-client area. |
| 1734 POINT temp = point; | 1739 POINT temp = point; |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 SetMsgHandled(TRUE); | 2085 SetMsgHandled(TRUE); |
| 2081 return; | 2086 return; |
| 2082 } | 2087 } |
| 2083 | 2088 |
| 2084 SetMsgHandled(FALSE); | 2089 SetMsgHandled(FALSE); |
| 2085 } | 2090 } |
| 2086 | 2091 |
| 2087 void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) { | 2092 void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) { |
| 2088 if (DidClientAreaSizeChange(window_pos)) | 2093 if (DidClientAreaSizeChange(window_pos)) |
| 2089 ClientAreaSizeChanged(); | 2094 ClientAreaSizeChanged(); |
| 2095 if (remove_standard_frame_ && window_pos->flags & SWP_FRAMECHANGED && |
| 2096 IsAeroGlassEnabled()) |
| 2097 UpdateDWMFrame(); |
| 2090 if (window_pos->flags & SWP_SHOWWINDOW) | 2098 if (window_pos->flags & SWP_SHOWWINDOW) |
| 2091 delegate_->OnNativeWidgetVisibilityChanged(true); | 2099 delegate_->OnNativeWidgetVisibilityChanged(true); |
| 2092 else if (window_pos->flags & SWP_HIDEWINDOW) | 2100 else if (window_pos->flags & SWP_HIDEWINDOW) |
| 2093 delegate_->OnNativeWidgetVisibilityChanged(false); | 2101 delegate_->OnNativeWidgetVisibilityChanged(false); |
| 2094 SetMsgHandled(FALSE); | 2102 SetMsgHandled(FALSE); |
| 2095 } | 2103 } |
| 2096 | 2104 |
| 2097 void NativeWidgetWin::OnFinalMessage(HWND window) { | 2105 void NativeWidgetWin::OnFinalMessage(HWND window) { |
| 2098 // We don't destroy props in WM_DESTROY as we may still get messages after | 2106 // We don't destroy props in WM_DESTROY as we may still get messages after |
| 2099 // WM_DESTROY that assume the properties are still valid (such as WM_CLOSE). | 2107 // 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... |
| 2289 break; | 2297 break; |
| 2290 default: | 2298 default: |
| 2291 NOTREACHED(); | 2299 NOTREACHED(); |
| 2292 } | 2300 } |
| 2293 | 2301 |
| 2294 set_initial_class_style(class_style); | 2302 set_initial_class_style(class_style); |
| 2295 set_window_style(window_style() | style); | 2303 set_window_style(window_style() | style); |
| 2296 set_window_ex_style(window_ex_style() | ex_style); | 2304 set_window_ex_style(window_ex_style() | ex_style); |
| 2297 | 2305 |
| 2298 has_non_client_view_ = Widget::RequiresNonClientView(params.type); | 2306 has_non_client_view_ = Widget::RequiresNonClientView(params.type); |
| 2307 remove_standard_frame_ = params.remove_standard_frame; |
| 2299 } | 2308 } |
| 2300 | 2309 |
| 2301 void NativeWidgetWin::RedrawInvalidRect() { | 2310 void NativeWidgetWin::RedrawInvalidRect() { |
| 2302 if (!use_layered_buffer_) { | 2311 if (!use_layered_buffer_) { |
| 2303 RECT r = { 0, 0, 0, 0 }; | 2312 RECT r = { 0, 0, 0, 0 }; |
| 2304 if (GetUpdateRect(hwnd(), &r, FALSE) && !IsRectEmpty(&r)) { | 2313 if (GetUpdateRect(hwnd(), &r, FALSE) && !IsRectEmpty(&r)) { |
| 2305 RedrawWindow(hwnd(), &r, NULL, | 2314 RedrawWindow(hwnd(), &r, NULL, |
| 2306 RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); | 2315 RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); |
| 2307 } | 2316 } |
| 2308 } | 2317 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2360 GetClientRect(&r); | 2369 GetClientRect(&r); |
| 2361 else | 2370 else |
| 2362 GetWindowRect(&r); | 2371 GetWindowRect(&r); |
| 2363 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), | 2372 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), |
| 2364 std::max(0, static_cast<int>(r.bottom - r.top))); | 2373 std::max(0, static_cast<int>(r.bottom - r.top))); |
| 2365 delegate_->OnNativeWidgetSizeChanged(s); | 2374 delegate_->OnNativeWidgetSizeChanged(s); |
| 2366 if (use_layered_buffer_) | 2375 if (use_layered_buffer_) |
| 2367 layered_window_contents_.reset(new gfx::CanvasSkia(s, false)); | 2376 layered_window_contents_.reset(new gfx::CanvasSkia(s, false)); |
| 2368 } | 2377 } |
| 2369 | 2378 |
| 2379 void NativeWidgetWin::UpdateDWMFrame() { |
| 2380 MARGINS m = {10, 10, 10, 10}; |
| 2381 DwmExtendFrameIntoClientArea(GetNativeView(), &m); |
| 2382 } |
| 2383 |
| 2370 void NativeWidgetWin::ResetWindowRegion(bool force) { | 2384 void NativeWidgetWin::ResetWindowRegion(bool force) { |
| 2371 // A native frame uses the native window region, and we don't want to mess | 2385 // A native frame uses the native window region, and we don't want to mess |
| 2372 // with it. | 2386 // with it. |
| 2373 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) { | 2387 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) { |
| 2374 if (force) | 2388 if (force) |
| 2375 SetWindowRgn(NULL, TRUE); | 2389 SetWindowRgn(NULL, TRUE); |
| 2376 return; | 2390 return; |
| 2377 } | 2391 } |
| 2378 | 2392 |
| 2379 // Changing the window region is going to force a paint. Only change the | 2393 // 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... |
| 2599 return (GetKeyState(VK_LBUTTON) & 0x80) || | 2613 return (GetKeyState(VK_LBUTTON) & 0x80) || |
| 2600 (GetKeyState(VK_RBUTTON) & 0x80) || | 2614 (GetKeyState(VK_RBUTTON) & 0x80) || |
| 2601 (GetKeyState(VK_MBUTTON) & 0x80) || | 2615 (GetKeyState(VK_MBUTTON) & 0x80) || |
| 2602 (GetKeyState(VK_XBUTTON1) & 0x80) || | 2616 (GetKeyState(VK_XBUTTON1) & 0x80) || |
| 2603 (GetKeyState(VK_XBUTTON2) & 0x80); | 2617 (GetKeyState(VK_XBUTTON2) & 0x80); |
| 2604 } | 2618 } |
| 2605 | 2619 |
| 2606 } // namespace internal | 2620 } // namespace internal |
| 2607 | 2621 |
| 2608 } // namespace views | 2622 } // namespace views |
| OLD | NEW |