2015-05-03 12:32:37 -07: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 04:12:37 -07: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-03-22 10:30:00 -07:00
|
|
|
|
2013-01-05 22:25:54 -08:00
|
|
|
#include "mozilla/dom/SVGSwitchElement.h"
|
2013-04-25 02:18:42 -07:00
|
|
|
|
2014-11-06 01:30:11 -08:00
|
|
|
#include "nsLayoutUtils.h"
|
2008-07-13 04:30:48 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2011-05-26 21:53:03 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-01-05 22:25:54 -08:00
|
|
|
#include "mozilla/dom/SVGSwitchElementBinding.h"
|
2011-05-26 21:53:03 -07:00
|
|
|
|
2013-03-11 15:05:58 -07:00
|
|
|
class nsIFrame;
|
|
|
|
|
2013-01-05 22:25:54 -08:00
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Switch)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-05 22:25:54 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-05 22:25:54 -08: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 07:13:33 -07:00
|
|
|
SVGSwitchElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-05 22:25:54 -08: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 07:13:33 -07:00
|
|
|
return SVGSwitchElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-05 22:25:54 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGSwitchElement, SVGSwitchElementBase,
|
|
|
|
mActiveChild)
|
2008-12-30 08:32:22 -08:00
|
|
|
|
2013-01-05 22:25:54 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGSwitchElement,SVGSwitchElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGSwitchElement,SVGSwitchElementBase)
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2013-05-21 12:59:27 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SVGSwitchElement)
|
2013-01-05 22:25:54 -08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(SVGSwitchElementBase)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
SVGSwitchElement::SVGSwitchElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-05 22:25:54 -08:00
|
|
|
: SVGSwitchElementBase(aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-08 14:23:16 -07:00
|
|
|
SVGSwitchElement::~SVGSwitchElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-07-13 04:30:48 -07:00
|
|
|
void
|
2013-01-05 22:25:54 -08:00
|
|
|
SVGSwitchElement::MaybeInvalidate()
|
2008-07-13 04:30:48 -07:00
|
|
|
{
|
2012-03-20 05:15:53 -07:00
|
|
|
// We must not change mActiveChild until after
|
|
|
|
// InvalidateAndScheduleBoundsUpdate has been called, otherwise
|
|
|
|
// it will not correctly invalidate the old mActiveChild area.
|
2012-03-11 17:23:35 -07:00
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
nsIContent *newActiveChild = FindActiveChild();
|
|
|
|
|
|
|
|
if (newActiveChild == mActiveChild) {
|
2009-05-07 12:37:33 -07:00
|
|
|
return;
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-07 12:37:33 -07:00
|
|
|
nsIFrame *frame = GetPrimaryFrame();
|
|
|
|
if (frame) {
|
2014-11-06 01:30:11 -08:00
|
|
|
nsLayoutUtils::PostRestyleEvent(
|
|
|
|
this, nsRestyleHint(0),
|
|
|
|
nsChangeHint_InvalidateRenderingObservers);
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(frame);
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
2012-03-20 05:15:53 -07:00
|
|
|
|
|
|
|
mActiveChild = newActiveChild;
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
|
|
|
|
2013-01-05 22:25:54 -08:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGSwitchElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-13 04:30:48 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsINode methods
|
|
|
|
|
|
|
|
nsresult
|
2013-01-05 22:25:54 -08:00
|
|
|
SVGSwitchElement::InsertChildAt(nsIContent* aKid,
|
|
|
|
uint32_t aIndex,
|
|
|
|
bool aNotify)
|
2008-07-13 04:30:48 -07:00
|
|
|
{
|
2013-01-05 22:25:54 -08:00
|
|
|
nsresult rv = SVGSwitchElementBase::InsertChildAt(aKid, aIndex, aNotify);
|
2008-07-13 04:30:48 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-11 17:23:35 -07:00
|
|
|
MaybeInvalidate();
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-29 14:09:07 -07:00
|
|
|
void
|
2013-01-05 22:25:54 -08:00
|
|
|
SVGSwitchElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
|
2008-07-13 04:30:48 -07:00
|
|
|
{
|
2013-01-05 22:25:54 -08:00
|
|
|
SVGSwitchElementBase::RemoveChildAt(aIndex, aNotify);
|
2012-03-29 14:09:07 -07:00
|
|
|
MaybeInvalidate();
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
2013-01-05 22:25:54 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-01-05 22:25:54 -08:00
|
|
|
SVGSwitchElement::IsAttributeMapped(const nsIAtom* name) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
sFEFloodMap,
|
|
|
|
sFiltersMap,
|
|
|
|
sFontSpecificationMap,
|
|
|
|
sGradientStopMap,
|
2007-07-25 23:57:42 -07:00
|
|
|
sLightingEffectsMap,
|
2007-03-22 10:30:00 -07:00
|
|
|
sMarkersMap,
|
|
|
|
sTextContentElementsMap,
|
|
|
|
sViewportsMap
|
|
|
|
};
|
|
|
|
|
2011-12-18 02:09:27 -08:00
|
|
|
return FindAttributeDependence(name, map) ||
|
2013-01-05 22:25:54 -08:00
|
|
|
SVGSwitchElementBase::IsAttributeMapped(name);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-05-07 12:37:33 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation Helpers:
|
|
|
|
|
|
|
|
nsIContent *
|
2013-01-05 22:25:54 -08:00
|
|
|
SVGSwitchElement::FindActiveChild() const
|
2009-05-07 12:37:33 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allowReorder = AttrValueIs(kNameSpaceID_None,
|
2014-09-09 05:00:03 -07:00
|
|
|
nsGkAtoms::allowReorder,
|
|
|
|
nsGkAtoms::yes, eCaseMatters);
|
2009-05-07 12:37:33 -07:00
|
|
|
|
|
|
|
const nsAdoptingString& acceptLangs =
|
2011-05-26 21:53:03 -07:00
|
|
|
Preferences::GetLocalizedString("intl.accept_languages");
|
2009-05-07 12:37:33 -07:00
|
|
|
|
|
|
|
if (allowReorder && !acceptLangs.IsEmpty()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t bestLanguagePreferenceRank = -1;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent *bestChild = nullptr;
|
2014-09-09 05:00:03 -07:00
|
|
|
nsIContent *defaultChild = nullptr;
|
2011-09-27 00:54:58 -07:00
|
|
|
for (nsIContent* child = nsINode::GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2011-12-31 01:44:03 -08:00
|
|
|
|
|
|
|
if (!child->IsElement()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-01 22:08:42 -08:00
|
|
|
nsCOMPtr<SVGTests> tests(do_QueryInterface(child));
|
2011-12-31 01:44:03 -08:00
|
|
|
if (tests) {
|
|
|
|
if (tests->PassesConditionalProcessingTests(
|
2013-03-01 22:08:42 -08:00
|
|
|
SVGTests::kIgnoreSystemLanguage)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t languagePreferenceRank =
|
2011-12-31 01:44:03 -08:00
|
|
|
tests->GetBestLanguagePreferenceRank(acceptLangs);
|
2009-05-07 12:37:33 -07:00
|
|
|
switch (languagePreferenceRank) {
|
|
|
|
case 0:
|
|
|
|
// best possible match
|
|
|
|
return child;
|
|
|
|
case -1:
|
2014-09-09 05:00:03 -07: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 12:37:33 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (bestLanguagePreferenceRank == -1 ||
|
|
|
|
languagePreferenceRank < bestLanguagePreferenceRank) {
|
|
|
|
bestLanguagePreferenceRank = languagePreferenceRank;
|
|
|
|
bestChild = child;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-12-31 01:44:03 -08:00
|
|
|
} else if (!bestChild) {
|
|
|
|
bestChild = child;
|
2009-05-07 12:37:33 -07:00
|
|
|
}
|
|
|
|
}
|
2014-09-09 05:00:03 -07:00
|
|
|
return bestChild ? bestChild : defaultChild;
|
2009-05-07 12:37:33 -07:00
|
|
|
}
|
|
|
|
|
2011-09-27 00:54:58 -07:00
|
|
|
for (nsIContent* child = nsINode::GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2011-12-31 01:44:03 -08:00
|
|
|
if (!child->IsElement()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-01 22:08:42 -08:00
|
|
|
nsCOMPtr<SVGTests> tests(do_QueryInterface(child));
|
2011-12-31 01:44:03 -08:00
|
|
|
if (!tests || tests->PassesConditionalProcessingTests(&acceptLangs)) {
|
2009-05-07 12:37:33 -07:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-05-07 12:37:33 -07:00
|
|
|
}
|
2013-01-05 22:25:54 -08:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|