Source/WebCore/ChangeLog

 12012-06-05 Dominic Cooney <dominicc@chromium.org>
 2
 3 SVGElementInstance should have EventTarget on the prototype chain
 4 https://bugs.webkit.org/show_bug.cgi?id=88232
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 SVG 1.1 specifies that SVGElementInstance has EventTarget as its
 9 parent interface:
 10 <http://www.w3.org/TR/SVG/struct.html#InterfaceSVGElementInstance>
 11 Match the spec by putting EventTarget on the prototype chain of
 12 SVGElementInstance instead of redundantly declaring
 13 addEventListener, removeEventListener and dispatchEvent on the
 14 SVGElementInstance interface. This is an incremental step to make
 15 all EventTargets do it this way, being tracked in bug 67312.
 16
 17 Covered by existing tests, eg
 18 svg/custom/use-instanceRoot-as-event-target.xhtml
 19
 20 * CMakeLists.txt: Finding base interface types requires
 21 searching directories with the IDLs of base interfaces.
 22 * DerivedSources.make: "
 23 * bindings/js/JSEventTargetCustom.cpp:
 24 (WebCore::toEventTarget): Try to unwrap EventTargets simply as
 25 EventTargets. When all EventTargets do this consistently this
 26 function will be simplified.
 27 * bindings/js/JSSVGElementInstanceCustom.cpp:
 28 (WebCore::JSSVGElementInstance::visitChildren): SVGElementInstance
 29 skips walking its event listener list because it forwards
 30 listeners to its corresponding element.
 31 * bindings/scripts/CodeGenerator.pm:
 32 (IsStrictSubtype): For finding what is an EventTarget based on
 33 parent interface.
 34 * bindings/scripts/CodeGeneratorJS.pm:
 35 (GenerateHeader): Extend the heuristic for what is an
 36 EventTarget. When all EventTargets are handled consistently this
 37 will be simplified.
 38 (GenerateImplementation):
 39 * bindings/scripts/CodeGeneratorV8.pm: Extend the heuristic for
 40 what is an EventTarget, and remove some of the special-casing for
 41 EventTarget.
 42 (GenerateHeader):
 43 (GetInternalFields):
 44 (GenerateImplementation):
 45 (GetNativeType):
 46 (JSValueToNative):
 47 (GetV8HeaderName):
 48 * svg/SVGElementInstance.h: Must extend EventTarget first so that
 49 static_cast<EventTarget*>(elementInstance) is the same pointer as
 50 elementInstance, similar to how static_cast<Node*>(element) is the
 51 same pointer as element.
 52 * svg/SVGElementInstance.idl: Extend EventTarget; no longer need
 53 to declare add/removeEventListener and dispatchEvent.
 54
1552012-06-04 Sheriff Bot <webkit.review.bot@gmail.com>
256
357 Unreviewed, rolling out r119421 and r119425.

Source/WebCore/CMakeLists.txt

@@SET(WebCore_INCLUDE_DIRECTORIES
9393)
9494
9595SET(WebCore_IDL_INCLUDES
 96 Modules/battery
9697 Modules/filesystem
 98 Modules/gamepad
9799 Modules/geolocation
98100 Modules/indexeddb
 101 Modules/intents
 102 Modules/mediastream
 103 Modules/networkinfo
 104 Modules/speech
 105 Modules/vibration
99106 Modules/webaudio
100107 Modules/webdatabase
101108 Modules/websockets

@@SET(WebCore_IDL_INCLUDES
105112 fileapi
106113 html
107114 html/canvas
 115 html/shadow
 116 html/track
108117 inspector
109118 loader/appcache
 119 notifications
110120 page
111121 plugins
112122 storage

Source/WebCore/DerivedSources.make

@@preprocess_idls_script = perl $(addprefix -I $(WebCore)/, $(sort $(dir $(1)))) $
933933# JS bindings generator
934934
935935IDL_INCLUDES = \
 936 $(WebCore)/Modules/battery \
 937 $(WebCore)/Modules/filesystem \
 938 $(WebCore)/Modules/gamepad \
 939 $(WebCore)/Modules/geolocation \
 940 $(WebCore)/Modules/indexeddb \
 941 $(WebCore)/Modules/intents \
 942 $(WebCore)/Modules/mediastream \
 943 $(WebCore)/Modules/networkinfo \
 944 $(WebCore)/Modules/speech \
 945 $(WebCore)/Modules/vibration \
 946 $(WebCore)/Modules/webaudio \
 947 $(WebCore)/Modules/webdatabase \
 948 $(WebCore)/Modules/websockets \
 949 $(WebCore)/css \
936950 $(WebCore)/dom \
937951 $(WebCore)/fileapi \
938952 $(WebCore)/html \
939  $(WebCore)/css \
940  $(WebCore)/page \
 953 $(WebCore)/html/canvas \
 954 $(WebCore)/html/shadow \
 955 $(WebCore)/html/track \
 956 $(WebCore)/inspector \
 957 $(WebCore)/loader/appcache \
941958 $(WebCore)/notifications \
942  $(WebCore)/xml \
943  $(WebCore)/svg
 959 $(WebCore)/page \
 960 $(WebCore)/plugins \
 961 $(WebCore)/storage \
 962 $(WebCore)/svg \
 963 $(WebCore)/workers \
 964 $(WebCore)/xml
944965
945966IDL_COMMON_ARGS = $(IDL_INCLUDES:%=--include %) --write-dependencies --outputDir .
946967

Source/WebCore/bindings/js/JSEventTargetCustom.cpp

@@EventTarget* toEventTarget(JSC::JSValue value)
7373 if (value.inherits(&JSDOMWindowShell::s_info))
7474 return jsCast<JSDOMWindowShell*>(asObject(value))->impl();
7575
 76 TRY_TO_UNWRAP_WITH_INTERFACE(EventTarget)
7677 DOM_EVENT_TARGET_INTERFACES_FOR_EACH(TRY_TO_UNWRAP_WITH_INTERFACE)
7778 return 0;
7879}

Source/WebCore/bindings/js/JSSVGElementInstanceCustom.cpp

3030
3131#include "JSSVGElementInstance.h"
3232
33 #include "JSNode.h"
34 #include "SVGElementInstance.h"
 33#include "JSEventTarget.h"
3534
3635namespace WebCore {
3736

@@void JSSVGElementInstance::visitChildren(JSC::JSCell* cell, JSC::SlotVisitor& vi
4140 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
4241 COMPILE_ASSERT(StructureFlags & JSC::OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
4342 ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
44  Base::visitChildren(thisObject, visitor);
 43 // Skip JSEventTarget::visitChildren because event listener registration is
 44 // forwarded to the corresponding element.
 45 JSEventTarget::Base::visitChildren(thisObject, visitor);
4546 visitor.addOpaqueRoot(root(thisObject->impl()->correspondingElement()));
4647}
4748

Source/WebCore/bindings/scripts/CodeGenerator.pm

@@sub GetVisibleInterfaceName
692692 return $interfaceName ? $interfaceName : $dataNode->name;
693693}
694694
 695sub IsStrictSubtype
 696{
 697 my $object = shift;
 698 my $dataNode = shift;
 699 my $interfaceName = shift;
 700 my $found = 0;
 701
 702 $object->ForAllParents($dataNode, sub {
 703 my $interface = shift;
 704 if ($object->StripModule($interface->name) eq $interfaceName) {
 705 $found = 1;
 706 }
 707 return "prune" if $found;
 708 }, 0, 1);
 709
 710 return $found;
 711}
 712
6957131;

Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

@@sub GenerateHeader
650650 my $hasRealParent = @{$dataNode->parents} > 0;
651651 my $hasParent = $hasLegacyParent || $hasRealParent;
652652 my $parentClassName = GetParentClassName($dataNode);
653  my $eventTarget = $dataNode->extendedAttributes->{"EventTarget"};
654  my $needsMarkChildren = $dataNode->extendedAttributes->{"JSCustomMarkFunction"} || $dataNode->extendedAttributes->{"EventTarget"};
 653 my $eventTarget = $dataNode->extendedAttributes->{"EventTarget"} || $codeGenerator->IsStrictSubtype($dataNode, "EventTarget");
 654 my $needsMarkChildren = $dataNode->extendedAttributes->{"JSCustomMarkFunction"} || $dataNode->extendedAttributes->{"EventTarget"} || $dataNode->name eq "EventTarget";
655655
656656 # - Add default header template and header protection
657657 push(@headerContentHeader, GenerateHeaderContentHeader($dataNode));

@@sub GenerateImplementation
13361336 my $hasParent = $hasLegacyParent || $hasRealParent;
13371337 my $parentClassName = GetParentClassName($dataNode);
13381338 my $visibleInterfaceName = $codeGenerator->GetVisibleInterfaceName($dataNode);
1339  my $eventTarget = $dataNode->extendedAttributes->{"EventTarget"};
1340  my $needsMarkChildren = $dataNode->extendedAttributes->{"JSCustomMarkFunction"} || $dataNode->extendedAttributes->{"EventTarget"};
 1339 my $eventTarget = $dataNode->extendedAttributes->{"EventTarget"} || $codeGenerator->IsStrictSubtype($dataNode, "EventTarget");
 1340 my $needsMarkChildren = $dataNode->extendedAttributes->{"JSCustomMarkFunction"} || $dataNode->extendedAttributes->{"EventTarget"} || $dataNode->name eq "EventTarget";
13411341
13421342 # - Add default header template
13431343 push(@implContentHeader, GenerateImplementationContentHeader($dataNode));

@@sub GenerateImplementation
21872187 push(@implContent, " COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);\n");
21882188 push(@implContent, " ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());\n");
21892189 push(@implContent, " Base::visitChildren(thisObject, visitor);\n");
2190  if ($dataNode->extendedAttributes->{"EventTarget"}) {
 2190 if ($dataNode->extendedAttributes->{"EventTarget"} || $dataNode->name eq "EventTarget") {
21912191 push(@implContent, " thisObject->impl()->visitJSEventListeners(visitor);\n");
21922192 }
21932193 if ($numCachedAttributes > 0) {

Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

@@sub GenerateHeader
230230 my $className = "V8$interfaceName";
231231 my $implClassName = $interfaceName;
232232
233  # Copy contents of parent classes except the first parent or if it is
234  # EventTarget.
 233 # Copy contents of parent classes except the first parent.
235234 $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@allParents, 1);
236235 $codeGenerator->LinkOverloadedFunctions($dataNode);
237236

@@sub GenerateHeader
239238 if (!$hasDependentLifetime) {
240239 foreach (@{$dataNode->parents}) {
241240 my $parent = $codeGenerator->StripModule($_);
242  next if $parent eq "EventTarget";
243241 $headerIncludes{"V8${parent}.h"} = 1;
244242 }
245243 }

@@END
305303 my $separator = "";
306304 foreach (@{$dataNode->parents}) {
307305 my $parent = $codeGenerator->StripModule($_);
308  next if $parent eq "EventTarget";
309306 $headerIncludes{"V8${parent}.h"} = 1;
310307 push(@headerContent, "${separator}V8${parent}::hasDependentLifetime");
311308 $separator = " || ";

@@sub GetInternalFields
511508 # We can't ask whether a parent type has a given extendedAttribute,
512509 # so special-case AbstractWorker and WorkerContext to include all sub-types.
513510 # Event listeners on DOM nodes are explicitly supported in the GC controller.
514  # FIXME: SVGElementInstance should probably have the EventTarget extended attribute, but doesn't.
515511 # FIXME: Simplify this when all EventTargets are subtypes of EventTarget.
516512 if (!IsNodeSubType($dataNode)
517513 && ($dataNode->extendedAttributes->{"EventTarget"}
518514 || $dataNode->extendedAttributes->{"IsWorkerContext"}
519515 || IsSubType($dataNode, "AbstractWorker")
520  || $name eq "SVGElementInstance"
521  || $name eq "EventTarget")) {
 516 || IsSubType($dataNode, "EventTarget"))) {
522517 push(@customInternalFields, "eventListenerCacheIndex");
523518 }
524519

@@sub GenerateImplementation
24332428 my $parentClassTemplate = "";
24342429 foreach (@{$dataNode->parents}) {
24352430 my $parent = $codeGenerator->StripModule($_);
2436  if ($parent eq "EventTarget") {
2437  next;
2438  }
24392431 AddToImplIncludes("V8${parent}.h");
24402432 $parentClass = "V8" . $parent;
24412433 $parentClassTemplate = $parentClass . "::GetTemplate()";

@@sub GetNativeType
34853477 return "Range::CompareHow" if $type eq "CompareHow";
34863478 return "DOMTimeStamp" if $type eq "DOMTimeStamp";
34873479 return "unsigned" if $type eq "unsigned int";
 3480 # TODO: When EventTarget is an interface and not a mixin, fix this so that
 3481 # EventTarget can be passed as a parameter.
34883482 return "Node*" if $type eq "EventTarget" and $isParameter;
34893483 return "double" if $type eq "Date";
34903484 return "ScriptValue" if $type eq "DOMObject";

@@sub JSValueToNative
36123606 }
36133607
36143608 # Default, assume autogenerated type conversion routines
 3609 # TODO: When EventTarget is an interface and not a mixin, fix this to use
 3610 # V8EventTarget::HasInstance etc.
36153611 if ($type eq "EventTarget") {
36163612 AddToImplIncludes("V8Node.h");
36173613

@@sub GetV8HeaderName
36503646 my $type = shift;
36513647 return "V8Event.h" if $type eq "DOMTimeStamp";
36523648 return "EventListener.h" if $type eq "EventListener";
3653  return "EventTarget.h" if $type eq "EventTarget";
36543649 return "SerializedScriptValue.h" if $type eq "SerializedScriptValue";
36553650 return "ScriptValue.h" if $type eq "DOMObject";
36563651 return "V8DOMStringList.h" if $type eq "DOMString[]";

@@my %non_wrapper_types = (
37373732 'Date' => 1,
37383733 'Dictionary' => 1,
37393734 'EventListener' => 1,
 3735 # TODO: When EventTarget is an interface and not a mixin, fix this so that
 3736 # EventTarget is treated as a wrapper type.
37403737 'EventTarget' => 1,
37413738 'IDBKey' => 1,
37423739 'JSObject' => 1,

Source/WebCore/svg/SVGElementInstance.h

@@class SVGElementInstanceList;
3838class SVGStyledElement;
3939
4040// SVGElementInstance mimics Node, but without providing all its functionality
41 class SVGElementInstance : public TreeShared<SVGElementInstance>,
42  public EventTarget {
 41class SVGElementInstance : public EventTarget,
 42 public TreeShared<SVGElementInstance> {
4343public:
4444 static PassRefPtr<SVGElementInstance> create(SVGUseElement* correspondingUseElement, SVGUseElement* directUseElement, PassRefPtr<SVGElement> originalElement)
4545 {

Source/WebCore/svg/SVGElementInstance.idl

@@module svg {
2929 interface [
3030 Conditional=SVG,
3131 JSCustomMarkFunction,
32  JSGenerateToNativeObject
 32 JSGenerateToNativeObject,
 33 JSGenerateToJSObject
3334 ] SVGElementInstance
3435#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C
3536 : Object, EventTarget
 37#else
 38 : EventTarget
3639#endif /* defined(LANGUAGE_OBJECTIVE_C) */
3740 {
3841 readonly attribute SVGElement correspondingElement;

@@module svg {
8689 attribute [NotEnumerable] EventListener onselectstart;
8790 attribute [NotEnumerable] EventListener onsubmit;
8891 attribute [NotEnumerable] EventListener onunload;
89 
90  void addEventListener(in DOMString type,
91  in EventListener listener,
92  in [Optional] boolean useCapture);
93  void removeEventListener(in DOMString type,
94  in EventListener listener,
95  in [Optional] boolean useCapture);
96  boolean dispatchEvent(in Event event)
97  raises(EventException);
9892#endif /* defined(LANGUAGE_OBJECTIVE_C) */
9993 };
10094}