Skip to content

Commit 1ebf361

Browse files
Positioning fixes, data URL mime fix
1 parent 86fe1ee commit 1ebf361

File tree

10 files changed

+96
-27
lines changed

10 files changed

+96
-27
lines changed

Spec/src/main/java/com/github/webicitybrowser/spec/fetch/imp/FetchEngineImp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.InputStream;
44
import java.util.List;
5+
import java.util.Map;
56
import java.util.Optional;
67
import java.util.function.Consumer;
78
import java.util.function.Supplier;
@@ -75,7 +76,7 @@ private FetchResponse schemeFetch(FetchParams params) {
7576
return new FetchResponseImp(
7677
safelyExtract(struct.get().body()).body(),
7778
request.urlList(),
78-
new EmptyFetchHeaderListImp());
79+
new MapFetchHeaderList(Map.of("Content-Type", struct.get().mimeType())));
7980
case "http":
8081
case "https":
8182
return httpFetch(params);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.webicitybrowser.spec.fetch.imp;
2+
3+
import java.util.Map;
4+
5+
import com.github.webicitybrowser.spec.fetch.FetchHeaderList;
6+
7+
public class MapFetchHeaderList implements FetchHeaderList {
8+
9+
private final Map<String, String> headers;
10+
11+
public MapFetchHeaderList(Map<String, String> headers) {
12+
this.headers = headers;
13+
}
14+
15+
@Override
16+
public String getHeaderValue(String headerName) {
17+
return headers.get(headerName);
18+
}
19+
20+
public static FetchHeaderList create(Map<String, String> headers) {
21+
return new MapFetchHeaderList(headers);
22+
}
23+
24+
}

ThreadyWeb/src/main/java/com/github/webicitybrowser/threadyweb/graphical/directive/layout/common/MarginDirective.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.github.webicitybrowser.threadyweb.graphical.directive.layout.common;
22

33
import com.github.webicitybrowser.thready.gui.directive.core.Directive;
4+
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.size.SizeCalculationDirective;
45
import com.github.webicitybrowser.threadyweb.graphical.value.SizeCalculation;
56

6-
public interface MarginDirective extends Directive {
7-
8-
SizeCalculation getSizeCalculation();
7+
public interface MarginDirective extends SizeCalculationDirective {
98

109
interface LeftMarginDirective extends MarginDirective {
1110

ThreadyWeb/src/main/java/com/github/webicitybrowser/threadyweb/graphical/directive/layout/common/position/PositionOffsetDirective.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.position;
22

33
import com.github.webicitybrowser.thready.gui.directive.core.Directive;
4+
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.size.SizeCalculationDirective;
45
import com.github.webicitybrowser.threadyweb.graphical.value.SizeCalculation;
56

6-
public interface PositionOffsetDirective extends Directive {
7-
8-
SizeCalculation getSizeCalculation();
7+
public interface PositionOffsetDirective extends SizeCalculationDirective {
98

109
public static interface LeftPositionOffsetDirective extends PositionOffsetDirective {
1110

ThreadyWeb/src/main/java/com/github/webicitybrowser/threadyweb/graphical/layout/adjusted/AdjustedLayout.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
import com.github.webicitybrowser.thready.dimensions.Rectangle;
66
import com.github.webicitybrowser.thready.dimensions.RelativeDimension;
77
import com.github.webicitybrowser.thready.dimensions.util.AbsoluteDimensionsMath;
8+
import com.github.webicitybrowser.thready.gui.directive.core.pool.DirectivePool;
89
import com.github.webicitybrowser.thready.gui.graphical.layout.core.ChildLayoutResult;
910
import com.github.webicitybrowser.thready.gui.graphical.layout.core.LayoutRenderContext;
1011
import com.github.webicitybrowser.thready.gui.graphical.lookandfeel.core.stage.box.Box;
1112
import com.github.webicitybrowser.thready.gui.graphical.lookandfeel.core.stage.render.LocalRenderContext;
1213
import com.github.webicitybrowser.thready.gui.graphical.lookandfeel.core.stage.render.unit.ContextSwitch;
1314
import com.github.webicitybrowser.thready.gui.graphical.lookandfeel.core.stage.render.unit.RenderedUnit;
15+
import com.github.webicitybrowser.threadyweb.graphical.layout.adjusted.position.PositionOffsetCalculations;
1416
import com.github.webicitybrowser.threadyweb.graphical.layout.adjusted.position.PositionOffsetUtil;
1517
import com.github.webicitybrowser.threadyweb.graphical.layout.flow.context.block.FlowBlockChildRenderResult;
1618
import com.github.webicitybrowser.threadyweb.graphical.layout.flow.context.block.FlowBlockPrerenderSizingInfo;
1719
import com.github.webicitybrowser.threadyweb.graphical.layout.flow.context.block.FlowBlockUnitRenderer;
1820
import com.github.webicitybrowser.threadyweb.graphical.layout.flow.context.block.FlowBlockUnitRenderingContext;
1921
import com.github.webicitybrowser.threadyweb.graphical.layout.util.BoxOffsetDimensions;
22+
import com.github.webicitybrowser.threadyweb.graphical.layout.util.LayoutMarginCalculations;
2023
import com.github.webicitybrowser.threadyweb.graphical.layout.util.LayoutSizeUtils;
2124
import com.github.webicitybrowser.threadyweb.graphical.lookandfeel.weblaf.stage.render.unit.StyledUnitContext;
2225
import com.github.webicitybrowser.threadyweb.graphical.lookandfeel.weblaf.stage.render.unit.StyledUnitGenerator;
@@ -62,39 +65,62 @@ public static ChildLayoutResult renderAdjustedBox(Box box, LayoutRenderContext l
6265
}
6366

6467
private static ChildLayoutResult renderFixedBox(Box childBox, LayoutRenderContext layoutRenderContext, StyledUnitGenerator styledUnitGenerator) {
65-
BoxOffsetDimensions boxDimensions = BoxOffsetDimensions.create(layoutRenderContext, childBox.styleDirectives());
68+
DirectivePool styleDirectives = childBox.styleDirectives();
69+
SizeCalculationContext sizeCalculationContext = LayoutSizeUtils.createSizeCalculationContext(layoutRenderContext, styleDirectives);
70+
float[] positions = PositionOffsetCalculations.calculateOffset(sizeCalculationContext, styleDirectives);
71+
72+
BoxOffsetDimensions boxDimensions = BoxOffsetDimensions.create(layoutRenderContext, styleDirectives);
6673
AbsoluteSize viewportSize = layoutRenderContext.globalRenderContext().viewportSize();
6774
FlowBlockUnitRenderingContext context = new FlowBlockUnitRenderingContext(
6875
childBox, boxDimensions,
6976
childSize -> new LocalRenderContext(childSize, new ContextSwitch[0]),
70-
childSize -> computeFallbackPreferredSize(viewportSize, childSize, boxDimensions.margins()));
77+
childSize -> computeFallbackPreferredSize(viewportSize, childSize, boxDimensions.margins(), positions));
7178

72-
FlowBlockPrerenderSizingInfo prerenderSizingInfo = FlowBlockUnitRenderer.prerenderChild(layoutRenderContext, context);
79+
FlowBlockPrerenderSizingInfo prerenderSizingInfo = FlowBlockUnitRenderer.prerenderChild(layoutRenderContext, context, true);
7380
FlowBlockChildRenderResult childRenderResult = FlowBlockUnitRenderer.generateChildUnit(
7481
context, prerenderSizingInfo, layoutRenderContext.globalRenderContext());
7582

7683
AbsoluteSize finalChildSize = LayoutSizeUtils.addPadding(childRenderResult.adjustedSize(), boxDimensions.totalPadding());
7784
AbsolutePosition fixedPosition = PositionOffsetUtil.getFixedPositionOffset(
7885
prerenderSizingInfo.sizingContext().sizeCalculationContext(),
79-
childBox.styleDirectives(), finalChildSize);
86+
styleDirectives, finalChildSize);
8087
Rectangle fixedRect = new Rectangle(fixedPosition, finalChildSize);
8188

8289
RenderedUnit styledUnit = styledUnitGenerator.generateStyledUnit(
83-
new StyledUnitContext(childBox.styleDirectives(), childRenderResult.unit(), finalChildSize, boxDimensions)
90+
new StyledUnitContext(styleDirectives, childRenderResult.unit(), finalChildSize, boxDimensions)
8491
);
8592
AdjustedUnit adjustedUnit = new AdjustedUnit(styledUnit, fixedRect);
8693

8794
return new ChildLayoutResult(adjustedUnit, new Rectangle(new AbsolutePosition(0, 0), AbsoluteSize.ZERO_SIZE));
8895
}
8996

90-
private static AbsoluteSize computeFallbackPreferredSize(AbsoluteSize parentSize, AbsoluteSize preferredSize, float[] margins) {
91-
float marginOffset = Math.max(0, margins[0]) + Math.max(0, margins[1]);
97+
private static AbsoluteSize computeFallbackPreferredSize(AbsoluteSize parentSize, AbsoluteSize preferredSize, float[] positions, float[] margins) {
98+
margins = LayoutMarginCalculations.zeroAutoMargins(margins);
99+
100+
float marginOffsetX = Math.max(0, margins[0]) + Math.max(0, margins[1]);
92101
float actualPreferredWidth = preferredSize.width() != RelativeDimension.UNBOUNDED ?
93102
preferredSize.width() :
94103
parentSize.width() == RelativeDimension.UNBOUNDED ?
95104
RelativeDimension.UNBOUNDED :
96-
Math.max(0, parentSize.width() - marginOffset);
105+
Math.max(0, parentSize.width() - marginOffsetX);
106+
if (
107+
actualPreferredWidth == RelativeDimension.UNBOUNDED
108+
&& positions[0] != RelativeDimension.UNBOUNDED
109+
&& positions[1] != RelativeDimension.UNBOUNDED
110+
) {
111+
actualPreferredWidth = Math.max(0, parentSize.width() - positions[0] - positions[1] - marginOffsetX);
112+
}
113+
97114
float actualPreferredHeight = preferredSize.height();
115+
if (
116+
actualPreferredHeight == RelativeDimension.UNBOUNDED
117+
&& positions[2] != RelativeDimension.UNBOUNDED
118+
&& positions[3] != RelativeDimension.UNBOUNDED
119+
) {
120+
float marginOffsetY = Math.max(0, margins[2]) + Math.max(0, margins[3]);
121+
actualPreferredHeight = Math.max(0, parentSize.height() - positions[2] - positions[3] - marginOffsetY);
122+
}
123+
98124

99125
return new AbsoluteSize(actualPreferredWidth, actualPreferredHeight);
100126
}

ThreadyWeb/src/main/java/com/github/webicitybrowser/threadyweb/graphical/layout/adjusted/position/PositionOffsetCalculations.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
import com.github.webicitybrowser.thready.dimensions.AbsoluteSize;
55
import com.github.webicitybrowser.thready.dimensions.RelativeDimension;
66
import com.github.webicitybrowser.thready.gui.directive.core.pool.DirectivePool;
7-
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.position.PositionOffsetDirective;
7+
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.MarginDirective.BottomMarginDirective;
8+
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.MarginDirective.LeftMarginDirective;
9+
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.MarginDirective.RightMarginDirective;
10+
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.MarginDirective.TopMarginDirective;
811
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.position.PositionOffsetDirective.BottomPositionOffsetDirective;
912
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.position.PositionOffsetDirective.LeftPositionOffsetDirective;
1013
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.position.PositionOffsetDirective.RightPositionOffsetDirective;
1114
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.position.PositionOffsetDirective.TopPositionOffsetDirective;
15+
import com.github.webicitybrowser.threadyweb.graphical.directive.layout.common.size.SizeCalculationDirective;
16+
import com.github.webicitybrowser.threadyweb.graphical.layout.util.LayoutMarginCalculations;
1217
import com.github.webicitybrowser.threadyweb.graphical.value.SizeCalculation;
1318
import com.github.webicitybrowser.threadyweb.graphical.value.SizeCalculation.SizeCalculationContext;
1419

@@ -28,9 +33,19 @@ public static float[] calculateOffset(SizeCalculationContext sizeCalculationCont
2833
return offsets;
2934
}
3035

36+
public static float[] calculateMargin(SizeCalculationContext sizeCalculationContext, DirectivePool styleDirectives) {
37+
float[] margins = new float[4];
38+
margins[0] = computePosition(sizeCalculationContext, styleDirectives, LeftMarginDirective.class, true);
39+
margins[1] = computePosition(sizeCalculationContext, styleDirectives, RightMarginDirective.class, true);
40+
margins[2] = computePosition(sizeCalculationContext, styleDirectives, TopMarginDirective.class, false);
41+
margins[3] = computePosition(sizeCalculationContext, styleDirectives, BottomMarginDirective.class, false);
42+
43+
return margins;
44+
}
45+
3146
private static float computePosition(
3247
SizeCalculationContext sizeCalculationContext, DirectivePool styleDirectives,
33-
Class<? extends PositionOffsetDirective> directiveClass, boolean isHorizontal
48+
Class<? extends SizeCalculationDirective> directiveClass, boolean isHorizontal
3449
) {
3550
SizeCalculation sizeCalculation = styleDirectives
3651
.getDirectiveOrEmpty(directiveClass)
@@ -55,13 +70,14 @@ public static AbsolutePosition calculateRelativePositionOffset(float[] positions
5570
return new AbsolutePosition(xOffset, yOffset);
5671
}
5772

58-
public static AbsolutePosition calculateFixedPositionOffset(float[] positions, AbsoluteSize viewportSize, AbsoluteSize boxSize) {
73+
public static AbsolutePosition calculateFixedPositionOffset(float[] positions, float[] margins, AbsoluteSize viewportSize, AbsoluteSize boxSize) {
74+
margins = LayoutMarginCalculations.zeroAutoMargins(margins);
5975
float xOffset = positions[0] == POSITION_AUTO ?
60-
positions[1] == POSITION_AUTO ? 0 : viewportSize.width() - positions[1] - boxSize.width() :
61-
positions[0];
76+
positions[1] == POSITION_AUTO ? 0 : viewportSize.width() - boxSize.width() - margins[1] - positions[1] :
77+
positions[0] + margins[0];
6278
float yOffset = positions[2] == POSITION_AUTO ?
63-
positions[3] == POSITION_AUTO ? 0 : viewportSize.height() - positions[3] - boxSize.height() :
64-
positions[2];
79+
positions[3] == POSITION_AUTO ? 0 : viewportSize.height() - boxSize.height() - margins[3] - positions[3] :
80+
positions[2] + margins[2];
6581

6682
return new AbsolutePosition(xOffset, yOffset);
6783
}

ThreadyWeb/src/main/java/com/github/webicitybrowser/threadyweb/graphical/layout/adjusted/position/PositionOffsetUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ public final class PositionOffsetUtil {
1212
private PositionOffsetUtil() {}
1313

1414
public static AbsolutePosition getRelativePositionOffset(SizeCalculationContext sizeCalculationContext, DirectivePool styleDirectives) {
15+
// TODO: Properly handle percentages
1516
float[] positions = PositionOffsetCalculations.calculateOffset(sizeCalculationContext, styleDirectives);
1617

1718
return PositionOffsetCalculations.calculateRelativePositionOffset(positions);
1819
}
1920

2021
public static AbsolutePosition getFixedPositionOffset(SizeCalculationContext sizeCalculationContext, DirectivePool styleDirectives, AbsoluteSize boxSize) {
2122
float[] positions = PositionOffsetCalculations.calculateOffset(sizeCalculationContext, styleDirectives);
23+
float[] margins = PositionOffsetCalculations.calculateMargin(sizeCalculationContext, styleDirectives);
2224

23-
return PositionOffsetCalculations.calculateFixedPositionOffset(positions, sizeCalculationContext.viewportSize(), boxSize);
25+
return PositionOffsetCalculations.calculateFixedPositionOffset(positions, margins, sizeCalculationContext.viewportSize(), boxSize);
2426
}
2527

2628
public static PositionType getPositionType(DirectivePool styleDirectives) {

ThreadyWeb/src/main/java/com/github/webicitybrowser/threadyweb/graphical/layout/flow/context/block/FlowBlockBlockRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void renderChild(FlowBlockRenderContext state, Box childBox) {
3636
childSize -> createChildLocalRenderContext(state, childSize, boxDimensions),
3737
childSize -> computeFallbackPreferredSize(parentSize, childSize, boxDimensions.margins()));
3838

39-
FlowBlockPrerenderSizingInfo prerenderSizingInfo = FlowBlockUnitRenderer.prerenderChild(layoutRenderContext, context);
39+
FlowBlockPrerenderSizingInfo prerenderSizingInfo = FlowBlockUnitRenderer.prerenderChild(layoutRenderContext, context, false);
4040
FlowBlockChildRenderResult childRenderResult = FlowBlockUnitRenderer.generateChildUnit(
4141
context, prerenderSizingInfo, layoutRenderContext.globalRenderContext());
4242
AbsoluteSize finalChildSize = computeFinalChildSize(prerenderSizingInfo, childRenderResult);

ThreadyWeb/src/main/java/com/github/webicitybrowser/threadyweb/graphical/layout/flow/context/block/FlowBlockUnitRenderer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class FlowBlockUnitRenderer {
1818

1919
private FlowBlockUnitRenderer() {}
2020

21-
public static FlowBlockPrerenderSizingInfo prerenderChild(LayoutRenderContext layoutRenderContext, FlowBlockUnitRenderingContext context) {
21+
public static FlowBlockPrerenderSizingInfo prerenderChild(LayoutRenderContext layoutRenderContext, FlowBlockUnitRenderingContext context, boolean forcePreferred) {
2222
AbsoluteSize parentSize = layoutRenderContext.localRenderContext().preferredSize();
2323
Box childBox = context.childBox();
2424
BoxOffsetDimensions renderParameters = context.renderParameters();
@@ -27,8 +27,10 @@ public static FlowBlockPrerenderSizingInfo prerenderChild(LayoutRenderContext la
2727
AbsoluteSize forcedChildOuterSize = computePreferredSize(childBox, layoutSizingContext);
2828
AbsoluteSize preferredChildOuterSize = context.childSizeGenerator().apply(forcedChildOuterSize);
2929

30-
AbsoluteSize forcedChildContentSize = LayoutSizeUtils.subtractPadding(forcedChildOuterSize, renderParameters.totalPadding());
3130
AbsoluteSize preferredChildContentSize = LayoutSizeUtils.subtractPadding(preferredChildOuterSize, renderParameters.totalPadding());
31+
AbsoluteSize forcedChildContentSize = forcePreferred ?
32+
preferredChildContentSize :
33+
LayoutSizeUtils.subtractPadding(forcedChildOuterSize, renderParameters.totalPadding());
3234

3335
return new FlowBlockPrerenderSizingInfo(forcedChildContentSize, preferredChildContentSize, parentSize, layoutSizingContext);
3436
}

ThreadyWeb/src/main/java/com/github/webicitybrowser/threadyweb/graphical/layout/flow/context/block/floatbox/FlowBlockFloatRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static RenderedUnit renderFloatBoxUnit(FlowBlockRenderContext state, Box
5656
FlowBlockFloatRenderer::computeFloatBoxPreferredSize
5757
);
5858

59-
FlowBlockPrerenderSizingInfo prerenderSizingInfo = FlowBlockUnitRenderer.prerenderChild(layoutRenderContext, context);
59+
FlowBlockPrerenderSizingInfo prerenderSizingInfo = FlowBlockUnitRenderer.prerenderChild(layoutRenderContext, context, false);
6060
FlowBlockChildRenderResult childRenderResult = FlowBlockUnitRenderer.generateChildUnit(
6161
context, prerenderSizingInfo, layoutRenderContext.globalRenderContext());
6262
AbsoluteSize styledUnitSize = LayoutSizeUtils.addPadding(childRenderResult.adjustedSize(), renderParameters.totalPadding());

0 commit comments

Comments
 (0)