Skip to content

Commit

Permalink
[refactor] make few fields in class PageBox final
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Oct 12, 2024
1 parent 19a47b5 commit ccc5ce7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.xhtmlrenderer.context;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -165,7 +167,9 @@ public CascadedStyle getCascadedStyle(@Nullable Element e, boolean restyle) {
return _matcher.getCascadedStyle(e, restyle);
}

public PageInfo getPageStyle(String pageName, String pseudoPage) {
@NonNull
@CheckReturnValue
public PageInfo getPageStyle(@Nullable String pageName, String pseudoPage) {
return _matcher.getPageCascadedStyle(pageName, pseudoPage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
package org.xhtmlrenderer.css.newmatch;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -105,7 +107,9 @@ public CascadedStyle getPECascadedStyle(Element e, String pseudoElement) {
}
}

public PageInfo getPageCascadedStyle(String pageName, String pseudoPage) {
@NonNull
@CheckReturnValue
public PageInfo getPageCascadedStyle(@Nullable String pageName, String pseudoPage) {
List<PropertyDeclaration> props = new ArrayList<>();
Map<MarginBoxName, List<PropertyDeclaration>> marginBoxes = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.xhtmlrenderer.css.sheet;

import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.css.constants.MarginBoxName;
import org.xhtmlrenderer.css.sheet.StylesheetInfo.Origin;

Expand Down Expand Up @@ -110,7 +111,7 @@ public long getOrder() {
return result;
}

public boolean applies(String pageName, String pseudoPage) {
public boolean applies(@Nullable String pageName, String pseudoPage) {
if (_name == null && _pseudoPage == null) {
return true;
} else if (_name == null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
package org.xhtmlrenderer.css.style;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.xhtmlrenderer.css.constants.CSSName;
import org.xhtmlrenderer.css.constants.IdentValue;
Expand Down Expand Up @@ -182,6 +184,8 @@ private static boolean checkBordersAllowed(IdentValue display) {
* @param matched the CascadedStyle to apply
* @return The derived child style
*/
@NonNull
@CheckReturnValue
public CalculatedStyle deriveStyle(CascadedStyle matched) {
String fingerprint = matched.getFingerprint();
return _childCache.computeIfAbsent(fingerprint, (key) -> new CalculatedStyle(this, matched));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,6 @@ public void removeLastPage() {

@CheckReturnValue
public static PageBox createPageBox(CssContext c, String pseudoPage) {
PageBox result = new PageBox();

String pageName = null;
// HACK We only create pages during layout, but the OutputDevice
// queries page positions and since pages are created lazily, changing
Expand All @@ -788,13 +786,8 @@ public static PageBox createPageBox(CssContext c, String pseudoPage) {
}

PageInfo pageInfo = c.getCss().getPageStyle(pageName, pseudoPage);
result.setPageInfo(pageInfo);

CalculatedStyle cs = new EmptyStyle().deriveStyle(pageInfo.getPageStyle());
result.setStyle(cs);
result.setOuterPageWidth(result.getWidth(c));

return result;
return new PageBox(pageInfo, c, cs);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.xhtmlrenderer.render;

import com.google.errorprone.annotations.CheckReturnValue;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.w3c.dom.css.CSSPrimitiveValue;
Expand Down Expand Up @@ -74,8 +75,7 @@ public class PageBox {

private static final int LEADING_TRAILING_SPLIT = 5;

@Nullable
private CalculatedStyle _style;
private final CalculatedStyle _style;

private int _top;
private int _bottom;
Expand All @@ -85,20 +85,26 @@ public class PageBox {

private int _pageNo;

private int _outerPageWidth;
private final int _outerPageWidth;

@Nullable
private PageDimensions _pageDimensions;

@Nullable
private PageInfo _pageInfo;
@NonNull
private final PageInfo _pageInfo;

@Nullable
private final MarginAreaContainer[] _marginAreas = new MarginAreaContainer[MARGIN_AREA_DEFS.length];

@Nullable
private Element _metadata;

public PageBox(PageInfo pageInfo, CssContext cssContext, CalculatedStyle style) {
_pageInfo = pageInfo;
_style = style;
_outerPageWidth = getWidth(cssContext);
}

public int getWidth(CssContext cssCtx) {
return getPageDimensions(cssCtx).width();
}
Expand Down Expand Up @@ -211,10 +217,6 @@ public CalculatedStyle getStyle() {
return _style;
}

public void setStyle(CalculatedStyle style) {
_style = style;
}

public int getBottom() {
return _bottom;
}
Expand Down Expand Up @@ -333,10 +335,6 @@ public int getOuterPageWidth() {
return _outerPageWidth;
}

public void setOuterPageWidth(int containingBlockWidth) {
_outerPageWidth = containingBlockWidth;
}

public int getMarginBorderPadding(CssContext cssCtx, Edge edge) {
return getStyle().getMarginBorderPadding(cssCtx, getOuterPageWidth(), edge);
}
Expand All @@ -345,10 +343,6 @@ public PageInfo getPageInfo() {
return _pageInfo;
}

public void setPageInfo(PageInfo pageInfo) {
_pageInfo = pageInfo;
}

@Nullable
@CheckReturnValue
public Element getMetadata() {
Expand Down Expand Up @@ -451,7 +445,7 @@ private record PageDimensions(int width, int height) {
private record MarginAreaContainer(MarginArea area, TableBox table) {
}

private abstract static class MarginArea {
private abstract static sealed class MarginArea {
private final MarginBoxName[] _marginBoxNames;

public abstract Dimension getLayoutDimension(CssContext c, PageBox page, RectPropertySet margin);
Expand All @@ -477,7 +471,7 @@ public MarginDirection getDirection() {
}
}

private static class TopLeftCorner extends MarginArea {
private static final class TopLeftCorner extends MarginArea {
private TopLeftCorner() {
super(MarginBoxName.TOP_LEFT_CORNER);
}
Expand All @@ -498,7 +492,7 @@ public Point getPaintingPosition(RenderingContext c, PageBox page, int additiona

}

private static class TopRightCorner extends MarginArea {
private static final class TopRightCorner extends MarginArea {
private TopRightCorner() {
super(MarginBoxName.TOP_RIGHT_CORNER);
}
Expand All @@ -519,7 +513,7 @@ public Point getPaintingPosition(RenderingContext c, PageBox page, int additiona
}
}

private static class BottomRightCorner extends MarginArea {
private static final class BottomRightCorner extends MarginArea {
private BottomRightCorner() {
super(MarginBoxName.BOTTOM_RIGHT_CORNER);
}
Expand All @@ -540,7 +534,7 @@ public Point getPaintingPosition(RenderingContext c, PageBox page, int additiona
}
}

private static class BottomLeftCorner extends MarginArea {
private static final class BottomLeftCorner extends MarginArea {
private BottomLeftCorner() {
super(MarginBoxName.BOTTOM_LEFT_CORNER);
}
Expand All @@ -560,7 +554,7 @@ public Point getPaintingPosition(RenderingContext c, PageBox page, int additiona
}
}

private static class LeftMarginArea extends MarginArea {
private static final class LeftMarginArea extends MarginArea {
private LeftMarginArea() {
super(new MarginBoxName[] {
MarginBoxName.LEFT_TOP,
Expand All @@ -587,7 +581,7 @@ public MarginDirection getDirection() {
}
}

private static class RightMarginArea extends MarginArea {
private static final class RightMarginArea extends MarginArea {
private RightMarginArea() {
super(new MarginBoxName[] {
MarginBoxName.RIGHT_TOP,
Expand Down Expand Up @@ -615,7 +609,7 @@ public MarginDirection getDirection() {
}
}

private static class TopMarginArea extends MarginArea {
private static final class TopMarginArea extends MarginArea {
private TopMarginArea() {
super(new MarginBoxName[] {
MarginBoxName.TOP_LEFT,
Expand All @@ -639,7 +633,7 @@ public Point getPaintingPosition(RenderingContext c, PageBox page, int additiona
}
}

private static class BottomMarginArea extends MarginArea {
private static final class BottomMarginArea extends MarginArea {
private BottomMarginArea() {
super(new MarginBoxName[] {
MarginBoxName.BOTTOM_LEFT,
Expand Down

0 comments on commit ccc5ce7

Please sign in to comment.