mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Fix a bunch of clippy lints
This commit is contained in:
parent
b1ca3d1cdf
commit
6b215f38ee
58 changed files with 281 additions and 356 deletions
|
@ -512,14 +512,12 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
|
||||
(Msg::ScrollTimeout(timestamp), ShutdownState::NotShuttingDown) => {
|
||||
debug!("scroll timeout, drawing unpainted content!");
|
||||
match self.composition_request {
|
||||
CompositionRequest::CompositeOnScrollTimeout(this_timestamp) => {
|
||||
if timestamp == this_timestamp {
|
||||
self.composition_request = CompositionRequest::CompositeNow(
|
||||
CompositingReason::HitScrollTimeout)
|
||||
}
|
||||
if let CompositionRequest::CompositeOnScrollTimeout(this_timestamp) =
|
||||
self.composition_request {
|
||||
if timestamp == this_timestamp {
|
||||
self.composition_request = CompositionRequest::CompositeNow(
|
||||
CompositingReason::HitScrollTimeout)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -644,7 +642,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
if !self.pipeline_details.contains_key(&pipeline_id) {
|
||||
self.pipeline_details.insert(pipeline_id, PipelineDetails::new());
|
||||
}
|
||||
return self.pipeline_details.get_mut(&pipeline_id).unwrap();
|
||||
self.pipeline_details.get_mut(&pipeline_id).unwrap()
|
||||
}
|
||||
|
||||
pub fn pipeline(&self, pipeline_id: PipelineId) -> Option<&CompositionPipeline> {
|
||||
|
@ -730,7 +728,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
root_layer.bounds.borrow_mut().size = Size2D::from_untyped(&frame_size);
|
||||
}
|
||||
|
||||
return root_layer;
|
||||
root_layer
|
||||
}
|
||||
|
||||
fn create_pipeline_details_for_frame_tree(&mut self, frame_tree: &SendableFrameTree) {
|
||||
|
@ -1223,11 +1221,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
result.layer.send_event(self, TouchEvent(TouchEventType::Up, identifier,
|
||||
result.point.to_untyped()));
|
||||
}
|
||||
match self.touch_handler.on_touch_up(identifier, point) {
|
||||
TouchAction::Click => {
|
||||
self.simulate_mouse_click(point);
|
||||
}
|
||||
_ => {}
|
||||
if let TouchAction::Click = self.touch_handler.on_touch_up(identifier, point) {
|
||||
self.simulate_mouse_click(point);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1882,7 +1877,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||
return None;
|
||||
}
|
||||
|
||||
return Some(HitTestResult { layer: layer, point: point_in_parent_layer });
|
||||
Some(HitTestResult { layer: layer, point: point_in_parent_layer })
|
||||
}
|
||||
|
||||
fn find_topmost_layer_at_point(&self,
|
||||
|
@ -2001,7 +1996,7 @@ fn find_layer_with_pipeline_and_layer_id_for_layer(layer: Rc<Layer<CompositorDat
|
|||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
|
||||
impl<Window> CompositorEventListener for IOCompositor<Window> where Window: WindowMethods {
|
||||
|
|
|
@ -359,9 +359,9 @@ impl CompositorLayer for Layer<CompositorData> {
|
|||
}
|
||||
|
||||
if result {
|
||||
return ScrollEventResult::ScrollPositionChanged;
|
||||
ScrollEventResult::ScrollPositionChanged
|
||||
} else {
|
||||
return ScrollEventResult::ScrollPositionUnchanged;
|
||||
ScrollEventResult::ScrollPositionUnchanged
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -414,7 +414,7 @@ impl CompositorLayer for Layer<CompositorData> {
|
|||
result |= child.scroll_layer_and_all_child_layers(offset_for_children);
|
||||
}
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
fn wants_scroll_events(&self) -> WantsScrollEventsFlag {
|
||||
|
|
|
@ -155,14 +155,14 @@ impl TimerScheduler {
|
|||
|
||||
let ret = sel.wait();
|
||||
if ret == scheduler_handle.id() {
|
||||
port.recv().ok().map(|req| Task::HandleRequest(req))
|
||||
port.recv().ok().map(Task::HandleRequest)
|
||||
} else if ret == timer_handle.id() {
|
||||
timer_port.recv().ok().map(|_| Task::DispatchDueEvents)
|
||||
} else {
|
||||
panic!("unexpected select result!")
|
||||
}
|
||||
} else {
|
||||
port.recv().ok().map(|req| Task::HandleRequest(req))
|
||||
port.recv().ok().map(Task::HandleRequest)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,8 +172,7 @@ impl TimerScheduler {
|
|||
let schedule_for = precise_time_ns() + duration_ns;
|
||||
|
||||
let previously_earliest = self.scheduled_events.borrow().peek()
|
||||
.map(|scheduled| scheduled.for_time)
|
||||
.unwrap_or(Length::new(u64::max_value()));
|
||||
.map_or(Length::new(u64::max_value()), |scheduled| scheduled.for_time);
|
||||
|
||||
self.scheduled_events.borrow_mut().push(ScheduledEvent {
|
||||
request: request,
|
||||
|
|
|
@ -203,16 +203,15 @@ impl TouchHandler {
|
|||
}
|
||||
|
||||
pub fn on_event_processed(&mut self, result: EventResult) {
|
||||
match self.state {
|
||||
WaitingForScript => self.state = match result {
|
||||
if let WaitingForScript = self.state {
|
||||
self.state = match result {
|
||||
EventResult::DefaultPrevented => DefaultPrevented,
|
||||
EventResult::DefaultAllowed => match self.touch_count() {
|
||||
1 => Touching,
|
||||
2 => Pinching,
|
||||
_ => MultiTouch,
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -340,9 +340,8 @@ impl NetworkEventActor {
|
|||
// TODO: Send the correct values for all these fields.
|
||||
let hSizeOption = self.response.headers.as_ref().map(|headers| headers.len() as u32);
|
||||
let hSize = hSizeOption.unwrap_or(0);
|
||||
let (status_code, status_message) =
|
||||
self.response.status.as_ref().map(|&RawStatus(ref code, ref text)| (*code, text.clone().into_owned())).
|
||||
unwrap_or((0, "".to_owned()));
|
||||
let (status_code, status_message) = self.response.status.as_ref().
|
||||
map_or((0, "".to_owned()), |&RawStatus(ref code, ref text)| (*code, text.clone().into_owned()));
|
||||
// TODO: Send the correct values for remoteAddress and remotePort and http_version.
|
||||
ResponseStartMsg {
|
||||
httpVersion: "HTTP/1.1".to_owned(),
|
||||
|
|
|
@ -14,18 +14,18 @@ use std::io::{Read, Write};
|
|||
use std::net::TcpStream;
|
||||
|
||||
pub trait JsonPacketStream {
|
||||
fn write_json_packet<'a, T: Encodable>(&mut self, obj: &T);
|
||||
fn write_json_packet<T: Encodable>(&mut self, obj: &T);
|
||||
fn read_json_packet(&mut self) -> Result<Option<Json>, String>;
|
||||
}
|
||||
|
||||
impl JsonPacketStream for TcpStream {
|
||||
fn write_json_packet<'a, T: Encodable>(&mut self, obj: &T) {
|
||||
fn write_json_packet<T: Encodable>(&mut self, obj: &T) {
|
||||
let s = json::encode(obj).unwrap().replace("__type__", "type");
|
||||
println!("<- {}", s);
|
||||
write!(self, "{}:{}", s.len(), s).unwrap();
|
||||
}
|
||||
|
||||
fn read_json_packet<'a>(&mut self) -> Result<Option<Json>, String> {
|
||||
fn read_json_packet(&mut self) -> Result<Option<Json>, String> {
|
||||
// https://wiki.mozilla.org/Remote_Debugging_Protocol_Stream_Transport
|
||||
// In short, each JSON packet is [ascii length]:[JSON data of given length]
|
||||
let mut buffer = vec!();
|
||||
|
|
|
@ -941,7 +941,7 @@ impl StackingContextLayerCreator {
|
|||
return Some(LayerInfo::new(layer.id, ScrollPolicy::Scrollable, None));
|
||||
}
|
||||
|
||||
return self.last_child_layer_info;
|
||||
self.last_child_layer_info
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -39,7 +39,7 @@ impl FontTemplates {
|
|||
}
|
||||
|
||||
/// Find a font in this family that matches a given descriptor.
|
||||
fn find_font_for_style<'a>(&'a mut self, desc: &FontTemplateDescriptor, fctx: &FontContextHandle)
|
||||
fn find_font_for_style(&mut self, desc: &FontTemplateDescriptor, fctx: &FontContextHandle)
|
||||
-> Option<Arc<FontTemplateData>> {
|
||||
// TODO(Issue #189): optimize lookup for
|
||||
// regular/bold/italic/bolditalic with fixed offsets and a
|
||||
|
@ -251,7 +251,7 @@ impl FontCache {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_font_in_local_family<'a>(&'a mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
|
||||
fn find_font_in_local_family(&mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
|
||||
-> Option<Arc<FontTemplateData>> {
|
||||
// TODO(Issue #188): look up localized font family names if canonical name not found
|
||||
// look up canonical name
|
||||
|
@ -275,14 +275,13 @@ impl FontCache {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_font_in_web_family<'a>(&'a mut self, family: &FontFamily, desc: &FontTemplateDescriptor)
|
||||
fn find_font_in_web_family(&mut self, family: &FontFamily, desc: &FontTemplateDescriptor)
|
||||
-> Option<Arc<FontTemplateData>> {
|
||||
let family_name = LowercaseString::new(family.name());
|
||||
|
||||
if self.web_families.contains_key(&family_name) {
|
||||
let templates = self.web_families.get_mut(&family_name).unwrap();
|
||||
let maybe_font = templates.find_font_for_style(desc, &self.font_context);
|
||||
maybe_font
|
||||
templates.find_font_for_style(desc, &self.font_context)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -166,12 +166,12 @@ impl FontHandleMethods for FontHandle {
|
|||
assert!(!self.face.is_null());
|
||||
unsafe {
|
||||
let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong);
|
||||
return if idx != 0 as FT_UInt {
|
||||
if idx != 0 as FT_UInt {
|
||||
Some(idx as GlyphId)
|
||||
} else {
|
||||
debug!("Invalid codepoint: {}", codepoint);
|
||||
None
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,10 +196,10 @@ impl FontHandleMethods for FontHandle {
|
|||
let advance = (*slot).metrics.horiAdvance;
|
||||
debug!("h_advance for {} is {}", glyph, advance);
|
||||
let advance = advance as i32;
|
||||
return Some(fixed_to_float_ft(advance) as FractionalPixel);
|
||||
Some(fixed_to_float_ft(advance) as FractionalPixel)
|
||||
} else {
|
||||
debug!("Unable to load glyph {}. reason: {}", glyph, res);
|
||||
return None;
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -239,8 +239,7 @@ impl FontHandleMethods for FontHandle {
|
|||
|
||||
let average_advance = self.glyph_index('0')
|
||||
.and_then(|idx| self.glyph_h_advance(idx))
|
||||
.map(|advance| self.font_units_to_au(advance))
|
||||
.unwrap_or(max_advance);
|
||||
.map_or(max_advance, |advance| self.font_units_to_au(advance));
|
||||
|
||||
let metrics = FontMetrics {
|
||||
underline_size: underline_size,
|
||||
|
@ -258,7 +257,7 @@ impl FontHandleMethods for FontHandle {
|
|||
};
|
||||
|
||||
debug!("Font metrics (@{}px): {:?}", em_size.to_f32_px(), metrics);
|
||||
return metrics;
|
||||
metrics
|
||||
}
|
||||
|
||||
fn table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> {
|
||||
|
@ -310,6 +309,6 @@ impl<'a> FontHandle {
|
|||
// If this isn't true then we're scaling one of the axes wrong
|
||||
assert!(metrics.x_ppem == metrics.y_ppem);
|
||||
|
||||
return Au::from_f64_px(value * x_scale);
|
||||
Au::from_f64_px(value * x_scale)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1520,12 +1520,10 @@ impl BlockFlow {
|
|||
}
|
||||
|
||||
fn determine_if_layer_needed(&mut self) {
|
||||
if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) {
|
||||
// Fixed position layers get layers.
|
||||
if self.is_fixed() {
|
||||
self.base.flags.insert(NEEDS_LAYER);
|
||||
return
|
||||
}
|
||||
// Fixed position layers get layers.
|
||||
if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) && self.is_fixed() {
|
||||
self.base.flags.insert(NEEDS_LAYER);
|
||||
return
|
||||
}
|
||||
|
||||
// This flow needs a layer if it has a 3d transform, or provides perspective
|
||||
|
|
|
@ -1102,12 +1102,9 @@ impl<'a, 'ln, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<'ln>>
|
|||
node,
|
||||
caption_side::T::top);
|
||||
|
||||
match construction_result {
|
||||
ConstructionResult::Flow(table_flow, table_abs_descendants) => {
|
||||
wrapper_flow.add_new_child(table_flow);
|
||||
abs_descendants.push_descendants(table_abs_descendants);
|
||||
}
|
||||
_ => {}
|
||||
if let ConstructionResult::Flow(table_flow, table_abs_descendants) = construction_result {
|
||||
wrapper_flow.add_new_child(table_flow);
|
||||
abs_descendants.push_descendants(table_abs_descendants);
|
||||
}
|
||||
|
||||
// If the value of `caption-side` is `bottom`, place it now.
|
||||
|
@ -1271,12 +1268,9 @@ impl<'a, 'ln, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<'ln>>
|
|||
for kid in node.children() {
|
||||
// CSS 2.1 § 17.2.1. Treat all non-column child fragments of `table-column-group`
|
||||
// as `display: none`.
|
||||
match kid.swap_out_construction_result() {
|
||||
ConstructionResult::ConstructionItem(ConstructionItem::TableColumnFragment(
|
||||
fragment)) => {
|
||||
col_fragments.push(fragment);
|
||||
}
|
||||
_ => {}
|
||||
if let ConstructionResult::ConstructionItem(ConstructionItem::TableColumnFragment(fragment))
|
||||
= kid.swap_out_construction_result() {
|
||||
col_fragments.push(fragment)
|
||||
}
|
||||
}
|
||||
if col_fragments.is_empty() {
|
||||
|
|
|
@ -236,24 +236,20 @@ impl<'le, ConcreteElement> PrivateElementMatchMethods<'le, ConcreteElement>
|
|||
let parent_data: Option<&PrivateStyleData> = unsafe {
|
||||
parent_node.borrow_data_unchecked().map(|d| &*d)
|
||||
};
|
||||
match parent_data {
|
||||
Some(parent_data_ref) => {
|
||||
// Check parent style.
|
||||
let parent_style = (*parent_data_ref).style.as_ref().unwrap();
|
||||
if !arc_ptr_eq(parent_style, &candidate.parent_style) {
|
||||
return None
|
||||
}
|
||||
|
||||
// Check tag names, classes, etc.
|
||||
if !candidate.can_share_style_with(self) {
|
||||
return None
|
||||
}
|
||||
|
||||
return Some(candidate.style.clone())
|
||||
if let Some(parent_data_ref) = parent_data {
|
||||
// Check parent style.
|
||||
let parent_style = (*parent_data_ref).style.as_ref().unwrap();
|
||||
if !arc_ptr_eq(parent_style, &candidate.parent_style) {
|
||||
return None
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Check tag names, classes, etc.
|
||||
if !candidate.can_share_style_with(self) {
|
||||
return None
|
||||
}
|
||||
|
||||
return Some(candidate.style.clone())
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2006,24 +2006,18 @@ impl Fragment {
|
|||
}
|
||||
|
||||
pub fn update_late_computed_inline_position_if_necessary(&mut self) {
|
||||
match self.specific {
|
||||
SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut info) => {
|
||||
let position = self.border_box.start.i;
|
||||
flow_ref::deref_mut(&mut info.flow_ref)
|
||||
.update_late_computed_inline_position_if_necessary(position)
|
||||
}
|
||||
_ => {}
|
||||
if let SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut info) = self.specific {
|
||||
let position = self.border_box.start.i;
|
||||
flow_ref::deref_mut(&mut info.flow_ref)
|
||||
.update_late_computed_inline_position_if_necessary(position)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_late_computed_block_position_if_necessary(&mut self) {
|
||||
match self.specific {
|
||||
SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut info) => {
|
||||
let position = self.border_box.start.b;
|
||||
flow_ref::deref_mut(&mut info.flow_ref)
|
||||
.update_late_computed_block_position_if_necessary(position)
|
||||
}
|
||||
_ => {}
|
||||
if let SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut info) = self.specific {
|
||||
let position = self.border_box.start.b;
|
||||
flow_ref::deref_mut(&mut info.flow_ref)
|
||||
.update_late_computed_block_position_if_necessary(position)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -302,9 +302,9 @@ impl<'a,'b> ResolveGeneratedContentFragmentMutator<'a,'b> {
|
|||
"es.0[self.traversal.quote as usize]
|
||||
};
|
||||
if close {
|
||||
close_quote.to_string()
|
||||
close_quote.clone()
|
||||
} else {
|
||||
open_quote.to_string()
|
||||
open_quote.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -654,7 +654,7 @@ impl LayoutTask {
|
|||
// FIXME(njn): Just measuring the display tree for now.
|
||||
let rw_data = possibly_locked_rw_data.lock();
|
||||
let stacking_context = rw_data.stacking_context.as_ref();
|
||||
let ref formatted_url = format!("url({})", *self.url.borrow());
|
||||
let formatted_url = &format!("url({})", *self.url.borrow());
|
||||
reports.push(Report {
|
||||
path: path![formatted_url, "layout-task", "display-list"],
|
||||
kind: ReportKind::ExplicitJemallocHeapSize,
|
||||
|
@ -731,7 +731,7 @@ impl LayoutTask {
|
|||
|
||||
/// Shuts down the layout task now. If there are any DOM nodes left, layout will now (safely)
|
||||
/// crash.
|
||||
fn exit_now<'a, 'b>(&mut self) {
|
||||
fn exit_now(&mut self) {
|
||||
if let Some(ref mut traversal) = self.parallel_traversal {
|
||||
traversal.shutdown()
|
||||
}
|
||||
|
|
|
@ -480,7 +480,7 @@ pub fn process_resolved_style_request<'ln, N: LayoutNode<'ln>>(
|
|||
requested_node: N,
|
||||
property: &Atom) -> Option<String> {
|
||||
let maybe_data = layout_node.borrow_layout_data();
|
||||
let position = maybe_data.map(|data| {
|
||||
let position = maybe_data.map_or(Point2D::zero(), |data| {
|
||||
match (*data).flow_construction_result {
|
||||
ConstructionResult::Flow(ref flow_ref, _) =>
|
||||
flow::base(flow_ref.deref()).stacking_relative_position,
|
||||
|
@ -488,7 +488,7 @@ pub fn process_resolved_style_request<'ln, N: LayoutNode<'ln>>(
|
|||
// https://github.com/servo/servo/issues/8307
|
||||
_ => Point2D::zero()
|
||||
}
|
||||
}).unwrap_or(Point2D::zero());
|
||||
});
|
||||
let property = match *property {
|
||||
atom!("bottom") => PositionProperty::Bottom,
|
||||
atom!("top") => PositionProperty::Top,
|
||||
|
|
|
@ -747,33 +747,27 @@ fn set_inline_position_of_child_flow(
|
|||
inline_start_border: border_collapse_info.collapsed_borders_for_row
|
||||
.inline
|
||||
.get(child_index)
|
||||
.map(|x| *x)
|
||||
.unwrap_or(CollapsedBorder::new()),
|
||||
.map_or(CollapsedBorder::new(), |x| *x),
|
||||
inline_end_border: border_collapse_info.collapsed_borders_for_row
|
||||
.inline
|
||||
.get(child_index + 1)
|
||||
.map(|x| *x)
|
||||
.unwrap_or(CollapsedBorder::new()),
|
||||
.map_or(CollapsedBorder::new(), |x| *x),
|
||||
block_start_border: border_collapse_info.collapsed_borders_for_row
|
||||
.block_start
|
||||
.get(child_index)
|
||||
.map(|x| *x)
|
||||
.unwrap_or(CollapsedBorder::new()),
|
||||
.map_or(CollapsedBorder::new(), |x| *x),
|
||||
block_end_border: border_collapse_info.collapsed_borders_for_row
|
||||
.block_end
|
||||
.get(child_index)
|
||||
.map(|x| *x)
|
||||
.unwrap_or(CollapsedBorder::new()),
|
||||
.map_or(CollapsedBorder::new(), |x| *x),
|
||||
inline_start_width: border_collapse_info.collapsed_border_spacing_for_row
|
||||
.inline
|
||||
.get(child_index)
|
||||
.map(|x| *x)
|
||||
.unwrap_or(Au(0)),
|
||||
.map_or(Au(0), |x| *x),
|
||||
inline_end_width: border_collapse_info.collapsed_border_spacing_for_row
|
||||
.inline
|
||||
.get(child_index + 1)
|
||||
.map(|x| *x)
|
||||
.unwrap_or(Au(0)),
|
||||
.map_or(Au(0), |x| *x),
|
||||
block_start_width: border_collapse_info.collapsed_border_spacing_for_row
|
||||
.block_start,
|
||||
block_end_width: border_collapse_info.collapsed_border_spacing_for_row.block_end,
|
||||
|
|
|
@ -38,15 +38,12 @@ fn text(fragments: &LinkedList<Fragment>) -> String {
|
|||
let mut text = String::new();
|
||||
|
||||
for fragment in fragments {
|
||||
match fragment.specific {
|
||||
SpecificFragmentInfo::UnscannedText(ref info) => {
|
||||
if fragment.white_space().preserve_newlines() {
|
||||
text.push_str(&info.text);
|
||||
} else {
|
||||
text.push_str(&info.text.replace("\n", " "));
|
||||
}
|
||||
if let SpecificFragmentInfo::UnscannedText(ref info) = fragment.specific {
|
||||
if fragment.white_space().preserve_newlines() {
|
||||
text.push_str(&info.text);
|
||||
} else {
|
||||
text.push_str(&info.text.replace("\n", " "));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
text
|
||||
|
|
|
@ -198,7 +198,7 @@ impl<'ln> TNode<'ln> for ServoLayoutNode<'ln> {
|
|||
}
|
||||
|
||||
fn as_document(&self) -> Option<ServoLayoutDocument<'ln>> {
|
||||
self.node.downcast().map(|document| ServoLayoutDocument::from_layout_js(document))
|
||||
self.node.downcast().map(ServoLayoutDocument::from_layout_js)
|
||||
}
|
||||
|
||||
fn has_changed(&self) -> bool {
|
||||
|
@ -432,7 +432,7 @@ impl<'le> ServoLayoutElement<'le> {
|
|||
}
|
||||
|
||||
fn as_element<'le>(node: LayoutJS<Node>) -> Option<ServoLayoutElement<'le>> {
|
||||
node.downcast().map(|element| ServoLayoutElement::from_layout_js(element))
|
||||
node.downcast().map(ServoLayoutElement::from_layout_js)
|
||||
}
|
||||
|
||||
macro_rules! state_getter {
|
||||
|
|
|
@ -39,7 +39,7 @@ impl Cookie {
|
|||
_ => (false, None)
|
||||
};
|
||||
|
||||
let url_host = request.host().map(|host| host.serialize()).unwrap_or("".to_owned());
|
||||
let url_host = request.host().map_or("".to_owned(), |host| host.serialize());
|
||||
|
||||
// Step 4
|
||||
let mut domain = cookie.domain.clone().unwrap_or("".to_owned());
|
||||
|
|
|
@ -69,8 +69,8 @@ impl CookieStorage {
|
|||
}
|
||||
|
||||
pub fn cookie_comparator(a: &Cookie, b: &Cookie) -> Ordering {
|
||||
let a_path_len = a.cookie.path.as_ref().map(|p| p.len()).unwrap_or(0);
|
||||
let b_path_len = b.cookie.path.as_ref().map(|p| p.len()).unwrap_or(0);
|
||||
let a_path_len = a.cookie.path.as_ref().map_or(0, |p| p.len());
|
||||
let b_path_len = b.cookie.path.as_ref().map_or(0, |p| p.len());
|
||||
match a_path_len.cmp(&b_path_len) {
|
||||
Ordering::Equal => {
|
||||
let a_creation_time = a.creation_time.to_timespec();
|
||||
|
|
|
@ -178,7 +178,7 @@ pub trait HttpResponse: Read {
|
|||
fn status(&self) -> StatusCode;
|
||||
fn status_raw(&self) -> &RawStatus;
|
||||
fn http_version(&self) -> String {
|
||||
return "HTTP/1.1".to_owned()
|
||||
"HTTP/1.1".to_owned()
|
||||
}
|
||||
fn content_encoding(&self) -> Option<Encoding> {
|
||||
self.headers().get::<ContentEncoding>().and_then(|h| {
|
||||
|
@ -295,11 +295,8 @@ impl HttpRequest for WrappedHttpRequest {
|
|||
};
|
||||
|
||||
if let Some(ref data) = *body {
|
||||
match request_writer.write_all(&data) {
|
||||
Err(e) => {
|
||||
return Err(LoadError::Connection(url, e.description().to_owned()))
|
||||
}
|
||||
_ => {}
|
||||
if let Err(e) = request_writer.write_all(&data) {
|
||||
return Err(LoadError::Connection(url, e.description().to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,9 +61,9 @@ pub fn parse_hostsfile(hostsfile_content: &str) -> Box<HashMap<String, String>>
|
|||
|
||||
pub fn replace_hosts(url: &Url) -> Url {
|
||||
unsafe {
|
||||
HOST_TABLE.map(|host_table| {
|
||||
HOST_TABLE.map_or_else(|| url.clone(), |host_table| {
|
||||
host_replacement(host_table, url)
|
||||
}).unwrap_or_else(|| url.clone())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -649,8 +649,7 @@ mod system_reporter {
|
|||
// Note that the sum of all these segments' RSS values differs from the "resident"
|
||||
// measurement obtained via /proc/<pid>/statm in resident(). It's unclear why this
|
||||
// difference occurs; for some processes the measurements match, but for Servo they do not.
|
||||
let segs: Vec<(String, usize)> = seg_map.into_iter().collect();
|
||||
segs
|
||||
seg_map.into_iter().collect()
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
|
|
|
@ -172,9 +172,10 @@ impl Profiler {
|
|||
let mut start_energy = read_energy_uj();
|
||||
loop {
|
||||
for _ in 0..loop_count {
|
||||
match run_ap_thread() {
|
||||
true => thread::sleep(Duration::from_millis(SLEEP_MS as u64)),
|
||||
false => return,
|
||||
if run_ap_thread() {
|
||||
thread::sleep(Duration::from_millis(SLEEP_MS as u64))
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
let end_time = precise_time_ns();
|
||||
|
@ -258,7 +259,7 @@ impl Profiler {
|
|||
let data_len = data.len();
|
||||
if data_len > 0 {
|
||||
let (mean, median, min, max) =
|
||||
(data.iter().map(|&x|x).sum::<f64>() / (data_len as f64),
|
||||
(data.iter().sum::<f64>() / (data_len as f64),
|
||||
data[data_len / 2],
|
||||
data.iter().fold(f64::INFINITY, |a, &b| a.min(b)),
|
||||
data.iter().fold(-f64::INFINITY, |a, &b| a.max(b)));
|
||||
|
|
|
@ -92,10 +92,9 @@ impl CORSRequest {
|
|||
method: Method,
|
||||
headers: Headers)
|
||||
-> CORSRequest {
|
||||
match referer.scheme_data {
|
||||
SchemeData::Relative(ref mut data) => data.path = vec![],
|
||||
_ => {}
|
||||
};
|
||||
if let SchemeData::Relative(ref mut data) = referer.scheme_data {
|
||||
data.path = vec![];
|
||||
}
|
||||
referer.fragment = None;
|
||||
referer.query = None;
|
||||
CORSRequest {
|
||||
|
@ -167,12 +166,11 @@ impl CORSRequest {
|
|||
let cache = &mut CORSCache(vec!()); // XXXManishearth Should come from user agent
|
||||
if self.preflight_flag &&
|
||||
!cache.match_method(self, &self.method) &&
|
||||
!self.headers.iter().all(|h| is_simple_header(&h) && cache.match_header(self, h.name())) {
|
||||
if !is_simple_method(&self.method) || self.mode == RequestMode::ForcedPreflight {
|
||||
return self.preflight_fetch();
|
||||
// Everything after this is part of XHR::fetch()
|
||||
// Expect the organization of code to improve once we have a fetch crate
|
||||
}
|
||||
!self.headers.iter().all(|h| is_simple_header(&h) && cache.match_header(self, h.name())) &&
|
||||
(!is_simple_method(&self.method) || self.mode == RequestMode::ForcedPreflight) {
|
||||
return self.preflight_fetch();
|
||||
// Everything after this is part of XHR::fetch()
|
||||
// Expect the organization of code to improve once we have a fetch crate
|
||||
}
|
||||
response
|
||||
}
|
||||
|
@ -398,12 +396,11 @@ impl CORSCache {
|
|||
self.cleanup();
|
||||
let CORSCache(ref mut buf) = *self;
|
||||
// Credentials are not yet implemented here
|
||||
let entry = buf.iter_mut().find(|e| {
|
||||
buf.iter_mut().find(|e| {
|
||||
e.origin.scheme == request.origin.scheme && e.origin.host() == request.origin.host() &&
|
||||
e.origin.port() == request.origin.port() && e.url == request.destination &&
|
||||
e.header_or_method.match_header(header_name)
|
||||
});
|
||||
entry
|
||||
})
|
||||
}
|
||||
|
||||
fn match_header(&mut self, request: &CORSRequest, header_name: &str) -> bool {
|
||||
|
@ -426,12 +423,11 @@ impl CORSCache {
|
|||
self.cleanup();
|
||||
let CORSCache(ref mut buf) = *self;
|
||||
// Credentials are not yet implemented here
|
||||
let entry = buf.iter_mut().find(|e| {
|
||||
buf.iter_mut().find(|e| {
|
||||
e.origin.scheme == request.origin.scheme && e.origin.host() == request.origin.host() &&
|
||||
e.origin.port() == request.origin.port() && e.url == request.destination &&
|
||||
e.header_or_method.match_method(method)
|
||||
});
|
||||
entry
|
||||
})
|
||||
}
|
||||
|
||||
/// https://fetch.spec.whatwg.org/#concept-cache-match-method
|
||||
|
|
|
@ -191,7 +191,7 @@ impl Attr {
|
|||
/// Sets the owner element. Should be called after the attribute is added
|
||||
/// or removed from its older parent.
|
||||
pub fn set_owner(&self, owner: Option<&Element>) {
|
||||
let ref ns = self.identifier.namespace;
|
||||
let ns = &self.identifier.namespace;
|
||||
match (self.owner().r(), owner) {
|
||||
(None, Some(new)) => {
|
||||
// Already in the list of attributes of new owner.
|
||||
|
|
|
@ -486,7 +486,7 @@ impl RootCollection {
|
|||
}
|
||||
|
||||
/// Start tracking a stack-based root
|
||||
fn root<'b>(&self, untracked_reflector: *const Reflector) {
|
||||
fn root(&self, untracked_reflector: *const Reflector) {
|
||||
debug_assert!(task_state::get().is_script());
|
||||
unsafe {
|
||||
let mut roots = &mut *self.roots.get();
|
||||
|
@ -496,7 +496,7 @@ impl RootCollection {
|
|||
}
|
||||
|
||||
/// Stop tracking a stack-based root, asserting if the reflector isn't found
|
||||
fn unroot<'b, T: Reflectable>(&self, rooted: &Root<T>) {
|
||||
fn unroot<T: Reflectable>(&self, rooted: &Root<T>) {
|
||||
debug_assert!(task_state::get().is_script());
|
||||
unsafe {
|
||||
let mut roots = &mut *self.roots.get();
|
||||
|
|
|
@ -148,9 +148,10 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
return XMLName::InvalidXMLName;
|
||||
}
|
||||
if c == ':' {
|
||||
match seen_colon {
|
||||
true => non_qname_colons = true,
|
||||
false => seen_colon = true,
|
||||
if seen_colon {
|
||||
non_qname_colons = true;
|
||||
} else {
|
||||
seen_colon = true;
|
||||
}
|
||||
}
|
||||
last = c
|
||||
|
@ -160,9 +161,10 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
non_qname_colons = true
|
||||
}
|
||||
|
||||
match non_qname_colons {
|
||||
false => XMLName::QName,
|
||||
true => XMLName::Name,
|
||||
if non_qname_colons {
|
||||
XMLName::Name
|
||||
} else {
|
||||
XMLName::QName
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -320,10 +320,8 @@ impl CanvasRenderingContext2D {
|
|||
}
|
||||
};
|
||||
|
||||
if result.is_ok() {
|
||||
if !self.is_origin_clean(image) {
|
||||
self.set_origin_unclean()
|
||||
}
|
||||
if result.is_ok() && !self.is_origin_clean(image) {
|
||||
self.set_origin_unclean()
|
||||
}
|
||||
result
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
|||
}
|
||||
});
|
||||
|
||||
result.map(DOMString::from).unwrap_or(DOMString::new())
|
||||
result.map_or(DOMString::new(), DOMString::from)
|
||||
}
|
||||
|
||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
||||
|
@ -175,11 +175,10 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
|||
}
|
||||
|
||||
// Step 3 & 4
|
||||
let result = match owner.get_inline_style_declaration(&property) {
|
||||
match owner.get_inline_style_declaration(&property) {
|
||||
Some(declaration) => DOMString::from(declaration.value()),
|
||||
None => DOMString::new(),
|
||||
};
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority
|
||||
|
|
|
@ -1926,9 +1926,10 @@ impl DocumentMethods for Document {
|
|||
}
|
||||
|
||||
// Step 2.
|
||||
let clone_children = match deep {
|
||||
true => CloneChildrenFlag::CloneChildren,
|
||||
false => CloneChildrenFlag::DoNotCloneChildren,
|
||||
let clone_children = if deep {
|
||||
CloneChildrenFlag::CloneChildren
|
||||
} else {
|
||||
CloneChildrenFlag::DoNotCloneChildren
|
||||
};
|
||||
|
||||
Ok(Node::clone(node, Some(self), clone_children))
|
||||
|
@ -2325,7 +2326,7 @@ impl DocumentMethods for Document {
|
|||
let (tx, rx) = ipc::channel().unwrap();
|
||||
let _ = self.window.resource_task().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
|
||||
let cookies = rx.recv().unwrap();
|
||||
Ok(cookies.map(DOMString::from).unwrap_or(DOMString::from("")))
|
||||
Ok(cookies.map_or(DOMString::new(), DOMString::from))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
|
||||
|
|
|
@ -54,10 +54,10 @@ impl DOMTokenList {
|
|||
impl DOMTokenListMethods for DOMTokenList {
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-length
|
||||
fn Length(&self) -> u32 {
|
||||
self.attribute().map(|attr| {
|
||||
self.attribute().map_or(0, |attr| {
|
||||
let attr = attr.r();
|
||||
attr.value().as_tokens().len()
|
||||
}).unwrap_or(0) as u32
|
||||
}) as u32
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domtokenlist-item
|
||||
|
@ -71,13 +71,13 @@ impl DOMTokenListMethods for DOMTokenList {
|
|||
// https://dom.spec.whatwg.org/#dom-domtokenlist-contains
|
||||
fn Contains(&self, token: DOMString) -> Fallible<bool> {
|
||||
self.check_token_exceptions(&token).map(|token| {
|
||||
self.attribute().map(|attr| {
|
||||
self.attribute().map_or(false, |attr| {
|
||||
let attr = attr.r();
|
||||
attr.value()
|
||||
.as_tokens()
|
||||
.iter()
|
||||
.any(|atom: &Atom| *atom == token)
|
||||
}).unwrap_or(false)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -924,9 +924,8 @@ impl Element {
|
|||
// https://html.spec.whatwg.org/multipage/#attr-data-*
|
||||
pub fn set_custom_attribute(&self, name: DOMString, value: DOMString) -> ErrorResult {
|
||||
// Step 1.
|
||||
match xml_name_type(&name) {
|
||||
InvalidXMLName => return Err(Error::InvalidCharacter),
|
||||
_ => {}
|
||||
if let InvalidXMLName = xml_name_type(&name) {
|
||||
return Err(Error::InvalidCharacter);
|
||||
}
|
||||
|
||||
// Steps 2-5.
|
||||
|
@ -1012,8 +1011,7 @@ impl Element {
|
|||
}
|
||||
};
|
||||
self.get_attribute(&ns!(), &atom!("class"))
|
||||
.map(|attr| attr.value().as_tokens().iter().any(|atom| is_equal(name, atom)))
|
||||
.unwrap_or(false)
|
||||
.map_or(false, |attr| attr.value().as_tokens().iter().any(|atom| is_equal(name, atom)))
|
||||
}
|
||||
|
||||
pub fn set_atomic_attribute(&self, local_name: &Atom, value: DOMString) {
|
||||
|
@ -1884,10 +1882,11 @@ impl Element {
|
|||
}
|
||||
let node = self.upcast::<Node>();
|
||||
node.owner_doc().element_state_will_change(self);
|
||||
match value {
|
||||
true => state.insert(which),
|
||||
false => state.remove(which),
|
||||
};
|
||||
if value {
|
||||
state.insert(which);
|
||||
} else {
|
||||
state.remove(which);
|
||||
}
|
||||
self.state.set(state);
|
||||
}
|
||||
|
||||
|
|
|
@ -355,24 +355,21 @@ impl EventTargetMethods for EventTarget {
|
|||
ty: DOMString,
|
||||
listener: Option<Rc<EventListener>>,
|
||||
capture: bool) {
|
||||
match listener {
|
||||
Some(listener) => {
|
||||
let mut handlers = self.handlers.borrow_mut();
|
||||
let entry = match handlers.entry(Atom::from(&*ty)) {
|
||||
Occupied(entry) => entry.into_mut(),
|
||||
Vacant(entry) => entry.insert(vec!()),
|
||||
};
|
||||
if let Some(listener) = listener {
|
||||
let mut handlers = self.handlers.borrow_mut();
|
||||
let entry = match handlers.entry(Atom::from(&*ty)) {
|
||||
Occupied(entry) => entry.into_mut(),
|
||||
Vacant(entry) => entry.insert(vec!()),
|
||||
};
|
||||
|
||||
let phase = if capture { ListenerPhase::Capturing } else { ListenerPhase::Bubbling };
|
||||
let new_entry = EventListenerEntry {
|
||||
phase: phase,
|
||||
listener: EventListenerType::Additive(listener)
|
||||
};
|
||||
if !entry.contains(&new_entry) {
|
||||
entry.push(new_entry);
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
let phase = if capture { ListenerPhase::Capturing } else { ListenerPhase::Bubbling };
|
||||
let new_entry = EventListenerEntry {
|
||||
phase: phase,
|
||||
listener: EventListenerType::Additive(listener)
|
||||
};
|
||||
if !entry.contains(&new_entry) {
|
||||
entry.push(new_entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -381,22 +378,19 @@ impl EventTargetMethods for EventTarget {
|
|||
ty: DOMString,
|
||||
listener: Option<Rc<EventListener>>,
|
||||
capture: bool) {
|
||||
match listener {
|
||||
Some(ref listener) => {
|
||||
let mut handlers = self.handlers.borrow_mut();
|
||||
let entry = handlers.get_mut(&Atom::from(&*ty));
|
||||
for entry in entry {
|
||||
let phase = if capture { ListenerPhase::Capturing } else { ListenerPhase::Bubbling };
|
||||
let old_entry = EventListenerEntry {
|
||||
phase: phase,
|
||||
listener: EventListenerType::Additive(listener.clone())
|
||||
};
|
||||
if let Some(position) = entry.iter().position(|e| *e == old_entry) {
|
||||
entry.remove(position);
|
||||
}
|
||||
if let Some(ref listener) = listener {
|
||||
let mut handlers = self.handlers.borrow_mut();
|
||||
let entry = handlers.get_mut(&Atom::from(&*ty));
|
||||
for entry in entry {
|
||||
let phase = if capture { ListenerPhase::Capturing } else { ListenerPhase::Bubbling };
|
||||
let old_entry = EventListenerEntry {
|
||||
phase: phase,
|
||||
listener: EventListenerType::Additive(listener.clone())
|
||||
};
|
||||
if let Some(position) = entry.iter().position(|e| *e == old_entry) {
|
||||
entry.remove(position);
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -287,8 +287,8 @@ impl<'a> Iterator for HTMLCollectionElementsIter<'a> {
|
|||
type Item = Root<Element>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let ref filter = self.filter;
|
||||
let ref root = self.root;
|
||||
let filter = &self.filter;
|
||||
let root = &self.root;
|
||||
self.node_iter.by_ref()
|
||||
.filter_map(Root::downcast)
|
||||
.filter(|element| filter.filter(&element, root))
|
||||
|
@ -306,8 +306,8 @@ impl<'a> Iterator for HTMLCollectionElementsRevIter<'a> {
|
|||
type Item = Root<Element>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let ref filter = self.filter;
|
||||
let ref root = self.root;
|
||||
let filter = &self.filter;
|
||||
let root = &self.root;
|
||||
self.node_iter.by_ref()
|
||||
.filter_map(Root::downcast)
|
||||
.filter(|element| filter.filter(&element, root))
|
||||
|
|
|
@ -307,40 +307,37 @@ impl HTMLFormElement {
|
|||
.any(|a| Root::downcast::<HTMLDataListElement>(a).is_some()) {
|
||||
continue;
|
||||
}
|
||||
match child.type_id() {
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(element)) => {
|
||||
match element {
|
||||
HTMLElementTypeId::HTMLInputElement => {
|
||||
let input = child.downcast::<HTMLInputElement>().unwrap();
|
||||
// Step 3.2-3.7
|
||||
if let Some(datum) = input.get_form_datum(submitter) {
|
||||
data_set.push(datum);
|
||||
}
|
||||
if let NodeTypeId::Element(ElementTypeId::HTMLElement(element)) = child.type_id() {
|
||||
match element {
|
||||
HTMLElementTypeId::HTMLInputElement => {
|
||||
let input = child.downcast::<HTMLInputElement>().unwrap();
|
||||
// Step 3.2-3.7
|
||||
if let Some(datum) = input.get_form_datum(submitter) {
|
||||
data_set.push(datum);
|
||||
}
|
||||
HTMLElementTypeId::HTMLButtonElement |
|
||||
HTMLElementTypeId::HTMLObjectElement => {
|
||||
// Unimplemented
|
||||
()
|
||||
}
|
||||
HTMLElementTypeId::HTMLSelectElement => {
|
||||
let select = child.downcast::<HTMLSelectElement>().unwrap();
|
||||
select.push_form_data(&mut data_set);
|
||||
}
|
||||
HTMLElementTypeId::HTMLTextAreaElement => {
|
||||
let textarea = child.downcast::<HTMLTextAreaElement>().unwrap();
|
||||
let name = textarea.Name();
|
||||
if !name.is_empty() {
|
||||
data_set.push(FormDatum {
|
||||
ty: textarea.Type(),
|
||||
name: name,
|
||||
value: textarea.Value()
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
HTMLElementTypeId::HTMLButtonElement |
|
||||
HTMLElementTypeId::HTMLObjectElement => {
|
||||
// Unimplemented
|
||||
()
|
||||
}
|
||||
HTMLElementTypeId::HTMLSelectElement => {
|
||||
let select = child.downcast::<HTMLSelectElement>().unwrap();
|
||||
select.push_form_data(&mut data_set);
|
||||
}
|
||||
HTMLElementTypeId::HTMLTextAreaElement => {
|
||||
let textarea = child.downcast::<HTMLTextAreaElement>().unwrap();
|
||||
let name = textarea.Name();
|
||||
if !name.is_empty() {
|
||||
data_set.push(FormDatum {
|
||||
ty: textarea.Type(),
|
||||
name: name,
|
||||
value: textarea.Value()
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
data_set
|
||||
|
@ -603,14 +600,11 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable {
|
|||
if !owner.is_empty() {
|
||||
let doc = document_from_node(elem);
|
||||
let owner = doc.GetElementById(owner);
|
||||
match owner {
|
||||
Some(ref o) => {
|
||||
let maybe_form = o.downcast::<HTMLFormElement>();
|
||||
if maybe_form.is_some() {
|
||||
return maybe_form.map(Root::from_ref);
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
if let Some(ref o) = owner {
|
||||
let maybe_form = o.downcast::<HTMLFormElement>();
|
||||
if maybe_form.is_some() {
|
||||
return maybe_form.map(Root::from_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
elem.upcast::<Node>().ancestors().filter_map(Root::downcast).next()
|
||||
|
|
|
@ -596,7 +596,7 @@ impl VirtualMethods for HTMLInputElement {
|
|||
&atom!("value") if !self.value_changed.get() => {
|
||||
let value = mutation.new_value(attr).map(|value| (**value).to_owned());
|
||||
self.textinput.borrow_mut().set_content(
|
||||
value.map(DOMString::from).unwrap_or(DOMString::from("")));
|
||||
value.map_or(DOMString::new(), DOMString::from));
|
||||
},
|
||||
&atom!("name") if self.input_type.get() == InputType::InputRadio => {
|
||||
self.radio_group_updated(
|
||||
|
@ -663,9 +663,8 @@ impl VirtualMethods for HTMLInputElement {
|
|||
}
|
||||
|
||||
if event.type_() == atom!("click") && !event.DefaultPrevented() {
|
||||
match self.input_type.get() {
|
||||
InputType::InputRadio => self.update_checked_state(true, true),
|
||||
_ => {}
|
||||
if let InputType::InputRadio = self.input_type.get() {
|
||||
self.update_checked_state(true, true);
|
||||
}
|
||||
|
||||
// TODO: Dispatch events for non activatable inputs
|
||||
|
|
|
@ -49,7 +49,7 @@ impl Activatable for HTMLLabelElement {
|
|||
}
|
||||
|
||||
fn is_instance_activatable(&self) -> bool {
|
||||
return true;
|
||||
true
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#run-pre-click-activation-steps
|
||||
|
|
|
@ -53,9 +53,8 @@ impl HTMLMetaElement {
|
|||
let name = name.value().to_ascii_lowercase();
|
||||
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
|
||||
|
||||
match name {
|
||||
"viewport" => self.apply_viewport(),
|
||||
_ => {}
|
||||
if name == "viewport" {
|
||||
self.apply_viewport();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ impl HTMLScriptElement {
|
|||
}));
|
||||
|
||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||
let listener = box NetworkListener {
|
||||
let listener = NetworkListener {
|
||||
context: context,
|
||||
script_chan: script_chan,
|
||||
};
|
||||
|
@ -354,7 +354,7 @@ impl HTMLScriptElement {
|
|||
parser.r().suspend();
|
||||
}
|
||||
}
|
||||
return NextParserState::Suspend;
|
||||
NextParserState::Suspend
|
||||
}
|
||||
|
||||
pub fn is_ready_to_be_executed(&self) -> bool {
|
||||
|
|
|
@ -72,7 +72,7 @@ impl HTMLTableCellElementMethods for HTMLTableCellElement {
|
|||
|
||||
parent_children.filter(|c| c.is::<HTMLTableCellElement>())
|
||||
.position(|c| c.r() == self_node)
|
||||
.map(|p| p as i32).unwrap_or(-1)
|
||||
.map_or(-1, |p| p as i32)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,8 +73,7 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> {
|
|||
unsafe {
|
||||
(*self.upcast::<Element>().unsafe_get())
|
||||
.get_attr_for_layout(&ns!(), &atom!("cols"))
|
||||
.map(AttrValue::as_uint)
|
||||
.unwrap_or(DEFAULT_COLS)
|
||||
.map_or(DEFAULT_COLS, AttrValue::as_uint)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,8 +82,7 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> {
|
|||
unsafe {
|
||||
(*self.upcast::<Element>().unsafe_get())
|
||||
.get_attr_for_layout(&ns!(), &atom!("rows"))
|
||||
.map(AttrValue::as_uint)
|
||||
.unwrap_or(DEFAULT_ROWS)
|
||||
.map_or(DEFAULT_ROWS, AttrValue::as_uint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -768,7 +768,7 @@ impl Node {
|
|||
NodeInfo {
|
||||
uniqueId: self.get_unique_id(),
|
||||
baseURI: String::from(self.BaseURI()),
|
||||
parent: self.GetParentNode().map(|node| node.get_unique_id()).unwrap_or("".to_owned()),
|
||||
parent: self.GetParentNode().map_or("".to_owned(), |node| node.get_unique_id()),
|
||||
nodeType: self.NodeType(),
|
||||
namespaceURI: String::new(), //FIXME
|
||||
nodeName: String::from(self.NodeName()),
|
||||
|
@ -783,8 +783,7 @@ impl Node {
|
|||
isDocumentElement:
|
||||
self.owner_doc()
|
||||
.GetDocumentElement()
|
||||
.map(|elem| elem.upcast::<Node>() == self)
|
||||
.unwrap_or(false),
|
||||
.map_or(false, |elem| elem.upcast::<Node>() == self),
|
||||
|
||||
shortValue: self.GetNodeValue().map(String::from).unwrap_or_default(), //FIXME: truncate
|
||||
incompleteValue: false, //FIXME: reflect truncation
|
||||
|
@ -1602,9 +1601,10 @@ impl Node {
|
|||
},
|
||||
NodeTypeId::Document(_) => {
|
||||
let document = node.downcast::<Document>().unwrap();
|
||||
let is_html_doc = match document.is_html_document() {
|
||||
true => IsHTMLDocument::HTMLDocument,
|
||||
false => IsHTMLDocument::NonHTMLDocument,
|
||||
let is_html_doc = if document.is_html_document() {
|
||||
IsHTMLDocument::HTMLDocument
|
||||
} else {
|
||||
IsHTMLDocument::NonHTMLDocument
|
||||
};
|
||||
let window = document.window();
|
||||
let loader = DocumentLoader::new(&*document.loader());
|
||||
|
@ -2435,8 +2435,7 @@ impl<'a> UnbindContext<'a> {
|
|||
if let Some(index) = self.index.get() {
|
||||
return index;
|
||||
}
|
||||
let index =
|
||||
self.prev_sibling.map(|sibling| sibling.index() + 1).unwrap_or(0);
|
||||
let index = self.prev_sibling.map_or(0, |sibling| sibling.index() + 1);
|
||||
self.index.set(Some(index));
|
||||
index
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ pub fn load_script(head: &HTMLHeadElement) {
|
|||
PathBuf::from(path_str)
|
||||
};
|
||||
|
||||
let mut files = read_dir(&path).ok().expect("Bad path passed to --userscripts")
|
||||
let mut files = read_dir(&path).expect("Bad path passed to --userscripts")
|
||||
.filter_map(|e| e.ok())
|
||||
.map(|e| e.path()).collect::<Vec<_>>();
|
||||
|
||||
|
|
|
@ -323,7 +323,7 @@ impl Window {
|
|||
}
|
||||
|
||||
pub fn css_error_reporter(&self) -> Box<ParseErrorReporter + Send> {
|
||||
return self.error_reporter.clone();
|
||||
self.error_reporter.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -782,9 +782,7 @@ impl WindowMethods for Window {
|
|||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-window-devicepixelratio
|
||||
fn DevicePixelRatio(&self) -> Finite<f64> {
|
||||
let dpr = self.window_size.get()
|
||||
.map(|data| data.device_pixel_ratio.get())
|
||||
.unwrap_or(1.0f32);
|
||||
let dpr = self.window_size.get().map_or(1.0f32, |data| data.device_pixel_ratio.get());
|
||||
Finite::wrap(dpr as f64)
|
||||
}
|
||||
}
|
||||
|
@ -904,10 +902,10 @@ impl Window {
|
|||
let point = Point2D::new(x, y);
|
||||
let smooth = match behavior {
|
||||
ScrollBehavior::Auto => {
|
||||
element.map(|_element| {
|
||||
element.map_or(false, |_element| {
|
||||
// TODO check computed scroll-behaviour CSS property
|
||||
true
|
||||
}).unwrap_or(false)
|
||||
})
|
||||
}
|
||||
ScrollBehavior::Instant => false,
|
||||
ScrollBehavior::Smooth => true
|
||||
|
|
|
@ -271,7 +271,7 @@ impl XMLHttpRequest {
|
|||
}
|
||||
|
||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||
let listener = box NetworkListener {
|
||||
let listener = NetworkListener {
|
||||
context: context,
|
||||
script_chan: script_chan,
|
||||
};
|
||||
|
@ -483,7 +483,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
_ => data
|
||||
};
|
||||
let extracted = data.as_ref().map(|d| d.extract());
|
||||
self.request_body_len.set(extracted.as_ref().map(|e| e.len()).unwrap_or(0));
|
||||
self.request_body_len.set(extracted.as_ref().map_or(0, |e| e.len()));
|
||||
|
||||
// Step 6
|
||||
self.upload_events.set(false);
|
||||
|
@ -1120,13 +1120,12 @@ impl XMLHttpRequest {
|
|||
let content_type = mime_type.map(|mime|{
|
||||
DOMString::from(format!("{}", mime))
|
||||
});
|
||||
let document = Document::new(win,
|
||||
parsed_url,
|
||||
is_html_document,
|
||||
content_type,
|
||||
None,
|
||||
DocumentSource::FromParser, docloader);
|
||||
document
|
||||
Document::new(win,
|
||||
parsed_url,
|
||||
is_html_document,
|
||||
content_type,
|
||||
None,
|
||||
DocumentSource::FromParser, docloader)
|
||||
}
|
||||
|
||||
fn filter_response_headers(&self) -> Headers {
|
||||
|
|
|
@ -130,7 +130,7 @@ fn perform_platform_specific_initialization() {
|
|||
}
|
||||
}
|
||||
};
|
||||
match libc::setrlimit(libc::RLIMIT_NOFILE, &mut rlim) {
|
||||
match libc::setrlimit(libc::RLIMIT_NOFILE, &rlim) {
|
||||
0 => (),
|
||||
_ => warn!("Failed to set file count limit"),
|
||||
};
|
||||
|
|
|
@ -22,10 +22,9 @@ impl ParseErrorReporter for CSSErrorReporter {
|
|||
}
|
||||
|
||||
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
|
||||
let error_reporter = box CSSErrorReporter { pipelineid: self.pipelineid, } ;
|
||||
return error_reporter;
|
||||
box CSSErrorReporter { pipelineid: self.pipelineid, }
|
||||
}
|
||||
fn pipeline(&self) -> PipelineId {
|
||||
return self.pipelineid;
|
||||
self.pipelineid
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1948,13 +1948,11 @@ impl ScriptTask {
|
|||
|
||||
// Notify Constellation about anchors that are no longer mouse over targets.
|
||||
for target in &*prev_mouse_over_targets {
|
||||
if !mouse_over_targets.contains(target) {
|
||||
if target.is::<HTMLAnchorElement>() {
|
||||
let event = ConstellationMsg::NodeStatus(None);
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(event).unwrap();
|
||||
break;
|
||||
}
|
||||
if !mouse_over_targets.contains(target) && target.is::<HTMLAnchorElement>() {
|
||||
let event = ConstellationMsg::NodeStatus(None);
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(event).unwrap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2108,7 +2106,7 @@ impl ScriptTask {
|
|||
let context = Arc::new(Mutex::new(ParserContext::new(id, subpage, script_chan.clone(),
|
||||
load_data.url.clone())));
|
||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||
let listener = box NetworkListener {
|
||||
let listener = NetworkListener {
|
||||
context: context,
|
||||
script_chan: script_chan.clone(),
|
||||
};
|
||||
|
|
|
@ -191,7 +191,7 @@ pub fn handle_get_text(page: &Rc<Page>,
|
|||
reply: IpcSender<Result<String, ()>>) {
|
||||
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||
Some(ref node) => {
|
||||
Ok(node.GetTextContent().map(String::from).unwrap_or("".to_owned()))
|
||||
Ok(node.GetTextContent().map_or("".to_owned(), String::from))
|
||||
},
|
||||
None => Err(())
|
||||
}).unwrap();
|
||||
|
|
|
@ -112,27 +112,27 @@ impl<'a, E> Element for ElementWrapper<'a, E> where E: Element {
|
|||
state_pseudo_classes!(snapshot_state_accessors);
|
||||
|
||||
fn parent_element(&self) -> Option<Self> {
|
||||
self.element.parent_element().map(|el| ElementWrapper::new(el))
|
||||
self.element.parent_element().map(ElementWrapper::new)
|
||||
}
|
||||
fn first_child_element(&self) -> Option<Self> {
|
||||
self.element.first_child_element().map(|el| ElementWrapper::new(el))
|
||||
self.element.first_child_element().map(ElementWrapper::new)
|
||||
}
|
||||
fn last_child_element(&self) -> Option<Self> {
|
||||
self.element.last_child_element().map(|el| ElementWrapper::new(el))
|
||||
self.element.last_child_element().map(ElementWrapper::new)
|
||||
}
|
||||
fn prev_sibling_element(&self) -> Option<Self> {
|
||||
self.element.prev_sibling_element().map(|el| ElementWrapper::new(el))
|
||||
self.element.prev_sibling_element().map(ElementWrapper::new)
|
||||
}
|
||||
fn next_sibling_element(&self) -> Option<Self> {
|
||||
self.element.next_sibling_element().map(|el| ElementWrapper::new(el))
|
||||
self.element.next_sibling_element().map(ElementWrapper::new)
|
||||
}
|
||||
fn is_html_element_in_html_document(&self) -> bool {
|
||||
self.element.is_html_element_in_html_document()
|
||||
}
|
||||
fn get_local_name<'b>(&'b self) -> &'b Atom {
|
||||
fn get_local_name(&self) -> &Atom {
|
||||
self.element.get_local_name()
|
||||
}
|
||||
fn get_namespace<'b>(&'b self) -> &'b Namespace {
|
||||
fn get_namespace<'b>(&self) -> &Namespace {
|
||||
self.element.get_namespace()
|
||||
}
|
||||
fn get_id(&self) -> Option<Atom> {
|
||||
|
|
|
@ -47,7 +47,7 @@ impl ParseErrorReporter for StdoutErrorReporter {
|
|||
}
|
||||
|
||||
fn pipeline(&self) -> PipelineId {
|
||||
return PipelineId::fake_root_pipeline_id();
|
||||
PipelineId::fake_root_pipeline_id()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ pub struct Stylist {
|
|||
impl Stylist {
|
||||
#[inline]
|
||||
pub fn new(device: Device) -> Stylist {
|
||||
let stylist = Stylist {
|
||||
Stylist {
|
||||
viewport_constraints: None,
|
||||
device: device,
|
||||
is_device_dirty: true,
|
||||
|
@ -140,9 +140,8 @@ impl Stylist {
|
|||
after_map: PerPseudoElementSelectorMap::new(),
|
||||
rules_source_order: 0,
|
||||
state_deps: DependencySet::new(),
|
||||
};
|
||||
}
|
||||
// FIXME: Add iso-8859-9.css when the document’s encoding is ISO-8859-8.
|
||||
stylist
|
||||
}
|
||||
|
||||
pub fn update(&mut self, doc_stylesheets: &[Arc<Stylesheet>],
|
||||
|
|
|
@ -201,19 +201,16 @@ impl<'a> Iterator for Rules<'a> {
|
|||
let top = self.stack.len() - 1;
|
||||
while let Some(rule) = self.stack[top].next() {
|
||||
// handle conditional group rules
|
||||
match rule {
|
||||
&CSSRule::Media(ref rule) => {
|
||||
if let Some(device) = self.device {
|
||||
if rule.evaluate(device) {
|
||||
self.stack.push(rule.rules.iter());
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if let &CSSRule::Media(ref rule) = rule {
|
||||
if let Some(device) = self.device {
|
||||
if rule.evaluate(device) {
|
||||
self.stack.push(rule.rules.iter());
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
self.stack.push(rule.rules.iter());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
return Some(rule)
|
||||
|
|
|
@ -581,11 +581,10 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
|
|||
let is_running_problem_test =
|
||||
url_opt
|
||||
.as_ref()
|
||||
.map(|url|
|
||||
.map_or(false, |url|
|
||||
url.starts_with("http://web-platform.test:8000/2dcontext/drawing-images-to-the-canvas/") ||
|
||||
url.starts_with("http://web-platform.test:8000/_mozilla/mozilla/canvas/") ||
|
||||
url.starts_with("http://web-platform.test:8000/_mozilla/css/canvas_over_area.html"))
|
||||
.unwrap_or(false);
|
||||
url.starts_with("http://web-platform.test:8000/_mozilla/css/canvas_over_area.html"));
|
||||
|
||||
let url = match url_opt {
|
||||
Some(url_string) => {
|
||||
|
|
|
@ -146,7 +146,7 @@ fn read_prefs() -> Result<HashMap<String, Pref>, ()> {
|
|||
}
|
||||
|
||||
pub fn get_pref(name: &str) -> Arc<PrefValue> {
|
||||
PREFS.lock().unwrap().get(name).map(|x| x.value().clone()).unwrap_or(Arc::new(PrefValue::Missing))
|
||||
PREFS.lock().unwrap().get(name).map_or(Arc::new(PrefValue::Missing), |x| x.value().clone())
|
||||
}
|
||||
|
||||
pub fn set_pref(name: &str, value: PrefValue) {
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn resources_dir_path() -> PathBuf {
|
|||
// FIXME: Find a way to not rely on the executable being
|
||||
// under `<servo source>[/$target_triple]/target/debug`
|
||||
// or `<servo source>[/$target_triple]/target/release`.
|
||||
let mut path = env::current_exe().ok().expect("can't get exe path");
|
||||
let mut path = env::current_exe().expect("can't get exe path");
|
||||
path.pop();
|
||||
path.push("resources");
|
||||
if !path.is_dir() { // resources dir not in same dir as exe?
|
||||
|
|
|
@ -461,19 +461,17 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
|||
|
||||
// Step 6.
|
||||
if input.len() == 4 {
|
||||
match (input.as_bytes()[0],
|
||||
hex(input.as_bytes()[1] as char),
|
||||
hex(input.as_bytes()[2] as char),
|
||||
hex(input.as_bytes()[3] as char)) {
|
||||
(b'#', Ok(r), Ok(g), Ok(b)) => {
|
||||
return Ok(RGBA {
|
||||
red: (r as f32) * 17.0 / 255.0,
|
||||
green: (g as f32) * 17.0 / 255.0,
|
||||
blue: (b as f32) * 17.0 / 255.0,
|
||||
alpha: 1.0,
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
if let (b'#', Ok(r), Ok(g), Ok(b)) =
|
||||
(input.as_bytes()[0],
|
||||
hex(input.as_bytes()[1] as char),
|
||||
hex(input.as_bytes()[2] as char),
|
||||
hex(input.as_bytes()[3] as char)) {
|
||||
return Ok(RGBA {
|
||||
red: (r as f32) * 17.0 / 255.0,
|
||||
green: (g as f32) * 17.0 / 255.0,
|
||||
blue: (b as f32) * 17.0 / 255.0,
|
||||
alpha: 1.0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue