Bug 1840485 - Change the type of BaseMargin::{top,right,bottom,left} to Coord. r=botond

Differential Revision: https://phabricator.services.mozilla.com/D182328
This commit is contained in:
Razvan Cojocaru
2023-07-01 02:23:21 +00:00
parent 7adce395fd
commit d313765c33
10 changed files with 61 additions and 54 deletions

View File

@@ -62,7 +62,7 @@ struct BaseMargin {
// Do not change the layout of these members; the Side() methods below
// depend on this order.
T top, right, bottom, left;
Coord top, right, bottom, left;
// Constructors
BaseMargin() : top(0), right(0), bottom(0), left(0) {}
@@ -79,11 +79,11 @@ struct BaseMargin {
T LeftRight() const { return left + right; }
T TopBottom() const { return top + bottom; }
T& Side(SideT aSide) {
Coord& Side(SideT aSide) {
// This is ugly!
return *(&top + int(aSide));
}
T Side(SideT aSide) const {
Coord Side(SideT aSide) const {
// This is ugly!
return *(&top + int(aSide));
}

View File

@@ -49,8 +49,8 @@ struct MOZ_EMPTY_BASES IntMarginTyped
static IntMarginTyped<Units> FromUnknownMargin(
const IntMarginTyped<UnknownUnits>& aMargin) {
return IntMarginTyped<Units>(aMargin.top, aMargin.right, aMargin.bottom,
aMargin.left);
return IntMarginTyped<Units>(aMargin.top.value, aMargin.right.value,
aMargin.bottom.value, aMargin.left.value);
}
IntMarginTyped<UnknownUnits> ToUnknownMargin() const {

View File

@@ -3656,8 +3656,8 @@ void APZCTreeManager::SendSubtreeTransformsToChromeMainThread(
void APZCTreeManager::SetFixedLayerMargins(ScreenIntCoord aTop,
ScreenIntCoord aBottom) {
MutexAutoLock lock(mMapLock);
mCompositorFixedLayerMargins.top = aTop;
mCompositorFixedLayerMargins.bottom = aBottom;
mCompositorFixedLayerMargins.top = ScreenCoord(aTop);
mCompositorFixedLayerMargins.bottom = ScreenCoord(aBottom);
}
/*static*/

View File

@@ -705,7 +705,7 @@ SideBits AxisY::ScrollableDirectionsWithDynamicToolbar(
directions |= SideBits::eTop;
}
if (mAsyncPanZoomController->FuzzyGreater(
aFixedLayerMargins.bottom + toolbarHeight, 0)) {
fixedLayerMargins.bottom + toolbarHeight, 0)) {
directions |= SideBits::eBottom;
}
}

View File

@@ -124,8 +124,9 @@ gfx::IntRectTyped<TargetUnits> ViewAs(
template <class TargetUnits, class SourceUnits>
gfx::MarginTyped<TargetUnits> ViewAs(
const gfx::MarginTyped<SourceUnits>& aMargin, PixelCastJustification) {
return gfx::MarginTyped<TargetUnits>(aMargin.top, aMargin.right,
aMargin.bottom, aMargin.left);
return gfx::MarginTyped<TargetUnits>(aMargin.top.value, aMargin.right.value,
aMargin.bottom.value,
aMargin.left.value);
}
template <class TargetUnits, class SourceUnits>
gfx::IntMarginTyped<TargetUnits> ViewAs(

View File

@@ -394,8 +394,10 @@ struct CSSPixel {
}
static nsMargin ToAppUnits(const CSSIntMargin& aMargin) {
return nsMargin(ToAppUnits(aMargin.top), ToAppUnits(aMargin.right),
ToAppUnits(aMargin.bottom), ToAppUnits(aMargin.left));
return nsMargin(ToAppUnits(CSSCoord(aMargin.top)),
ToAppUnits(CSSCoord(aMargin.right)),
ToAppUnits(CSSCoord(aMargin.bottom)),
ToAppUnits(CSSCoord(aMargin.left)));
}
// Conversion from a given CSS point value.
@@ -877,8 +879,8 @@ template <class Src, class Dst>
gfx::MarginTyped<Dst> operator*(const gfx::MarginTyped<Src>& aMargin,
const gfx::ScaleFactor<Src, Dst>& aScale) {
return gfx::MarginTyped<Dst>(
aMargin.top * aScale.scale, aMargin.right * aScale.scale,
aMargin.bottom * aScale.scale, aMargin.left * aScale.scale);
aMargin.top.value * aScale.scale, aMargin.right.value * aScale.scale,
aMargin.bottom.value * aScale.scale, aMargin.left.value * aScale.scale);
}
template <class Src, class Dst>
@@ -894,8 +896,8 @@ gfx::MarginTyped<Dst, F> operator*(
const gfx::MarginTyped<Src, F>& aMargin,
const gfx::BaseScaleFactors2D<Src, Dst, F>& aScale) {
return gfx::MarginTyped<Dst, F>(
aMargin.top * aScale.yScale, aMargin.right * aScale.xScale,
aMargin.bottom * aScale.yScale, aMargin.left * aScale.xScale);
aMargin.top.value * aScale.yScale, aMargin.right.value * aScale.xScale,
aMargin.bottom.value * aScale.yScale, aMargin.left.value * aScale.xScale);
}
template <class Src, class Dst, class F>
@@ -903,8 +905,8 @@ gfx::MarginTyped<Dst, F> operator/(
const gfx::MarginTyped<Src, F>& aMargin,
const gfx::BaseScaleFactors2D<Dst, Src, F>& aScale) {
return gfx::MarginTyped<Dst, F>(
aMargin.top / aScale.yScale, aMargin.right / aScale.xScale,
aMargin.bottom / aScale.yScale, aMargin.left / aScale.xScale);
aMargin.top.value / aScale.yScale, aMargin.right.value / aScale.xScale,
aMargin.bottom.value / aScale.yScale, aMargin.left.value / aScale.xScale);
}
// Calculate the max or min or the ratios of the widths and heights of two

View File

@@ -740,8 +740,9 @@ CSSIntMargin nsNativeThemeGTK::GetExtraSizeForWidget(
if (IsDefaultButton(aFrame)) {
// Some themes draw a default indicator outside the widget,
// include that in overflow
moz_gtk_button_get_default_overflow(&extra.top, &extra.left,
&extra.bottom, &extra.right);
moz_gtk_button_get_default_overflow(&extra.top.value, &extra.left.value,
&extra.bottom.value,
&extra.right.value);
break;
}
return {};
@@ -948,8 +949,9 @@ CSSIntMargin nsNativeThemeGTK::GetCachedWidgetBorder(
if (mBorderCacheValid[cacheIndex] & cacheBit) {
result = mBorderCache[gtkWidgetType];
} else {
moz_gtk_get_widget_border(gtkWidgetType, &result.left, &result.top,
&result.right, &result.bottom, aDirection);
moz_gtk_get_widget_border(gtkWidgetType, &result.left.value,
&result.top.value, &result.right.value,
&result.bottom.value, aDirection);
if (gtkWidgetType != MOZ_GTK_DROPDOWN) { // depends on aDirection
mBorderCacheValid[cacheIndex] |= cacheBit;
mBorderCache[gtkWidgetType] = result;
@@ -986,9 +988,9 @@ LayoutDeviceIntMargin nsNativeThemeGTK::GetWidgetBorder(
&flags)) {
return {};
}
moz_gtk_get_tab_border(&result.left, &result.top, &result.right,
&result.bottom, direction, (GtkTabFlags)flags,
gtkWidgetType);
moz_gtk_get_tab_border(&result.left.value, &result.top.value,
&result.right.value, &result.bottom.value,
direction, (GtkTabFlags)flags, gtkWidgetType);
} break;
default: {
result = GetCachedWidgetBorder(aFrame, aAppearance, direction);

View File

@@ -360,23 +360,25 @@ nsresult nsPrintSettingsService::ReadPrefs(nsIPrintSettings* aPS,
if (aFlags & nsIPrintSettings::kInitSaveUnwriteableMargins) {
nsIntMargin margin;
bool allPrefsRead =
GETINTPREF(kUnwriteableMarginTopTwips, &margin.top) &&
GETINTPREF(kUnwriteableMarginRightTwips, &margin.right) &&
GETINTPREF(kUnwriteableMarginBottomTwips, &margin.bottom) &&
GETINTPREF(kUnwriteableMarginLeftTwips, &margin.left);
GETINTPREF(kUnwriteableMarginTopTwips, &margin.top.value) &&
GETINTPREF(kUnwriteableMarginRightTwips, &margin.right.value) &&
GETINTPREF(kUnwriteableMarginBottomTwips, &margin.bottom.value) &&
GETINTPREF(kUnwriteableMarginLeftTwips, &margin.left.value);
if (!allPrefsRead) {
// We failed to read the new unwritable margin twips prefs. Try to read
// the old ones in case they exist.
allPrefsRead =
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginTop, aPrinterName), margin.top) &&
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginLeft, aPrinterName), margin.left) &&
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginBottom, aPrinterName),
margin.bottom) &&
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginRight, aPrinterName), margin.right);
allPrefsRead = ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginTop, aPrinterName),
margin.top.value) &&
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginLeft, aPrinterName),
margin.left.value) &&
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginBottom, aPrinterName),
margin.bottom.value) &&
ReadInchesIntToTwipsPref(
GetPrefName(kUnwriteableMarginRight, aPrinterName),
margin.right.value);
}
// SetUnwriteableMarginInTwips does its own validation and drops negative
// values individually. We still want to block overly large values though,
@@ -392,16 +394,16 @@ nsresult nsPrintSettingsService::ReadPrefs(nsIPrintSettings* aPS,
int32_t halfInch = NS_INCHES_TO_INT_TWIPS(0.5);
nsIntMargin margin(halfInch, halfInch, halfInch, halfInch);
bool prefRead = ReadInchesToTwipsPref(GetPrefName(kMarginTop, aPrinterName),
margin.top);
margin.top.value);
prefRead = ReadInchesToTwipsPref(GetPrefName(kMarginLeft, aPrinterName),
margin.left) ||
margin.left.value) ||
prefRead;
prefRead = ReadInchesToTwipsPref(GetPrefName(kMarginBottom, aPrinterName),
margin.bottom) ||
margin.bottom.value) ||
prefRead;
prefRead = ReadInchesToTwipsPref(GetPrefName(kMarginRight, aPrinterName),
margin.right) ||
margin.right.value) ||
prefRead;
if (prefRead && MarginIsOK(margin)) {
aPS->SetMarginInTwips(margin);
@@ -417,17 +419,17 @@ nsresult nsPrintSettingsService::ReadPrefs(nsIPrintSettings* aPS,
if (aFlags & nsIPrintSettings::kInitSaveEdges) {
nsIntMargin margin(0, 0, 0, 0);
bool prefRead = ReadInchesIntToTwipsPref(
GetPrefName(kEdgeTop, aPrinterName), margin.top);
GetPrefName(kEdgeTop, aPrinterName), margin.top.value);
prefRead = ReadInchesIntToTwipsPref(GetPrefName(kEdgeLeft, aPrinterName),
margin.left) ||
margin.left.value) ||
prefRead;
prefRead = ReadInchesIntToTwipsPref(GetPrefName(kEdgeBottom, aPrinterName),
margin.bottom) ||
margin.bottom.value) ||
prefRead;
prefRead = ReadInchesIntToTwipsPref(GetPrefName(kEdgeRight, aPrinterName),
margin.right) ||
margin.right.value) ||
prefRead;
;
if (prefRead && MarginIsOK(margin)) {

View File

@@ -1799,10 +1799,10 @@ LayoutDeviceIntMargin nsNativeThemeWin::GetWidgetBorder(
if (content && content->IsHTMLElement()) {
// We need to pad textfields by 1 pixel, since the caret will draw
// flush against the edge by default if we don't.
result.top++;
result.left++;
result.bottom++;
result.right++;
result.top.value++;
result.left.value++;
result.bottom.value++;
result.right.value++;
}
}

View File

@@ -813,11 +813,11 @@ class nsWindow final : public nsBaseWidget {
// Indicates custom resize margins are in effect
bool mUseResizeMarginOverrides = false;
// Width of the left and right portions of the resize region
int32_t mHorResizeMargin;
mozilla::LayoutDeviceIntCoord mHorResizeMargin;
// Height of the top and bottom portions of the resize region
int32_t mVertResizeMargin;
mozilla::LayoutDeviceIntCoord mVertResizeMargin;
// Height of the caption plus border
int32_t mCaptionHeight;
mozilla::LayoutDeviceIntCoord mCaptionHeight;
// not yet set, will be calculated on first use
double mDefaultScale = -1.0;