Skip to content

Commit

Permalink
Bug 1720792: Add MozNativevisitedhyperlinktext color, use it to style…
Browse files Browse the repository at this point in the history
… visited links r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D120657
  • Loading branch information
MReschenberg committed Jul 28, 2021
1 parent 6477942 commit a27ddec
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
27 changes: 19 additions & 8 deletions layout/style/PreferenceSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,29 @@ void PreferenceSheet::Prefs::Load(bool aIsChrome) {
useStandins ? ColorID::Window : ColorID::WindowBackground, scheme,
standins, mColors.mDefaultBackground);
mColors.mLink = LookAndFeel::Color(ColorID::MozNativehyperlinktext, scheme,
standins, mColors.mLink);
standins, mColors.mLink);

if (auto color = LookAndFeel::GetColor(
ColorID::MozNativevisitedhyperlinktext, scheme, standins)) {
// If the system provides a visited link color, we should use it.
mColors.mVisitedLink = *color;
} else if (mUseAccessibilityTheme) {
// The fallback visited link color on HCM (if the system doesn't provide
// one) is produced by preserving the foreground's green and averaging the
// foreground and background for the red and blue. This is how IE and
// Edge do it too.
mColors.mVisitedLink = NS_RGB(AVG2(NS_GET_R(mColors.mDefault),
NS_GET_R(mColors.mDefaultBackground)),
NS_GET_G(mColors.mDefault),
AVG2(NS_GET_B(mColors.mDefault),
NS_GET_B(mColors.mDefaultBackground)));
} else {
// Otherwise we keep the default visited link color
}
}

if (mUseAccessibilityTheme && !useStandins) {
mColors.mActiveLink = mColors.mLink;
// Visited link color is produced by preserving the foreground's green
// and averaging the foreground and background for the red and blue.
// This is how IE and Edge do it too.
mColors.mVisitedLink = NS_RGB(
AVG2(NS_GET_R(mColors.mDefault), NS_GET_R(mColors.mDefaultBackground)),
NS_GET_G(mColors.mDefault),
AVG2(NS_GET_B(mColors.mDefault), NS_GET_B(mColors.mDefaultBackground)));
} else {
GetColor("browser.active_color", mColors.mActiveLink);
GetColor("browser.visited_color", mColors.mVisitedLink);
Expand Down
1 change: 1 addition & 0 deletions layout/style/test/test_non_content_accessible_values.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"-moz-colheadertext",
"-moz-system-color(highlight, light)",
"-moz-system-color(highlight, dark)",
"-moz-nativevisitedhyperlinktext",
"text-select-foreground",
"text-select-background",
"text-select-background-disabled",
Expand Down
4 changes: 4 additions & 0 deletions servo/components/style/values/specified/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ pub enum SystemColor {
/// colors.
MozNativehyperlinktext,

/// As above, but visited link color.
#[css(skip)]
MozNativevisitedhyperlinktext,

#[parse(aliases = "-moz-hyperlinktext")]
Linktext,
#[parse(aliases = "-moz-activehyperlinktext")]
Expand Down
5 changes: 5 additions & 0 deletions widget/cocoa/SDKDeclarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@

using NSAppearanceName = NSString*;

@interface NSColor (NSColor10_13)
// "Available in 10.10", but not present in any SDK less than 10.13
@property(class, strong, readonly) NSColor* systemPurpleColor NS_AVAILABLE_MAC(10_10);
@end

#endif

#if !defined(MAC_OS_X_VERSION_10_14) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_14
Expand Down
4 changes: 4 additions & 0 deletions widget/cocoa/nsLookAndFeel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "SDKDeclarations.h"

#import <Cocoa/Cocoa.h>
#import <AppKit/NSColor.h>

// This must be included last:
#include "nsObjCExceptions.h"
Expand Down Expand Up @@ -337,6 +338,9 @@ static nscolor GetColorFromNSColorWithCustomAlpha(NSColor* aColor, float alpha)
case ColorID::MozNativehyperlinktext:
color = GetColorFromNSColor(NSColor.linkColor);
break;
case ColorID::MozNativevisitedhyperlinktext:
color = GetColorFromNSColor(NSColor.systemPurpleColor);
break;
// The following colors are supposed to be used as font-smoothing background
// colors, in the chrome-only -moz-font-smoothing-background-color property.
// This property is used for text on "vibrant" -moz-appearances.
Expand Down
2 changes: 2 additions & 0 deletions widget/nsXPLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ static const char sColorPrefs[][41] = {
"ui.-moz-win-mediatext",
"ui.-moz-win-communicationstext",
"ui.-moz-nativehyperlinktext",
"ui.-moz-nativevisitedhyperlinktext",
"ui.-moz-hyperlinktext",
"ui.-moz-activehyperlinktext",
"ui.-moz-visitedhyperlinktext",
Expand Down Expand Up @@ -579,6 +580,7 @@ nscolor nsXPLookAndFeel::GetStandinForNativeColor(ColorID aID) {
COLOR(MozWinMediatext, 0xFF, 0xFF, 0xFF)
COLOR(MozWinCommunicationstext, 0xFF, 0xFF, 0xFF)
COLOR(MozNativehyperlinktext, 0x00, 0x66, 0xCC)
COLOR(MozNativevisitedhyperlinktext, 0x55, 0x1A, 0x8B)
COLOR(MozComboboxtext, 0x00, 0x00, 0x00)
COLOR(MozCombobox, 0xFF, 0xFF, 0xFF)
default:
Expand Down
5 changes: 5 additions & 0 deletions widget/uikit/nsLookAndFeel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ static nscolor GetColorFromUIColor(UIColor* aColor) {
// There appears to be no available system defined color. HARDCODING to the appropriate color.
aResult = NS_RGB(0x14, 0x4F, 0xAE);
break;
case ColorID::MozNativevisitedhyperlinktext:
// Safari defaults to the MacOS color implementation for visited links, which in turn uses
// systemPurpleColor, so we do the same here.
aResult = GetColorFromUIColor([UIColor systemPurpleColor]);
break;
default:
NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about");
aResult = NS_RGB(0xff, 0xff, 0xff);
Expand Down

0 comments on commit a27ddec

Please sign in to comment.