mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 20:54:43 +00:00
webapi.Element: optimize checkVisibility and refactor loops
This commit is contained in:
@@ -1044,6 +1044,7 @@ pub fn parentElement(self: *Element) ?*Element {
|
|||||||
const CSSStyleRule = @import("css/CSSStyleRule.zig");
|
const CSSStyleRule = @import("css/CSSStyleRule.zig");
|
||||||
|
|
||||||
pub fn checkVisibility(self: *Element, page: *Page) bool {
|
pub fn checkVisibility(self: *Element, page: *Page) bool {
|
||||||
|
const doc_sheets = page.document.getStyleSheets(page) catch null;
|
||||||
var current: ?*Element = self;
|
var current: ?*Element = self;
|
||||||
|
|
||||||
while (current) |el| {
|
while (current) |el| {
|
||||||
@@ -1055,14 +1056,11 @@ pub fn checkVisibility(self: *Element, page: *Page) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Also check if any global stylesheet hides this element
|
// Also check if any global stylesheet hides this element
|
||||||
const doc_sheets = page.document.getStyleSheets(page) catch null;
|
|
||||||
if (doc_sheets) |sheets| {
|
if (doc_sheets) |sheets| {
|
||||||
var i: usize = 0;
|
for (0..sheets.length()) |i| {
|
||||||
while (i < sheets.length()) : (i += 1) {
|
|
||||||
const sheet = sheets.item(i) orelse continue;
|
const sheet = sheets.item(i) orelse continue;
|
||||||
const rules = sheet.getCssRules(page) catch continue;
|
const rules = sheet.getCssRules(page) catch continue;
|
||||||
var j: usize = 0;
|
for (0..rules.length()) |j| {
|
||||||
while (j < rules.length()) : (j += 1) {
|
|
||||||
const rule = rules.item(j) orelse continue;
|
const rule = rules.item(j) orelse continue;
|
||||||
if (rule.is(CSSStyleRule)) |style_rule| {
|
if (rule.is(CSSStyleRule)) |style_rule| {
|
||||||
const selector = style_rule.getSelectorText();
|
const selector = style_rule.getSelectorText();
|
||||||
|
|||||||
Reference in New Issue
Block a user