Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/text-flow-sli…
Browse files Browse the repository at this point in the history
…ver-css
  • Loading branch information
andycall committed Sep 18, 2023
2 parents 83f479b + aafcda7 commit 47441f7
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 10 deletions.
18 changes: 18 additions & 0 deletions bridge/core/html/parser/html_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <utility>

#include "core/dom/comment.h"
#include "core/dom/document.h"
#include "core/dom/element.h"
#include "core/dom/text.h"
Expand Down Expand Up @@ -92,6 +93,23 @@ void HTMLParser::traverseHTML(Node* root_node, GumboNode* node) {
} else if (child->type == GUMBO_NODE_TEXT) {
auto* text = context->document()->createTextNode(AtomicString(ctx, child->v.text.text), ASSERT_NO_EXCEPTION());
root_container->AppendChild(text);
} else if (child->type == GUMBO_NODE_WHITESPACE) {
bool isBlankSpace = true;
int nLen = strlen(child->v.text.text);
for (int j = 0; j < nLen; ++j) {
isBlankSpace = child->v.text.text[j] == ' ';
if (!isBlankSpace) {
break;
}
}

if (isBlankSpace) {
if (nLen > 0) {
auto* textNode =
context->document()->createTextNode(AtomicString(ctx, child->v.text.text), ASSERT_NO_EXCEPTION());
root_container->appendChild(textNode, ASSERT_NO_EXCEPTION());
}
}
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions integration_tests/scripts/html_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@ const loader = function(source) {
}
})

const htmlString = root.toString().replace(/['\n]/g, function(c){
return {'\n': '','\'': '\\'}[c];
});

return `
describe('HTMLSpec/${testRelativePath}', () => {
// Use html_parse to parser html in html file.
const html_parse = () => __webf_parse_html__(\`${htmlString}\`);
const html_parse = () => __webf_parse_html__(\`${root.toString()}\`);
var index = 0;
const snapshotAction = async () => { await snapshot(null, '${snapshotFilepath}', ${scripts.length === 0 ? 'null' : 'index.toString()'}); index++; };
${isFit ? 'fit' : isXit ? 'xit' : 'it'}("should work", async (done) => {\
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@
</body>
<script>
await snapshotAction();
await sleep(0.1);
</script>
</html>
34 changes: 34 additions & 0 deletions integration_tests/specs/css/css-empty/empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<style>

.emptyStyle:empty {
background: #ff0000;
height: 50px;
width: 300px;
}
</style>
</head>

<body class="emptyStyle">
<p>p</p>
<p class="emptyStyle"></p>
<p>p1</p>
<p class="emptyStyle"> </p>
<p>h1</p>
<h1 class="emptyStyle"> </h1>
<p>h2</p>
<h2 class="emptyStyle"></h2>
<p>h3</p>
<p>h4</p>
<div class="emptyStyle" id="debug"></div>
<div class="empty" id="debug1">xx</div>
<div class="emptyStyle" id="debug"> </div>
<div class="empty" id="debug1">xx11</div>
<div class="emptyStyle" id="debug"><!-- xx --></div>
<div class="empty" id="debug1">xx22</div>
<p class="emptyStyle" id="debug"></p>
<div class="empty" id="debug1">xx33</div>
</body>
</html>
49 changes: 49 additions & 0 deletions webf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
## 0.15.0

This version will support Flutter 3.10.x

**Break Changes**

1. Remove `navigator.connection` API. https://github.com/openwebf/webf/pull/411

**Features**

1. Upgrade Flutter support to 3.10.x. https://github.com/openwebf/webf/pull/345
2. Optimize location API for better performance results. https://github.com/openwebf/webf/pull/420
3. Optimize the size of webf_bridge.xcframework and quickjs.xcframework. https://github.com/openwebf/webf/pull/414
4. Support CSS initial length value. https://github.com/openwebf/webf/pull/421
5. Optimize Element.children() and Document.all() performance. https://github.com/openwebf/webf/pull/424
6. Support base64 format font data in `@font-face` src. https://github.com/openwebf/webf/pull/399
7. Support Element.dir API. https://github.com/openwebf/webf/pull/418
8. Add `<circle />` and `<ellipse>` tags for SVG. https://github.com/openwebf/webf/pull/423
9. Support share customized JS properties in event object. https://github.com/openwebf/webf/pull/427
10. Support `window.pageXOffset` and `window.pageYOffset` API. https://github.com/openwebf/webf/pull/428/files
11. Optimize layout/paint performance when block box size is fixed. https://github.com/openwebf/webf/pull/450
12. Optimize performance when update Element.className. https://github.com/openwebf/webf/pull/452
13. Support CanvasRenderingContext2D.createPattern() API. https://github.com/openwebf/webf/pull/464

**Bug Fixed**

1. Fix use css vars with initial. https://github.com/openwebf/webf/pull/421
2. Fix toggle position: fixed on bodyElement with other fixed elements. https://github.com/openwebf/webf/pull/416
3. Fss nth-child not work. https://github.com/openwebf/webf/pull/417
4. Fix Node.childNodes didn't update when nodes changed. https://github.com/openwebf/webf/pull/419
5. Fix loading fonts cause assertion when remove or attach RenderObjects. https://github.com/openwebf/webf/pull/425
6. Fix percentage width and height not working under inline block box. https://github.com/openwebf/webf/pull/430
7. Fix Node.insertBefore with SVGElement error. https://github.com/openwebf/webf/pull/431
8. Fix cookie delete file error when it's not available. https://github.com/openwebf/webf/pull/429
9. Fix read ANDROID_SDK_HOME before implying to platform defaults. https://github.com/openwebf/webf/pull/422
10. Fix cookie delete file error. https://github.com/openwebf/webf/pull/429
11. Fix percentage width and height not working under inline block box. https://github.com/openwebf/webf/pull/430
12. Fix Node.insertBefore with SVGElement error. https://github.com/openwebf/webf/pull/431
13. Fix DevTool's network panel not working. https://github.com/openwebf/webf/pull/435
14. Losen intl dependency constraint. https://github.com/openwebf/webf/pull/439
15. Fix built-in methods in the event object cannot be overridden. https://github.com/openwebf/webf/pull/443
16. Fix crash when touching pseduo elements. https://github.com/openwebf/webf/pull/445
17. Fix event not responding when multiple flutter engine created. https://github.com/openwebf/webf/pull/451
18. Fix Element.style.cssText API not works. https://github.com/openwebf/webf/pull/455
19. Fix use-of-free crash of shared string property in event object. https://github.com/openwebf/webf/pull/458
20. Fix dynamic build items in WidgetElement. https://github.com/openwebf/webf/pull/461
21. Fix CSS content property have sequences of unicode chars. https://github.com/openwebf/webf/pull/463
22. Fix crash when create unsupported svg element with style. https://github.com/openwebf/webf/pull/465

## 0.14.1

**Features**
Expand Down
4 changes: 3 additions & 1 deletion webf/lib/src/css/query_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ class SelectorEvaluator extends SelectorVisitor {

// http://dev.w3.org/csswg/selectors-4/#the-empty-pseudo
case 'empty':
return _element!.childNodes.every((n) => !(n is Element || n is TextNode && n.data.isNotEmpty));
return _element!.childNodes.every((n) =>
!(n is Element || (n is TextNode && n.data.isNotEmpty))
);

// http://dev.w3.org/csswg/selectors-4/#the-blank-pseudo
case 'blank':
Expand Down
5 changes: 4 additions & 1 deletion webf/lib/src/rendering/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ class WebFRenderParagraph extends RenderBox

/// Compute distance to baseline of last text line
double computeDistanceToLastLineBaseline() {
double lastLineOffset = _lineRenders[_lineRenders.length - 1].lineRect.top;
if (_lineOffset.isEmpty) {
return 0.0;
}
double lastLineOffset = _lineOffset[_lineOffset.length - 1];
ui.LineMetrics lastLineMetrics = _lineMetrics[_lineMetrics.length - 1];

// Use the baseline of the last line as paragraph baseline.
Expand Down
8 changes: 7 additions & 1 deletion webf/lib/src/rendering/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,13 @@ class RenderTextBox extends RenderBox with RenderObjectWithChildMixin<RenderBox>

// ' a b c' => 'a b c'
static String _trimLeftWhitespace(String string) {
return string.replaceAllMapped(_trimLeftWhitespaceReg, (Match m) => '${m[1]}');
String result = string.replaceAllMapped(_trimLeftWhitespaceReg, (Match m) =>
'${m[1]}'
);
if (result.startsWith(' ')) {
return '';
}
return result;
}

// 'a b c ' => 'a b c'
Expand Down
2 changes: 1 addition & 1 deletion webf/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: webf
description: W3C standards-compliant web rendering engine based on Flutter, allowing web applications to run natively on Flutter.
version: 0.15.0-beta.1+1
version: 0.15.0
homepage: https://openwebf.com

environment:
Expand Down

0 comments on commit 47441f7

Please sign in to comment.