Skip to content

Commit

Permalink
update visibility of constructor of LayoutObject
Browse files Browse the repository at this point in the history
  • Loading branch information
d0iasm committed Aug 17, 2024
1 parent d776a09 commit d67933f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
52 changes: 50 additions & 2 deletions core/src/renderer/layout/layout_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::display_item::DisplayItem;
use crate::renderer::css::cssom::ComponentValue;
use crate::renderer::css::cssom::Declaration;
use crate::renderer::css::cssom::Selector;
use crate::renderer::css::cssom::StyleSheet;
use crate::renderer::css::token::CssToken;
use crate::renderer::dom::node::ElementKind;
use crate::renderer::dom::node::Node;
Expand All @@ -30,6 +31,53 @@ use alloc::string::String;
use alloc::vec::Vec;
use core::cell::RefCell;

pub fn create_layout_object(
browser: Weak<RefCell<Browser>>,
node: &Option<Rc<RefCell<Node>>>,
parent_obj: &Option<Rc<RefCell<LayoutObject>>>,
cssom: &StyleSheet,
) -> Option<Rc<RefCell<LayoutObject>>> {
match node {
Some(n) => {
let layout_object =
Rc::new(RefCell::new(LayoutObject::new(browser.clone(), n.clone())));

// Apply CSS rules to LayoutObject.
for rule in &cssom.rules {
if layout_object.borrow().is_node_selected(&rule.selector) {
layout_object
.borrow_mut()
.cascading_style(rule.declarations.clone());
}
}

// Apply a default value to a property.
{
layout_object.borrow_mut().defaulting_style(n);
}

// Inherit a parent CSS style.
if let Some(parent) = parent_obj {
layout_object
.borrow_mut()
.inherit_style(&parent.borrow().style());
}

let display_type = layout_object.borrow().style().display();
if display_type == DisplayType::DisplayNone {
return None;
}

let kind = layout_object.borrow().kind();
layout_object
.borrow_mut()
.set_kind(layout_object_kind_from_display(kind, display_type));
Some(layout_object)
}
None => None,
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum LayoutObjectKind {
Block,
Expand All @@ -52,7 +100,7 @@ fn layout_object_kind_by_node(node: &Rc<RefCell<Node>>) -> LayoutObjectKind {
}
}

pub fn layout_object_kind_from_display(
fn layout_object_kind_from_display(
kind: LayoutObjectKind,
display: DisplayType,
) -> LayoutObjectKind {
Expand Down Expand Up @@ -85,7 +133,7 @@ pub struct LayoutObject {
}

impl LayoutObject {
pub fn new(browser: Weak<RefCell<Browser>>, node: Rc<RefCell<Node>>) -> Self {
fn new(browser: Weak<RefCell<Browser>>, node: Rc<RefCell<Node>>) -> Self {
Self {
browser,
kind: layout_object_kind_by_node(&node),
Expand Down
50 changes: 1 addition & 49 deletions core/src/renderer/layout/layout_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use crate::renderer::css::cssom::StyleSheet;
use crate::renderer::dom::api::get_target_element_node;
use crate::renderer::dom::node::ElementKind;
use crate::renderer::dom::node::Node;
use crate::renderer::layout::computed_style::*;
use crate::renderer::layout::layout_object::layout_object_kind_from_display;
use crate::renderer::layout::layout_object::create_layout_object;
use crate::renderer::layout::layout_object::LayoutObject;
use crate::renderer::layout::layout_object::LayoutObjectKind;
use crate::renderer::layout::layout_point::LayoutPoint;
Expand All @@ -19,53 +18,6 @@ use alloc::rc::{Rc, Weak};
use alloc::vec::Vec;
use core::cell::RefCell;

fn create_layout_object(
browser: Weak<RefCell<Browser>>,
node: &Option<Rc<RefCell<Node>>>,
parent_obj: &Option<Rc<RefCell<LayoutObject>>>,
cssom: &StyleSheet,
) -> Option<Rc<RefCell<LayoutObject>>> {
match node {
Some(n) => {
let layout_object =
Rc::new(RefCell::new(LayoutObject::new(browser.clone(), n.clone())));

// Apply CSS rules to LayoutObject.
for rule in &cssom.rules {
if layout_object.borrow().is_node_selected(&rule.selector) {
layout_object
.borrow_mut()
.cascading_style(rule.declarations.clone());
}
}

// Apply a default value to a property.
{
layout_object.borrow_mut().defaulting_style(n);
}

// Inherit a parent CSS style.
if let Some(parent) = parent_obj {
layout_object
.borrow_mut()
.inherit_style(&parent.borrow().style());
}

let display_type = layout_object.borrow().style().display();
if display_type == DisplayType::DisplayNone {
return None;
}

let kind = layout_object.borrow().kind();
layout_object
.borrow_mut()
.set_kind(layout_object_kind_from_display(kind, display_type));
Some(layout_object)
}
None => None,
}
}

/// Converts DOM tree to render tree.
fn build_layout_tree(
browser: Weak<RefCell<Browser>>,
Expand Down

0 comments on commit d67933f

Please sign in to comment.