| OLD | NEW |
| 1 Sky Style Language | 1 Sky Style Language |
| 2 ================== | 2 ================== |
| 3 | 3 |
| 4 Planed changes | 4 Planed changes |
| 5 -------------- | 5 -------------- |
| 6 | 6 |
| 7 Add //-to-end-of-line comments to be consistent with the script | 7 Add //-to-end-of-line comments to be consistent with the script |
| 8 language. | 8 language. |
| 9 | 9 |
| 10 | 10 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 269 |
| 270 The types marked with * in the list above are not part of sky:core. | 270 The types marked with * in the list above are not part of sky:core. |
| 271 | 271 |
| 272 TODO(ianh): consider removing 'StyleValue' from these class names | 272 TODO(ianh): consider removing 'StyleValue' from these class names |
| 273 | 273 |
| 274 ```javascript | 274 ```javascript |
| 275 abstract class StyleNode { | 275 abstract class StyleNode { |
| 276 abstract void markDirty(); | 276 abstract void markDirty(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 dictionary StyleValueResolverSettingsSettings { |
| 280 Boolean firstTime = false; |
| 281 any state = null; |
| 282 } |
| 283 |
| 279 class StyleValueResolverSettings { | 284 class StyleValueResolverSettings { |
| 280 // this is used as an "out" parameter for 'resolve()' below | 285 // this is used as an "out" parameter for 'resolve()' below |
| 281 constructor(); | 286 constructor(StyleValueResolverSettingsSettings initial); |
| 282 void reset(); // resets values to defaults so that object can be reused | 287 void reset(StyleValueResolverSettingsSettings initial); |
| 288 // sets firstTime and state to given values |
| 289 // sets layoutDependent to false |
| 290 // sets dependencies to empty set |
| 291 |
| 292 readonly attribute Boolean firstTime; |
| 293 // true if this is the first time this property is being resolved for this e
lement, |
| 294 // or if the last time it was resolved, the value was a different object |
| 295 |
| 283 attribute Boolean layoutDependent; // default to false | 296 attribute Boolean layoutDependent; // default to false |
| 284 // set this if the value should be recomputed each time the ownerLayoutManag
er's dimensions change, rather than being precomputed | 297 // set this if the value should be recomputed each time the ownerLayoutManag
er's dimensions change, rather than being cached |
| 285 | 298 |
| 286 // attribute "BitField" dependencies; // defaults to no bits set | 299 // attribute "BitField" dependencies; // defaults to no bits set |
| 287 void dependsOn(PropertyHandle property); | 300 void dependsOn(PropertyHandle property); |
| 288 // if the given property doesn't have a dependency bit assigned: | 301 // if the given property doesn't have a dependency bit assigned: |
| 289 // - assign the next bit to the property | 302 // - assign the next bit to the property |
| 290 // - if there's no bits left, throw | 303 // - if there's no bits left, throw |
| 291 // set the bit on this StyleValueResolverSettings's dependencies bitfield | 304 // set the bit on this StyleValueResolverSettings's dependencies bitfield |
| 305 Array<PropertyHandle> getDependencies(); |
| 306 // returns an array of the PropertyHandle values for the bits that are set i
n dependencies |
| 307 |
| 308 attribute any state; // initially null, can be set to store value for this Ren
derNode/property pair |
| 309 // for example, TransitioningColorStyleValue would store |
| 310 // { |
| 311 // initial: /* color at time of transition */, |
| 312 // target: /* color at end of transition */, |
| 313 // start: /* time at start of transition */, |
| 314 // } |
| 315 // ...which would enable it to update appropriately, and would also |
| 316 // let other transitions that come later know that you were half-way |
| 317 // through a transition so they can shorten their time accordingly |
| 292 } | 318 } |
| 293 | 319 |
| 294 class Property : StyleNode { | 320 class Property : StyleNode { |
| 295 constructor (AbstractStyleDeclaration parentNode, PropertyHandle property, Abs
tractStyleValue? initialValue = null); | 321 constructor (AbstractStyleDeclaration parentNode, PropertyHandle property, Abs
tractStyleValue? initialValue = null); |
| 296 readonly attribute AbstractStyleDeclaration parentNode; | 322 readonly attribute AbstractStyleDeclaration parentNode; |
| 297 readonly attribute PropertyHandle property; | 323 readonly attribute PropertyHandle property; |
| 298 readonly attribute AbstractStyleValue value; | 324 readonly attribute AbstractStyleValue value; |
| 299 | 325 |
| 300 void setValue(AbstractStyleValue? newValue); | 326 void setValue(AbstractStyleValue? newValue); |
| 301 // updates value and calls markDirty() | 327 // updates value and calls markDirty() |
| 302 | 328 |
| 303 void markDirty(); | 329 void markDirty(); |
| 304 // call parentNode.markDirty(property); | 330 // call parentNode.markDirty(property); |
| 305 | 331 |
| 306 abstract any resolve(RenderNode node, StyleValueResolverSettings? settings = n
ull); | 332 abstract any resolve(RenderNode node, StyleValueResolverSettings? settings = n
ull); |
| 307 // if value is null, returns null | 333 // if value is null, returns null |
| 308 // otherwise, returns value.resolve(property, node, settings) | 334 // otherwise, returns value.resolve(property, node, settings) |
| 309 } | 335 } |
| 310 | 336 |
| 311 abstract class AbstractStyleValue : StyleNode { | 337 abstract class AbstractStyleValue : StyleNode { |
| 312 abstract constructor(StyleNode parentNode); | 338 abstract constructor(StyleNode? parentNode = null); |
| 313 readonly attribute StyleNode parentNode; | 339 attribute StyleNode? parentNode; |
| 314 | 340 |
| 315 void markDirty(); | 341 void markDirty(); |
| 316 // call this.parentNode.markDirty() | 342 // call this.parentNode.markDirty() |
| 317 | 343 |
| 318 abstract any resolve(PropertyHandle property, RenderNode node, StyleValueResol
verSettings? settings = null); | 344 abstract any resolve(PropertyHandle property, RenderNode node, StyleValueResol
verSettings? settings = null); |
| 319 } | 345 } |
| 320 | 346 |
| 321 abstract class LengthStyleValue : AbstractStyleValue { | 347 abstract class LengthStyleValue : AbstractStyleValue { |
| 322 abstract Float resolve(PropertyHandle property, RenderNode node, StyleValueRes
olverSettings? settings = null); | 348 abstract Float resolve(PropertyHandle property, RenderNode node, StyleValueRes
olverSettings? settings = null); |
| 323 } | 349 } |
| 324 | 350 |
| 325 class PixelLengthStyleValue : LengthStyleValue { | 351 class PixelLengthStyleValue : LengthStyleValue { |
| 326 constructor(StyleNode parentNode, Float number); | 352 constructor(Float number, StyleNode? parentNode = null); |
| 327 readonly attribute Float value; | 353 attribute Float value; |
| 354 // on setting, calls markDirty(); |
| 328 Float resolve(PropertyHandle property, RenderNode node, StyleValueResolverSett
ings? settings = null); | 355 Float resolve(PropertyHandle property, RenderNode node, StyleValueResolverSett
ings? settings = null); |
| 356 // return value |
| 329 } | 357 } |
| 330 | 358 |
| 331 typedef RawColor Float; // TODO(ianh): figure out what Color should be | 359 typedef RawColor Float; // TODO(ianh): figure out what Color should be |
| 332 class ColorStyleValue : LengthStyleValue { | 360 class ColorStyleValue : LengthStyleValue { |
| 333 constructor(StyleNode parentNode, Float red, Float green, Float blue, Float al
pha); | 361 constructor(Float red, Float green, Float blue, Float alpha, StyleNode? parent
Node = null); |
| 334 // ... color API ... | 362 // ... color API ... |
| 335 RawColor resolve(PropertyHandle property, RenderNode node, StyleValueResolverS
ettings? settings = null); | 363 RawColor resolve(PropertyHandle property, RenderNode node, StyleValueResolverS
ettings? settings = null); |
| 336 } | 364 } |
| 337 | 365 |
| 338 class AbstractOpaqueStyleValue : AbstractStyleValue { | 366 class AbstractOpaqueStyleValue : AbstractStyleValue { |
| 339 abstract constructor(StyleNode parentNode, any value); | 367 abstract constructor(any value, StyleNode? parentNode = null); |
| 340 readonly attribute any value; | 368 attribute any value; |
| 369 // on setting, calls markDirty(); |
| 341 any resolve(PropertyHandle property, RenderNode node, StyleValueResolverSettin
gs? settings = null); | 370 any resolve(PropertyHandle property, RenderNode node, StyleValueResolverSettin
gs? settings = null); |
| 342 // returns value | 371 // returns value |
| 343 } | 372 } |
| 344 | 373 |
| 345 class IdentifierStyleValue : AbstractOpaqueStyleValue { | 374 class IdentifierStyleValue : AbstractOpaqueStyleValue { |
| 346 constructor(StyleNode parentNode, String value); | 375 constructor(String value, StyleNode? parentNode = null); |
| 347 // calls superclass constructor | 376 // calls superclass constructor |
| 348 } | 377 } |
| 349 | 378 |
| 350 /* | 379 /* |
| 351 class AnimatableIdentifierStyleValue : AbstractOpaqueStyleValue { | 380 class AnimatableIdentifierStyleValue : AbstractOpaqueStyleValue { |
| 352 constructor(StyleNode parentNode, String value, String newValue, AnimationFunc
tion player); | 381 constructor(String value, String newValue, AnimationFunction player, StyleNode
? parentNode = null); |
| 353 readonly attribute String newValue; | 382 readonly attribute String newValue; |
| 354 readonly attribute AnimationFunction player; | 383 readonly attribute AnimationFunction player; |
| 355 any resolve(PropertyHandle property, RenderNode node, StyleValueResolverSettin
gs? settings = null); | 384 any resolve(PropertyHandle property, RenderNode node, StyleValueResolverSettin
gs? settings = null); |
| 356 } | 385 } |
| 357 */ | 386 */ |
| 358 | 387 |
| 359 class ObjectStyleValue : AbstractOpaqueStyleValue { | 388 class ObjectStyleValue : AbstractOpaqueStyleValue { |
| 360 constructor(StyleNode parentNode, any value); | 389 constructor(any value, StyleNode? parentNode = null); |
| 361 // calls superclass constructor | 390 // calls superclass constructor |
| 362 } | 391 } |
| 363 | 392 |
| 364 dictionary PropertySettings { | 393 dictionary PropertySettings { |
| 365 String? name = null; // null if the property can't be set from a <style> block | 394 String? name = null; // null if the property can't be set from a <style> block |
| 366 StyleGrammar? grammar = null; // msut be non-null if name is non-null; must be
null otherwise | 395 StyleGrammar? grammar = null; // must be non-null if name is non-null; must be
null otherwise |
| 367 Boolean inherited = false; | 396 Boolean inherited = false; |
| 368 any initialValue = null; | 397 any initialValue = null; |
| 369 Boolean needsManager = false; | 398 Boolean needsManager = false; |
| 370 Boolean needsLayout = false; | 399 Boolean needsLayout = false; |
| 371 Boolean needsPaint = false; | 400 Boolean needsPaint = false; |
| 372 // PropertyHandle propertyHandle; // assigned by registerProperty | 401 // PropertyHandle propertyHandle; // assigned by registerProperty |
| 373 // Integer dependencyBit; // assigned by StyleValueResolverSettings.dependsOn(
) | 402 // Integer dependencyBit; // assigned by StyleValueResolverSettings.dependsOn(
) |
| 374 } | 403 } |
| 375 typedef PropertyHandle Integer; | 404 typedef PropertyHandle Integer; |
| 376 PropertyHandle registerProperty(PropertySettings propertySettings); | 405 PropertyHandle registerProperty(PropertySettings propertySettings); |
| 377 // registers a property with the given settings, and returns an integer >= 0 | 406 // registers a property with the given settings, and returns an integer >= 0 |
| 378 // that can be used to refer to this property | 407 // that can be used to refer to this property |
| 379 | 408 |
| 380 // sky:core exports a bunch of style grammars so that people can extend them | 409 // sky:core exports a bunch of style grammars so that people can extend them |
| 381 attribute StyleGrammar PositiveLengthOrInfinityStyleGrammar; // resolves to Leng
thStyleValue | 410 attribute StyleGrammar PositiveLengthOrInfinityStyleGrammar; // resolves to Leng
thStyleValue |
| 382 attribute StyleGrammar PositiveLengthOrAutoStyleGrammar; // resolves to LengthSt
yleValue or IdentifierStyleValue (with value 'auto') | 411 attribute StyleGrammar PositiveLengthOrAutoStyleGrammar; // resolves to LengthSt
yleValue or IdentifierStyleValue (with value 'auto') |
| 383 attribute StyleGrammar PositiveLengthStyleGrammar; // resolves to LengthStyleVal
ue | 412 attribute StyleGrammar PositiveLengthStyleGrammar; // resolves to LengthStyleVal
ue |
| 384 attribute StyleGrammar NumberGrammar; // resolves to NumericStyleValue | 413 attribute StyleGrammar NumberGrammar; // resolves to NumericStyleValue |
| 385 attribute StyleGrammar ColorGrammar; // resolves to ColorStyleValue | 414 attribute StyleGrammar ColorGrammar; // resolves to ColorStyleValue |
| 386 attribute StyleGrammar DisplayStyleGrammar; // resolves to ObjectStyleValue | 415 attribute StyleGrammar DisplayStyleGrammar; // resolves to ObjectStyleValue |
| 387 ``` | 416 ``` |
| 388 | 417 |
| 389 Inline Styles | 418 Inline Styles |
| 390 ------------- | 419 ------------- |
| 391 | 420 |
| 392 ```javascript | 421 ```javascript |
| 393 abstract class AbstractStyleDeclarationList { | 422 abstract class AbstractStyleDeclarationList { |
| 394 void addStyles(StyleDeclaration styles, String? pseudoElement = null); // O(1) | 423 void addStyles(StyleDeclaration styles, String pseudoElement = ''); // O(1) |
| 395 void removeStyles(StyleDeclaration styles, String? pseudoElement = null); // O
(N) in number of declarations | 424 void removeStyles(StyleDeclaration styles, String pseudoElement = ''); // O(N)
in number of declarations |
| 396 Array<StyleDeclaration> getDeclarations(String? pseudoElement = null); // O(N)
in number of declarations | 425 Array<StyleDeclaration> getDeclarations(String pseudoElement = ''); // O(N) in
number of declarations |
| 397 } | 426 } |
| 398 | 427 |
| 399 class ElementStyleDeclarationList : AbstractStyleDeclarationList { | 428 class ElementStyleDeclarationList : AbstractStyleDeclarationList { |
| 400 constructor (Element? element); | 429 constructor (Element? element); |
| 401 | 430 |
| 402 // there are two batches of styles in an ElementStyleDeclarationList. | 431 // there are two batches of styles in an ElementStyleDeclarationList. |
| 403 | 432 |
| 404 // the first batch is the per-frame styles; these get (conceptually) | 433 // the first batch is the per-frame styles; these get (conceptually) |
| 405 // cleared each frame, after which all the matching rules in relevant | 434 // cleared each frame, after which all the matching rules in relevant |
| 406 // <style> blocks get added back in, followed by all the animation- | 435 // <style> blocks get added back in, followed by all the animation- |
| 407 // derived rules; scripts can also add styles themselves, but they are | 436 // derived rules; scripts can also add styles themselves, but they are |
| 408 // dropped after the next frame | 437 // dropped after the next frame |
| 409 void addFrameStyles(StyleDeclaration styles, String? pseudoElement = null); //
O(1) | 438 void addFrameStyles(StyleDeclaration styles, String pseudoElement = ''); // O(
1) |
| 410 void clearFrameStyles(); | 439 void clearFrameStyles(); |
| 411 | 440 |
| 412 // the second batch is the persistent styles, which remain until removed; | 441 // the second batch is the persistent styles, which remain until removed; |
| 413 // they are accessed via the AbstractStyleDeclarationList accessors | 442 // they are accessed via the AbstractStyleDeclarationList accessors |
| 414 | 443 |
| 415 // as StyleDeclarations are added and removed, the ElementStyleDeclarationList | 444 // as StyleDeclarations are added and removed, the ElementStyleDeclarationList |
| 416 // calls register(element) and unregister(element) respectively on those | 445 // calls register(element) and unregister(element) respectively on those |
| 417 // StyleDeclaration objects, where element is the element that was passed | 446 // StyleDeclaration objects, where element is the element that was passed |
| 418 // to the constructor, if not null | 447 // to the constructor, if not null |
| 419 // then, it calls element.renderNode.cascadedValueAdded/cascadedValueRemoved | 448 // then, it calls element.renderNode.cascadedValueChanged |
| 420 // for each property on the object | 449 // for each property on the object |
| 421 | 450 |
| 422 // the inherited getDeclarations() method returns all the frame | 451 // the inherited getDeclarations() method returns all the frame |
| 423 // styles followed by all the persistent styles, in insertion order | 452 // styles followed by all the persistent styles, in insertion order |
| 424 } | 453 } |
| 425 | 454 |
| 426 class RenderNodeStyleDeclarationList : AbstractStyleDeclarationList { | 455 class RenderNodeStyleDeclarationList : AbstractStyleDeclarationList { |
| 427 constructor (RenderNode? renderNode); | 456 constructor (RenderNode? renderNode); |
| 428 | 457 |
| 429 // as StyleDeclarations are added and removed, the RenderNodeStyleDeclarationL
ist | 458 // as StyleDeclarations are added and removed, the RenderNodeStyleDeclarationL
ist |
| 430 // calls register(renderNode) and unregister(renderNode) respectively on those | 459 // calls register(renderNode) and unregister(renderNode) respectively on those |
| 431 // StyleDeclaration objects, where renderNode is the RenderNode that was passe
d | 460 // StyleDeclaration objects, where renderNode is the RenderNode that was passe
d |
| 432 // to the constructor, if not null | 461 // to the constructor, if not null |
| 433 // then, it calls renderNode.cascadedValueAdded/cascadedValueRemoved | 462 // then, it calls renderNode.cascadedValueChanged |
| 434 // for each property on the object | 463 // for each property on the object |
| 435 } | 464 } |
| 436 | 465 |
| 437 class StyleDeclaration { | 466 class StyleDeclaration { |
| 438 constructor (); | 467 constructor (); |
| 439 | 468 |
| 440 void markDirty(PropertyHandle property); | 469 void markDirty(PropertyHandle property); |
| 441 // this indicates that the cascaded value of the property thinks | 470 // this indicates that the cascaded value of the property thinks |
| 442 // it will now have a different result (as opposed to the cascaded | 471 // it will now have a different result (as opposed to the cascaded |
| 443 // value itself having changed) | 472 // value itself having changed) |
| 444 // invoke element.renderNode.cascadedValueDirty(property, pseudoElement); fo
r each | 473 // invoke element.renderNode.cascadedValueDirty(property, pseudoElement); fo
r each |
| 445 // currently registered consumer element/pseudoElement pair | 474 // currently registered consumer element/pseudoElement pair |
| 446 | 475 |
| 447 void register((Element or RenderNode) consumer, String? pseudoElement = null);
// O(1) | 476 void register((Element or RenderNode) consumer, String pseudoElement = ''); //
O(1) |
| 448 void unregister((Element or RenderNode) consumer, String? pseudoElement = null
); // O(N) | 477 void unregister((Element or RenderNode) consumer, String pseudoElement = '');
// O(N) |
| 449 // registers an element/pseudoElement or renderNode/pseudoElement pair with | 478 // registers an element/pseudoElement or renderNode/pseudoElement pair with |
| 450 // this StyleDeclaration so that a property/value on the style declaration | 479 // this StyleDeclaration so that a property/value on the style declaration |
| 451 // is marked dirty, the relevant render node is informed and can then update | 480 // is marked dirty, the relevant render node is informed and can then update |
| 452 // its property cache accordingly | 481 // its property cache accordingly |
| 453 | 482 |
| 454 getter AbstractStyleValue? (PropertyHandle property); | 483 getter AbstractStyleValue? (PropertyHandle property); |
| 455 // looks up the Property object for /property/, and returns its value | 484 // looks up the Property object for /property/, and returns its value |
| 456 // null if property is missing | 485 // null if property is missing |
| 457 | 486 |
| 458 setter void (PropertyHandle property, AbstractStyleValue value); | 487 setter void (PropertyHandle property, AbstractStyleValue value); |
| 488 // verify that value.parentNode is null |
| 459 // if there is no Property object for /property/, creates one | 489 // if there is no Property object for /property/, creates one |
| 460 // else calls its update() method to change the value | 490 // else calls its update() method to change the value |
| 461 // if the value changed: | 491 // update value's parentNode |
| 462 // invoke consumer.renderNode.cascadedValueChanged(property); for each | 492 // invoke consumer.renderNode.cascadedValueChanged(property); for each |
| 463 // currently registered consumer | 493 // currently registered consumer |
| 464 // if the value is new: | |
| 465 // invoke consumer.renderNode.cascadedValueAdded(property); for each | |
| 466 // currently registered consumer | |
| 467 | 494 |
| 468 void remove(PropertyHandle property); | 495 void remove(PropertyHandle property); |
| 469 // drops the Property object for /property/ from this StyleDeclaration objec
t | 496 // drops the Property object for /property/ from this StyleDeclaration objec
t |
| 470 // invoke consumer.renderNode.cascadedValueRemoved(property); for each | 497 // invoke consumer.renderNode.cascadedValueChanged(property); for each |
| 471 // currently registered consumer | 498 // currently registered consumer |
| 472 } | 499 } |
| 473 ``` | 500 ``` |
| 474 | 501 |
| 475 Rule Matching | 502 Rule Matching |
| 476 ------------- | 503 ------------- |
| 477 | 504 |
| 478 ```javascript | 505 ```javascript |
| 479 class Rule { | 506 class Rule { |
| 480 constructor (); | 507 constructor (); |
| 481 attribute SelectorQuery selector; // O(1) | 508 attribute SelectorQuery selector; // O(1) |
| 482 attribute String? pseudoElement; // O(1) | 509 attribute String pseudoElement; // O(1) |
| 483 attribute StyleDeclaration styles; // O(1) | 510 attribute StyleDeclaration styles; // O(1) |
| 484 } | 511 } |
| 485 ``` | 512 ``` |
| 486 | 513 |
| 487 Each frame, at some defined point relative to requestAnimationFrame(), | 514 Each frame, at some defined point relative to requestAnimationFrame(), |
| 488 if a Rule has started applying, or a Rule stopped applying, to an | 515 if a Rule has started applying, or a Rule stopped applying, to an |
| 489 element, sky:core calls thatElement.style.clearFrameStyles() and then, | 516 element, sky:core calls thatElement.style.clearFrameStyles() and then, |
| 490 for each Rule that now applies, calls | 517 for each Rule that now applies, calls |
| 491 thatElement.style.addFrameStyles() with the relevant StyleDeclaration | 518 thatElement.style.addFrameStyles() with the relevant StyleDeclaration |
| 492 and pseudoElement from each such Rule. | 519 and pseudoElement from each such Rule. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 When an Element is to be removed from its parent, regardless of the | 557 When an Element is to be removed from its parent, regardless of the |
| 531 above, the node's renderNode attribute should be nulled out. | 558 above, the node's renderNode attribute should be nulled out. |
| 532 | 559 |
| 533 When a RenderNode is added with isNew=true, call its parent | 560 When a RenderNode is added with isNew=true, call its parent |
| 534 RenderNode's LayoutManager's childAdded() callback. When a a | 561 RenderNode's LayoutManager's childAdded() callback. When a a |
| 535 RenderNode has its isGhost property set to true, then call it's parent | 562 RenderNode has its isGhost property set to true, then call it's parent |
| 536 RenderNode's LayoutManager's childRemoved() callback. | 563 RenderNode's LayoutManager's childRemoved() callback. |
| 537 | 564 |
| 538 | 565 |
| 539 ```javascript | 566 ```javascript |
| 540 callback any ValueResolver (any value, String propertyName, RenderNode node, Flo
at containerWidth, Float containerHeight); | 567 dictionary PropertySettings { |
| 568 String? name = null; // null if the property can't be set from a <style> block |
| 569 StyleGrammar? grammar = null; // must be non-null if name is non-null; must be
null otherwise |
| 570 Boolean inherited = false; |
| 571 any initialValue = null; |
| 572 Boolean needsManager = false; |
| 573 Boolean needsLayout = false; |
| 574 Boolean needsPaint = false; |
| 575 // PropertyHandle propertyHandle; // assigned by registerProperty |
| 576 // Integer dependencyBit; // assigned by StyleValueResolverSettings.dependsOn(
) |
| 577 } |
| 578 |
| 579 dictionary GetPropertySettings { |
| 580 String pseudoElement = ''; |
| 581 Boolean forceCache = false; |
| 582 // if set to true, will return the cached value if any, or null otherwise |
| 583 // this is used by transitions to figure out what to transition from |
| 584 } |
| 541 | 585 |
| 542 class RenderNode { // implemented in C++ with no virtual tables | 586 class RenderNode { // implemented in C++ with no virtual tables |
| 543 // this is generated before layout | 587 // this is generated before layout |
| 544 readonly attribute String text; | 588 readonly attribute String text; |
| 545 readonly attribute Node? parentNode; | 589 readonly attribute Node? parentNode; |
| 546 readonly attribute Node? firstChild; | 590 readonly attribute Node? firstChild; |
| 547 readonly attribute Node? nextSibling; | 591 readonly attribute Node? nextSibling; |
| 548 | 592 |
| 549 any getProperty(PropertyHandle property, String? pseudoElement = null); | 593 // internal state: |
| 594 // - back pointer to backing Node, if we're not a ghost |
| 595 // - cache of resolved property values, mapping as follows: |
| 596 // - pseudoElement, property => StyleValue object, resolved value, StyleVal
ueResolverSettings, cascade dirty bit, value dirty bit |
| 597 // - property state map (initially empty), as follows: |
| 598 // - pseudoElement, property => object |
| 599 |
| 600 any getProperty(PropertyHandle property, GetPropertySettings? settings = null)
; |
| 550 // looking at the cached data for the given pseudoElement: | 601 // looking at the cached data for the given pseudoElement: |
| 551 // if there's a cached value, return it | 602 // if there's a cached value: |
| 552 // otherwise, figure out which StyleValue we're going to be using, in this
order: | 603 // if settings.forceCache is true, return the value |
| 553 // - look out our override declarations (first with the pseudo, if any, t
hen without) | 604 // if neither dirty bit is set, return the cached resolved value |
| 554 // - if there's an element: | 605 // if the cascade dirty bit is not set (value dirty is set) then |
| 555 // - look at this element's StyleDeclarations (first with the pseudo, i
f any, then without) | 606 // resolve the value using the same StyleValue object |
| 556 // - if it's an inherited property and there's a parent: | 607 // - with firstTime=false on the resolver settings |
| 557 // - call getProperty() on the parent (without the pseudo) | 608 // - with the cached state object if any |
| 558 // - use the default value | 609 // if settings.forceCache is true, return null |
| 559 // resolve the StyleValue giving it the property and node in question | 610 // - if there's an override declaration with the property (with |
| 560 // cache the value, along with the StyleValueResolverSettings | 611 // the pseudo or without), then get the value object from there and |
| 612 // jump to "resolve" below. |
| 613 // - if there's an element and it has a style declaration with the property |
| 614 // (with the pseudo or without), then get the value object from there |
| 615 // and jump to "resolve" below. |
| 616 // - if it's not an inherited property, or if there's no parent, then get t
he |
| 617 // default value and jump to "resolve" below. |
| 618 // - call the parent render node's getProperty() with the same property |
| 619 // but no settings, then cache that value as the value for this element |
| 620 // with the given pseudoElement, with no StyleValue object, no resolver |
| 621 // settings, and set the state to null. |
| 622 // resolve: |
| 623 // - get a new resolver settings object |
| 624 // - if the obtained StyleValue object is different than the |
| 625 // cached StyleValue object, or if there is no cached object, then set |
| 626 // the resolver settings to firstTime=true, otherwise it's the same obj
ect |
| 627 // and set firstTime=false. |
| 628 // - set the resolver settings' state to the current state for this |
| 629 // pseudoElement/property combination |
| 630 // - using the obtained StyleValue object, call resolve(), |
| 631 // passing it this node and the resolver settings object. |
| 632 // - update the cache with the obtained value and resolver settings, |
| 633 // resetting the dirty bits; update the state similarly |
| 561 | 634 |
| 562 readonly attribute RenderNodeStyleDeclarationList overrideStyles; | 635 readonly attribute RenderNodeStyleDeclarationList overrideStyles; |
| 563 // mutable; initially empty | 636 // mutable; initially empty |
| 564 // this is used when isGhost is true, and can also be used more generally t
o | 637 // this is used when isGhost is true, and can also be used more generally t
o |
| 565 // override styles from the layout manager (e.g. to animate a new node into
view) | 638 // override styles from the layout manager (e.g. to animate a new node into
view) |
| 566 | 639 |
| 567 private void cascadedValueAdded(PropertyHandle property, String? pseudoElement
= null); | 640 private void cascadedValueChanged(PropertyHandle property, String pseudoElemen
t = ''); |
| 568 private void cascadedValueRemoved(PropertyHandle property, String? pseudoEleme
nt = null); | 641 private void cascadedValueDirty(PropertyHandle property, String pseudoElement
= ''); |
| 569 private void cascadedValueChanged(PropertyHandle property, String? pseudoEleme
nt = null); | 642 // - set the appropriate dirty bit on the cached data for this property/pseu
doElement pair |
| 570 private void cascadedValueDirty(PropertyHandle property, String? pseudoElement
= null); | 643 // - cascade dirty for cascadedValueChanged |
| 571 // - clear the cached data for this property/pseudoElement pair | 644 // - value dirty for cascadedValueDirty |
| 572 // - if the property is needsManager, set needsManager to true | 645 // - if the property is needsManager, set needsManager to true |
| 573 // - if the property is needsLayout, set needsLayout to true and walk | 646 // - if the property is needsLayout, set needsLayout to true and walk up the |
| 574 // up the tree setting descendantNeedsLayout | 647 // tree setting descendantNeedsLayout |
| 575 // - if the property is needsPaint, add the node to the list of nodes that n
eed painting | 648 // - if the property is needsPaint, add the node to the list of nodes that n
eed painting |
| 576 // - if the property has a dependencyBit defined, then check the cache of al
l the | 649 // - if the property has a dependencyBit defined, then check the cache of al
l the |
| 577 // properties on this RenderNode, and the cache for the property in all th
e child | 650 // properties on this RenderNode, and the cache for the property in all th
e child |
| 578 // nodes and (if pseudoElement is null) or the pseudoElements | 651 // nodes and, if pseudoElement is '', the pseudoElements of this node, and
, |
| 579 // and if any of them have the relevant dependency bit set then call | 652 // if any of them have the relevant dependency bit set, then call |
| 580 // thatRenderNode.cascadedValueDirty(thatProperty, thatPseudoElement) | 653 // thatRenderNode.cascadedValueDirty(thatProperty, thatPseudoElement) |
| 581 // - if the property is inherited: | 654 // - if the property is inherited, then for each child node, and, if pseudoE
lement |
| 582 // - call this.cascadedValueDirty(property, eachPseudoElement) | 655 // is '', the pseudoElements of this node, if the cached value for this pr
operty |
| 583 // - call eachChildRenderNode.cascadedValueDirty(property, null) | 656 // is present but has no StyleValue, call thatNode.cascadedValueChanged(pr
operty, thatPseudoElement) |
| 584 // (these four methods all do the same thing; they might get merged into one
. For now | |
| 585 // they're separate in case we want to make them cleverer later.) | |
| 586 | 657 |
| 587 readonly attribute Boolean needsManager; | 658 readonly attribute Boolean needsManager; |
| 588 // means that a property with needsManager:true has changed on this node | 659 // means that a property with needsManager:true has changed on this node |
| 589 | 660 |
| 590 readonly attribute Boolean needsLayout; | 661 readonly attribute Boolean needsLayout; |
| 591 // means that either needsManager is true or a property with needsLayout:tru
e has changed on this node | 662 // means that either needsManager is true or a property with needsLayout:tru
e has changed on this node |
| 592 // needsLayout is set to false by the ownerLayoutManager's default layout()
method | 663 // needsLayout is set to false by the ownerLayoutManager's default layout()
method |
| 593 | 664 |
| 594 readonly attribute Boolean descendantNeedsLayout; | 665 readonly attribute Boolean descendantNeedsLayout; |
| 595 // means that some child of this node has needsLayout set to true | 666 // means that some child of this node has needsLayout set to true |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 733 |
| 663 virtual Array<EventTarget> getEventDispatchChain(); // O(N) in number of this.
node's ancestors // implements EventTarget.getEventDispatchChain() | 734 virtual Array<EventTarget> getEventDispatchChain(); // O(N) in number of this.
node's ancestors // implements EventTarget.getEventDispatchChain() |
| 664 // let result = []; | 735 // let result = []; |
| 665 // let node = this.node; | 736 // let node = this.node; |
| 666 // while (node && node.layoutManager) { | 737 // while (node && node.layoutManager) { |
| 667 // result.push(node.layoutManager); | 738 // result.push(node.layoutManager); |
| 668 // node = node.parentNode; | 739 // node = node.parentNode; |
| 669 // } | 740 // } |
| 670 // return result; | 741 // return result; |
| 671 | 742 |
| 672 void setProperty(RenderNode node, PropertyHandle property, any value, String?
pseudoElement = null); // O(1) | 743 void setProperty(RenderNode node, PropertyHandle property, any value, String p
seudoElement = ''); // O(1) |
| 673 // if called from an adjustProperties() method during the property adjustmen
t phase, | 744 // if called from an adjustProperties() method during the property adjustmen
t phase, |
| 674 // replaces the value that getProperty() would return on that node with /val
ue/ | 745 // replaces the value that getProperty() would return on that node with /val
ue/ |
| 746 // this also clears the dependency bits and sets the property state to null |
| 675 | 747 |
| 676 void take(RenderNode victim); // sets victim.ownerLayoutManager = this; | 748 void take(RenderNode victim); // sets victim.ownerLayoutManager = this; |
| 677 // assert: victim hasn't been take()n yet during this layout | 749 // assert: victim hasn't been take()n yet during this layout |
| 678 // assert: victim.needsLayout == true | 750 // assert: victim.needsLayout == true |
| 679 // assert: an ancestor of victim has node.layoutManager == this (aka, victim
is a descendant of this.node) | 751 // assert: an ancestor of victim has node.layoutManager == this (aka, victim
is a descendant of this.node) |
| 680 | 752 |
| 681 virtual void release(RenderNode victim); | 753 virtual void release(RenderNode victim); |
| 682 // called when the RenderNode was removed from the tree | 754 // called when the RenderNode was removed from the tree |
| 683 | 755 |
| 684 virtual void childAdded(RenderNode child); | 756 virtual void childAdded(RenderNode child); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 ``` | 1000 ``` |
| 929 | 1001 |
| 930 The ``div`` element doesn't have any default styles. | 1002 The ``div`` element doesn't have any default styles. |
| 931 | 1003 |
| 932 These declarations are all shared between all the elements (so e.g. if | 1004 These declarations are all shared between all the elements (so e.g. if |
| 933 you reach in and change the declaration that was added to a ``title`` | 1005 you reach in and change the declaration that was added to a ``title`` |
| 934 element, you're going to change the styles of all the other | 1006 element, you're going to change the styles of all the other |
| 935 default-hidden elements). (In other words, in the code snippets above, | 1007 default-hidden elements). (In other words, in the code snippets above, |
| 936 the ``d`` variable is initialised in shared code, and only the | 1008 the ``d`` variable is initialised in shared code, and only the |
| 937 addStyles() call is per-element.) | 1009 addStyles() call is per-element.) |
| OLD | NEW |