Diff
Modified: trunk/LayoutTests/ChangeLog (124483 => 124484)
--- trunk/LayoutTests/ChangeLog 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/LayoutTests/ChangeLog 2012-08-02 19:29:26 UTC (rev 124484)
@@ -1,3 +1,15 @@
+2012-08-02 Konrad Piascik <[email protected]>
+
+ Web Inspector: Override the DeviceOrientation
+ https://bugs.webkit.org/show_bug.cgi?id=91008
+
+ Reviewed by Pavel Feldman.
+
+ New tests for Device Orientation override.
+
+ * inspector/device-orientation-success-expected.txt: Added.
+ * inspector/device-orientation-success.html: Added.
+
2012-08-02 Chris Fleizach <[email protected]>
AXEnabled = false for AXIncrementors inside text fields
Added: trunk/LayoutTests/inspector/device-orientation-success-expected.txt (0 => 124484)
--- trunk/LayoutTests/inspector/device-orientation-success-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/device-orientation-success-expected.txt 2012-08-02 19:29:26 UTC (rev 124484)
@@ -0,0 +1,3 @@
+CONSOLE MESSAGE: line 17: alpha: 20 beta: 30 gamma: 40
+CONSOLE MESSAGE: line 17: alpha: 1.1 beta: 2.2 gamma: 3.3
+
Added: trunk/LayoutTests/inspector/device-orientation-success.html (0 => 124484)
--- trunk/LayoutTests/inspector/device-orientation-success.html (rev 0)
+++ trunk/LayoutTests/inspector/device-orientation-success.html 2012-08-02 19:29:26 UTC (rev 124484)
@@ -0,0 +1,37 @@
+<html>
+<head>
+<script src=""
+<script>
+
+var mockAlpha = 1.1;
+var mockBeta = 2.2;
+var mockGamma = 3.3;
+
+if (window.layoutTestController)
+ layoutTestController.setMockDeviceOrientation(true, mockAlpha, true, mockBeta, true, mockGamma);
+else
+ debug('This test can not be run without the LayoutTestController');
+
+function handler(evt)
+{
+ console.log('alpha: ' + evt.alpha + ' beta: ' + evt.beta + ' gamma: ' + evt.gamma);
+}
+
+function test()
+{
+ function callback()
+ {
+ PageAgent.clearDeviceOrientationOverride();
+ InspectorTest.completeTest();
+ }
+
+ InspectorTest.evaluateInPage("window.addEventListener('deviceorientation', handler, false);", callback);
+ PageAgent.setDeviceOrientationOverride(20, 30, 40);
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>
+</p>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (124483 => 124484)
--- trunk/Source/WebCore/ChangeLog 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/ChangeLog 2012-08-02 19:29:26 UTC (rev 124484)
@@ -1,3 +1,63 @@
+2012-08-02 Konrad Piascik <[email protected]>
+
+ Web Inspector: Override the DeviceOrientation
+ https://bugs.webkit.org/show_bug.cgi?id=91008
+
+ Reviewed by Pavel Feldman.
+
+ Re-added the m_page member variable to DeviceOrientationController and
+ added InspectorInstrumentation to see if the DeviceOrientationData
+ should be overridden or not.
+
+ Added UI to the web inspector front-end to allow users to override the
+ device orientation. This is currently hidden behind an experiment.
+
+ Test: inspector/device-orientation-success.html
+
+ * English.lproj/localizedStrings.js:
+ * dom/DeviceOrientationController.cpp:
+ (WebCore::DeviceOrientationController::DeviceOrientationController):
+ (WebCore::DeviceOrientationController::create):
+ (WebCore::DeviceOrientationController::didChangeDeviceOrientation):
+ (WebCore::provideDeviceOrientationTo):
+ * dom/DeviceOrientationController.h:
+ (DeviceOrientationController):
+ * inspector/Inspector.json:
+ * inspector/InspectorInstrumentation.cpp:
+ (WebCore):
+ (WebCore::InspectorInstrumentation::overrideDeviceOrientationImpl):
+ * inspector/InspectorInstrumentation.h:
+ (WebCore):
+ (InspectorInstrumentation):
+ (WebCore::InspectorInstrumentation::overrideDeviceOrientation):
+ * inspector/InspectorPageAgent.cpp:
+ (WebCore::InspectorPageAgent::setDeviceOrientationOverride):
+ (WebCore):
+ (WebCore::InspectorPageAgent::clearDeviceOrientationOverride):
+ (WebCore::InspectorPageAgent::canOverrideDeviceOrientation):
+ (WebCore::InspectorPageAgent::overrideDeviceOrientation):
+ * inspector/InspectorPageAgent.h:
+ * inspector/front-end/Settings.js:
+ (WebInspector.ExperimentsSettings):
+ * inspector/front-end/SettingsScreen.js:
+ (WebInspector.UserAgentSettingsTab):
+ (WebInspector.UserAgentSettingsTab.prototype._createInput):
+ (WebInspector.UserAgentSettingsTab.prototype._createDeviceMetricsElement):
+ (WebInspector.UserAgentSettingsTab.prototype._createGeolocationOverrideElement):
+ (WebInspector.UserAgentSettingsTab.prototype._onDeviceOrientationOverrideCheckboxClicked):
+ (WebInspector.UserAgentSettingsTab.prototype._applyDeviceOrientationUserInput):
+ (WebInspector.UserAgentSettingsTab.prototype._setDeviceOrientation.set if):
+ (WebInspector.UserAgentSettingsTab.prototype._setDeviceOrientation):
+ (WebInspector.UserAgentSettingsTab.prototype._createDeviceOrientationOverrideElement):
+ * inspector/front-end/UserAgentSupport.js:
+ (WebInspector.UserAgentSupport.DeviceOrientation):
+ (WebInspector.UserAgentSupport.DeviceOrientation.prototype.toSetting):
+ (WebInspector.UserAgentSupport.DeviceOrientation.parseSetting):
+ (WebInspector.UserAgentSupport.DeviceOrientation.parseUserInput):
+ (WebInspector.UserAgentSupport.DeviceOrientation.clearDeviceOrientationOverride):
+ * inspector/front-end/inspector.js:
+ (WebInspector.doLoadedDone):
+
2012-08-02 Arnaud Renevier <[email protected]>
TypedArray set method is slow when called with another typed array
Modified: trunk/Source/WebCore/English.lproj/localizedStrings.js (124483 => 124484)
--- trunk/Source/WebCore/English.lproj/localizedStrings.js 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/English.lproj/localizedStrings.js 2012-08-02 19:29:26 UTC (rev 124484)
@@ -726,3 +726,4 @@
localizedStrings["Emulate position unavailable"] = "Emulate position unavailable";
localizedStrings["Override Geolocation"] = "Override Geolocation";
localizedStrings["Geolocation Position"] = "Geolocation Position";
+localizedStrings["Override Device Orientation"] = "Override Device Orientation";
Modified: trunk/Source/WebCore/dom/DeviceOrientationController.cpp (124483 => 124484)
--- trunk/Source/WebCore/dom/DeviceOrientationController.cpp 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/dom/DeviceOrientationController.cpp 2012-08-02 19:29:26 UTC (rev 124484)
@@ -29,11 +29,13 @@
#include "DeviceOrientationClient.h"
#include "DeviceOrientationData.h"
#include "DeviceOrientationEvent.h"
+#include "InspectorInstrumentation.h"
namespace WebCore {
-DeviceOrientationController::DeviceOrientationController(DeviceOrientationClient* client)
+DeviceOrientationController::DeviceOrientationController(Page* page, DeviceOrientationClient* client)
: m_client(client)
+ , m_page(page)
, m_timer(this, &DeviceOrientationController::timerFired)
{
ASSERT(m_client);
@@ -45,9 +47,9 @@
m_client->deviceOrientationControllerDestroyed();
}
-PassOwnPtr<DeviceOrientationController> DeviceOrientationController::create(DeviceOrientationClient* client)
+PassOwnPtr<DeviceOrientationController> DeviceOrientationController::create(Page* page, DeviceOrientationClient* client)
{
- return adoptPtr(new DeviceOrientationController(client));
+ return adoptPtr(new DeviceOrientationController(page, client));
}
void DeviceOrientationController::timerFired(Timer<DeviceOrientationController>* timer)
@@ -129,6 +131,7 @@
void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationData* orientation)
{
+ orientation = InspectorInstrumentation::overrideDeviceOrientation(m_page, orientation);
RefPtr<DeviceOrientationEvent> event = DeviceOrientationEvent::create(eventNames().deviceorientationEvent, orientation);
Vector<RefPtr<DOMWindow> > listenersVector;
copyToVector(m_listeners, listenersVector);
@@ -151,7 +154,7 @@
void provideDeviceOrientationTo(Page* page, DeviceOrientationClient* client)
{
- DeviceOrientationController::provideTo(page, DeviceOrientationController::supplementName(), DeviceOrientationController::create(client));
+ DeviceOrientationController::provideTo(page, DeviceOrientationController::supplementName(), DeviceOrientationController::create(page, client));
}
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/DeviceOrientationController.h (124483 => 124484)
--- trunk/Source/WebCore/dom/DeviceOrientationController.h 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/dom/DeviceOrientationController.h 2012-08-02 19:29:26 UTC (rev 124484)
@@ -41,7 +41,7 @@
public:
~DeviceOrientationController();
- static PassOwnPtr<DeviceOrientationController> create(DeviceOrientationClient*);
+ static PassOwnPtr<DeviceOrientationController> create(Page*, DeviceOrientationClient*);
void addListener(DOMWindow*);
void removeListener(DOMWindow*);
@@ -61,11 +61,12 @@
static bool isActiveAt(Page*);
private:
- explicit DeviceOrientationController(DeviceOrientationClient*);
+ explicit DeviceOrientationController(Page*, DeviceOrientationClient*);
void timerFired(Timer<DeviceOrientationController>*);
DeviceOrientationClient* m_client;
+ Page* m_page;
typedef HashCountedSet<RefPtr<DOMWindow> > ListenersCountedSet;
ListenersCountedSet m_listeners;
ListenersCountedSet m_suspendedListeners;
Modified: trunk/Source/WebCore/inspector/Inspector.json (124483 => 124484)
--- trunk/Source/WebCore/inspector/Inspector.json 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/inspector/Inspector.json 2012-08-02 19:29:26 UTC (rev 124484)
@@ -373,6 +373,29 @@
{ "name": "result", "type": "boolean", "description": "True if browser can ovrride Geolocation." }
],
"hidden": true
+ },
+ {
+ "name": "setDeviceOrientationOverride",
+ "description": "Overrides the Device Orientation.",
+ "parameters": [
+ { "name": "alpha", "type": "number", "description": "Mock alpha"},
+ { "name": "beta", "type": "number", "description": "Mock beta"},
+ { "name": "gamma", "type": "number", "description": "Mock gamma"}
+ ],
+ "hidden": true
+ },
+ {
+ "name": "clearDeviceOrientationOverride",
+ "description": "Clears the overridden Device Orientation.",
+ "hidden": true
+ },
+ {
+ "name": "canOverrideDeviceOrientation",
+ "description": "Check the backend if Web Inspector can override the device orientation.",
+ "returns": [
+ { "name": "result", "type": "boolean", "description": "If true, <code>setDeviceOrientationOverride</code> can safely be invoked on the agent." }
+ ],
+ "hidden": true
}
],
"events": [
Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (124483 => 124484)
--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp 2012-08-02 19:29:26 UTC (rev 124484)
@@ -38,6 +38,7 @@
#include "CSSStyleRule.h"
#include "DOMWindow.h"
#include "Database.h"
+#include "DeviceOrientationData.h"
#include "DocumentLoader.h"
#include "Event.h"
#include "EventContext.h"
@@ -1217,6 +1218,13 @@
}
#endif
+DeviceOrientationData* InspectorInstrumentation::overrideDeviceOrientationImpl(InstrumentingAgents* instrumentingAgents, DeviceOrientationData* deviceOrientation)
+{
+ if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
+ deviceOrientation = pageAgent->overrideDeviceOrientation(deviceOrientation);
+ return deviceOrientation;
+}
+
} // namespace WebCore
#endif // !ENABLE(INSPECTOR)
Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (124483 => 124484)
--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2012-08-02 19:29:26 UTC (rev 124484)
@@ -56,6 +56,7 @@
class Element;
class EventContext;
class DocumentLoader;
+class DeviceOrientationData;
class GeolocationPosition;
class GraphicsContext;
class HitTestResult;
@@ -267,6 +268,8 @@
static void registerInstrumentingAgents(InstrumentingAgents*);
static void unregisterInstrumentingAgents(InstrumentingAgents*);
+ static DeviceOrientationData* overrideDeviceOrientation(Page*, DeviceOrientationData*);
+
private:
#if ENABLE(INSPECTOR)
static WTF::ThreadSpecific<InspectorTimelineAgent*>& threadSpecificTimelineAgentForOrphanEvents();
@@ -431,6 +434,7 @@
static GeolocationPosition* overrideGeolocationPositionImpl(InstrumentingAgents*, GeolocationPosition*);
#endif
+ static DeviceOrientationData* overrideDeviceOrientationImpl(InstrumentingAgents*, DeviceOrientationData*);
static int s_frontendCounter;
#endif
};
@@ -1386,7 +1390,6 @@
#endif
}
-
#if ENABLE(GEOLOCATION)
inline GeolocationPosition* InspectorInstrumentation::overrideGeolocationPosition(Page* page, GeolocationPosition* position)
{
@@ -1399,7 +1402,17 @@
}
#endif
+inline DeviceOrientationData* InspectorInstrumentation::overrideDeviceOrientation(Page* page, DeviceOrientationData* deviceOrientation)
+{
#if ENABLE(INSPECTOR)
+ FAST_RETURN_IF_NO_FRONTENDS(deviceOrientation);
+ if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(page))
+ return overrideDeviceOrientationImpl(instrumentingAgents, deviceOrientation);
+#endif
+ return deviceOrientation;
+}
+
+#if ENABLE(INSPECTOR)
inline bool InspectorInstrumentation::collectingHTMLParseErrors(Page* page)
{
FAST_RETURN_IF_NO_FRONTENDS(false);
Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (124483 => 124484)
--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp 2012-08-02 19:29:26 UTC (rev 124484)
@@ -46,6 +46,7 @@
#include "DOMImplementation.h"
#include "DOMNodeHighlighter.h"
#include "DOMPatchSupport.h"
+#include "DeviceOrientationController.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "Frame.h"
@@ -1033,6 +1034,42 @@
return position;
}
+void InspectorPageAgent::setDeviceOrientationOverride(ErrorString* error, double alpha, double beta, double gamma)
+{
+ DeviceOrientationController* controller = DeviceOrientationController::from(m_page);
+ if (!controller) {
+ *error = "Internal error: unable to override device orientation.";
+ return;
+ }
+
+ ErrorString clearError;
+ clearDeviceOrientationOverride(&clearError);
+
+ m_deviceOrientation = DeviceOrientationData::create(true, alpha, true, beta, true, gamma);
+ controller->didChangeDeviceOrientation(m_deviceOrientation.get());
+}
+
+void InspectorPageAgent::clearDeviceOrientationOverride(ErrorString*)
+{
+ m_deviceOrientation.clear();
+}
+
+void InspectorPageAgent::canOverrideDeviceOrientation(ErrorString*, bool* outParam)
+{
+#if ENABLE(DEVICE_ORIENTATION)
+ *outParam = true;
+#else
+ *outParam = false;
+#endif
+}
+
+DeviceOrientationData* InspectorPageAgent::overrideDeviceOrientation(DeviceOrientationData* deviceOrientation)
+{
+ if (m_deviceOrientation)
+ deviceOrientation = m_deviceOrientation.get();
+ return deviceOrientation;
+}
+
} // namespace WebCore
#endif // ENABLE(INSPECTOR)
Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.h (124483 => 124484)
--- trunk/Source/WebCore/inspector/InspectorPageAgent.h 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.h 2012-08-02 19:29:26 UTC (rev 124484)
@@ -33,6 +33,7 @@
#if ENABLE(INSPECTOR)
+#include "DeviceOrientationData.h"
#include "Frame.h"
#include "GeolocationPosition.h"
#include "InspectorBaseAgent.h"
@@ -113,11 +114,16 @@
virtual void setGeolocationOverride(ErrorString*, const double*, const double*, const double*);
virtual void clearGeolocationOverride(ErrorString*);
virtual void canOverrideGeolocation(ErrorString*, bool* out_param);
+ virtual void setDeviceOrientationOverride(ErrorString*, double, double, double);
+ virtual void clearDeviceOrientationOverride(ErrorString*);
+ virtual void canOverrideDeviceOrientation(ErrorString*, bool*);
-
// Geolocation override helpers.
GeolocationPosition* overrideGeolocationPosition(GeolocationPosition*);
+ // DeviceOrientation helper
+ DeviceOrientationData* overrideDeviceOrientation(DeviceOrientationData*);
+
// InspectorInstrumentation API
void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld*);
void domContentEventFired();
@@ -169,6 +175,7 @@
bool m_geolocationOverridden;
RefPtr<GeolocationPosition> m_geolocationPosition;
RefPtr<GeolocationPosition> m_platformGeolocationPosition;
+ RefPtr<DeviceOrientationData> m_deviceOrientation;
};
Modified: trunk/Source/WebCore/inspector/front-end/Settings.js (124483 => 124484)
--- trunk/Source/WebCore/inspector/front-end/Settings.js 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/inspector/front-end/Settings.js 2012-08-02 19:29:26 UTC (rev 124484)
@@ -100,6 +100,7 @@
this.savedURLs = this.createSetting("savedURLs", {});
this._javascript_Disabled = this.createSetting("_javascript_Disabled", false);
this.geolocationOverride = this.createSetting("geolocationOverride", "");
+ this.deviceOrientationOverride = this.createSetting("deviceOrientationOverride", "");
// If there are too many breakpoints in a storage, it is likely due to a recent bug that caused
// periodical breakpoints duplication leading to inspector slowness.
@@ -190,6 +191,7 @@
this.fileSystemInspection = this._createExperiment("fileSystemInspection", "FileSystem inspection");
this.mainThreadMonitoring = this._createExperiment("mainThreadMonitoring", "Show CPU activity in Timeline");
this.geolocationOverride = this._createExperiment("geolocationOverride", "Override Device Geolocation");
+ this.deviceOrientationOverride = this._createExperiment("deviceOrientationOverride", "Override Device Orientation");
this.sass = this._createExperiment("sass", "Support for SASS");
this._cleanUpSetting();
Modified: trunk/Source/WebCore/inspector/front-end/SettingsScreen.js (124483 => 124484)
--- trunk/Source/WebCore/inspector/front-end/SettingsScreen.js 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/inspector/front-end/SettingsScreen.js 2012-08-02 19:29:26 UTC (rev 124484)
@@ -351,6 +351,8 @@
p.appendChild(this._createDeviceMetricsControl());
if (Capabilities.canOverrideGeolocation && WebInspector.experimentsSettings.geolocationOverride.isEnabled())
p.appendChild(this._createGeolocationOverrideControl());
+ if (Capabilities.canOverrideDeviceOrientation && WebInspector.experimentsSettings.deviceOrientationOverride.isEnabled())
+ p.appendChild(this._createDeviceOrientationOverrideControl());
p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Emulate touch events"), WebInspector.settings.emulateTouchEvents));
}
@@ -507,6 +509,27 @@
PageAgent.getScriptExecutionStatus(executionStatusCallback.bind(this));
},
+ /**
+ * Creates an input element under the parentElement with the given id and defaultText.
+ * It also sets an onblur event listener.
+ * @param {Element} parentElement
+ * @param {string} id
+ * @param {string} defaultText
+ * @param {function} eventListener
+ * @return {Element} element
+ */
+ _createInput: function(parentElement, id, defaultText, eventListener)
+ {
+ var element = parentElement.createChild("input");
+ element.id = id;
+ element.maxLength = 12;
+ element.style.width = "80px";
+ element.value = defaultText;
+ element.align = "right";
+ element.addEventListener("blur", eventListener, false);
+ return element;
+ },
+
_createDeviceMetricsControl: function()
{
const metricsSetting = WebInspector.settings.deviceMetrics.get();
@@ -604,17 +627,6 @@
var fieldsetElement = document.createElement("fieldset");
fieldsetElement.id = "metrics-override-section";
- function createInput(parentElement, id, defaultText)
- {
- var element = parentElement.createChild("input");
- element.id = id;
- element.maxLength = 6;
- element.style.width = "48px";
- element.value = defaultText;
- element.addEventListener("blur", this._applyDeviceMetricsUserInput.bind(this), false);
- return element;
- }
-
function swapDimensionsClicked(event)
{
var widthValue = this._widthOverrideElement.value;
@@ -629,9 +641,9 @@
var cellElement = rowElement.createChild("td");
cellElement.appendChild(document.createTextNode(WebInspector.UIString("Screen resolution:")));
cellElement = rowElement.createChild("td");
- this._widthOverrideElement = createInput.call(this, cellElement, "metrics-override-width", String(metrics.width || screen.width));
+ this._widthOverrideElement = this._createInput(cellElement, "metrics-override-width", String(metrics.width || screen.width), this._applyDeviceMetricsUserInput.bind(this));
cellElement.appendChild(document.createTextNode(" \u00D7 ")); // MULTIPLICATION SIGN.
- this._heightOverrideElement = createInput.call(this, cellElement, "metrics-override-height", String(metrics.height || screen.height));
+ this._heightOverrideElement = this._createInput(cellElement, "metrics-override-height", String(metrics.height || screen.height), this._applyDeviceMetricsUserInput.bind(this));
cellElement.appendChild(document.createTextNode(" \u2014 ")); // EM DASH.
this._swapDimensionsElement = cellElement.createChild("button");
this._swapDimensionsElement.appendChild(document.createTextNode(" \u21C4 ")); // RIGHTWARDS ARROW OVER LEFTWARDS ARROW.
@@ -642,7 +654,7 @@
cellElement = rowElement.createChild("td");
cellElement.appendChild(document.createTextNode(WebInspector.UIString("Font scale factor:")));
cellElement = rowElement.createChild("td");
- this._fontScaleFactorOverrideElement = createInput.call(this, cellElement, "metrics-override-font-scale", String(metrics.fontScaleFactor || 1));
+ this._fontScaleFactorOverrideElement = this._createInput(cellElement, "metrics-override-font-scale", String(metrics.fontScaleFactor || 1), this._applyDeviceMetricsUserInput.bind(this));
rowElement = tableElement.createChild("tr");
cellElement = rowElement.createChild("td");
@@ -728,26 +740,14 @@
var fieldsetElement = document.createElement("fieldset");
fieldsetElement.id = "geolocation-override-section";
- function createInput(parentElement, id, defaultText)
- {
- var element = parentElement.createChild("input");
- element.id = id;
- element.maxLength = 12;
- element.style.width = "80px";
- element.value = defaultText;
- element.addEventListener("blur", this._applyGeolocationUserInput.bind(this), false);
- return element;
- }
-
var tableElement = fieldsetElement.createChild("table");
-
var rowElement = tableElement.createChild("tr");
var cellElement = rowElement.createChild("td");
cellElement.appendChild(document.createTextNode(WebInspector.UIString("Geolocation Position") + ":"));
cellElement = rowElement.createChild("td");
- this._latitudeElement = createInput.call(this, cellElement, "geolocation-override-latitude", String(geolocation.latitude));
+ this._latitudeElement = this._createInput(cellElement, "geolocation-override-latitude", String(geolocation.latitude), this._applyGeolocationUserInput.bind(this));
cellElement.appendChild(document.createTextNode(" , "));
- this._longitudeElement = createInput.call(this, cellElement, "geolocation-override-longitude", String(geolocation.longitude));
+ this._longitudeElement = this._createInput(cellElement, "geolocation-override-longitude", String(geolocation.longitude), this._applyGeolocationUserInput.bind(this));
rowElement = tableElement.createChild("tr");
cellElement = rowElement.createChild("td");
var geolocationErrorLabelElement = document.createElement("label");
@@ -761,6 +761,99 @@
cellElement.appendChild(geolocationErrorLabelElement);
return fieldsetElement;
+ },
+
+ _createDeviceOrientationOverrideControl: function()
+ {
+ const deviceOrientationSetting = WebInspector.settings.deviceOrientationOverride.get();
+ var deviceOrientation = WebInspector.UserAgentSupport.DeviceOrientation.parseSetting(deviceOrientationSetting);
+
+ var p = document.createElement("p");
+ var labelElement = p.createChild("label");
+ var checkboxElement = labelElement.createChild("input");
+ checkboxElement.id = "device-orientation-override-checkbox";
+ checkboxElement.type = "checkbox";
+ checkboxElement.checked = !deviceOrientation;
+ checkboxElement.addEventListener("click", this._onDeviceOrientationOverrideCheckboxClicked.bind(this), false);
+ this._deviceOrientationOverrideCheckboxElement = checkboxElement;
+ labelElement.appendChild(document.createTextNode(WebInspector.UIString("Override Device Orientation")));
+
+ var deviceOrientationSectionElement = this._createDeviceOrientationOverrideElement(deviceOrientation);
+ p.appendChild(deviceOrientationSectionElement);
+ this._deviceOrientationSectionElement = deviceOrientationSectionElement;
+
+ this._setDeviceOrientation(deviceOrientation, false, true);
+
+ return p;
+ },
+
+ _onDeviceOrientationOverrideCheckboxClicked: function()
+ {
+ var controlsDisabled = !this._deviceOrientationOverrideCheckboxElement.checked;
+ this._alphaElement.disabled = controlsDisabled;
+ this._betaElement.disabled = controlsDisabled;
+ this._gammaElement.disabled = controlsDisabled;
+
+ if (this._deviceOrientationOverrideCheckboxElement.checked) {
+ var deviceOrientation = WebInspector.UserAgentSupport.DeviceOrientation.parseUserInput(this._alphaElement.value, this._betaElement.value, this._gammaElement.value);
+ if (deviceOrientation)
+ this._setDeviceOrientation(deviceOrientation, false, false);
+ if (!this._alphaElement.value)
+ this._alphaElement.focus();
+ } else
+ WebInspector.UserAgentSupport.DeviceOrientation.clearDeviceOrientationOverride();
+ },
+
+ _applyDeviceOrientationUserInput: function()
+ {
+ this._setDeviceOrientation(WebInspector.UserAgentSupport.DeviceOrientation.parseUserInput(this._alphaElement.value.trim(), this._betaElement.value.trim(), this._gammaElement.value.trim()), true, false);
+ },
+
+ /**
+ * @param {?WebInspector.UserAgentSupport.DeviceOrientation} deviceOrientation
+ * @param {boolean} userInputModified
+ * @param {boolean} updateCheckbox
+ */
+ _setDeviceOrientation: function(deviceOrientation, userInputModified, updateCheckbox)
+ {
+ if (!deviceOrientation)
+ return;
+
+ if (!userInputModified) {
+ this._alphaElement.value = deviceOrientation.alpha;
+ this._betaElement.value = deviceOrientation.beta;
+ this._gammaElement.value = deviceOrientation.gamma;
+ }
+
+ var value = deviceOrientation.toSetting();
+ WebInspector.settings.deviceOrientationOverride.set(value);
+
+ if (this._deviceOrientationOverrideCheckboxElement && updateCheckbox) {
+ this._deviceOrientationOverrideCheckboxElement.checked = !!deviceOrientation.toSetting();
+ this._onDeviceOrientationOverrideCheckboxClicked();
+ }
+ },
+
+ /**
+ * @param {WebInspector.UserAgentSupport.DeviceOrientation} deviceOrientation
+ */
+ _createDeviceOrientationOverrideElement: function(deviceOrientation)
+ {
+ var fieldsetElement = document.createElement("fieldset");
+ fieldsetElement.id = "device-orientation-override-section";
+
+ var tableElement = fieldsetElement.createChild("table");
+
+ var rowElement = tableElement.createChild("tr");
+ var cellElement = rowElement.createChild("td");
+ cellElement.appendChild(document.createTextNode("\u03B1: "));
+ this._alphaElement = this._createInput(cellElement, "device-orientation-override-alpha", String(deviceOrientation.alpha), this._applyDeviceOrientationUserInput.bind(this));
+ cellElement.appendChild(document.createTextNode(" \u03B2: "));
+ this._betaElement = this._createInput(cellElement, "device-orientation-override-beta", String(deviceOrientation.beta), this._applyDeviceOrientationUserInput.bind(this));
+ cellElement.appendChild(document.createTextNode(" \u03B3: "));
+ this._gammaElement = this._createInput(cellElement, "device-orientation-override-gamma", String(deviceOrientation.gamma), this._applyDeviceOrientationUserInput.bind(this));
+
+ return fieldsetElement;
}
}
Modified: trunk/Source/WebCore/inspector/front-end/UserAgentSupport.js (124483 => 124484)
--- trunk/Source/WebCore/inspector/front-end/UserAgentSupport.js 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/inspector/front-end/UserAgentSupport.js 2012-08-02 19:29:26 UTC (rev 124484)
@@ -38,6 +38,7 @@
WebInspector.settings.deviceMetrics.addChangeListener(this._deviceMetricsChanged, this);
WebInspector.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChanged, this);
WebInspector.settings.geolocationOverride.addChangeListener(this._geolocationPositionChanged, this);
+ WebInspector.settings.deviceOrientationOverride.addChangeListener(this._deviceOrientationChanged, this);
}
/**
@@ -234,6 +235,69 @@
PageAgent.clearGeolocationOverride();
}
+WebInspector.UserAgentSupport.DeviceOrientation = function (alpha, beta, gamma)
+{
+ this.alpha = alpha;
+ this.beta = beta;
+ this.gamma = gamma;
+}
+
+WebInspector.UserAgentSupport.DeviceOrientation.prototype = {
+ /**
+ * @return {string}
+ */
+ toSetting: function()
+ {
+ return JSON.stringify(this);
+ }
+}
+
+/*
+ * @return {WebInspector.UserAgentSupport.DeviceOrientation}
+ */
+WebInspector.UserAgentSupport.DeviceOrientation.parseSetting = function(value)
+{
+ if (value) {
+ var jsonObject = JSON.parse(value);
+ return new WebInspector.UserAgentSupport.DeviceOrientation(jsonObject.alpha, jsonObject.beta, jsonObject.gamma);
+ }
+ return new WebInspector.UserAgentSupport.DeviceOrientation(0, 0, 0);
+}
+
+/**
+ * @return {?WebInspector.UserAgentSupport.DeviceOrientation}
+ */
+WebInspector.UserAgentSupport.DeviceOrientation.parseUserInput = function(alphaString, betaString, gammaString)
+{
+ function isUserInputValid(value)
+ {
+ if (!value)
+ return true;
+ return /^[-]?[0-9]*[.]?[0-9]*$/.test(value);
+ }
+
+ if (!alphaString ^ !betaString ^ !gammaString)
+ return null;
+
+ var isAlphaValid = isUserInputValid(alphaString);
+ var isBetaValid = isUserInputValid(betaString);
+ var isGammaValid = isUserInputValid(gammaString);
+
+ if (!isAlphaValid && !isBetaValid && !isGammaValid)
+ return null;
+
+ var alpha = isAlphaValid ? parseFloat(alphaString) : -1;
+ var beta = isBetaValid ? parseFloat(betaString) : -1;
+ var gamma = isGammaValid ? parseFloat(gammaString) : -1;
+
+ return new WebInspector.UserAgentSupport.DeviceOrientation(alpha, beta, gamma);
+}
+
+WebInspector.UserAgentSupport.DeviceOrientation.clearDeviceOrientationOverride = function()
+{
+ PageAgent.clearDeviceOrientationOverride();
+}
+
WebInspector.UserAgentSupport.prototype = {
_deviceMetricsChanged: function()
{
@@ -249,6 +313,15 @@
PageAgent.setGeolocationOverride();
else
PageAgent.setGeolocationOverride(geolocation.latitude, geolocation.longitude, 150);
+ },
+
+ /**
+ * @param {WebInspector.Event} event
+ */
+ _deviceOrientationChanged: function(event)
+ {
+ var deviceOrientation = WebInspector.UserAgentSupport.DeviceOrientation.parseSetting(WebInspector.settings.deviceOrientationOverride.get());
+ PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOrientation.beta, deviceOrientation.gamma);
}
}
Modified: trunk/Source/WebCore/inspector/front-end/inspector.js (124483 => 124484)
--- trunk/Source/WebCore/inspector/front-end/inspector.js 2012-08-02 19:20:33 UTC (rev 124483)
+++ trunk/Source/WebCore/inspector/front-end/inspector.js 2012-08-02 19:29:26 UTC (rev 124484)
@@ -437,7 +437,8 @@
ProfilerAgent.hasHeapProfiler(WebInspector._initializeCapability.bind(WebInspector, "heapProfilerPresent", null));
TimelineAgent.supportsFrameInstrumentation(WebInspector._initializeCapability.bind(WebInspector, "timelineSupportsFrameInstrumentation", null));
PageAgent.canOverrideDeviceMetrics(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceMetrics", null));
- PageAgent.canOverrideGeolocation(WebInspector._initializeCapability.bind(WebInspector, "canOverrideGeolocation", WebInspector._doLoadedDoneWithCapabilities.bind(WebInspector)));
+ PageAgent.canOverrideGeolocation(WebInspector._initializeCapability.bind(WebInspector, "canOverrideGeolocation", null));
+ PageAgent.canOverrideDeviceOrientation(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceOrientation", WebInspector._doLoadedDoneWithCapabilities.bind(WebInspector)));
}
WebInspector._doLoadedDoneWithCapabilities = function()