Skip to content

Commit

Permalink
Use the new style system
Browse files Browse the repository at this point in the history
Credits to:
    Deokjin Kim
    Ilyong Cho
    Jaeman Park
    Junyoung Cho
    Ryan Choi
    Sangeun Kim
    Yongjin Kim
    Youngmin Yoo
    Youngsoo Son
  • Loading branch information
sanxiyn committed Oct 23, 2013
1 parent f3f6e62 commit b243191
Show file tree
Hide file tree
Showing 28 changed files with 347 additions and 488 deletions.
8 changes: 4 additions & 4 deletions Makefile.in
Expand Up @@ -219,21 +219,21 @@ DONE_msg = $(B)src/components/msg/libmsg.dummy

DEPS_msg = $(CRATE_msg) $(SRC_msg) $(DONE_SUBMODULES)

RFLAGS_gfx = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util -L $(B)src/components/net -L $(B)src/components/msg
RFLAGS_gfx = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util -L $(B)src/components/style -L $(B)src/components/net -L $(B)src/components/msg
SRC_gfx = $(call rwildcard,$(S)src/components/gfx/,*.rs)
CRATE_gfx = $(S)src/components/gfx/gfx.rc
DONE_gfx = $(B)src/components/gfx/libgfx.dummy

DEPS_gfx = $(CRATE_gfx) $(SRC_gfx) $(DONE_SUBMODULES) $(DONE_util) $(DONE_net) $(DONE_msg)
DEPS_gfx = $(CRATE_gfx) $(SRC_gfx) $(DONE_SUBMODULES) $(DONE_util) $(DONE_style) $(DONE_net) $(DONE_msg)

RFLAGS_script = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util -L $(B)src/components/net -L $(B)src/components/gfx -L $(B)src/components/msg
RFLAGS_script = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util -L $(B)src/components/style -L $(B)src/components/net -L $(B)src/components/gfx -L $(B)src/components/msg
WEBIDL_script = $(call rwildcard,$(S)src/components/script/,*.webidl)
AUTOGEN_SRC_script = $(patsubst %.webidl, %Binding.rs, $(WEBIDL_script))
SRC_script = $(call rwildcard,$(S)src/components/script/,*.rs) $(AUTOGEN_SRC_script)
CRATE_script = $(S)src/components/script/script.rc
DONE_script = $(B)src/components/script/libscript.dummy

DEPS_script = $(CRATE_script) $(SRC_script) $(DONE_SUBMODULES) $(DONE_util) $(DONE_net) $(DONE_gfx) $(DONE_msg)
DEPS_script = $(CRATE_script) $(SRC_script) $(DONE_SUBMODULES) $(DONE_util) $(DONE_style) $(DONE_net) $(DONE_gfx) $(DONE_msg)

RFLAGS_style = $(strip $(CFG_RUSTC_FLAGS)) $(addprefix -L $(B)src/,$(DEPS_SUBMODULES)) -L $(B)src/components/util
MAKO_ZIP = $(S)src/components/style/Mako-0.8.1.zip
Expand Down
9 changes: 4 additions & 5 deletions src/components/gfx/color.rs
Expand Up @@ -8,15 +8,14 @@ use AzColor = azure::azure_hl::Color;
pub type Color = AzColor;

pub fn rgb(r: u8, g: u8, b: u8) -> AzColor {
rgba(r, g, b, 1.0)
}

pub fn rgba(r: u8, g: u8, b: u8, a: f64) -> AzColor {
AzColor {
r: (r as AzFloat) / (255.0 as AzFloat),
g: (g as AzFloat) / (255.0 as AzFloat),
b: (b as AzFloat) / (255.0 as AzFloat),
a: a as AzFloat
a: 1.0 as AzFloat
}
}

pub fn rgba(r: AzFloat, g: AzFloat, b: AzFloat, a: AzFloat) -> AzColor {
AzColor { r: r, g: g, b: b, a: a }
}
41 changes: 18 additions & 23 deletions src/components/gfx/display_list.rs
Expand Up @@ -16,7 +16,7 @@

use color::Color;
use servo_util::geometry::Au;
use newcss::values::CSSBorderStyle;
use style::computed_values::border_style;
use render_context::RenderContext;
use text::SendableTextRun;

Expand All @@ -26,8 +26,6 @@ use servo_net::image::base::Image;
use servo_util::range::Range;
use extra::arc::Arc;

use newcss::values::{CSSTextDecorationUnderline, CSSTextDecorationOverline, CSSTextDecorationLineThrough};

/// A list of rendering operations to be performed.
pub struct DisplayList<E> {
list: ~[DisplayItem<E>]
Expand Down Expand Up @@ -110,7 +108,7 @@ pub struct BorderDisplayItem<E> {
color: SideOffsets2D<Color>,

/// The border styles.
style: SideOffsets2D<CSSBorderStyle>
style: SideOffsets2D<border_style::T>
}

impl<E> DisplayItem<E> {
Expand Down Expand Up @@ -143,25 +141,22 @@ impl<E> DisplayItem<E> {
let strikeout_size = font.metrics.strikeout_size;
let strikeout_offset = font.metrics.strikeout_offset;

match new_run.decoration {
CSSTextDecorationUnderline => {
let underline_y = baseline_origin.y - underline_offset;
let underline_bounds = Rect(Point2D(baseline_origin.x, underline_y),
Size2D(width, underline_size));
render_context.draw_solid_color(&underline_bounds, text.color);
},
CSSTextDecorationOverline => {
let overline_bounds = Rect(Point2D(baseline_origin.x, origin.y),
Size2D(width, underline_size));
render_context.draw_solid_color(&overline_bounds, text.color);
},
CSSTextDecorationLineThrough => {
let strikeout_y = baseline_origin.y - strikeout_offset;
let strikeout_bounds = Rect(Point2D(baseline_origin.x, strikeout_y),
Size2D(width, strikeout_size));
render_context.draw_solid_color(&strikeout_bounds, text.color);
},
_ => ()
if new_run.decoration.underline {
let underline_y = baseline_origin.y - underline_offset;
let underline_bounds = Rect(Point2D(baseline_origin.x, underline_y),
Size2D(width, underline_size));
render_context.draw_solid_color(&underline_bounds, text.color);
}
if new_run.decoration.overline {
let overline_bounds = Rect(Point2D(baseline_origin.x, origin.y),
Size2D(width, underline_size));
render_context.draw_solid_color(&overline_bounds, text.color);
}
if new_run.decoration.line_through {
let strikeout_y = baseline_origin.y - strikeout_offset;
let strikeout_bounds = Rect(Point2D(baseline_origin.x, strikeout_y),
Size2D(width, strikeout_size));
render_context.draw_solid_color(&strikeout_bounds, text.color);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/gfx/font.rs
Expand Up @@ -28,7 +28,7 @@ use servo_util::time;
use servo_util::time::profile;
use servo_util::time::ProfilerChan;

use newcss::values::CSSTextDecoration;
use style::computed_values::text_decoration;

// FontHandle encapsulates access to the platform's font API,
// e.g. quartz, FreeType. It provides access to metrics and tables
Expand Down Expand Up @@ -195,7 +195,7 @@ impl FontGroup {
self.fonts = ~[];
}

pub fn create_textrun(&self, text: ~str, decoration: CSSTextDecoration) -> TextRun {
pub fn create_textrun(&self, text: ~str, decoration: text_decoration::T) -> TextRun {
assert!(self.fonts.len() > 0);

// TODO(Issue #177): Actually fall back through the FontGroup when a font is unsuitable.
Expand Down
1 change: 1 addition & 0 deletions src/components/gfx/gfx.rc
Expand Up @@ -17,6 +17,7 @@ extern mod stb_image;
extern mod extra;
extern mod servo_net (name = "net");
extern mod servo_util (name = "util");
extern mod style;
extern mod servo_msg (name = "msg");

// Eventually we would like the shaper to be pluggable, as many operating systems have their own
Expand Down
33 changes: 9 additions & 24 deletions src/components/gfx/render_context.rs
Expand Up @@ -5,8 +5,7 @@
use servo_msg::compositor_msg::LayerBuffer;
use servo_util::geometry::Au;
use font_context::FontContext;
use newcss::values::CSSBorderStyle;
use newcss::values::{CSSBorderStyleNone, CSSBorderStyleHidden, CSSBorderStyleDotted, CSSBorderStyleDashed, CSSBorderStyleSolid, CSSBorderStyleDouble, CSSBorderStyleGroove, CSSBorderStyleRidge, CSSBorderStyleInset, CSSBorderStyleOutset};
use style::computed_values::border_style;
use opts::Opts;

use azure::azure_hl::{B8G8R8A8, Color, ColorPattern, DrawOptions};
Expand Down Expand Up @@ -44,7 +43,7 @@ impl<'self> RenderContext<'self> {
bounds: &Rect<Au>,
border: SideOffsets2D<Au>,
color: SideOffsets2D<Color>,
style: SideOffsets2D<CSSBorderStyle>) {
style: SideOffsets2D<border_style::T>) {
let draw_opts = DrawOptions(1 as AzFloat, 0 as uint16_t);
let rect = bounds.to_azure_rect();
let border = border.to_float_px();
Expand Down Expand Up @@ -113,14 +112,14 @@ impl<'self> RenderContext<'self> {
self.canvas.draw_target.fill_rect(&rect, &pattern);
}

fn apply_border_style(style: CSSBorderStyle, border_width: AzFloat, dash: &mut [AzFloat], stroke_opts: &mut StrokeOptions){
fn apply_border_style(style: border_style::T, border_width: AzFloat, dash: &mut [AzFloat], stroke_opts: &mut StrokeOptions){
match style{
CSSBorderStyleNone => {
border_style::none => {
}
CSSBorderStyleHidden => {
border_style::hidden => {
}
//FIXME(sammykim): This doesn't work with dash_pattern and cap_style well. I referred firefox code.
CSSBorderStyleDotted => {
border_style::dotted => {
stroke_opts.line_width = border_width;

if border_width > 2.0 {
Expand All @@ -135,7 +134,7 @@ impl<'self> RenderContext<'self> {
stroke_opts.mDashPattern = vec::raw::to_ptr(dash);
stroke_opts.mDashLength = dash.len() as size_t;
}
CSSBorderStyleDashed => {
border_style::dashed => {
stroke_opts.set_cap_style(AZ_CAP_BUTT as u8);
stroke_opts.line_width = border_width;
dash[0] = border_width*3 as AzFloat;
Expand All @@ -144,28 +143,14 @@ impl<'self> RenderContext<'self> {
stroke_opts.mDashLength = dash.len() as size_t;
}
//FIXME(sammykim): BorderStyleSolid doesn't show proper join-style with comparing firefox.
CSSBorderStyleSolid => {
border_style::solid => {
stroke_opts.set_cap_style(AZ_CAP_BUTT as u8);
stroke_opts.set_join_style(AZ_JOIN_BEVEL as u8);
stroke_opts.line_width = border_width;
stroke_opts.mDashLength = 0 as size_t;
}
//FIXME(sammykim): Five more styles should be implemented.
CSSBorderStyleDouble => {

}
CSSBorderStyleGroove => {

}
CSSBorderStyleRidge => {

}
CSSBorderStyleInset => {

}
CSSBorderStyleOutset => {

}
//double, groove, ridge, inset, outset
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/gfx/text/text_run.rs
Expand Up @@ -10,21 +10,21 @@ use text::glyph::GlyphStore;
use font::{Font, FontDescriptor, RunMetrics};
use servo_util::range::Range;
use extra::arc::Arc;
use newcss::values::CSSTextDecoration;
use style::computed_values::text_decoration;

/// A text run.
pub struct TextRun {
text: ~str,
font: @mut Font,
decoration: CSSTextDecoration,
decoration: text_decoration::T,
glyphs: ~[Arc<GlyphStore>],
}

/// This is a hack until TextRuns are normally sendable, or we instead use Arc<TextRun> everywhere.
pub struct SendableTextRun {
text: ~str,
font: FontDescriptor,
decoration: CSSTextDecoration,
decoration: text_decoration::T,
priv glyphs: ~[Arc<GlyphStore>],
}

Expand Down Expand Up @@ -117,7 +117,7 @@ impl<'self> Iterator<Range> for LineIterator<'self> {
}

impl<'self> TextRun {
pub fn new(font: @mut Font, text: ~str, decoration: CSSTextDecoration) -> TextRun {
pub fn new(font: @mut Font, text: ~str, decoration: text_decoration::T) -> TextRun {
let glyphs = TextRun::break_and_shape(font, text);

let run = TextRun {
Expand Down
94 changes: 44 additions & 50 deletions src/components/main/css/matching.rs
Expand Up @@ -4,72 +4,66 @@

// High-level interface to CSS selector matching.

use css::node_util::NodeUtil;
use css::select_handler::NodeSelectHandler;
use layout::incremental;
use std::cell::Cell;
use css::node_style::StyledNode;

use script::dom::node::{AbstractNode, LayoutView};
use newcss::complete::CompleteSelectResults;
use newcss::select::{SelectCtx, SelectResults};
use style::Stylist;
use style::cascade;
use servo_util::tree::TreeNodeRef;

pub trait MatchMethods {
fn restyle_subtree(&self, select_ctx: &SelectCtx);
fn match_node(&self, stylist: &Stylist);
fn match_subtree(&self, stylist: &Stylist);

fn cascade_node(&self, parent: Option<AbstractNode<LayoutView>>);
fn cascade_subtree(&self, parent: Option<AbstractNode<LayoutView>>);
}

impl MatchMethods for AbstractNode<LayoutView> {
/**
* Performs CSS selector matching on a subtree.
*
* This is, importantly, the function that updates the layout data for
* the node (the reader-auxiliary box in the COW model) with the
* computed style.
*/
fn restyle_subtree(&self, select_ctx: &SelectCtx) {
// Only elements have styles
if self.is_element() {
do self.with_imm_element |elem| {
let inline_style = match elem.style_attribute {
None => None,
Some(ref sheet) => Some(sheet),
};
let select_handler = NodeSelectHandler { node: *self };
let incomplete_results = select_ctx.select_style(self, inline_style, &select_handler);
// Combine this node's results with its parent's to resolve all inherited values
let complete_results = compose_results(*self, incomplete_results);

// If there was an existing style, compute the damage that
// incremental layout will need to fix.
if self.have_css_select_results() {
let damage = incremental::compute_damage(self, self.get_css_select_results(), &complete_results);
self.set_restyle_damage(damage);
}
self.set_css_select_results(complete_results);
fn match_node(&self, stylist: &Stylist) {
let applicable_declarations = do self.with_imm_element |element| {
let style_attribute = match element.style_attribute {
None => None,
Some(ref style_attribute) => Some(style_attribute)
};
stylist.get_applicable_declarations(self, style_attribute, None)
};
let cell = Cell::new(applicable_declarations);
do self.write_layout_data |data| {
data.applicable_declarations = cell.take();
}
}
fn match_subtree(&self, stylist: &Stylist) {
self.match_node(stylist);

for kid in self.children() {
kid.restyle_subtree(select_ctx);
if kid.is_element() {
kid.match_subtree(stylist);
}
}
}
}

fn compose_results(node: AbstractNode<LayoutView>, results: SelectResults)
-> CompleteSelectResults {
match find_parent_element_node(node) {
None => CompleteSelectResults::new_root(results),
Some(parent_node) => {
let parent_results = parent_node.get_css_select_results();
CompleteSelectResults::new_from_parent(parent_results, results)
fn cascade_node(&self, parent: Option<AbstractNode<LayoutView>>) {
let parent_style = match parent {
Some(parent) => Some(parent.style()),
None => None
};
let computed_values = do self.read_layout_data |data| {
cascade(data.applicable_declarations, parent_style)
};
let cell = Cell::new(computed_values);
do self.write_layout_data |data| {
data.style = Some(cell.take());
}
}
}
}
fn cascade_subtree(&self, parent: Option<AbstractNode<LayoutView>>) {
self.cascade_node(parent);

fn find_parent_element_node(node: AbstractNode<LayoutView>) -> Option<AbstractNode<LayoutView>> {
match node.parent_node() {
Some(parent) if parent.is_element() => Some(parent),
Some(parent) => find_parent_element_node(parent),
None => None,
for kid in self.children() {
if kid.is_element() {
kid.cascade_subtree(Some(*self));
}
}
}
}

8 changes: 4 additions & 4 deletions src/components/main/css/node_style.rs
Expand Up @@ -7,22 +7,22 @@
use css::node_util::NodeUtil;
use layout::incremental::RestyleDamage;

use newcss::complete::CompleteStyle;
use style::ComputedValues;
use script::dom::node::{AbstractNode, LayoutView};
use servo_util::tree::TreeNodeRef;


/// Node mixin providing `style` method that returns a `NodeStyle`
pub trait StyledNode {
fn style(&self) -> CompleteStyle;
fn style(&self) -> &ComputedValues;
fn restyle_damage(&self) -> RestyleDamage;
}

impl StyledNode for AbstractNode<LayoutView> {
fn style(&self) -> CompleteStyle {
fn style(&self) -> &ComputedValues {
assert!(self.is_element()); // Only elements can have styles
let results = self.get_css_select_results();
results.computed_style()
results
}

fn restyle_damage(&self) -> RestyleDamage {
Expand Down

5 comments on commit b243191

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at sanxiyn@b243191

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging sanxiyn/servo/new-style = b243191 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanxiyn/servo/new-style = b243191 merged ok, testing candidate = 9b25df1

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9b25df1

Please sign in to comment.