Skip to content

Commit

Permalink
Bug 1678540 - Refactor nsXPLookAndFeel::GetIntImpl etc. r=spohl
Browse files Browse the repository at this point in the history
This will allow calling into NativeGetInt etc. to get native LookAndFeel values without
looking at the prefs.

Differential Revision: https://phabricator.services.mozilla.com/D97725
  • Loading branch information
heycam committed Nov 20, 2020
1 parent 727f6c4 commit 53d32e3
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 123 deletions.
17 changes: 6 additions & 11 deletions widget/android/nsLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,8 @@ nsresult nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
return rv;
}

nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
nsresult rv = nsXPLookAndFeel::GetIntImpl(aID, aResult);
if (NS_SUCCEEDED(rv)) return rv;

rv = NS_OK;
nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
nsresult rv = NS_OK;

switch (aID) {
case IntID::ScrollButtonLeftMouseButtonAction:
Expand Down Expand Up @@ -432,10 +429,8 @@ nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
return rv;
}

nsresult nsLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
nsresult rv = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
if (NS_SUCCEEDED(rv)) return rv;
rv = NS_OK;
nsresult nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
nsresult rv = NS_OK;

switch (aID) {
case FloatID::IMEUnderlineRelativeSize:
Expand All @@ -455,8 +450,8 @@ nsresult nsLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
}

/*virtual*/
bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) {
bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) {
aFontName.AssignLiteral("\"Roboto\"");
aFontStyle.style = FontSlantStyle::Normal();
aFontStyle.weight = FontWeight::Normal();
Expand Down
10 changes: 5 additions & 5 deletions widget/android/nsLookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class nsLookAndFeel final : public nsXPLookAndFeel {

void NativeInit() final;
virtual void RefreshImpl() override;
virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
virtual nsresult GetIntImpl(IntID aID, int32_t& aResult) override;
virtual nsresult GetFloatImpl(FloatID aID, float& aResult) override;
virtual bool GetFontImpl(FontID aID, nsString& aName,
gfxFontStyle& aStyle) override;
nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
nsresult NativeGetFloat(FloatID aID, float& aResult) override;
nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
bool NativeGetFont(FontID aID, nsString& aName,
gfxFontStyle& aStyle) override;
virtual bool GetEchoPasswordImpl() override;
virtual uint32_t GetPasswordMaskDelayImpl() override;
virtual char16_t GetPasswordCharacterImpl() override;
Expand Down
10 changes: 5 additions & 5 deletions widget/cocoa/nsLookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class nsLookAndFeel final : public nsXPLookAndFeel {

void NativeInit() final;
virtual void RefreshImpl() override;
virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
virtual nsresult GetIntImpl(IntID aID, int32_t& aResult) override;
virtual nsresult GetFloatImpl(FloatID aID, float& aResult) override;
virtual bool GetFontImpl(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) override;
nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
nsresult NativeGetFloat(FloatID aID, float& aResult) override;
bool NativeGetFont(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) override;

virtual char16_t GetPasswordCharacterImpl() override {
// unicode value for the bullet character, used for password textfields.
Expand Down
14 changes: 5 additions & 9 deletions widget/cocoa/nsLookAndFeel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,10 @@ static nscolor GetColorFromNSColorWithAlpha(NSColor* aColor, float alpha) {
return res;
}

nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;

nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
if (NS_SUCCEEDED(res)) return res;
res = NS_OK;
nsresult res = NS_OK;

switch (aID) {
case IntID::ScrollButtonLeftMouseButtonAction:
Expand Down Expand Up @@ -592,10 +590,8 @@ static nscolor GetColorFromNSColorWithAlpha(NSColor* aColor, float alpha) {
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}

nsresult nsLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
if (NS_SUCCEEDED(res)) return res;
res = NS_OK;
nsresult nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
nsresult res = NS_OK;

switch (aID) {
case FloatID::IMEUnderlineRelativeSize:
Expand Down Expand Up @@ -625,7 +621,7 @@ static nscolor GetColorFromNSColorWithAlpha(NSColor* aColor, float alpha) {
return !![[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
}

bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle) {
bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName, gfxFontStyle& aFontStyle) {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;

// hack for now
Expand Down
22 changes: 7 additions & 15 deletions widget/gtk/nsLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,9 @@ static int32_t ConvertGTKStepperStyleToMozillaScrollArrowStyle(
mozilla::LookAndFeel::eScrollArrow_StartForward);
}

nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
nsresult res = NS_OK;

res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
if (NS_SUCCEEDED(res)) return res;
res = NS_OK;

// We use delayed initialization by EnsureInit() here
// to make sure mozilla::Preferences is available (Bug 115807).
// IntID::UseAccessibilityTheme is requested before user preferences
Expand Down Expand Up @@ -813,12 +809,8 @@ nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
return res;
}

nsresult nsLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
nsresult res = NS_OK;
res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
if (NS_SUCCEEDED(res)) return res;
res = NS_OK;

nsresult nsLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
nsresult rv = NS_OK;
switch (aID) {
case FloatID::IMEUnderlineRelativeSize:
aResult = 1.0f;
Expand All @@ -832,9 +824,9 @@ nsresult nsLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
break;
default:
aResult = -1.0;
res = NS_ERROR_FAILURE;
rv = NS_ERROR_FAILURE;
}
return res;
return rv;
}

static void GetSystemFontInfo(GtkStyleContext* aStyle, nsString* aFontName,
Expand Down Expand Up @@ -873,8 +865,8 @@ static void GetSystemFontInfo(GtkStyleContext* aStyle, nsString* aFontName,
pango_font_description_free(desc);
}

bool nsLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) {
bool nsLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) {
switch (aID) {
case FontID::Menu: // css2
case FontID::PullDownMenu: // css3
Expand Down
8 changes: 4 additions & 4 deletions widget/gtk/nsLookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class nsLookAndFeel final : public nsXPLookAndFeel {

void NativeInit() final;
void RefreshImpl() override;
nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
nsresult NativeGetFloat(FloatID aID, float& aResult) override;
nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
nsresult GetIntImpl(IntID aID, int32_t& aResult) override;
nsresult GetFloatImpl(FloatID aID, float& aResult) override;
bool GetFontImpl(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) override;
bool NativeGetFont(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) override;

char16_t GetPasswordCharacterImpl() override;
bool GetEchoPasswordImpl() override;
Expand Down
10 changes: 5 additions & 5 deletions widget/headless/HeadlessLookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class HeadlessLookAndFeel : public nsXPLookAndFeel {
HeadlessLookAndFeel();
virtual ~HeadlessLookAndFeel();

virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
void NativeInit() final{};
virtual nsresult GetIntImpl(IntID aID, int32_t& aResult) override;
virtual nsresult GetFloatImpl(FloatID aID, float& aResult) override;
virtual bool GetFontImpl(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) override;
virtual nsresult NativeGetInt(IntID aID, int32_t& aResult) override;
virtual nsresult NativeGetFloat(FloatID aID, float& aResult) override;
virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) override;
virtual bool NativeGetFont(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) override;

virtual void RefreshImpl() override;
virtual char16_t GetPasswordCharacterImpl() override;
Expand Down
22 changes: 9 additions & 13 deletions widget/headless/HeadlessLookAndFeelGTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,8 @@ nsresult HeadlessLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor) {
return res;
}

nsresult HeadlessLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
if (NS_SUCCEEDED(res)) return res;
res = NS_OK;

nsresult HeadlessLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) {
nsresult res = NS_OK;
// These values should be sane defaults for headless mode under GTK.
switch (aID) {
case IntID::CaretBlinkTime:
Expand Down Expand Up @@ -301,18 +298,16 @@ nsresult HeadlessLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
break;
default:
NS_WARNING(
"HeadlessLookAndFeel::GetIntImpl called with an unrecognized aID");
"HeadlessLookAndFeel::NativeGetInt called with an unrecognized aID");
aResult = 0;
res = NS_ERROR_FAILURE;
break;
}
return res;
}

nsresult HeadlessLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
if (NS_SUCCEEDED(res)) return res;
res = NS_OK;
nsresult HeadlessLookAndFeel::NativeGetFloat(FloatID aID, float& aResult) {
nsresult res = NS_OK;

// Hardcoded values for GTK.
switch (aID) {
Expand All @@ -329,7 +324,8 @@ nsresult HeadlessLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
break;
default:
NS_WARNING(
"HeadlessLookAndFeel::GetFloatImpl called with an unrecognized aID");
"HeadlessLookAndFeel::NativeGetFloat called with an unrecognized "
"aID");
aResult = -1.0;
res = NS_ERROR_FAILURE;
break;
Expand All @@ -338,8 +334,8 @@ nsresult HeadlessLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
return res;
}

bool HeadlessLookAndFeel::GetFontImpl(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) {
bool HeadlessLookAndFeel::NativeGetFont(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle) {
// Default to san-serif for everything.
aFontStyle.style = FontSlantStyle::Normal();
aFontStyle.weight = FontWeight::Normal();
Expand Down
26 changes: 13 additions & 13 deletions widget/nsXPLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,9 @@ nscolor nsXPLookAndFeel::GetStandinForNativeColor(ColorID aID) {
// otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
// platform-specific nsLookAndFeel should use its own values instead.
//
nsresult nsXPLookAndFeel::GetColorImpl(ColorID aID,
bool aUseStandinsForNativeColors,
nscolor& aResult) {
nsresult nsXPLookAndFeel::GetColorValue(ColorID aID,
bool aUseStandinsForNativeColors,
nscolor& aResult) {
if (!sInitialized) Init();

// define DEBUG_SYSTEM_COLOR_USE if you want to debug system color
Expand Down Expand Up @@ -947,7 +947,7 @@ nsresult nsXPLookAndFeel::GetColorImpl(ColorID aID,
return NS_ERROR_NOT_AVAILABLE;
}

nsresult nsXPLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
nsresult nsXPLookAndFeel::GetIntValue(IntID aID, int32_t& aResult) {
if (!sInitialized) Init();

for (unsigned int i = 0; i < ArrayLength(sIntPrefs); ++i) {
Expand All @@ -957,10 +957,10 @@ nsresult nsXPLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
}
}

return NS_ERROR_NOT_AVAILABLE;
return NativeGetInt(aID, aResult);
}

nsresult nsXPLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
nsresult nsXPLookAndFeel::GetFloatValue(FloatID aID, float& aResult) {
if (!sInitialized) Init();

for (unsigned int i = 0; i < ArrayLength(sFloatPrefs); ++i) {
Expand All @@ -970,7 +970,7 @@ nsresult nsXPLookAndFeel::GetFloatImpl(FloatID aID, float& aResult) {
}
}

return NS_ERROR_NOT_AVAILABLE;
return NativeGetFloat(aID, aResult);
}

void nsXPLookAndFeel::RefreshImpl() {
Expand Down Expand Up @@ -1009,7 +1009,7 @@ void nsXPLookAndFeel::RecordTelemetry() {
int32_t i;
Telemetry::ScalarSet(
Telemetry::ScalarID::WIDGET_DARK_MODE,
NS_SUCCEEDED(GetIntImpl(IntID::SystemUsesDarkTheme, i)) && i != 0);
NS_SUCCEEDED(GetIntValue(IntID::SystemUsesDarkTheme, i)) && i != 0);

RecordLookAndFeelSpecificTelemetry();
}
Expand All @@ -1026,28 +1026,28 @@ void LookAndFeel::NotifyChangedAllWindows(widget::ThemeChangeKind aKind) {

// static
nsresult LookAndFeel::GetColor(ColorID aID, nscolor* aResult) {
return nsLookAndFeel::GetInstance()->GetColorImpl(aID, false, *aResult);
return nsLookAndFeel::GetInstance()->GetColorValue(aID, false, *aResult);
}

nsresult LookAndFeel::GetColor(ColorID aID, bool aUseStandinsForNativeColors,
nscolor* aResult) {
return nsLookAndFeel::GetInstance()->GetColorImpl(
return nsLookAndFeel::GetInstance()->GetColorValue(
aID, aUseStandinsForNativeColors, *aResult);
}

// static
nsresult LookAndFeel::GetInt(IntID aID, int32_t* aResult) {
return nsLookAndFeel::GetInstance()->GetIntImpl(aID, *aResult);
return nsLookAndFeel::GetInstance()->GetIntValue(aID, *aResult);
}

// static
nsresult LookAndFeel::GetFloat(FloatID aID, float* aResult) {
return nsLookAndFeel::GetInstance()->GetFloatImpl(aID, *aResult);
return nsLookAndFeel::GetInstance()->GetFloatValue(aID, *aResult);
}

// static
bool LookAndFeel::GetFont(FontID aID, nsString& aName, gfxFontStyle& aStyle) {
return nsLookAndFeel::GetInstance()->GetFontImpl(aID, aName, aStyle);
return nsLookAndFeel::GetInstance()->GetFontValue(aID, aName, aStyle);
}

// static
Expand Down
35 changes: 20 additions & 15 deletions widget/nsXPLookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,27 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {

void Init();

// These functions will return a value specified by an override pref, if it
// exists, and otherwise will call into the NativeGetXxx function to get the
// platform-specific value.
//
// All these routines will return NS_OK if they have a value,
// in which case the nsLookAndFeel should use that value;
// otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
// platform-specific nsLookAndFeel should use its own values instead.
//
nsresult GetColorImpl(ColorID aID, bool aUseStandinsForNativeColors,
nscolor& aResult);
virtual nsresult GetIntImpl(IntID aID, int32_t& aResult);
virtual nsresult GetFloatImpl(FloatID aID, float& aResult);

// This one is different: there are no override prefs (fixme?), so
// there is no XP implementation, only per-system impls.
virtual bool GetFontImpl(FontID aID, nsString& aName,
gfxFontStyle& aStyle) = 0;
// NS_ERROR_NOT_AVAILABLE is returned if there is neither an override pref or
// a platform-specific value.
nsresult GetColorValue(ColorID aID, bool aUseStandinsForNativeColors,
nscolor& aResult);
nsresult GetIntValue(IntID aID, int32_t& aResult);
nsresult GetFloatValue(FloatID aID, float& aResult);
// Same, but returns false if there is no platform-specific value.
// (There are no override prefs for font values.)
bool GetFontValue(FontID aID, nsString& aName, gfxFontStyle& aStyle) {
return NativeGetFont(aID, aName, aStyle);
}

virtual nsresult NativeGetInt(IntID aID, int32_t& aResult) = 0;
virtual nsresult NativeGetFloat(FloatID aID, float& aResult) = 0;
virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) = 0;
virtual bool NativeGetFont(FontID aID, nsString& aName,
gfxFontStyle& aStyle) = 0;

virtual void RefreshImpl();

Expand Down Expand Up @@ -92,7 +98,6 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {
void InitFromPref(nsLookAndFeelIntPref* aPref);
void InitFromPref(nsLookAndFeelFloatPref* aPref);
void InitColorFromPref(int32_t aIndex);
virtual nsresult NativeGetColor(ColorID aID, nscolor& aResult) = 0;
bool IsSpecialColor(ColorID aID, nscolor& aColor);
bool ColorIsNotCSSAccessible(ColorID aID);
nscolor GetStandinForNativeColor(ColorID aID);
Expand Down
Loading

0 comments on commit 53d32e3

Please sign in to comment.