Changeset 270875 in webkit
- Timestamp:
- Dec 15, 2020 5:05:20 PM (19 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/forms/date/date-editable-components/date-editable-components-placeholder-color-expected.html (added)
-
LayoutTests/fast/forms/date/date-editable-components/date-editable-components-placeholder-color.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/html/shadow/DateTimeFieldElement.cpp (modified) (4 diffs)
-
Source/WebCore/html/shadow/DateTimeFieldElement.h (modified) (4 diffs)
-
Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp (modified) (5 diffs)
-
Source/WebCore/html/shadow/DateTimeNumericFieldElement.h (modified) (1 diff)
-
Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp (modified) (4 diffs)
-
Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h (modified) (1 diff)
-
Source/WebCore/rendering/RenderTheme.cpp (modified) (1 diff)
-
Source/WebCore/rendering/RenderTheme.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r270874 r270875 1 2020-12-15 Aditya Keerthi <akeerthi@apple.com> 2 3 [macOS] Adjust date input placeholder color based on specified text color 4 https://bugs.webkit.org/show_bug.cgi?id=219875 5 <rdar://problem/72314705> 6 7 Reviewed by Darin Adler. 8 9 Added a test to verify that the color of the placeholder changes based 10 on the input's color property. 11 12 * fast/forms/date/date-editable-components/date-editable-components-placeholder-color-expected.html: Added. 13 * fast/forms/date/date-editable-components/date-editable-components-placeholder-color.html: Added. 14 1 15 2020-12-15 Alexey Shvayka <shvaikalesh@gmail.com> 2 16 -
trunk/Source/WebCore/ChangeLog
r270874 r270875 1 2020-12-15 Aditya Keerthi <akeerthi@apple.com> 2 3 [macOS] Adjust date input placeholder color based on specified text color 4 https://bugs.webkit.org/show_bug.cgi?id=219875 5 <rdar://problem/72314705> 6 7 Reviewed by Darin Adler. 8 9 Empty date inputs currently show the current date in dark gray text as 10 a placeholder. 11 12 The existing behavior results in an issue on Nike's membership registration 13 page, where their custom placeholder and the placeholder date are visible 14 at the same time. Nike uses "color: transparent" to hide the contents of 15 the date input and display their own placeholder. However, since the 16 placeholder date is always displayed in dark gray text, both placeholders 17 are visible. 18 19 To fix, the color of the placeholder should be adjusted based on the text 20 color specified by the site author. This will ensure that 21 "color: transparent" will hide the placeholder, and also ensures the 22 placeholder better matches the style of the rest of the input. 23 24 Test: fast/forms/date/date-editable-components/date-editable-components-placeholder-color.html 25 26 * html/shadow/DateTimeFieldElement.cpp: 27 (WebCore::DateTimeFieldElement::resolveCustomStyle): 28 29 Moved custom style resolution out of the derived classes and into the 30 base class to reduce code duplication. The min-width adjustment is 31 preserved by calling the pure virtual method adjustMinWidth. The 32 new color resolution for placeholder dates is performed by obtaining 33 the text and background colors through the shadow host (the 34 HTMLInputElement) and calling into RenderTheme for the adjustment 35 algorithm. 36 37 * html/shadow/DateTimeFieldElement.h: 38 39 Made setEmptyValue and setValueAsInteger pure virtual methods since 40 the base implementation is now empty. 41 42 Introduced adjustMinWidth as a pure virtual method to allow numeric 43 and symbolic field elements to set their minimum width. This replaces 44 the need to have the derived classes implement resolveCustomStyle. 45 46 * html/shadow/DateTimeNumericFieldElement.cpp: 47 (WebCore::DateTimeNumericFieldElement::adjustMinWidth const): 48 (WebCore::DateTimeNumericFieldElement::setEmptyValue): 49 (WebCore::DateTimeNumericFieldElement::setValueAsInteger): 50 * html/shadow/DateTimeNumericFieldElement.h: 51 * html/shadow/DateTimeSymbolicFieldElement.cpp: 52 (WebCore::DateTimeSymbolicFieldElement::adjustMinWidth const): 53 (WebCore::DateTimeSymbolicFieldElement::setEmptyValue): 54 (WebCore::DateTimeSymbolicFieldElement::setValueAsInteger): 55 * html/shadow/DateTimeSymbolicFieldElement.h: 56 * rendering/RenderTheme.cpp: 57 (WebCore::RenderTheme::datePlaceholderTextColor const): 58 59 Adjust the placeholder text color based on the text and background color 60 specified. The adjustment is performed by changing the lightness of the 61 specified text color. The lightness is increased for dark text on a light 62 background, and is decreased for light text on a dark background. The 63 chosen adjustment factor ensures that a dark gray color is obtained for 64 both white on black, and black on white. 65 66 * rendering/RenderTheme.h: 67 1 68 2020-12-15 Alexey Shvayka <shvaikalesh@gmail.com> 2 69 -
trunk/Source/WebCore/html/shadow/DateTimeFieldElement.cpp
r270245 r270875 31 31 32 32 #include "CSSPropertyNames.h" 33 #include "CSSValueKeywords.h"34 33 #include "DateComponents.h" 35 34 #include "EventNames.h" … … 38 37 #include "LocalizedStrings.h" 39 38 #include "PlatformLocale.h" 39 #include "RenderStyle.h" 40 #include "RenderTheme.h" 41 #include "StyleResolver.h" 40 42 #include "Text.h" 41 43 #include <wtf/IsoMallocInlines.h> … … 60 62 { 61 63 setPseudo(pseudo); 64 } 65 66 Optional<Style::ElementStyle> DateTimeFieldElement::resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle) 67 { 68 auto elementStyle = resolveStyle(&parentStyle); 69 if (!elementStyle.renderStyle) 70 return WTF::nullopt; 71 72 auto& style = *elementStyle.renderStyle; 73 adjustMinWidth(style); 74 75 if (!hasValue() && shadowHostStyle) { 76 auto textColor = shadowHostStyle->visitedDependentColorWithColorFilter(CSSPropertyColor); 77 auto backgroundColor = shadowHostStyle->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor); 78 style.setColor(RenderTheme::singleton().datePlaceholderTextColor(textColor, backgroundColor)); 79 } 80 81 return elementStyle; 62 82 } 63 83 … … 161 181 } 162 182 163 void DateTimeFieldElement::setEmptyValue(EventBehavior)164 {165 setInlineStyleProperty(CSSPropertyColor, CSSValueDarkgray);166 }167 168 void DateTimeFieldElement::setValueAsInteger(int, EventBehavior)169 {170 if (!hasValue())171 removeInlineStyleProperty(CSSPropertyColor);172 }173 174 183 String DateTimeFieldElement::visibleValue() const 175 184 { -
trunk/Source/WebCore/html/shadow/DateTimeFieldElement.h
r270245 r270875 37 37 38 38 class DateComponents; 39 class RenderStyle; 40 39 41 struct DateTimeFieldsState; 40 42 … … 62 64 String visibleValue() const; 63 65 64 virtual void setEmptyValue(EventBehavior = DispatchNoEvent);65 virtual void setValueAsInteger(int, EventBehavior = DispatchNoEvent);66 67 66 virtual bool hasValue() const = 0; 68 67 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) = 0; 68 virtual void setEmptyValue(EventBehavior = DispatchNoEvent) = 0; 69 69 virtual void setValueAsDate(const DateComponents&) = 0; 70 virtual void setValueAsInteger(int, EventBehavior = DispatchNoEvent) = 0; 70 71 virtual void stepDown() = 0; 71 72 virtual void stepUp() = 0; … … 79 80 AtomString localeIdentifier() const; 80 81 void updateVisibleValue(EventBehavior); 82 virtual void adjustMinWidth(RenderStyle&) const = 0; 81 83 virtual int valueAsInteger() const = 0; 82 84 virtual void handleKeyboardEvent(KeyboardEvent&) = 0; … … 84 86 85 87 private: 88 Optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle&, const RenderStyle*) final; 89 86 90 bool supportsFocus() const override; 87 91 -
trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp
r270245 r270875 36 36 #include "RenderBlock.h" 37 37 #include "RenderStyle.h" 38 #include "StyleResolver.h"39 38 #include <wtf/IsoMallocInlines.h> 40 39 … … 62 61 } 63 62 64 Optional<Style::ElementStyle> DateTimeNumericFieldElement::resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle*) 63 void DateTimeNumericFieldElement::adjustMinWidth(RenderStyle& style) const 65 64 { 66 auto elementStyle = resolveStyle(&parentStyle); 67 if (!elementStyle.renderStyle) 68 return WTF::nullopt; 69 70 auto& font = elementStyle.renderStyle->fontCascade(); 65 auto& font = style.fontCascade(); 71 66 72 67 unsigned length = 2; … … 81 76 for (char c = '0'; c <= '9'; ++c) { 82 77 auto numberString = locale.convertToLocalizedNumber(makeString(pad(c, length, makeString(c)))); 83 width = std::max(width, font.width(RenderBlock::constructTextRun(numberString, *elementStyle.renderStyle)));78 width = std::max(width, font.width(RenderBlock::constructTextRun(numberString, style))); 84 79 } 85 80 86 elementStyle.renderStyle->setMinWidth({ width, Fixed }); 87 return elementStyle; 81 style.setMinWidth({ width, Fixed }); 88 82 } 89 83 … … 116 110 void DateTimeNumericFieldElement::setEmptyValue(EventBehavior eventBehavior) 117 111 { 118 DateTimeFieldElement::setEmptyValue(eventBehavior);119 120 112 m_value = 0; 121 113 m_hasValue = false; … … 126 118 void DateTimeNumericFieldElement::setValueAsInteger(int value, EventBehavior eventBehavior) 127 119 { 128 DateTimeFieldElement::setValueAsInteger(value, eventBehavior);129 130 120 m_value = m_range.clampValue(value); 131 121 m_hasValue = true; -
trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.h
r270245 r270875 63 63 64 64 private: 65 Optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle&, const RenderStyle*) final;66 67 65 // DateTimeFieldElement functions: 66 void adjustMinWidth(RenderStyle&) const final; 68 67 String value() const final; 69 68 String placeholderValue() const final; -
trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp
r270245 r270875 33 33 #include "RenderBlock.h" 34 34 #include "RenderStyle.h" 35 #include "StyleResolver.h"36 35 #include <wtf/IsoMallocInlines.h> 37 36 #include <wtf/text/StringBuilder.h> … … 51 50 } 52 51 53 Optional<Style::ElementStyle> DateTimeSymbolicFieldElement::resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle*) 52 void DateTimeSymbolicFieldElement::adjustMinWidth(RenderStyle& style) const 54 53 { 55 auto elementStyle = resolveStyle(&parentStyle); 56 if (!elementStyle.renderStyle) 57 return WTF::nullopt; 58 59 auto& font = elementStyle.renderStyle->fontCascade(); 54 auto& font = style.fontCascade(); 60 55 61 56 float width = 0; 62 57 for (auto& symbol : m_symbols) 63 width = std::max(width, font.width(RenderBlock::constructTextRun(symbol, *elementStyle.renderStyle)));58 width = std::max(width, font.width(RenderBlock::constructTextRun(symbol, style))); 64 59 65 elementStyle.renderStyle->setMinWidth({ width, Fixed }); 66 return elementStyle; 60 style.setMinWidth({ width, Fixed }); 67 61 } 68 62 … … 79 73 void DateTimeSymbolicFieldElement::setEmptyValue(EventBehavior eventBehavior) 80 74 { 81 DateTimeFieldElement::setEmptyValue(eventBehavior);82 83 75 m_selectedIndex = invalidIndex; 84 76 updateVisibleValue(eventBehavior); … … 87 79 void DateTimeSymbolicFieldElement::setValueAsInteger(int newSelectedIndex, EventBehavior eventBehavior) 88 80 { 89 DateTimeFieldElement::setValueAsInteger(newSelectedIndex, eventBehavior);90 91 81 m_selectedIndex = std::max(0, std::min(newSelectedIndex, static_cast<int>(m_symbols.size() - 1))); 92 82 updateVisibleValue(eventBehavior); -
trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h
r270245 r270875 48 48 static constexpr int invalidIndex = -1; 49 49 50 Optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle&, const RenderStyle*) final;51 52 50 // DateTimeFieldElement functions: 51 void adjustMinWidth(RenderStyle&) const final; 53 52 void stepDown() final; 54 53 void stepUp() final; -
trunk/Source/WebCore/rendering/RenderTheme.cpp
r270678 r270875 1429 1429 } 1430 1430 1431 // Value chosen to return dark gray for both white on black and black on white. 1432 constexpr float datePlaceholderColorLightnessAdjustmentFactor = 0.66f; 1433 1434 Color RenderTheme::datePlaceholderTextColor(const Color& textColor, const Color& backgroundColor) const 1435 { 1436 auto hsla = toHSLA(textColor.toSRGBALossy<float>()); 1437 if (textColor.luminance() < backgroundColor.luminance()) 1438 hsla.lightness += datePlaceholderColorLightnessAdjustmentFactor * (1.0f - hsla.lightness); 1439 else 1440 hsla.lightness *= datePlaceholderColorLightnessAdjustmentFactor; 1441 1442 return toSRGBA(hsla); 1443 } 1444 1431 1445 void RenderTheme::setCustomFocusRingColor(const Color& color) 1432 1446 { -
trunk/Source/WebCore/rendering/RenderTheme.h
r270713 r270875 164 164 // Default highlighting color for app highlights. 165 165 Color appHighlightColor(OptionSet<StyleColor::Options>) const; 166 167 Color datePlaceholderTextColor(const Color& textColor, const Color& backgroundColor) const; 166 168 167 169 virtual Color disabledTextColor(const Color& textColor, const Color& backgroundColor) const;
Note: See TracChangeset
for help on using the changeset viewer.