Closed Bug 850805 Opened 8 years ago Closed 7 years ago

Implement DOMPoint (aka WebKitPoint)


(Core :: Layout, defect)

Not set





(Reporter: lmandel, Assigned: roc)


(Depends on 2 open bugs)


(Keywords: dev-doc-needed)


(2 files, 2 obsolete files)

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:
Depends on: 850806
Depends on: 850808
Attached patch Implements WebKitPoint (obsolete) — Splinter Review
Attachment #724846 - Flags: feedback?(bzbarsky)
Hacked this up as discussed in this www-style thread:

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 */
> +
> +/* DOM object representing color values in DOM computed style */

Oh really?

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


@@ +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!
(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.
I ran into a pretty big snag when I nuked the wrappercache:

Thread 0 Crashed:: Dispatch queue:
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:
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)
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)
Depends on: 854490
Yeah I think it should be fine to have constructors on dictionaries.
Flags: needinfo?(cam)
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 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
> */
>[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
As soon as bug 854490 lands, this patch will add DOMPoint to Firefox, hidden behind this pref:

Attachment #726575 - Attachment is obsolete: true
Summary: Implement WebKitPoint → Implement DOMPoint (aka WebKitPoint)
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.
Turning this back into an interface from dictionary should just work without any changes.
DOMPoint is implemented now, in bug 917755.
Closed: 7 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.