gfx: Remove glob imports added in #4405

This commit is contained in:
Tetsuharu OHZEKI 2014-12-18 13:08:53 +09:00
parent d7f38a8973
commit a590012322
6 changed files with 113 additions and 125 deletions

View file

@ -357,7 +357,7 @@ impl StackingContext {
continue continue
} }
match *item { match *item {
BorderDisplayItemClass(ref border) => { DisplayItem::BorderClass(ref border) => {
// If the point is inside the border, it didn't hit the border! // If the point is inside the border, it didn't hit the border!
let interior_rect = let interior_rect =
Rect(Point2D(border.base.bounds.origin.x + border.border_widths.left, Rect(Point2D(border.base.bounds.origin.x + border.border_widths.left,
@ -459,13 +459,13 @@ pub fn find_stacking_context_with_layer_id(this: &Arc<StackingContext>, layer_id
/// One drawing command in the list. /// One drawing command in the list.
#[deriving(Clone)] #[deriving(Clone)]
pub enum DisplayItem { pub enum DisplayItem {
SolidColorDisplayItemClass(Box<SolidColorDisplayItem>), SolidColorClass(Box<SolidColorDisplayItem>),
TextDisplayItemClass(Box<TextDisplayItem>), TextClass(Box<TextDisplayItem>),
ImageDisplayItemClass(Box<ImageDisplayItem>), ImageClass(Box<ImageDisplayItem>),
BorderDisplayItemClass(Box<BorderDisplayItem>), BorderClass(Box<BorderDisplayItem>),
GradientDisplayItemClass(Box<GradientDisplayItem>), GradientClass(Box<GradientDisplayItem>),
LineDisplayItemClass(Box<LineDisplayItem>), LineClass(Box<LineDisplayItem>),
BoxShadowDisplayItemClass(Box<BoxShadowDisplayItem>), BoxShadowClass(Box<BoxShadowDisplayItem>),
} }
/// Information common to all display items. /// Information common to all display items.
@ -656,16 +656,16 @@ pub struct BoxShadowDisplayItem {
} }
pub enum DisplayItemIterator<'a> { pub enum DisplayItemIterator<'a> {
EmptyDisplayItemIterator, Empty,
ParentDisplayItemIterator(dlist::Items<'a,DisplayItem>), Parent(dlist::Items<'a,DisplayItem>),
} }
impl<'a> Iterator<&'a DisplayItem> for DisplayItemIterator<'a> { impl<'a> Iterator<&'a DisplayItem> for DisplayItemIterator<'a> {
#[inline] #[inline]
fn next(&mut self) -> Option<&'a DisplayItem> { fn next(&mut self) -> Option<&'a DisplayItem> {
match *self { match *self {
EmptyDisplayItemIterator => None, DisplayItemIterator::Empty => None,
ParentDisplayItemIterator(ref mut subiterator) => subiterator.next(), DisplayItemIterator::Parent(ref mut subiterator) => subiterator.next(),
} }
} }
} }
@ -683,16 +683,16 @@ impl DisplayItem {
} }
match *self { match *self {
SolidColorDisplayItemClass(ref solid_color) => { DisplayItem::SolidColorClass(ref solid_color) => {
paint_context.draw_solid_color(&solid_color.base.bounds, solid_color.color) paint_context.draw_solid_color(&solid_color.base.bounds, solid_color.color)
} }
TextDisplayItemClass(ref text) => { DisplayItem::TextClass(ref text) => {
debug!("Drawing text at {}.", text.base.bounds); debug!("Drawing text at {}.", text.base.bounds);
paint_context.draw_text(&**text); paint_context.draw_text(&**text);
} }
ImageDisplayItemClass(ref image_item) => { DisplayItem::ImageClass(ref image_item) => {
debug!("Drawing image at {}.", image_item.base.bounds); debug!("Drawing image at {}.", image_item.base.bounds);
let mut y_offset = Au(0); let mut y_offset = Au(0);
@ -713,7 +713,7 @@ impl DisplayItem {
} }
} }
BorderDisplayItemClass(ref border) => { DisplayItem::BorderClass(ref border) => {
paint_context.draw_border(&border.base.bounds, paint_context.draw_border(&border.base.bounds,
border.border_widths, border.border_widths,
&border.radius, &border.radius,
@ -721,20 +721,20 @@ impl DisplayItem {
border.style) border.style)
} }
GradientDisplayItemClass(ref gradient) => { DisplayItem::GradientClass(ref gradient) => {
paint_context.draw_linear_gradient(&gradient.base.bounds, paint_context.draw_linear_gradient(&gradient.base.bounds,
&gradient.start_point, &gradient.start_point,
&gradient.end_point, &gradient.end_point,
gradient.stops.as_slice()); gradient.stops.as_slice());
} }
LineDisplayItemClass(ref line) => { DisplayItem::LineClass(ref line) => {
paint_context.draw_line(&line.base.bounds, paint_context.draw_line(&line.base.bounds,
line.color, line.color,
line.style) line.style)
} }
BoxShadowDisplayItemClass(ref box_shadow) => { DisplayItem::BoxShadowClass(ref box_shadow) => {
paint_context.draw_box_shadow(&box_shadow.box_bounds, paint_context.draw_box_shadow(&box_shadow.box_bounds,
&box_shadow.offset, &box_shadow.offset,
box_shadow.color, box_shadow.color,
@ -747,25 +747,25 @@ impl DisplayItem {
pub fn base<'a>(&'a self) -> &'a BaseDisplayItem { pub fn base<'a>(&'a self) -> &'a BaseDisplayItem {
match *self { match *self {
SolidColorDisplayItemClass(ref solid_color) => &solid_color.base, DisplayItem::SolidColorClass(ref solid_color) => &solid_color.base,
TextDisplayItemClass(ref text) => &text.base, DisplayItem::TextClass(ref text) => &text.base,
ImageDisplayItemClass(ref image_item) => &image_item.base, DisplayItem::ImageClass(ref image_item) => &image_item.base,
BorderDisplayItemClass(ref border) => &border.base, DisplayItem::BorderClass(ref border) => &border.base,
GradientDisplayItemClass(ref gradient) => &gradient.base, DisplayItem::GradientClass(ref gradient) => &gradient.base,
LineDisplayItemClass(ref line) => &line.base, DisplayItem::LineClass(ref line) => &line.base,
BoxShadowDisplayItemClass(ref box_shadow) => &box_shadow.base, DisplayItem::BoxShadowClass(ref box_shadow) => &box_shadow.base,
} }
} }
pub fn mut_base<'a>(&'a mut self) -> &'a mut BaseDisplayItem { pub fn mut_base<'a>(&'a mut self) -> &'a mut BaseDisplayItem {
match *self { match *self {
SolidColorDisplayItemClass(ref mut solid_color) => &mut solid_color.base, DisplayItem::SolidColorClass(ref mut solid_color) => &mut solid_color.base,
TextDisplayItemClass(ref mut text) => &mut text.base, DisplayItem::TextClass(ref mut text) => &mut text.base,
ImageDisplayItemClass(ref mut image_item) => &mut image_item.base, DisplayItem::ImageClass(ref mut image_item) => &mut image_item.base,
BorderDisplayItemClass(ref mut border) => &mut border.base, DisplayItem::BorderClass(ref mut border) => &mut border.base,
GradientDisplayItemClass(ref mut gradient) => &mut gradient.base, DisplayItem::GradientClass(ref mut gradient) => &mut gradient.base,
LineDisplayItemClass(ref mut line) => &mut line.base, DisplayItem::LineClass(ref mut line) => &mut line.base,
BoxShadowDisplayItemClass(ref mut box_shadow) => &mut box_shadow.base, DisplayItem::BoxShadowClass(ref mut box_shadow) => &mut box_shadow.base,
} }
} }
@ -786,13 +786,13 @@ impl fmt::Show for DisplayItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} @ {} ({:x})", write!(f, "{} @ {} ({:x})",
match *self { match *self {
SolidColorDisplayItemClass(_) => "SolidColor", DisplayItem::SolidColorClass(_) => "SolidColor",
TextDisplayItemClass(_) => "Text", DisplayItem::TextClass(_) => "Text",
ImageDisplayItemClass(_) => "Image", DisplayItem::ImageClass(_) => "Image",
BorderDisplayItemClass(_) => "Border", DisplayItem::BorderClass(_) => "Border",
GradientDisplayItemClass(_) => "Gradient", DisplayItem::GradientClass(_) => "Gradient",
LineDisplayItemClass(_) => "Line", DisplayItem::LineClass(_) => "Line",
BoxShadowDisplayItemClass(_) => "BoxShadow", DisplayItem::BoxShadowClass(_) => "BoxShadow",
}, },
self.base().bounds, self.base().bounds,
self.base().metadata.node.id() self.base().metadata.node.id()

View file

@ -2,9 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use self::Command::*;
use self::Reply::*;
use platform::font_list::get_available_families; use platform::font_list::get_available_families;
use platform::font_list::get_system_default_family; use platform::font_list::get_system_default_family;
use platform::font_list::get_variations_for_family; use platform::font_list::get_variations_for_family;
@ -114,16 +111,16 @@ impl FontCache {
let msg = self.port.recv(); let msg = self.port.recv();
match msg { match msg {
GetFontTemplate(family, descriptor, result) => { Command::GetFontTemplate(family, descriptor, result) => {
let family = LowercaseString::new(family.as_slice()); let family = LowercaseString::new(family.as_slice());
let maybe_font_template = self.get_font_template(&family, &descriptor); let maybe_font_template = self.get_font_template(&family, &descriptor);
result.send(GetFontTemplateReply(maybe_font_template)); result.send(Reply::GetFontTemplateReply(maybe_font_template));
} }
GetLastResortFontTemplate(descriptor, result) => { Command::GetLastResortFontTemplate(descriptor, result) => {
let font_template = self.get_last_resort_font_template(&descriptor); let font_template = self.get_last_resort_font_template(&descriptor);
result.send(GetFontTemplateReply(Some(font_template))); result.send(Reply::GetFontTemplateReply(Some(font_template)));
} }
AddWebFont(family_name, src, result) => { Command::AddWebFont(family_name, src, result) => {
let family_name = LowercaseString::new(family_name.as_slice()); let family_name = LowercaseString::new(family_name.as_slice());
if !self.web_families.contains_key(&family_name) { if !self.web_families.contains_key(&family_name) {
let family = FontFamily::new(); let family = FontFamily::new();
@ -153,7 +150,7 @@ impl FontCache {
} }
result.send(()); result.send(());
} }
Exit(result) => { Command::Exit(result) => {
result.send(()); result.send(());
break; break;
} }
@ -286,12 +283,12 @@ impl FontCacheTask {
-> Option<Arc<FontTemplateData>> { -> Option<Arc<FontTemplateData>> {
let (response_chan, response_port) = channel(); let (response_chan, response_port) = channel();
self.chan.send(GetFontTemplate(family, desc, response_chan)); self.chan.send(Command::GetFontTemplate(family, desc, response_chan));
let reply = response_port.recv(); let reply = response_port.recv();
match reply { match reply {
GetFontTemplateReply(data) => { Reply::GetFontTemplateReply(data) => {
data data
} }
} }
@ -301,12 +298,12 @@ impl FontCacheTask {
-> Arc<FontTemplateData> { -> Arc<FontTemplateData> {
let (response_chan, response_port) = channel(); let (response_chan, response_port) = channel();
self.chan.send(GetLastResortFontTemplate(desc, response_chan)); self.chan.send(Command::GetLastResortFontTemplate(desc, response_chan));
let reply = response_port.recv(); let reply = response_port.recv();
match reply { match reply {
GetFontTemplateReply(data) => { Reply::GetFontTemplateReply(data) => {
data.unwrap() data.unwrap()
} }
} }
@ -314,13 +311,13 @@ impl FontCacheTask {
pub fn add_web_font(&self, family: String, src: Source) { pub fn add_web_font(&self, family: String, src: Source) {
let (response_chan, response_port) = channel(); let (response_chan, response_port) = channel();
self.chan.send(AddWebFont(family, src, response_chan)); self.chan.send(Command::AddWebFont(family, src, response_chan));
response_port.recv(); response_port.recv();
} }
pub fn exit(&self) { pub fn exit(&self) {
let (response_chan, response_port) = channel(); let (response_chan, response_port) = channel();
self.chan.send(Exit(response_chan)); self.chan.send(Command::Exit(response_chan));
response_port.recv(); response_port.recv();
} }
} }

View file

@ -4,10 +4,6 @@
//! The task that handles all painting. //! The task that handles all painting.
use self::Msg::*;
use self::MsgFromWorkerThread::*;
use self::MsgToWorkerThread::*;
use buffer_map::BufferMap; use buffer_map::BufferMap;
use display_list::{mod, StackingContext}; use display_list::{mod, StackingContext};
use font_cache_task::FontCacheTask; use font_cache_task::FontCacheTask;
@ -231,7 +227,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send {
loop { loop {
match self.port.recv() { match self.port.recv() {
PaintInitMsg(stacking_context) => { Msg::PaintInitMsg(stacking_context) => {
self.epoch.next(); self.epoch.next();
self.root_stacking_context = Some(stacking_context.clone()); self.root_stacking_context = Some(stacking_context.clone());
@ -247,7 +243,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send {
self.epoch, self.epoch,
&*stacking_context); &*stacking_context);
} }
PaintMsg(requests) => { Msg::PaintMsg(requests) => {
if !self.paint_permission { if !self.paint_permission {
debug!("paint_task: paint ready msg"); debug!("paint_task: paint ready msg");
let ConstellationChan(ref mut c) = self.constellation_chan; let ConstellationChan(ref mut c) = self.constellation_chan;
@ -272,12 +268,12 @@ impl<C> PaintTask<C> where C: PaintListener + Send {
debug!("paint_task: returning surfaces"); debug!("paint_task: returning surfaces");
self.compositor.paint(self.id, self.epoch, replies); self.compositor.paint(self.id, self.epoch, replies);
} }
UnusedBufferMsg(unused_buffers) => { Msg::UnusedBufferMsg(unused_buffers) => {
for buffer in unused_buffers.into_iter().rev() { for buffer in unused_buffers.into_iter().rev() {
self.buffer_map.insert(native_graphics_context!(self), buffer); self.buffer_map.insert(native_graphics_context!(self), buffer);
} }
} }
PaintPermissionGranted => { Msg::PaintPermissionGranted => {
self.paint_permission = true; self.paint_permission = true;
match self.root_stacking_context { match self.root_stacking_context {
@ -291,10 +287,10 @@ impl<C> PaintTask<C> where C: PaintListener + Send {
} }
} }
} }
PaintPermissionRevoked => { Msg::PaintPermissionRevoked => {
self.paint_permission = false; self.paint_permission = false;
} }
ExitMsg(response_ch) => { Msg::ExitMsg(response_ch) => {
debug!("paint_task: exitmsg response send"); debug!("paint_task: exitmsg response send");
response_ch.map(|ch| ch.send(())); response_ch.map(|ch| ch.send(()));
break; break;
@ -431,17 +427,17 @@ impl WorkerThreadProxy {
layer_buffer: Option<Box<LayerBuffer>>, layer_buffer: Option<Box<LayerBuffer>>,
stacking_context: Arc<StackingContext>, stacking_context: Arc<StackingContext>,
scale: f32) { scale: f32) {
self.sender.send(PaintTileMsgToWorkerThread(tile, layer_buffer, stacking_context, scale)) self.sender.send(MsgToWorkerThread::PaintTile(tile, layer_buffer, stacking_context, scale))
} }
fn get_painted_tile_buffer(&mut self) -> Box<LayerBuffer> { fn get_painted_tile_buffer(&mut self) -> Box<LayerBuffer> {
match self.receiver.recv() { match self.receiver.recv() {
PaintedTileMsgFromWorkerThread(layer_buffer) => layer_buffer, MsgFromWorkerThread::PaintedTile(layer_buffer) => layer_buffer,
} }
} }
fn exit(&mut self) { fn exit(&mut self) {
self.sender.send(ExitMsgToWorkerThread) self.sender.send(MsgToWorkerThread::Exit)
} }
} }
@ -474,14 +470,14 @@ impl WorkerThread {
fn main(&mut self) { fn main(&mut self) {
loop { loop {
match self.receiver.recv() { match self.receiver.recv() {
ExitMsgToWorkerThread => break, MsgToWorkerThread::Exit => break,
PaintTileMsgToWorkerThread(tile, layer_buffer, stacking_context, scale) => { MsgToWorkerThread::PaintTile(tile, layer_buffer, stacking_context, scale) => {
let draw_target = self.optimize_and_paint_tile(&tile, stacking_context, scale); let draw_target = self.optimize_and_paint_tile(&tile, stacking_context, scale);
let buffer = self.create_layer_buffer_for_painted_tile(&tile, let buffer = self.create_layer_buffer_for_painted_tile(&tile,
layer_buffer, layer_buffer,
draw_target, draw_target,
scale); scale);
self.sender.send(PaintedTileMsgFromWorkerThread(buffer)) self.sender.send(MsgFromWorkerThread::PaintedTile(buffer))
} }
} }
} }
@ -586,10 +582,10 @@ impl WorkerThread {
} }
enum MsgToWorkerThread { enum MsgToWorkerThread {
ExitMsgToWorkerThread, Exit,
PaintTileMsgToWorkerThread(BufferRequest, Option<Box<LayerBuffer>>, Arc<StackingContext>, f32), PaintTile(BufferRequest, Option<Box<LayerBuffer>>, Arc<StackingContext>, f32),
} }
enum MsgFromWorkerThread { enum MsgFromWorkerThread {
PaintedTileMsgFromWorkerThread(Box<LayerBuffer>), PaintedTile(Box<LayerBuffer>),
} }

View file

@ -2,9 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use self::BreakType::*;
use self::GlyphInfo::*;
use servo_util::vec::*; use servo_util::vec::*;
use servo_util::range; use servo_util::range;
use servo_util::range::{Range, RangeIndex, EachIndex}; use servo_util::range::{Range, RangeIndex, EachIndex};
@ -92,9 +89,9 @@ pub type GlyphId = u32;
// TODO: unify with bit flags? // TODO: unify with bit flags?
#[deriving(PartialEq)] #[deriving(PartialEq)]
pub enum BreakType { pub enum BreakType {
BreakTypeNone, None,
BreakTypeNormal, Normal,
BreakTypeHyphen, Hyphen,
} }
static BREAK_TYPE_NONE: u8 = 0x0; static BREAK_TYPE_NONE: u8 = 0x0;
@ -103,19 +100,19 @@ static BREAK_TYPE_HYPHEN: u8 = 0x2;
fn break_flag_to_enum(flag: u8) -> BreakType { fn break_flag_to_enum(flag: u8) -> BreakType {
if (flag & BREAK_TYPE_NORMAL) != 0 { if (flag & BREAK_TYPE_NORMAL) != 0 {
BreakTypeNormal BreakType::Normal
} else if (flag & BREAK_TYPE_HYPHEN) != 0 { } else if (flag & BREAK_TYPE_HYPHEN) != 0 {
BreakTypeHyphen BreakType::Hyphen
} else { } else {
BreakTypeNone BreakType::None
} }
} }
fn break_enum_to_flag(e: BreakType) -> u8 { fn break_enum_to_flag(e: BreakType) -> u8 {
match e { match e {
BreakTypeNone => BREAK_TYPE_NONE, BreakType::None => BREAK_TYPE_NONE,
BreakTypeNormal => BREAK_TYPE_NORMAL, BreakType::Normal => BREAK_TYPE_NORMAL,
BreakTypeHyphen => BREAK_TYPE_HYPHEN, BreakType::Hyphen => BREAK_TYPE_HYPHEN,
} }
} }
@ -447,15 +444,15 @@ impl GlyphData {
// Rather than eagerly assembling and copying glyph data, it only retrieves // Rather than eagerly assembling and copying glyph data, it only retrieves
// values as they are needed from the GlyphStore, using provided offsets. // values as they are needed from the GlyphStore, using provided offsets.
pub enum GlyphInfo<'a> { pub enum GlyphInfo<'a> {
SimpleGlyphInfo(&'a GlyphStore, CharIndex), Simple(&'a GlyphStore, CharIndex),
DetailGlyphInfo(&'a GlyphStore, CharIndex, u16), Detail(&'a GlyphStore, CharIndex, u16),
} }
impl<'a> GlyphInfo<'a> { impl<'a> GlyphInfo<'a> {
pub fn id(self) -> GlyphId { pub fn id(self) -> GlyphId {
match self { match self {
SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i.to_uint()].id(), GlyphInfo::Simple(store, entry_i) => store.entry_buffer[entry_i.to_uint()].id(),
DetailGlyphInfo(store, entry_i, detail_j) => { GlyphInfo::Detail(store, entry_i, detail_j) => {
store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).id store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).id
} }
} }
@ -465,8 +462,8 @@ impl<'a> GlyphInfo<'a> {
// FIXME: Resolution conflicts with IteratorUtil trait so adding trailing _ // FIXME: Resolution conflicts with IteratorUtil trait so adding trailing _
pub fn advance(self) -> Au { pub fn advance(self) -> Au {
match self { match self {
SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i.to_uint()].advance(), GlyphInfo::Simple(store, entry_i) => store.entry_buffer[entry_i.to_uint()].advance(),
DetailGlyphInfo(store, entry_i, detail_j) => { GlyphInfo::Detail(store, entry_i, detail_j) => {
store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).advance store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).advance
} }
} }
@ -474,8 +471,8 @@ impl<'a> GlyphInfo<'a> {
pub fn offset(self) -> Option<Point2D<Au>> { pub fn offset(self) -> Option<Point2D<Au>> {
match self { match self {
SimpleGlyphInfo(_, _) => None, GlyphInfo::Simple(_, _) => None,
DetailGlyphInfo(store, entry_i, detail_j) => { GlyphInfo::Detail(store, entry_i, detail_j) => {
Some(store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).offset) Some(store.detail_store.get_detailed_glyph_with_index(entry_i, detail_j).offset)
} }
} }
@ -705,7 +702,7 @@ impl<'a> GlyphIterator<'a> {
fn next_glyph_range(&mut self) -> Option<(CharIndex, GlyphInfo<'a>)> { fn next_glyph_range(&mut self) -> Option<(CharIndex, GlyphInfo<'a>)> {
match self.glyph_range.as_mut().unwrap().next() { match self.glyph_range.as_mut().unwrap().next() {
Some(j) => Some((self.char_index, Some(j) => Some((self.char_index,
DetailGlyphInfo(self.store, self.char_index, j.get() as u16 /* ??? */))), GlyphInfo::Detail(self.store, self.char_index, j.get() as u16 /* ??? */))),
None => { None => {
// No more glyphs for current character. Try to get another. // No more glyphs for current character. Try to get another.
self.glyph_range = None; self.glyph_range = None;
@ -744,7 +741,7 @@ impl<'a> Iterator<(CharIndex, GlyphInfo<'a>)> for GlyphIterator<'a> {
assert!(i < self.store.char_len()); assert!(i < self.store.char_len());
let entry = self.store.entry_buffer[i.to_uint()]; let entry = self.store.entry_buffer[i.to_uint()];
if entry.is_simple() { if entry.is_simple() {
Some((self.char_index, SimpleGlyphInfo(self.store, i))) Some((self.char_index, GlyphInfo::Simple(self.store, i)))
} else { } else {
// Fall back to the slow path. // Fall back to the slow path.
self.next_complex_glyph(&entry, i) self.next_complex_glyph(&entry, i)

View file

@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use self::CompressionMode::*;
use text::glyph::CharIndex; use text::glyph::CharIndex;
#[deriving(PartialEq)] #[deriving(PartialEq)]
@ -31,7 +29,7 @@ pub fn transform_text(text: &str,
new_line_pos: &mut Vec<CharIndex>) new_line_pos: &mut Vec<CharIndex>)
-> bool { -> bool {
let out_whitespace = match mode { let out_whitespace = match mode {
CompressNone | DiscardNewline => { CompressionMode::CompressNone | CompressionMode::DiscardNewline => {
let mut new_line_index = CharIndex(0); let mut new_line_index = CharIndex(0);
for ch in text.chars() { for ch in text.chars() {
if is_discardable_char(ch, mode) { if is_discardable_char(ch, mode) {
@ -56,7 +54,7 @@ pub fn transform_text(text: &str,
text.len() > 0 && is_in_whitespace(text.char_at_reverse(0), mode) text.len() > 0 && is_in_whitespace(text.char_at_reverse(0), mode)
}, },
CompressWhitespace | CompressWhitespaceNewline => { CompressionMode::CompressWhitespace | CompressionMode::CompressWhitespaceNewline => {
let mut in_whitespace: bool = incoming_whitespace; let mut in_whitespace: bool = incoming_whitespace;
for ch in text.chars() { for ch in text.chars() {
// TODO: discard newlines between CJK chars // TODO: discard newlines between CJK chars
@ -92,7 +90,7 @@ pub fn transform_text(text: &str,
match (ch, mode) { match (ch, mode) {
(' ', _) => true, (' ', _) => true,
('\t', _) => true, ('\t', _) => true,
('\n', CompressWhitespaceNewline) => true, ('\n', CompressionMode::CompressWhitespaceNewline) => true,
(_, _) => false (_, _) => false
} }
} }
@ -102,7 +100,7 @@ pub fn transform_text(text: &str,
return true; return true;
} }
match mode { match mode {
DiscardNewline | CompressWhitespaceNewline => ch == '\n', CompressionMode::DiscardNewline | CompressionMode::CompressWhitespaceNewline => ch == '\n',
_ => false _ => false
} }
} }
@ -155,7 +153,7 @@ fn test_transform_compress_none() {
"foo bar baz", "foo bar baz",
"foobarbaz\n\n" "foobarbaz\n\n"
); );
let mode = CompressNone; let mode = CompressionMode::CompressNone;
for test in test_strs.iter() { for test in test_strs.iter() {
let mut new_line_pos = vec!(); let mut new_line_pos = vec!();
@ -188,7 +186,7 @@ fn test_transform_discard_newline() {
); );
assert_eq!(test_strs.len(), oracle_strs.len()); assert_eq!(test_strs.len(), oracle_strs.len());
let mode = DiscardNewline; let mode = CompressionMode::DiscardNewline;
for (test, oracle) in test_strs.iter().zip(oracle_strs.iter()) { for (test, oracle) in test_strs.iter().zip(oracle_strs.iter()) {
let mut new_line_pos = vec!(); let mut new_line_pos = vec!();
@ -246,7 +244,7 @@ fn test_transform_compress_whitespace_newline() {
"foobarbaz ".to_string()]; "foobarbaz ".to_string()];
assert_eq!(test_strs.len(), oracle_strs.len()); assert_eq!(test_strs.len(), oracle_strs.len());
let mode = CompressWhitespaceNewline; let mode = CompressionMode::CompressWhitespaceNewline;
for i in range(0, test_strs.len()) { for i in range(0, test_strs.len()) {
let mut new_line_pos = ~[]; let mut new_line_pos = ~[];
@ -281,7 +279,7 @@ fn test_transform_compress_whitespace_newline_no_incoming() {
); );
assert_eq!(test_strs.len(), oracle_strs.len()); assert_eq!(test_strs.len(), oracle_strs.len());
let mode = CompressWhitespaceNewline; let mode = CompressionMode::CompressWhitespaceNewline;
for (test, oracle) in test_strs.iter().zip(oracle_strs.iter()) { for (test, oracle) in test_strs.iter().zip(oracle_strs.iter()) {
let mut new_line_pos = vec!(); let mut new_line_pos = vec!();

View file

@ -23,13 +23,13 @@ use geom::approxeq::ApproxEq;
use geom::{Point2D, Rect, Size2D, SideOffsets2D}; use geom::{Point2D, Rect, Size2D, SideOffsets2D};
use gfx::color; use gfx::color;
use gfx::display_list::{BOX_SHADOW_INFLATION_FACTOR, BaseDisplayItem, BorderDisplayItem}; use gfx::display_list::{BOX_SHADOW_INFLATION_FACTOR, BaseDisplayItem, BorderDisplayItem};
use gfx::display_list::{BorderDisplayItemClass, BorderRadii, BoxShadowDisplayItem}; use gfx::display_list::{BorderRadii, BoxShadowDisplayItem};
use gfx::display_list::{BoxShadowDisplayItemClass, DisplayItem, DisplayItemMetadata, DisplayList}; use gfx::display_list::{DisplayItem, DisplayList, DisplayItemMetadata};
use gfx::display_list::{GradientDisplayItem, GradientDisplayItemClass}; use gfx::display_list::{GradientDisplayItem};
use gfx::display_list::{GradientStop, ImageDisplayItem, ImageDisplayItemClass, LineDisplayItem}; use gfx::display_list::{GradientStop, ImageDisplayItem, LineDisplayItem};
use gfx::display_list::{LineDisplayItemClass, SidewaysLeft}; use gfx::display_list::{SidewaysLeft};
use gfx::display_list::{SidewaysRight, SolidColorDisplayItem, SolidColorDisplayItemClass}; use gfx::display_list::{SidewaysRight, SolidColorDisplayItem};
use gfx::display_list::{StackingContext, TextDisplayItem, TextDisplayItemClass, Upright}; use gfx::display_list::{StackingContext, TextDisplayItem, Upright};
use gfx::paint_task::PaintLayer; use gfx::paint_task::PaintLayer;
use servo_msg::compositor_msg::{FixedPosition, Scrollable}; use servo_msg::compositor_msg::{FixedPosition, Scrollable};
use servo_msg::constellation_msg::{ConstellationChan, FrameRectMsg}; use servo_msg::constellation_msg::{ConstellationChan, FrameRectMsg};
@ -198,7 +198,7 @@ impl FragmentDisplayListBuilding for Fragment {
// doesn't have a fragment". // doesn't have a fragment".
let background_color = style.resolve_color(style.get_background().background_color); let background_color = style.resolve_color(style.get_background().background_color);
if !background_color.alpha.approx_eq(&0.0) { if !background_color.alpha.approx_eq(&0.0) {
display_list.push(SolidColorDisplayItemClass(box SolidColorDisplayItem { display_list.push(DisplayItem::SolidColorClass(box SolidColorDisplayItem {
base: BaseDisplayItem::new(*absolute_bounds, base: BaseDisplayItem::new(*absolute_bounds,
DisplayItemMetadata::new(self.node, DisplayItemMetadata::new(self.node,
style, style,
@ -314,7 +314,7 @@ impl FragmentDisplayListBuilding for Fragment {
}; };
// Create the image display item. // Create the image display item.
display_list.push(ImageDisplayItemClass(box ImageDisplayItem { display_list.push(DisplayItem::ImageClass(box ImageDisplayItem {
base: BaseDisplayItem::new(bounds, base: BaseDisplayItem::new(bounds,
DisplayItemMetadata::new(self.node, style, DefaultCursor), DisplayItemMetadata::new(self.node, style, DefaultCursor),
clip_rect), clip_rect),
@ -424,7 +424,7 @@ impl FragmentDisplayListBuilding for Fragment {
let center = Point2D(absolute_bounds.origin.x + absolute_bounds.size.width / 2, let center = Point2D(absolute_bounds.origin.x + absolute_bounds.size.width / 2,
absolute_bounds.origin.y + absolute_bounds.size.height / 2); absolute_bounds.origin.y + absolute_bounds.size.height / 2);
let gradient_display_item = GradientDisplayItemClass(box GradientDisplayItem { let gradient_display_item = DisplayItem::GradientClass(box GradientDisplayItem {
base: BaseDisplayItem::new(*absolute_bounds, base: BaseDisplayItem::new(*absolute_bounds,
DisplayItemMetadata::new(self.node, style, DefaultCursor), DisplayItemMetadata::new(self.node, style, DefaultCursor),
clip_rect), clip_rect),
@ -450,7 +450,7 @@ impl FragmentDisplayListBuilding for Fragment {
let bounds = let bounds =
absolute_bounds.translate(&Point2D(box_shadow.offset_x, box_shadow.offset_y)) absolute_bounds.translate(&Point2D(box_shadow.offset_x, box_shadow.offset_y))
.inflate(inflation, inflation); .inflate(inflation, inflation);
list.push(BoxShadowDisplayItemClass(box BoxShadowDisplayItem { list.push(DisplayItem::BoxShadowClass(box BoxShadowDisplayItem {
base: BaseDisplayItem::new(bounds, base: BaseDisplayItem::new(bounds,
DisplayItemMetadata::new(self.node, DisplayItemMetadata::new(self.node,
style, style,
@ -483,7 +483,7 @@ impl FragmentDisplayListBuilding for Fragment {
let left_color = style.resolve_color(style.get_border().border_left_color); let left_color = style.resolve_color(style.get_border().border_left_color);
// Append the border to the display list. // Append the border to the display list.
display_list.push(BorderDisplayItemClass(box BorderDisplayItem { display_list.push(DisplayItem::BorderClass(box BorderDisplayItem {
base: BaseDisplayItem::new(*abs_bounds, base: BaseDisplayItem::new(*abs_bounds,
DisplayItemMetadata::new(self.node, style, DefaultCursor), DisplayItemMetadata::new(self.node, style, DefaultCursor),
*clip_rect), *clip_rect),
@ -525,7 +525,7 @@ impl FragmentDisplayListBuilding for Fragment {
// Append the outline to the display list. // Append the outline to the display list.
let color = style.resolve_color(style.get_outline().outline_color).to_gfx_color(); let color = style.resolve_color(style.get_outline().outline_color).to_gfx_color();
display_list.outlines.push_back(BorderDisplayItemClass(box BorderDisplayItem { display_list.outlines.push_back(DisplayItem::BorderClass(box BorderDisplayItem {
base: BaseDisplayItem::new(bounds, base: BaseDisplayItem::new(bounds,
DisplayItemMetadata::new(self.node, style, DefaultCursor), DisplayItemMetadata::new(self.node, style, DefaultCursor),
*clip_rect), *clip_rect),
@ -551,7 +551,7 @@ impl FragmentDisplayListBuilding for Fragment {
fragment_bounds.size); fragment_bounds.size);
// Compute the text fragment bounds and draw a border surrounding them. // Compute the text fragment bounds and draw a border surrounding them.
display_list.content.push_back(BorderDisplayItemClass(box BorderDisplayItem { display_list.content.push_back(DisplayItem::BorderClass(box BorderDisplayItem {
base: BaseDisplayItem::new(absolute_fragment_bounds, base: BaseDisplayItem::new(absolute_fragment_bounds,
DisplayItemMetadata::new(self.node, style, DefaultCursor), DisplayItemMetadata::new(self.node, style, DefaultCursor),
*clip_rect), *clip_rect),
@ -576,7 +576,7 @@ impl FragmentDisplayListBuilding for Fragment {
color: color::rgb(0, 200, 0), color: color::rgb(0, 200, 0),
style: border_style::dashed, style: border_style::dashed,
}; };
display_list.content.push_back(LineDisplayItemClass(line_display_item)); display_list.content.push_back(DisplayItem::LineClass(line_display_item));
} }
fn build_debug_borders_around_fragment(&self, fn build_debug_borders_around_fragment(&self,
@ -592,7 +592,7 @@ impl FragmentDisplayListBuilding for Fragment {
fragment_bounds.size); fragment_bounds.size);
// This prints a debug border around the border of this fragment. // This prints a debug border around the border of this fragment.
display_list.content.push_back(BorderDisplayItemClass(box BorderDisplayItem { display_list.content.push_back(DisplayItem::BorderClass(box BorderDisplayItem {
base: BaseDisplayItem::new(absolute_fragment_bounds, base: BaseDisplayItem::new(absolute_fragment_bounds,
DisplayItemMetadata::new(self.node, DisplayItemMetadata::new(self.node,
&*self.style, &*self.style,
@ -776,7 +776,7 @@ impl FragmentDisplayListBuilding for Fragment {
+ flow_origin + flow_origin
}; };
display_list.content.push_back(TextDisplayItemClass(box TextDisplayItem { display_list.content.push_back(DisplayItem::TextClass(box TextDisplayItem {
base: BaseDisplayItem::new(absolute_content_box, base: BaseDisplayItem::new(absolute_content_box,
DisplayItemMetadata::new(self.node, DisplayItemMetadata::new(self.node,
self.style(), self.style(),
@ -798,7 +798,7 @@ impl FragmentDisplayListBuilding for Fragment {
None => {} None => {}
Some(color) => { Some(color) => {
let bounds = rect_to_absolute(self.style.writing_mode, rect()); let bounds = rect_to_absolute(self.style.writing_mode, rect());
display_list.content.push_back(SolidColorDisplayItemClass( display_list.content.push_back(DisplayItem::SolidColorClass(
box SolidColorDisplayItem { box SolidColorDisplayItem {
base: BaseDisplayItem::new( base: BaseDisplayItem::new(
bounds, bounds,
@ -859,7 +859,7 @@ impl FragmentDisplayListBuilding for Fragment {
debug!("(building display list) building image fragment"); debug!("(building display list) building image fragment");
// Place the image into the display list. // Place the image into the display list.
display_list.content.push_back(ImageDisplayItemClass(box ImageDisplayItem { display_list.content.push_back(DisplayItem::ImageClass(box ImageDisplayItem {
base: BaseDisplayItem::new(absolute_content_box, base: BaseDisplayItem::new(absolute_content_box,
DisplayItemMetadata::new(self.node, DisplayItemMetadata::new(self.node,
&*self.style, &*self.style,