Merge m-i to m-c

This commit is contained in:
Phil Ringnalda 2013-12-08 18:53:55 -08:00
commit 14593afdaa
33 changed files with 539 additions and 141 deletions

View File

@ -112,6 +112,9 @@ endif
DEFINES += -DBINPATH=$(BINPATH)
DEFINES += -DMOZ_ICU_VERSION=$(MOZ_ICU_VERSION)
ifdef MOZ_NATIVE_ICU
DEFINES += -DMOZ_NATIVE_ICU
endif
ifdef MOZ_SHARED_ICU
DEFINES += -DMOZ_SHARED_ICU
endif

View File

@ -101,6 +101,7 @@
#endif
#endif
#endif
#ifndef MOZ_NATIVE_ICU
#ifdef MOZ_SHARED_ICU
#ifdef XP_WIN
#ifdef MOZ_DEBUG
@ -122,6 +123,7 @@
@BINPATH@/libicuuc.so.@MOZ_ICU_VERSION@
#endif
#endif
#endif
[browser]
; [Base Browser Files]

View File

@ -86,6 +86,7 @@ LOCAL_INCLUDES += [
'/dom/base',
'/dom/settings',
'/dom/src/storage',
'/js/xpconnect/wrappers',
'/layout/generic',
'/layout/xul',
'/layout/xul/tree/',

View File

@ -5,6 +5,7 @@
#include "base/basictypes.h"
#include "AccessCheck.h"
#include "ipc/IPCMessageUtils.h"
#include "nsCOMPtr.h"
#include "nsError.h"
@ -33,6 +34,14 @@
using namespace mozilla;
using namespace mozilla::dom;
namespace mozilla {
namespace dom {
namespace workers {
extern bool IsCurrentThreadRunningChromeWorker();
} // namespace workers
} // namespace dom
} // namespace mozilla
static char *sPopupAllowedEvents;
@ -217,6 +226,14 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
bool
nsDOMEvent::IsChrome(JSContext* aCx) const
{
return mIsMainThreadEvent ?
xpc::AccessCheck::isChrome(js::GetContextCompartment(aCx)) :
mozilla::dom::workers::IsCurrentThreadRunningChromeWorker();
}
// nsIDOMEventInterface
NS_METHOD nsDOMEvent::GetType(nsAString& aType)
{
@ -436,25 +453,40 @@ nsDOMEvent::GetIsTrusted(bool *aIsTrusted)
NS_IMETHODIMP
nsDOMEvent::PreventDefault()
{
if (mEvent->mFlags.mCancelable) {
mEvent->mFlags.mDefaultPrevented = true;
// This method is called only from C++ code which must handle default action
// of this event. So, pass true always.
PreventDefaultInternal(true);
return NS_OK;
}
// Need to set an extra flag for drag events.
if (mEvent->eventStructType == NS_DRAG_EVENT && IsTrusted()) {
nsCOMPtr<nsINode> node = do_QueryInterface(mEvent->currentTarget);
if (!node) {
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mEvent->currentTarget);
if (win) {
node = win->GetExtantDoc();
}
}
if (node && !nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
mEvent->mFlags.mDefaultPreventedByContent = true;
}
}
void
nsDOMEvent::PreventDefault(JSContext* aCx)
{
MOZ_ASSERT(aCx, "JS context must be specified");
// Note that at handling default action, another event may be dispatched.
// Then, JS in content mey be call preventDefault()
// even in the event is in system event group. Therefore, don't refer
// mInSystemGroup here.
PreventDefaultInternal(IsChrome(aCx));
}
void
nsDOMEvent::PreventDefaultInternal(bool aCalledByDefaultHandler)
{
if (!mEvent->mFlags.mCancelable) {
return;
}
return NS_OK;
mEvent->mFlags.mDefaultPrevented = true;
// Note that even if preventDefault() has already been called by chrome,
// a call of preventDefault() by content needs to overwrite
// mDefaultPreventedByContent to true because in such case, defaultPrevented
// must be true when web apps check it after they call preventDefault().
if (!aCalledByDefaultHandler) {
mEvent->mFlags.mDefaultPreventedByContent = true;
}
}
void
@ -1143,6 +1175,24 @@ const char* nsDOMEvent::GetEventName(uint32_t aEventType)
return nullptr;
}
bool
nsDOMEvent::DefaultPrevented(JSContext* aCx) const
{
MOZ_ASSERT(aCx, "JS context must be specified");
NS_ENSURE_TRUE(mEvent, false);
// If preventDefault() has never been called, just return false.
if (!mEvent->mFlags.mDefaultPrevented) {
return false;
}
// If preventDefault() has been called by content, return true. Otherwise,
// i.e., preventDefault() has been called by chrome, return true only when
// this is called by chrome.
return mEvent->mFlags.mDefaultPreventedByContent || IsChrome(aCx);
}
bool
nsDOMEvent::GetPreventDefault() const
{
@ -1151,6 +1201,9 @@ nsDOMEvent::GetPreventDefault() const
doc->WarnOnceAbout(nsIDocument::eGetPreventDefault);
}
}
// GetPreventDefault() is legacy and Gecko specific method. Although,
// the result should be same as defaultPrevented, we don't need to break
// backward compatibility of legacy method. Let's behave traditionally.
return DefaultPrevented();
}
@ -1166,6 +1219,9 @@ NS_IMETHODIMP
nsDOMEvent::GetDefaultPrevented(bool* aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
// This method must be called by only event handlers implemented by C++.
// Then, the handlers must handle default action. So, this method don't need
// to check if preventDefault() has been called by content or chrome.
*aReturn = DefaultPrevented();
return NS_OK;
}

View File

@ -153,9 +153,20 @@ public:
// xpidl implementation
// void PreventDefault();
// You MUST NOT call PreventDefaultJ(JSContext*) from C++ code. A call of
// this method always sets Event.defaultPrevented true for web contents.
// If default action handler calls this, web applications meet wrong
// defaultPrevented value.
void PreventDefault(JSContext* aCx);
// You MUST NOT call DefaultPrevented(JSContext*) from C++ code. This may
// return false even if PreventDefault() has been called.
// See comments in its implementation for the detail.
bool DefaultPrevented(JSContext* aCx) const;
bool DefaultPrevented() const
{
return mEvent && mEvent->mFlags.mDefaultPrevented;
return mEvent->mFlags.mDefaultPrevented;
}
bool MultipleActionsPrevented() const
@ -190,6 +201,20 @@ protected:
void SetEventType(const nsAString& aEventTypeArg);
already_AddRefed<nsIContent> GetTargetFromFrame();
/**
* IsChrome() returns true if aCx is chrome context or the event is created
* in chrome's thread. Otherwise, false.
*/
bool IsChrome(JSContext* aCx) const;
/**
* @param aCalledByDefaultHandler Should be true when this is called by
* C++ or Chrome. Otherwise, e.g., called
* by a call of Event.preventDefault() in
* content script, false.
*/
void PreventDefaultInternal(bool aCalledByDefaultHandler);
mozilla::WidgetEvent* mEvent;
nsRefPtr<nsPresContext> mPresContext;
nsCOMPtr<mozilla::dom::EventTarget> mExplicitOriginalTarget;

View File

@ -2610,10 +2610,13 @@ nsEventStateManager::DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
nsWeakFrame targetFrame(aTargetFrame);
nsEventStatus statusX = *aStatus;
nsEventStatus statusY = *aStatus;
MOZ_ASSERT(*aStatus != nsEventStatus_eConsumeNoDefault &&
!aEvent->mFlags.mDefaultPrevented,
"If you make legacy events dispatched for default prevented wheel "
"event, you need to initialize stateX and stateY");
EventState stateX, stateY;
if (scrollDeltaY) {
SendLineScrollEvent(aTargetFrame, aEvent, &statusY,
SendLineScrollEvent(aTargetFrame, aEvent, stateY,
scrollDeltaY, DELTA_DIRECTION_Y);
if (!targetFrame.IsAlive()) {
*aStatus = nsEventStatus_eConsumeNoDefault;
@ -2622,7 +2625,7 @@ nsEventStateManager::DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
}
if (pixelDeltaY) {
SendPixelScrollEvent(aTargetFrame, aEvent, &statusY,
SendPixelScrollEvent(aTargetFrame, aEvent, stateY,
pixelDeltaY, DELTA_DIRECTION_Y);
if (!targetFrame.IsAlive()) {
*aStatus = nsEventStatus_eConsumeNoDefault;
@ -2631,7 +2634,7 @@ nsEventStateManager::DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
}
if (scrollDeltaX) {
SendLineScrollEvent(aTargetFrame, aEvent, &statusX,
SendLineScrollEvent(aTargetFrame, aEvent, stateX,
scrollDeltaX, DELTA_DIRECTION_X);
if (!targetFrame.IsAlive()) {
*aStatus = nsEventStatus_eConsumeNoDefault;
@ -2640,7 +2643,7 @@ nsEventStateManager::DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
}
if (pixelDeltaX) {
SendPixelScrollEvent(aTargetFrame, aEvent, &statusX,
SendPixelScrollEvent(aTargetFrame, aEvent, stateX,
pixelDeltaX, DELTA_DIRECTION_X);
if (!targetFrame.IsAlive()) {
*aStatus = nsEventStatus_eConsumeNoDefault;
@ -2648,21 +2651,18 @@ nsEventStateManager::DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
}
}
if (statusY == nsEventStatus_eConsumeNoDefault ||
statusX == nsEventStatus_eConsumeNoDefault) {
if (stateY.mDefaultPrevented || stateX.mDefaultPrevented) {
*aStatus = nsEventStatus_eConsumeNoDefault;
return;
}
if (statusY == nsEventStatus_eConsumeDoDefault ||
statusX == nsEventStatus_eConsumeDoDefault) {
*aStatus = nsEventStatus_eConsumeDoDefault;
aEvent->mFlags.mDefaultPrevented = true;
aEvent->mFlags.mDefaultPreventedByContent |=
stateY.mDefaultPreventedByContent || stateX.mDefaultPreventedByContent;
}
}
void
nsEventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
WidgetWheelEvent* aEvent,
nsEventStatus* aStatus,
EventState& aState,
int32_t aDelta,
DeltaDirection aDeltaDirection)
{
@ -2678,9 +2678,8 @@ nsEventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
WidgetMouseScrollEvent event(aEvent->mFlags.mIsTrusted, NS_MOUSE_SCROLL,
aEvent->widget);
if (*aStatus == nsEventStatus_eConsumeNoDefault) {
event.mFlags.mDefaultPrevented = true;
}
event.mFlags.mDefaultPrevented = aState.mDefaultPrevented;
event.mFlags.mDefaultPreventedByContent = aState.mDefaultPreventedByContent;
event.refPoint = aEvent->refPoint;
event.widget = aEvent->widget;
event.time = aEvent->time;
@ -2690,14 +2689,18 @@ nsEventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
event.delta = aDelta;
event.inputSource = aEvent->inputSource;
nsEventStatus status = nsEventStatus_eIgnore;
nsEventDispatcher::Dispatch(targetContent, aTargetFrame->PresContext(),
&event, nullptr, aStatus);
&event, nullptr, &status);
aState.mDefaultPrevented =
event.mFlags.mDefaultPrevented || status == nsEventStatus_eConsumeNoDefault;
aState.mDefaultPreventedByContent = event.mFlags.mDefaultPreventedByContent;
}
void
nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
WidgetWheelEvent* aEvent,
nsEventStatus* aStatus,
EventState& aState,
int32_t aPixelDelta,
DeltaDirection aDeltaDirection)
{
@ -2714,9 +2717,8 @@ nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
WidgetMouseScrollEvent event(aEvent->mFlags.mIsTrusted, NS_MOUSE_PIXEL_SCROLL,
aEvent->widget);
if (*aStatus == nsEventStatus_eConsumeNoDefault) {
event.mFlags.mDefaultPrevented = true;
}
event.mFlags.mDefaultPrevented = aState.mDefaultPrevented;
event.mFlags.mDefaultPreventedByContent = aState.mDefaultPreventedByContent;
event.refPoint = aEvent->refPoint;
event.widget = aEvent->widget;
event.time = aEvent->time;
@ -2726,8 +2728,12 @@ nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
event.delta = aPixelDelta;
event.inputSource = aEvent->inputSource;
nsEventStatus status = nsEventStatus_eIgnore;
nsEventDispatcher::Dispatch(targetContent, aTargetFrame->PresContext(),
&event, nullptr, aStatus);
&event, nullptr, &status);
aState.mDefaultPrevented =
event.mFlags.mDefaultPrevented || status == nsEventStatus_eConsumeNoDefault;
aState.mDefaultPreventedByContent = event.mFlags.mDefaultPreventedByContent;
}
nsIScrollableFrame*

View File

@ -481,6 +481,17 @@ protected:
DELTA_DIRECTION_Y
};
struct MOZ_STACK_CLASS EventState
{
bool mDefaultPrevented;
bool mDefaultPreventedByContent;
EventState() :
mDefaultPrevented(false), mDefaultPreventedByContent(false)
{
}
};
/**
* SendLineScrollEvent() dispatches a DOMMouseScroll event for the
* WidgetWheelEvent. This method shouldn't be called for non-trusted
@ -488,14 +499,15 @@ protected:
*
* @param aTargetFrame The event target of wheel event.
* @param aEvent The original Wheel event.
* @param aStatus The event status, must not be
* nsEventStatus_eConsumeNoDefault.
* @param aState The event which should be set to the dispatching
* event. This also returns the dispatched event
* state.
* @param aDelta The delta value of the event.
* @param aDeltaDirection The X/Y direction of dispatching event.
*/
void SendLineScrollEvent(nsIFrame* aTargetFrame,
mozilla::WidgetWheelEvent* aEvent,
nsEventStatus* aStatus,
EventState& aState,
int32_t aDelta,
DeltaDirection aDeltaDirection);
@ -506,14 +518,15 @@ protected:
*
* @param aTargetFrame The event target of wheel event.
* @param aEvent The original Wheel event.
* @param aStatus The event status, must not be
* nsEventStatus_eConsumeNoDefault.
* @param aState The event which should be set to the dispatching
* event. This also returns the dispatched event
* state.
* @param aPixelDelta The delta value of the event.
* @param aDeltaDirection The X/Y direction of dispatching event.
*/
void SendPixelScrollEvent(nsIFrame* aTargetFrame,
mozilla::WidgetWheelEvent* aEvent,
nsEventStatus* aStatus,
EventState& aState,
int32_t aPixelDelta,
DeltaDirection aDeltaDirection);

View File

@ -15,4 +15,5 @@ support-files =
[test_bug602962.xul]
[test_bug617528.xul]
[test_bug679494.xul]
[test_bug930374-chrome.html]
[test_eventctors.xul]

View File

@ -83,6 +83,7 @@ skip-if = true # Disabled due to timeouts.
[test_bug847597.html]
[test_bug855741.html]
[test_bug864040.html]
[test_bug930374-content.html]
skip-if = toolkit == "gonk"
[test_clickevent_on_input.html]
[test_continuous_wheel_events.html]

View File

@ -0,0 +1,59 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=930374
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 930374</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=930374">Mozilla Bug 930374</a>
<div id="display">
<input id="input-text">
</div>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
var gKeyPress = null;
function onKeyPress(aEvent)
{
gKeyPress = aEvent;
is(aEvent.target, document.getElementById("input-text"), "input element should have focus");
ok(!aEvent.defaultPrevented, "keypress event should be consumed before keypress event handler");
}
function runTests()
{
document.addEventListener("keypress", onKeyPress, false);
var input = document.getElementById("input-text");
input.focus();
input.addEventListener("input", function (aEvent) {
input.removeEventListener("input", arguments.callee, false);
ok(gKeyPress,
"Test1: keypress event must be fired before an input event");
ok(gKeyPress.defaultPrevented,
"Test1: keypress event's defaultPrevented should be true in chrome even if it's consumed by default action handler of editor");
setTimeout(function () {
ok(gKeyPress.defaultPrevented,
"Test2: keypress event's defaultPrevented should be true after event dispatching finished");
SimpleTest.finish();
}, 0);
}, false);
sendChar("a");
}
SimpleTest.waitForFocus(runTests);
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,72 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=930374
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 930374</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=930374">Mozilla Bug 930374</a>
<div id="display">
<input id="input-text">
</div>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
var gKeyPress = null;
function onKeyPress(aEvent)
{
gKeyPress = aEvent;
is(aEvent.target, document.getElementById("input-text"), "input element should have focus");
ok(!aEvent.defaultPrevented, "keypress event should be consumed before keypress event handler");
}
function runTests()
{
document.addEventListener("keypress", onKeyPress, false);
var input = document.getElementById("input-text");
input.focus();
input.addEventListener("input", function (aEvent) {
input.removeEventListener("input", arguments.callee, false);
ok(gKeyPress,
"Test1: keypress event must be fired before an input event");
ok(!gKeyPress.defaultPrevented,
"Test1: keypress event's defaultPrevented should be false even though it's consumed by the default action handler of editor");
gKeyPress.preventDefault();
ok(gKeyPress.defaultPrevented,
"Test1: keypress event's defaultPrevented should become true because of a call of preventDefault()");
}, false);
sendChar("a");
gKeyPress = null;
input.addEventListener("input", function (aEvent) {
input.removeEventListener("input", arguments.callee, false);
ok(gKeyPress,
"Test2: keypress event must be fired before an input event");
ok(!gKeyPress.defaultPrevented,
"Test2: keypress event's defaultPrevented should be false even though it's consumed by the default action handler of editor");
setTimeout(function () {
ok(!gKeyPress.defaultPrevented,
"Test2: keypress event's defaultPrevented should not become true after event dispatching finished");
SimpleTest.finish();
}, 0);
}, false);
sendChar("b");
}
SimpleTest.waitForFocus(runTests);
</script>
</pre>
</body>
</html>

View File

@ -3835,11 +3835,10 @@ HTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
// the editor's handling of up/down keypress events. For that reason we
// just ignore aVisitor.mEventStatus here and go ahead and handle the
// event to increase/decrease the value of the number control.
// XXX we still need to allow script to call preventDefault() on the
// event, but right now we can't tell the difference between the editor
// on script doing that (bug 930374).
StepNumberControlForUserEvent(keyEvent->keyCode == NS_VK_UP ? 1 : -1);
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
if (!aVisitor.mEvent->mFlags.mDefaultPreventedByContent) {
StepNumberControlForUserEvent(keyEvent->keyCode == NS_VK_UP ? 1 : -1);
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
} else if (nsEventStatus_eIgnore == aVisitor.mEventStatus) {
switch (aVisitor.mEvent->message) {

View File

@ -177,6 +177,16 @@ function test() {
expectedVal = expectedValAfterKeyEvent(key, elem);
synthesizeKey(key, {});
is(elem.value, expectedVal, "Test repeat of " + key + " for number control");
// Test preventDefault():
elem.addEventListener("keypress", function(evt) {
evt.preventDefault();
elem.removeEventListener("keypress", arguments.callee, false);
}, false);
oldVal = elem.value = 0;
expectedVal = 0;
synthesizeKey(key, {});
is(elem.value, expectedVal, "Test " + key + " for number control where scripted preventDefault() should prevent the value changing");
}
}

View File

@ -161,8 +161,6 @@ AudioStream::~AudioStream()
Preferences::RegisterCallback(PrefChanged, PREF_VOLUME_SCALE);
PrefChanged(PREF_CUBEB_LATENCY, nullptr);
Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_LATENCY);
InitPreferredSampleRate();
}
/*static*/ void AudioStream::ShutdownLibrary()
@ -267,16 +265,28 @@ int64_t AudioStream::GetWritten()
return 0;
}
/*static */ void AudioStream::InitPreferredSampleRate()
/*static*/ int AudioStream::PreferredSampleRate()
{
const int fallbackSampleRate = 44100;
StaticMutexAutoLock lock(sMutex);
if (sPreferredSampleRate != 0) {
return sPreferredSampleRate;
}
cubeb* cubebContext = GetCubebContextUnlocked();
if (!cubebContext) {
sPreferredSampleRate = fallbackSampleRate;
}
// Get the preferred samplerate for this platform, or fallback to something
// sensible if we fail. We cache the value, because this might be accessed
// often, and the complexity of the function call below depends on the
// backend used.
if (cubeb_get_preferred_sample_rate(GetCubebContext(),
if (cubeb_get_preferred_sample_rate(cubebContext,
&sPreferredSampleRate) != CUBEB_OK) {
sPreferredSampleRate = 44100;
sPreferredSampleRate = fallbackSampleRate;
}
return sPreferredSampleRate;
}
static void SetUint16LE(uint8_t* aDest, uint16_t aValue)

View File

@ -179,13 +179,9 @@ public:
// Returns the maximum number of channels supported by the audio hardware.
static int MaxNumberOfChannels();
static void InitPreferredSampleRate();
// Returns the samplerate the systems prefer, because it is the
// samplerate the hardware/mixer supports.
static int PreferredSampleRate() {
MOZ_ASSERT(sPreferredSampleRate);
return sPreferredSampleRate;
}
static int PreferredSampleRate();
AudioStream();
~AudioStream();
@ -377,14 +373,14 @@ private:
StreamState mState;
// This mutex protects the static members below.
static StaticMutex sMutex;
static cubeb* sCubebContext;
// Prefered samplerate, in Hz (characteristic of the
// hardware/mixer/platform/API used).
static uint32_t sPreferredSampleRate;
// This mutex protects the static members below
static StaticMutex sMutex;
static cubeb* sCubebContext;
static double sVolumeScale;
static uint32_t sCubebLatency;
static bool sCubebLatencyPrefSet;

View File

@ -385,6 +385,7 @@ DOMInterfaces = {
'Event': {
'nativeType': 'nsDOMEvent',
'implicitJSContext': [ 'defaultPrevented', 'preventDefault' ],
},
'EventTarget': {

View File

@ -9,3 +9,4 @@ support-files = green.png
[test_bug635636.html]
[test_bug780908.xul]
[test_contenteditable_text_input_handling.html]
[test_htmleditor_keyevent_handling.html]

View File

@ -130,7 +130,6 @@ support-files =
[test_bug857487.html]
[test_contenteditable_focus.html]
[test_dom_input_event_on_htmleditor.html]
[test_htmleditor_keyevent_handling.html]
[test_keypress_untrusted_event.html]
[test_root_element_replacement.html]
[test_select_all_without_body.html]

View File

@ -2,11 +2,11 @@
<head>
<title>Test for key event handler of HTML editor</title>
<script type="text/javascript"
src="/tests/SimpleTest/SimpleTest.js"></script>
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript"
src="/tests/SimpleTest/EventUtils.js"></script>
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css"
href="/tests/SimpleTest/test.css" />
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<div id="display">

View File

@ -6,7 +6,7 @@
# disables the key handling test on gtk because gtk overrides some key events
# on our editor, and the combinations depend on the system.
ifndef MOZ_WIDGET_GTK
MOCHITEST_FILES += \
MOCHITEST_CHROME_FILES += \
test_texteditor_keyevent_handling.html \
$(NULL)
endif

View File

@ -2,11 +2,11 @@
<head>
<title>Test for key event handler of text editor</title>
<script type="text/javascript"
src="/tests/SimpleTest/SimpleTest.js"></script>
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript"
src="/tests/SimpleTest/EventUtils.js"></script>
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css"
href="/tests/SimpleTest/test.css" />
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<div id="display">

View File

@ -2548,10 +2548,30 @@ nsDisplayBorder::Paint(nsDisplayListBuilder* aBuilder,
nsRect
nsDisplayBorder::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
{
nsRect borderBounds(ToReferenceFrame(), mFrame->GetSize());
borderBounds.Inflate(mFrame->StyleBorder()->GetImageOutset());
*aSnap = true;
return borderBounds;
const nsStyleBorder *styleBorder = mFrame->StyleBorder();
nsRect borderBounds(ToReferenceFrame(), mFrame->GetSize());
if (styleBorder->IsBorderImageLoaded()) {
borderBounds.Inflate(mFrame->StyleBorder()->GetImageOutset());
return borderBounds;
} else {
nsMargin border = styleBorder->GetComputedBorder();
nsRect result;
if (border.top > 0) {
result = nsRect(borderBounds.X(), borderBounds.Y(), borderBounds.Width(), border.top);
}
if (border.right > 0) {
result.UnionRect(result, nsRect(borderBounds.XMost() - border.right, borderBounds.Y(), border.right, borderBounds.Height()));
}
if (border.bottom > 0) {
result.UnionRect(result, nsRect(borderBounds.X(), borderBounds.YMost() - border.bottom, borderBounds.Width(), border.bottom));
}
if (border.left > 0) {
result.UnionRect(result, nsRect(borderBounds.X(), borderBounds.Y(), border.left, borderBounds.Height()));
}
return result;
}
}
// Given a region, compute a conservative approximation to it as a list

View File

@ -32,8 +32,9 @@ function focus_area() {
// working directly after page load, hence it is retried 10 times, see bug bug 922524
timer = setInterval(function() {
if (counter > 10) {
clearInterval(timer);
parent.ok(false, "Too often tried to focus image map, giving up");
parent.Simpletest.finish();
parent.finish();
return;
}
synthesizeKey("VK_TAB", { shiftKey: shiftKeyOn }, window);

View File

@ -32,8 +32,9 @@ function focus_area() {
// working directly after page load, hence it is retried 10 times, see bug bug 922524
timer = setInterval(function() {
if (counter > 10) {
clearInterval(timer);
parent.ok(false, "Too often tried to focus image map, giving up");
parent.Simpletest.finish();
parent.finish();
return;
}
synthesizeKey("VK_TAB", { shiftKey: shiftKeyOn }, window);

View File

@ -30,6 +30,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=448987
/** Test for Bug 448987 **/
SimpleTest.waitForExplicitFinish();
SpecialPowers.setIntPref("accessibility.tabfocus", 7);
var f1 = document.getElementById("f1");
var f2 = document.getElementById("f2");
var f3 = document.getElementById("f3");
@ -56,6 +58,12 @@ function thirdIframeLoaded() {
ok(compareSnapshots(snapshotf1,
snapshotWindow(f3.contentWindow), false)[0],
"file_bug448987.html should render focus outline, file_bug448987_notref.html should not");
finish();
}
function finish()
{
SpecialPowers.clearUserPref("accessibility.tabfocus");
SimpleTest.finish();
}
</script>

View File

@ -2504,7 +2504,7 @@ nsRuleNode::AdjustLogicalBoxProp(nsStyleContext* aContext,
bool canStoreInRuleTree = aCanStoreInRuleTree;
/**
* Begin an nsRuleNode::Compute*Data function for an inherited struct.
* End an nsRuleNode::Compute*Data function for an inherited struct.
*
* @param type_ The nsStyle* type this function computes.
* @param data_ Variable holding the result of this function.
@ -2539,7 +2539,7 @@ nsRuleNode::AdjustLogicalBoxProp(nsStyleContext* aContext,
return data_;
/**
* Begin an nsRuleNode::Compute*Data function for a reset struct.
* End an nsRuleNode::Compute*Data function for a reset struct.
*
* @param type_ The nsStyle* type this function computes.
* @param data_ Variable holding the result of this function.

View File

@ -2267,7 +2267,7 @@ nsStyleAnimation::AddWeighted(nsCSSProperty aProperty,
if (list2) {
list2 = list2->mNext;
}
};
}
NS_ABORT_IF_FALSE(!*resultTail,
"resultTail isn't pointing to the tail (may leak)");

View File

@ -20,6 +20,7 @@ EXPORTS += [
'nsCacheService.h',
]
# These files cannot be built in unified mode because they force NSPR logging.
SOURCES += [
'nsApplicationCacheService.cpp',
'nsCache.cpp',

View File

@ -9,6 +9,7 @@
* synthesizeMouseAtCenter
* synthesizeWheel
* synthesizeKey
* synthesizeNativeKey
* synthesizeMouseExpectEvent
* synthesizeKeyExpectEvent
*
@ -568,6 +569,114 @@ function synthesizeKey(aKey, aEvent, aWindow)
}
}
function _parseNativeModifiers(aModifiers)
{
var modifiers;
if (aModifiers.capsLockKey) {
modifiers |= 0x00000001;
}
if (aModifiers.numLockKey) {
modifiers |= 0x00000002;
}
if (aModifiers.shiftKey) {
modifiers |= 0x00000100;
}
if (aModifiers.shiftRightKey) {
modifiers |= 0x00000200;
}
if (aModifiers.ctrlKey) {
modifiers |= 0x00000400;
}
if (aModifiers.ctrlRightKey) {
modifiers |= 0x00000800;
}
if (aModifiers.altKey) {
modifiers |= 0x00001000;
}
if (aModifiers.altRightKey) {
modifiers |= 0x00002000;
}
if (aModifiers.metaKey) {
modifiers |= 0x00004000;
}
if (aModifiers.metaRightKey) {
modifiers |= 0x00008000;
}
if (aModifiers.helpKey) {
modifiers |= 0x00010000;
}
if (aModifiers.fnKey) {
modifiers |= 0x00100000;
}
if (aModifiers.numericKeyPadKey) {
modifiers |= 0x01000000;
}
if (aModifiers.accelKey) {
modifiers |=
(navigator.platform.indexOf("Mac") == 0) ? 0x00004000 : 0x00000400;
}
if (aModifiers.accelRightKey) {
modifiers |=
(navigator.platform.indexOf("Mac") == 0) ? 0x00008000 : 0x00000800;
}
return modifiers;
}
const KEYBOARD_LAYOUT_EN_US = 0;
/**
* synthesizeNativeKey() dispatches native key event on active window.
* This is implemented only on Windows and Mac.
*
* @param aKeyboardLayout One of KEYBOARD_LAYOUT_* defined above.
* @param aNativeKeyCode A native keycode value defined in
* NativeKeyCodes.js.
* @param aModifiers Modifier keys. If no modifire key is pressed,
* this must be {}. Otherwise, one or more items
* referred in _parseNativeModifiers() must be
* true.
* @param aChars Specify characters which should be generated
* by the key event.
* @param aUnmodifiedChars Specify characters of unmodified (except Shift)
* aChar value.
* @return True if this function succeed dispatching
* native key event. Otherwise, false.
*/
function synthesizeNativeKey(aKeyboardLayout, aNativeKeyCode, aModifiers,
aChars, aUnmodifiedChars)
{
var utils = _getDOMWindowUtils(window);
if (!utils) {
return false;
}
var nativeKeyboardLayout;
if (navigator.platform.indexOf("Mac") == 0) {
switch (aKeyboardLayout) {
case KEYBOARD_LAYOUT_EN_US:
nativeKeyboardLayout = 0;
break;
default:
return false;
}
} else if (navigator.platform.indexOf("Win") == 0) {
switch (aKeyboardLayout) {
case KEYBOARD_LAYOUT_EN_US:
nativeKeyboardLayout = 0x409;
break;
default:
return false;
}
} else {
return false;
}
utils.sendNativeKeyEvent(nativeKeyboardLayout, aNativeKeyCode,
_parseNativeModifiers(aModifiers),
aChars, aUnmodifiedChars);
return true;
}
var _gSeenEvent = false;
/**

View File

@ -26,7 +26,6 @@ support-files = window_composition_text_querycontent.xul
[test_position_on_resize.xul]
[test_sizemode_events.xul]
[test_bug760802.xul]
[test_assign_event_data.html]
# Cocoa
[test_native_menus.xul]

View File

@ -1,3 +1,5 @@
[test_assign_event_data.html]
skip-if = toolkit == "cocoa" # Bug 933303
[test_bug565392.html]
skip-if = toolkit != "windows"
[test_picker_no_crash.html]

View File

@ -2,11 +2,10 @@
<html>
<head>
<title>Testing ns*Event::Assign*EventData()</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/NativeKeyCodes.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<style>
#a {
background-color: transparent;
@ -50,16 +49,19 @@
SimpleTest.waitForExplicitFinish();
var gUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
const kIsMac = (navigator.platform.indexOf("Mac") == 0);
const kIsWin = (navigator.platform.indexOf("Win") == 0);
var gEvent = null;
var gCopiedEvent = [];
var gCallback = null;
var gCallPreventDefault = false;
function onEvent(aEvent)
{
if (gCallPreventDefault) {
aEvent.preventDefault();
}
gEvent = aEvent;
for (var attr in aEvent) {
if (!attr.match(/^[A-Z0-9_]+$/) && // ignore const attributes
@ -71,13 +73,6 @@ function onEvent(aEvent)
setTimeout(gCallback, 0);
}
const WIN_KL_US = 0x409;
const MAC_KL_US = 0;
const NATIVE_SHIFT_LEFT = 0x0100;
const NATIVE_CONTROL_RIGHT = 0x0800;
const NATIVE_META_RIGHT = 0x8000;
const kTests = [
{ description: "InternalScriptErrorEvent",
targetID: "input-text", eventType: "error",
@ -137,11 +132,8 @@ const kTests = [
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
if (kIsWin) {
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_A, 0, "a", "a");
} else if (kIsMac) {
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_A, 0, "a", "a");
}
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_A : MAC_VK_ANSI_A,
{}, "a", "a");
},
canRun: function () {
return (kIsMac || kIsWin);
@ -153,11 +145,8 @@ const kTests = [
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
if (kIsWin) {
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_A, 0, "a", "a");
} else if (kIsMac) {
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_A, 0, "a", "a");
}
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_A : MAC_VK_ANSI_A,
{}, "a", "a");
},
canRun: function () {
return (kIsMac || kIsWin);
@ -169,34 +158,26 @@ const kTests = [
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
if (kIsWin) {
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_B, NATIVE_SHIFT_LEFT, "B", "B");
} else if (kIsMac) {
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_B, NATIVE_SHIFT_LEFT, "B", "B");
}
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_B : MAC_VK_ANSI_B,
{ shiftKey: true }, "B", "B");
},
canRun: function () {
return (kIsMac || kIsWin);
},
// "defaultPrevented" becomes true because the editor consumes the keypress event.
todoMismatch: [ "defaultPrevented" ],
todoMismatch: [],
},
{ description: "WidgetKeyboardEvent (keypress of 'c' key with Accel)",
targetID: "input-text", eventType: "keypress",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
if (kIsWin) {
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_C, NATIVE_CONTROL_RIGHT, "\u0003", "c");
} else if (kIsMac) {
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_C, NATIVE_META_RIGHT, "c", "c");
}
synthesizeNativeKey(KEYBOARD_LAYOUT_EN_US, kIsWin ? WIN_VK_C : MAC_VK_ANSI_C,
{ accelKey: true }, kIsWin ? "\u0003" : "c", "c");
},
canRun: function () {
return (kIsMac || kIsWin);
},
// "defaultPrevented" becomes true because the editor consumes the keypress event.
todoMismatch: [ "defaultPrevented" ],
todoMismatch: [],
},
{ description: "WidgetMouseEvent (mousedown of left button without modifier)",
targetID: "button", eventType: "mousedown",
@ -539,21 +520,22 @@ function doTest(aTest)
var target = aTest.target ? aTest.target() : document.getElementById(aTest.targetID);
target.addEventListener(aTest.eventType, onEvent, true);
gCallback = function () {
var description = aTest.description + " (gCallPreventDefault=" + gCallPreventDefault + ")";
target.removeEventListener(aTest.eventType, onEvent, true);
ok(gEvent !== null, aTest.description + ": failed to get duplicated event");
ok(gCopiedEvent.length > 0, aTest.description + ": count of attribute of the event must be larger than 0");
ok(gEvent !== null, description + ": failed to get duplicated event");
ok(gCopiedEvent.length > 0, description + ": count of attribute of the event must be larger than 0");
for (var i = 0; i < gCopiedEvent.length; ++i) {
var name = gCopiedEvent[i].name;
if (name == "rangeOffset") {
todo(false, aTest.description + ": " + name + " attribute value is never reset (" + gEvent[name] + ")");
todo(false, description + ": " + name + " attribute value is never reset (" + gEvent[name] + ")");
} else if (name == "eventPhase") {
is(gEvent[name], 0, aTest.description + ": mismatch with fixed value (" + name + ")");
is(gEvent[name], 0, description + ": mismatch with fixed value (" + name + ")");
} else if (name == "rangeParent" || name == "currentTarget") {
is(gEvent[name], null, aTest.description + ": mismatch with fixed value (" + name + ")");
is(gEvent[name], null, description + ": mismatch with fixed value (" + name + ")");
} else if (aTest.todoMismatch.indexOf(name) >= 0) {
todo_is(gEvent[name], gCopiedEvent[i].value, aTest.description + ": mismatch (" + name + ")");
todo_is(gEvent[name], gCopiedEvent[i].value, description + ": mismatch (" + name + ")");
} else {
is(gEvent[name], gCopiedEvent[i].value, aTest.description + ": mismatch (" + name + ")");
is(gEvent[name], gCopiedEvent[i].value, description + ": mismatch (" + name + ")");
}
}
runNextTest();
@ -565,7 +547,27 @@ var gIndex = -1;
function runNextTest()
{
if (++gIndex == kTests.length) {
finish();
if (gCallPreventDefault) {
finish();
return;
}
// Test with a call of preventDefault() of the events.
gCallPreventDefault = true;
gIndex = -1;
// Restoring the initial state of all elements.
document.getElementById("scrollable-div").style.height = "30px";
document.getElementById("scrollable-div").style.width = "30px";
document.getElementById("scrolled-div").style.height = "10px";
document.getElementById("scrolled-div").style.width = "10px";
document.getElementById("input-text").value = "";
document.getElementById("animated-div").className = "";
document.getElementById("animated-div").removeAttribute("x-data");
if (document.activeElement) {
document.activeElement.blur();
}
window.requestAnimationFrame(function () {
setTimeout(runNextTest, 0);
});
return;
}
doTest(kTests[gIndex]);

View File

@ -38,10 +38,10 @@ protected:
typedef bool (* nsBaseArrayEnumFunc)
(void* aElement, void *aData);
// enumerate through the array with a callback.
bool EnumerateForwards(nsBaseArrayEnumFunc aFunc, void* aData) const;
bool EnumerateBackwards(nsBaseArrayEnumFunc aFunc, void* aData) const;
typedef int (* nsBaseArrayComparatorFunc)
@ -121,7 +121,7 @@ public:
nsISupports* ElementAt(uint32_t aIndex) const {
return mArray[aIndex];
}
nsISupports* SafeObjectAt(int32_t aIndex) const {
return mArray.SafeElementAt(aIndex, nullptr);
}
@ -172,7 +172,7 @@ public:
mozilla::MallocSizeOf aMallocSizeOf, void* aData = nullptr) const;
private:
// the actual storage
nsTArray<nsISupports*> mArray;
@ -193,8 +193,8 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
uint32_t aFlags = 0)
{
aFlags |= CycleCollectionEdgeNameArrayFlag;
size_t length = aField.Count();
for (size_t i = 0; i < length; ++i) {
int32_t length = aField.Count();
for (int32_t i = 0; i < length; ++i) {
CycleCollectionNoteChild(aCallback, aField[i], aName, aFlags);
}
}
@ -226,7 +226,7 @@ class nsCOMArray : public nsCOMArray_base
explicit
nsCOMArray(int32_t aCount) : nsCOMArray_base(aCount) {}
explicit
nsCOMArray(const nsCOMArray<T>& aOther) : nsCOMArray_base(aOther) { }
@ -315,7 +315,7 @@ class nsCOMArray : public nsCOMArray_base
// bool enumerate(T* aElement, void* aData)
typedef bool (* nsCOMArrayEnumFunc)
(T* aElement, void *aData);
// enumerate through the array with a callback.
bool EnumerateForwards(nsCOMArrayEnumFunc aFunc, void* aData) {
return nsCOMArray_base::EnumerateForwards(nsBaseArrayEnumFunc(aFunc),
@ -326,10 +326,10 @@ class nsCOMArray : public nsCOMArray_base
return nsCOMArray_base::EnumerateBackwards(nsBaseArrayEnumFunc(aFunc),
aData);
}
typedef int (* nsCOMArrayComparatorFunc)
(T* aElement1, T* aElement2, void* aData);
void Sort(nsCOMArrayComparatorFunc aFunc, void* aData) {
nsCOMArray_base::Sort(nsBaseArrayComparatorFunc(aFunc), aData);
}
@ -354,7 +354,7 @@ class nsCOMArray : public nsCOMArray_base
void AppendElements(T* const* aElements, uint32_t aCount) {
InsertElementsAt(Length(), aElements, aCount);
}
// remove the first instance of the given object and shrink the
// array as necessary
// Warning: if you pass null here, it will remove the first null element
@ -378,7 +378,7 @@ class nsCOMArray : public nsCOMArray_base
// the memory taken by the T itself as well as anything it points to.
typedef size_t (* nsCOMArraySizeOfElementIncludingThisFunc)
(T* aElement, mozilla::MallocSizeOf aMallocSizeOf, void *aData);
size_t SizeOfExcludingThis(
nsCOMArraySizeOfElementIncludingThisFunc aSizeOfElementIncludingThis,
mozilla::MallocSizeOf aMallocSizeOf, void *aData = nullptr) const {
@ -408,8 +408,8 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
uint32_t aFlags = 0)
{
aFlags |= CycleCollectionEdgeNameArrayFlag;
size_t length = aField.Count();
for (size_t i = 0; i < length; ++i) {
int32_t length = aField.Count();
for (int32_t i = 0; i < length; ++i) {
CycleCollectionNoteChild(aCallback, aField[i], aName, aFlags);
}
}