зеркало из https://github.com/mozilla/gecko-dev.git
servo: Fixed syntax by changing alt to match
Source-Repo: https://github.com/servo/servo Source-Revision: 7e8d0949d092bb6c5fe162861261efae2e5fdc28
This commit is contained in:
Родитель
62e4484ad8
Коммит
9ff002d06f
|
@ -43,8 +43,6 @@ import std::net::url::url;
|
||||||
import url_to_str = std::net::url::to_str;
|
import url_to_str = std::net::url::to_str;
|
||||||
import util::url::make_url;
|
import util::url::make_url;
|
||||||
|
|
||||||
type Content = chan<ControlMsg>;
|
|
||||||
|
|
||||||
enum ControlMsg {
|
enum ControlMsg {
|
||||||
ParseMsg(url),
|
ParseMsg(url),
|
||||||
ExecuteMsg(url),
|
ExecuteMsg(url),
|
||||||
|
@ -114,14 +112,14 @@ class Content<S:Sink send copy> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_msg(msg: either<ControlMsg,Event>) -> bool {
|
fn handle_msg(msg: either<ControlMsg,Event>) -> bool {
|
||||||
alt msg {
|
match msg {
|
||||||
left(control_msg) => self.handle_control_msg(control_msg),
|
left(control_msg) => self.handle_control_msg(control_msg),
|
||||||
right(event) => self.handle_event(event)
|
right(event) => self.handle_event(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_control_msg(control_msg: ControlMsg) -> bool {
|
fn handle_control_msg(control_msg: ControlMsg) -> bool {
|
||||||
alt control_msg {
|
match control_msg {
|
||||||
ParseMsg(url) => {
|
ParseMsg(url) => {
|
||||||
#debug["content: Received url `%s` to parse", url_to_str(url)];
|
#debug["content: Received url `%s` to parse", url_to_str(url)];
|
||||||
|
|
||||||
|
@ -161,7 +159,7 @@ class Content<S:Sink send copy> {
|
||||||
ExecuteMsg(url) => {
|
ExecuteMsg(url) => {
|
||||||
#debug["content: Received url `%s` to execute", url_to_str(url)];
|
#debug["content: Received url `%s` to execute", url_to_str(url)];
|
||||||
|
|
||||||
alt read_whole_file(url.path) {
|
match read_whole_file(url.path) {
|
||||||
err(msg) => {
|
err(msg) => {
|
||||||
println(#fmt["Error opening %s: %s", url_to_str(url), msg]);
|
println(#fmt["Error opening %s: %s", url_to_str(url), msg]);
|
||||||
}
|
}
|
||||||
|
@ -202,10 +200,10 @@ class Content<S:Sink send copy> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_event(event: Event) -> bool {
|
fn handle_event(event: Event) -> bool {
|
||||||
alt event {
|
match event {
|
||||||
ResizeEvent(new_width, new_height) => {
|
ResizeEvent(new_width, new_height) => {
|
||||||
#debug("content got resize event: %d, %d", new_width, new_height);
|
#debug("content got resize event: %d, %d", new_width, new_height);
|
||||||
alt copy self.document {
|
match copy self.document {
|
||||||
none => {
|
none => {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ unsafe fn unwrap(obj: *JSObject) -> *rust_box<Node> {
|
||||||
extern fn getFirstChild(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
|
extern fn getFirstChild(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*unwrap(obj)).payload.read(|nd| {
|
(*unwrap(obj)).payload.read(|nd| {
|
||||||
alt nd.tree.first_child {
|
match nd.tree.first_child {
|
||||||
some(n) => {
|
some(n) => {
|
||||||
let obj = create(cx, n).ptr;
|
let obj = create(cx, n).ptr;
|
||||||
*rval = RUST_OBJECT_TO_JSVAL(obj);
|
*rval = RUST_OBJECT_TO_JSVAL(obj);
|
||||||
|
@ -110,7 +110,7 @@ extern fn getFirstChild(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut js
|
||||||
extern fn getNextSibling(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
|
extern fn getNextSibling(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*unwrap(obj)).payload.read(|nd| {
|
(*unwrap(obj)).payload.read(|nd| {
|
||||||
alt nd.tree.next_sibling {
|
match nd.tree.next_sibling {
|
||||||
some(n) => {
|
some(n) => {
|
||||||
let obj = create(cx, n).ptr;
|
let obj = create(cx, n).ptr;
|
||||||
*rval = RUST_OBJECT_TO_JSVAL(obj);
|
*rval = RUST_OBJECT_TO_JSVAL(obj);
|
||||||
|
@ -127,7 +127,7 @@ extern fn getNextSibling(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut j
|
||||||
extern fn getTagName(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
|
extern fn getTagName(cx: *JSContext, obj: *JSObject, _id: jsid, rval: *mut jsval) -> JSBool {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*unwrap(obj)).payload.read(|nd| {
|
(*unwrap(obj)).payload.read(|nd| {
|
||||||
alt nd.kind {
|
match nd.kind {
|
||||||
~Element(ed) => {
|
~Element(ed) => {
|
||||||
let s = str(copy ed.tag_name);
|
let s = str(copy ed.tag_name);
|
||||||
*rval = domstring_to_jsval(cx, s);
|
*rval = domstring_to_jsval(cx, s);
|
||||||
|
|
|
@ -54,7 +54,7 @@ fn jsval_to_str(cx: *JSContext, v: jsval) -> result<~str, ()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn domstring_to_jsval(cx: *JSContext, str: DOMString) -> jsval {
|
unsafe fn domstring_to_jsval(cx: *JSContext, str: DOMString) -> jsval {
|
||||||
alt str {
|
match str {
|
||||||
null_string => {
|
null_string => {
|
||||||
JSVAL_NULL
|
JSVAL_NULL
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,14 +249,14 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mutate(a: animal) {
|
fn mutate(a: animal) {
|
||||||
alt a.species {
|
match a.species {
|
||||||
chicken(c) => c.eggs_per_day += 1u,
|
chicken(c) => c.eggs_per_day += 1u,
|
||||||
bull(c) => c.horns += 1u
|
bull(c) => c.horns += 1u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_characteristic(a: animal) -> uint {
|
fn read_characteristic(a: animal) -> uint {
|
||||||
alt a.species {
|
match a.species {
|
||||||
chicken(c) => c.eggs_per_day,
|
chicken(c) => c.eggs_per_day,
|
||||||
bull(c) => c.horns
|
bull(c) => c.horns
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,9 @@ class Engine<S:Sink send copy> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_request(request: Msg) -> bool {
|
fn handle_request(request: Msg) -> bool {
|
||||||
alt request {
|
match request {
|
||||||
LoadURLMsg(url) => {
|
LoadURLMsg(url) => {
|
||||||
// TODO: change copy to move once we have alt move
|
// TODO: change copy to move once we have match move
|
||||||
let url = copy url;
|
let url = copy url;
|
||||||
if url.path.ends_with(".js") {
|
if url.path.ends_with(".js") {
|
||||||
self.content.send(ExecuteMsg(url))
|
self.content.send(ExecuteMsg(url))
|
||||||
|
|
|
@ -58,7 +58,7 @@ fn PngSink(output: chan<~[u8]>) -> PngSink {
|
||||||
assert draw_target.is_not_null();
|
assert draw_target.is_not_null();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
alt po.recv() {
|
match po.recv() {
|
||||||
BeginDrawing(sender) => {
|
BeginDrawing(sender) => {
|
||||||
#debug("pngsink: begin_drawing");
|
#debug("pngsink: begin_drawing");
|
||||||
sender.send(draw_target);
|
sender.send(draw_target);
|
||||||
|
|
|
@ -46,7 +46,7 @@ fn Renderer<S: Sink send copy>(sink: S) -> comm::chan<Msg> {
|
||||||
sink.begin_drawing(draw_target_ch);
|
sink.begin_drawing(draw_target_ch);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
alt po.recv() {
|
match po.recv() {
|
||||||
RenderMsg(display_list) => {
|
RenderMsg(display_list) => {
|
||||||
#debug("renderer: got render request");
|
#debug("renderer: got render request");
|
||||||
let draw_target = draw_target_po.recv();
|
let draw_target = draw_target_po.recv();
|
||||||
|
@ -87,7 +87,7 @@ fn draw_display_list(draw_target: AzDrawTargetRef, display_list: dl::display_lis
|
||||||
for display_list.each |item| {
|
for display_list.each |item| {
|
||||||
#debug["drawing %?", item];
|
#debug["drawing %?", item];
|
||||||
|
|
||||||
alt item.item_type {
|
match item.item_type {
|
||||||
dl::display_item_solid_color(r, g, b) => draw_solid_color(draw_target, item, r, g, b),
|
dl::display_item_solid_color(r, g, b) => draw_solid_color(draw_target, item, r, g, b),
|
||||||
dl::display_item_image(image) => draw_image(draw_target, item, *image),
|
dl::display_item_image(image) => draw_image(draw_target, item, *image),
|
||||||
dl::display_item_text(text_run) => draw_text(draw_target, item, text_run),
|
dl::display_item_text(text_run) => draw_text(draw_target, item, text_run),
|
||||||
|
@ -132,7 +132,7 @@ fn draw_image(draw_target: AzDrawTargetRef, item: dl::display_item, image: arc<~
|
||||||
let data = do vec::from_fn(image.width * image.height * 4) |i| {
|
let data = do vec::from_fn(image.width * image.height * 4) |i| {
|
||||||
let color = i % 4;
|
let color = i % 4;
|
||||||
let pixel = i / 4;
|
let pixel = i / 4;
|
||||||
alt color {
|
match color {
|
||||||
0 => image.data[pixel * 3 + 2],
|
0 => image.data[pixel * 3 + 2],
|
||||||
1 => image.data[pixel * 3 + 1],
|
1 => image.data[pixel * 3 + 1],
|
||||||
2 => image.data[pixel * 3 + 0],
|
2 => image.data[pixel * 3 + 0],
|
||||||
|
|
|
@ -14,7 +14,7 @@ type image_surface = {
|
||||||
|
|
||||||
impl format for format {
|
impl format for format {
|
||||||
fn bpp() -> uint {
|
fn bpp() -> uint {
|
||||||
alt self {
|
match self {
|
||||||
fo_rgba_8888 => 32u
|
fo_rgba_8888 => 32u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Appearance {
|
||||||
let mut image = none;
|
let mut image = none;
|
||||||
|
|
||||||
// Do a dance where we swap the ImageHolder out before we can
|
// Do a dance where we swap the ImageHolder out before we can
|
||||||
// get the image out of it because we can't alt over it
|
// get the image out of it because we can't match against it
|
||||||
// because holder.get_image() is not pure.
|
// because holder.get_image() is not pure.
|
||||||
if (self.background_image).is_some() {
|
if (self.background_image).is_some() {
|
||||||
let mut temp = none;
|
let mut temp = none;
|
||||||
|
@ -179,7 +179,7 @@ impl layout_methods_priv for @Box {
|
||||||
impl layout_methods for @Box {
|
impl layout_methods for @Box {
|
||||||
#[doc="The main reflow routine."]
|
#[doc="The main reflow routine."]
|
||||||
fn reflow(available_width: au) {
|
fn reflow(available_width: au) {
|
||||||
alt self.kind {
|
match self.kind {
|
||||||
BlockBox => self.reflow_block(available_width),
|
BlockBox => self.reflow_block(available_width),
|
||||||
InlineBox => self.reflow_inline(available_width),
|
InlineBox => self.reflow_inline(available_width),
|
||||||
IntrinsicBox(size) => self.reflow_intrinsic(*size),
|
IntrinsicBox(size) => self.reflow_intrinsic(*size),
|
||||||
|
|
|
@ -54,10 +54,10 @@ impl methods for ctxt {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the child's box to the current enclosing box or the current anonymous box.
|
// Add the child's box to the current enclosing box or the current anonymous box.
|
||||||
alt kid.get_specified_style().display_type {
|
match kid.get_specified_style().display_type {
|
||||||
some(DisBlock) => BTree.add_child(self.parent_box, kid_box),
|
some(DisBlock) => BTree.add_child(self.parent_box, kid_box),
|
||||||
some(DisInline) => {
|
some(DisInline) => {
|
||||||
let anon_box = alt self.anon_box {
|
let anon_box = match self.anon_box {
|
||||||
none => {
|
none => {
|
||||||
//
|
//
|
||||||
// The anonymous box inherits the attributes of its parents for now, so
|
// The anonymous box inherits the attributes of its parents for now, so
|
||||||
|
@ -101,7 +101,7 @@ impl methods for ctxt {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the child's box to the current enclosing box.
|
// Add the child's box to the current enclosing box.
|
||||||
alt kid.get_specified_style().display_type {
|
match kid.get_specified_style().display_type {
|
||||||
some(DisBlock) => {
|
some(DisBlock) => {
|
||||||
// TODO
|
// TODO
|
||||||
#warn("TODO: non-inline display found inside inline box");
|
#warn("TODO: non-inline display found inside inline box");
|
||||||
|
@ -124,7 +124,7 @@ impl methods for ctxt {
|
||||||
#debug("parent node:");
|
#debug("parent node:");
|
||||||
self.parent_node.dump();
|
self.parent_node.dump();
|
||||||
|
|
||||||
alt self.parent_node.get_specified_style().display_type {
|
match self.parent_node.get_specified_style().display_type {
|
||||||
some(DisBlock) => self.construct_boxes_for_block_children(),
|
some(DisBlock) => self.construct_boxes_for_block_children(),
|
||||||
some(DisInline) => self.construct_boxes_for_inline_children(),
|
some(DisInline) => self.construct_boxes_for_inline_children(),
|
||||||
some(DisNone) => { /* Nothing to do. */ }
|
some(DisNone) => { /* Nothing to do. */ }
|
||||||
|
@ -141,7 +141,7 @@ impl methods for ctxt {
|
||||||
anonymous box to the block.
|
anonymous box to the block.
|
||||||
"]
|
"]
|
||||||
fn finish_anonymous_box_if_necessary() {
|
fn finish_anonymous_box_if_necessary() {
|
||||||
alt copy self.anon_box {
|
match copy self.anon_box {
|
||||||
none => { /* Nothing to do. */ }
|
none => { /* Nothing to do. */ }
|
||||||
some(b) => BTree.add_child(self.parent_box, b)
|
some(b) => BTree.add_child(self.parent_box, b)
|
||||||
}
|
}
|
||||||
|
@ -159,10 +159,10 @@ impl box_builder_priv of box_builder_priv for Node {
|
||||||
size.
|
size.
|
||||||
"]
|
"]
|
||||||
fn determine_box_kind() -> BoxKind {
|
fn determine_box_kind() -> BoxKind {
|
||||||
alt self.read(|n| copy n.kind) {
|
match self.read(|n| copy n.kind) {
|
||||||
~Text(string) => TextBox(@text_box(copy string)),
|
~Text(string) => TextBox(@text_box(copy string)),
|
||||||
~Element(element) => {
|
~Element(element) => {
|
||||||
alt *element.kind {
|
match *element.kind {
|
||||||
HTMLDivElement => BlockBox,
|
HTMLDivElement => BlockBox,
|
||||||
HTMLImageElement({size}) => IntrinsicBox(@size),
|
HTMLImageElement({size}) => IntrinsicBox(@size),
|
||||||
UnknownElement => InlineBox
|
UnknownElement => InlineBox
|
||||||
|
@ -181,7 +181,7 @@ impl box_builder_methods of box_builder_methods for Node {
|
||||||
fn construct_boxes() -> @Box {
|
fn construct_boxes() -> @Box {
|
||||||
let box_kind = self.determine_box_kind();
|
let box_kind = self.determine_box_kind();
|
||||||
let my_box = @Box(self, box_kind);
|
let my_box = @Box(self, box_kind);
|
||||||
alt box_kind {
|
match box_kind {
|
||||||
BlockBox | InlineBox => {
|
BlockBox | InlineBox => {
|
||||||
let cx = create_context(self, my_box);
|
let cx = create_context(self, my_box);
|
||||||
cx.construct_boxes_for_children();
|
cx.construct_boxes_for_children();
|
||||||
|
|
|
@ -72,7 +72,7 @@ fn box_to_display_items(list: dl::display_list, box: @Box, origin: Point2D<au>)
|
||||||
let bounds = Rect(origin, copy box.bounds.size);
|
let bounds = Rect(origin, copy box.bounds.size);
|
||||||
let col = box.appearance.background_color;
|
let col = box.appearance.background_color;
|
||||||
|
|
||||||
alt box.kind {
|
match box.kind {
|
||||||
TextBox(subbox) => {
|
TextBox(subbox) => {
|
||||||
let run = copy subbox.run;
|
let run = copy subbox.run;
|
||||||
assert run.is_some();
|
assert run.is_some();
|
||||||
|
@ -119,13 +119,13 @@ fn should_convert_text_boxes_to_solid_color_background_items() {
|
||||||
let n = s.new_node(Text(~"firecracker"));
|
let n = s.new_node(Text(~"firecracker"));
|
||||||
let b = n.construct_boxes();
|
let b = n.construct_boxes();
|
||||||
|
|
||||||
let subbox = alt check b.kind { TextBox(subbox) => subbox };
|
let subbox = match check b.kind { TextBox(subbox) => subbox };
|
||||||
|
|
||||||
b.reflow_text(px_to_au(800), subbox);
|
b.reflow_text(px_to_au(800), subbox);
|
||||||
let list = dvec();
|
let list = dvec();
|
||||||
box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
|
box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
|
||||||
|
|
||||||
alt list[0].item_type {
|
match list[0].item_type {
|
||||||
dl::display_item_solid_color(*) => { }
|
dl::display_item_solid_color(*) => { }
|
||||||
_ => { fail }
|
_ => { fail }
|
||||||
}
|
}
|
||||||
|
@ -140,13 +140,13 @@ fn should_convert_text_boxes_to_text_items() {
|
||||||
let n = s.new_node(Text(~"firecracker"));
|
let n = s.new_node(Text(~"firecracker"));
|
||||||
let b = n.construct_boxes();
|
let b = n.construct_boxes();
|
||||||
|
|
||||||
let subbox = alt check b.kind { TextBox(subbox) => { subbox } };
|
let subbox = match check b.kind { TextBox(subbox) => { subbox } };
|
||||||
|
|
||||||
b.reflow_text(px_to_au(800), subbox);
|
b.reflow_text(px_to_au(800), subbox);
|
||||||
let list = dvec();
|
let list = dvec();
|
||||||
box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
|
box_to_display_items(list, b, Point2D(px_to_au(0), px_to_au(0)));
|
||||||
|
|
||||||
alt list[1].item_type {
|
match list[1].item_type {
|
||||||
dl::display_item_text(_) => { }
|
dl::display_item_text(_) => { }
|
||||||
_ => { fail }
|
_ => { fail }
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ fn should_calculate_the_bounds_of_the_text_box_background_color() {
|
||||||
let n = s.new_node(Text(~"firecracker"));
|
let n = s.new_node(Text(~"firecracker"));
|
||||||
let b = n.construct_boxes();
|
let b = n.construct_boxes();
|
||||||
|
|
||||||
let subbox = alt check b.kind { TextBox(subbox) => { subbox } };
|
let subbox = match check b.kind { TextBox(subbox) => { subbox } };
|
||||||
|
|
||||||
b.reflow_text(px_to_au(800), subbox);
|
b.reflow_text(px_to_au(800), subbox);
|
||||||
let list = dvec();
|
let list = dvec();
|
||||||
|
@ -182,7 +182,7 @@ fn should_calculate_the_bounds_of_the_text_items() {
|
||||||
let n = s.new_node(Text(~"firecracker"));
|
let n = s.new_node(Text(~"firecracker"));
|
||||||
let b = n.construct_boxes();
|
let b = n.construct_boxes();
|
||||||
|
|
||||||
let subbox = alt check b.kind { TextBox(subbox) => { subbox } };
|
let subbox = match check b.kind { TextBox(subbox) => { subbox } };
|
||||||
|
|
||||||
b.reflow_text(px_to_au(800), subbox);
|
b.reflow_text(px_to_au(800), subbox);
|
||||||
let list = dvec();
|
let list = dvec();
|
||||||
|
|
|
@ -29,7 +29,7 @@ enum Msg {
|
||||||
fn Layout(renderer: Renderer) -> Layout {
|
fn Layout(renderer: Renderer) -> Layout {
|
||||||
do spawn_listener::<Msg>|request| {
|
do spawn_listener::<Msg>|request| {
|
||||||
loop {
|
loop {
|
||||||
alt request.recv() {
|
match request.recv() {
|
||||||
PingMsg(ping_channel) => ping_channel.send(content::PongMsg),
|
PingMsg(ping_channel) => ping_channel.send(content::PongMsg),
|
||||||
ExitMsg => {
|
ExitMsg => {
|
||||||
#debug("layout: ExitMsg received");
|
#debug("layout: ExitMsg received");
|
||||||
|
|
|
@ -33,16 +33,16 @@ impl ApplyStyleBoxMethods of ApplyStyleBoxMethods for @Box {
|
||||||
fn apply_style() {
|
fn apply_style() {
|
||||||
// Right now, we only handle images.
|
// Right now, we only handle images.
|
||||||
do self.node.read |node| {
|
do self.node.read |node| {
|
||||||
alt node.kind {
|
match node.kind {
|
||||||
~Element(element) => {
|
~Element(element) => {
|
||||||
let style = self.node.get_specified_style();
|
let style = self.node.get_specified_style();
|
||||||
|
|
||||||
self.appearance.background_color = alt style.background_color {
|
self.appearance.background_color = match style.background_color {
|
||||||
some(col) => col,
|
some(col) => col,
|
||||||
none => node.kind.default_color()
|
none => node.kind.default_color()
|
||||||
};
|
};
|
||||||
|
|
||||||
alt element.kind {
|
match element.kind {
|
||||||
~HTMLImageElement(*) => {
|
~HTMLImageElement(*) => {
|
||||||
let url = element.get_attr(~"src");
|
let url = element.get_attr(~"src");
|
||||||
|
|
||||||
|
|
|
@ -13,15 +13,15 @@ export matching_methods;
|
||||||
|
|
||||||
#[doc="Check if a CSS attribute matches the attribute of an HTML element."]
|
#[doc="Check if a CSS attribute matches the attribute of an HTML element."]
|
||||||
fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
|
fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
|
||||||
alt attr {
|
match attr {
|
||||||
Exists(name) => {
|
Exists(name) => {
|
||||||
alt elmt.get_attr(name) {
|
match elmt.get_attr(name) {
|
||||||
some(_) => true,
|
some(_) => true,
|
||||||
none => false
|
none => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Exact(name, val) => {
|
Exact(name, val) => {
|
||||||
alt elmt.get_attr(name) {
|
match elmt.get_attr(name) {
|
||||||
some(value) => value == val,
|
some(value) => value == val,
|
||||||
none => false
|
none => false
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,13 @@ fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
|
||||||
// it cannot match.
|
// it cannot match.
|
||||||
if val == ~"" { return false; }
|
if val == ~"" { return false; }
|
||||||
|
|
||||||
alt elmt.get_attr(name) {
|
match elmt.get_attr(name) {
|
||||||
some(value) => value.split_char(' ').contains(val),
|
some(value) => value.split_char(' ').contains(val),
|
||||||
none => false
|
none => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StartsWith(name, val) => {
|
StartsWith(name, val) => {
|
||||||
alt elmt.get_attr(name) {
|
match elmt.get_attr(name) {
|
||||||
some(value) => {
|
some(value) => {
|
||||||
//check that there is only one attribute value and it
|
//check that there is only one attribute value and it
|
||||||
//starts with the perscribed value
|
//starts with the perscribed value
|
||||||
|
@ -66,10 +66,10 @@ impl priv_matching_methods of priv_matching_methods for Node {
|
||||||
information, describes the given HTML element.
|
information, describes the given HTML element.
|
||||||
"]
|
"]
|
||||||
fn matches_element(sel: ~Selector) -> bool {
|
fn matches_element(sel: ~Selector) -> bool {
|
||||||
alt *sel {
|
match *sel {
|
||||||
Child(_, _) | Descendant(_, _) | Sibling(_, _) => { return false; }
|
Child(_, _) | Descendant(_, _) | Sibling(_, _) => { return false; }
|
||||||
Element(tag, attrs) => {
|
Element(tag, attrs) => {
|
||||||
alt self.read(|n| copy *n.kind) {
|
match self.read(|n| copy *n.kind) {
|
||||||
base::Element(elmt) => {
|
base::Element(elmt) => {
|
||||||
if !(tag == ~"*" || tag == elmt.tag_name) {
|
if !(tag == ~"*" || tag == elmt.tag_name) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -94,10 +94,10 @@ impl priv_matching_methods of priv_matching_methods for Node {
|
||||||
|
|
||||||
#[doc = "Checks if a generic CSS selector matches a given HTML element"]
|
#[doc = "Checks if a generic CSS selector matches a given HTML element"]
|
||||||
fn matches_selector(sel : ~Selector) -> bool {
|
fn matches_selector(sel : ~Selector) -> bool {
|
||||||
alt *sel {
|
match *sel {
|
||||||
Element(str, atts) => { return self.matches_element(sel); }
|
Element(str, atts) => { return self.matches_element(sel); }
|
||||||
Child(sel1, sel2) => {
|
Child(sel1, sel2) => {
|
||||||
return alt self.read(|n| n.tree.parent) {
|
return match self.read(|n| n.tree.parent) {
|
||||||
some(parent) => self.matches_element(sel2) && parent.matches_selector(sel1),
|
some(parent) => self.matches_element(sel2) && parent.matches_selector(sel1),
|
||||||
none => false
|
none => false
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ impl priv_matching_methods of priv_matching_methods for Node {
|
||||||
|
|
||||||
//loop over all ancestors to check if they are the person
|
//loop over all ancestors to check if they are the person
|
||||||
//we should be descended from.
|
//we should be descended from.
|
||||||
let mut cur_parent = alt self.read(|n| n.tree.parent) {
|
let mut cur_parent = match self.read(|n| n.tree.parent) {
|
||||||
some(parent) => parent,
|
some(parent) => parent,
|
||||||
none => return false
|
none => return false
|
||||||
};
|
};
|
||||||
|
@ -115,7 +115,7 @@ impl priv_matching_methods of priv_matching_methods for Node {
|
||||||
loop {
|
loop {
|
||||||
if cur_parent.matches_selector(sel1) { return true; }
|
if cur_parent.matches_selector(sel1) { return true; }
|
||||||
|
|
||||||
cur_parent = alt cur_parent.read(|n| n.tree.parent) {
|
cur_parent = match cur_parent.read(|n| n.tree.parent) {
|
||||||
some(parent) => parent,
|
some(parent) => parent,
|
||||||
none => return false
|
none => return false
|
||||||
};
|
};
|
||||||
|
@ -125,13 +125,13 @@ impl priv_matching_methods of priv_matching_methods for Node {
|
||||||
if !self.matches_element(sel2) { return false; }
|
if !self.matches_element(sel2) { return false; }
|
||||||
|
|
||||||
// Loop over this node's previous siblings to see if they match.
|
// Loop over this node's previous siblings to see if they match.
|
||||||
alt self.read(|n| n.tree.prev_sibling) {
|
match self.read(|n| n.tree.prev_sibling) {
|
||||||
some(sib) => {
|
some(sib) => {
|
||||||
let mut cur_sib = sib;
|
let mut cur_sib = sib;
|
||||||
loop {
|
loop {
|
||||||
if cur_sib.matches_selector(sel1) { return true; }
|
if cur_sib.matches_selector(sel1) { return true; }
|
||||||
|
|
||||||
cur_sib = alt cur_sib.read(|n| n.tree.prev_sibling) {
|
cur_sib = match cur_sib.read(|n| n.tree.prev_sibling) {
|
||||||
some(sib) => sib,
|
some(sib) => sib,
|
||||||
none => { break; }
|
none => { break; }
|
||||||
};
|
};
|
||||||
|
@ -141,13 +141,13 @@ impl priv_matching_methods of priv_matching_methods for Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the rest of the siblings
|
// check the rest of the siblings
|
||||||
alt self.read(|n| n.tree.next_sibling) {
|
match self.read(|n| n.tree.next_sibling) {
|
||||||
some(sib) => {
|
some(sib) => {
|
||||||
let mut cur_sib = sib;
|
let mut cur_sib = sib;
|
||||||
loop {
|
loop {
|
||||||
if cur_sib.matches_selector(sel1) { return true; }
|
if cur_sib.matches_selector(sel1) { return true; }
|
||||||
|
|
||||||
cur_sib = alt cur_sib.read(|n| n.tree.next_sibling) {
|
cur_sib = match cur_sib.read(|n| n.tree.next_sibling) {
|
||||||
some(sib) => sib,
|
some(sib) => sib,
|
||||||
none => { break; }
|
none => { break; }
|
||||||
};
|
};
|
||||||
|
@ -170,7 +170,7 @@ impl priv_style_methods of priv_style_methods for Node {
|
||||||
#[doc="Update the computed style of an HTML element with a style specified by CSS."]
|
#[doc="Update the computed style of an HTML element with a style specified by CSS."]
|
||||||
fn update_style(decl : StyleDeclaration) {
|
fn update_style(decl : StyleDeclaration) {
|
||||||
self.aux(|layout| {
|
self.aux(|layout| {
|
||||||
alt decl {
|
match decl {
|
||||||
BackgroundColor(col) => layout.specified_style.background_color = some(col),
|
BackgroundColor(col) => layout.specified_style.background_color = some(col),
|
||||||
Display(dis) => layout.specified_style.display_type = some(dis),
|
Display(dis) => layout.specified_style.display_type = some(dis),
|
||||||
FontSize(size) => layout.specified_style.font_size = some(size),
|
FontSize(size) => layout.specified_style.font_size = some(size),
|
||||||
|
|
|
@ -29,7 +29,7 @@ trait default_style_methods {
|
||||||
#[doc="Default stylesfor various attributes in case they don't get initialized from css selectors"]
|
#[doc="Default stylesfor various attributes in case they don't get initialized from css selectors"]
|
||||||
impl default_style_methods of default_style_methods for NodeKind {
|
impl default_style_methods of default_style_methods for NodeKind {
|
||||||
fn default_color() -> Color {
|
fn default_color() -> Color {
|
||||||
alt self {
|
match self {
|
||||||
Text(*) => { white() }
|
Text(*) => { white() }
|
||||||
Element(*) => {
|
Element(*) => {
|
||||||
let r = rand::rng();
|
let r = rand::rng();
|
||||||
|
@ -39,10 +39,10 @@ impl default_style_methods of default_style_methods for NodeKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_display_type() -> DisplayType {
|
fn default_display_type() -> DisplayType {
|
||||||
alt self {
|
match self {
|
||||||
Text(*) => { DisInline }
|
Text(*) => { DisInline }
|
||||||
Element(element) => {
|
Element(element) => {
|
||||||
alt *element.kind {
|
match *element.kind {
|
||||||
HTMLDivElement => DisBlock,
|
HTMLDivElement => DisBlock,
|
||||||
HTMLHeadElement => DisNone,
|
HTMLHeadElement => DisNone,
|
||||||
HTMLImageElement(*) => DisInline,
|
HTMLImageElement(*) => DisInline,
|
||||||
|
|
|
@ -23,7 +23,7 @@ trait text_layout_methods {
|
||||||
#[doc="The main reflow routine for text layout."]
|
#[doc="The main reflow routine for text layout."]
|
||||||
impl text_layout_methods of text_layout_methods for @Box {
|
impl text_layout_methods of text_layout_methods for @Box {
|
||||||
fn reflow_text(_available_width: au, subbox: @text_box) {
|
fn reflow_text(_available_width: au, subbox: @text_box) {
|
||||||
alt self.kind {
|
match self.kind {
|
||||||
TextBox(*) => { /* ok */ }
|
TextBox(*) => { /* ok */ }
|
||||||
_ => { fail ~"expected text box in reflow_text!" }
|
_ => { fail ~"expected text box in reflow_text!" }
|
||||||
};
|
};
|
||||||
|
@ -51,7 +51,7 @@ fn should_calculate_the_size_of_the_text_box() {
|
||||||
let n = s.new_node(Text(~"firecracker"));
|
let n = s.new_node(Text(~"firecracker"));
|
||||||
let b = n.construct_boxes();
|
let b = n.construct_boxes();
|
||||||
|
|
||||||
let subbox = alt check b.kind { TextBox(subbox) => { subbox } };
|
let subbox = match check b.kind { TextBox(subbox) => { subbox } };
|
||||||
b.reflow_text(px_to_au(800), subbox);
|
b.reflow_text(px_to_au(800), subbox);
|
||||||
let expected = Size2D(px_to_au(84), px_to_au(20));
|
let expected = Size2D(px_to_au(84), px_to_au(20));
|
||||||
assert b.bounds.size == expected;
|
assert b.bounds.size == expected;
|
||||||
|
|
|
@ -25,7 +25,7 @@ fn from_cmdline_args(args: ~[~str]) -> Opts {
|
||||||
getopts::optopt(~"o")
|
getopts::optopt(~"o")
|
||||||
];
|
];
|
||||||
|
|
||||||
let opt_match = alt getopts::getopts(args, opts) {
|
let opt_match = match getopts::getopts(args, opts) {
|
||||||
result::ok(m) => { copy m }
|
result::ok(m) => { copy m }
|
||||||
result::err(f) => { fail getopts::fail_str(f) }
|
result::err(f) => { fail getopts::fail_str(f) }
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@ fn from_cmdline_args(args: ~[~str]) -> Opts {
|
||||||
copy opt_match.free
|
copy opt_match.free
|
||||||
};
|
};
|
||||||
|
|
||||||
let render_mode = alt getopts::opt_maybe_str(opt_match, ~"o") {
|
let render_mode = match getopts::opt_maybe_str(opt_match, ~"o") {
|
||||||
some(output_file) => { Png(copy output_file) }
|
some(output_file) => { Png(copy output_file) }
|
||||||
none => { Screen }
|
none => { Screen }
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,7 @@ trait util_methods {
|
||||||
|
|
||||||
impl util_methods of util_methods for TokenReader {
|
impl util_methods of util_methods for TokenReader {
|
||||||
fn get() -> Token {
|
fn get() -> Token {
|
||||||
alt copy self.lookahead {
|
match copy self.lookahead {
|
||||||
some(tok) => { self.lookahead = none; copy tok }
|
some(tok) => { self.lookahead = none; copy tok }
|
||||||
none => { self.stream.recv() }
|
none => { self.stream.recv() }
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ trait parser_methods {
|
||||||
impl parser_methods of parser_methods for TokenReader {
|
impl parser_methods of parser_methods for TokenReader {
|
||||||
fn parse_element() -> option<~style::Selector> {
|
fn parse_element() -> option<~style::Selector> {
|
||||||
// Get the current element type
|
// Get the current element type
|
||||||
let elmt_name = alt self.get() {
|
let elmt_name = match self.get() {
|
||||||
Element(tag) => { copy tag }
|
Element(tag) => { copy tag }
|
||||||
Eof => { return none; }
|
Eof => { return none; }
|
||||||
_ => { fail ~"Expected an element" }
|
_ => { fail ~"Expected an element" }
|
||||||
|
@ -59,7 +59,7 @@ impl parser_methods of parser_methods for TokenReader {
|
||||||
// Get the attributes associated with that element
|
// Get the attributes associated with that element
|
||||||
loop {
|
loop {
|
||||||
let tok = self.get();
|
let tok = self.get();
|
||||||
alt tok {
|
match tok {
|
||||||
Attr(attr) => { push(attr_list, copy attr); }
|
Attr(attr) => { push(attr_list, copy attr); }
|
||||||
StartDescription | Descendant | Child | Sibling | Comma => {
|
StartDescription | Descendant | Child | Sibling | Comma => {
|
||||||
self.unget(tok);
|
self.unget(tok);
|
||||||
|
@ -81,7 +81,7 @@ impl parser_methods of parser_methods for TokenReader {
|
||||||
loop {
|
loop {
|
||||||
let mut cur_sel;
|
let mut cur_sel;
|
||||||
|
|
||||||
alt self.parse_element() {
|
match self.parse_element() {
|
||||||
some(elmt) => { cur_sel = copy elmt; }
|
some(elmt) => { cur_sel = copy elmt; }
|
||||||
none => { return none; } // we hit an eof in the middle of a rule
|
none => { return none; } // we hit an eof in the middle of a rule
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,9 @@ impl parser_methods of parser_methods for TokenReader {
|
||||||
let tok = self.get();
|
let tok = self.get();
|
||||||
let built_sel <- cur_sel;
|
let built_sel <- cur_sel;
|
||||||
|
|
||||||
alt tok {
|
match tok {
|
||||||
Descendant => {
|
Descendant => {
|
||||||
alt self.parse_element() {
|
match self.parse_element() {
|
||||||
some(elmt) => {
|
some(elmt) => {
|
||||||
let new_sel = copy elmt;
|
let new_sel = copy elmt;
|
||||||
cur_sel <- ~style::Descendant(built_sel, new_sel)
|
cur_sel <- ~style::Descendant(built_sel, new_sel)
|
||||||
|
@ -101,7 +101,7 @@ impl parser_methods of parser_methods for TokenReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Child => {
|
Child => {
|
||||||
alt self.parse_element() {
|
match self.parse_element() {
|
||||||
some(elmt) => {
|
some(elmt) => {
|
||||||
let new_sel = copy elmt;
|
let new_sel = copy elmt;
|
||||||
cur_sel <- ~style::Child(built_sel, new_sel)
|
cur_sel <- ~style::Child(built_sel, new_sel)
|
||||||
|
@ -110,7 +110,7 @@ impl parser_methods of parser_methods for TokenReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Sibling => {
|
Sibling => {
|
||||||
alt self.parse_element() {
|
match self.parse_element() {
|
||||||
some(elmt) => {
|
some(elmt) => {
|
||||||
let new_sel = copy elmt;
|
let new_sel = copy elmt;
|
||||||
cur_sel <- ~style::Sibling(built_sel, new_sel)
|
cur_sel <- ~style::Sibling(built_sel, new_sel)
|
||||||
|
@ -138,7 +138,7 @@ impl parser_methods of parser_methods for TokenReader {
|
||||||
// check if we should break out of the nesting loop as well
|
// check if we should break out of the nesting loop as well
|
||||||
// TODO: fix this when rust gets labelled loops
|
// TODO: fix this when rust gets labelled loops
|
||||||
let tok = self.get();
|
let tok = self.get();
|
||||||
alt tok {
|
match tok {
|
||||||
StartDescription => { break; }
|
StartDescription => { break; }
|
||||||
Comma => { }
|
Comma => { }
|
||||||
_ => { self.unget(tok); }
|
_ => { self.unget(tok); }
|
||||||
|
@ -154,10 +154,10 @@ impl parser_methods of parser_methods for TokenReader {
|
||||||
// Get the description to be applied to the selector
|
// Get the description to be applied to the selector
|
||||||
loop {
|
loop {
|
||||||
let tok = self.get();
|
let tok = self.get();
|
||||||
alt tok {
|
match tok {
|
||||||
EndDescription => { break; }
|
EndDescription => { break; }
|
||||||
Description(prop, val) => {
|
Description(prop, val) => {
|
||||||
let desc = alt prop {
|
let desc = match prop {
|
||||||
// TODO: have color parsing return an option instead of a real value
|
// TODO: have color parsing return an option instead of a real value
|
||||||
~"background-color" => parse_color(val).map(|res| BackgroundColor(res)),
|
~"background-color" => parse_color(val).map(|res| BackgroundColor(res)),
|
||||||
~"color" => parse_color(val).map(|res| TextColor(res)),
|
~"color" => parse_color(val).map(|res| TextColor(res)),
|
||||||
|
@ -180,8 +180,8 @@ impl parser_methods of parser_methods for TokenReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_rule() -> option<~style::Rule> {
|
fn parse_rule() -> option<~style::Rule> {
|
||||||
// TODO: get rid of copies once alt move works
|
// TODO: get rid of copies once match move works
|
||||||
let sel_list = alt self.parse_selector() {
|
let sel_list = match self.parse_selector() {
|
||||||
some(list) => { copy list }
|
some(list) => { copy list }
|
||||||
none => { return none; }
|
none => { return none; }
|
||||||
};
|
};
|
||||||
|
@ -189,7 +189,7 @@ impl parser_methods of parser_methods for TokenReader {
|
||||||
#debug("sel_list: %?", sel_list);
|
#debug("sel_list: %?", sel_list);
|
||||||
|
|
||||||
// Get the description to be applied to the selector
|
// Get the description to be applied to the selector
|
||||||
let desc_list = alt self.parse_description() {
|
let desc_list = match self.parse_description() {
|
||||||
some(list) => { copy list }
|
some(list) => { copy list }
|
||||||
none => { return none; }
|
none => { return none; }
|
||||||
};
|
};
|
||||||
|
@ -205,7 +205,7 @@ fn build_stylesheet(+stream : pipes::port<Token>) -> ~[~style::Rule] {
|
||||||
let reader = {stream : stream, mut lookahead : none};
|
let reader = {stream : stream, mut lookahead : none};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
alt reader.parse_rule() {
|
match reader.parse_rule() {
|
||||||
some(rule) => { push(rule_list, copy rule); }
|
some(rule) => { push(rule_list, copy rule); }
|
||||||
none => { break; }
|
none => { break; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,12 +49,12 @@ trait css_methods {
|
||||||
impl css_methods of css_methods for CssLexer {
|
impl css_methods of css_methods for CssLexer {
|
||||||
fn parse_css() -> Token {
|
fn parse_css() -> Token {
|
||||||
let mut ch: u8;
|
let mut ch: u8;
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => ch = c,
|
CoeChar(c) => ch = c,
|
||||||
CoeEof => { return Eof; }
|
CoeEof => { return Eof; }
|
||||||
}
|
}
|
||||||
|
|
||||||
let token = alt self.parser_state {
|
let token = match self.parser_state {
|
||||||
CssDescription => self.parse_css_description(ch),
|
CssDescription => self.parse_css_description(ch),
|
||||||
CssAttribute => self.parse_css_attribute(ch),
|
CssAttribute => self.parse_css_attribute(ch),
|
||||||
CssElement => self.parse_css_element(ch),
|
CssElement => self.parse_css_element(ch),
|
||||||
|
@ -68,7 +68,7 @@ impl css_methods of css_methods for CssLexer {
|
||||||
fn parse_css_relation(c : u8) -> Token {
|
fn parse_css_relation(c : u8) -> Token {
|
||||||
self.parser_state = CssElement;
|
self.parser_state = CssElement;
|
||||||
|
|
||||||
let token = alt c {
|
let token = match c {
|
||||||
'{' as u8 => { self.parser_state = CssDescription; StartDescription }
|
'{' as u8 => { self.parser_state = CssDescription; StartDescription }
|
||||||
'>' as u8 => { Child }
|
'>' as u8 => { Child }
|
||||||
'+' as u8 => { Sibling }
|
'+' as u8 => { Sibling }
|
||||||
|
@ -112,7 +112,7 @@ impl css_methods of css_methods for CssLexer {
|
||||||
self.parser_state = CssRelation;
|
self.parser_state = CssRelation;
|
||||||
self.input_state.eat_whitespace();
|
self.input_state.eat_whitespace();
|
||||||
|
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => { ch = c }
|
CoeChar(c) => { ch = c }
|
||||||
CoeEof => { fail ~"File ended before description of style" }
|
CoeEof => { fail ~"File ended before description of style" }
|
||||||
}
|
}
|
||||||
|
@ -120,13 +120,13 @@ impl css_methods of css_methods for CssLexer {
|
||||||
return self.parse_css_relation(ch);
|
return self.parse_css_relation(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
alt ch {
|
match ch {
|
||||||
'.' as u8 => return Attr(style::Includes(~"class", self.input_state.parse_ident())),
|
'.' as u8 => return Attr(style::Includes(~"class", self.input_state.parse_ident())),
|
||||||
'#' as u8 => return Attr(style::Includes(~"id", self.input_state.parse_ident())),
|
'#' as u8 => return Attr(style::Includes(~"id", self.input_state.parse_ident())),
|
||||||
'[' as u8 => {
|
'[' as u8 => {
|
||||||
let attr_name = self.input_state.parse_ident();
|
let attr_name = self.input_state.parse_ident();
|
||||||
|
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => { ch = c; }
|
CoeChar(c) => { ch = c; }
|
||||||
CoeEof => { fail ~"File ended before description finished"; }
|
CoeEof => { fail ~"File ended before description finished"; }
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ impl css_methods of css_methods for CssLexer {
|
||||||
} else if ch.is_whitespace() {
|
} else if ch.is_whitespace() {
|
||||||
self.input_state.eat_whitespace();
|
self.input_state.eat_whitespace();
|
||||||
|
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => { ch = c }
|
CoeChar(c) => { ch = c }
|
||||||
CoeEof => { fail ~"Reached end of file in CSS description" }
|
CoeEof => { fail ~"Reached end of file in CSS description" }
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ impl css_methods of css_methods for CssLexer {
|
||||||
push(desc_name, ch);
|
push(desc_name, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => { ch = c }
|
CoeChar(c) => { ch = c }
|
||||||
CoeEof => { fail ~"Reached end of file in CSS description" }
|
CoeEof => { fail ~"Reached end of file in CSS description" }
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ impl css_methods of css_methods for CssLexer {
|
||||||
|
|
||||||
// Get the value of the descriptor
|
// Get the value of the descriptor
|
||||||
loop {
|
loop {
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => { ch = c }
|
CoeChar(c) => { ch = c }
|
||||||
CoeEof => { fail ~"Reached end of file in CSS description" }
|
CoeEof => { fail ~"Reached end of file in CSS description" }
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,12 @@ enum js_message {
|
||||||
fn link_up_attribute(scope: NodeScope, node: Node, -key: ~str, -value: ~str) {
|
fn link_up_attribute(scope: NodeScope, node: Node, -key: ~str, -value: ~str) {
|
||||||
// TODO: Implement atoms so that we don't always perform string comparisons.
|
// TODO: Implement atoms so that we don't always perform string comparisons.
|
||||||
scope.read(node, |node_contents| {
|
scope.read(node, |node_contents| {
|
||||||
alt *node_contents.kind {
|
match *node_contents.kind {
|
||||||
Element(element) => {
|
Element(element) => {
|
||||||
element.attrs.push(~Attr(copy key, copy value));
|
element.attrs.push(~Attr(copy key, copy value));
|
||||||
alt *element.kind {
|
match *element.kind {
|
||||||
HTMLImageElement(img) if key == ~"width" => {
|
HTMLImageElement(img) if key == ~"width" => {
|
||||||
alt int::from_str(value) {
|
match int::from_str(value) {
|
||||||
none => {
|
none => {
|
||||||
// Drop on the floor.
|
// Drop on the floor.
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ fn link_up_attribute(scope: NodeScope, node: Node, -key: ~str, -value: ~str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HTMLImageElement(img) if key == ~"height" => {
|
HTMLImageElement(img) if key == ~"height" => {
|
||||||
alt int::from_str(value) {
|
match int::from_str(value) {
|
||||||
none => {
|
none => {
|
||||||
// Drop on the floor.
|
// Drop on the floor.
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ fn link_up_attribute(scope: NodeScope, node: Node, -key: ~str, -value: ~str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_element_kind(tag_name: ~str) -> ~ElementKind {
|
fn build_element_kind(tag_name: ~str) -> ~ElementKind {
|
||||||
alt tag_name {
|
match tag_name {
|
||||||
~"div" => ~HTMLDivElement,
|
~"div" => ~HTMLDivElement,
|
||||||
~"img" => {
|
~"img" => {
|
||||||
~HTMLImageElement({ mut size: Size2D(geometry::px_to_au(100),
|
~HTMLImageElement({ mut size: Size2D(geometry::px_to_au(100),
|
||||||
|
@ -101,11 +101,11 @@ fn css_link_listener(to_parent : comm::chan<Stylesheet>, from_parent : comm::por
|
||||||
let mut result_vec = ~[];
|
let mut result_vec = ~[];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
alt from_parent.recv() {
|
match from_parent.recv() {
|
||||||
File(url) => {
|
File(url) => {
|
||||||
let result_port = comm::port();
|
let result_port = comm::port();
|
||||||
let result_chan = comm::chan(result_port);
|
let result_chan = comm::chan(result_port);
|
||||||
// TODO: change copy to move once we have alt move
|
// TODO: change copy to move once we have match move
|
||||||
let url = copy url;
|
let url = copy url;
|
||||||
task::spawn(|| {
|
task::spawn(|| {
|
||||||
// TODO: change copy to move once we can move into closures
|
// TODO: change copy to move once we can move into closures
|
||||||
|
@ -132,11 +132,11 @@ fn js_script_listener(to_parent : comm::chan<~[~[u8]]>, from_parent : comm::port
|
||||||
let mut result_vec = ~[];
|
let mut result_vec = ~[];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
alt from_parent.recv() {
|
match from_parent.recv() {
|
||||||
js_file(url) => {
|
js_file(url) => {
|
||||||
let result_port = comm::port();
|
let result_port = comm::port();
|
||||||
let result_chan = comm::chan(result_port);
|
let result_chan = comm::chan(result_port);
|
||||||
// TODO: change copy to move once we have alt move
|
// TODO: change copy to move once we have match move
|
||||||
let url = copy url;
|
let url = copy url;
|
||||||
do task::spawn || {
|
do task::spawn || {
|
||||||
let input_port = port();
|
let input_port = port();
|
||||||
|
@ -145,7 +145,7 @@ fn js_script_listener(to_parent : comm::chan<~[~[u8]]>, from_parent : comm::port
|
||||||
|
|
||||||
let mut buf = ~[];
|
let mut buf = ~[];
|
||||||
loop {
|
loop {
|
||||||
alt input_port.recv() {
|
match input_port.recv() {
|
||||||
Payload(data) => {
|
Payload(data) => {
|
||||||
buf += data;
|
buf += data;
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ fn build_dom(scope: NodeScope, stream: comm::port<Token>, url: url,
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let token = stream.recv();
|
let token = stream.recv();
|
||||||
alt token {
|
match token {
|
||||||
parser::Eof => { break; }
|
parser::Eof => { break; }
|
||||||
parser::StartOpeningTag(tag_name) => {
|
parser::StartOpeningTag(tag_name) => {
|
||||||
#debug["starting tag %s", tag_name];
|
#debug["starting tag %s", tag_name];
|
||||||
|
@ -216,11 +216,11 @@ fn build_dom(scope: NodeScope, stream: comm::port<Token>, url: url,
|
||||||
parser::SelfCloseTag => {
|
parser::SelfCloseTag => {
|
||||||
//TODO: check for things other than the link tag
|
//TODO: check for things other than the link tag
|
||||||
scope.read(cur_node, |n| {
|
scope.read(cur_node, |n| {
|
||||||
alt *n.kind {
|
match *n.kind {
|
||||||
Element(elmt) if elmt.tag_name == ~"link" => {
|
Element(elmt) if elmt.tag_name == ~"link" => {
|
||||||
alt elmt.get_attr(~"rel") {
|
match elmt.get_attr(~"rel") {
|
||||||
some(r) if r == ~"stylesheet" => {
|
some(r) if r == ~"stylesheet" => {
|
||||||
alt elmt.get_attr(~"href") {
|
match elmt.get_attr(~"href") {
|
||||||
some(filename) => {
|
some(filename) => {
|
||||||
#debug["Linking to a css sheet named: %s", filename];
|
#debug["Linking to a css sheet named: %s", filename];
|
||||||
// FIXME: Need to base the new url on the current url
|
// FIXME: Need to base the new url on the current url
|
||||||
|
@ -241,9 +241,9 @@ fn build_dom(scope: NodeScope, stream: comm::port<Token>, url: url,
|
||||||
parser::EndTag(tag_name) => {
|
parser::EndTag(tag_name) => {
|
||||||
// TODO: Assert that the closing tag has the right name.
|
// TODO: Assert that the closing tag has the right name.
|
||||||
scope.read(cur_node, |n| {
|
scope.read(cur_node, |n| {
|
||||||
alt *n.kind {
|
match *n.kind {
|
||||||
Element(elmt) if elmt.tag_name == ~"script" => {
|
Element(elmt) if elmt.tag_name == ~"script" => {
|
||||||
alt elmt.get_attr(~"src") {
|
match elmt.get_attr(~"src") {
|
||||||
some(filename) => {
|
some(filename) => {
|
||||||
#debug["Linking to a js script named: %s", filename];
|
#debug["Linking to a js script named: %s", filename];
|
||||||
let new_url = make_url(filename, some(copy url));
|
let new_url = make_url(filename, some(copy url));
|
||||||
|
|
|
@ -38,11 +38,11 @@ trait html_methods {
|
||||||
impl html_methods of html_methods for HtmlLexer {
|
impl html_methods of html_methods for HtmlLexer {
|
||||||
fn parse_html() -> Token {
|
fn parse_html() -> Token {
|
||||||
let mut ch: u8;
|
let mut ch: u8;
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => { ch = c; }
|
CoeChar(c) => { ch = c; }
|
||||||
CoeEof => { return Eof; }
|
CoeEof => { return Eof; }
|
||||||
}
|
}
|
||||||
let token = alt self.parser_state {
|
let token = match self.parser_state {
|
||||||
NormalHtml => { self.parse_in_normal_state(ch) }
|
NormalHtml => { self.parse_in_normal_state(ch) }
|
||||||
TagHtml => { self.parse_in_tag_state(ch) }
|
TagHtml => { self.parse_in_tag_state(ch) }
|
||||||
};
|
};
|
||||||
|
@ -54,7 +54,7 @@ impl html_methods of html_methods for HtmlLexer {
|
||||||
fn parse_in_normal_state(c: u8) -> Token {
|
fn parse_in_normal_state(c: u8) -> Token {
|
||||||
let mut ch = c;
|
let mut ch = c;
|
||||||
if ch == ('<' as u8) {
|
if ch == ('<' as u8) {
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => { ch = c; }
|
CoeChar(c) => { ch = c; }
|
||||||
CoeEof => { self.input_state.parse_err(~"eof after '<'") }
|
CoeEof => { self.input_state.parse_err(~"eof after '<'") }
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ impl html_methods of html_methods for HtmlLexer {
|
||||||
// Make a text node.
|
// Make a text node.
|
||||||
let mut s: ~[u8] = ~[ch];
|
let mut s: ~[u8] = ~[ch];
|
||||||
loop {
|
loop {
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => {
|
CoeChar(c) => {
|
||||||
if c == ('<' as u8) {
|
if c == ('<' as u8) {
|
||||||
self.input_state.unget(c);
|
self.input_state.unget(c);
|
||||||
|
@ -110,7 +110,7 @@ impl html_methods of html_methods for HtmlLexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ch == ('/' as u8) {
|
if ch == ('/' as u8) {
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => {
|
CoeChar(c) => {
|
||||||
if c == ('>' as u8) {
|
if c == ('>' as u8) {
|
||||||
self.parser_state = NormalHtml;
|
self.parser_state = NormalHtml;
|
||||||
|
@ -132,7 +132,7 @@ impl html_methods of html_methods for HtmlLexer {
|
||||||
// Parse an attribute.
|
// Parse an attribute.
|
||||||
let mut attribute_name = ~[ch];
|
let mut attribute_name = ~[ch];
|
||||||
loop {
|
loop {
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => {
|
CoeChar(c) => {
|
||||||
if c == ('=' as u8) { break; }
|
if c == ('=' as u8) { break; }
|
||||||
push(attribute_name, c);
|
push(attribute_name, c);
|
||||||
|
@ -148,7 +148,7 @@ impl html_methods of html_methods for HtmlLexer {
|
||||||
self.input_state.expect('"' as u8);
|
self.input_state.expect('"' as u8);
|
||||||
let mut attribute_value = ~[];
|
let mut attribute_value = ~[];
|
||||||
loop {
|
loop {
|
||||||
alt self.input_state.get() {
|
match self.input_state.get() {
|
||||||
CoeChar(c) => {
|
CoeChar(c) => {
|
||||||
if c == ('"' as u8) { break; }
|
if c == ('"' as u8) { break; }
|
||||||
push(attribute_value, c);
|
push(attribute_value, c);
|
||||||
|
|
|
@ -46,7 +46,7 @@ trait util_methods {
|
||||||
|
|
||||||
impl util_methods of util_methods for InputState {
|
impl util_methods of util_methods for InputState {
|
||||||
fn get() -> CharOrEof {
|
fn get() -> CharOrEof {
|
||||||
alt copy self.lookahead {
|
match copy self.lookahead {
|
||||||
some(coe) => {
|
some(coe) => {
|
||||||
let rv = coe;
|
let rv = coe;
|
||||||
self.lookahead = none;
|
self.lookahead = none;
|
||||||
|
@ -67,9 +67,9 @@ impl util_methods of util_methods for InputState {
|
||||||
return CoeEof;
|
return CoeEof;
|
||||||
}
|
}
|
||||||
|
|
||||||
alt self.input_port.recv() {
|
match self.input_port.recv() {
|
||||||
Payload(data) => {
|
Payload(data) => {
|
||||||
// TODO: change copy to move once we have alt move
|
// TODO: change copy to move once we have match move
|
||||||
self.buffer = copy data;
|
self.buffer = copy data;
|
||||||
return CoeChar(vec::shift(self.buffer));
|
return CoeChar(vec::shift(self.buffer));
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ impl util_methods of util_methods for InputState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expect(ch: u8) {
|
fn expect(ch: u8) {
|
||||||
alt self.get() {
|
match self.get() {
|
||||||
CoeChar(c) => { if c != ch { self.parse_err(#fmt("expected '%c'", ch as char)); } }
|
CoeChar(c) => { if c != ch { self.parse_err(#fmt("expected '%c'", ch as char)); } }
|
||||||
CoeEof => { self.parse_err(#fmt("expected '%c' at eof", ch as char)); }
|
CoeEof => { self.parse_err(#fmt("expected '%c' at eof", ch as char)); }
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ impl util_methods of util_methods for InputState {
|
||||||
fn parse_ident() -> ~str {
|
fn parse_ident() -> ~str {
|
||||||
let mut result: ~[u8] = ~[];
|
let mut result: ~[u8] = ~[];
|
||||||
loop {
|
loop {
|
||||||
alt self.get() {
|
match self.get() {
|
||||||
CoeChar(c) => {
|
CoeChar(c) => {
|
||||||
if (c.is_alpha()) { push(result, c); }
|
if (c.is_alpha()) { push(result, c); }
|
||||||
else if result.len() == 0u { self.parse_err(~"expected ident"); }
|
else if result.len() == 0u { self.parse_err(~"expected ident"); }
|
||||||
|
@ -125,7 +125,7 @@ impl util_methods of util_methods for InputState {
|
||||||
|
|
||||||
fn eat_whitespace() {
|
fn eat_whitespace() {
|
||||||
loop {
|
loop {
|
||||||
alt self.get() {
|
match self.get() {
|
||||||
CoeChar(c) => {
|
CoeChar(c) => {
|
||||||
if !c.is_whitespace() {
|
if !c.is_whitespace() {
|
||||||
self.unget(c);
|
self.unget(c);
|
||||||
|
|
|
@ -10,7 +10,7 @@ export parse_size;
|
||||||
export parse_display_type;
|
export parse_display_type;
|
||||||
|
|
||||||
fn parse_unit(str : ~str) -> option<Unit> {
|
fn parse_unit(str : ~str) -> option<Unit> {
|
||||||
alt str {
|
match str {
|
||||||
s if s.ends_with(~"%") => from_str(str.substr(0, str.len() - 1)).map(|f| Percent(f)),
|
s if s.ends_with(~"%") => from_str(str.substr(0, str.len() - 1)).map(|f| Percent(f)),
|
||||||
s if s.ends_with(~"in") => from_str(str.substr(0, str.len() - 2)).map(|f| In(f)),
|
s if s.ends_with(~"in") => from_str(str.substr(0, str.len() - 2)).map(|f| In(f)),
|
||||||
s if s.ends_with(~"cm") => from_str(str.substr(0, str.len() - 2)).map(|f| Cm(f)),
|
s if s.ends_with(~"cm") => from_str(str.substr(0, str.len() - 2)).map(|f| Cm(f)),
|
||||||
|
@ -28,7 +28,7 @@ fn parse_font_size(str : ~str) -> option<Unit> {
|
||||||
// The default pixel size, not sure if this is accurate.
|
// The default pixel size, not sure if this is accurate.
|
||||||
let default = 16.0;
|
let default = 16.0;
|
||||||
|
|
||||||
alt str {
|
match str {
|
||||||
~"xx-small" => some(Px(0.6*default)),
|
~"xx-small" => some(Px(0.6*default)),
|
||||||
~"x-small" => some(Px(0.75*default)),
|
~"x-small" => some(Px(0.75*default)),
|
||||||
~"small" => some(Px(8.0/9.0*default)),
|
~"small" => some(Px(8.0/9.0*default)),
|
||||||
|
@ -45,7 +45,7 @@ fn parse_font_size(str : ~str) -> option<Unit> {
|
||||||
|
|
||||||
// For width / height, and anything else with the same attribute values
|
// For width / height, and anything else with the same attribute values
|
||||||
fn parse_size(str : ~str) -> option<Unit> {
|
fn parse_size(str : ~str) -> option<Unit> {
|
||||||
alt str {
|
match str {
|
||||||
~"auto" => some(Auto),
|
~"auto" => some(Auto),
|
||||||
~"inherit" => some(Em(1.0)),
|
~"inherit" => some(Em(1.0)),
|
||||||
_ => parse_unit(str),
|
_ => parse_unit(str),
|
||||||
|
@ -53,7 +53,7 @@ fn parse_size(str : ~str) -> option<Unit> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_display_type(str : ~str) -> option<DisplayType> {
|
fn parse_display_type(str : ~str) -> option<DisplayType> {
|
||||||
alt str {
|
match str {
|
||||||
~"inline" => some(DisInline),
|
~"inline" => some(DisInline),
|
||||||
~"block" => some(DisBlock),
|
~"block" => some(DisBlock),
|
||||||
~"none" => some(DisNone),
|
~"none" => some(DisNone),
|
||||||
|
|
|
@ -70,7 +70,7 @@ fn mainloop(po: port<Msg>) {
|
||||||
// Handle messages
|
// Handle messages
|
||||||
#debug("osmain: peeking");
|
#debug("osmain: peeking");
|
||||||
while po.peek() {
|
while po.peek() {
|
||||||
alt po.recv() {
|
match po.recv() {
|
||||||
AddKeyHandler(key_ch) => key_handlers.push(#move(key_ch)),
|
AddKeyHandler(key_ch) => key_handlers.push(#move(key_ch)),
|
||||||
AddEventListener(event_listener) => event_listeners.push(event_listener),
|
AddEventListener(event_listener) => event_listeners.push(event_listener),
|
||||||
BeginDrawing(sender) => lend_surface(*surfaces, sender),
|
BeginDrawing(sender) => lend_surface(*surfaces, sender),
|
||||||
|
@ -224,7 +224,7 @@ fn destroy_surface(+surface: surface) {
|
||||||
|
|
||||||
#[doc = "A function for spawning into the platform's main thread"]
|
#[doc = "A function for spawning into the platform's main thread"]
|
||||||
fn on_osmain<T: send>(+f: fn~(comm::port<T>)) -> comm::chan<T> {
|
fn on_osmain<T: send>(+f: fn~(comm::port<T>)) -> comm::chan<T> {
|
||||||
task::task().sched_mode(task::osmain).spawn_listener(f)
|
task::task().sched_mode(task::platform_thread).spawn_listener(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(target_os = "linux")]
|
// #[cfg(target_os = "linux")]
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn factory(url: url, progress_chan: chan<ProgressMsg>) {
|
||||||
assert url.scheme == ~"file";
|
assert url.scheme == ~"file";
|
||||||
|
|
||||||
do spawn {
|
do spawn {
|
||||||
alt file_reader(url.path) {
|
match file_reader(url.path) {
|
||||||
ok(reader) => {
|
ok(reader) => {
|
||||||
while !reader.eof() {
|
while !reader.eof() {
|
||||||
let data = reader.read_bytes(READ_SIZE);
|
let data = reader.read_bytes(READ_SIZE);
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn factory(url: url, progress_chan: chan<ProgressMsg>) {
|
||||||
let errored = @mut false;
|
let errored = @mut false;
|
||||||
do request.begin |event| {
|
do request.begin |event| {
|
||||||
let url = copy url;
|
let url = copy url;
|
||||||
alt event {
|
match event {
|
||||||
http_client::Status(*) => { }
|
http_client::Status(*) => { }
|
||||||
http_client::Payload(data) => {
|
http_client::Payload(data) => {
|
||||||
#debug("http_loader: got data from %?", url);
|
#debug("http_loader: got data from %?", url);
|
||||||
|
|
|
@ -67,7 +67,7 @@ class ResourceManager {
|
||||||
|
|
||||||
fn start() {
|
fn start() {
|
||||||
loop {
|
loop {
|
||||||
alt self.from_client.recv() {
|
match self.from_client.recv() {
|
||||||
Load(url, progress_chan) => {
|
Load(url, progress_chan) => {
|
||||||
self.load(url, progress_chan)
|
self.load(url, progress_chan)
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ class ResourceManager {
|
||||||
|
|
||||||
fn load(url: url, progress_chan: chan<ProgressMsg>) {
|
fn load(url: url, progress_chan: chan<ProgressMsg>) {
|
||||||
|
|
||||||
alt self.get_loader_factory(url) {
|
match self.get_loader_factory(url) {
|
||||||
some(loader_factory) => {
|
some(loader_factory) => {
|
||||||
#debug("resource_task: loading url: %s", url::to_str(url));
|
#debug("resource_task: loading url: %s", url::to_str(url));
|
||||||
loader_factory(url, progress_chan);
|
loader_factory(url, progress_chan);
|
||||||
|
@ -115,7 +115,7 @@ fn test_bad_scheme() {
|
||||||
let resource_task = ResourceTask();
|
let resource_task = ResourceTask();
|
||||||
let progress = port();
|
let progress = port();
|
||||||
resource_task.send(Load(url::from_str(~"bogus://whatever").get(), progress.chan()));
|
resource_task.send(Load(url::from_str(~"bogus://whatever").get(), progress.chan()));
|
||||||
alt check progress.recv() {
|
match check progress.recv() {
|
||||||
Done(result) => { assert result.is_err() }
|
Done(result) => { assert result.is_err() }
|
||||||
}
|
}
|
||||||
resource_task.send(Exit);
|
resource_task.send(Exit);
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn main(args: ~[~str]) {
|
||||||
|
|
||||||
#[allow(non_implicitly_copyable_typarams)]
|
#[allow(non_implicitly_copyable_typarams)]
|
||||||
fn run(opts: Opts) {
|
fn run(opts: Opts) {
|
||||||
alt opts.render_mode {
|
match opts.render_mode {
|
||||||
Screen => run_pipeline_screen(opts.urls),
|
Screen => run_pipeline_screen(opts.urls),
|
||||||
Png(outfile) => {
|
Png(outfile) => {
|
||||||
assert opts.urls.is_not_empty();
|
assert opts.urls.is_not_empty();
|
||||||
|
@ -47,7 +47,7 @@ fn run_pipeline_screen(urls: ~[~str]) {
|
||||||
engine_chan.send(LoadURLMsg(url));
|
engine_chan.send(LoadURLMsg(url));
|
||||||
#debug["master: Waiting for keypress"];
|
#debug["master: Waiting for keypress"];
|
||||||
|
|
||||||
alt keypress_from_osmain.try_recv() {
|
match keypress_from_osmain.try_recv() {
|
||||||
some(*) => { }
|
some(*) => { }
|
||||||
none => { #error("keypress stream closed unexpectedly") }
|
none => { #error("keypress stream closed unexpectedly") }
|
||||||
};
|
};
|
||||||
|
@ -76,7 +76,7 @@ fn run_pipeline_png(-url: ~str, outfile: ~str) {
|
||||||
let engine_chan = engine.start();
|
let engine_chan = engine.start();
|
||||||
engine_chan.send(LoadURLMsg(make_url(url, none)));
|
engine_chan.send(LoadURLMsg(make_url(url, none)));
|
||||||
|
|
||||||
alt buffered_file_writer(outfile) {
|
match buffered_file_writer(outfile) {
|
||||||
ok(writer) => writer.write(pngdata_from_sink.recv()),
|
ok(writer) => writer.write(pngdata_from_sink.recv()),
|
||||||
err(e) => fail e
|
err(e) => fail e
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ class Font {
|
||||||
self.cairo_font, unsafe { vec_to_ptr(glyphs) },
|
self.cairo_font, unsafe { vec_to_ptr(glyphs) },
|
||||||
1 as c_int, addr_of(extents));
|
1 as c_int, addr_of(extents));
|
||||||
|
|
||||||
alt cairo_scaled_font_status(self.cairo_font) {
|
match cairo_scaled_font_status(self.cairo_font) {
|
||||||
status if status == CAIRO_STATUS_SUCCESS => {
|
status if status == CAIRO_STATUS_SUCCESS => {
|
||||||
|
|
||||||
#debug("x_advance: %?", extents.x_advance);
|
#debug("x_advance: %?", extents.x_advance);
|
||||||
|
|
|
@ -111,7 +111,7 @@ extern fn glyph_func(_font: *hb_font_t,
|
||||||
let font: *Font = reinterpret_cast(font_data);
|
let font: *Font = reinterpret_cast(font_data);
|
||||||
assert font.is_not_null();
|
assert font.is_not_null();
|
||||||
|
|
||||||
return alt (*font).glyph_idx(unicode as char) {
|
return match (*font).glyph_idx(unicode as char) {
|
||||||
some(g) => {
|
some(g) => {
|
||||||
*glyph = g as hb_codepoint_t;
|
*glyph = g as hb_codepoint_t;
|
||||||
true
|
true
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn hsla(h : float, s : float, l : float, a : float) -> Color {
|
||||||
fn hue_to_rgb(m1 : float, m2 : float, h : float) -> float {
|
fn hue_to_rgb(m1 : float, m2 : float, h : float) -> float {
|
||||||
let h = if h < 0.0 { h + 1.0 } else if h > 1.0 { h - 1.0 } else { h };
|
let h = if h < 0.0 { h + 1.0 } else if h > 1.0 { h - 1.0 } else { h };
|
||||||
|
|
||||||
alt h {
|
match h {
|
||||||
0.0 to 1.0/6.0 => m1 + (m2 - m1)*h*6.0,
|
0.0 to 1.0/6.0 => m1 + (m2 - m1)*h*6.0,
|
||||||
1.0/6.0 to 1.0/2.0 => m2,
|
1.0/6.0 to 1.0/2.0 => m2,
|
||||||
1.0/2.0 to 2.0/3.0 => m1 + (m2 - m1)*(4.0 - 6.0*h),
|
1.0/2.0 to 2.0/3.0 => m1 + (m2 - m1)*(4.0 - 6.0*h),
|
||||||
|
@ -73,7 +73,7 @@ mod parsing {
|
||||||
|
|
||||||
#[doc="Match an exact color keyword."]
|
#[doc="Match an exact color keyword."]
|
||||||
fn parse_by_name(color : ~str) -> option<Color> {
|
fn parse_by_name(color : ~str) -> option<Color> {
|
||||||
let col = alt color.to_lower() {
|
let col = match color.to_lower() {
|
||||||
~"black" => black(),
|
~"black" => black(),
|
||||||
~"silver" => silver(),
|
~"silver" => silver(),
|
||||||
~"gray" => gray(),
|
~"gray" => gray(),
|
||||||
|
@ -106,7 +106,7 @@ mod parsing {
|
||||||
let cols = only_colors.split_char(',');
|
let cols = only_colors.split_char(',');
|
||||||
if cols.len() != 3u { return fail_unrecognized(color); }
|
if cols.len() != 3u { return fail_unrecognized(color); }
|
||||||
|
|
||||||
alt (u8::from_str(cols[0]), u8::from_str(cols[1]),
|
match (u8::from_str(cols[0]), u8::from_str(cols[1]),
|
||||||
u8::from_str(cols[2])) {
|
u8::from_str(cols[2])) {
|
||||||
(some(r), some(g), some(b)) => { some(rgb(r, g, b)) }
|
(some(r), some(g), some(b)) => { some(rgb(r, g, b)) }
|
||||||
_ => { fail_unrecognized(color) }
|
_ => { fail_unrecognized(color) }
|
||||||
|
@ -122,7 +122,7 @@ mod parsing {
|
||||||
let cols = only_vals.split_char(',');
|
let cols = only_vals.split_char(',');
|
||||||
if cols.len() != 4u { return fail_unrecognized(color); }
|
if cols.len() != 4u { return fail_unrecognized(color); }
|
||||||
|
|
||||||
alt (u8::from_str(cols[0]), u8::from_str(cols[1]),
|
match (u8::from_str(cols[0]), u8::from_str(cols[1]),
|
||||||
u8::from_str(cols[2]), float::from_str(cols[3])) {
|
u8::from_str(cols[2]), float::from_str(cols[3])) {
|
||||||
(some(r), some(g), some(b), some(a)) => { some(rgba(r, g, b, a)) }
|
(some(r), some(g), some(b), some(a)) => { some(rgba(r, g, b, a)) }
|
||||||
_ => { fail_unrecognized(color) }
|
_ => { fail_unrecognized(color) }
|
||||||
|
@ -138,7 +138,7 @@ mod parsing {
|
||||||
let vals = only_vals.split_char(',');
|
let vals = only_vals.split_char(',');
|
||||||
if vals.len() != 3u { return fail_unrecognized(color); }
|
if vals.len() != 3u { return fail_unrecognized(color); }
|
||||||
|
|
||||||
alt (float::from_str(vals[0]), float::from_str(vals[1]),
|
match (float::from_str(vals[0]), float::from_str(vals[1]),
|
||||||
float::from_str(vals[2])) {
|
float::from_str(vals[2])) {
|
||||||
(some(h), some(s), some(l)) => { some(hsl(h, s, l)) }
|
(some(h), some(s), some(l)) => { some(hsl(h, s, l)) }
|
||||||
_ => { fail_unrecognized(color) }
|
_ => { fail_unrecognized(color) }
|
||||||
|
@ -153,7 +153,7 @@ mod parsing {
|
||||||
let vals = only_vals.split_char(',');
|
let vals = only_vals.split_char(',');
|
||||||
if vals.len() != 4u { return fail_unrecognized(color); }
|
if vals.len() != 4u { return fail_unrecognized(color); }
|
||||||
|
|
||||||
alt (float::from_str(vals[0]), float::from_str(vals[1]),
|
match (float::from_str(vals[0]), float::from_str(vals[1]),
|
||||||
float::from_str(vals[2]), float::from_str(vals[3])) {
|
float::from_str(vals[2]), float::from_str(vals[3])) {
|
||||||
(some(h), some(s), some(l), some(a)) => { some(hsla(h, s, l, a)) }
|
(some(h), some(s), some(l), some(a)) => { some(hsla(h, s, l, a)) }
|
||||||
_ => { fail_unrecognized(color) }
|
_ => { fail_unrecognized(color) }
|
||||||
|
@ -164,7 +164,7 @@ mod parsing {
|
||||||
// keywords for several common colors.
|
// keywords for several common colors.
|
||||||
// TODO: extend this
|
// TODO: extend this
|
||||||
fn parse_color(color : ~str) -> option<Color> {
|
fn parse_color(color : ~str) -> option<Color> {
|
||||||
alt color {
|
match color {
|
||||||
c if c.starts_with(~"rgb(") => parse_rgb(c),
|
c if c.starts_with(~"rgb(") => parse_rgb(c),
|
||||||
c if c.starts_with(~"rgba(") => parse_rgba(c),
|
c if c.starts_with(~"rgba(") => parse_rgba(c),
|
||||||
c if c.starts_with(~"hsl(") => parse_hsl(c),
|
c if c.starts_with(~"hsl(") => parse_hsl(c),
|
||||||
|
|
|
@ -21,7 +21,7 @@ trait WriteMethods<T> {
|
||||||
fn each_child<T:copy,O:ReadMethods<T>>(ops: O, node: T, f: fn(T) -> bool) {
|
fn each_child<T:copy,O:ReadMethods<T>>(ops: O, node: T, f: fn(T) -> bool) {
|
||||||
let mut p = ops.with_tree_fields(node, |f| f.first_child);
|
let mut p = ops.with_tree_fields(node, |f| f.first_child);
|
||||||
loop {
|
loop {
|
||||||
alt copy p {
|
match copy p {
|
||||||
none => { return; }
|
none => { return; }
|
||||||
some(c) => {
|
some(c) => {
|
||||||
if !f(c) { return; }
|
if !f(c) { return; }
|
||||||
|
@ -42,7 +42,7 @@ fn empty<T>() -> Tree<T> {
|
||||||
fn add_child<T:copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) {
|
fn add_child<T:copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) {
|
||||||
|
|
||||||
ops.with_tree_fields(child, |child_tf| {
|
ops.with_tree_fields(child, |child_tf| {
|
||||||
alt child_tf.parent {
|
match child_tf.parent {
|
||||||
some(_) => { fail ~"Already has a parent"; }
|
some(_) => { fail ~"Already has a parent"; }
|
||||||
none => { child_tf.parent = some(parent); }
|
none => { child_tf.parent = some(parent); }
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ fn add_child<T:copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) {
|
||||||
assert child_tf.next_sibling == none;
|
assert child_tf.next_sibling == none;
|
||||||
|
|
||||||
ops.with_tree_fields(parent, |parent_tf| {
|
ops.with_tree_fields(parent, |parent_tf| {
|
||||||
alt copy parent_tf.last_child {
|
match copy parent_tf.last_child {
|
||||||
none => {
|
none => {
|
||||||
parent_tf.first_child = some(child);
|
parent_tf.first_child = some(child);
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче