Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicts resolved in conflicting files. OffscreenCanvas ready to be merged. #19067

Closed
wants to merge 11 commits into from

Width and height added to offscreen-canvas constructor

  • Loading branch information
gauraangkhurana committed Dec 6, 2017
commit 03df4417488c934b978398cc05b070ec454bb267
@@ -41,22 +41,25 @@ pub trait LayoutOffscreenCanvasHelpers {
pub struct OffscreenCanvas {
reflector_: Reflector,
context: DomRefCell<Option<CanvasContext>>,
width: u64,
height: u64,
}

impl OffscreenCanvas {
pub fn new_inherited(
width: u64,
height: u64,
document: &Document
height: u64
) -> OffscreenCanvas {

OffscreenCanvas {
reflector_: Reflector::new(),
context: DomRefCell::new(None),
width: width,
height: height,
}
}
//#[allow(unrooted_must_root)]
pub fn new(
fn new(
global: &GlobalScope,
width: u64,
height: u64
@@ -78,22 +81,22 @@ impl OffscreenCanvas {
impl OffscreenCanvasMethods for OffscreenCanvas {
// https://html.spec.whatwg.org/multipage/#dom-img-width
fn Width(&self) -> u64 {
let width: u64 = 300;
width
self.width
}

// https://html.spec.whatwg.org/multipage/#dom-img-height
fn SetHeight(&self, height: u64) {
self.height = height
}

// https://html.spec.whatwg.org/multipage/#dom-img-width
fn SetWidth(&self, width: u64) {
self.width = width
}

// https://html.spec.whatwg.org/multipage/#dom-img-height
fn Height(&self) -> u64 {
let height: u64 = 300;
height
self.height
}
}

@@ -60,6 +60,17 @@ enum CanvasFillOrStrokeStyle {
Pattern(Dom<CanvasPattern>),
}

/// Trait to get dimensions of off-screen element
pub trait OffscreenCanvasRendering {
//get width of offscreen-canvas element
fn width(&self) -> u64{
}

// Get the height of the offscreen-canvas element
fn Height(&self) -> u64{
}
}

#[dom_struct]
pub struct OffscreenCanvasRenderingContext2D {

This comment has been minimized.

Copy link
@jdm

jdm Nov 7, 2017

Member

Rather than duplicating so much code in this file, we should be looking at ways to share as much code as possible. Consider extracting common data members and methods into a separate CommonCanvasRenderingContext2d structure that is used as a member by both OffscreenCanvasRenderingContext2D and CanvasRenderingContext2D.

This comment has been minimized.

Copy link
@gauraangkhurana

gauraangkhurana Nov 27, 2017

Author

Yes @jdm , I agree with you. This was done when we were trying it and I will change this now.
Can you suggest some example files that use the same path of sharing files ?
It would be convenient to go through an example before trying my hands on this.

This comment has been minimized.

Copy link
@jdm

jdm Nov 27, 2017

Member

One example is components/script/dom/webgl2renderingcontext.rs which shares a lot of code with components/script/dom/webglrenderingcontext.rs. components/script/dom/textcontrol.rs is an example of sharing code between components/script/dom/htmlinputelement.rs and components/script/dom/htmltextareaelement.rs.

reflector_: Reflector,
@@ -120,23 +131,23 @@ impl OffscreenCanvasRenderingContext2D {
size: Size2D<i32>)
-> OffscreenCanvasRenderingContext2D {
let base = CanvasRenderingContext2D::new(global, &canvas, size);
Some(OffscreenCanvasRenderingContext2D {
OffscreenCanvasRenderingContext2D {
reflector_: Reflector::new(),
base: Dom::from_ref(&*base),
})
}
}

pub fn new(global: &GlobalScope,
canvas: &OffscreenCanvas,
size: Size2D<i32>)
-> DomRoot<OffscreenCanvasRenderingContext2D> {
let window = window_from_node(canvas);
let image_cache = window.image_cache();
let base_url = window.get_url();
let boxed = Box::new(OffscreenCanvasRenderingContext2D::new_inherited(
global, Some(canvas), image_cache, base_url, size
));
reflect_dom_object(boxed, global, OffscreenCanvasRenderingContext2DBinding::Wrap)
//let image_cache = window.image_cache();
//let base_url = window.get_url();
//let boxed = Box::new(OffscreenCanvasRenderingContext2D::new_inherited(
// global, Some(canvas), image_cache, base_url, size
//));
//reflect_dom_object(boxed, global, OffscreenCanvasRenderingContext2DBinding::Wrap)
unimplemented!()
}

fn draw_image(&self,
@@ -221,7 +232,8 @@ pub fn parse_color(string: &str) -> Result<RGBA, ()> {
impl LayoutOffscreenCanvasRenderingContext2DHelpers for LayoutDom<OffscreenCanvasRenderingContext2D> {
#[allow(unsafe_code)]
unsafe fn get_ipc_renderer(&self) -> IpcSender<CanvasMsg> {
self.base.get_ipc_renderer()
//self.base.get_ipc_renderer()
unimplemented!()
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.