Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded .webidl files. #22070
Added .webidl files. #22070
Conversation
highfive
commented
Nov 1, 2018
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @jdm (or someone else) soon. |
highfive
commented
Nov 1, 2018
|
Heads up! This PR modifies the following files:
|
highfive
commented
Nov 1, 2018
|
This won't be able to merge until there's a corresponding Rust implementation. The bindings that are generated from the WebIDL file will complain, otherwise. |
| attribute [EnforceRange] unsigned long long height; | ||
|
|
||
| OffscreenRenderingContext? getContext(OffscreenRenderingContextId contextId, optional any options = null); | ||
| ImageBitmap transferToImageBitmap(); |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 1, 2018
Member
This will need to be commented out until we also add the ImageBitmap interface. Servo currently does not implement it.
| "dom.compositionevent.enabled": false, | ||
| "dom.customelements.enabled": true, | ||
| "dom.forcetouch.enabled": false, | ||
| "dom.gamepad.enabled": false, | ||
| "dom.microdata.testing.enabled": true, | ||
| "dom.mouseevent.which.enabled": false, | ||
| "dom.mutation_observer.enabled": true, | ||
| "dom.offscreen_canvas.enabled": true, |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 1, 2018
Member
We don't actually want to enable this preference by default until the implementation is ready.
|
@jdm Can you tell us which variables would be part of structure of OffscreenCanvas apart from height and width? |
|
You will also need to store a context member similar to https://github.com/servo/servo/blob/master/components/script/dom/htmlcanvaselement.rs#L58 . Apart from that, I don't know that there will need to be any other members for OffscreenCanvas. |
Chiaggs
commented
Nov 5, 2018
#[dom_struct]
pub struct OffscreenCanvas{
height: u64,
width: u64,
context: DomRefCell<Option<CanvasContext>>,
}
impl OffscreenCanvas{
pub fn new_inherited(height: u64,width: u64) -> OffscreenCanvas {
OffscreenCanvas {
height: height,
width: width,
context: DomRefCell::new(None),
}
}
pub fn new(global: &GlobalScope,height: u64,width: u64) -> DomRoot<OffscreenCanvas> {
reflect_dom_object(box OffscreenCanvas::new_inherited(), global, OffscreenCanvas::Bindings::Wrap)
}
pub fn Constructor (global: &GlobalScope,height: u64,width: u64) -> Fallible<DomRoot<OffscreenCanvas>> {
//step 1
let offscreencanvas = OffscreenCanvas::new(global);
//step 2
//step 3
Ok(offscreencanvas);
}
}@jdm Apart from step 2 and get context, does this code for OffscreenCanvas.rs file looks good to you ? |
|
You are missing a reflector field in OffscreenCanvas. That stores the pointer to the JS object that represents this Rust object. |
|
@jdm For initial step, which functionality should we implement for "offscreencanvasrenderingcontext2d.rs" ? |
|
The initial step only requires an implementation for OffscreenCanvas.getContext and the OffscreenCanvas constructor. transferToImageBitmap and convertToBlob can remain commented out. The OffscreenCanvasRenderingContext2D interface should have the |
Yes it makes sense. What about "commit()" in OffscreenCanvasRenderingContext2D? Should it be implemented? |
|
I don't think it makes sense to implement it separately from the actual rendering. |
|
@jdm Can you review this code. We are getting lots of error and are stuck. It would be great if you can suggest changes. use dom::bindings::codegen::Bindings::OffscreenCanvasBinding::{OffscreenCanvasMethods, Wrap as OffscreenCanvasWrap};
use dom::bindings::codegen::Bindings::OffscreenCanvasBinding;
use dom::bindings::codegen::UnionTypes;
use dom::bindings::error::{Error, Fallible};
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use std::ptr;
use dom::bindings::root::{DomRoot, Dom};
use std::cell::Ref;
use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope;
use dom::htmlcanvaselement::{CanvasContext, HTMLCanvasElement};
use dom_struct::dom_struct;
use dom::bindings::cell::DomRefCell;
use ref_filter_map;
use dom::offscreencanvasrenderingcontext2d::OffscreenCanvasRenderingContext2D;
use js::rust::HandleValue;
use js::jsapi::JSContext;
use dom::node::{Node, window_from_node};
pub enum OffscreenCanvasContext {
Context2D(Dom<OffscreenCanvasRenderingContext2D>),
//WebGL(Dom<WebGLRenderingContext>),
//WebGL2(Dom<WebGL2RenderingContext>),
}
#[dom_struct]
pub struct OffscreenCanvas{
reflector_: Reflector,
height: u64,
width: u64,
context: DomRefCell<Option<OffscreenCanvasContext>>,
placeholder: Option<Dom<HTMLCanvasElement>>,
}
impl OffscreenCanvas{
pub fn new_inherited(height: u64, width: u64, placeholder: Option<&HTMLCanvasElement>) -> OffscreenCanvas {
OffscreenCanvas {
reflector_: Reflector::new(),
height: height,
width: width,
context: DomRefCell::new(None),
placeholder: placeholder.map(|canvas| Dom::from_rooted(canvas)),
}
}
pub fn new(global: &GlobalScope, height: u64, width: u64, placeholder: Option<&HTMLCanvasElement>) -> DomRoot<OffscreenCanvas> {
reflect_dom_object(Box::new(OffscreenCanvas::new_inherited(height,width,placeholder)), global, OffscreenCanvasWrap)
}
pub fn Constructor (global: &GlobalScope, height: u64, width: u64) -> Fallible<DomRoot<OffscreenCanvas>> {
//step 1
let offscreencanvas = OffscreenCanvas::new(global,height,width,None);
//step 2
if offscreencanvas.context.borrow().is_some() {
return Err(Error::InvalidState);
}
offscreencanvas.height = height;
offscreencanvas.width = width;
offscreencanvas.placeholder = None;
//step 3
Ok(offscreencanvas)
}
/*pub fn context(&self) -> Option<Ref<OffscreenCanvasContext>> {
ref_filter_map::ref_filter_map(self.context.borrow(), |ctx| ctx.as_ref())
}*/
fn get_or_init_2d_context(&self) -> Option<DomRoot<OffscreenCanvasRenderingContext2D>> {
if let Some(ctx) = self.context() {
return match *ctx {
OffscreenCanvasContext::Context2d(ref ctx) => Some(DomRoot::from_ref(ctx)),
_ => None,
};
}
let window = window_from_node(self);
let size = self.get_size();
let context = OffscreenCanvasRenderingContext2D::new(window.upcast::<GlobalScope>(), self, size);
*self.context.borrow_mut() = Some(OffscreenCanvasContext::Context2d(Dom::from_ref(&*context)));
Some(context)
}
}
impl OffscreenCanvasMethods for OffscreenCanvas{
#[allow(unsafe_code)]
unsafe fn GetContext(&self,cx: *mut JSContext, contextID: DOMString, options: HandleValue) -> Option<UnionTypes::OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingContext> {
//let options =
if !options.is_object() {
options = HandleValue::null();
}
if(self.context.is_none())
{
if(contextID == "2d")
{
//self.get_or_init_2d_context();
}
}
}
fn Width(&self) -> u64 {
return self.width;
}
fn SetWidth(&self, value: u64) -> () {
self.width = value;
}
fn Height(&self) -> u64 {
return self.height;
}
fn SetHeight(&self, value: u64) -> () {
self.height = value;
}
}Errors: https://pastebin.com/jvN1u4NP |
|
@maharsh312 It would be useful if you specified the errors you are observing. |
|
Sorry, I missed the link to the errors. |
|
Followed Josh's review 1 and 4
|
I'm closing this PR under the assumption that it's a duplicate of #22168. |
PrayaniSingh0106 commentedNov 1, 2018
•
edited by SimonSapin
@maharsh312 @Chiaggs
Added 3 file as following:
r? @jdm
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is