mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 347327, [XForms] mediatype for output, p=surkov, r=aaronr+doronr
This commit is contained in:
parent
d25fb28b27
commit
e6270ff676
@ -188,6 +188,7 @@ CPPSRCS = \
|
||||
nsXFormsInsertDeleteElement.cpp \
|
||||
nsXFormsLoadElement.cpp \
|
||||
nsXFormsMessageElement.cpp \
|
||||
nsXFormsMediatypeElement.cpp \
|
||||
nsXFormsLabelElement.cpp \
|
||||
nsXFormsToggleElement.cpp \
|
||||
nsXFormsCaseElement.cpp \
|
||||
|
@ -86,9 +86,13 @@ NS_HIDDEN_(nsresult) NS_NewXFormsSetValueElement(nsIXTFElement **aResult);
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsSetIndexElement(nsIXTFElement **aResult);
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsMessageElement(nsIXTFElement **aResult);
|
||||
|
||||
// XForms Controls. Additional Elements.
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsMediatypeElement(nsIXTFElement **aResult);
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsHintElement(nsIXTFElement **aResult);
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsHelpElement(nsIXTFElement **aResult);
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsAlertElement(nsIXTFElement **aResult);
|
||||
|
||||
// XForms User Interface. The XForms Switch Module.
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsToggleElement(nsIXTFElement **aResult);
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsCaseElement(nsIXTFElement **aResult);
|
||||
NS_HIDDEN_(nsresult) NS_NewXFormsSwitchElement(nsIXTFElement **aResult);
|
||||
@ -177,6 +181,8 @@ nsXFormsElementFactory::CreateElement(const nsAString& aTagName,
|
||||
return NS_NewXFormsHelpElement(aElement);
|
||||
if (aTagName.EqualsLiteral("alert"))
|
||||
return NS_NewXFormsAlertElement(aElement);
|
||||
if (aTagName.EqualsLiteral("mediatype"))
|
||||
return NS_NewXFormsMediatypeElement(aElement);
|
||||
if (aTagName.EqualsLiteral("submission"))
|
||||
return NS_NewXFormsSubmissionElement(aElement);
|
||||
if (aTagName.EqualsLiteral("trigger"))
|
||||
|
93
extensions/xforms/nsXFormsMediatypeElement.cpp
Normal file
93
extensions/xforms/nsXFormsMediatypeElement.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XForms support.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Alexander Surkov.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Implementation of the XForms \<mediatype\> element.
|
||||
*/
|
||||
|
||||
#include "nsXFormsDelegateStub.h"
|
||||
#include "nsIDOM3Node.h"
|
||||
|
||||
class nsXFormsMediatypeElement : public nsXFormsDelegateStub
|
||||
{
|
||||
public:
|
||||
// nsIXFormsDelegate
|
||||
NS_IMETHOD GetValue(nsAString& aValue);
|
||||
|
||||
nsXFormsMediatypeElement();
|
||||
|
||||
#ifdef DEBUG_smaug
|
||||
virtual const char* Name() { return "mediatype"; }
|
||||
#endif
|
||||
};
|
||||
|
||||
nsXFormsMediatypeElement::nsXFormsMediatypeElement():
|
||||
nsXFormsDelegateStub(NS_LITERAL_STRING("mediatype"))
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsMediatypeElement::GetValue(nsAString& aValue)
|
||||
{
|
||||
// The order of precedence for determining the mediatype is:
|
||||
// single node binding, inline text
|
||||
|
||||
nsXFormsDelegateStub::GetValue(aValue);
|
||||
if (aValue.IsVoid()) {
|
||||
NS_ENSURE_STATE(mElement);
|
||||
|
||||
nsCOMPtr<nsIDOM3Node> inner(do_QueryInterface(mElement));
|
||||
if (inner) {
|
||||
inner->GetTextContent(aValue);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult)
|
||||
NS_NewXFormsMediatypeElement(nsIXTFElement **aResult)
|
||||
{
|
||||
*aResult = new nsXFormsMediatypeElement();
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -111,6 +111,58 @@
|
||||
</binding>
|
||||
|
||||
|
||||
<!-- OUTPUT: <MEDIATYPE="image/*", TYPE="xsd:anyURI"> -->
|
||||
<binding id="xformswidget-output-mediatype-anyURI"
|
||||
extends="chrome://xforms/content/xforms.xml#xformswidget-output-base">
|
||||
<content>
|
||||
<children includes="label"/>
|
||||
<html:img class="xf-value" anonid="control"/>
|
||||
<children/>
|
||||
</content>
|
||||
|
||||
<implementation>
|
||||
<method name="getControlElement">
|
||||
<body>
|
||||
return {
|
||||
__proto__: this.ownerDocument.
|
||||
getAnonymousElementByAttribute(this, "anonid", "control"),
|
||||
|
||||
set value(val) {
|
||||
this.src = val;
|
||||
}
|
||||
};
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
</binding>
|
||||
|
||||
|
||||
<!-- OUTPUT: <MEDIATYPE="image/*", TYPE="xsd:base64Binary"> -->
|
||||
<binding id="xformswidget-output-mediatype-base64Binary"
|
||||
extends="chrome://xforms/content/xforms.xml#xformswidget-output-base">
|
||||
<content>
|
||||
<children includes="label"/>
|
||||
<html:img class="xf-value" anonid="control"/>
|
||||
<children/>
|
||||
</content>
|
||||
|
||||
<implementation>
|
||||
<method name="getControlElement">
|
||||
<body>
|
||||
return {
|
||||
__proto__: this.ownerDocument.
|
||||
getAnonymousElementByAttribute(this, "anonid", "control"),
|
||||
|
||||
set value(val) {
|
||||
this.src = "data:[image/*][;base64]," + val;
|
||||
}
|
||||
};
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
</binding>
|
||||
|
||||
|
||||
<!-- LABEL: <DEFAULT> -->
|
||||
<binding id="xformswidget-label"
|
||||
extends="chrome://xforms/content/xforms.xml#xformswidget-label-base">
|
||||
|
@ -95,6 +95,58 @@
|
||||
</binding>
|
||||
|
||||
|
||||
<!-- OUTPUT: <MEDIATYPE="image/*", TYPE="xsd:anyURI"> -->
|
||||
<binding id="xformswidget-output-mediatype-anyURI"
|
||||
extends="chrome://xforms/content/xforms.xml#xformswidget-output-base">
|
||||
<content>
|
||||
<children includes="label"/>
|
||||
<xul:image class="xf-value" anonid="control"/>
|
||||
<children/>
|
||||
</content>
|
||||
|
||||
<implementation>
|
||||
<method name="getControlElement">
|
||||
<body>
|
||||
return {
|
||||
__proto__: this.ownerDocument.
|
||||
getAnonymousElementByAttribute(this, "anonid", "control"),
|
||||
|
||||
set value(val) {
|
||||
this.src = val;
|
||||
}
|
||||
};
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
</binding>
|
||||
|
||||
|
||||
<!-- OUTPUT: <MEDIATYPE="image/*", TYPE="xsd:base64Binary"> -->
|
||||
<binding id="xformswidget-output-mediatype-base64Binary"
|
||||
extends="chrome://xforms/content/xforms.xml#xformswidget-output-base">
|
||||
<content>
|
||||
<children includes="label"/>
|
||||
<xul:image class="xf-value" anonid="control"/>
|
||||
<children/>
|
||||
</content>
|
||||
|
||||
<implementation>
|
||||
<method name="getControlElement">
|
||||
<body>
|
||||
return {
|
||||
__proto__: this.ownerDocument.
|
||||
getAnonymousElementByAttribute(this, "anonid", "control"),
|
||||
|
||||
set value(val) {
|
||||
this.src = "data:[image/*][;base64]," + val;
|
||||
}
|
||||
};
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
</binding>
|
||||
|
||||
|
||||
<!-- LABEL: <DEFAULT> -->
|
||||
<binding id="xformswidget-label"
|
||||
extends="chrome://xforms/content/xforms.xml#xformswidget-label-base">
|
||||
|
@ -109,6 +109,11 @@ message, alert, help {
|
||||
display: none;
|
||||
}
|
||||
|
||||
mediatype {
|
||||
-moz-binding: url('chrome://xforms/content/xforms.xml#xformswidget-mediatype');
|
||||
display: none;
|
||||
}
|
||||
|
||||
html|*:root message[level="ephemeral"], html|*:root hint {
|
||||
position: absolute;
|
||||
z-index: 2147481647;
|
||||
@ -197,6 +202,24 @@ xul|*:root output[mozType|type="http://www.w3.org/2001/XMLSchema#date"][appearan
|
||||
-moz-binding: url('chrome://xforms/content/widgets-xul.xml#calendar-full');
|
||||
}
|
||||
|
||||
/* output mediatype="image/*"
|
||||
XXX: We should support controls for derived types too (bug 316691).
|
||||
*/
|
||||
|
||||
html|*:root output[mozType|type="http://www.w3.org/2001/XMLSchema#anyURI"][mozType|mediatype^="image"] {
|
||||
-moz-binding: url('chrome://xforms/content/xforms-xhtml.xml#xformswidget-output-mediatype-anyURI');
|
||||
}
|
||||
html|*:root output[mozType|type="http://www.w3.org/2001/XMLSchema#base64Binary"][mozType|mediatype^="image"] {
|
||||
-moz-binding: url('chrome://xforms/content/xforms-xhtml.xml#xformswidget-output-mediatype-base64Binary');
|
||||
}
|
||||
|
||||
xul|*:root output[mozType|type="http://www.w3.org/2001/XMLSchema#anyURI"][mozType|mediatype^="image"] {
|
||||
-moz-binding: url('chrome://xforms/content/xforms-xhtml.xml#xformswidget-output-mediatype-anyURI');
|
||||
}
|
||||
xul|*:root output[mozType|type="http://www.w3.org/2001/XMLSchema#base64Binary"][mozType|mediatype^="image"] {
|
||||
-moz-binding: url('chrome://xforms/content/xforms-xhtml.xml#xformswidget-output-mediatype-base64Binary');
|
||||
}
|
||||
|
||||
/* range widgets */
|
||||
range {
|
||||
-moz-binding: url('chrome://xforms/content/range.xml#xformswidget-range');
|
||||
|
@ -77,6 +77,12 @@
|
||||
</getter>
|
||||
</property>
|
||||
|
||||
<property name="MOZTYPE_NS" readonly="true">
|
||||
<getter>
|
||||
return "http://www.mozilla.org/projects/xforms/2005/type";
|
||||
</getter>
|
||||
</property>
|
||||
|
||||
<!-- Dispatch UI Event to the control itself -->
|
||||
<method name="dispatchDOMUIEvent">
|
||||
<parameter name="aType"/>
|
||||
@ -239,7 +245,31 @@
|
||||
return true;
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<constructor>
|
||||
this.setMediatype();
|
||||
</constructor>
|
||||
|
||||
<method name="setMediatype">
|
||||
<body>
|
||||
if (this.hasAttribute("mediatype")) {
|
||||
this.setAttributeNS(this.MOZTYPE_NS, "mediatype",
|
||||
this.getAttribute("mediatype"));
|
||||
}
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
|
||||
<handlers>
|
||||
<handler event="DOMAttrModified">
|
||||
<![CDATA[
|
||||
if (event.attrName == "mediatype" &&
|
||||
event.relatedNode.namespaceURI == "") {
|
||||
this.setMediatype();
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
|
||||
@ -480,4 +510,36 @@
|
||||
</content>
|
||||
</binding>
|
||||
|
||||
|
||||
<!-- MEDIATYPE -->
|
||||
<binding id="xformswidget-mediatype" extends="#xformswidget-base">
|
||||
<implementation implements="nsIXFormsUIWidget">
|
||||
<method name="refresh">
|
||||
<body>
|
||||
this.setMediatype();
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="setMediatype">
|
||||
<body>
|
||||
<![CDATA[
|
||||
var parent = this.parentNode;
|
||||
if (parent.namespaceURI == this.XFORMS_NS &&
|
||||
parent.localName == "output" &&
|
||||
!parent.hasAttribute("mediatype")) {
|
||||
parent.setAttributeNS(this.MOZTYPE_NS, "mediatype",
|
||||
this.stringValue);
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
|
||||
<handlers>
|
||||
<handler event="DOMCharacterDataModified">
|
||||
this.setMediatype();
|
||||
</handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
</bindings>
|
||||
|
Loading…
Reference in New Issue
Block a user