Bug 333029, XBLize xf:message. r=allan+doronr

This commit is contained in:
Olli.Pettay%helsinki.fi 2006-04-17 13:06:08 +00:00
Родитель 0fdce37806
Коммит ba3856f3a9
5 изменённых файлов: 230 добавлений и 142 удалений

Просмотреть файл

@ -147,6 +147,7 @@ XPIDLSRCS = \
nsIXFormsUploadElement.idl \
nsIXFormsUploadUIElement.idl \
nsIXFormsCopyElement.idl \
nsIXFormsEphemeralMessageUI.idl \
$(NULL)
# XForms source files

Просмотреть файл

@ -0,0 +1,58 @@
/* -*- Mode: IDL; 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
* Olli Pettay.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Olli Pettay <Olli.Pettay@helsinki.fi> (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 ***** */
#include "nsISupports.idl"
/**
* Interface implemented by the UI part of the ephemeral message and hint.
*/
[scriptable, uuid(631c0e3b-3cd8-4a61-8d93-7f8181a19bf9)]
interface nsIXFormsEphemeralMessageUI : nsISupports
{
/**
* Called, when element should make itself visible.
* Parameters are hints to where to place the element.
*/
void show(in long coordinateHintX, in long coordinateHintY);
/**
* Called, when element should hide itself.
*/
void hide();
};

Просмотреть файл

@ -38,12 +38,10 @@
#include "nsXFormsAtoms.h"
#include "nsXFormsStubElement.h"
#include "nsXFormsDelegateStub.h"
#include "nsXFormsActionElement.h"
#include "nsIXFormsActionModuleElement.h"
#include "nsIXTFXMLVisual.h"
#include "nsIXTFXMLVisualWrapper.h"
#include "nsIDOMText.h"
#include "nsIDOM3Node.h"
#include "nsIDOMElement.h"
@ -81,19 +79,11 @@
#include "nsNetUtil.h"
#include "nsIDOMDocumentEvent.h"
#include "nsIChannelEventSink.h"
#define EPHEMERAL_STYLE \
"position:absolute;z-index:2147483647; \
background:inherit;color:inherit; \
border:inherit;visibility:visible;"
#define EPHEMERAL_STYLE_HIDDEN \
"position:absolute;z-index:2147483647;visibility:hidden;"
#include "nsIXFormsEphemeralMessageUI.h"
#define MESSAGE_WINDOW_PROPERTIES \
"location=false,scrollbars=yes,centerscreen"
// Defining a simple dialog for modeless and modal messages.
#define MESSAGE_WINDOW_UI_PART1 \
@ -129,7 +119,7 @@ class nsXFormsEventListener;
*
* @see http://www.w3.org/TR/xforms/slice10.html#action-info
*/
class nsXFormsMessageElement : public nsXFormsXMLVisualStub,
class nsXFormsMessageElement : public nsXFormsDelegateStub,
public nsIDOMEventListener,
public nsIXFormsActionModuleElement,
public nsIStreamListener,
@ -142,13 +132,6 @@ public:
// nsIXTFElement overrides
NS_IMETHOD WillChangeDocument(nsIDOMDocument *aNewDocument);
NS_IMETHOD OnDestroyed();
// nsIXTFXMLVisual overrides
NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper);
// nsIXTFVisual overrides
NS_IMETHOD GetVisualContent(nsIDOMElement **aElement);
NS_IMETHOD GetInsertionPoint(nsIDOMElement **aElement);
NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent);
NS_IMETHOD WillChangeParent(nsIDOMElement *aNewParent);
NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aSrc);
@ -188,7 +171,7 @@ public:
nsXFormsMessageElement(MessageType aType) :
mType(aType), mElement(nsnull), mPosX(-1), mPosY(-1),
mType(aType), mPosX(-1), mPosY(-1), mDocument(nsnull),
mStopType(eStopType_None) {}
private:
nsresult HandleEphemeralMessage(nsIDOMDocument* aDoc, nsIDOMEvent* aEvent);
@ -215,23 +198,20 @@ private:
*/
void AddRemoveExternalResource(PRBool aAdd);
MessageType mType;
nsCOMPtr<nsIDOMElement> mVisualElement;
nsIDOMElement *mElement;
MessageType mType;
// The position of the ephemeral message
PRInt32 mPosX;
PRInt32 mPosY;
PRInt32 mPosX;
PRInt32 mPosY;
nsCOMPtr<nsITimer> mEphemeralTimer;
nsCOMPtr<nsIDOMDocument> mDocument;
nsCOMPtr<nsITimer> mEphemeralTimer;
nsIDOMDocument* mDocument;
nsCOMPtr<nsIChannel> mChannel;
StopType mStopType;
};
NS_IMPL_ADDREF_INHERITED(nsXFormsMessageElement, nsXFormsXMLVisualStub)
NS_IMPL_RELEASE_INHERITED(nsXFormsMessageElement, nsXFormsXMLVisualStub)
NS_IMPL_ADDREF_INHERITED(nsXFormsMessageElement, nsXFormsDelegateStub)
NS_IMPL_RELEASE_INHERITED(nsXFormsMessageElement, nsXFormsDelegateStub)
NS_INTERFACE_MAP_BEGIN(nsXFormsMessageElement)
NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink)
@ -239,57 +219,7 @@ NS_INTERFACE_MAP_BEGIN(nsXFormsMessageElement)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsIXFormsActionModuleElement)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
NS_INTERFACE_MAP_END_INHERITING(nsXFormsXMLVisualStub)
// nsIXTFXMLVisual
NS_IMETHODIMP
nsXFormsMessageElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
{
nsresult rv = nsXFormsXMLVisualStub::OnCreated(aWrapper);
NS_ENSURE_SUCCESS(rv, rv);
aWrapper->SetNotificationMask(nsIXTFElement::NOTIFY_WILL_CHANGE_DOCUMENT |
nsIXTFElement::NOTIFY_PARENT_CHANGED |
nsIXTFElement::NOTIFY_ATTRIBUTE_SET |
nsIXTFElement::NOTIFY_ATTRIBUTE_REMOVED);
nsCOMPtr<nsIDOMElement> node;
rv = aWrapper->GetElementNode(getter_AddRefs(node));
NS_ENSURE_SUCCESS(rv, rv);
mElement = node;
NS_ASSERTION(mElement, "Wrapper is not an nsIDOMElement, we'll crash soon");
nsCOMPtr<nsIDOMDocument> domDoc;
mElement->GetOwnerDocument(getter_AddRefs(domDoc));
domDoc->CreateElementNS(NS_LITERAL_STRING(NS_NAMESPACE_XHTML),
mType == eType_Alert
? NS_LITERAL_STRING("span")
: NS_LITERAL_STRING("div"),
getter_AddRefs(mVisualElement));
if (mVisualElement && mType != eType_Alert)
mVisualElement->SetAttribute(NS_LITERAL_STRING("style"),
NS_LITERAL_STRING(EPHEMERAL_STYLE_HIDDEN));
return NS_OK;
}
// nsIXTFVisual
NS_IMETHODIMP
nsXFormsMessageElement::GetVisualContent(nsIDOMElement **aElement)
{
NS_IF_ADDREF(*aElement = mVisualElement);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsMessageElement::GetInsertionPoint(nsIDOMElement **aElement)
{
NS_IF_ADDREF(*aElement = mVisualElement);
return NS_OK;
}
NS_INTERFACE_MAP_END_INHERITING(nsXFormsDelegateStub)
// nsIXTFElement
@ -319,16 +249,15 @@ nsXFormsMessageElement::WillChangeDocument(nsIDOMDocument *aNewDocument)
}
mDocument = aNewDocument;
return NS_OK;
return nsXFormsDelegateStub::WillChangeDocument(aNewDocument);
}
NS_IMETHODIMP
nsXFormsMessageElement::OnDestroyed()
{
mElement = nsnull;
mVisualElement = nsnull;
mChannel = nsnull;
return NS_OK;
mDocument = nsnull;
return nsXFormsDelegateStub::OnDestroyed();
}
NS_IMETHODIMP
@ -397,12 +326,12 @@ NS_IMETHODIMP
nsXFormsMessageElement::WillChangeParent(nsIDOMElement *aNewParent)
{
if (mType == eType_Normal)
return NS_OK;
return nsXFormsDelegateStub::WillChangeParent(aNewParent);
nsCOMPtr<nsIDOMNode> parent;
mElement->GetParentNode(getter_AddRefs(parent));
if (!parent)
return NS_OK;
return nsXFormsDelegateStub::WillChangeParent(aNewParent);
nsCOMPtr<nsIDOMEventTarget> targ(do_QueryInterface(parent));
NS_ENSURE_STATE(targ);
@ -419,14 +348,14 @@ nsXFormsMessageElement::WillChangeParent(nsIDOMElement *aNewParent)
targ->RemoveEventListener(NS_LITERAL_STRING("xforms-binding-exception"),this, PR_TRUE);
}
return NS_OK;
return nsXFormsDelegateStub::WillChangeParent(aNewParent);
}
NS_IMETHODIMP
nsXFormsMessageElement::ParentChanged(nsIDOMElement *aNewParent)
{
if (mType == eType_Normal || !aNewParent)
return NS_OK;
return nsXFormsDelegateStub::ParentChanged(aNewParent);
nsCOMPtr<nsIDOMEventTarget> targ(do_QueryInterface(aNewParent));
NS_ENSURE_STATE(targ);
@ -444,7 +373,7 @@ nsXFormsMessageElement::ParentChanged(nsIDOMElement *aNewParent)
targ->AddEventListener(NS_LITERAL_STRING("xforms-binding-exception"), this, PR_TRUE);
}
return NS_OK;
return nsXFormsDelegateStub::ParentChanged(aNewParent);
}
NS_IMETHODIMP
@ -461,7 +390,7 @@ nsXFormsMessageElement::AttributeSet(nsIAtom *aName, const nsAString &aValue)
TestExternalFile();
}
return NS_OK;
return nsXFormsDelegateStub::AttributeSet(aName, aValue);
}
NS_IMETHODIMP
@ -477,7 +406,7 @@ nsXFormsMessageElement::AttributeRemoved(nsIAtom *aName)
mStopType = eStopType_None;
}
return NS_OK;
return nsXFormsDelegateStub::AttributeRemoved(aName);
}
NS_IMETHODIMP
@ -597,21 +526,8 @@ nsXFormsMessageElement::HandleInlineAlert(nsIDOMEvent* aEvent)
if (displayValue) {
nsAutoString type;
displayValue->GetStringValue(type);
if (type.EqualsLiteral("none"))
return PR_FALSE;
nsAutoString instanceData;
PRBool hasBinding = nsXFormsUtils::GetSingleNodeBindingValue(mElement,
instanceData);
if (hasBinding) {
nsCOMPtr<nsIDOM3Node> visualElement3(do_QueryInterface(mVisualElement));
if (visualElement3) {
visualElement3->SetTextContent(instanceData);
}
}
return PR_TRUE;
return !type.EqualsLiteral("none");
}
}
return PR_FALSE;
}
@ -644,10 +560,10 @@ nsXFormsMessageElement::HandleEphemeralMessage(nsIDOMDocument* aDoc,
mEphemeralTimer = nsnull;
}
doc->UnsetProperty(nsXFormsAtoms::messageProperty);
if (mVisualElement) {
mVisualElement->SetAttribute(NS_LITERAL_STRING("style"),
NS_LITERAL_STRING(EPHEMERAL_STYLE_HIDDEN));
nsCOMPtr<nsIXFormsEphemeralMessageUI> ui(do_QueryInterface(mElement));
if (ui) {
ui->Hide();
}
ResetEphemeralPosition();
}
@ -692,15 +608,6 @@ nsXFormsMessageElement::HandleEphemeralMessage(nsIDOMDocument* aDoc,
return NS_OK;
}
nsAutoString instanceData;
PRBool hasBinding = nsXFormsUtils::GetSingleNodeBindingValue(mElement,
instanceData);
if (hasBinding) {
nsCOMPtr<nsIDOM3Node> visualElement3(do_QueryInterface(mVisualElement));
if (visualElement3) {
visualElement3->SetTextContent(instanceData);
}
}
StartEphemeral();
}
}
@ -935,17 +842,14 @@ nsXFormsMessageElement::ShowEphemeral()
if (!mElement)
return;
nsAutoString style;
style.AppendLiteral(EPHEMERAL_STYLE);
style.AppendLiteral("left:");
style.AppendInt(mPosX);
style.AppendLiteral("px;top:");
style.AppendInt(mPosY);
style.AppendLiteral("px;");
mVisualElement->SetAttribute(NS_LITERAL_STRING("style"), style);
nsCOMPtr<nsIXFormsEphemeralMessageUI> ui(do_QueryInterface(mElement));
if (ui) {
ui->Show(mPosX, mPosY);
}
mEphemeralTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
if (mEphemeralTimer)
mEphemeralTimer->InitWithFuncCallback(sEphemeralCallbackHide, this,
mEphemeralTimer->InitWithFuncCallback(sEphemeralCallbackHide, this,
HIDE_EPHEMERAL_TIMEOUT,
nsITimer::TYPE_ONE_SHOT);
}
@ -974,9 +878,10 @@ nsXFormsMessageElement::HideEphemeral()
}
doc->UnsetProperty(nsXFormsAtoms::messageProperty);
if (mVisualElement)
mVisualElement->SetAttribute(NS_LITERAL_STRING("style"),
NS_LITERAL_STRING(EPHEMERAL_STYLE_HIDDEN));
nsCOMPtr<nsIXFormsEphemeralMessageUI> ui(do_QueryInterface(mElement));
if (ui) {
ui->Hide();
}
mEphemeralTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
if (mEphemeralTimer)

Просмотреть файл

@ -41,6 +41,17 @@
@namespace xul url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
@namespace mozType url(http://www.mozilla.org/projects/xforms/2005/type);
rebuild,
recalculate,
revalidate,
refresh,
model,
instance,
submission,
bind {
display: none !important;
}
html|*:root repeat,
html|*:root repeatitem,
html|*:root contextcontainer,
@ -88,17 +99,11 @@ html|*:root select1[appearance='full'] choices {
display: none;
}
message[level="ephemeral"], hint {
background-color: InfoBackground;
color: InfoText;
padding: 2px 3px;
font: message-box;
border: 1px black solid;
visibility: hidden !important;
position: absolute !important;
message, alert {
display: none;
}
action {
action, message[level="ephemeral"], hint {
position: absolute;
z-index: 2147481647;
visibility: hidden;
@ -106,10 +111,38 @@ action {
left: 0px;
width: 0px;
height: 0px;
display: block;
}
alert {
display: none;
-moz-binding: url('chrome://xforms/content/xforms.xml#inline-alert');
}
message[level="ephemeral"], hint {
-moz-binding: url('chrome://xforms/content/xforms.xml#ephemeral-message');
background-color: InfoBackground;
color: InfoText;
border: 1px black solid;
padding: 2px 3px;
font: message-box;
position: absolute !important;
width: auto;
height: auto;
display: block;
}
message[level="ephemeral"] > html|div.-moz-xforms-message-container,
hint > html|div.-moz-xforms-message-container {
background-color: inherit;
color: inherit;
border: inherit;
padding: inherit;
font: inherit;
position: inherit;
width: inherit;
height: inherit;
display: inherit;
z-index: 2147483647;
}
/* group */

Просмотреть файл

@ -319,6 +319,97 @@
</implementation>
</binding>
<!-- ALERT: <DEFAULT> -->
<binding id="inline-alert"
extends="chrome://xforms/content/xforms.xml#xformswidget-base">
<content>
<html:div anonid="container" class="-moz-xforms-message-container">
<html:div anonid="inlineData" style="display: inherit;">
<children/>
</html:div>
<html:div anonid="bindingData" style="display: inherit;"/>
</html:div>
</content>
<implementation>
<field name="_inlineData">null</field>
<property name="inlineData" readonly="true">
<getter>
if (!this._inlineData) {
this._inlineData = document.
getAnonymousElementByAttribute(this, "anonid", "inlineData");
}
return this._inlineData;
</getter>
</property>
<field name="_bindingData">null</field>
<property name="bindingData" readonly="true">
<getter>
if (!this._bindingData) {
this._bindingData = document.
getAnonymousElementByAttribute(this, "anonid", "bindingData");
}
return this._bindingData;
</getter>
</property>
<method name="refresh">
<body>
if (this.accessors.hasBoundNode()) {
this.bindingData.textContent = this.stringValue;
this.inlineData.style.display = "none";
this.bindingData.style.display = "inherit";
} else {
this.bindingData.style.display = "none";
this.inlineData.style.display = "inherit";
}
</body>
</method>
</implementation>
</binding>
<!-- MESSAGE: <DEFAULT>, reusing the content of inline-alert -->
<binding id="ephemeral-message"
extends="chrome://xforms/content/xforms.xml#inline-alert">
<implementation implements="nsIXFormsEphemeralMessageUI">
<field name="_container">null</field>
<property name="container" readonly="true">
<getter>
if (!this._container) {
this._container = document.
getAnonymousElementByAttribute(this, "anonid", "container");
}
return this._container;
</getter>
</property>
<method name="show">
<parameter name="x"/>
<parameter name="y"/>
<body>
this.container.style.visibility = "visible";
this.container.style.display = "inherit";
this.container.style.left = x + "px";
this.container.style.top = y + "px";
return true;
</body>
</method>
<method name="hide">
<body>
this.container.style.left = "0px";
this.container.style.top = "0px";
this.container.style.visibility = "hidden";
this.container.style.display = "none";
</body>
</method>
</implementation>
</binding>
<!-- UPLOAD: <DEFAULT>
The upload widget assumes successors bindings implement getElementControl()