-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Fix insert/delete rule invalidation for adopted style sheets
Invalidaiton for adopted style sheets was broken because we had an assumption that "active" style sheet is always attached to StyleSheetList which is not true for adopted style sheets. This change addresses that by keeping track of all documents/shadow roots that own a style sheet and notifying them about invalidation instead of going through the StyleSheetList.
- Loading branch information
1 parent
cf57efd
commit 9802d5a
Showing
9 changed files
with
105 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Tests/LibWeb/Text/expected/css/insert-rule-in-adopted-style-sheet.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
color of box 1 before rule insertion: rgb(255, 0, 0) | ||
color of box 2 before rule insertion: rgb(255, 0, 0) | ||
color of box 1 after rule insertion: rgb(0, 128, 0) | ||
color of box 2 after rule insertion: rgb(0, 128, 0) |
47 changes: 47 additions & 0 deletions
47
Tests/LibWeb/Text/input/css/insert-rule-in-adopted-style-sheet.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE html> | ||
<script src="../include.js"></script> | ||
<my-shadow-box id="box1"></my-shadow-box> | ||
<my-shadow-box id="box2"></my-shadow-box> | ||
<script> | ||
const myStyleSheet = new CSSStyleSheet(); | ||
|
||
myStyleSheet.replaceSync(` | ||
.box { | ||
width: 100px; | ||
height: 100px; | ||
background-color: red; | ||
} | ||
`); | ||
|
||
class MyShadowBox extends HTMLElement { | ||
constructor() { | ||
super(); | ||
|
||
const shadowRoot = this.attachShadow({ mode: 'open' }); | ||
shadowRoot.adoptedStyleSheets = [myStyleSheet]; | ||
|
||
this.box = document.createElement('div'); | ||
this.box.classList.add('box'); | ||
|
||
shadowRoot.appendChild(this.box); | ||
} | ||
|
||
getBoxColor() { | ||
return getComputedStyle(this.box).backgroundColor; | ||
} | ||
} | ||
|
||
|
||
test(() => { | ||
customElements.define('my-shadow-box', MyShadowBox); | ||
|
||
println("color of box 1 before rule insertion: " + box1.getBoxColor()); | ||
println("color of box 2 before rule insertion: " + box2.getBoxColor()); | ||
myStyleSheet.insertRule( | ||
'.box { background-color: green; }', | ||
myStyleSheet.cssRules.length | ||
); | ||
println("color of box 1 after rule insertion: " + box1.getBoxColor()); | ||
println("color of box 2 after rule insertion: " + box2.getBoxColor()); | ||
}); | ||
</script> |