mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 982141 - Move CalculateRootCompositionSize to nsLayoutUtils and clean it up a bit. r=tn
--HG-- extra : rebase_source : 8ffa71055b05836ce166b6b2c8c9896b6d08fdd5
This commit is contained in:
parent
803fc64902
commit
ed1e60ff0b
@ -622,83 +622,6 @@ static bool GetApzcTreePrintPref() {
|
||||
return gPrintApzcTree;
|
||||
}
|
||||
|
||||
static CSSSize
|
||||
CalculateRootCompositionSize(FrameMetrics& aMetrics,
|
||||
bool aIsRootContentDocRootScrollFrame,
|
||||
nsPresContext* aPresContext,
|
||||
nsIFrame* aForFrame, nsIFrame* aScrollFrame)
|
||||
{
|
||||
|
||||
if (aIsRootContentDocRootScrollFrame) {
|
||||
return ViewAs<LayerPixel>(ParentLayerSize(aMetrics.mCompositionBounds.Size()),
|
||||
PixelCastJustification::ParentLayerToLayerForRootComposition)
|
||||
/ aMetrics.LayersPixelsPerCSSPixel();
|
||||
}
|
||||
LayerSize rootCompositionSize;
|
||||
nsPresContext* rootPresContext =
|
||||
aPresContext->GetToplevelContentDocumentPresContext();
|
||||
if (!rootPresContext) {
|
||||
rootPresContext = aPresContext->GetRootPresContext();
|
||||
}
|
||||
nsIPresShell* rootPresShell = nullptr;
|
||||
if (rootPresContext) {
|
||||
// See the comments in the code that calculates the root
|
||||
// composition bounds in RecordFrameMetrics.
|
||||
// TODO: Reuse that code here.
|
||||
nsIPresShell* rootPresShell = rootPresContext->PresShell();
|
||||
if (nsIFrame* rootFrame = rootPresShell->GetRootFrame()) {
|
||||
if (nsView* view = rootFrame->GetView()) {
|
||||
LayoutDeviceToParentLayerScale parentResolution(
|
||||
rootPresShell->GetCumulativeResolution().width
|
||||
/ rootPresShell->GetResolution().width);
|
||||
int32_t rootAUPerDevPixel = rootPresContext->AppUnitsPerDevPixel();
|
||||
nsRect viewBounds = view->GetBounds();
|
||||
LayerSize viewSize = ViewAs<LayerPixel>(
|
||||
(LayoutDeviceRect::FromAppUnits(viewBounds, rootAUPerDevPixel)
|
||||
* parentResolution).Size(), PixelCastJustification::ParentLayerToLayerForRootComposition);
|
||||
nsIWidget* widget =
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
rootFrame->GetNearestWidget();
|
||||
#else
|
||||
view->GetWidget();
|
||||
#endif
|
||||
if (widget) {
|
||||
nsIntRect widgetBounds;
|
||||
widget->GetBounds(widgetBounds);
|
||||
rootCompositionSize = LayerSize(ViewAs<LayerPixel>(widgetBounds.Size()));
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
if (viewSize.height < rootCompositionSize.height) {
|
||||
rootCompositionSize.height = viewSize.height;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
rootCompositionSize = viewSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nsIWidget* widget = (aScrollFrame ? aScrollFrame : aForFrame)->GetNearestWidget();
|
||||
nsIntRect bounds;
|
||||
widget->GetBounds(bounds);
|
||||
rootCompositionSize = LayerSize(ViewAs<LayerPixel>(bounds.Size()));
|
||||
}
|
||||
|
||||
// Adjust composition size for the size of scroll bars.
|
||||
nsIFrame* rootRootScrollFrame = rootPresShell ? rootPresShell->GetRootScrollFrame() : nullptr;
|
||||
nsIScrollableFrame* rootScrollableFrame = nullptr;
|
||||
if (rootRootScrollFrame) {
|
||||
rootScrollableFrame = aScrollFrame->GetScrollTargetFrame();
|
||||
}
|
||||
if (rootScrollableFrame && !LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars)) {
|
||||
CSSMargin margins = CSSMargin::FromAppUnits(rootScrollableFrame->GetActualScrollbarSizes());
|
||||
// Scrollbars are not subject to scaling, so CSS pixels = layer pixels for them.
|
||||
rootCompositionSize.width -= margins.LeftRight();
|
||||
rootCompositionSize.height -= margins.TopBottom();
|
||||
}
|
||||
|
||||
return rootCompositionSize / aMetrics.LayersPixelsPerCSSPixel();
|
||||
}
|
||||
|
||||
static void RecordFrameMetrics(nsIFrame* aForFrame,
|
||||
nsIFrame* aScrollFrame,
|
||||
const nsIFrame* aReferenceFrame,
|
||||
@ -858,8 +781,8 @@ static void RecordFrameMetrics(nsIFrame* aForFrame,
|
||||
}
|
||||
|
||||
metrics.SetRootCompositionSize(
|
||||
CalculateRootCompositionSize(metrics, isRootContentDocRootScrollFrame,
|
||||
presContext, aForFrame, aScrollFrame));
|
||||
nsLayoutUtils::CalculateRootCompositionSize(aScrollFrame ? aScrollFrame : aForFrame,
|
||||
isRootContentDocRootScrollFrame, metrics));
|
||||
|
||||
if (GetApzcTreePrintPref()) {
|
||||
if (nsIContent* content = frameForCompositionBoundsCalculation->GetContent()) {
|
||||
|
@ -74,6 +74,7 @@
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "gfx2DGlue.h"
|
||||
#include "mozilla/LookAndFeel.h"
|
||||
#include "UnitTransforms.h"
|
||||
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
@ -6216,6 +6217,82 @@ nsLayoutUtils::CalculateCompositionSizeForFrame(nsIFrame* aFrame)
|
||||
|
||||
return size;
|
||||
}
|
||||
/* static */ CSSSize
|
||||
nsLayoutUtils::CalculateRootCompositionSize(nsIFrame* aFrame,
|
||||
bool aIsRootContentDocRootScrollFrame,
|
||||
const FrameMetrics& aMetrics)
|
||||
{
|
||||
|
||||
if (aIsRootContentDocRootScrollFrame) {
|
||||
return ViewAs<LayerPixel>(ParentLayerSize(aMetrics.mCompositionBounds.Size()),
|
||||
PixelCastJustification::ParentLayerToLayerForRootComposition)
|
||||
/ aMetrics.LayersPixelsPerCSSPixel();
|
||||
}
|
||||
nsPresContext* presContext = aFrame->PresContext();
|
||||
LayerSize rootCompositionSize;
|
||||
nsPresContext* rootPresContext =
|
||||
presContext->GetToplevelContentDocumentPresContext();
|
||||
if (!rootPresContext) {
|
||||
rootPresContext = presContext->GetRootPresContext();
|
||||
}
|
||||
nsIPresShell* rootPresShell = nullptr;
|
||||
if (rootPresContext) {
|
||||
// See the comments in the code that calculates the root
|
||||
// composition bounds in RecordFrameMetrics.
|
||||
// TODO: Reuse that code here.
|
||||
nsIPresShell* rootPresShell = rootPresContext->PresShell();
|
||||
if (nsIFrame* rootFrame = rootPresShell->GetRootFrame()) {
|
||||
if (nsView* view = rootFrame->GetView()) {
|
||||
LayoutDeviceToParentLayerScale parentResolution(
|
||||
rootPresShell->GetCumulativeResolution().width
|
||||
/ rootPresShell->GetResolution().width);
|
||||
int32_t rootAUPerDevPixel = rootPresContext->AppUnitsPerDevPixel();
|
||||
nsRect viewBounds = view->GetBounds();
|
||||
LayerSize viewSize = ViewAs<LayerPixel>(
|
||||
(LayoutDeviceRect::FromAppUnits(viewBounds, rootAUPerDevPixel)
|
||||
* parentResolution).Size(), PixelCastJustification::ParentLayerToLayerForRootComposition);
|
||||
nsIWidget* widget =
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
rootFrame->GetNearestWidget();
|
||||
#else
|
||||
view->GetWidget();
|
||||
#endif
|
||||
if (widget) {
|
||||
nsIntRect widgetBounds;
|
||||
widget->GetBounds(widgetBounds);
|
||||
rootCompositionSize = LayerSize(ViewAs<LayerPixel>(widgetBounds.Size()));
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
if (viewSize.height < rootCompositionSize.height) {
|
||||
rootCompositionSize.height = viewSize.height;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
rootCompositionSize = viewSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nsIWidget* widget = aFrame->GetNearestWidget();
|
||||
nsIntRect widgetBounds;
|
||||
widget->GetBounds(widgetBounds);
|
||||
rootCompositionSize = LayerSize(ViewAs<LayerPixel>(widgetBounds.Size()));
|
||||
}
|
||||
|
||||
// Adjust composition size for the size of scroll bars.
|
||||
nsIFrame* rootRootScrollFrame = rootPresShell ? rootPresShell->GetRootScrollFrame() : nullptr;
|
||||
nsIScrollableFrame* rootScrollableFrame = nullptr;
|
||||
if (rootRootScrollFrame) {
|
||||
rootScrollableFrame = rootRootScrollFrame->GetScrollTargetFrame();
|
||||
}
|
||||
if (rootScrollableFrame && !LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars)) {
|
||||
CSSMargin margins = CSSMargin::FromAppUnits(rootScrollableFrame->GetActualScrollbarSizes());
|
||||
// Scrollbars are not subject to scaling, so CSS pixels = layer pixels for them.
|
||||
rootCompositionSize.width -= margins.LeftRight();
|
||||
rootCompositionSize.height -= margins.TopBottom();
|
||||
}
|
||||
|
||||
return rootCompositionSize / aMetrics.LayersPixelsPerCSSPixel();
|
||||
}
|
||||
|
||||
/* static */ nsRect
|
||||
nsLayoutUtils::CalculateScrollableRectForFrame(nsIScrollableFrame* aScrollableFrame, nsIFrame* aRootFrame)
|
||||
|
@ -126,6 +126,7 @@ public:
|
||||
typedef mozilla::layers::FrameMetrics FrameMetrics;
|
||||
typedef FrameMetrics::ViewID ViewID;
|
||||
typedef mozilla::CSSPoint CSSPoint;
|
||||
typedef mozilla::CSSSize CSSSize;
|
||||
|
||||
/**
|
||||
* Finds previously assigned ViewID for the given content element, if any.
|
||||
@ -2100,6 +2101,22 @@ public:
|
||||
static nsSize
|
||||
CalculateCompositionSizeForFrame(nsIFrame* aFrame);
|
||||
|
||||
/**
|
||||
* Calculate the composition size for the root scroll frame of the root
|
||||
* content document.
|
||||
* @param aFrame A frame in the root content document (or a descendant of it).
|
||||
* @param aIsRootContentDocRootScrollFrame Whether aFrame is already the root
|
||||
* scroll frame of the root content document. In this case we just
|
||||
* use aFrame's own composition size.
|
||||
* @param aMetrics A partially populated FrameMetrics for aFrame. Must have at
|
||||
* least mCompositionBounds, mCumulativeResolution, and
|
||||
* mDevPixelsPerCSSPixel set.
|
||||
*/
|
||||
static CSSSize
|
||||
CalculateRootCompositionSize(nsIFrame* aFrame,
|
||||
bool aIsRootContentDocRootScrollFrame,
|
||||
const FrameMetrics& aMetrics);
|
||||
|
||||
/**
|
||||
* Calculate the scrollable rect for a frame. See FrameMetrics.h for
|
||||
* defintion of scrollable rect. aScrollableFrame is the scroll frame to calculate
|
||||
|
Loading…
Reference in New Issue
Block a user