Commit 129efa2e by ibaker Committed by Oliver Woodman

Remove WebvttCssStyle from null-checking blacklist

PiperOrigin-RevId: 277916508
parent 2139973e
...@@ -17,7 +17,9 @@ package com.google.android.exoplayer2.text.webvtt; ...@@ -17,7 +17,9 @@ package com.google.android.exoplayer2.text.webvtt;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.text.Layout; import android.text.Layout;
import android.text.TextUtils;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
...@@ -25,6 +27,7 @@ import java.lang.annotation.RetentionPolicy; ...@@ -25,6 +27,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
/** /**
* Style object of a Css style block in a Webvtt file. * Style object of a Css style block in a Webvtt file.
...@@ -80,7 +83,7 @@ public final class WebvttCssStyle { ...@@ -80,7 +83,7 @@ public final class WebvttCssStyle {
private String targetVoice; private String targetVoice;
// Style properties. // Style properties.
private String fontFamily; @Nullable private String fontFamily;
private int fontColor; private int fontColor;
private boolean hasFontColor; private boolean hasFontColor;
private int backgroundColor; private int backgroundColor;
...@@ -91,12 +94,16 @@ public final class WebvttCssStyle { ...@@ -91,12 +94,16 @@ public final class WebvttCssStyle {
@OptionalBoolean private int italic; @OptionalBoolean private int italic;
@FontSizeUnit private int fontSizeUnit; @FontSizeUnit private int fontSizeUnit;
private float fontSize; private float fontSize;
private Layout.Alignment textAlign; @Nullable private Layout.Alignment textAlign;
// Calling reset() is forbidden because `this` isn't initialized. This can be safely suppressed
// because reset() only assigns fields, it doesn't read any.
@SuppressWarnings("nullness:method.invocation.invalid")
public WebvttCssStyle() { public WebvttCssStyle() {
reset(); reset();
} }
@EnsuresNonNull({"targetId", "targetTag", "targetClasses", "targetVoice"})
public void reset() { public void reset() {
targetId = ""; targetId = "";
targetTag = ""; targetTag = "";
...@@ -133,13 +140,12 @@ public final class WebvttCssStyle { ...@@ -133,13 +140,12 @@ public final class WebvttCssStyle {
* Returns a value in a score system compliant with the CSS Specificity rules. * Returns a value in a score system compliant with the CSS Specificity rules.
* *
* @see <a href="https://www.w3.org/TR/CSS2/cascade.html">CSS Cascading</a> * @see <a href="https://www.w3.org/TR/CSS2/cascade.html">CSS Cascading</a>
* * <p>The score works as follows:
* The score works as follows:
* <ul> * <ul>
* <li> Id match adds 0x40000000 to the score. * <li>Id match adds 0x40000000 to the score.
* <li> Each class and voice match adds 4 to the score. * <li>Each class and voice match adds 4 to the score.
* <li> Tag matching adds 2 to the score. * <li>Tag matching adds 2 to the score.
* <li> Universal selector matching scores 1. * <li>Universal selector matching scores 1.
* </ul> * </ul>
* *
* @param id The id of the cue if present, {@code null} otherwise. * @param id The id of the cue if present, {@code null} otherwise.
...@@ -148,12 +154,13 @@ public final class WebvttCssStyle { ...@@ -148,12 +154,13 @@ public final class WebvttCssStyle {
* @param voice Annotated voice if present, {@code null} otherwise. * @param voice Annotated voice if present, {@code null} otherwise.
* @return The score of the match, zero if there is no match. * @return The score of the match, zero if there is no match.
*/ */
public int getSpecificityScore(String id, String tag, String[] classes, String voice) { public int getSpecificityScore(
@Nullable String id, @Nullable String tag, String[] classes, @Nullable String voice) {
if (targetId.isEmpty() && targetTag.isEmpty() && targetClasses.isEmpty() if (targetId.isEmpty() && targetTag.isEmpty() && targetClasses.isEmpty()
&& targetVoice.isEmpty()) { && targetVoice.isEmpty()) {
// The selector is universal. It matches with the minimum score if and only if the given // The selector is universal. It matches with the minimum score if and only if the given
// element is a whole cue. // element is a whole cue.
return tag.isEmpty() ? 1 : 0; return TextUtils.isEmpty(tag) ? 1 : 0;
} }
int score = 0; int score = 0;
score = updateScoreForMatch(score, targetId, id, 0x40000000); score = updateScoreForMatch(score, targetId, id, 0x40000000);
...@@ -208,6 +215,7 @@ public final class WebvttCssStyle { ...@@ -208,6 +215,7 @@ public final class WebvttCssStyle {
return this; return this;
} }
@Nullable
public String getFontFamily() { public String getFontFamily() {
return fontFamily; return fontFamily;
} }
...@@ -251,6 +259,7 @@ public final class WebvttCssStyle { ...@@ -251,6 +259,7 @@ public final class WebvttCssStyle {
return hasBackgroundColor; return hasBackgroundColor;
} }
@Nullable
public Layout.Alignment getTextAlign() { public Layout.Alignment getTextAlign() {
return textAlign; return textAlign;
} }
...@@ -309,8 +318,8 @@ public final class WebvttCssStyle { ...@@ -309,8 +318,8 @@ public final class WebvttCssStyle {
} }
} }
private static int updateScoreForMatch(int currentScore, String target, String actual, private static int updateScoreForMatch(
int score) { int currentScore, String target, @Nullable String actual, int score) {
if (target.isEmpty() || currentScore == -1) { if (target.isEmpty() || currentScore == -1) {
return currentScore; return currentScore;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment