WebCore/ChangeLog

 12010-07-07 Steve Block <steveblock@google.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 DeviceOrientationEvent should use optional properties
 6 https://bugs.webkit.org/show_bug.cgi?id=41607
 7
 8 This change adds a new DeviceOrientation class which takes care of which of the
 9 optional properties are present. DeviceOrientationEvent owns an instance of
 10 DeviceOrientation, rather than owning the properties directly.
 11 DeviceOrientationEvent now requires custom bindings.
 12
 13 Test: fast/dom/DeviceOrientation/optional-event-properties.html
 14
 15 * Android.jscbindings.mk:
 16 * Android.v8bindings.mk:
 17 * CMakeLists.txt:
 18 * GNUmakefile.am:
 19 * WebCore.gypi:
 20 * WebCore.pro:
 21 * WebCore.vcproj/WebCore.vcproj:
 22 * WebCore.xcodeproj/project.pbxproj:
 23 * bindings/js/JSDeviceOrientationEventCustom.cpp: Added.
 24 (WebCore::JSDeviceOrientationEvent::alpha):
 25 (WebCore::JSDeviceOrientationEvent::beta):
 26 (WebCore::JSDeviceOrientationEvent::gamma):
 27 (WebCore::JSDeviceOrientationEvent::initDeviceOrientationEvent):
 28 * bindings/v8/custom/V8DeviceOrientationEventCustom.cpp: Added.
 29 (WebCore::V8DeviceOrientationEvent::alphaAccessorGetter):
 30 (WebCore::V8DeviceOrientationEvent::betaAccessorGetter):
 31 (WebCore::V8DeviceOrientationEvent::gammaAccessorGetter):
 32 (WebCore::V8DeviceOrientationEvent::initDeviceOrientationEventCallback):
 33 * dom/DeviceOrientation.h: Added.
 34 (WebCore::DeviceOrientation::create):
 35 (WebCore::DeviceOrientation::canProvideAlpha):
 36 (WebCore::DeviceOrientation::alpha):
 37 (WebCore::DeviceOrientation::canProvideBeta):
 38 (WebCore::DeviceOrientation::beta):
 39 (WebCore::DeviceOrientation::canProvideGamma):
 40 (WebCore::DeviceOrientation::gamma):
 41 (WebCore::DeviceOrientation::DeviceOrientation):
 42 * dom/DeviceOrientationEvent.cpp:
 43 (WebCore::DeviceOrientationEvent::DeviceOrientationEvent):
 44 (WebCore::DeviceOrientationEvent::initDeviceOrientationEvent):
 45 * dom/DeviceOrientationEvent.h:
 46 (WebCore::DeviceOrientationEvent::create):
 47 (WebCore::DeviceOrientationEvent::orientation):
 48 * dom/DeviceOrientationEvent.idl:
 49
1502010-07-07 Adam Barth <abarth@webkit.org>
251
352 Unreviewed.
62681

WebCore/Android.jscbindings.mk

@@LOCAL_SRC_FILES += \
7979 bindings/js/JSCustomSQLTransactionCallback.cpp \
8080 bindings/js/JSCustomSQLTransactionErrorCallback.cpp \
8181 bindings/js/JSCustomVoidCallback.cpp \
82  bindings/js/JSDatabaseCallback.cpp \
83  bindings/js/JSDesktopNotificationsCustom.cpp \
8482 bindings/js/JSDOMApplicationCacheCustom.cpp \
8583 bindings/js/JSDOMBinding.cpp \
86  bindings/js/JSDOMFormDataCustom.cpp \
 84 bindings/js/JSDOMFormDataCustom.cpp \
8785 bindings/js/JSDOMGlobalObject.cpp \
8886 bindings/js/JSDOMWindowBase.cpp \
8987 bindings/js/JSDOMWindowCustom.cpp \
9088 bindings/js/JSDOMWindowShell.cpp \
 89 bindings/js/JSDatabaseCallback.cpp \
9190 bindings/js/JSDataGridColumnListCustom.cpp \
9291 bindings/js/JSDataGridDataSource.cpp \
9392 bindings/js/JSDatabaseCustom.cpp \
9493 bindings/js/JSDedicatedWorkerContextCustom.cpp \
 94 bindings/js/JSDesktopNotificationsCustom.cpp \
 95 bindings/js/JSDeviceOrientationEventCustom.cpp \
9596 bindings/js/JSDocumentCustom.cpp \
9697 bindings/js/JSElementCustom.cpp \
9798 bindings/js/JSEventCustom.cpp \
62668

WebCore/Android.v8bindings.mk

@@LOCAL_SRC_FILES += \
107107 bindings/v8/custom/V8DatabaseCallback.cpp \
108108 bindings/v8/custom/V8DatabaseCustom.cpp \
109109 bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp \
 110 bindings/v8/custom/V8DeviceOrientationEventCustom.cpp \
110111 bindings/v8/custom/V8DocumentCustom.cpp \
111112 bindings/v8/custom/V8DocumentLocationCustom.cpp \
112113 bindings/v8/custom/V8ElementCustom.cpp \
62668

WebCore/CMakeLists.txt

@@SET(WebCore_SOURCES
580580 bindings/js/JSDataGridDataSource.cpp
581581 bindings/js/JSDebugWrapperSet.cpp
582582 bindings/js/JSDedicatedWorkerContextCustom.cpp
 583 bindings/js/JSDeviceOrientationEventCustom.cpp
583584 bindings/js/JSDocumentCustom.cpp
584585 bindings/js/JSDOMApplicationCacheCustom.cpp
585586 bindings/js/JSDOMBinding.cpp
62668

WebCore/GNUmakefile.am

@@webcore_sources += \
446446 WebCore/bindings/js/JSDOMWindowShell.h \
447447 WebCore/bindings/js/JSDOMWrapper.cpp \
448448 WebCore/bindings/js/JSDOMWrapper.h \
 449 WebCore/bindings/js/JSDeviceOrientationEventCustom.cpp \
449450 WebCore/bindings/js/JSDocumentCustom.cpp \
450451 WebCore/bindings/js/JSElementCustom.cpp \
451452 WebCore/bindings/js/JSEventCustom.cpp \

@@webcore_sources += \
795796 WebCore/dom/DatasetDOMStringMap.h \
796797 WebCore/dom/DecodedDataDocumentParser.cpp \
797798 WebCore/dom/DecodedDataDocumentParser.h \
 799 WebCore/dom/DeviceOrientation.h \
798800 WebCore/dom/DeviceOrientationClient.h \
799801 WebCore/dom/DeviceOrientationController.cpp \
800802 WebCore/dom/DeviceOrientationController.h \
62668

WebCore/WebCore.gypi

541541 'bindings/js/JSDedicatedWorkerContextCustom.cpp',
542542 'bindings/js/JSDebugWrapperSet.cpp',
543543 'bindings/js/JSDebugWrapperSet.h',
 544 'bindings/js/JSDeviceOrientationEventCustom.cpp',
544545 'bindings/js/JSDocumentCustom.cpp',
545546 'bindings/js/JSDOMApplicationCacheCustom.cpp',
546547 'bindings/js/JSDOMBinding.cpp',

733734 'bindings/v8/custom/V8DatabaseSyncCustom.cpp',
734735 'bindings/v8/custom/V8DataGridColumnListCustom.cpp',
735736 'bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp',
 737 'bindings/v8/custom/V8DeviceOrientationEventCustom.cpp',
736738 'bindings/v8/custom/V8DocumentLocationCustom.cpp',
737739 'bindings/v8/custom/V8DOMFormDataCustom.cpp',
738740 'bindings/v8/custom/V8DOMWindowCustom.cpp',

11161118 'dom/DatasetDOMStringMap.h',
11171119 'dom/DecodedDataDocumentParser.cpp',
11181120 'dom/DecodedDataDocumentParser.h',
 1121 'dom/DeviceOrientation.h',
11191122 'dom/DeviceOrientationClient.h',
11201123 'dom/DeviceOrientationController.cpp',
11211124 'dom/DeviceOrientationController.h',
62668

WebCore/WebCore.pro

@@SOURCES += \
298298 bindings/js/JSDataGridDataSource.cpp \
299299 bindings/js/JSDebugWrapperSet.cpp \
300300 bindings/js/JSDesktopNotificationsCustom.cpp \
 301 bindings/js/JSDeviceOrientationEventCustom.cpp \
301302 bindings/js/JSDocumentCustom.cpp \
302303 bindings/js/JSDOMFormDataCustom.cpp \
303304 bindings/js/JSDOMGlobalObject.cpp \

@@HEADERS += \
12311232 dom/CSSMappedAttributeDeclaration.h \
12321233 dom/CustomEvent.h \
12331234 dom/default/PlatformMessagePortChannel.h \
 1235 dom/DeviceOrientation.h \
12341236 dom/DeviceOrientationClient.h \
12351237 dom/DeviceOrientationController.h \
12361238 dom/DeviceOrientationEvent.h \
62668

WebCore/WebCore.vcproj/WebCore.vcproj

3237332373 >
3237432374 </File>
3237532375 <File
 32376 RelativePath="..\dom\DeviceOrientation.h"
 32377 >
 32378 </File>
 32379 <File
3237632380 RelativePath="..\dom\DeviceOrientationClient.h"
3237732381 >
3237832382 </File>

4262442628 >
4262542629 </File>
4262642630 <File
 42631 RelativePath="..\bindings\js\JSDeviceOrientationEventCustom.cpp"
 42632 >
 42633 <FileConfiguration
 42634 Name="Debug|Win32"
 42635 ExcludedFromBuild="true"
 42636 >
 42637 <Tool
 42638 Name="VCCLCompilerTool"
 42639 />
 42640 </FileConfiguration>
 42641 <FileConfiguration
 42642 Name="Release|Win32"
 42643 ExcludedFromBuild="true"
 42644 >
 42645 <Tool
 42646 Name="VCCLCompilerTool"
 42647 />
 42648 </FileConfiguration>
 42649 <FileConfiguration
 42650 Name="Debug_Internal|Win32"
 42651 ExcludedFromBuild="true"
 42652 >
 42653 <Tool
 42654 Name="VCCLCompilerTool"
 42655 />
 42656 </FileConfiguration>
 42657 <FileConfiguration
 42658 Name="Debug_Cairo|Win32"
 42659 ExcludedFromBuild="true"
 42660 >
 42661 <Tool
 42662 Name="VCCLCompilerTool"
 42663 />
 42664 </FileConfiguration>
 42665 <FileConfiguration
 42666 Name="Release_Cairo|Win32"
 42667 ExcludedFromBuild="true"
 42668 >
 42669 <Tool
 42670 Name="VCCLCompilerTool"
 42671 />
 42672 </FileConfiguration>
 42673 <FileConfiguration
 42674 Name="Debug_All|Win32"
 42675 ExcludedFromBuild="true"
 42676 >
 42677 <Tool
 42678 Name="VCCLCompilerTool"
 42679 />
 42680 </FileConfiguration>
 42681 </File>
 42682 <File
4262742683 RelativePath="..\bindings\js\JSElementCustom.cpp"
4262842684 >
4262942685 <FileConfiguration
62668

WebCore/WebCore.xcodeproj/project.pbxproj

11841184 54C50F7B0E801DF3009832A0 /* XMLDocumentParserLibxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 54C50F7A0E801DF3009832A0 /* XMLDocumentParserLibxml2.cpp */; };
11851185 550A0BC9085F6039007353D6 /* QualifiedName.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 550A0BC7085F6039007353D6 /* QualifiedName.cpp */; };
11861186 550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */ = {isa = PBXBuildFile; fileRef = 550A0BC8085F6039007353D6 /* QualifiedName.h */; settings = {ATTRIBUTES = (Private, ); }; };
 1187 590E1B4911E4EF4B0069F784 /* DeviceOrientation.h in Headers */ = {isa = PBXBuildFile; fileRef = 590E1B4811E4EF4B0069F784 /* DeviceOrientation.h */; };
 1188 590E1B4B11E4EF700069F784 /* JSDeviceOrientationEventCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 590E1B4A11E4EF700069F784 /* JSDeviceOrientationEventCustom.cpp */; };
11871189 5913953B110758450083EC55 /* JNIBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 5913953A110758450083EC55 /* JNIBridge.h */; };
11881190 5913953D1107584E0083EC55 /* JNIBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5913953C1107584E0083EC55 /* JNIBridge.cpp */; };
11891191 596229781133EFD700DC4CBB /* GeolocationPositionCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 596229771133EFD700DC4CBB /* GeolocationPositionCache.cpp */; };

69196921 54C50F7A0E801DF3009832A0 /* XMLDocumentParserLibxml2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLDocumentParserLibxml2.cpp; sourceTree = "<group>"; };
69206922 550A0BC7085F6039007353D6 /* QualifiedName.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = QualifiedName.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
69216923 550A0BC8085F6039007353D6 /* QualifiedName.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = QualifiedName.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
 6924 590E1B4811E4EF4B0069F784 /* DeviceOrientation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceOrientation.h; sourceTree = "<group>"; };
 6925 590E1B4A11E4EF700069F784 /* JSDeviceOrientationEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDeviceOrientationEventCustom.cpp; sourceTree = "<group>"; };
69226926 5913953A110758450083EC55 /* JNIBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JNIBridge.h; sourceTree = "<group>"; };
69236927 5913953C1107584E0083EC55 /* JNIBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JNIBridge.cpp; sourceTree = "<group>"; };
69246928 596229771133EFD700DC4CBB /* GeolocationPositionCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeolocationPositionCache.cpp; sourceTree = "<group>"; };

1572015724 BC4EDEF70C08F414007EDD49 /* Custom */ = {
1572115725 isa = PBXGroup;
1572215726 children = (
 15727 590E1B4A11E4EF700069F784 /* JSDeviceOrientationEventCustom.cpp */,
1572315728 BC275CB211C5E85C00C9206C /* JSArrayBufferCustom.cpp */,
1572415729 492273A21083B3B100EE5C84 /* JSArrayBufferViewCustom.cpp */,
1572515730 86243D0011BC31F700CC006A /* JSArrayBufferViewHelper.h */,

1681016815 F523D32402DE4478018635CA /* dom */ = {
1681116816 isa = PBXGroup;
1681216817 children = (
 16818 590E1B4811E4EF4B0069F784 /* DeviceOrientation.h */,
1681316819 E1C4DE6D0EA75C650023CCD6 /* ActiveDOMObject.cpp */,
1681416820 E1C4DE680EA75C1E0023CCD6 /* ActiveDOMObject.h */,
1681516821 A8C4A7FC09D563270003AC8D /* Attr.cpp */,

1976219768 97EF561111E40783007E026F /* HTMLConstructionSite.h in Headers */,
1976319769 BCA8C81E11E3D36900812FB7 /* BackForwardController.h in Headers */,
1976419770 BCA8C83111E3D53200812FB7 /* BackForwardControllerClient.h in Headers */,
 19771 590E1B4911E4EF4B0069F784 /* DeviceOrientation.h in Headers */,
1976519772 );
1976619773 runOnlyForDeploymentPostprocessing = 0;
1976719774 };

2214822155 BCA8C81F11E3D36900812FB7 /* BackForwardController.cpp in Sources */,
2214922156 4F4F5FFB11CBD2E100A186BF /* RemoteInspectorFrontend2.cpp in Sources */,
2215022157 97EF561011E40783007E026F /* HTMLConstructionSite.cpp in Sources */,
 22158 590E1B4B11E4EF700069F784 /* JSDeviceOrientationEventCustom.cpp in Sources */,
2215122159 );
2215222160 runOnlyForDeploymentPostprocessing = 0;
2215322161 };
62668

WebCore/bindings/js/JSDeviceOrientationEventCustom.cpp

 1/*
 2 * Copyright 2010, The Android Open Source Project
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * * Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * * Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "JSDeviceOrientationEvent.h"
 28
 29#if ENABLE(DEVICE_ORIENTATION)
 30
 31#include "DeviceOrientation.h"
 32#include "DeviceOrientationEvent.h"
 33
 34using namespace JSC;
 35
 36namespace WebCore {
 37
 38JSValue JSDeviceOrientationEvent::alpha(ExecState* exec) const
 39{
 40 DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl());
 41 if (!imp->orientation()->canProvideAlpha())
 42 return jsNull();
 43 return jsNumber(exec, imp->orientation()->alpha());
 44}
 45
 46JSValue JSDeviceOrientationEvent::beta(ExecState* exec) const
 47{
 48 DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl());
 49 if (!imp->orientation()->canProvideBeta())
 50 return jsNull();
 51 return jsNumber(exec, imp->orientation()->beta());
 52}
 53
 54JSValue JSDeviceOrientationEvent::gamma(ExecState* exec) const
 55{
 56 DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl());
 57 if (!imp->orientation()->canProvideGamma())
 58 return jsNull();
 59 return jsNumber(exec, imp->orientation()->gamma());
 60}
 61
 62JSValue JSDeviceOrientationEvent::initDeviceOrientationEvent(ExecState* exec)
 63{
 64 const String& type = ustringToString(exec->argument(0).toString(exec));
 65 bool bubbles = exec->argument(1).toBoolean(exec);
 66 bool cancelable = exec->argument(2).toBoolean(exec);
 67 // If alpha, beta or gamma are null or undefined, mark them as not provided.
 68 // Otherwise, use the standard JavaScript conversion.
 69 bool alphaProvided = !exec->argument(3).isUndefinedOrNull();
 70 double alpha = exec->argument(3).toNumber(exec);
 71 bool betaProvided = !exec->argument(4).isUndefinedOrNull();
 72 double beta = exec->argument(4).toNumber(exec);
 73 bool gammaProvided = !exec->argument(5).isUndefinedOrNull();
 74 double gamma = exec->argument(5).toNumber(exec);
 75 RefPtr<DeviceOrientation> orientation = DeviceOrientation::create(alphaProvided, alpha, betaProvided, beta, gammaProvided, gamma);
 76 DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl());
 77 imp->initDeviceOrientationEvent(type, bubbles, cancelable, orientation.get());
 78 return jsUndefined();
 79}
 80
 81} // namespace WebCore
 82
 83#endif // ENABLE(DEVICE_ORIENTATION)
0

WebCore/bindings/v8/custom/V8DeviceOrientationEventCustom.cpp

 1/*
 2 * Copyright 2010, The Android Open Source Project
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * * Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * * Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "V8DeviceOrientationEvent.h"
 28
 29#if ENABLE(DEVICE_ORIENTATION)
 30
 31#include "DeviceOrientation.h"
 32#include "V8Binding.h"
 33#include "V8Proxy.h"
 34
 35#include <v8.h>
 36
 37namespace WebCore {
 38
 39v8::Handle<v8::Value> V8DeviceOrientationEvent::alphaAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
 40{
 41 INC_STATS("DOM.DeviceOrientationEvent.alpha._get");
 42 v8::Handle<v8::Object> holder = info.Holder();
 43 DeviceOrientationEvent* imp = V8DeviceOrientationEvent::toNative(holder);
 44 if (!imp->orientation()->canProvideAlpha())
 45 return v8::Null();
 46 return v8::Number::New(imp->orientation()->alpha());
 47}
 48
 49v8::Handle<v8::Value> V8DeviceOrientationEvent::betaAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
 50{
 51 INC_STATS("DOM.DeviceOrientationEvent.beta._get");
 52 v8::Handle<v8::Object> holder = info.Holder();
 53 DeviceOrientationEvent* imp = V8DeviceOrientationEvent::toNative(holder);
 54 if (!imp->orientation()->canProvideBeta())
 55 return v8::Null();
 56 return v8::Number::New(imp->orientation()->beta());
 57}
 58
 59v8::Handle<v8::Value> V8DeviceOrientationEvent::gammaAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
 60{
 61 INC_STATS("DOM.DeviceOrientationEvent.gamma._get");
 62 v8::Handle<v8::Object> holder = info.Holder();
 63 DeviceOrientationEvent* imp = V8DeviceOrientationEvent::toNative(holder);
 64 if (!imp->orientation()->canProvideGamma())
 65 return v8::Null();
 66 return v8::Number::New(imp->orientation()->gamma());
 67}
 68
 69v8::Handle<v8::Value> V8DeviceOrientationEvent::initDeviceOrientationEventCallback(const v8::Arguments& args)
 70{
 71 DeviceOrientationEvent* imp = V8DeviceOrientationEvent::toNative(args.Holder());
 72 V8Parameter<> type = args[0];
 73 bool bubbles = args[1]->BooleanValue();
 74 bool cancelable = args[2]->BooleanValue();
 75 // If alpha, beta or gamma are null or undefined, mark them as not provided.
 76 // Otherwise, use the standard JavaScript conversion.
 77 bool alphaProvided = !isUndefinedOrNull(args[3]);
 78 double alpha = static_cast<double>(args[3]->NumberValue());
 79 bool betaProvided = !isUndefinedOrNull(args[4]);
 80 double beta = static_cast<double>(args[4]->NumberValue());
 81 bool gammaProvided = !isUndefinedOrNull(args[5]);
 82 double gamma = static_cast<double>(args[5]->NumberValue());
 83 RefPtr<DeviceOrientation> orientation = DeviceOrientation::create(alphaProvided, alpha, betaProvided, beta, gammaProvided, gamma);
 84 imp->initDeviceOrientationEvent(type, bubbles, cancelable, orientation.get());
 85 return v8::Handle<v8::Value>();
 86}
 87
 88} // namespace WebCore
 89
 90#endif // ENABLE(DEVICE_ORIENTATION)
0

WebCore/dom/DeviceOrientation.h

 1/*
 2 * Copyright 2010, The Android Open Source Project
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * * Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * * Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef DeviceOrientation_h
 27#define DeviceOrientation_h
 28
 29#include "RefCounted.h"
 30
 31namespace WebCore {
 32
 33class DeviceOrientation : public RefCounted<DeviceOrientation> {
 34public:
 35 static PassRefPtr<DeviceOrientation> create()
 36 {
 37 return adoptRef(new DeviceOrientation);
 38 }
 39
 40 static PassRefPtr<DeviceOrientation> create(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
 41 {
 42 return adoptRef(new DeviceOrientation(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma));
 43 }
 44
 45 bool canProvideAlpha() const { return m_canProvideAlpha; }
 46 double alpha() const { return m_alpha; }
 47 bool canProvideBeta() const { return m_canProvideBeta; }
 48 double beta() const { return m_beta; }
 49 bool canProvideGamma() const { return m_canProvideGamma; }
 50 double gamma() const { return m_gamma; }
 51
 52private:
 53 DeviceOrientation()
 54 : m_canProvideAlpha(false)
 55 , m_canProvideBeta(false)
 56 , m_canProvideGamma(false) {}
 57
 58 DeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
 59 : m_canProvideAlpha(canProvideAlpha)
 60 , m_alpha(alpha)
 61 , m_canProvideBeta(canProvideBeta)
 62 , m_beta(beta)
 63 , m_canProvideGamma(canProvideGamma)
 64 , m_gamma(gamma) {}
 65
 66 bool m_canProvideAlpha;
 67 double m_alpha;
 68 bool m_canProvideBeta;
 69 double m_beta;
 70 bool m_canProvideGamma;
 71 double m_gamma;
 72};
 73
 74} // namespace WebCore
 75
 76#endif // DeviceOrientation_h
0

WebCore/dom/DeviceOrientationEvent.cpp

2626#include "config.h"
2727#include "DeviceOrientationEvent.h"
2828
 29#include "DeviceOrientation.h"
 30
2931#if ENABLE(DEVICE_ORIENTATION)
3032
3133namespace WebCore {
3234
3335DeviceOrientationEvent::DeviceOrientationEvent()
34  : m_alpha(0)
35  , m_beta(0)
36  , m_gamma(0)
 36 : m_orientation(DeviceOrientation::create())
3737{
3838}
3939
40 DeviceOrientationEvent::DeviceOrientationEvent(const AtomicString& eventType, double alpha, double beta, double gamma)
 40DeviceOrientationEvent::DeviceOrientationEvent(const AtomicString& eventType, DeviceOrientation* orientation)
4141 : Event(eventType, false, false) // Can't bubble, not cancelable
42  , m_alpha(alpha)
43  , m_beta(beta)
44  , m_gamma(gamma)
 42 , m_orientation(orientation)
4543{
4644}
4745
48 void DeviceOrientationEvent::initDeviceOrientationEvent(const AtomicString& eventType, bool canBubble, bool cancelable, double alpha, double beta, double gamma)
 46void DeviceOrientationEvent::initDeviceOrientationEvent(const AtomicString& type, bool bubbles, bool cancelable, DeviceOrientation* orientation)
4947{
5048 if (dispatched())
5149 return;
5250
53  initEvent(eventType, canBubble, cancelable);
54 
55  m_alpha = alpha;
56  m_beta = beta;
57  m_gamma = gamma;
 51 initEvent(type, bubbles, cancelable);
 52 m_orientation = orientation;
5853}
5954
6055} // namespace WebCore
62668

WebCore/dom/DeviceOrientationEvent.h

3131
3232namespace WebCore {
3333
 34class DeviceOrientation;
 35
3436class DeviceOrientationEvent : public Event {
3537public:
3638 static PassRefPtr<DeviceOrientationEvent> create()
3739 {
3840 return adoptRef(new DeviceOrientationEvent);
3941 }
40  static PassRefPtr<DeviceOrientationEvent> create(const AtomicString& eventType, double alpha, double beta, double gamma)
 42 static PassRefPtr<DeviceOrientationEvent> create(const AtomicString& eventType, DeviceOrientation* orientation)
4143 {
42  return adoptRef(new DeviceOrientationEvent(eventType, alpha, beta, gamma));
 44 return adoptRef(new DeviceOrientationEvent(eventType, orientation));
4345 }
4446
45  void initDeviceOrientationEvent(const AtomicString& eventType, bool canBubble, bool cancelable, double alpha, double beta, double gamma);
46  double alpha() const { return m_alpha; }
47  double beta() const { return m_beta; }
48  double gamma() const { return m_gamma; }
 47 void initDeviceOrientationEvent(const AtomicString& type, bool bubbles, bool cancelable, DeviceOrientation*);
4948
5049 virtual bool isDeviceOrientationEvent() const { return true; }
5150
 51 DeviceOrientation* orientation() const { return m_orientation.get(); }
 52
5253private:
5354 DeviceOrientationEvent();
54  DeviceOrientationEvent(const AtomicString& eventType, double alpha, double beta, double gamma);
 55 DeviceOrientationEvent(const AtomicString& eventType, DeviceOrientation*);
5556
56  double m_alpha;
57  double m_beta;
58  double m_gamma;
 57 RefPtr<DeviceOrientation> m_orientation;
5958};
6059
6160} // namespace WebCore
62668

WebCore/dom/DeviceOrientationEvent.idl

@@module core {
2828 interface [
2929 Conditional=DEVICE_ORIENTATION
3030 ] DeviceOrientationEvent : Event {
31  readonly attribute double alpha;
32  readonly attribute double beta;
33  readonly attribute double gamma;
34  void initDeviceOrientationEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in double alpha, in double beta, in double gamma);
 31 readonly attribute [Custom] double alpha;
 32 readonly attribute [Custom] double beta;
 33 readonly attribute [Custom] double gamma;
 34 [Custom] void initDeviceOrientationEvent(in DOMString type, in boolean bubbles, in boolean cancelable, in double alpha, in double beta, in double gamma);
3535 };
3636
3737}
62668

LayoutTests/ChangeLog

 12010-07-07 Steve Block <steveblock@google.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 DeviceOrientationEvent should use optional properties
 6 https://bugs.webkit.org/show_bug.cgi?id=41607
 7
 8 * fast/dom/DeviceOrientation/optional-event-properties-expected.txt: Added.
 9 * fast/dom/DeviceOrientation/optional-event-properties.html: Added.
 10 * fast/dom/DeviceOrientation/script-tests/optional-event-properties.js: Added.
 11
1122010-07-07 Dan Bernstein <mitz@apple.com>
213
314 Reviewed by Sam Weinig.
62681

LayoutTests/fast/dom/DeviceOrientation/optional-event-properties-expected.txt

 1Tests the optional properties of DeviceOrientationEvent. Each property should be null if not set, or set to null or undefined.
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6PASS event.alpha == null is true
 7PASS event.beta == null is true
 8PASS event.gamma == null is true
 9PASS event.alpha == 0 is true
 10PASS event.beta == 1 is true
 11PASS event.gamma == 2 is true
 12PASS event.alpha == null is true
 13PASS event.beta == null is true
 14PASS event.gamma == null is true
 15PASS event.alpha == 0 is true
 16PASS event.beta == 0 is true
 17PASS event.gamma == 0 is true
 18PASS event.alpha == null is true
 19PASS event.beta == null is true
 20PASS event.gamma == null is true
 21PASS event.alpha == 0 is true
 22PASS event.beta == 0 is true
 23PASS event.gamma == 0 is true
 24PASS event.alpha == null is true
 25PASS event.beta == null is true
 26PASS event.gamma == null is true
 27PASS successfullyParsed is true
 28
 29TEST COMPLETE
 30
0

LayoutTests/fast/dom/DeviceOrientation/optional-event-properties.html

 1<html>
 2<head>
 3<link rel="stylesheet" href="../../js/resources/js-test-style.css">
 4<script src="../../js/resources/js-test-pre.js"></script>
 5</head>
 6<body>
 7<p id="description"></p>
 8<div id="console"></div>
 9<script src="script-tests/optional-event-properties.js"></script>
 10<script src="../../js/resources/js-test-post.js"></script>
 11</body>
 12</html>
0

LayoutTests/fast/dom/DeviceOrientation/script-tests/optional-event-properties.js

 1description("Tests the optional properties of DeviceOrientationEvent. Each property should be null if not set, or set to null or undefined.");
 2
 3var event = document.createEvent('DeviceOrientationEvent');
 4
 5shouldBeTrue("event.alpha == null");
 6shouldBeTrue("event.beta == null");
 7shouldBeTrue("event.gamma == null");
 8
 9event.initDeviceOrientationEvent("", false, false, 0, 1, 2);
 10
 11shouldBeTrue("event.alpha == 0");
 12shouldBeTrue("event.beta == 1");
 13shouldBeTrue("event.gamma == 2");
 14
 15event.initDeviceOrientationEvent();
 16
 17shouldBeTrue("event.alpha == null");
 18shouldBeTrue("event.beta == null");
 19shouldBeTrue("event.gamma == null");
 20
 21event.initDeviceOrientationEvent("", false, false, [], [], []);
 22
 23shouldBeTrue("event.alpha == 0");
 24shouldBeTrue("event.beta == 0");
 25shouldBeTrue("event.gamma == 0");
 26
 27event.initDeviceOrientationEvent("", false, false, undefined, undefined, undefined);
 28
 29shouldBeTrue("event.alpha == null");
 30shouldBeTrue("event.beta == null");
 31shouldBeTrue("event.gamma == null");
 32
 33event.initDeviceOrientationEvent("", false, false, "", "", "");
 34
 35shouldBeTrue("event.alpha == 0");
 36shouldBeTrue("event.beta == 0");
 37shouldBeTrue("event.gamma == 0");
 38
 39event.initDeviceOrientationEvent("", false, false, null, null, null);
 40
 41shouldBeTrue("event.alpha == null");
 42shouldBeTrue("event.beta == null");
 43shouldBeTrue("event.gamma == null");
 44
 45window.successfullyParsed = true;
0