Home | History | Annotate | Download | only in location_bar
      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 #import "chrome/browser/ui/cocoa/location_bar/omnibox_popup_view.h"
      6 
      7 #include "base/logging.h"
      8 
      9 @implementation OmniboxPopupView
     10 
     11 // If there is only one subview, it is sized to fill all available space.  If
     12 // there are two subviews, the second subview is placed at the bottom of the
     13 // view, and the first subview is sized to fill all remaining space.
     14 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize {
     15   NSArray* subviews = [self subviews];
     16   if ([subviews count] == 0)
     17     return;
     18 
     19   DCHECK_LE([subviews count], 2U);
     20 
     21   NSRect availableSpace = [self bounds];
     22 
     23   if ([subviews count] >= 2) {
     24     NSView* instantView = [subviews objectAtIndex:1];
     25     CGFloat height = NSHeight([instantView frame]);
     26     NSRect instantFrame = availableSpace;
     27     instantFrame.size.height = height;
     28 
     29     availableSpace.origin.y = height;
     30     availableSpace.size.height -= height;
     31     [instantView setFrame:instantFrame];
     32   }
     33 
     34   if ([subviews count] >= 1) {
     35     NSView* matrixView = [subviews objectAtIndex:0];
     36     if (NSHeight(availableSpace) < 0)
     37       availableSpace.size.height = 0;
     38 
     39     [matrixView setFrame:availableSpace];
     40   }
     41 }
     42 
     43 @end
     44