Skip to content

Commit

Permalink
Merge pull request #488 from openwebf/revert-434-feat/empty_fix
Browse files Browse the repository at this point in the history
Revert "fix: fix :empty selector."
  • Loading branch information
andycall authored Sep 20, 2023
2 parents 1cc8a36 + 976a2ba commit 040c646
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 66 deletions.
18 changes: 0 additions & 18 deletions bridge/core/html/parser/html_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#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 @@ -93,23 +92,6 @@ 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: 5 additions & 1 deletion integration_tests/scripts/html_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ 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__(\`${root.toString()}\`);
const html_parse = () => __webf_parse_html__(\`${htmlString}\`);
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
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
</body>
<script>
await snapshotAction();
await sleep(0.1);
</script>
</html>
34 changes: 0 additions & 34 deletions integration_tests/specs/css/css-empty/empty.html

This file was deleted.

4 changes: 1 addition & 3 deletions webf/lib/src/css/query_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ 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
3 changes: 0 additions & 3 deletions webf/lib/src/rendering/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ class WebFRenderParagraph extends RenderBox

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

Expand Down
8 changes: 1 addition & 7 deletions webf/lib/src/rendering/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,7 @@ class RenderTextBox extends RenderBox with RenderObjectWithChildMixin<RenderBox>

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

// 'a b c ' => 'a b c'
Expand Down

0 comments on commit 040c646

Please sign in to comment.