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