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

Add WindowProxy support and basic browsing context concept. #1818

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Add bindings support for types that are raw JS objects. Remove Rust r…

…epresentation of WindowProxy.
  • Loading branch information
jdm committed Apr 14, 2014
commit 648ba150501b688343d927f80f6062b3b7d2805e
@@ -119,7 +119,12 @@ DOMInterfaces = {
],
},

'WindowProxy': {},
'WindowProxy': {
'nativeType': 'JSObject',
'pointerType': '*',
'concrete': False,
'register': False
},

'TestBinding': {},

@@ -129,7 +134,6 @@ DOMInterfaces = {
def addHTMLElement(element, concrete=None, needsAbstract=[]):
DOMInterfaces[element] = {
'nativeType': 'JS<%s>' % element,
'pointerType': '',
'concreteType': concrete if concrete else element,
'needsAbstract': needsAbstract
}
@@ -571,6 +571,23 @@ def wrapObjectTemplate(templateBody, isDefinitelyObject, type,

return templateBody

# A helper function for converting things that look like a JSObject*.
def handleJSObjectType(type, isMember, failureCode):
if not isMember:
declType = CGGeneric('Option<*JSObject>')
declArgs="cx"
else:
#assert (isMember == "Sequence" or isMember == "Variadic" or
# isMember == "Dictionary" or isMember == "OwningUnion")
# We'll get traced by the sequence or dictionary or union tracer
declType = CGGeneric("Option<*JSObject>")
declArgs = None
templateBody = "${declName} = Some(${val}.to_object());"
setToNullCode = "${declName} = None;"
template = wrapObjectTemplate(templateBody, type, setToNullCode,
failureCode)
return (template, declType, None, isOptional, None) #XXX declArgs

assert not (isEnforceRange and isClamp) # These are mutually exclusive

if type.isArray():
@@ -621,6 +638,9 @@ def wrapObjectTemplate(templateBody, isDefinitelyObject, type,
failureCode)
return (template, declType, None, isOptional, None)

if descriptor.nativeType == 'JSObject':
return handleJSObjectType(type, isMember, failureCode)

# Sequences and callbacks have to hold a strong ref to the thing being
# passed down.
forceOwningType = descriptor.interface.isCallback() or isMember
@@ -1090,7 +1110,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
if returnType.isGeckoInterface():
descriptor = descriptorProvider.getDescriptor(
returnType.unroll().inner.identifier.name)
result = CGGeneric(descriptor.nativeType)
result = CGGeneric(descriptor.pointerType + descriptor.nativeType)
if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">")
return result
@@ -4209,6 +4229,8 @@ def defaultValue(ty):
return '~""'
elif ty.startswith("Option"):
return "None"
elif ty == '*JSObject':
return "ptr::null()"
else:
return "/* uh oh: %s */" % ty

@@ -133,6 +133,7 @@ def __init__(self, config, interface, desc):
else:
nativeTypeDefault = 'JS<%s>' % ifaceName

self.pointerType = desc.get('pointerType', '')
self.nativeType = desc.get('nativeType', nativeTypeDefault)
self.concreteType = desc.get('concreteType', ifaceName)
self.needsAbstract = desc.get('needsAbstract', [])
@@ -7,15 +7,15 @@ use dom::bindings::utils::Reflectable;
use dom::bindings::utils::jsstring_to_str;
use servo_util::str::DOMString;

use js::jsapi::{JSBool, JSContext};
use js::jsapi::{JSBool, JSContext, JSObject};
use js::jsapi::{JS_ValueToUint64, JS_ValueToInt64};
use js::jsapi::{JS_ValueToECMAUint32, JS_ValueToECMAInt32};
use js::jsapi::{JS_ValueToUint16, JS_ValueToNumber, JS_ValueToBoolean};
use js::jsapi::{JS_NewUCStringCopyN, JS_ValueToString};
use js::jsapi::{JS_WrapValue};
use js::jsval::JSVal;
use js::jsval::{UndefinedValue, NullValue, BooleanValue, Int32Value, UInt32Value};
use js::jsval::{StringValue, ObjectValue};
use js::jsval::{StringValue, ObjectValue, ObjectOrNullValue};
use js::glue::RUST_JS_NumberValue;
use std::default::Default;
use std::libc;
@@ -202,6 +202,12 @@ impl FromJSValConvertible<()> for f64 {
}
}

impl ToJSValConvertible for *JSObject {
fn to_jsval(&self, _cx: *JSContext) -> JSVal {
ObjectOrNullValue(*self)
}
}

impl ToJSValConvertible for DOMString {
fn to_jsval(&self, cx: *JSContext) -> JSVal {
unsafe {
@@ -5,7 +5,7 @@
use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, Reflector};

use js::jsapi::{JSTracer, JS_CallTracer, JSTRACE_OBJECT};
use js::jsapi::{JSObject, JSTracer, JS_CallTracer, JSTRACE_OBJECT};

use std::cast;
use std::libc;
@@ -35,14 +35,17 @@ pub trait Traceable {
}

pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) {
trace_object(tracer, description, reflector.get_jsobject())
}

pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *JSObject) {
unsafe {
description.to_c_str().with_ref(|name| {
(*tracer).debugPrinter = ptr::null();
(*tracer).debugPrintIndex = -1;
(*tracer).debugPrintArg = name as *libc::c_void;
debug!("tracing {:s}", description);
JS_CallTracer(tracer as *JSTracer, reflector.get_jsobject(),
JSTRACE_OBJECT as u32);
JS_CallTracer(tracer as *JSTracer, obj, JSTRACE_OBJECT as u32);
});
}
}
@@ -94,7 +94,7 @@ impl HTMLFrameElement {
None
}

pub fn GetContentWindow(&self) -> Option<JS<WindowProxy>> {
pub fn GetContentWindow(&self) -> Option<WindowProxy> {
None
}

@@ -154,7 +154,7 @@ impl HTMLIFrameElement {
None
}

pub fn GetContentWindow(&self) -> Option<JS<WindowProxy>> {
pub fn GetContentWindow(&self) -> Option<WindowProxy> {
None
}

@@ -135,7 +135,7 @@ impl HTMLObjectElement {
None
}

pub fn GetContentWindow(&self) -> Option<JS<WindowProxy>> {
pub fn GetContentWindow(&self) -> Option<WindowProxy> {
None
}

@@ -124,7 +124,7 @@ impl MouseEvent {
typeArg: DOMString,
canBubbleArg: bool,
cancelableArg: bool,
viewArg: Option<JS<WindowProxy>>,
viewArg: Option<WindowProxy>,
detailArg: i32,
screenXArg: i32,
screenYArg: i32,
@@ -6,20 +6,42 @@ use dom::bindings::codegen::UIEventBinding;
use dom::bindings::codegen::InheritTypes::UIEventDerived;
use dom::bindings::js::JS;
use dom::bindings::error::Fallible;
use dom::bindings::trace::trace_object;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::event::{Event, EventTypeId, UIEventTypeId};
use dom::node::Node;
use dom::window::Window;
use dom::windowproxy::WindowProxy;
use servo_util::str::DOMString;

use js::jsapi::JSTracer;

use serialize::{Encoder, Encodable};
use std::cast;

#[deriving(Encodable)]
pub struct UIEvent {
event: Event,
view: Option<JS<WindowProxy>>,
extra: Untraceable,
detail: i32
}

pub struct Untraceable {
view: Option<WindowProxy>,
}

impl<S: Encoder> Encodable<S> for Untraceable {
fn encode(&self, tracer: &mut S) {
match self.view {
Some(view) => {
let tracer: &mut JSTracer = unsafe { cast::transmute(tracer) };
trace_object(tracer, "view", view);
}
None => (),
}
}
}

impl UIEventDerived for Event {
fn is_uievent(&self) -> bool {
self.type_id == UIEventTypeId
@@ -30,7 +52,9 @@ impl UIEvent {
pub fn new_inherited(type_id: EventTypeId) -> UIEvent {
UIEvent {
event: Event::new_inherited(type_id),
view: None,
extra: Untraceable {
view: None,
},
detail: 0
}
}
@@ -50,8 +74,8 @@ impl UIEvent {
Ok(ev)
}

pub fn GetView(&self) -> Option<JS<WindowProxy>> {
self.view.clone()
pub fn GetView(&self) -> Option<WindowProxy> {
self.extra.view
}

pub fn Detail(&self) -> i32 {
@@ -62,10 +86,10 @@ impl UIEvent {
type_: DOMString,
can_bubble: bool,
cancelable: bool,
view: Option<JS<WindowProxy>>,
view: Option<WindowProxy>,
detail: i32) {
self.event.InitEvent(type_, can_bubble, cancelable);
self.view = view;
self.extra.view = view;
self.detail = detail;
}

This file was deleted.

@@ -157,7 +157,11 @@ pub mod dom {
pub mod validitystate;
pub mod virtualmethods;
pub mod window;
pub mod windowproxy;

pub mod windowproxy {
use js::jsapi::JSObject;
pub type WindowProxy = *JSObject;
}

pub mod testbinding;
}
@@ -17,7 +17,6 @@ use dom::uievent::UIEvent;
use dom::eventtarget::EventTarget;
use dom::node::{Node, NodeHelpers};
use dom::window::{TimerData, Window};
use dom::windowproxy::WindowProxy;
use html::hubbub_html_parser::HtmlParserResult;
use html::hubbub_html_parser::{HtmlDiscoveredStyle, HtmlDiscoveredIFrame, HtmlDiscoveredScript};
use html::hubbub_html_parser;
@@ -970,7 +969,7 @@ impl ScriptTask {
Some(ref frame) => {
// http://dev.w3.org/csswg/cssom-view/#resizing-viewports
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize
let window_proxy: JS<WindowProxy> = WindowProxy::new(&frame.window);
let window_proxy = ptr::null();
let mut uievent = UIEvent::new(&frame.window);
uievent.get_mut().InitUIEvent(~"resize", false, false, Some(window_proxy), 0i32);
let event: &mut JS<Event> = &mut EventCast::from(&uievent);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.