mirror of
https://github.com/servo/servo.git
synced 2025-10-02 01:29:15 +01:00
style: Refactor TRestyleDamage and TNode to accept/provide a "style source"
In the Gecko case, this style source would be the style context. In the servo case, it will be always the computed values. We could optimise this further in the case of stylo (from three FFI calls to one) if we use an API of the form CalcAndStore(node, new_cv). But that would imply borrowing the data twice from Servo (we also have borrow_data_unchecked fwiw, but...).
This commit is contained in:
parent
1470d5b174
commit
6d67525172
10 changed files with 120 additions and 48 deletions
|
@ -144,6 +144,10 @@ use structs::nsFont;
|
|||
use structs::FontFamilyList;
|
||||
use structs::FontFamilyType;
|
||||
use structs::nsIAtom;
|
||||
use structs::nsStyleContext;
|
||||
unsafe impl Send for nsStyleContext {}
|
||||
unsafe impl Sync for nsStyleContext {}
|
||||
impl HeapSizeOf for nsStyleContext { fn heap_size_of_children(&self) -> usize { 0 } }
|
||||
|
||||
pub type RawGeckoNode = nsINode;
|
||||
pub enum Element { }
|
||||
|
@ -294,7 +298,9 @@ extern "C" {
|
|||
pub fn Gecko_GetNodeFlags(node: *mut RawGeckoNode) -> u32;
|
||||
pub fn Gecko_SetNodeFlags(node: *mut RawGeckoNode, flags: u32);
|
||||
pub fn Gecko_UnsetNodeFlags(node: *mut RawGeckoNode, flags: u32);
|
||||
pub fn Gecko_CalcStyleDifference(oldstyle: *mut ServoComputedValues,
|
||||
pub fn Gecko_GetStyleContext(node: *mut RawGeckoNode)
|
||||
-> *mut nsStyleContext;
|
||||
pub fn Gecko_CalcStyleDifference(oldstyle: *mut nsStyleContext,
|
||||
newstyle: *mut ServoComputedValues)
|
||||
-> nsChangeHint;
|
||||
pub fn Gecko_StoreStyleDifference(node: *mut RawGeckoNode,
|
||||
|
|
|
@ -128,7 +128,7 @@ COMPILATION_TARGETS = {
|
|||
"nsStyleCoord::Calc", "nsRestyleHint", "ServoElementSnapshot",
|
||||
"nsChangeHint", "SheetParsingMode", "nsMainThreadPtrHandle",
|
||||
"nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList",
|
||||
"FontFamilyType", "nsIAtom",
|
||||
"FontFamilyType", "nsIAtom", "nsStyleContext"
|
||||
],
|
||||
"void_types": [
|
||||
"nsINode", "nsIDocument", "nsIPrincipal", "nsIURI",
|
||||
|
|
|
@ -8,6 +8,7 @@ use gecko_bindings::bindings;
|
|||
use gecko_bindings::bindings::Gecko_ChildrenCount;
|
||||
use gecko_bindings::bindings::Gecko_ClassOrClassList;
|
||||
use gecko_bindings::bindings::Gecko_GetNodeData;
|
||||
use gecko_bindings::bindings::Gecko_GetStyleContext;
|
||||
use gecko_bindings::bindings::ServoComputedValues;
|
||||
use gecko_bindings::bindings::ServoNodeData;
|
||||
use gecko_bindings::bindings::{Gecko_CalcStyleDifference, Gecko_StoreStyleDifference};
|
||||
|
@ -24,7 +25,7 @@ use gecko_bindings::bindings::{Gecko_IsUnvisitedLink, Gecko_IsVisitedLink};
|
|||
use gecko_bindings::bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsElement, Gecko_SetNodeData};
|
||||
use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode};
|
||||
use gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO};
|
||||
use gecko_bindings::structs::{nsIAtom, nsChangeHint};
|
||||
use gecko_bindings::structs::{nsIAtom, nsChangeHint, nsStyleContext};
|
||||
use glue::GeckoDeclarationBlock;
|
||||
use libc::uintptr_t;
|
||||
use selectors::Element;
|
||||
|
@ -97,19 +98,19 @@ impl<'ln> GeckoNode<'ln> {
|
|||
pub struct GeckoRestyleDamage(nsChangeHint);
|
||||
|
||||
impl TRestyleDamage for GeckoRestyleDamage {
|
||||
fn compute(previous_style: Option<&Arc<ComputedValues>>,
|
||||
current_style: &Arc<ComputedValues>) -> Self {
|
||||
type PreExistingComputedValues = nsStyleContext;
|
||||
fn compute(source: Option<&nsStyleContext>,
|
||||
new_style: &Arc<ComputedValues>) -> Self {
|
||||
type Helpers = ArcHelpers<ServoComputedValues, ComputedValues>;
|
||||
let previous_style = match previous_style {
|
||||
Some(previous) => previous,
|
||||
let context = match source {
|
||||
Some(ctx) => ctx as *const nsStyleContext as *mut nsStyleContext,
|
||||
None => return Self::rebuild_and_reflow(),
|
||||
};
|
||||
|
||||
let previous = unsafe { Helpers::borrow(previous_style) };
|
||||
let current = unsafe { Helpers::borrow(current_style) };
|
||||
let hint = unsafe { Gecko_CalcStyleDifference(*previous, *current) };
|
||||
|
||||
GeckoRestyleDamage(hint)
|
||||
Helpers::borrow(new_style, |new_style| {
|
||||
let hint = unsafe { Gecko_CalcStyleDifference(context, new_style) };
|
||||
GeckoRestyleDamage(hint)
|
||||
})
|
||||
}
|
||||
|
||||
fn rebuild_and_reflow() -> Self {
|
||||
|
@ -307,6 +308,20 @@ impl<'ln> TNode for GeckoNode<'ln> {
|
|||
}
|
||||
}
|
||||
|
||||
fn existing_style_for_restyle_damage<'a>(&'a self,
|
||||
current_cv: Option<&'a Arc<ComputedValues>>)
|
||||
-> Option<&'a nsStyleContext> {
|
||||
if current_cv.is_none() {
|
||||
// Don't bother in doing an ffi call to get null back.
|
||||
return None;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let context_ptr = Gecko_GetStyleContext(self.node);
|
||||
context_ptr.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
fn needs_dirty_on_viewport_size_changed(&self) -> bool {
|
||||
// Gecko's node doesn't have the DIRTY_ON_VIEWPORT_SIZE_CHANGE flag,
|
||||
// so we force them to be dirtied on viewport size change, regardless if
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue