Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: ui/views/widget/native_widget_win.cc

Issue 9254046: Custom frame UI for platform apps on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rearchitect to use NonClientFrameView Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/native_widget_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 gfx::Rect bounds; 807 gfx::Rect bounds;
808 GetWindowPlacement(&bounds, NULL); 808 GetWindowPlacement(&bounds, NULL);
809 return bounds; 809 return bounds;
810 } 810 }
811 811
812 void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) { 812 void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) {
813 LONG style = GetWindowLong(GWL_STYLE); 813 LONG style = GetWindowLong(GWL_STYLE);
814 if (style & WS_MAXIMIZE) 814 if (style & WS_MAXIMIZE)
815 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE); 815 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE);
816 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(), 816 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(),
817 SWP_NOACTIVATE | SWP_NOZORDER); 817 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED);
jeremya 2012/02/06 00:58:32 I added this to make the call to SetInitialBounds(
818 } 818 }
819 819
820 void NativeWidgetWin::SetSize(const gfx::Size& size) { 820 void NativeWidgetWin::SetSize(const gfx::Size& size) {
821 SetWindowPos(NULL, 0, 0, size.width(), size.height(), 821 SetWindowPos(NULL, 0, 0, size.width(), size.height(),
822 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE); 822 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
823 } 823 }
824 824
825 void NativeWidgetWin::StackAbove(gfx::NativeView native_view) { 825 void NativeWidgetWin::StackAbove(gfx::NativeView native_view) {
826 SetWindowPos(native_view, 0, 0, 0, 0, 826 SetWindowPos(native_view, 0, 0, 0, 0,
827 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); 827 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 return TRUE; 1634 return TRUE;
1635 } 1635 }
1636 1636
1637 return DefWindowProcWithRedrawLock(WM_NCACTIVATE, 1637 return DefWindowProcWithRedrawLock(WM_NCACTIVATE,
1638 inactive_rendering_disabled || active, 0); 1638 inactive_rendering_disabled || active, 0);
1639 } 1639 }
1640 1640
1641 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { 1641 LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) {
1642 // We only override the default handling if we need to specify a custom 1642 // 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 1643 // 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. 1644 // custom width, but in fullscreen mode or when the NonClientFrameView
1645 // requests it, we want a custom width of 0.
1645 gfx::Insets insets = GetClientAreaInsets(); 1646 gfx::Insets insets = GetClientAreaInsets();
1646 if (insets.empty() && !IsFullscreen()) { 1647 if (insets.empty() && !IsFullscreen() &&
1648 !(mode && ShouldRemoveStandardFrame())) {
1647 SetMsgHandled(FALSE); 1649 SetMsgHandled(FALSE);
1648 return 0; 1650 return 0;
1649 } 1651 }
1650 1652
1651 RECT* client_rect = mode ? 1653 RECT* client_rect = mode ?
1652 &(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) : 1654 &(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) :
1653 reinterpret_cast<RECT*>(l_param); 1655 reinterpret_cast<RECT*>(l_param);
1654 client_rect->left += insets.left(); 1656 client_rect->left += insets.left();
1655 client_rect->top += insets.top(); 1657 client_rect->top += insets.top();
1656 client_rect->bottom -= insets.bottom(); 1658 client_rect->bottom -= insets.bottom();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 } 1723 }
1722 1724
1723 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { 1725 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) {
1724 if (!GetWidget()->non_client_view()) { 1726 if (!GetWidget()->non_client_view()) {
1725 SetMsgHandled(FALSE); 1727 SetMsgHandled(FALSE);
1726 return 0; 1728 return 0;
1727 } 1729 }
1728 1730
1729 // If the DWM is rendering the window controls, we need to give the DWM's 1731 // 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. 1732 // default window procedure first chance to handle hit testing.
1731 if (GetWidget()->ShouldUseNativeFrame()) { 1733 if (!ShouldRemoveStandardFrame() && GetWidget()->ShouldUseNativeFrame()) {
1732 LRESULT result; 1734 LRESULT result;
1733 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, 1735 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0,
1734 MAKELPARAM(point.x, point.y), &result)) { 1736 MAKELPARAM(point.x, point.y), &result)) {
1735 return result; 1737 return result;
1736 } 1738 }
1737 } 1739 }
1738 1740
1739 // First, give the NonClientView a chance to test the point to see if it 1741 // First, give the NonClientView a chance to test the point to see if it
1740 // provides any of the non-client area. 1742 // provides any of the non-client area.
1741 POINT temp = point; 1743 POINT temp = point;
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2354 SetWindowLong(GWL_STYLE, GetWindowLong(GWL_STYLE) | WS_VISIBLE); 2356 SetWindowLong(GWL_STYLE, GetWindowLong(GWL_STYLE) | WS_VISIBLE);
2355 lock_updates_count_ = 0; 2357 lock_updates_count_ = 0;
2356 } 2358 }
2357 } 2359 }
2358 2360
2359 bool NativeWidgetWin::WidgetSizeIsClientSize() const { 2361 bool NativeWidgetWin::WidgetSizeIsClientSize() const {
2360 const Widget* widget = GetWidget()->GetTopLevelWidget(); 2362 const Widget* widget = GetWidget()->GetTopLevelWidget();
2361 return IsZoomed() || (widget && widget->ShouldUseNativeFrame()); 2363 return IsZoomed() || (widget && widget->ShouldUseNativeFrame());
2362 } 2364 }
2363 2365
2366 bool NativeWidgetWin::ShouldRemoveStandardFrame() const {
2367 NonClientFrameView* frame_view = GetWidget()->non_client_view()->frame_view();
jeremya 2012/02/06 00:58:32 I've hit some problems (hopefully none of which re
2368 gfx::Rect client_area = frame_view->GetBoundsForClientView();
2369 gfx::Rect window_area =
2370 frame_view->GetWindowBoundsForClientBounds(client_area);
2371 return client_area == window_area;
2372 }
2373
2364 void NativeWidgetWin::ClientAreaSizeChanged() { 2374 void NativeWidgetWin::ClientAreaSizeChanged() {
2365 RECT r; 2375 RECT r;
2366 if (WidgetSizeIsClientSize()) 2376 if (WidgetSizeIsClientSize())
2367 GetClientRect(&r); 2377 GetClientRect(&r);
2368 else 2378 else
2369 GetWindowRect(&r); 2379 GetWindowRect(&r);
2370 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), 2380 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)),
2371 std::max(0, static_cast<int>(r.bottom - r.top))); 2381 std::max(0, static_cast<int>(r.bottom - r.top)));
2372 if (compositor_.get()) 2382 if (compositor_.get())
2373 compositor_->WidgetSizeChanged(s); 2383 compositor_->WidgetSizeChanged(s);
2374 delegate_->OnNativeWidgetSizeChanged(s); 2384 delegate_->OnNativeWidgetSizeChanged(s);
2375 if (use_layered_buffer_) 2385 if (use_layered_buffer_)
2376 layered_window_contents_.reset(new gfx::CanvasSkia(s, false)); 2386 layered_window_contents_.reset(new gfx::CanvasSkia(s, false));
2387
2388 if (ShouldRemoveStandardFrame()) {
2389 MARGINS m = {10, 10, 10, 10};
2390 DwmExtendFrameIntoClientArea(GetNativeView(), &m);
jeremya 2012/02/06 00:58:32 This is appropriate for the specific case of the S
2391 }
2377 } 2392 }
2378 2393
2379 void NativeWidgetWin::ResetWindowRegion(bool force) { 2394 void NativeWidgetWin::ResetWindowRegion(bool force) {
2380 // A native frame uses the native window region, and we don't want to mess 2395 // A native frame uses the native window region, and we don't want to mess
2381 // with it. 2396 // with it.
2382 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) { 2397 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) {
2383 if (force) 2398 if (force)
2384 SetWindowRgn(NULL, TRUE); 2399 SetWindowRgn(NULL, TRUE);
2385 return; 2400 return;
2386 } 2401 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2608 return (GetKeyState(VK_LBUTTON) & 0x80) || 2623 return (GetKeyState(VK_LBUTTON) & 0x80) ||
2609 (GetKeyState(VK_RBUTTON) & 0x80) || 2624 (GetKeyState(VK_RBUTTON) & 0x80) ||
2610 (GetKeyState(VK_MBUTTON) & 0x80) || 2625 (GetKeyState(VK_MBUTTON) & 0x80) ||
2611 (GetKeyState(VK_XBUTTON1) & 0x80) || 2626 (GetKeyState(VK_XBUTTON1) & 0x80) ||
2612 (GetKeyState(VK_XBUTTON2) & 0x80); 2627 (GetKeyState(VK_XBUTTON2) & 0x80);
2613 } 2628 }
2614 2629
2615 } // namespace internal 2630 } // namespace internal
2616 2631
2617 } // namespace views 2632 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698