Home | History | Annotate | Download | only in internal
      1 // Copyright (c) 2010 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_frame/infobars/internal/displaced_window_manager.h"
      6 
      7 DisplacedWindowManager::DisplacedWindowManager() {
      8 }
      9 
     10 void DisplacedWindowManager::UpdateLayout() {
     11   // Call SetWindowPos with SWP_FRAMECHANGED for displaced window.
     12   // Displaced window will receive WM_NCCALCSIZE to recalculate its client size.
     13   ::SetWindowPos(m_hWnd,
     14                  NULL, 0, 0, 0, 0,
     15                  SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
     16                  SWP_FRAMECHANGED);
     17 }
     18 
     19 LRESULT DisplacedWindowManager::OnNcCalcSize(BOOL calc_valid_rects,
     20                                              LPARAM lparam) {
     21   // Ask the original window proc to calculate the 'natural' size of the window.
     22   LRESULT ret = DefWindowProc(WM_NCCALCSIZE,
     23                               static_cast<WPARAM>(calc_valid_rects), lparam);
     24   if (lparam == NULL)
     25     return ret;
     26 
     27   // Whether calc_valid_rects is true or false, we could treat beginning of
     28   // lparam as a RECT object.
     29   RECT* rect = reinterpret_cast<RECT*>(lparam);
     30   RECT natural_rect = *rect;
     31   if (delegate() != NULL)
     32     delegate()->AdjustDisplacedWindowDimensions(rect);
     33 
     34   // If we modified the window's dimensions, there is no way to respect a custom
     35   // "client-area preservation strategy", so we must force a redraw to be safe.
     36   if (calc_valid_rects && ret == WVR_VALIDRECTS &&
     37       !EqualRect(&natural_rect, rect)) {
     38     ret = WVR_REDRAW;
     39   }
     40 
     41   return ret;
     42 }
     43