From 7a48cb68153cd7ca86c17cd1e59f00ac082cbc8d Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 24 Oct 2013 16:09:46 +0200 Subject: [PATCH] Only export an explicit public API in the style crate I.e. make every module private by default. --- src/components/main/css/select.rs | 2 +- src/components/main/layout/box.rs | 15 +++------- .../main/layout/display_list_builder.rs | 4 +-- src/components/main/layout/layout_task.rs | 4 +-- src/components/main/layout/model.rs | 2 +- src/components/script/dom/node.rs | 3 +- src/components/style/properties.rs.mako | 29 +++++++++++-------- src/components/style/style.rc | 23 +++++++-------- 8 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/components/main/css/select.rs b/src/components/main/css/select.rs index a3e055a8e91..af020d04ae8 100644 --- a/src/components/main/css/select.rs +++ b/src/components/main/css/select.rs @@ -4,7 +4,7 @@ use style::Stylesheet; use style::Stylist; -use style::selector_matching::UserAgentOrigin; +use style::UserAgentOrigin; pub fn new_stylist() -> Stylist { let mut stylist = Stylist::new(); diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index 5dc426d3af0..dc5243b0b4d 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -26,16 +26,9 @@ use std::cmp::ApproxEq; use std::num::Zero; use std::unstable::raw::Box; use style::ComputedValues; -use style::computed_values::border_style; -use style::computed_values::clear; -use style::computed_values::float; -use style::properties::longhands::font_family::FamilyName; -use style::computed_values::font_style; -use style::computed_values::line_height; -use style::computed_values::position; -use style::computed_values::text_align; -use style::computed_values::text_decoration; -use style::computed_values::vertical_align; +use style::computed_values::{ + border_style, clear, float, font_family, font_style, line_height, + position, text_align, text_decoration, vertical_align}; use css::node_style::StyledNode; use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData, ToGfxColor}; @@ -733,7 +726,7 @@ impl RenderBoxBase { // FIXME: Too much allocation here. let font_families = do my_style.Font.font_family.map |family| { match *family { - FamilyName(ref name) => (*name).clone(), + font_family::FamilyName(ref name) => (*name).clone(), } }; let font_families = font_families.connect(", "); diff --git a/src/components/main/layout/display_list_builder.rs b/src/components/main/layout/display_list_builder.rs index ac0cfaf716a..5e8ebc12305 100644 --- a/src/components/main/layout/display_list_builder.rs +++ b/src/components/main/layout/display_list_builder.rs @@ -23,7 +23,7 @@ pub type Nothing = (); impl ExtraDisplayListData for AbstractNode<()> { fn new(box: &@RenderBox) -> AbstractNode<()> { - unsafe { + unsafe { transmute(box.base().node) } } @@ -61,7 +61,7 @@ pub trait ToGfxColor { fn to_gfx_color(&self) -> gfx::color::Color; } -impl ToGfxColor for style::properties::RGBA { +impl ToGfxColor for style::computed_values::RGBA { fn to_gfx_color(&self) -> gfx::color::Color { gfx::color::rgba(self.red, self.green, self.blue, self.alpha) } diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs index a0a2161e2da..819cfffcf72 100644 --- a/src/components/main/layout/layout_task.rs +++ b/src/components/main/layout/layout_task.rs @@ -32,7 +32,7 @@ use gfx::render_task::{RenderMsg, RenderChan, RenderLayer}; use gfx::render_task; use style::Stylist; use style::Stylesheet; -use style::selector_matching::AuthorOrigin; +use style::AuthorOrigin; use script::dom::event::ReflowEvent; use script::dom::node::{AbstractNode, LayoutView}; use script::layout_interface::{AddStylesheetMsg, ContentBoxQuery}; @@ -240,7 +240,7 @@ impl LayoutTask { screen_size: None, display_list: None, - + stylist: RWArc::new(new_stylist()), profiler_chan: profiler_chan, } diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index cc66ec1f70d..1569442f63a 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -8,7 +8,7 @@ use std::num::Zero; use geom::side_offsets::SideOffsets2D; use servo_util::geometry::Au; use style::ComputedValues; -use style::properties::common_types::computed; +use computed = style::computed_values; /// Encapsulates the borders, padding, and margins, which we collectively call the "box model". #[deriving(Clone)] diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 725d69e711f..bcfe7f93373 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -23,8 +23,7 @@ use std::cast::transmute; use std::unstable::raw::Box; use extra::arc::Arc; use js::jsapi::{JSObject, JSContext}; -use style::ComputedValues; -use style::properties::PropertyDeclaration; +use style::{ComputedValues, PropertyDeclaration}; use servo_util::tree::{TreeNode, TreeNodeRef, TreeNodeRefAsElement}; use servo_util::range::Range; use gfx::display_list::DisplayList; diff --git a/src/components/style/properties.rs.mako b/src/components/style/properties.rs.mako index 20cff68c7d3..c12062e504d 100644 --- a/src/components/style/properties.rs.mako +++ b/src/components/style/properties.rs.mako @@ -402,20 +402,20 @@ pub mod longhands { <%self:longhand name="font-family" inherited="True"> pub use to_computed_value = super::computed_as_specified; - #[deriving(Eq, Clone)] - pub enum FontFamily { - FamilyName(~str), - // Generic -// Serif, -// SansSerif, -// Cursive, -// Fantasy, -// Monospace, - } - pub type SpecifiedValue = ~[FontFamily]; pub mod computed_value { - pub type T = super::SpecifiedValue; + #[deriving(Eq, Clone)] + pub enum FontFamily { + FamilyName(~str), + // Generic +// Serif, +// SansSerif, +// Cursive, +// Fantasy, +// Monospace, + } + pub type T = ~[FontFamily]; } + pub type SpecifiedValue = computed_value::T; #[inline] pub fn get_initial_value() -> computed_value::T { ~[FamilyName(~"serif")] } /// # /// = | [ + ] @@ -1119,4 +1119,9 @@ pub mod computed_values { % endfor // Don't use a side-specific name needlessly: pub use border_style = super::longhands::border_top_style::computed_value; + + pub use cssparser::RGBA; + pub use super::common_types::computed::{ + LengthOrPercentage, LP_Length, LP_Percentage, + LengthOrPercentageOrAuto, LPA_Length, LPA_Percentage, LPA_Auto}; } diff --git a/src/components/style/style.rc b/src/components/style/style.rc index 6fe31302f7c..1579d3abcd3 100644 --- a/src/components/style/style.rc +++ b/src/components/style/style.rc @@ -18,21 +18,20 @@ extern mod cssparser; extern mod servo_util (name = "util"); -// The "real" public API +// Public API pub use stylesheets::Stylesheet; -pub use selector_matching::{Stylist, StylesheetOrigin}; -pub use properties::{cascade, ComputedValues, computed_values}; +pub use selector_matching::{Stylist, StylesheetOrigin, UserAgentOrigin, AuthorOrigin, UserOrigin}; +pub use properties::{cascade, PropertyDeclaration, ComputedValues, computed_values}; pub use properties::{PropertyDeclarationBlock, parse_style_attribute}; // Style attributes -// Things that need to be public to make the compiler happy -pub mod stylesheets; -pub mod errors; -pub mod selectors; -pub mod selector_matching; -pub mod properties; -pub mod namespaces; -pub mod media_queries; -pub mod parsing_utils; +mod stylesheets; +mod errors; +mod selectors; +mod selector_matching; +mod properties; +mod namespaces; +mod media_queries; +mod parsing_utils; #[cfg(test)] mod tests;