Bug 1736795 [Linux] Export titlebar radius as int from LookAndFeel, r=emilio

Titlebar radius is exported as integer from Gtk so there's no need to use floats here.

Differential Revision: https://phabricator.services.mozilla.com/D128993
This commit is contained in:
stransky
2021-10-20 18:01:02 +00:00
parent 8d6d9922b2
commit ba2afe8f45
6 changed files with 18 additions and 17 deletions

View File

@@ -371,7 +371,7 @@ impl Device {
/// Returns the gtk titlebar radius in CSS pixels. /// Returns the gtk titlebar radius in CSS pixels.
pub fn titlebar_radius(&self) -> f32 { pub fn titlebar_radius(&self) -> f32 {
unsafe { unsafe {
bindings::Gecko_GetLookAndFeelFloat(bindings::LookAndFeel_FloatID::TitlebarRadius as i32) bindings::Gecko_GetLookAndFeelInt(bindings::LookAndFeel_IntID::TitlebarRadius as i32) as f32
} }
} }

View File

@@ -337,6 +337,9 @@ class LookAndFeel {
/** A boolean value to determine whether a touch device is present */ /** A boolean value to determine whether a touch device is present */
TouchDeviceSupportPresent, TouchDeviceSupportPresent,
/** GTK titlebar radius */
TitlebarRadius,
/* /*
* Not an ID; used to define the range of valid IDs. Must be last. * Not an ID; used to define the range of valid IDs. Must be last.
*/ */
@@ -397,9 +400,6 @@ class LookAndFeel {
// GTK text scale factor. // GTK text scale factor.
TextScaleFactor, TextScaleFactor,
// GTK titlebar radius.
TitlebarRadius,
// Not an ID; used to define the range of valid IDs. Must be last. // Not an ID; used to define the range of valid IDs. Must be last.
End, End,
}; };

View File

@@ -832,6 +832,11 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
aResult = mSystemTheme.mHighContrast; aResult = mSystemTheme.mHighContrast;
break; break;
} }
case IntID::TitlebarRadius: {
EnsureInit();
aResult = EffectiveTheme().mTitlebarRadius;
break;
}
case IntID::AllowOverlayScrollbarsOverlap: { case IntID::AllowOverlayScrollbarsOverlap: {
aResult = 1; aResult = 1;
break; break;
@@ -872,10 +877,6 @@ nsresult nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
EnsureInit(); EnsureInit();
aResult = mSystemTheme.mCaretRatio; aResult = mSystemTheme.mCaretRatio;
break; break;
case FloatID::TitlebarRadius:
EnsureInit();
aResult = EffectiveTheme().mTitlebarRadius;
break;
case FloatID::TextScaleFactor: case FloatID::TextScaleFactor:
aResult = gfxPlatformGtk::GetFontScaleFactor(); aResult = gfxPlatformGtk::GetFontScaleFactor();
break; break;
@@ -1555,15 +1556,15 @@ void nsLookAndFeel::PerThemeData::Init() {
gtk_style_context_get_property(style, "border-radius", gtk_style_context_get_property(style, "border-radius",
GTK_STATE_FLAG_NORMAL, &value); GTK_STATE_FLAG_NORMAL, &value);
mTitlebarRadius = [&]() -> float { mTitlebarRadius = [&]() -> int {
auto type = G_VALUE_TYPE(&value); auto type = G_VALUE_TYPE(&value);
if (type == G_TYPE_INT) { if (type == G_TYPE_INT) {
return float(g_value_get_int(&value)); return g_value_get_int(&value);
} }
NS_WARNING( NS_WARNING(
nsPrintfCString("Unknown value type %lu for titlebar radius", type) nsPrintfCString("Unknown value type %lu for titlebar radius", type)
.get()); .get());
return 0.0f; return 0;
}(); }();
g_value_unset(&value); g_value_unset(&value);
} }
@@ -1827,7 +1828,7 @@ void nsLookAndFeel::PerThemeData::Init() {
GetColorPrefName(id), NS_SUCCEEDED(rv), GetColorPrefName(id), NS_SUCCEEDED(rv),
NS_SUCCEEDED(rv) ? color : 0); NS_SUCCEEDED(rv) ? color : 0);
} }
LOGLNF(" * titlebar-radius: %f\n", mTitlebarRadius); LOGLNF(" * titlebar-radius: %d\n", mTitlebarRadius);
} }
} }

View File

@@ -123,7 +123,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
nscolor mThemedScrollbarThumbInactive = kBlack; nscolor mThemedScrollbarThumbInactive = kBlack;
float mCaretRatio = 0.0f; float mCaretRatio = 0.0f;
float mTitlebarRadius = 0.0f; int32_t mTitlebarRadius = 0;
char16_t mInvisibleCharacter = 0; char16_t mInvisibleCharacter = 0;
bool mMenuSupportsDrag = false; bool mMenuSupportsDrag = false;

View File

@@ -6102,8 +6102,7 @@ void nsWindow::UpdateWindowDraggingRegion(
} }
LayoutDeviceIntCoord nsWindow::GetTitlebarRadius() { LayoutDeviceIntCoord nsWindow::GetTitlebarRadius() {
int32_t cssCoord = int32_t cssCoord = LookAndFeel::GetInt(LookAndFeel::IntID::TitlebarRadius);
std::ceil(LookAndFeel::GetFloat(LookAndFeel::FloatID::TitlebarRadius));
return GdkCoordToDevicePixels(cssCoord); return GdkCoordToDevicePixels(cssCoord);
} }
@@ -6359,7 +6358,8 @@ LayoutDeviceIntRect nsWindow::GetTitlebarRect() {
return LayoutDeviceIntRect(); return LayoutDeviceIntRect();
} }
return LayoutDeviceIntRect(0, 0, mBounds.width, GetTitlebarRadius()); int radius = DoDrawTilebarCorners() ? int(GetTitlebarRadius()) : 0;
return LayoutDeviceIntRect(0, 0, mBounds.width, radius);
} }
void nsWindow::UpdateTitlebarTransparencyBitmap() { void nsWindow::UpdateTitlebarTransparencyBitmap() {

View File

@@ -175,6 +175,7 @@ static const char sIntPrefs[][43] = {
"ui.systemVerticalScrollbarWidth", "ui.systemVerticalScrollbarWidth",
"ui.systemHorizontalScrollbarHeight", "ui.systemHorizontalScrollbarHeight",
"ui.touchDeviceSupportPresent", "ui.touchDeviceSupportPresent",
"ui.titlebarRadius",
}; };
static_assert(ArrayLength(sIntPrefs) == size_t(LookAndFeel::IntID::End), static_assert(ArrayLength(sIntPrefs) == size_t(LookAndFeel::IntID::End),
@@ -188,7 +189,6 @@ static const char sFloatPrefs[][37] = {
"ui.SpellCheckerUnderlineRelativeSize", "ui.SpellCheckerUnderlineRelativeSize",
"ui.caretAspectRatio", "ui.caretAspectRatio",
"ui.textScaleFactor", "ui.textScaleFactor",
"ui.titlebarRadius",
}; };
// clang-format on // clang-format on