Chromium Code Reviews| 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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 543 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 544 // We need to toggle the rendering policy of the DWM/glass frame as we | 544 // We need to toggle the rendering policy of the DWM/glass frame as we |
| 545 // change from opaque to glass. "Non client rendering enabled" means that | 545 // change from opaque to glass. "Non client rendering enabled" means that |
| 546 // the DWM's glass non-client rendering is enabled, which is why | 546 // the DWM's glass non-client rendering is enabled, which is why |
| 547 // DWMNCRP_ENABLED is used for the native frame case. _DISABLED means the | 547 // DWMNCRP_ENABLED is used for the native frame case. _DISABLED means the |
| 548 // DWM doesn't render glass, and so is used in the custom frame case. | 548 // DWM doesn't render glass, and so is used in the custom frame case. |
| 549 DWMNCRENDERINGPOLICY policy = GetWidget()->ShouldUseNativeFrame() ? | 549 DWMNCRENDERINGPOLICY policy = GetWidget()->ShouldUseNativeFrame() ? |
| 550 DWMNCRP_ENABLED : DWMNCRP_DISABLED; | 550 DWMNCRP_ENABLED : DWMNCRP_DISABLED; |
| 551 DwmSetWindowAttribute(GetNativeView(), DWMWA_NCRENDERING_POLICY, | 551 DwmSetWindowAttribute(GetNativeView(), DWMWA_NCRENDERING_POLICY, |
| 552 &policy, sizeof(DWMNCRENDERINGPOLICY)); | 552 &policy, sizeof(DWMNCRENDERINGPOLICY)); |
| 553 | |
| 554 if (remove_standard_frame_) { | |
| 555 UpdateDWMFrame(); | |
|
Ben Goodger (Google)
2012/02/07 20:18:57
no braces on single line if
jeremya
2012/02/08 00:35:16
Done.
| |
| 556 } | |
| 553 } | 557 } |
| 554 | 558 |
| 555 // Send a frame change notification, since the non-client metrics have | 559 // Send a frame change notification, since the non-client metrics have |
| 556 // changed. | 560 // changed. |
| 557 SendFrameChanged(GetNativeView()); | 561 SendFrameChanged(GetNativeView()); |
| 558 | 562 |
| 559 // Update the non-client view with the correct frame view for the active frame | 563 // Update the non-client view with the correct frame view for the active frame |
| 560 // type. | 564 // type. |
| 561 GetWidget()->non_client_view()->UpdateFrame(); | 565 GetWidget()->non_client_view()->UpdateFrame(); |
| 562 | 566 |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1285 | 1289 |
| 1286 // This message initializes the window so that focus border are shown for | 1290 // This message initializes the window so that focus border are shown for |
| 1287 // windows. | 1291 // windows. |
| 1288 SendMessage( | 1292 SendMessage( |
| 1289 hwnd(), WM_CHANGEUISTATE, MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); | 1293 hwnd(), WM_CHANGEUISTATE, MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); |
| 1290 | 1294 |
| 1291 // Bug 964884: detach the IME attached to this window. | 1295 // Bug 964884: detach the IME attached to this window. |
| 1292 // We should attach IMEs only when we need to input CJK strings. | 1296 // We should attach IMEs only when we need to input CJK strings. |
| 1293 ImmAssociateContextEx(hwnd(), NULL, 0); | 1297 ImmAssociateContextEx(hwnd(), NULL, 0); |
| 1294 | 1298 |
| 1299 if (remove_standard_frame_) { | |
| 1300 SendFrameChanged(GetNativeView()); | |
| 1301 UpdateDWMFrame(); | |
| 1302 } | |
| 1303 | |
| 1295 // We need to allow the delegate to size its contents since the window may not | 1304 // 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 | 1305 // receive a size notification when its initial bounds are specified at window |
| 1297 // creation time. | 1306 // creation time. |
| 1298 ClientAreaSizeChanged(); | 1307 ClientAreaSizeChanged(); |
| 1299 | 1308 |
| 1300 delegate_->OnNativeWidgetCreated(); | 1309 delegate_->OnNativeWidgetCreated(); |
| 1301 | 1310 |
| 1302 // Get access to a modifiable copy of the system menu. | 1311 // Get access to a modifiable copy of the system menu. |
| 1303 GetSystemMenu(hwnd(), false); | 1312 GetSystemMenu(hwnd(), false); |
| 1304 return 0; | 1313 return 0; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1634 return TRUE; | 1643 return TRUE; |
| 1635 } | 1644 } |
| 1636 | 1645 |
| 1637 return DefWindowProcWithRedrawLock(WM_NCACTIVATE, | 1646 return DefWindowProcWithRedrawLock(WM_NCACTIVATE, |
| 1638 inactive_rendering_disabled || active, 0); | 1647 inactive_rendering_disabled || active, 0); |
| 1639 } | 1648 } |
| 1640 | 1649 |
| 1641 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { | 1650 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { |
| 1642 // We only override the default handling if we need to specify a custom | 1651 // 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 | 1652 // 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. | 1653 // custom width, but in fullscreen mode or when the NonClientFrameView |
| 1654 // requests it, we want a custom width of 0. | |
| 1645 gfx::Insets insets = GetClientAreaInsets(); | 1655 gfx::Insets insets = GetClientAreaInsets(); |
| 1646 if (insets.empty() && !IsFullscreen()) { | 1656 if (insets.empty() && !IsFullscreen() && |
| 1657 !(mode && remove_standard_frame_)) { | |
| 1647 SetMsgHandled(FALSE); | 1658 SetMsgHandled(FALSE); |
| 1648 return 0; | 1659 return 0; |
| 1649 } | 1660 } |
| 1650 | 1661 |
| 1651 RECT* client_rect = mode ? | 1662 RECT* client_rect = mode ? |
| 1652 &(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) : | 1663 &(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) : |
| 1653 reinterpret_cast<RECT*>(l_param); | 1664 reinterpret_cast<RECT*>(l_param); |
| 1654 client_rect->left += insets.left(); | 1665 client_rect->left += insets.left(); |
| 1655 client_rect->top += insets.top(); | 1666 client_rect->top += insets.top(); |
| 1656 client_rect->bottom -= insets.bottom(); | 1667 client_rect->bottom -= insets.bottom(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1721 } | 1732 } |
| 1722 | 1733 |
| 1723 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { | 1734 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { |
| 1724 if (!GetWidget()->non_client_view()) { | 1735 if (!GetWidget()->non_client_view()) { |
| 1725 SetMsgHandled(FALSE); | 1736 SetMsgHandled(FALSE); |
| 1726 return 0; | 1737 return 0; |
| 1727 } | 1738 } |
| 1728 | 1739 |
| 1729 // If the DWM is rendering the window controls, we need to give the DWM's | 1740 // 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. | 1741 // default window procedure first chance to handle hit testing. |
| 1731 if (GetWidget()->ShouldUseNativeFrame()) { | 1742 if (!remove_standard_frame_ && GetWidget()->ShouldUseNativeFrame()) { |
| 1732 LRESULT result; | 1743 LRESULT result; |
| 1733 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, | 1744 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, |
| 1734 MAKELPARAM(point.x, point.y), &result)) { | 1745 MAKELPARAM(point.x, point.y), &result)) { |
| 1735 return result; | 1746 return result; |
| 1736 } | 1747 } |
| 1737 } | 1748 } |
| 1738 | 1749 |
| 1739 // First, give the NonClientView a chance to test the point to see if it | 1750 // First, give the NonClientView a chance to test the point to see if it |
| 1740 // provides any of the non-client area. | 1751 // provides any of the non-client area. |
| 1741 POINT temp = point; | 1752 POINT temp = point; |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2296 break; | 2307 break; |
| 2297 default: | 2308 default: |
| 2298 NOTREACHED(); | 2309 NOTREACHED(); |
| 2299 } | 2310 } |
| 2300 | 2311 |
| 2301 set_initial_class_style(class_style); | 2312 set_initial_class_style(class_style); |
| 2302 set_window_style(window_style() | style); | 2313 set_window_style(window_style() | style); |
| 2303 set_window_ex_style(window_ex_style() | ex_style); | 2314 set_window_ex_style(window_ex_style() | ex_style); |
| 2304 | 2315 |
| 2305 has_non_client_view_ = Widget::RequiresNonClientView(params.type); | 2316 has_non_client_view_ = Widget::RequiresNonClientView(params.type); |
| 2317 remove_standard_frame_ = params.remove_standard_frame; | |
| 2306 } | 2318 } |
| 2307 | 2319 |
| 2308 void NativeWidgetWin::RedrawInvalidRect() { | 2320 void NativeWidgetWin::RedrawInvalidRect() { |
| 2309 if (!use_layered_buffer_) { | 2321 if (!use_layered_buffer_) { |
| 2310 RECT r = { 0, 0, 0, 0 }; | 2322 RECT r = { 0, 0, 0, 0 }; |
| 2311 if (GetUpdateRect(hwnd(), &r, FALSE) && !IsRectEmpty(&r)) { | 2323 if (GetUpdateRect(hwnd(), &r, FALSE) && !IsRectEmpty(&r)) { |
| 2312 RedrawWindow(hwnd(), &r, NULL, | 2324 RedrawWindow(hwnd(), &r, NULL, |
| 2313 RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); | 2325 RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); |
| 2314 } | 2326 } |
| 2315 } | 2327 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2369 GetWindowRect(&r); | 2381 GetWindowRect(&r); |
| 2370 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), | 2382 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), |
| 2371 std::max(0, static_cast<int>(r.bottom - r.top))); | 2383 std::max(0, static_cast<int>(r.bottom - r.top))); |
| 2372 if (compositor_.get()) | 2384 if (compositor_.get()) |
| 2373 compositor_->WidgetSizeChanged(s); | 2385 compositor_->WidgetSizeChanged(s); |
| 2374 delegate_->OnNativeWidgetSizeChanged(s); | 2386 delegate_->OnNativeWidgetSizeChanged(s); |
| 2375 if (use_layered_buffer_) | 2387 if (use_layered_buffer_) |
| 2376 layered_window_contents_.reset(new gfx::CanvasSkia(s, false)); | 2388 layered_window_contents_.reset(new gfx::CanvasSkia(s, false)); |
| 2377 } | 2389 } |
| 2378 | 2390 |
| 2391 void NativeWidgetWin::UpdateDWMFrame() { | |
| 2392 MARGINS m = {10, 10, 10, 10}; | |
| 2393 DwmExtendFrameIntoClientArea(GetNativeView(), &m); | |
|
Ben Goodger (Google)
2012/02/07 20:18:57
I understand the NCCALCSIZE handling... but what i
jeremya
2012/02/08 00:35:16
Without this, Windows doesn't draw any glass, whic
| |
| 2394 } | |
| 2395 | |
| 2379 void NativeWidgetWin::ResetWindowRegion(bool force) { | 2396 void NativeWidgetWin::ResetWindowRegion(bool force) { |
| 2380 // A native frame uses the native window region, and we don't want to mess | 2397 // A native frame uses the native window region, and we don't want to mess |
| 2381 // with it. | 2398 // with it. |
| 2382 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) { | 2399 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) { |
| 2383 if (force) | 2400 if (force) |
| 2384 SetWindowRgn(NULL, TRUE); | 2401 SetWindowRgn(NULL, TRUE); |
| 2385 return; | 2402 return; |
| 2386 } | 2403 } |
| 2387 | 2404 |
| 2388 // Changing the window region is going to force a paint. Only change the | 2405 // 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) || | 2625 return (GetKeyState(VK_LBUTTON) & 0x80) || |
| 2609 (GetKeyState(VK_RBUTTON) & 0x80) || | 2626 (GetKeyState(VK_RBUTTON) & 0x80) || |
| 2610 (GetKeyState(VK_MBUTTON) & 0x80) || | 2627 (GetKeyState(VK_MBUTTON) & 0x80) || |
| 2611 (GetKeyState(VK_XBUTTON1) & 0x80) || | 2628 (GetKeyState(VK_XBUTTON1) & 0x80) || |
| 2612 (GetKeyState(VK_XBUTTON2) & 0x80); | 2629 (GetKeyState(VK_XBUTTON2) & 0x80); |
| 2613 } | 2630 } |
| 2614 | 2631 |
| 2615 } // namespace internal | 2632 } // namespace internal |
| 2616 | 2633 |
| 2617 } // namespace views | 2634 } // namespace views |
| OLD | NEW |