Skip to content

Commit

Permalink
Bug 1506687 Part 1: Make FlexItemValues also provide the item's frame…
Browse files Browse the repository at this point in the history
… rect. r=dholbert

Differential Revision: https://phabricator.services.mozilla.com/D12182

--HG--
extra : moz-landing-system : lando
  • Loading branch information
bradwerth committed Nov 17, 2018
1 parent d1b2c17 commit cae2b12
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions dom/chrome-webidl/Flex.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum FlexItemClampState {
interface FlexItemValues
{
readonly attribute Node? node;
readonly attribute DOMRectReadOnly frameRect;
readonly attribute double mainBaseSize;
readonly attribute double mainDeltaSize;
readonly attribute double mainMinSize;
Expand Down
17 changes: 16 additions & 1 deletion dom/flex/FlexItemValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
namespace mozilla {
namespace dom {

NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItemValues, mParent)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItemValues, mParent, mNode,
mFrameRect)
NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexItemValues)
NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexItemValues)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItemValues)
Expand Down Expand Up @@ -49,6 +50,14 @@ FlexItemValues::FlexItemValues(FlexLineValues* aParent,
// going to keep it around.
mNode = aItem->mNode;

// Since mNode might be null, we associate the mFrameRect with
// our parent.
mFrameRect = new DOMRectReadOnly(mParent,
nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.X()),
nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Y()),
nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Width()),
nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Height()));

// Convert app unit sizes to css pixel sizes.
mMainBaseSize = nsPresContext::AppUnitsToDoubleCSSPixels(
aItem->mMainBaseSize);
Expand Down Expand Up @@ -76,6 +85,12 @@ FlexItemValues::GetNode() const
return mNode;
}

DOMRectReadOnly*
FlexItemValues::FrameRect() const
{
return mFrameRect;
}

double
FlexItemValues::MainBaseSize() const
{
Expand Down
2 changes: 2 additions & 0 deletions dom/flex/FlexItemValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class FlexItemValues : public nsISupports
}

nsINode* GetNode() const;
DOMRectReadOnly* FrameRect() const;
double MainBaseSize() const;
double MainDeltaSize() const;
double MainMinSize() const;
Expand All @@ -50,6 +51,7 @@ class FlexItemValues : public nsISupports
protected:
RefPtr<FlexLineValues> mParent;
RefPtr<nsINode> mNode;
RefPtr<DOMRectReadOnly> mFrameRect;

// These sizes are all CSS pixel units.
double mMainBaseSize;
Expand Down
24 changes: 15 additions & 9 deletions layout/generic/nsFlexContainerFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4849,14 +4849,9 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext,

itemInfo->mNode = content;

// mMainBaseSize and itemInfo->mMainDeltaSize will
// be filled out in ResolveFlexibleLengths().

// Other FlexItem properties can be captured now.
itemInfo->mMainMinSize = item->GetMainMinSize();
itemInfo->mMainMaxSize = item->GetMainMaxSize();
itemInfo->mCrossMinSize = item->GetCrossMinSize();
itemInfo->mCrossMaxSize = item->GetCrossMaxSize();
// itemInfo->mMainBaseSize and mMainDeltaSize will be filled out
// in ResolveFlexibleLengths(). Other measurements will be captured
// at the end of this function.
}
}
}
Expand Down Expand Up @@ -5261,7 +5256,7 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext,

NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize)

// Finally update our line sizing values in our containerInfo.
// Finally update our line and item measurements in our containerInfo.
if (MOZ_UNLIKELY(containerInfo)) {
lineIndex = 0;
for (const FlexLine* line = lines.getFirst(); line;
Expand All @@ -5271,6 +5266,17 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext,
lineInfo.mCrossSize = line->GetLineCrossSize();
lineInfo.mFirstBaselineOffset = line->GetFirstBaselineOffset();
lineInfo.mLastBaselineOffset = line->GetLastBaselineOffset();

uint32_t itemIndex = 0;
for (const FlexItem* item = line->GetFirstItem(); item;
item = item->getNext(), ++itemIndex) {
ComputedFlexItemInfo& itemInfo = lineInfo.mItems[itemIndex];
itemInfo.mFrameRect = item->Frame()->GetRect();
itemInfo.mMainMinSize = item->GetMainMinSize();
itemInfo.mMainMaxSize = item->GetMainMaxSize();
itemInfo.mCrossMinSize = item->GetCrossMinSize();
itemInfo.mCrossMaxSize = item->GetCrossMaxSize();
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions layout/generic/nsFlexContainerFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ nsContainerFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell,
struct ComputedFlexItemInfo
{
nsCOMPtr<nsINode> mNode;
nsRect mFrameRect;
/**
* mMainBaseSize is a measure of the size of the item in the main
* axis before the flex sizing algorithm is applied. In the spec,
Expand Down

0 comments on commit cae2b12

Please sign in to comment.