[XForms] Show dialogbox on fatal errors. Binding-errors for now. Bug 290465, r=doronr+smaug.

This commit is contained in:
allan%beaufour.dk 2005-08-24 09:43:27 +00:00
Родитель eca26ce6f3
Коммит 98a3d73aae
8 изменённых файлов: 150 добавлений и 6 удалений

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

@ -10,6 +10,8 @@ xforms.jar:
content/xforms/xforms.xml (resources/content/xforms.xml)
content/xforms/select1.xml (resources/content/select1.xml)
content/xforms/select.xml (resources/content/select.xml)
content/xforms/bindingex.css (resources/content/bindingex.css)
content/xforms/bindingex.xul (resources/content/bindingex.xul)
* locale/en-US/xforms/contents.rdf (resources/locale/en-US/contents.rdf)
locale/en-US/xforms/xforms.properties (resources/locale/en-US/xforms.properties)
locale/en-US/xforms/xforms.dtd (resources/locale/en-US/xforms.dtd)

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

@ -62,6 +62,7 @@ nsIAtom *nsXFormsAtoms::clazz;
nsIAtom *nsXFormsAtoms::deferredBindListProperty;
nsIAtom *nsXFormsAtoms::readyForBindProperty;
nsIAtom *nsXFormsAtoms::accesskey;
nsIAtom *nsXFormsAtoms::fatalError;
const nsStaticAtom nsXFormsAtoms::Atoms_info[] = {
{ "src", &nsXFormsAtoms::src },
@ -86,7 +87,8 @@ const nsStaticAtom nsXFormsAtoms::Atoms_info[] = {
{ "class", &nsXFormsAtoms::clazz },
{ "DeferredBindListProperty", &nsXFormsAtoms::deferredBindListProperty },
{ "ReadyForBindProperty", &nsXFormsAtoms::readyForBindProperty },
{ "accesskey", &nsXFormsAtoms::accesskey }
{ "accesskey", &nsXFormsAtoms::accesskey },
{ "fatalError", &nsXFormsAtoms::fatalError }
};
void

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

@ -70,6 +70,7 @@ class nsXFormsAtoms
static NS_HIDDEN_(nsIAtom *) deferredBindListProperty;
static NS_HIDDEN_(nsIAtom *) readyForBindProperty;
static NS_HIDDEN_(nsIAtom *) accesskey;
static NS_HIDDEN_(nsIAtom *) fatalError;
static NS_HIDDEN_(void) InitAtoms();

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

@ -46,12 +46,17 @@
#include "nsIDOMKeyEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMXPathResult.h"
#include "nsIDOMDocumentView.h"
#include "nsIDOMAbstractView.h"
#include "nsIXTFXMLVisualWrapper.h"
#include "nsIDocument.h"
#include "nsXFormsModelElement.h"
#include "nsPIDOMWindow.h"
#include "nsIFocusController.h"
#include "nsIScriptGlobalObject.h"
#include "nsIServiceManager.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
/** This class is used to generate xforms-hint and xforms-help events.*/
class nsXFormsHintHelpListener : public nsIDOMEventListener {
@ -418,12 +423,69 @@ nsXFormsControlStubBase::HandleDefault(nsIDOMEvent *aEvent,
} else {
focusController->MoveFocus(PR_FALSE, nsnull);
}
} else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_BindingException].name)) {
*aHandled = HandleBindingException();
}
}
return NS_OK;
}
PRBool
nsXFormsControlStubBase::HandleBindingException()
{
if (!mElement) {
return PR_FALSE;
}
nsCOMPtr<nsIDOMDocument> doc;
mElement->GetOwnerDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDocument> iDoc(do_QueryInterface(doc));
if (!iDoc) {
return PR_FALSE;
}
// check for fatalError property, enforcing that only one fatal error will
// be shown to the user
if (iDoc->GetProperty(nsXFormsAtoms::fatalError)) {
return PR_FALSE;
}
iDoc->SetProperty(nsXFormsAtoms::fatalError, iDoc);
// Check for preference, disabling this popup
PRBool disablePopup = PR_FALSE;
nsresult rv;
nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && pref) {
PRBool val;
if (NS_SUCCEEDED(pref->GetBoolPref("xforms.disablePopup", &val)))
disablePopup = val;
}
if (disablePopup)
return PR_FALSE;
// Get nsIDOMWindowInternal
nsCOMPtr<nsIDOMDocumentView> dview(do_QueryInterface(doc));
if (!dview)
return PR_FALSE;
nsCOMPtr<nsIDOMAbstractView> aview;
dview->GetDefaultView(getter_AddRefs(aview));
nsCOMPtr<nsIDOMWindowInternal> internal(do_QueryInterface(aview));
if (!internal)
return PR_FALSE;
// Show popup
nsCOMPtr<nsIDOMWindow> messageWindow;
rv = internal->OpenDialog(NS_LITERAL_STRING("chrome://xforms/content/bindingex.xul"),
NS_LITERAL_STRING("XFormsBindingException"),
NS_LITERAL_STRING("modal,dialog,chrome,dependent"),
nsnull, getter_AddRefs(messageWindow));
return NS_SUCCEEDED(rv);
}
#ifdef DEBUG_smaug
static nsVoidArray* sControlList = nsnull;
class ControlDebug

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

@ -65,11 +65,6 @@ class nsIXTFXMLVisualWrapper;
/**
* Common stub for all XForms controls that inherit from nsIXFormsControl and
* is bound to an instance node.
*
* @bug If a control has a model attribute, but no binding attributes we fail
* to set this as the context for children. We need to return the contextnode
* from EvaluateNodeBinding in that case, and return that in GetContext(). (XXX)
* @see http://bugzilla.mozilla.org/show_bug.cgi?id=280366
*/
class nsXFormsControlStubBase : public nsIXFormsControl
{
@ -230,6 +225,16 @@ protected:
/** Removes the index change event listeners */
void RemoveIndexListeners();
/**
* Shows an error dialog for the user the first time an
* xforms-binding-exception event is received by the control.
*
* The dialog can be disabled via the |xforms.disablePopup| preference.
*
* @return Whether handling was successful
*/
PRBool HandleBindingException();
};

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

@ -0,0 +1,7 @@
.descr1 {
padding-bottom: 5px;
}
.descr2 {
font-size: 0.8em;
}

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

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ***** 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
- IBM Corportation.
- Portions created by the Initial Developer are Copyright (C) 2005
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Allan Beaufour <allan@beaufour.dk>
-
- 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 LGPL or the GPL. 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 ***** -->
<!DOCTYPE dialog SYSTEM "chrome://xforms/locale/xforms.dtd">
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://xforms/content/bindingex.css" type="text/css"?>
<dialog id="XFormsBindingDialog"
minwidth="40em"
title="&xforms.bindingdialog.title;"
buttons="accept"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<hbox flex="1">
<hbox align="start">
<image class="alert-icon spaced"/>
</hbox>
<vbox>
<description class="header descr1">
&xforms.bindingdialog.description1;
</description>
<description class="descr2">
&xforms.bindingdialog.description2;
</description>
</vbox>
</hbox>
</dialog>

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

@ -39,3 +39,7 @@
<!ENTITY allowedSitesXForms.label "Allowed Sites">
<!ENTITY allowedSitesXForms.accesskey "t">
<!ENTITY xforms.bindingdialog.title "XForms Error">
<!ENTITY xforms.bindingdialog.description1 "The form on this page contains an error and will not work properly">
<!ENTITY xforms.bindingdialog.description2 "See the JavaScript Console for details">