Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 5e8c30c

Browse files
committed
Update for language changes
1 parent 865f539 commit 5e8c30c

File tree

9 files changed

+63
-61
lines changed

9 files changed

+63
-61
lines changed

color.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use core::float::round;
6-
use core::libc::types::os::arch::c95::c_double;
7-
use core::cmp::Eq;
5+
use std::float::round;
6+
use std::libc::types::os::arch::c95::c_double;
7+
use std::cmp::Eq;
88

99
#[deriving(Eq)]
1010
pub struct Color {
@@ -32,12 +32,17 @@ pub fn hsla(h : float, s : float, l : float, a : float) -> Color {
3232
fn hue_to_rgb(m1 : float, m2 : float, h : float) -> float {
3333
let h = if h < 0.0 { h + 1.0 } else if h > 1.0 { h - 1.0 } else { h };
3434

35-
match h {
36-
0.0 .. 1.0/6.0 => m1 + (m2 - m1)*h*6.0,
37-
1.0/6.0 .. 1.0/2.0 => m2,
38-
1.0/2.0 .. 2.0/3.0 => m1 + (m2 - m1)*(4.0 - 6.0*h),
39-
2.0/3.0 .. 1.0 => return m1,
40-
_ => fail!(~"unexpected hue value")
35+
// FIXME (Rust #7222) - Auugh. Patterns would be much better here
36+
if 0.0 <= h && h < 1.0/6.0 {
37+
m1 + (m2 - m1)*h*6.0
38+
} else if 1.0/6.0 <= h && h < 1.0/2.0 {
39+
m2
40+
} else if 1.0/2.0 <= h && h < 2.0/3.0 {
41+
m1 + (m2 - m1)*(4.0 - 6.0*h)
42+
} else if 2.0/3.0 <= h && h <= 1.0 {
43+
m1
44+
} else {
45+
fail!(~"unexpected hue value")
4146
}
4247
}
4348
@@ -97,18 +102,18 @@ pub mod parsing {
97102
/** Parses a color specification in the form rgb(foo,bar,baz) */
98103
fn parse_rgb(color : &str) -> Option<Color> {
99104
// Shave off the rgb( and the )
100-
let only_colors = color.substr(4u, color.len() - 5u);
105+
let only_colors = color.slice(4u, color.len() - 1);
101106
102107
// split up r, g, and b
103108
let mut cols = ~[];
104-
for str::each_split_char(only_colors, ',') |s| {
109+
for only_colors.split_iter(',').advance |s| {
105110
cols.push(s);
106111
};
107112
108113
if cols.len() != 3u { return fail_unrecognized(color); }
109114
110-
match (u8::from_str(cols[0]), u8::from_str(cols[1]),
111-
u8::from_str(cols[2])) {
115+
match (FromStr::from_str(cols[0]), FromStr::from_str(cols[1]),
116+
FromStr::from_str(cols[2])) {
112117
(Some(r), Some(g), Some(b)) => { Some(rgb(r, g, b)) }
113118
_ => { fail_unrecognized(color) }
114119
}
@@ -117,18 +122,18 @@ pub mod parsing {
117122
/** Parses a color specification in the form rgba(foo,bar,baz,qux) */
118123
fn parse_rgba(color : &str) -> Option<Color> {
119124
// Shave off the rgba( and the )
120-
let only_vals = color.substr(5u, color.len() - 6u);
125+
let only_vals = color.slice(5u, color.len() - 1);
121126
122127
// split up r, g, and b
123128
let mut cols = ~[];
124-
for str::each_split_char(only_vals, ',') |s| {
129+
for only_vals.split_iter(',').advance |s| {
125130
cols.push(s);
126131
};
127132
128133
if cols.len() != 4u { return fail_unrecognized(color); }
129134
130-
match (u8::from_str(cols[0]), u8::from_str(cols[1]),
131-
u8::from_str(cols[2]), float::from_str(cols[3])) {
135+
match (FromStr::from_str(cols[0]), FromStr::from_str(cols[1]),
136+
FromStr::from_str(cols[2]), FromStr::from_str(cols[3])) {
132137
(Some(r), Some(g), Some(b), Some(a)) => { Some(rgba(r, g, b, a)) }
133138
_ => { fail_unrecognized(color) }
134139
}
@@ -137,18 +142,18 @@ pub mod parsing {
137142
/** Parses a color specification in the form hsl(foo,bar,baz) */
138143
fn parse_hsl(color : &str) -> Option<Color> {
139144
// Shave off the hsl( and the )
140-
let only_vals = color.substr(4u, color.len() - 5u);
145+
let only_vals = color.slice(4u, color.len() - 1);
141146
142147
// split up h, s, and l
143148
let mut vals = ~[];
144-
for str::each_split_char(only_vals, ',') |s| {
149+
for only_vals.split_iter(',').advance |s| {
145150
vals.push(s);
146151
};
147152
148153
if vals.len() != 3u { return fail_unrecognized(color); }
149154
150-
match (float::from_str(vals[0]), float::from_str(vals[1]),
151-
float::from_str(vals[2])) {
155+
match (FromStr::from_str(vals[0]), FromStr::from_str(vals[1]),
156+
FromStr::from_str(vals[2])) {
152157
(Some(h), Some(s), Some(l)) => { Some(hsl(h, s, l)) }
153158
_ => { fail_unrecognized(color) }
154159
}
@@ -157,17 +162,17 @@ pub mod parsing {
157162
/** Parses a color specification in the form hsla(foo,bar,baz,qux) */
158163
fn parse_hsla(color : &str) -> Option<Color> {
159164
// Shave off the hsla( and the )
160-
let only_vals = color.substr(5u, color.len() - 6u);
165+
let only_vals = color.slice(5u, color.len() - 1);
161166
162167
let mut vals = ~[];
163-
for str::each_split_char(only_vals, ',') |s| {
168+
for only_vals.split_iter(',').advance |s| {
164169
vals.push(s);
165170
};
166171
167172
if vals.len() != 4u { return fail_unrecognized(color); }
168173
169-
match (float::from_str(vals[0]), float::from_str(vals[1]),
170-
float::from_str(vals[2]), float::from_str(vals[3])) {
174+
match (FromStr::from_str(vals[0]), FromStr::from_str(vals[1]),
175+
FromStr::from_str(vals[2]), FromStr::from_str(vals[3])) {
171176
(Some(h), Some(s), Some(l), Some(a)) => { Some(hsla(h, s, l, a)) }
172177
_ => { fail_unrecognized(color) }
173178
}

complete.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
use std::cast;
56
use color::Color;
67
use select::SelectResults;
78
use computed::ComputedStyle;
@@ -14,15 +15,15 @@ pub struct CompleteSelectResults {
1415
inner: SelectResults
1516
}
1617

17-
pub impl<'self> CompleteSelectResults {
18-
fn new_root(root: SelectResults) -> CompleteSelectResults {
18+
impl<'self> CompleteSelectResults {
19+
pub fn new_root(root: SelectResults) -> CompleteSelectResults {
1920
CompleteSelectResults {
2021
inner: root
2122
}
2223
}
2324

24-
fn new_from_parent(parent: &CompleteSelectResults,
25-
child: SelectResults) -> CompleteSelectResults {
25+
pub fn new_from_parent(parent: &CompleteSelectResults,
26+
child: SelectResults) -> CompleteSelectResults {
2627
// New lifetime
2728
{
2829
let parent_computed = parent.computed_style();
@@ -65,7 +66,7 @@ pub impl<'self> CompleteSelectResults {
6566
}
6667
}
6768

68-
fn computed_style(&'self self) -> CompleteStyle<'self> {
69+
pub fn computed_style(&'self self) -> CompleteStyle<'self> {
6970
CompleteStyle {
7071
inner: self.inner.computed_style()
7172
}
@@ -132,10 +133,6 @@ impl<'self> CompleteStyle<'self> {
132133
strip(self.inner.border_top_color())
133134
}
134135

135-
pub fn border_top_color(&self) -> Color {
136-
strip(self.inner.border_top_color())
137-
}
138-
139136
pub fn border_right_color(&self) -> Color {
140137
strip(self.inner.border_right_color())
141138
}

computed.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
use color::{Color, rgba};
66
use units::{Length, Px, Em, Pt};
77
use netsurfcss::util::css_fixed_to_float;
8-
use core::either::{Either, Left, Right};
8+
use std::either::{Either, Left, Right};
99
use n;
1010
use values::*;
1111

1212
pub struct ComputedStyle<'self> {
1313
inner: n::c::CssComputedStyle<'self>
1414
}
1515

16-
pub impl<'self> ComputedStyle<'self> {
16+
impl<'self> ComputedStyle<'self> {
1717

1818
// CSS 2.1, Section 8 - Box model
1919

@@ -69,10 +69,6 @@ pub impl<'self> ComputedStyle<'self> {
6969
convert_net_color_value(self.inner.border_top_color())
7070
}
7171

72-
pub fn border_top_color(&self) -> CSSValue<Color> {
73-
convert_net_color_value(self.inner.border_top_color())
74-
}
75-
7672
pub fn border_right_color(&self) -> CSSValue<Color> {
7773
convert_net_color_value(self.inner.border_right_color())
7874
}

css.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Basic operation:
2121
vers = "0.1")];
2222
#[crate_type = "lib"];
2323

24-
extern mod std;
24+
extern mod extra;
2525
extern mod netsurfcss;
2626
extern mod wapcaplet;
2727

parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use netsurfcss::stylesheet::{CssStylesheet, CssStylesheetParams, CssStylesheetPa
1414
use netsurfcss::types::CssLevel21;
1515
use netsurfcss::CssResult;
1616
use wapcaplet::LwcString;
17-
use std::net::url::Url;
17+
use extra::net::url::Url;
1818
use netsurfcss::stylesheet::CssUrlResolutionFn;
1919

2020
// This takes a DataStreamFactory instead of a DataStream because

select.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ The `SelectCtx` takes ownership of any number of `Stylesheet` objects,
3030
encapsulates the cascade. Individual node styles can be requested with
3131
the `select_style` method.
3232
*/
33-
pub impl SelectCtx {
34-
fn new() -> SelectCtx {
33+
impl SelectCtx {
34+
pub fn new() -> SelectCtx {
3535
SelectCtx {
3636
inner: n::s::css_select_ctx_create()
3737
}
@@ -41,7 +41,7 @@ pub impl SelectCtx {
4141
Add `Stylesheet`s to the selection context, where they will participate in the cascade
4242
during future selector matching
4343
*/
44-
fn append_sheet(&mut self, sheet: Stylesheet, origin: StylesheetOrigin) {
44+
pub fn append_sheet(&mut self, sheet: Stylesheet, origin: StylesheetOrigin) {
4545
let sheet = match sheet {
4646
Stylesheet { inner: inner } => inner
4747
};
@@ -54,9 +54,9 @@ pub impl SelectCtx {
5454
a wide range of client-specific details like node relationships, names, and UA
5555
defaults.
5656
*/
57-
fn select_style<N: VoidPtrLike, H: SelectHandler<N>>(&self, node: &N, handler: &H) -> SelectResults {
57+
pub fn select_style<N: VoidPtrLike, H: SelectHandler<N>>(&self, node: &N, handler: &H) -> SelectResults {
5858
let inner_handler = SelectHandlerWrapper {
59-
inner: ptr::to_unsafe_ptr(handler)
59+
inner: handler
6060
};
6161
SelectResults {
6262
inner: self.inner.select_style::<N, SelectHandlerWrapper<N, H>>(node, n::ll::t::CSS_MEDIA_SCREEN, None, &inner_handler)
@@ -71,9 +71,9 @@ pub struct SelectResults {
7171
inner: n::s::CssSelectResults
7272
}
7373

74-
pub impl<'self> SelectResults {
74+
impl<'self> SelectResults {
7575
/** Retrieve the computed style of a single pseudo-element */
76-
fn computed_style(&'self self) -> ComputedStyle<'self> {
76+
pub fn computed_style(&'self self) -> ComputedStyle<'self> {
7777
ComputedStyle {
7878
inner: self.inner.computed_style(n::s::CssPseudoElementNone)
7979
}
@@ -102,7 +102,7 @@ struct SelectHandlerWrapper<N, H> {
102102
inner: *H
103103
}
104104

105-
priv impl<'self, N, H: SelectHandler<N>> SelectHandlerWrapper<N, H> {
105+
impl<'self, N, H: SelectHandler<N>> SelectHandlerWrapper<N, H> {
106106
priv fn inner_ref(&self) -> &'self H {
107107
unsafe { &*self.inner }
108108
}
@@ -120,7 +120,7 @@ impl<N, H: SelectHandler<N>> n::s::CssSelectHandler<N> for SelectHandlerWrapper<
120120
do node_classes_opt.map |s| {
121121
debug!("SelectHandlerWrapper::node_classes - classes: %?", *s);
122122
let mut v = ~[];
123-
for str::each_split_char(*s, ' ') |s| {
123+
for s.split_iter(' ').advance |s| {
124124
debug!("SelectHandlerWrapper::node_classes - class: %?", s);
125125
if s != ~"" { v.push(lwcstr_from_rust_str(s)) }
126126
}

stylesheet.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
CSS stylesheets, owned types, immutable after creation
77
*/
88

9-
use std::net::url::Url;
9+
use extra::net::url::Url;
1010
use util::DataStream;
1111
use netsurfcss::stylesheet::CssStylesheet;
1212
use parser::parse_stylesheet;
@@ -15,8 +15,8 @@ pub struct Stylesheet {
1515
inner: CssStylesheet
1616
}
1717

18-
pub impl Stylesheet {
19-
fn new(url: Url, input: DataStream) -> Stylesheet {
18+
impl Stylesheet {
19+
pub fn new(url: Url, input: DataStream) -> Stylesheet {
2020
Stylesheet {
2121
inner: parse_stylesheet(url, input)
2222
}

test.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use std::net::url::Url;
6-
use url_from_str = std::net::url::from_str;
7-
use core::cell::Cell;
5+
use extra::net::url::Url;
6+
use url_from_str = extra::net::url::from_str;
7+
use std::cast;
8+
use std::libc;
9+
use std::cell::Cell;
10+
use std::result;
811
use util::{DataStream, VoidPtrLike};
912
use values::*;
1013
use types::*;
@@ -21,10 +24,11 @@ fn test_url() -> Url {
2124
}
2225

2326
fn style_stream(style: &str) -> DataStream {
24-
let style = Cell(style.to_str());
27+
let style = Cell::new(style.to_str());
2528
let d: DataStream = || {
2629
if !style.is_empty() {
27-
Some(str::to_bytes(style.take()))
30+
let style = style.take();
31+
Some(style.as_bytes().to_owned())
2832
} else {
2933
None
3034
}

values.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ in the spec lead to the variant CSSBackgroundColorColor(Color).
1515
At least it's consistent though.
1616
*/
1717

18-
use core::cmp::Eq;
19-
use std::net::url::Url;
18+
use std::cmp::Eq;
19+
use extra::net::url::Url;
2020
use units::{Length, AbsoluteSize, RelativeSize};
2121
use units::GenericFontFamily;
2222
use color::Color;

0 commit comments

Comments
 (0)