Closed Bug 329127 Opened 20 years ago Closed 12 years ago

Simplify nsDOMEvent::DuplicatePrivateData

Categories

(Core :: DOM: Events, defect)

defect
Not set
normal

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...
No longer depends on: 234455
Assignee: events → nobody
QA Contact: ian → events
Assignee: nobody → masayuki
Status: NEW → ASSIGNED
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.
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.
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
Comment on attachment 8360975 [details] [diff] [review] part.1 Make Assign*EventData() a virtual method See comment 2.
Attachment #8360975 - Flags: review?(bugs)
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)
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)
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)
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-
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.
Attachment #8360978 - Flags: review?(bugs)
Attachment #8360979 - Flags: review?(bugs)
Attachment #8360981 - Flags: review?(bugs)
Attachment #8360982 - Flags: review?(bugs)
Attachment #8360984 - Flags: review?(bugs)
Attachment #8360985 - Flags: review?(bugs)
Attachment #8360986 - Flags: review?(bugs)
Attachment #8361513 - Flags: review?(bugs)
Attachment #8361514 - Flags: review?(bugs)
> 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)
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)
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)
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.
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+
File a followup for the touch event case?
(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
(In reply to Olli Pettay [:smaug] from comment #28) > File a followup for the touch event case? Filed bug 964153.
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla29
fixed
Whiteboard: [qa-]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: