Bug 1367576 - Refactor to allow for caching of some gtk widget padding/border results. r=karlt

This refactors the two nearly-identical callsites into a method so that
I can do caching in that method in the next patch.

Note that there was a slight difference between them in that the
aWidgetFlags parameter to GetGtkWidgetAndState was only passed from one
callsite.  However, given that the aState parameter is null, this
doesn't cause any behavior differences.  (Some controls in
GetGtkWidgetAndState null-check aWidgetFlags and some don't!)

Note also that this makes it always assign a result (often zero).  This
is fine for both callsites; GetWidgetPadding previously assigned zero
right before the call, and GetWidgetBorder did so at the start of the
function (and wasn't modified in between, since it was immediately
before the switch that the modified code is a case in).

MozReview-Commit-ID: IKurwry3UTi
This commit is contained in:
L. David Baron 2017-06-06 22:27:17 -07:00
Родитель 06ad92ffc6
Коммит ee1674ecc5
2 изменённых файлов: 22 добавлений и 15 удалений

Просмотреть файл

@ -1258,6 +1258,22 @@ nsNativeThemeGTK::NativeThemeToGtkTheme(uint8_t aWidgetType, nsIFrame* aFrame)
return gtkWidgetType;
}
void
nsNativeThemeGTK::GetCachedWidgetBorder(nsIFrame* aFrame, uint8_t aWidgetType,
GtkTextDirection aDirection,
nsIntMargin* aResult)
{
aResult->SizeTo(0, 0, 0, 0);
WidgetNodeType gtkWidgetType;
gint unusedFlags;
if (GetGtkWidgetAndState(aWidgetType, aFrame, gtkWidgetType, nullptr,
&unusedFlags)) {
moz_gtk_get_widget_border(gtkWidgetType, &aResult->left, &aResult->top,
&aResult->right, &aResult->bottom, aDirection);
}
}
NS_IMETHODIMP
nsNativeThemeGTK::GetWidgetBorder(nsDeviceContext* aContext, nsIFrame* aFrame,
uint8_t aWidgetType, nsIntMargin* aResult)
@ -1333,13 +1349,7 @@ nsNativeThemeGTK::GetWidgetBorder(nsDeviceContext* aContext, nsIFrame* aFrame,
MOZ_FALLTHROUGH;
default:
{
WidgetNodeType gtkWidgetType;
gint unusedFlags;
if (GetGtkWidgetAndState(aWidgetType, aFrame, gtkWidgetType, nullptr,
&unusedFlags)) {
moz_gtk_get_widget_border(gtkWidgetType, &aResult->left, &aResult->top,
&aResult->right, &aResult->bottom, direction);
}
GetCachedWidgetBorder(aFrame, aWidgetType, direction, aResult);
}
}
@ -1384,14 +1394,8 @@ nsNativeThemeGTK::GetWidgetPadding(nsDeviceContext* aContext,
if (!IsRegularMenuItem(aFrame))
return false;
aResult->SizeTo(0, 0, 0, 0);
WidgetNodeType gtkWidgetType;
if (GetGtkWidgetAndState(aWidgetType, aFrame, gtkWidgetType, nullptr,
nullptr)) {
moz_gtk_get_widget_border(gtkWidgetType, &aResult->left, &aResult->top,
&aResult->right, &aResult->bottom,
GetTextDirection(aFrame));
}
GetCachedWidgetBorder(aFrame, aWidgetType, GetTextDirection(aFrame),
aResult);
gint horizontal_padding;

Просмотреть файл

@ -88,6 +88,9 @@ private:
uint8_t mDisabledWidgetTypes[32];
uint8_t mSafeWidgetStates[1024]; // 256 widgets * 32 bits per widget
static const char* sDisabledEngines[];
void GetCachedWidgetBorder(nsIFrame* aFrame, uint8_t aWidgetType,
GtkTextDirection aDirection, nsIntMargin* aResult);
};
#endif