nsGridRowLeafFrame.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "nsGridRowLeafFrame.h"
  12. #include "nsGridRowLeafLayout.h"
  13. #include "nsGridRow.h"
  14. #include "nsBoxLayoutState.h"
  15. #include "nsGridLayout2.h"
  16. already_AddRefed<nsBoxLayout> NS_NewGridRowLeafLayout();
  17. nsIFrame*
  18. NS_NewGridRowLeafFrame(nsIPresShell* aPresShell,
  19. nsStyleContext* aContext)
  20. {
  21. nsCOMPtr<nsBoxLayout> layout = NS_NewGridRowLeafLayout();
  22. return new (aPresShell) nsGridRowLeafFrame(aContext, false, layout);
  23. }
  24. NS_IMPL_FRAMEARENA_HELPERS(nsGridRowLeafFrame)
  25. /*
  26. * Our border and padding could be affected by our columns or rows.
  27. * Let's go check it out.
  28. */
  29. nsresult
  30. nsGridRowLeafFrame::GetXULBorderAndPadding(nsMargin& aBorderAndPadding)
  31. {
  32. // if our columns have made our padding larger add it in.
  33. nsresult rv = nsBoxFrame::GetXULBorderAndPadding(aBorderAndPadding);
  34. nsIGridPart* part = nsGrid::GetPartFromBox(this);
  35. if (!part)
  36. return rv;
  37. int32_t index = 0;
  38. nsGrid* grid = part->GetGrid(this, &index);
  39. if (!grid)
  40. return rv;
  41. bool isHorizontal = IsXULHorizontal();
  42. int32_t firstIndex = 0;
  43. int32_t lastIndex = 0;
  44. nsGridRow* firstRow = nullptr;
  45. nsGridRow* lastRow = nullptr;
  46. grid->GetFirstAndLastRow(firstIndex, lastIndex, firstRow, lastRow, isHorizontal);
  47. // only the first and last rows can be affected.
  48. if (firstRow && firstRow->GetBox() == this) {
  49. nscoord top = 0;
  50. nscoord bottom = 0;
  51. grid->GetRowOffsets(firstIndex, top, bottom, isHorizontal);
  52. if (isHorizontal) {
  53. if (top > aBorderAndPadding.top)
  54. aBorderAndPadding.top = top;
  55. } else {
  56. if (top > aBorderAndPadding.left)
  57. aBorderAndPadding.left = top;
  58. }
  59. }
  60. if (lastRow && lastRow->GetBox() == this) {
  61. nscoord top = 0;
  62. nscoord bottom = 0;
  63. grid->GetRowOffsets(lastIndex, top, bottom, isHorizontal);
  64. if (isHorizontal) {
  65. if (bottom > aBorderAndPadding.bottom)
  66. aBorderAndPadding.bottom = bottom;
  67. } else {
  68. if (bottom > aBorderAndPadding.right)
  69. aBorderAndPadding.right = bottom;
  70. }
  71. }
  72. return rv;
  73. }