layout/xul/grid/nsGridCell.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/grid/nsGridCell.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,127 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +//
    1.10 +// Eric Vaughan
    1.11 +// Netscape Communications
    1.12 +//
    1.13 +// See documentation in associated header file
    1.14 +//
    1.15 +
    1.16 +#include "nsGridCell.h"
    1.17 +#include "nsFrame.h"
    1.18 +#include "nsBox.h"
    1.19 +#include "nsGridLayout2.h"
    1.20 +
    1.21 +
    1.22 +nsGridCell::nsGridCell():mBoxInColumn(nullptr),mBoxInRow(nullptr)
    1.23 +{
    1.24 +    MOZ_COUNT_CTOR(nsGridCell);
    1.25 +}                                               
    1.26 +        
    1.27 +nsGridCell::~nsGridCell()
    1.28 +{
    1.29 +    MOZ_COUNT_DTOR(nsGridCell);
    1.30 +}
    1.31 +
    1.32 +nsSize
    1.33 +nsGridCell::GetPrefSize(nsBoxLayoutState& aState)
    1.34 +{
    1.35 +  nsSize sum(0,0);
    1.36 +
    1.37 +  // take our 2 children and add them up.
    1.38 +  // we are as wide as the widest child plus its left offset
    1.39 +  // we are tall as the tallest child plus its top offset
    1.40 +
    1.41 +  if (mBoxInColumn) {
    1.42 +    nsSize pref = mBoxInColumn->GetPrefSize(aState);
    1.43 +
    1.44 +    nsBox::AddMargin(mBoxInColumn, pref);
    1.45 +    nsGridLayout2::AddOffset(aState, mBoxInColumn, pref);
    1.46 +
    1.47 +    nsBoxLayout::AddLargestSize(sum, pref);
    1.48 +  }
    1.49 +
    1.50 +  if (mBoxInRow) {
    1.51 +    nsSize pref = mBoxInRow->GetPrefSize(aState);
    1.52 +
    1.53 +    nsBox::AddMargin(mBoxInRow, pref);
    1.54 +    nsGridLayout2::AddOffset(aState, mBoxInRow, pref);
    1.55 +
    1.56 +    nsBoxLayout::AddLargestSize(sum, pref);
    1.57 +  }
    1.58 +
    1.59 +  return sum;
    1.60 +}
    1.61 +
    1.62 +nsSize
    1.63 +nsGridCell::GetMinSize(nsBoxLayoutState& aState)
    1.64 +{
    1.65 +  nsSize sum(0, 0);
    1.66 +
    1.67 +  // take our 2 children and add them up.
    1.68 +  // we are as wide as the widest child plus its left offset
    1.69 +  // we are tall as the tallest child plus its top offset
    1.70 +
    1.71 +  if (mBoxInColumn) {
    1.72 +    nsSize min = mBoxInColumn->GetMinSize(aState);
    1.73 +
    1.74 +    nsBox::AddMargin(mBoxInColumn, min);
    1.75 +    nsGridLayout2::AddOffset(aState, mBoxInColumn, min);
    1.76 +
    1.77 +    nsBoxLayout::AddLargestSize(sum, min);
    1.78 +  }
    1.79 +
    1.80 +  if (mBoxInRow) {
    1.81 +    nsSize min = mBoxInRow->GetMinSize(aState);
    1.82 +
    1.83 +    nsBox::AddMargin(mBoxInRow, min);
    1.84 +    nsGridLayout2::AddOffset(aState, mBoxInRow, min);
    1.85 +
    1.86 +    nsBoxLayout::AddLargestSize(sum, min);
    1.87 +  }
    1.88 +
    1.89 +  return sum;
    1.90 +}
    1.91 +
    1.92 +nsSize
    1.93 +nsGridCell::GetMaxSize(nsBoxLayoutState& aState)
    1.94 +{
    1.95 +  nsSize sum(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
    1.96 +
    1.97 +  // take our 2 children and add them up.
    1.98 +  // we are as wide as the smallest child plus its left offset
    1.99 +  // we are tall as the shortest child plus its top offset
   1.100 +
   1.101 +  if (mBoxInColumn) {
   1.102 +    nsSize max = mBoxInColumn->GetMaxSize(aState);
   1.103 + 
   1.104 +    nsBox::AddMargin(mBoxInColumn, max);
   1.105 +    nsGridLayout2::AddOffset(aState, mBoxInColumn, max);
   1.106 +
   1.107 +    nsBoxLayout::AddSmallestSize(sum, max);
   1.108 +  }
   1.109 +
   1.110 +  if (mBoxInRow) {
   1.111 +    nsSize max = mBoxInRow->GetMaxSize(aState);
   1.112 +
   1.113 +    nsBox::AddMargin(mBoxInRow, max);
   1.114 +    nsGridLayout2::AddOffset(aState, mBoxInRow, max);
   1.115 +
   1.116 +    nsBoxLayout::AddSmallestSize(sum, max);
   1.117 +  }
   1.118 +
   1.119 +  return sum;
   1.120 +}
   1.121 +
   1.122 +
   1.123 +bool
   1.124 +nsGridCell::IsCollapsed()
   1.125 +{
   1.126 +  return ((mBoxInColumn && mBoxInColumn->IsCollapsed()) ||
   1.127 +          (mBoxInRow && mBoxInRow->IsCollapsed()));
   1.128 +}
   1.129 +
   1.130 +

mercurial