nsGridCell.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. //
  6. // Eric Vaughan
  7. // Netscape Communications
  8. //
  9. // See documentation in associated header file
  10. //
  11. #include "nsGridCell.h"
  12. #include "nsFrame.h"
  13. #include "nsBox.h"
  14. #include "nsGridLayout2.h"
  15. nsGridCell::nsGridCell():mBoxInColumn(nullptr),mBoxInRow(nullptr)
  16. {
  17. MOZ_COUNT_CTOR(nsGridCell);
  18. }
  19. nsGridCell::~nsGridCell()
  20. {
  21. MOZ_COUNT_DTOR(nsGridCell);
  22. }
  23. nsSize
  24. nsGridCell::GetXULPrefSize(nsBoxLayoutState& aState)
  25. {
  26. nsSize sum(0,0);
  27. // take our 2 children and add them up.
  28. // we are as wide as the widest child plus its left offset
  29. // we are tall as the tallest child plus its top offset
  30. if (mBoxInColumn) {
  31. nsSize pref = mBoxInColumn->GetXULPrefSize(aState);
  32. nsBox::AddMargin(mBoxInColumn, pref);
  33. nsGridLayout2::AddOffset(mBoxInColumn, pref);
  34. nsBoxLayout::AddLargestSize(sum, pref);
  35. }
  36. if (mBoxInRow) {
  37. nsSize pref = mBoxInRow->GetXULPrefSize(aState);
  38. nsBox::AddMargin(mBoxInRow, pref);
  39. nsGridLayout2::AddOffset(mBoxInRow, pref);
  40. nsBoxLayout::AddLargestSize(sum, pref);
  41. }
  42. return sum;
  43. }
  44. nsSize
  45. nsGridCell::GetXULMinSize(nsBoxLayoutState& aState)
  46. {
  47. nsSize sum(0, 0);
  48. // take our 2 children and add them up.
  49. // we are as wide as the widest child plus its left offset
  50. // we are tall as the tallest child plus its top offset
  51. if (mBoxInColumn) {
  52. nsSize min = mBoxInColumn->GetXULMinSize(aState);
  53. nsBox::AddMargin(mBoxInColumn, min);
  54. nsGridLayout2::AddOffset(mBoxInColumn, min);
  55. nsBoxLayout::AddLargestSize(sum, min);
  56. }
  57. if (mBoxInRow) {
  58. nsSize min = mBoxInRow->GetXULMinSize(aState);
  59. nsBox::AddMargin(mBoxInRow, min);
  60. nsGridLayout2::AddOffset(mBoxInRow, min);
  61. nsBoxLayout::AddLargestSize(sum, min);
  62. }
  63. return sum;
  64. }
  65. nsSize
  66. nsGridCell::GetXULMaxSize(nsBoxLayoutState& aState)
  67. {
  68. nsSize sum(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
  69. // take our 2 children and add them up.
  70. // we are as wide as the smallest child plus its left offset
  71. // we are tall as the shortest child plus its top offset
  72. if (mBoxInColumn) {
  73. nsSize max = mBoxInColumn->GetXULMaxSize(aState);
  74. nsBox::AddMargin(mBoxInColumn, max);
  75. nsGridLayout2::AddOffset(mBoxInColumn, max);
  76. nsBoxLayout::AddSmallestSize(sum, max);
  77. }
  78. if (mBoxInRow) {
  79. nsSize max = mBoxInRow->GetXULMaxSize(aState);
  80. nsBox::AddMargin(mBoxInRow, max);
  81. nsGridLayout2::AddOffset(mBoxInRow, max);
  82. nsBoxLayout::AddSmallestSize(sum, max);
  83. }
  84. return sum;
  85. }
  86. bool
  87. nsGridCell::IsXULCollapsed()
  88. {
  89. return ((mBoxInColumn && mBoxInColumn->IsXULCollapsed()) ||
  90. (mBoxInRow && mBoxInRow->IsXULCollapsed()));
  91. }