Closed
Bug 329127
Opened 20 years ago
Closed 12 years ago
Simplify nsDOMEvent::DuplicatePrivateData
Categories
(Core :: DOM: Events, defect)
Core
DOM: Events
Tracking
()
RESOLVED
FIXED
mozilla29
People
(Reporter: smaug, Assigned: masayuki)
References
Details
(Whiteboard: [qa-])
Attachments
(11 files, 5 obsolete files)
68.86 KB,
patch
|
smaug
:
review-
|
Details | Diff | Splinter Review |
2.81 KB,
patch
|
Details | Diff | Splinter Review | |
3.61 KB,
patch
|
Details | Diff | Splinter Review | |
5.66 KB,
patch
|
Details | Diff | Splinter Review | |
5.94 KB,
patch
|
Details | Diff | Splinter Review | |
8.31 KB,
patch
|
Details | Diff | Splinter Review | |
8.69 KB,
patch
|
Details | Diff | Splinter Review | |
72.98 KB,
patch
|
Details | Diff | Splinter Review | |
14.69 KB,
patch
|
Details | Diff | Splinter Review | |
27.35 KB,
patch
|
Details | Diff | Splinter Review | |
39.58 KB,
patch
|
smaug
:
review+
|
Details | Diff | Splinter Review |
nsDOMEvent::DuplicatePrivateData gets actually implemented in Bug 234455.
We should have a simple mechanism to extend nsDOMEvent::DuplicatePrivateData
to support new event types. Perhaps using macros or something...
Updated•16 years ago
|
Assignee: events → nobody
QA Contact: ian → events
Assignee | ||
Updated•12 years ago
|
Assignee: nobody → masayuki
Status: NEW → ASSIGNED
Assignee | ||
Comment 2•12 years ago
|
||
By creating virtual methods of event classes, nsDOMEvent::DuplicatePrivateData() can remove the switch statement.
This patch makes Assign*EventData() to a virtual method AssignEventData(). By this patch, AssignEventData() can be called outside the switch statement.
Assignee | ||
Comment 3•12 years ago
|
||
For making new instance of event class by one line, we need to remove some arguments of constructors which are only used for specific class.
Assignee | ||
Comment 4•12 years ago
|
||
Assignee | ||
Comment 5•12 years ago
|
||
Assignee | ||
Comment 6•12 years ago
|
||
Assignee | ||
Comment 7•12 years ago
|
||
Assignee | ||
Comment 8•12 years ago
|
||
Assignee | ||
Comment 9•12 years ago
|
||
Assignee | ||
Comment 10•12 years ago
|
||
Assignee | ||
Comment 11•12 years ago
|
||
Finally, creates new instance with same class of existing instance. We can do it with new virtual method, WidgetEvent::CreateNewInstance().
Then, we can make nsDOMEvent::DuplicatePrivateData() simple. And nobody needs to touch it when anybody add new event class.
https://tbpl.mozilla.org/?tree=Try&usebuildbot=1&rev=7e31502f5abc
Assignee | ||
Comment 12•12 years ago
|
||
Attachment #8360983 -
Attachment is obsolete: true
Assignee | ||
Comment 13•12 years ago
|
||
Attachment #8360988 -
Attachment is obsolete: true
Assignee | ||
Comment 14•12 years ago
|
||
Attachment #8361056 -
Attachment is obsolete: true
Assignee | ||
Comment 15•12 years ago
|
||
Attachment #8361058 -
Attachment is obsolete: true
Assignee | ||
Comment 16•12 years ago
|
||
Comment on attachment 8360975 [details] [diff] [review]
part.1 Make Assign*EventData() a virtual method
See comment 2.
Attachment #8360975 -
Flags: review?(bugs)
Assignee | ||
Comment 17•12 years ago
|
||
Comment on attachment 8360978 [details] [diff] [review]
part.2 Remove a constructor of WidgetPointerEvent which takes a lot of member values
See comment 3.
Attachment #8360978 -
Flags: review?(bugs)
Assignee | ||
Updated•12 years ago
|
Attachment #8360979 -
Flags: review?(bugs)
Assignee | ||
Updated•12 years ago
|
Attachment #8360981 -
Flags: review?(bugs)
Assignee | ||
Updated•12 years ago
|
Attachment #8360982 -
Flags: review?(bugs)
Assignee | ||
Updated•12 years ago
|
Attachment #8361513 -
Flags: review?(bugs)
Assignee | ||
Updated•12 years ago
|
Attachment #8360984 -
Flags: review?(bugs)
Assignee | ||
Updated•12 years ago
|
Attachment #8360985 -
Flags: review?(bugs)
Assignee | ||
Updated•12 years ago
|
Attachment #8360986 -
Flags: review?(bugs)
Assignee | ||
Comment 18•12 years ago
|
||
Comment on attachment 8361514 [details] [diff] [review]
part.10 Implement WidgetEvent::CreateNewInstance() for duplicating new instance of same inherited class
See comment 11.
Attachment #8361514 -
Flags: review?(bugs)
Reporter | ||
Comment 19•12 years ago
|
||
Comment on attachment 8360975 [details] [diff] [review]
part.1 Make Assign*EventData() a virtual method
># HG changeset patch
># User Masayuki Nakano <masayuki@d-toybox.com>
># Parent c2555af879bdfc57a8cc4e46c38c284283d8a11d
>Bug 329127 part.1 Make Assign*EventData() a virtual method r=
>
>diff --git a/dom/events/MutationEvent.h b/dom/events/MutationEvent.h
>--- a/dom/events/MutationEvent.h
>+++ b/dom/events/MutationEvent.h
>@@ -10,42 +10,48 @@
> #include "nsCOMPtr.h"
> #include "nsIAtom.h"
> #include "nsIDOMNode.h"
>
> namespace mozilla {
>
> class InternalMutationEvent : public WidgetEvent
> {
>+ NS_IMPL_EVENT_CLASS_COMMON_VIRTUAL_METHOD(Internal, MutationEvent,
>+ WidgetEvent)
> public:
>- virtual InternalMutationEvent* AsMutationEvent() MOZ_OVERRIDE { return this; }
>-
> InternalMutationEvent(bool aIsTrusted, uint32_t aMessage) :
> WidgetEvent(aIsTrusted, aMessage, NS_MUTATION_EVENT),
> mAttrChange(0)
> {
> mFlags.mCancelable = false;
> }
>
> nsCOMPtr<nsIDOMNode> mRelatedNode;
> nsCOMPtr<nsIAtom> mAttrName;
> nsCOMPtr<nsIAtom> mPrevAttrValue;
> nsCOMPtr<nsIAtom> mNewAttrValue;
> unsigned short mAttrChange;
>
>- void AssignMutationEventData(const InternalMutationEvent& aEvent,
>- bool aCopyTargets)
>+ virtual void AssignEventData(const WidgetEvent& aEvent,
>+ bool aCopyTargets) MOZ_OVERRIDE
> {
>- AssignEventData(aEvent, aCopyTargets);
>+ if (eventStructType != aEvent.eventStructType) {
>+ MOZ_CRASH("Called with invalid event instance");
>+ }
It is somewhat ugly to make everything to have
virtual void AssignEventData(const WidgetEvent& aEvent, bool aCopyTargets)
but only accept certain kinds of WidgetEvents as input.
For DuplicatePrivateData, could we add new ctors which take the right kind of event.
That way DuplicatePrivateData wouldn't need to call AssignEventData
Attachment #8360975 -
Flags: review?(bugs)
Reporter | ||
Comment 20•12 years ago
|
||
Comment on attachment 8360975 [details] [diff] [review]
part.1 Make Assign*EventData() a virtual method
So r-, but if you think there is really a strong reason for this approach, please
re-ask review.
Btw, would be nice to have also a patch which has all the changes.
That way it is easier to see the big picture.
Attachment #8360975 -
Flags: review-
Reporter | ||
Comment 21•12 years ago
|
||
So the approach the patches take effectively split switch-case of event struct types to
several AssignEventData implementation, since each of those have the struct type check.
Reporter | ||
Updated•12 years ago
|
Attachment #8360978 -
Flags: review?(bugs)
Reporter | ||
Updated•12 years ago
|
Attachment #8360979 -
Flags: review?(bugs)
Reporter | ||
Updated•12 years ago
|
Attachment #8360981 -
Flags: review?(bugs)
Reporter | ||
Updated•12 years ago
|
Attachment #8360982 -
Flags: review?(bugs)
Reporter | ||
Updated•12 years ago
|
Attachment #8360984 -
Flags: review?(bugs)
Reporter | ||
Updated•12 years ago
|
Attachment #8360985 -
Flags: review?(bugs)
Reporter | ||
Updated•12 years ago
|
Attachment #8360986 -
Flags: review?(bugs)
Reporter | ||
Updated•12 years ago
|
Attachment #8361513 -
Flags: review?(bugs)
Reporter | ||
Updated•12 years ago
|
Attachment #8361514 -
Flags: review?(bugs)
Assignee | ||
Comment 22•12 years ago
|
||
> For DuplicatePrivateData, could we add new ctors which take the right kind
> of event.
Of course, I was thinking about that. However, some event classes already have copy constructor and some other event classes' default copy constructor is used in some places.
So, we need to create a constructor which has different argument from default copy constructor. And it copies only private data (i.e., not all data even though its style is copy constructor).
Therefore, I used this approach which duplicates event class instance with WidgetEvent::CreateNewInstance() (see part.10). And keeping separating AssignEventData() for CreateNewInstance() useful for some other purpose.
(In reply to Olli Pettay [:smaug] from comment #21)
> So the approach the patches take effectively split switch-case of event
> struct types to
> several AssignEventData implementation, since each of those have the struct
> type check.
It's possible to check only in debug build with |#ifdef DEBUG| if you want.
I had another idea which creates new copy constructor, but there are some reasons why I don't take the approach:
1. Some classes already implemented copy constructor.
2. Some classes' default constructors are used in some places.
I.e., we need to design another style constructor which takes additional argument but I have no good idea.
3. Using constructor cannot indicate its meaning.
This what is the main reason why I don't use new constructor approach. Even though the new constructor looks like copy constructor, it does NOT copy all members. It only copies necessary members which referred by DOM event classes. This must make other developers confused.
(It might be better AssignEventData() renamed to AssignPrivateEventData() for indicating what it does)
How about you? If you thought it was not problem and we should create new constructor, I'd create new patches, otherwise, I'll request review for these patches again.
Flags: needinfo?(bugs)
Reporter | ||
Comment 23•12 years ago
|
||
Could we add
virtual WidgetEvent* Duplicate(); to WidgetEvent, and then all its subclasses would override it, and
call parent class' Duplicate().
It would be quite close to your CreateNewInstance, but would do the necessary
data copying inside it.
Flags: needinfo?(bugs)
Assignee | ||
Comment 24•12 years ago
|
||
Assignee | ||
Comment 25•12 years ago
|
||
https://tbpl.mozilla.org/?tree=Try&usebuildbot=1&rev=37812601dd5c
WidgetPointerEvent should be tested by test_assign_event_data.html if it's possible. I'll file a bug after landing this.
WidgetTouchEvent copies WidgetGUIEvent::widget. I'm not sure whether this is a problem. If it's not problem, why don't we copy widget of other events?
Attachment #8364874 -
Attachment is obsolete: true
Attachment #8364932 -
Flags: review?(bugs)
Assignee | ||
Comment 26•12 years ago
|
||
BTW, I'd like to sort out constructors which initialize some members. Initializing by arguments may cause mistake by wrong order and/or redundant when some specific events don't use the members.
The patches part.2 - part.9 do it. Smaug, if you agree with them, I'll file separated bugs for them.
Reporter | ||
Comment 27•12 years ago
|
||
Comment on attachment 8364932 [details] [diff] [review]
Another approach: WidgetEvent::Duplicate()
>+ virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
>+ {
>+ MOZ_ASSERT(eventStructType == NS_TOUCH_EVENT,
>+ "Duplicate() must be overridden by sub class");
>+ // XXX Why does only WidgetTouchEvent copy the widget?
This shouldn't be a problem, since widget is a strong reference, but would need to look at
TouchEvent usage to see why it is needed.
Anyhow, I think this approach is pretty easy to understand.
Attachment #8364932 -
Flags: review?(bugs) → review+
Reporter | ||
Comment 28•12 years ago
|
||
File a followup for the touch event case?
Reporter | ||
Comment 29•12 years ago
|
||
(In reply to Masayuki Nakano (:masayuki) (Mozilla Japan) from comment #26)
> The patches part.2 - part.9 do it. Smaug, if you agree with them, I'll file
> separated bugs for them.
I think removing those ctors is a good thing
Assignee | ||
Comment 30•12 years ago
|
||
Assignee | ||
Comment 31•12 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #28)
> File a followup for the touch event case?
Filed bug 964153.
Comment 32•12 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla29
Comment 33•12 years ago
|
||
fixed
Updated•12 years ago
|
Whiteboard: [qa-]
You need to log in
before you can comment on or make changes to this bug.
Description
•