app_window_desktop_window_tree_host_win.cc revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/views/apps/app_window_desktop_window_tree_host_win.h" 6 7#include <dwmapi.h> 8 9#include "chrome/browser/ui/views/apps/chrome_native_app_window_views_win.h" 10#include "chrome/browser/ui/views/apps/glass_app_window_frame_view_win.h" 11#include "grit/theme_resources.h" 12#include "ui/base/theme_provider.h" 13#include "ui/gfx/win/dpi.h" 14#include "ui/views/controls/menu/native_menu_win.h" 15 16#pragma comment(lib, "dwmapi.lib") 17 18AppWindowDesktopWindowTreeHostWin::AppWindowDesktopWindowTreeHostWin( 19 ChromeNativeAppWindowViewsWin* app_window, 20 views::DesktopNativeWidgetAura* desktop_native_widget_aura) 21 : DesktopWindowTreeHostWin(app_window->widget(), 22 desktop_native_widget_aura), 23 app_window_(app_window) { 24} 25 26AppWindowDesktopWindowTreeHostWin::~AppWindowDesktopWindowTreeHostWin() { 27} 28 29bool AppWindowDesktopWindowTreeHostWin::GetClientAreaInsets( 30 gfx::Insets* insets) const { 31 // Use the default client insets for an opaque frame or a glass popup/app 32 // frame. 33 if (!app_window_->glass_frame_view()) 34 return false; 35 36 // This tells Windows that the whole of the window is a client area, meaning 37 // Chrome will draw it. Windows still fills in the glass bits because of the 38 // DwmExtendFrameIntoClientArea call in |UpdateDWMFrame|. 39 insets->Set(0, 0, 0, 0); 40 return true; 41} 42 43void AppWindowDesktopWindowTreeHostWin::HandleFrameChanged() { 44 // We need to update the glass region on or off before the base class adjusts 45 // the window region. 46 UpdateDWMFrame(); 47 DesktopWindowTreeHostWin::HandleFrameChanged(); 48} 49 50void AppWindowDesktopWindowTreeHostWin::PostHandleMSG(UINT message, 51 WPARAM w_param, 52 LPARAM l_param) { 53 switch (message) { 54 case WM_WINDOWPOSCHANGED: { 55 UpdateDWMFrame(); 56 break; 57 } 58 } 59} 60 61void AppWindowDesktopWindowTreeHostWin::UpdateDWMFrame() { 62 if (!GetWidget()->client_view() || !app_window_->glass_frame_view()) 63 return; 64 65 MARGINS margins = {0}; 66 67 // If the opaque frame is visible, we use the default (zero) margins. 68 // Otherwise, we need to figure out how to extend the glass in. 69 if (app_window_->glass_frame_view()) { 70 gfx::Insets insets = app_window_->glass_frame_view()->GetGlassInsets(); 71 margins.cxLeftWidth = insets.left(); 72 margins.cxRightWidth = insets.right(); 73 margins.cyBottomHeight = insets.bottom(); 74 margins.cyTopHeight = insets.top(); 75 } 76 77 DwmExtendFrameIntoClientArea(GetHWND(), &margins); 78} 79