2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-02-05 16:26:23 +00:00
|
|
|
|
2013-01-06 06:25:54 +00:00
|
|
|
#include "mozilla/dom/SVGSwitchElement.h"
|
2013-04-25 09:18:42 +00:00
|
|
|
|
2014-11-06 09:30:11 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2008-07-13 11:30:48 +00:00
|
|
|
#include "nsSVGUtils.h"
|
2011-05-27 04:53:03 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-01-06 06:25:54 +00:00
|
|
|
#include "mozilla/dom/SVGSwitchElementBinding.h"
|
2011-05-27 04:53:03 +00:00
|
|
|
|
2013-03-11 22:05:58 +00:00
|
|
|
class nsIFrame;
|
|
|
|
|
2013-01-06 06:25:54 +00:00
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Switch)
|
2007-02-05 16:26:23 +00:00
|
|
|
|
2013-01-06 06:25:54 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2007-02-05 16:26:23 +00:00
|
|
|
|
2013-01-06 06:25:54 +00:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
SVGSwitchElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-06 06:25:54 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return SVGSwitchElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-06 06:25:54 +00:00
|
|
|
}
|
2007-02-05 16:26:23 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGSwitchElement, SVGSwitchElementBase,
|
|
|
|
mActiveChild)
|
2008-12-30 16:32:22 +00:00
|
|
|
|
2013-01-06 06:25:54 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGSwitchElement,SVGSwitchElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGSwitchElement,SVGSwitchElementBase)
|
2010-01-12 13:08:43 +00:00
|
|
|
|
2013-05-21 19:59:27 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SVGSwitchElement)
|
2013-01-06 06:25:54 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(SVGSwitchElementBase)
|
2007-02-05 16:26:23 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
SVGSwitchElement::SVGSwitchElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-06 06:25:54 +00:00
|
|
|
: SVGSwitchElementBase(aNodeInfo)
|
2007-02-05 16:26:23 +00:00
|
|
|
{
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
2007-02-05 16:26:23 +00:00
|
|
|
|
2014-07-08 21:23:16 +00:00
|
|
|
SVGSwitchElement::~SVGSwitchElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-07-13 11:30:48 +00:00
|
|
|
void
|
2013-01-06 06:25:54 +00:00
|
|
|
SVGSwitchElement::MaybeInvalidate()
|
2008-07-13 11:30:48 +00:00
|
|
|
{
|
2012-03-20 12:15:53 +00:00
|
|
|
// We must not change mActiveChild until after
|
|
|
|
// InvalidateAndScheduleBoundsUpdate has been called, otherwise
|
|
|
|
// it will not correctly invalidate the old mActiveChild area.
|
2012-03-12 00:23:35 +00:00
|
|
|
|
2012-03-20 12:15:53 +00:00
|
|
|
nsIContent *newActiveChild = FindActiveChild();
|
|
|
|
|
|
|
|
if (newActiveChild == mActiveChild) {
|
2009-05-07 19:37:33 +00:00
|
|
|
return;
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
2007-02-05 16:26:23 +00:00
|
|
|
|
2009-05-07 19:37:33 +00:00
|
|
|
nsIFrame *frame = GetPrimaryFrame();
|
|
|
|
if (frame) {
|
2014-11-06 09:30:11 +00:00
|
|
|
nsLayoutUtils::PostRestyleEvent(
|
|
|
|
this, nsRestyleHint(0),
|
|
|
|
nsChangeHint_InvalidateRenderingObservers);
|
2012-11-28 09:42:13 +00:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(frame);
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
2012-03-20 12:15:53 +00:00
|
|
|
|
|
|
|
mActiveChild = newActiveChild;
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
2007-02-05 16:26:23 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
|
|
|
|
2013-01-06 06:25:54 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGSwitchElement)
|
2007-02-05 16:26:23 +00:00
|
|
|
|
2008-07-13 11:30:48 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsINode methods
|
|
|
|
|
|
|
|
nsresult
|
2013-01-06 06:25:54 +00:00
|
|
|
SVGSwitchElement::InsertChildAt(nsIContent* aKid,
|
|
|
|
uint32_t aIndex,
|
|
|
|
bool aNotify)
|
2008-07-13 11:30:48 +00:00
|
|
|
{
|
2013-01-06 06:25:54 +00:00
|
|
|
nsresult rv = SVGSwitchElementBase::InsertChildAt(aKid, aIndex, aNotify);
|
2008-07-13 11:30:48 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-12 00:23:35 +00:00
|
|
|
MaybeInvalidate();
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2007-02-05 16:26:23 +00:00
|
|
|
|
2012-03-29 21:09:07 +00:00
|
|
|
void
|
2013-01-06 06:25:54 +00:00
|
|
|
SVGSwitchElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
|
2008-07-13 11:30:48 +00:00
|
|
|
{
|
2013-01-06 06:25:54 +00:00
|
|
|
SVGSwitchElementBase::RemoveChildAt(aIndex, aNotify);
|
2012-03-29 21:09:07 +00:00
|
|
|
MaybeInvalidate();
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
2013-01-06 06:25:54 +00:00
|
|
|
|
2007-02-05 16:26:23 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-01-06 06:25:54 +00:00
|
|
|
SVGSwitchElement::IsAttributeMapped(const nsIAtom* name) const
|
2007-02-05 16:26:23 +00:00
|
|
|
{
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
sFEFloodMap,
|
2007-03-20 10:43:33 +00:00
|
|
|
sFiltersMap,
|
2007-02-05 16:26:23 +00:00
|
|
|
sFontSpecificationMap,
|
|
|
|
sGradientStopMap,
|
2007-07-26 06:57:42 +00:00
|
|
|
sLightingEffectsMap,
|
2007-02-05 16:26:23 +00:00
|
|
|
sMarkersMap,
|
|
|
|
sTextContentElementsMap,
|
|
|
|
sViewportsMap
|
|
|
|
};
|
|
|
|
|
2011-12-18 10:09:27 +00:00
|
|
|
return FindAttributeDependence(name, map) ||
|
2013-01-06 06:25:54 +00:00
|
|
|
SVGSwitchElementBase::IsAttributeMapped(name);
|
2007-02-05 16:26:23 +00:00
|
|
|
}
|
2009-05-07 19:37:33 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation Helpers:
|
|
|
|
|
|
|
|
nsIContent *
|
2013-01-06 06:25:54 +00:00
|
|
|
SVGSwitchElement::FindActiveChild() const
|
2009-05-07 19:37:33 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool allowReorder = AttrValueIs(kNameSpaceID_None,
|
2014-09-09 12:00:03 +00:00
|
|
|
nsGkAtoms::allowReorder,
|
|
|
|
nsGkAtoms::yes, eCaseMatters);
|
2009-05-07 19:37:33 +00:00
|
|
|
|
|
|
|
const nsAdoptingString& acceptLangs =
|
2011-05-27 04:53:03 +00:00
|
|
|
Preferences::GetLocalizedString("intl.accept_languages");
|
2009-05-07 19:37:33 +00:00
|
|
|
|
|
|
|
if (allowReorder && !acceptLangs.IsEmpty()) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t bestLanguagePreferenceRank = -1;
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIContent *bestChild = nullptr;
|
2014-09-09 12:00:03 +00:00
|
|
|
nsIContent *defaultChild = nullptr;
|
2011-09-27 07:54:58 +00:00
|
|
|
for (nsIContent* child = nsINode::GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2011-12-31 09:44:03 +00:00
|
|
|
|
|
|
|
if (!child->IsElement()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-02 06:08:42 +00:00
|
|
|
nsCOMPtr<SVGTests> tests(do_QueryInterface(child));
|
2011-12-31 09:44:03 +00:00
|
|
|
if (tests) {
|
|
|
|
if (tests->PassesConditionalProcessingTests(
|
2013-03-02 06:08:42 +00:00
|
|
|
SVGTests::kIgnoreSystemLanguage)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t languagePreferenceRank =
|
2011-12-31 09:44:03 +00:00
|
|
|
tests->GetBestLanguagePreferenceRank(acceptLangs);
|
2009-05-07 19:37:33 +00:00
|
|
|
switch (languagePreferenceRank) {
|
|
|
|
case 0:
|
|
|
|
// best possible match
|
|
|
|
return child;
|
|
|
|
case -1:
|
2014-09-09 12:00:03 +00:00
|
|
|
// no match
|
|
|
|
break;
|
|
|
|
case -2:
|
|
|
|
// no systemLanguage attribute. If there's nothing better
|
|
|
|
// we'll use the last such child.
|
|
|
|
defaultChild = child;
|
2009-05-07 19:37:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (bestLanguagePreferenceRank == -1 ||
|
|
|
|
languagePreferenceRank < bestLanguagePreferenceRank) {
|
|
|
|
bestLanguagePreferenceRank = languagePreferenceRank;
|
|
|
|
bestChild = child;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-12-31 09:44:03 +00:00
|
|
|
} else if (!bestChild) {
|
|
|
|
bestChild = child;
|
2009-05-07 19:37:33 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-09 12:00:03 +00:00
|
|
|
return bestChild ? bestChild : defaultChild;
|
2009-05-07 19:37:33 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 07:54:58 +00:00
|
|
|
for (nsIContent* child = nsINode::GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2011-12-31 09:44:03 +00:00
|
|
|
if (!child->IsElement()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-02 06:08:42 +00:00
|
|
|
nsCOMPtr<SVGTests> tests(do_QueryInterface(child));
|
2011-12-31 09:44:03 +00:00
|
|
|
if (!tests || tests->PassesConditionalProcessingTests(&acceptLangs)) {
|
2009-05-07 19:37:33 +00:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-05-07 19:37:33 +00:00
|
|
|
}
|
2013-01-06 06:25:54 +00:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|