Skip to content

Instantly share code, notes, and snippets.

Created November 6, 2015 16:51
Show Gist options
  • Save anonymous/b0fed0d6d8c9122744d8 to your computer and use it in GitHub Desktop.
Save anonymous/b0fed0d6d8c9122744d8 to your computer and use it in GitHub Desktop.
Changes to window.rs
use style_traits::ParseErrorReporter;
fn SetProperty(&self, mut property: DOMString, value: DOMString,
priority: DOMString) -> ErrorResult {
// Step 1
if self.readonly {
return Err(Error::NoModificationAllowed);
}
// Step 2
property.make_ascii_lowercase();
// Step 3
if !is_supported_property(&property) {
return Ok(());
}
// Step 4
if value.is_empty() {
return self.RemoveProperty(property).map(|_| ());
}
// Step 5
let priority = match &*priority {
"" => StylePriority::Normal,
p if p.eq_ignore_ascii_case("important") => StylePriority::Important,
_ => return Ok(()),
};
// Step 6
let window = window_from_node(&*self.owner);
let error_reporter=window.css_error_reporter();
let declarations = parse_one_declaration(&property, &value, &window.r().get_url(), error_reporter);
// Step 7
let declarations = if let Ok(declarations) = declarations {
declarations
} else {
return Ok(());
};
let element = self.owner.upcast::<Element>();
// Step 8
for decl in declarations {
// Step 9
element.update_inline_style(decl, priority);
}
let document = document_from_node(element);
let node = element.upcast();
document.r().content_changed(node, NodeDamage::NodeStyleDamaged);
Ok(())
}
use style_traits::ParseErrorReporter;
impl Window {
pub fn new(runtime: Rc<Runtime>,
page: Rc<Page>,
script_chan: MainThreadScriptChan,
image_cache_chan: ImageCacheChan,
control_chan: Sender<ConstellationControlMsg>,
compositor: IpcSender<ScriptToCompositorMsg>,
image_cache_task: ImageCacheTask,
resource_task: Arc<ResourceTask>,
storage_task: StorageTask,
mem_profiler_chan: mem::ProfilerChan,
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
constellation_chan: ConstellationChan,
scheduler_chan: Sender<TimerEventRequest>,
timer_event_chan: MainThreadTimerEventChan,
layout_chan: LayoutChan,
id: PipelineId,
parent_info: Option<(PipelineId, SubpageId)>,
window_size: Option<WindowSizeData>)
-> Root<Window> {
let layout_rpc: Box<LayoutRPC> = {
let (rpc_send, rpc_recv) = channel();
let LayoutChan(ref lchan) = layout_chan;
lchan.send(Msg::GetRPC(rpc_send)).unwrap();
rpc_recv.recv().unwrap()
};
let win = box Window {
eventtarget: EventTarget::new_inherited(),
script_chan: script_chan,
image_cache_chan: image_cache_chan,
control_chan: control_chan,
console: Default::default(),
crypto: Default::default(),
compositor: compositor,
page: page,
navigator: Default::default(),
image_cache_task: image_cache_task,
mem_profiler_chan: mem_profiler_chan,
devtools_chan: devtools_chan,
browsing_context: DOMRefCell::new(None),
performance: Default::default(),
navigation_start: time::get_time().sec as u64,
navigation_start_precise: time::precise_time_ns() as f64,
screen: Default::default(),
session_storage: Default::default(),
local_storage: Default::default(),
scheduler_chan: scheduler_chan.clone(),
timers: ActiveTimers::new(box timer_event_chan, scheduler_chan),
next_worker_id: Cell::new(WorkerId(0)),
id: id,
parent_info: parent_info,
dom_static: GlobalStaticData::new(),
js_runtime: DOMRefCell::new(Some(runtime.clone())),
resource_task: resource_task,
storage_task: storage_task,
constellation_chan: constellation_chan,
page_clip_rect: Cell::new(MAX_RECT),
fragment_name: DOMRefCell::new(None),
last_reflow_id: Cell::new(0),
resize_event: Cell::new(None),
next_subpage_id: Cell::new(SubpageId(0)),
layout_chan: layout_chan,
layout_rpc: layout_rpc,
window_size: Cell::new(window_size),
current_viewport: Cell::new(Rect::zero()),
pending_reflow_count: Cell::new(0),
current_state: Cell::new(WindowState::Alive),
devtools_marker_sender: RefCell::new(None),
devtools_markers: RefCell::new(HashSet::new()),
devtools_wants_updates: Cell::new(false),
webdriver_script_chan: RefCell::new(None),
};
WindowBinding::Wrap(runtime.cx(), win)
}
pub fn css_error_reporter(&self) -> Box<ParseErrorReporter+Send> {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment