Implement DOMPoint (aka WebKitPoint)

RESOLVED FIXED in mozilla31

Status

()

Core
Layout
RESOLVED FIXED
4 years ago
3 years ago

People

(Reporter: lmandel, Assigned: roc)

Tracking

(Depends on: 3 bugs, {dev-doc-needed})

unspecified
mozilla31
dev-doc-needed
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 2 obsolete attachments)

WebKitPoint is a common feature in use on the mobile Web that provides functionality that is useful. We should add this feature to Gecko...albeit with a more generic/standard name.

Class reference: http://developer.apple.com/library/safari/#documentation/AudioVideo/Reference/WebKitPointClassReference/WebKitPoint/WebKitPoint.html
Depends on: 850806
Depends on: 850808

Comment 1

4 years ago
Created attachment 724846 [details] [diff] [review]
Implements WebKitPoint
Attachment #724846 - Flags: feedback?(bzbarsky)

Comment 2

4 years ago
Hacked this up as discussed in this www-style thread:
http://lists.w3.org/Archives/Public/public-pointer-events/2013JanMar/0099.html

I'm using the WebKitPoint name for now (not DOMPoint or CSSPoint yet) so I can test on existing sites. 

Need feedback on the general approach here, especially around the DOM bindings macros.
Comment on attachment 724846 [details] [diff] [review]
Implements WebKitPoint

Review of attachment 724846 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/bindings/Bindings.conf
@@ +973,5 @@
>     'wrapperCache': False
>  },
>  
> +'WebKitPoint': {
> +    'nativeOwnership': 'refcounted',

Dunno if you actually need to refcount this; you could probably make it 'owned'.

@@ +974,5 @@
>  },
>  
> +'WebKitPoint': {
> +    'nativeOwnership': 'refcounted',
> +    'nativeType': 'mozilla::dom::WebKitPoint',

That's the default

::: dom/webidl/WebKitPoint.webidl
@@ +9,5 @@
> +interface WebKitPoint {
> +
> +  attribute float x;
> +  attribute float y;
> +  

Trailing whitespace

::: layout/style/WebKitPoint.cpp
@@ +7,5 @@
> +#include "WebKitPoint.h"
> +#include "nsContentUtils.h"
> +#include "mozilla/dom/WebKitPointBinding.h"
> +
> +using namespace mozilla::dom;

wrap the file in namespace {}

::: layout/style/WebKitPoint.h
@@ +2,5 @@
> +/* This Source Code Form is subject to the terms of the Mozilla Public
> + * License, v. 2.0. If a copy of the MPL was not distributed with this
> + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
> +
> +/* DOM object representing color values in DOM computed style */

Oh really?

@@ +14,5 @@
> +
> +// 3900c55f-5a66-42e7-a8e2-0a6dca9b9dae
> +#define MOZILLA_WEBKITPOINT_IID \
> +{ 0x3900c55f, 0x5a66, 0x42e7, \
> +  { 0xa8, 0xe2, 0x0a, 0x6d, 0xca, 0x9b, 0x9d, 0xae } }

Why?

@@ +33,5 @@
> +  Constructor(const GlobalObject& aGlobal, float aX, float aY, ErrorResult& aError);
> +
> +  WebKitPoint(float aX, float aY);
> +
> +  virtual ~WebKitPoint(void);

No need for the void, or the virtual.

@@ +65,5 @@
> +  }
> +
> +  nsISupports* GetParentObject() const
> +  {
> +    return nullptr;

You need to return something here; the window from the constructor, say.
Comment on attachment 724846 [details] [diff] [review]
Implements WebKitPoint

If we don't expect to be handing out WebKitPoint objects from various places, then Ms2ger is right: we could just nuke the wrapper cache, and make them non-wrappercached and owned.

In fact, I agree with most of his nits, except returning null from GetParentObject() should in fact be OK here, I think.

I don't see why you need to check for a Window in the constructor.  Doesn't seem like you actually care whether your global is a Window or not.

You should probably just export the header to mozilla/dom and then you don't need the headerFile annotation in Bindings.conf either.

Apart from that, looks good.
Attachment #724846 - Flags: feedback?(bzbarsky) → feedback+
Were you also planning to implement Node.convertPointFromNode?

Also, I don't think it's a great idea to name the C++ class WebKitPoint.  DOMPoint seems like a much better name!

Comment 6

4 years ago
(In reply to :Ehsan Akhgari from comment #5)
> Were you also planning to implement Node.convertPointFromNode?

WebKitPoint isn't too useful without the coord-space converters, so Yes, I think we need those (see dependent bugs.)

> Also, I don't think it's a great idea to name the C++ class WebKitPoint. 
> DOMPoint seems like a much better name!

Agreed, mozilla::dom::DOMPoint sounds like a plan.

Comment 7

4 years ago
I ran into a pretty big snag when I nuked the wrappercache:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   XUL                           	0x0000000101c80169 ReleaseSliceNow(unsigned int, void*) + 89
1   XUL                           	0x0000000101c8047c XPCIncrementalReleaseRunnable::ReleaseNow(bool) + 156
2   XUL                           	0x0000000101c8056e XPCIncrementalReleaseRunnable::Run() + 30
3   XUL                           	0x00000001022c60b6 nsThread::ProcessNextEvent(bool, bool*) + 742 (nsThread.cpp:627)

I think it's because DOMPoint objects can be handed out from anywhere like so:

var pt = new DOMPoint();

I don't think I can change it to 'owned' because we'll want this to be prefable. My current strategy is to implement it like this binding:

http://dxr.mozilla.org/mozilla-central/content/svg/content/src/nsISVGPoint.h.html
In public-fx the consensus was to create a Point type that's actually a WebIDL dictionary. This allows authors to pass {x:3, y:2} and things like that.

Maybe we can just use that type here instead of Webkit/DOMPoint? The only thing is that for compatibility with WebKitPoint we should have a constructor, and WebIDL dictionaries don't have constructors. Could we add support (in the spec and our implementation) for [Constructor] on WebIDL dictionaries?
Flags: needinfo?(bzbarsky)

Comment 9

4 years ago
Created attachment 726575 [details] [diff] [review]
WIP patch implements DOMPoint. Still need to change this to a WebIDL dictionary (or have it return one.)
Attachment #724846 - Attachment is obsolete: true
We should be able to hook up constructors for dictionaries, yeah.  As far as spec goes, should check with heycam.
Flags: needinfo?(bzbarsky) → needinfo?(cam)

Updated

4 years ago
Depends on: 854490
Yeah I think it should be fine to have constructors on dictionaries.
Flags: needinfo?(cam)
I've added this now:

http://dev.w3.org/2006/webapi/WebIDL/#Constructor
http://dev.w3.org/2006/webapi/WebIDL/#es-dictionary-constructors

http://dev.w3.org/cvsweb/2006/webapi/WebIDL/Overview.xml.diff?r1=1.617;r2=1.618;f=h
WebKitPoint should not be exposed on beta/release even if it is prefed off by default. See bug 837211. If we expose it anyway, we should spec it. (Silly name? yes, but navigator.product is already speced which just returns the hard-coded "Gecko").

Comment 14

4 years ago
Created attachment 744454 [details]
Proposed WebIDL for DOMPoint

Comment 15

4 years ago
Comment on attachment 744454 [details]
Proposed WebIDL for DOMPoint

>/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
>/* This Source Code Form is subject to the terms of the Mozilla Public
> * License, v. 2.0. If a copy of the MPL was not distributed with this file,
> * You can obtain one at http://mozilla.org/MPL/2.0/.
> */
>
>[Constructor(optional float x = 0, optional float y = 0),Pref="layout.css.dompoint.enabled"]
>dictionary DOMPoint {
>  float x = 0;
>  float y = 0;
>};
Attachment #744454 - Attachment mime type: text/x-csrc → text/plain

Comment 16

4 years ago
Created attachment 744455 [details] [diff] [review]
Adds DOMPoint.webidl to Firefox

As soon as bug 854490 lands, this patch will add DOMPoint to Firefox, hidden behind this pref:

layout.css.dompoint.enabled
Attachment #726575 - Attachment is obsolete: true

Updated

4 years ago
Summary: Implement WebKitPoint → Implement DOMPoint (aka WebKitPoint)
Keywords: dev-doc-needed
Making DOMPoint a dictionary is a problem because it means other objects (like the proposed DOMQuad) can't have DOMPoints as attributes. I have posted to public-fx/www-style about this.
Depends on: 917755

Comment 18

4 years ago
Turning this back into an interface from dictionary should just work without any codegen.py changes.
DOMPoint is implemented now, in bug 917755.
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
Assignee: nobody → roc
Target Milestone: --- → mozilla31
You need to log in before you can comment on or make changes to this bug.