From baad6e3963c72024e05ad649047572945018d209 Mon Sep 17 00:00:00 2001 From: patrick kim Date: Wed, 22 Jan 2014 16:29:23 +0900 Subject: [PATCH] add RareFlowFlags --- src/components/main/layout/box_.rs | 6 +- src/components/main/layout/flow.rs | 117 ++++++++++++++++++++++++++--- 2 files changed, 111 insertions(+), 12 deletions(-) diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index c0cff13159e..95e6d2e6b5c 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -778,9 +778,9 @@ impl Box { text_run: text_box.run.clone(), range: text_box.range, text_color: text_color, - overline_color: flow_flags.overline_color, - underline_color: flow_flags.underline_color, - line_through_color: flow_flags.line_through_color, + overline_color: flow_flags.overline_color(text_color), + underline_color: flow_flags.underline_color(text_color), + line_through_color: flow_flags.line_through_color(text_color), flags: text_flags, }; diff --git a/src/components/main/layout/flow.rs b/src/components/main/layout/flow.rs index dca5777e49f..ed5961601aa 100644 --- a/src/components/main/layout/flow.rs +++ b/src/components/main/layout/flow.rs @@ -263,6 +263,11 @@ pub struct FlowFlagsInfo{ flags: FlowFlags, /// text-decoration colors + rare_flow_flags: Option, +} + +#[deriving(Clone)] +pub struct RareFlowFlags { underline_color: Color, overline_color: Color, line_through_color: Color, @@ -296,27 +301,116 @@ impl FlowFlagsInfo { flags.set_override_line_through(text_decoration.line_through); // TODO(ksh8281) compute text-decoration-color,style,line - let underline_color = style.Color.color.to_gfx_color(); - let overline_color = style.Color.color.to_gfx_color(); - let line_through_color = style.Color.color.to_gfx_color(); + let rare_flow_flags = if flags.is_text_decoration_enable() { + Some(RareFlowFlags { + underline_color: style.Color.color.to_gfx_color(), + overline_color: style.Color.color.to_gfx_color(), + line_through_color: style.Color.color.to_gfx_color(), + }) + } else { + None + }; + FlowFlagsInfo { flags: flags, - underline_color: underline_color, - overline_color: overline_color, - line_through_color: line_through_color, + rare_flow_flags: rare_flow_flags, + } + } + + pub fn underline_color(&self, default_color: Color) -> Color { + match self.rare_flow_flags { + Some(ref data) => { + data.underline_color + }, + None => { + default_color + } + } + } + + pub fn overline_color(&self, default_color: Color) -> Color { + match self.rare_flow_flags { + Some(ref data) => { + data.overline_color + }, + None => { + default_color + } + } + } + + pub fn line_through_color(&self, default_color: Color) -> Color { + match self.rare_flow_flags { + Some(ref data) => { + data.line_through_color + }, + None => { + default_color + } } } /// Propagates text decoration flags from an appropriate parent flow per CSS 2.1 ยง 16.3.1. pub fn propagate_text_decoration_from_parent(&mut self, parent: FlowFlagsInfo) { + if !parent.flags.is_text_decoration_enable() { + return ; + } + + if !self.flags.is_text_decoration_enable() && parent.flags.is_text_decoration_enable() { + self.rare_flow_flags = parent.rare_flow_flags.clone(); + return ; + } + if !self.flags.override_underline() && parent.flags.override_underline() { - self.underline_color = parent.underline_color; + match parent.rare_flow_flags { + Some(ref parent_data) => { + match self.rare_flow_flags { + Some(ref mut data) => { + data.underline_color = parent_data.underline_color; + }, + None => { + fail!("if flow has text-decoration, it must have rare_flow_flags"); + } + } + }, + None => { + fail!("if flow has text-decoration, it must have rare_flow_flags"); + } + } } if !self.flags.override_overline() && parent.flags.override_overline() { - self.overline_color = parent.overline_color; + match parent.rare_flow_flags { + Some(ref parent_data) => { + match self.rare_flow_flags { + Some(ref mut data) => { + data.overline_color = parent_data.overline_color; + }, + None => { + fail!("if flow has text-decoration, it must have rare_flow_flags"); + } + } + }, + None => { + fail!("if flow has text-decoration, it must have rare_flow_flags"); + } + } } if !self.flags.override_line_through() && parent.flags.override_line_through() { - self.line_through_color = parent.line_through_color; + match parent.rare_flow_flags { + Some(ref parent_data) => { + match self.rare_flow_flags { + Some(ref mut data) => { + data.line_through_color = parent_data.line_through_color; + }, + None => { + fail!("if flow has text-decoration, it must have rare_flow_flags"); + } + } + }, + None => { + fail!("if flow has text-decoration, it must have rare_flow_flags"); + } + } } self.flags.set_text_decoration_override(parent.flags); } @@ -366,6 +460,11 @@ impl FlowFlags { pub fn set_text_decoration_override(&mut self, parent: FlowFlags) { *self = FlowFlags(**self | (*parent & TEXT_DECORATION_OVERRIDE_BITMASK)); } + + #[inline] + pub fn is_text_decoration_enable(&self) -> bool { + (**self & TEXT_DECORATION_OVERRIDE_BITMASK) != 0 + } } /// Data common to all flows.