Changeset 213285 in webkit
- Timestamp:
- Mar 2, 2017 10:08:41 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r213284 r213285 1 2017-03-02 Jon Lee <jonlee@apple.com> 2 3 Improve consistency of captions rendering on Mac 4 https://bugs.webkit.org/show_bug.cgi?id=169071 5 6 Reviewed by Eric Carlson. 7 8 * page/CaptionUserPreferencesMediaAF.h: 9 (WebCore::CaptionUserPreferencesMediaAF::captionsEdgeColorForTextColor): Deleted. 10 (WebCore::CaptionUserPreferencesMediaAF::cssPropertyWithTextEdgeColor): Deleted. 11 12 * page/CaptionUserPreferencesMediaAF.cpp: 13 (WebCore::appendCSS): Helper function to add a CSS rule with a provided StringBuilder. 14 (WebCore::CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS): Refactor to use 15 appendCSS. 16 (WebCore::CaptionUserPreferencesMediaAF::colorPropertyCSS): Ditto. 17 (WebCore::CaptionUserPreferencesMediaAF::captionsTextEdgeCSS): Update text edge styles. 18 - Add a blur to the shadow 19 - Drop shadow style includes 1px text border 20 - Always use black for the text edge color 21 Also convert the stroke rules to using the CSS property and values instead of straight strings. 22 (WebCore::CaptionUserPreferencesMediaAF::captionsStyleSheetOverride): Fly-by fix of a typo. 23 1 24 2017-03-02 Chris Dumez <cdumez@apple.com> 2 25 -
trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp
r212562 r213285 328 328 return colorPropertyCSS(CSSPropertyColor, textColor, important); 329 329 } 330 331 static void appendCSS(StringBuilder& builder, CSSPropertyID id, const String& value, bool important) 332 { 333 builder.append(getPropertyNameString(id)); 334 builder.append(':'); 335 builder.append(value); 336 if (important) 337 builder.appendLiteral(" !important"); 338 builder.append(';'); 339 } 330 340 331 341 String CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS() const … … 337 347 338 348 StringBuilder builder; 339 builder.append(getPropertyNameString(CSSPropertyBorderRadius)); 340 builder.append(String::format(":%.02fpx", radius)); 341 if (behavior == kMACaptionAppearanceBehaviorUseValue) 342 builder.appendLiteral(" !important"); 343 builder.append(';'); 344 349 appendCSS(builder, CSSPropertyBorderRadius, String::format("%.02fpx", radius), behavior == kMACaptionAppearanceBehaviorUseValue); 345 350 return builder.toString(); 346 351 } 347 348 Color CaptionUserPreferencesMediaAF::captionsEdgeColorForTextColor(const Color& textColor) const 349 { 350 int distanceFromWhite = differenceSquared(textColor, Color::white); 351 int distanceFromBlack = differenceSquared(textColor, Color::black); 352 353 if (distanceFromWhite < distanceFromBlack) 354 return textColor.dark(); 355 356 return textColor.light(); 357 } 358 359 String CaptionUserPreferencesMediaAF::cssPropertyWithTextEdgeColor(CSSPropertyID id, const String& value, const Color& textColor, bool important) const 352 353 String CaptionUserPreferencesMediaAF::colorPropertyCSS(CSSPropertyID id, const Color& color, bool important) const 360 354 { 361 355 StringBuilder builder; 362 363 builder.append(getPropertyNameString(id)); 364 builder.append(':'); 365 builder.append(value); 366 builder.append(' '); 367 builder.append(captionsEdgeColorForTextColor(textColor).serialized()); 368 if (important) 369 builder.appendLiteral(" !important"); 370 builder.append(';'); 371 if (id == CSSPropertyWebkitTextStroke) { 372 builder.append(" paint-order: stroke;"); 373 builder.append(" stroke-linejoin: round;"); 374 builder.append(" stroke-linecap: round;"); 375 } 376 377 return builder.toString(); 378 } 379 380 String CaptionUserPreferencesMediaAF::colorPropertyCSS(CSSPropertyID id, const Color& color, bool important) const 381 { 382 StringBuilder builder; 383 384 builder.append(getPropertyNameString(id)); 385 builder.append(':'); 386 builder.append(color.serialized()); 387 if (important) 388 builder.appendLiteral(" !important"); 389 builder.append(';'); 390 356 appendCSS(builder, id, color.serialized(), important); 391 357 return builder.toString(); 392 358 } … … 418 384 String CaptionUserPreferencesMediaAF::captionsTextEdgeCSS() const 419 385 { 420 static NeverDestroyed<const String> edgeStyleRaised(ASCIILiteral(" -.05em -.05em 0 ")); 421 static NeverDestroyed<const String> edgeStyleDepressed(ASCIILiteral(" .05em .05em 0 ")); 422 static NeverDestroyed<const String> edgeStyleDropShadow(ASCIILiteral(" .075em .075em 0 ")); 423 424 bool unused; 425 Color color = captionsTextColor(unused); 426 if (!color.isValid()) 427 color = Color { Color::black }; 428 color = captionsEdgeColorForTextColor(color); 386 static NeverDestroyed<const String> edgeStyleRaised(ASCIILiteral(" -.1em -.1em .16em ")); 387 static NeverDestroyed<const String> edgeStyleDepressed(ASCIILiteral(" .1em .1em .16em ")); 388 static NeverDestroyed<const String> edgeStyleDropShadow(ASCIILiteral(" 0 .1em .16em ")); 429 389 430 390 MACaptionAppearanceBehavior behavior; 431 391 MACaptionAppearanceTextEdgeStyle textEdgeStyle = MACaptionAppearanceGetTextEdgeStyle(kMACaptionAppearanceDomainUser, &behavior); 432 switch (textEdgeStyle) { 433 case kMACaptionAppearanceTextEdgeStyleUndefined: 434 case kMACaptionAppearanceTextEdgeStyleNone: 392 393 if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleUndefined || textEdgeStyle == kMACaptionAppearanceTextEdgeStyleNone) 435 394 return emptyString(); 436 437 case kMACaptionAppearanceTextEdgeStyleRaised: 438 return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleRaised, color, behavior == kMACaptionAppearanceBehaviorUseValue); 439 case kMACaptionAppearanceTextEdgeStyleDepressed: 440 return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDepressed, color, behavior == kMACaptionAppearanceBehaviorUseValue); 441 case kMACaptionAppearanceTextEdgeStyleDropShadow: 442 return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDropShadow, color, behavior == kMACaptionAppearanceBehaviorUseValue); 443 case kMACaptionAppearanceTextEdgeStyleUniform: 444 return cssPropertyWithTextEdgeColor(CSSPropertyWebkitTextStroke, strokeWidth(), color, behavior == kMACaptionAppearanceBehaviorUseValue); 445 446 default: 447 ASSERT_NOT_REACHED(); 448 break; 449 } 450 451 return emptyString(); 395 396 StringBuilder builder; 397 bool important = behavior == kMACaptionAppearanceBehaviorUseValue; 398 if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleRaised) 399 appendCSS(builder, CSSPropertyTextShadow, makeString(edgeStyleRaised.get(), " black"), important); 400 else if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleDepressed) 401 appendCSS(builder, CSSPropertyTextShadow, makeString(edgeStyleDepressed.get(), " black"), important); 402 else if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleDropShadow) 403 appendCSS(builder, CSSPropertyTextShadow, makeString(edgeStyleDropShadow.get(), " black"), important); 404 405 if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleDropShadow || textEdgeStyle == kMACaptionAppearanceTextEdgeStyleUniform) { 406 if (textEdgeStyle == kMACaptionAppearanceTextEdgeStyleDropShadow) 407 appendCSS(builder, CSSPropertyWebkitTextStroke, ".03em black", important); 408 else 409 appendCSS(builder, CSSPropertyWebkitTextStroke, makeString(strokeWidth(), " black"), important); 410 411 appendCSS(builder, CSSPropertyPaintOrder, getValueName(CSSValueStroke), important); 412 appendCSS(builder, CSSPropertyStrokeLinejoin, getValueName(CSSValueRound), important); 413 appendCSS(builder, CSSPropertyStrokeLinecap, getValueName(CSSValueRound), important); 414 } 415 416 return builder.toString(); 452 417 } 453 418 … … 621 586 #endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 622 587 623 LOG(Media, "CaptionUserPreferencesMediaAF::captionsStyleSheetOverrideSetting s ytle to:\n%s", captionsOverrideStyleSheet.toString().utf8().data());588 LOG(Media, "CaptionUserPreferencesMediaAF::captionsStyleSheetOverrideSetting style to:\n%s", captionsOverrideStyleSheet.toString().utf8().data()); 624 589 625 590 return captionsOverrideStyleSheet.toString(); -
trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h
r211803 r213285 80 80 Color captionsTextColor(bool&) const; 81 81 String captionsDefaultFontCSS() const; 82 Color captionsEdgeColorForTextColor(const Color&) const;83 82 String windowRoundedCornerRadiusCSS() const; 84 83 String strokeWidth() const; 85 84 String captionsTextEdgeCSS() const; 86 String cssPropertyWithTextEdgeColor(CSSPropertyID, const String&, const Color&, bool) const;87 85 String colorPropertyCSS(CSSPropertyID, const Color&, bool) const; 88 86 Timer m_updateStyleSheetTimer;
Note: See TracChangeset
for help on using the changeset viewer.