2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-08-04 03:45:50 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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/
|
2000-08-04 03:45:50 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
2000-08-04 03:45:50 +04:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-08-04 03:45:50 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-08-04 03:45:50 +04:00
|
|
|
|
|
|
|
#include "nsIsIndexFrame.h"
|
|
|
|
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsIAtom.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2005-01-28 01:52:53 +03:00
|
|
|
#include "nsPresState.h"
|
2000-08-04 03:45:50 +04:00
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIDocument.h"
|
2000-08-04 03:45:50 +04:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsIStatefulFrame.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
2000-08-04 03:45:50 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsLinebreakConverter.h"
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIHTMLDocument.h"
|
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2000-08-04 03:45:50 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsICharsetConverterManager.h"
|
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsIDOMKeyListener.h"
|
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsIFormControlFrame.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsINodeInfo.h"
|
|
|
|
#include "nsIDOMEventReceiver.h"
|
2001-02-20 00:50:04 +03:00
|
|
|
#include "nsContentCID.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2004-12-17 23:40:48 +03:00
|
|
|
#include "nsContentUtils.h"
|
2001-02-20 00:50:04 +03:00
|
|
|
|
2005-11-01 23:40:54 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewIsIndexFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsIsIndexFrame(aContext);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsIsIndexFrame::nsIsIndexFrame(nsStyleContext* aContext) :
|
|
|
|
nsAreaFrame(aContext)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
2005-11-21 01:05:24 +03:00
|
|
|
//Shrink the area around its contents
|
2004-10-27 05:36:35 +04:00
|
|
|
SetFlags(NS_BLOCK_SHRINK_WRAP | NS_BLOCK_SPACE_MGR);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIsIndexFrame::~nsIsIndexFrame()
|
|
|
|
{
|
|
|
|
// remove ourself as a listener of the text control (bug 40533)
|
|
|
|
if (mInputContent) {
|
2005-11-21 01:05:24 +03:00
|
|
|
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(mInputContent));
|
|
|
|
receiver->RemoveEventListenerByIID(this, NS_GET_IID(nsIDOMKeyListener));
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// REVIEW: We don't need to override BuildDisplayList, nsAreaFrame will honour
|
|
|
|
// our visibility setting
|
2001-01-27 17:09:34 +03:00
|
|
|
|
2000-08-04 03:45:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIsIndexFrame::UpdatePromptLabel()
|
|
|
|
{
|
|
|
|
if (!mTextContent) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2001-04-11 11:39:48 +04:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2000-08-04 03:45:50 +04:00
|
|
|
// Get the text from the "prompt" attribute.
|
|
|
|
// If it is zero length, set it to a default value (localized)
|
2005-01-19 02:46:59 +03:00
|
|
|
nsXPIDLString prompt;
|
2005-01-12 22:45:38 +03:00
|
|
|
if (mContent)
|
2006-12-26 20:47:52 +03:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::prompt, prompt);
|
2005-01-12 22:45:38 +03:00
|
|
|
|
2003-05-24 01:34:47 +04:00
|
|
|
if (prompt.IsEmpty()) {
|
2000-08-04 03:45:50 +04:00
|
|
|
// Generate localized label.
|
|
|
|
// We can't make any assumption as to what the default would be
|
|
|
|
// because the value is localized for non-english platforms, thus
|
|
|
|
// it might not be the string "This is a searchable index. Enter search keywords: "
|
2004-12-17 23:40:48 +03:00
|
|
|
result =
|
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
|
|
|
"IsIndexPrompt", prompt);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
2004-08-10 14:22:36 +04:00
|
|
|
|
|
|
|
mTextContent->SetText(prompt, PR_TRUE);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
|
2005-12-07 02:56:17 +03:00
|
|
|
nsresult
|
|
|
|
nsIsIndexFrame::GetInputFrame(nsIFormControlFrame** oFrame)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
2005-12-07 02:56:17 +03:00
|
|
|
nsIPresShell *presShell = GetPresContext()->GetPresShell();
|
2002-03-15 03:40:07 +03:00
|
|
|
if (!mInputContent) NS_WARNING("null content - cannot restore state");
|
|
|
|
if (presShell && mInputContent) {
|
2005-08-23 02:24:29 +04:00
|
|
|
nsIFrame *frame = presShell->GetPrimaryFrameFor(mInputContent);
|
2000-08-04 03:45:50 +04:00
|
|
|
if (frame) {
|
2005-12-07 02:56:17 +03:00
|
|
|
return CallQueryInterface(frame, oFrame);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-12-07 02:56:17 +03:00
|
|
|
void
|
|
|
|
nsIsIndexFrame::GetInputValue(nsString& oString)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
|
|
|
nsIFormControlFrame* frame = nsnull;
|
2005-12-07 02:56:17 +03:00
|
|
|
GetInputFrame(&frame);
|
2000-08-04 03:45:50 +04:00
|
|
|
if (frame) {
|
2002-05-16 22:26:05 +04:00
|
|
|
((nsNewFrame*)frame)->GetValue(oString, PR_FALSE);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-07 02:56:17 +03:00
|
|
|
void
|
|
|
|
nsIsIndexFrame::SetInputValue(const nsString& aString)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
|
|
|
nsIFormControlFrame* frame = nsnull;
|
2005-12-07 02:56:17 +03:00
|
|
|
GetInputFrame(&frame);
|
2000-08-04 03:45:50 +04:00
|
|
|
if (frame) {
|
2002-05-16 22:26:05 +04:00
|
|
|
((nsNewFrame*)frame)->SetValue(aString);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsIsIndexFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
nsIFormControlFrame* frame = nsnull;
|
2005-12-07 02:56:17 +03:00
|
|
|
GetInputFrame(&frame);
|
2000-08-04 03:45:50 +04:00
|
|
|
if (frame) {
|
|
|
|
frame->SetFocus(aOn, aRepaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsIsIndexFrame::CreateAnonymousContent(nsPresContext* aPresContext,
|
2000-08-04 03:45:50 +04:00
|
|
|
nsISupportsArray& aChildList)
|
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
// Get the node info manager (used to create hr's and input's)
|
2003-07-29 01:25:13 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
|
2004-06-25 16:26:02 +04:00
|
|
|
nsNodeInfoManager *nimgr = doc->NodeInfoManager();
|
2000-08-04 03:45:50 +04:00
|
|
|
|
|
|
|
// Create an hr
|
|
|
|
nsCOMPtr<nsINodeInfo> hrInfo;
|
2006-12-26 20:47:52 +03:00
|
|
|
nimgr->GetNodeInfo(nsGkAtoms::hr, nsnull, kNameSpaceID_None,
|
2003-06-14 00:10:01 +04:00
|
|
|
getter_AddRefs(hrInfo));
|
2004-06-25 16:26:02 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> prehr;
|
|
|
|
result = NS_NewHTMLElement(getter_AddRefs(prehr), hrInfo);
|
2001-02-20 00:50:04 +03:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
result = aChildList.AppendElement(prehr);
|
2000-08-04 03:45:50 +04:00
|
|
|
|
|
|
|
// Add a child text content node for the label
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2006-07-19 08:36:36 +04:00
|
|
|
nsCOMPtr<nsIContent> labelContent;
|
2005-09-24 22:43:15 +04:00
|
|
|
NS_NewTextNode(getter_AddRefs(labelContent), nimgr);
|
2004-08-10 14:22:36 +04:00
|
|
|
if (labelContent) {
|
2000-08-04 03:45:50 +04:00
|
|
|
// set the value of the text node and add it to the child list
|
2004-08-10 14:22:36 +04:00
|
|
|
mTextContent.swap(labelContent);
|
|
|
|
UpdatePromptLabel();
|
|
|
|
aChildList.AppendElement(mTextContent);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create text input field
|
|
|
|
nsCOMPtr<nsINodeInfo> inputInfo;
|
2006-12-26 20:47:52 +03:00
|
|
|
nimgr->GetNodeInfo(nsGkAtoms::input, nsnull, kNameSpaceID_None,
|
2003-06-14 00:10:01 +04:00
|
|
|
getter_AddRefs(inputInfo));
|
2000-08-04 03:45:50 +04:00
|
|
|
|
2004-08-10 14:22:36 +04:00
|
|
|
result = NS_NewHTMLElement(getter_AddRefs(mInputContent), inputInfo);
|
2001-02-20 00:50:04 +03:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
mInputContent->SetAttr(kNameSpaceID_None, nsGkAtoms::type, NS_LITERAL_STRING("text"), PR_FALSE);
|
2001-02-20 00:50:04 +03:00
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
aChildList.AppendElement(mInputContent);
|
2000-08-04 03:45:50 +04:00
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
// Register as an event listener to submit on Enter press
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(mInputContent));
|
|
|
|
receiver->AddEventListenerByIID(this, NS_GET_IID(nsIDOMKeyListener));
|
2000-08-04 03:45:50 +04:00
|
|
|
|
|
|
|
// Create an hr
|
2004-06-25 16:26:02 +04:00
|
|
|
nsCOMPtr<nsIContent> posthr;
|
|
|
|
result = NS_NewHTMLElement(getter_AddRefs(posthr), hrInfo);
|
2001-02-20 00:50:04 +03:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
aChildList.AppendElement(posthr);
|
2000-08-04 03:45:50 +04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Frames are not refcounted, no need to AddRef
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsIsIndexFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {
|
|
|
|
*aInstancePtr = (void*)(nsIAnonymousContentCreator*) this;
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
|
|
|
|
*aInstancePtr = (void*)(nsIStatefulFrame*) this;
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIDOMKeyListener))) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMKeyListener*) this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsIsIndexFrame::ScrollIntoView(nsPresContext* aPresContext)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
|
|
|
if (aPresContext) {
|
2003-12-21 08:36:36 +03:00
|
|
|
nsIPresShell *presShell = aPresContext->GetPresShell();
|
2000-09-08 09:53:28 +04:00
|
|
|
if (presShell) {
|
|
|
|
presShell->ScrollFrameIntoView(this,
|
2000-08-04 03:45:50 +04:00
|
|
|
NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE,NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE);
|
2000-09-08 09:53:28 +04:00
|
|
|
}
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord
|
|
|
|
nsIsIndexFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
|
|
|
// Our min width is our pref width; the rest of our reflow is
|
|
|
|
// happily handled by nsAreaFrame
|
|
|
|
result = GetPrefWidth(aRenderingContext);
|
|
|
|
return result;
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
|
2005-08-17 02:52:48 +04:00
|
|
|
PRBool
|
|
|
|
nsIsIndexFrame::IsLeaf() const
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2000-08-04 03:45:50 +04:00
|
|
|
NS_IMETHODIMP
|
2005-09-07 20:49:21 +04:00
|
|
|
nsIsIndexFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
2004-12-31 04:13:27 +03:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::prompt == aAttribute) {
|
2000-09-06 11:37:49 +04:00
|
|
|
rv = UpdatePromptLabel();
|
|
|
|
} else {
|
2005-09-07 20:49:21 +04:00
|
|
|
rv = nsAreaFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
2000-09-06 11:37:49 +04:00
|
|
|
return rv;
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsIsIndexFrame::KeyPress(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
|
|
|
|
if (keyEvent) {
|
|
|
|
PRUint32 code;
|
|
|
|
keyEvent->GetKeyCode(&code);
|
|
|
|
if (code == 0) {
|
|
|
|
keyEvent->GetCharCode(&code);
|
|
|
|
}
|
|
|
|
if (nsIDOMKeyEvent::DOM_VK_RETURN == code) {
|
2005-08-16 16:20:58 +04:00
|
|
|
OnSubmit(GetPresContext());
|
2000-08-04 03:45:50 +04:00
|
|
|
aEvent->PreventDefault(); // XXX Needed?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_IMETHODIMP
|
2001-11-14 04:33:42 +03:00
|
|
|
nsIsIndexFrame::GetFrameName(nsAString& aResult) const
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("IsIndex"), aResult);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// submission
|
|
|
|
// much of this is cut and paste from nsFormFrame::OnSubmit
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsIsIndexFrame::OnSubmit(nsPresContext* aPresContext)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
|
|
|
if (!mContent || !mInputContent) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2001-04-11 11:39:48 +04:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2000-08-04 03:45:50 +04:00
|
|
|
// Begin ProcessAsURLEncoded
|
|
|
|
nsAutoString data;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIUnicodeEncoder> encoder;
|
|
|
|
if(NS_FAILED(GetEncoder(getter_AddRefs(encoder)))) // Non-fatal error
|
|
|
|
encoder = nsnull;
|
|
|
|
|
|
|
|
nsAutoString value;
|
2005-12-07 02:56:17 +03:00
|
|
|
GetInputValue(value);
|
2000-08-04 03:45:50 +04:00
|
|
|
URLEncode(value, encoder, data);
|
|
|
|
// End ProcessAsURLEncoded
|
|
|
|
|
|
|
|
// make the url string
|
2004-02-01 13:09:07 +03:00
|
|
|
nsILinkHandler *handler = aPresContext->GetLinkHandler();
|
2000-08-04 03:45:50 +04:00
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
nsAutoString href;
|
2000-08-04 03:45:50 +04:00
|
|
|
|
2004-02-01 13:09:07 +03:00
|
|
|
// Get the document.
|
|
|
|
// We'll need it now to form the URL we're submitting to.
|
|
|
|
// We'll also need it later to get the DOM window when notifying form submit observers (bug 33203)
|
|
|
|
nsCOMPtr<nsIDocument> document = mContent->GetDocument();
|
|
|
|
if (!document) return NS_OK; // No doc means don't submit, see Bug 28988
|
|
|
|
|
|
|
|
// Resolve url to an absolute url
|
2006-03-24 03:09:50 +03:00
|
|
|
nsIURI *baseURI = document->GetBaseURI();
|
|
|
|
if (!baseURI) {
|
2004-02-01 13:09:07 +03:00
|
|
|
NS_ERROR("No Base URL found in Form Submit!\n");
|
|
|
|
return NS_OK; // No base URL -> exit early, see Bug 30721
|
|
|
|
}
|
|
|
|
|
|
|
|
// If an action is not specified and we are inside
|
|
|
|
// a HTML document then reload the URL. This makes us
|
|
|
|
// compatible with 4.x browsers.
|
|
|
|
// If we are in some other type of document such as XML or
|
|
|
|
// XUL, do nothing. This prevents undesirable reloading of
|
|
|
|
// a document inside XUL.
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc;
|
|
|
|
htmlDoc = do_QueryInterface(document, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Must be a XML, XUL or other non-HTML document type
|
|
|
|
// so do nothing.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Necko's MakeAbsoluteURI doesn't reuse the baseURL's rel path if it is
|
|
|
|
// passed a zero length rel path.
|
|
|
|
nsCAutoString relPath;
|
2006-03-24 03:09:50 +03:00
|
|
|
baseURI->GetSpec(relPath);
|
2004-02-01 13:09:07 +03:00
|
|
|
if (!relPath.IsEmpty()) {
|
|
|
|
CopyUTF8toUTF16(relPath, href);
|
|
|
|
|
|
|
|
// If re-using the same URL, chop off old query string (bug 25330)
|
|
|
|
PRInt32 queryStart = href.FindChar('?');
|
|
|
|
if (kNotFound != queryStart) {
|
|
|
|
href.Truncate(queryStart);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
2004-02-01 13:09:07 +03:00
|
|
|
} else {
|
|
|
|
NS_ERROR("Rel path couldn't be formed in form submit!\n");
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the URI encoded form values to the URI
|
|
|
|
// Get the scheme of the URI.
|
|
|
|
nsCOMPtr<nsIURI> actionURL;
|
|
|
|
nsXPIDLCString scheme;
|
|
|
|
PRBool isJSURL = PR_FALSE;
|
|
|
|
const nsACString &docCharset = document->GetDocumentCharacterSet();
|
|
|
|
const nsPromiseFlatCString& flatDocCharset = PromiseFlatCString(docCharset);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result = NS_NewURI(getter_AddRefs(actionURL), href,
|
|
|
|
flatDocCharset.get(),
|
2006-03-24 03:09:50 +03:00
|
|
|
baseURI))) {
|
2004-02-01 13:09:07 +03:00
|
|
|
result = actionURL->SchemeIs("javascript", &isJSURL);
|
|
|
|
}
|
|
|
|
// Append the URI encoded variable/value pairs for GET's
|
|
|
|
if (!isJSURL) { // Not for JS URIs, see bug 26917
|
|
|
|
if (href.FindChar('?') == kNotFound) { // Add a ? if needed
|
|
|
|
href.Append(PRUnichar('?'));
|
|
|
|
} else { // Adding to existing query string
|
|
|
|
if (href.Last() != '&' && href.Last() != '?') { // Add a & if needed
|
|
|
|
href.Append(PRUnichar('&'));
|
|
|
|
}
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
2004-02-01 13:09:07 +03:00
|
|
|
href.Append(data);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href,
|
2006-03-24 03:09:50 +03:00
|
|
|
flatDocCharset.get(), baseURI);
|
2004-02-01 13:09:07 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
// Now pass on absolute url to the click handler
|
|
|
|
if (handler) {
|
|
|
|
handler->OnLinkClick(mContent, eLinkVerb_Replace,
|
|
|
|
uri,
|
|
|
|
nsnull, nsnull);
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
void nsIsIndexFrame::GetSubmitCharset(nsCString& oCharset)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
oCharset.AssignLiteral("UTF-8"); // default to utf-8
|
2000-08-04 03:45:50 +04:00
|
|
|
// XXX
|
|
|
|
// We may want to get it from the HTML 4 Accept-Charset attribute first
|
|
|
|
// see 17.3 The FORM element in HTML 4 for details
|
|
|
|
|
|
|
|
// Get the charset from document
|
2003-07-29 01:25:13 +04:00
|
|
|
nsIDocument* doc = mContent->GetDocument();
|
2003-06-14 00:10:01 +04:00
|
|
|
if (doc) {
|
2003-10-22 10:09:48 +04:00
|
|
|
oCharset = doc->GetDocumentCharacterSet();
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsIsIndexFrame::GetEncoder(nsIUnicodeEncoder** encoder)
|
|
|
|
{
|
|
|
|
*encoder = nsnull;
|
2003-06-11 22:16:03 +04:00
|
|
|
nsCAutoString charset;
|
2000-08-04 03:45:50 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
GetSubmitCharset(charset);
|
|
|
|
|
|
|
|
// Get Charset, get the encoder.
|
|
|
|
nsICharsetConverterManager * ccm = nsnull;
|
2006-06-04 03:35:59 +04:00
|
|
|
rv = CallGetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &ccm);
|
2000-08-04 03:45:50 +04:00
|
|
|
if(NS_SUCCEEDED(rv) && (nsnull != ccm)) {
|
2003-06-11 22:16:03 +04:00
|
|
|
rv = ccm->GetUnicodeEncoderRaw(charset.get(), encoder);
|
2004-11-08 02:59:35 +03:00
|
|
|
NS_RELEASE(ccm);
|
2006-05-11 17:23:55 +04:00
|
|
|
if (!*encoder) {
|
2000-08-04 03:45:50 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = (*encoder)->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, (PRUnichar)'?');
|
|
|
|
}
|
|
|
|
}
|
2006-05-11 17:23:55 +04:00
|
|
|
return rv;
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX i18n helper routines
|
|
|
|
char*
|
|
|
|
nsIsIndexFrame::UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen, nsIUnicodeEncoder* encoder)
|
|
|
|
{
|
|
|
|
char* res = nsnull;
|
|
|
|
if(NS_SUCCEEDED(encoder->Reset()))
|
|
|
|
{
|
|
|
|
PRInt32 maxByteLen = 0;
|
|
|
|
if(NS_SUCCEEDED(encoder->GetMaxLength(aSrc, (PRInt32) aLen, &maxByteLen)))
|
|
|
|
{
|
|
|
|
res = new char[maxByteLen+1];
|
|
|
|
if(nsnull != res)
|
|
|
|
{
|
|
|
|
PRInt32 reslen = maxByteLen;
|
|
|
|
PRInt32 reslen2 ;
|
|
|
|
PRInt32 srclen = aLen;
|
|
|
|
encoder->Convert(aSrc, &srclen, res, &reslen);
|
|
|
|
reslen2 = maxByteLen-reslen;
|
|
|
|
encoder->Finish(res+reslen, &reslen2);
|
|
|
|
res[reslen+reslen2] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX i18n helper routines
|
|
|
|
void
|
|
|
|
nsIsIndexFrame::URLEncode(const nsString& aString, nsIUnicodeEncoder* encoder, nsString& oString)
|
|
|
|
{
|
|
|
|
char* inBuf = nsnull;
|
|
|
|
if(encoder)
|
2001-06-30 15:02:25 +04:00
|
|
|
inBuf = UnicodeToNewBytes(aString.get(), aString.Length(), encoder);
|
2000-08-04 03:45:50 +04:00
|
|
|
|
|
|
|
if(nsnull == inBuf)
|
2001-09-29 12:28:41 +04:00
|
|
|
inBuf = ToNewCString(aString);
|
2000-08-04 03:45:50 +04:00
|
|
|
|
|
|
|
// convert to CRLF breaks
|
|
|
|
char* convertedBuf = nsLinebreakConverter::ConvertLineBreaks(inBuf,
|
|
|
|
nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakNet);
|
|
|
|
delete [] inBuf;
|
|
|
|
|
|
|
|
char* outBuf = nsEscape(convertedBuf, url_XPAlphas);
|
2004-07-25 16:18:04 +04:00
|
|
|
oString.AssignASCII(outBuf);
|
2006-09-08 08:35:17 +04:00
|
|
|
nsMemory::Free(outBuf);
|
2000-08-04 03:45:50 +04:00
|
|
|
nsMemory::Free(convertedBuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIStatefulFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2005-12-07 02:56:17 +03:00
|
|
|
nsIsIndexFrame::SaveState(SpecialStateID aStateID, nsPresState** aState)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
2001-02-06 04:59:59 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
|
|
|
|
|
|
|
// Get the value string
|
2000-08-04 03:45:50 +04:00
|
|
|
nsAutoString stateString;
|
2005-12-07 02:56:17 +03:00
|
|
|
GetInputValue(stateString);
|
2000-08-04 03:45:50 +04:00
|
|
|
|
2005-12-07 02:56:17 +03:00
|
|
|
nsresult res = NS_OK;
|
2001-02-06 04:59:59 +03:00
|
|
|
if (! stateString.IsEmpty()) {
|
|
|
|
|
|
|
|
// Construct a pres state and store value in it.
|
|
|
|
res = NS_NewPresState(aState);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
res = (*aState)->SetStateProperty(NS_LITERAL_STRING("value"), stateString);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-12-07 02:56:17 +03:00
|
|
|
nsIsIndexFrame::RestoreState(nsPresState* aState)
|
2000-08-04 03:45:50 +04:00
|
|
|
{
|
2001-02-06 04:59:59 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
2000-08-04 03:45:50 +04:00
|
|
|
|
2001-02-06 04:59:59 +03:00
|
|
|
// Set the value to the stored state.
|
|
|
|
nsAutoString stateString;
|
|
|
|
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("value"), stateString);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
|
2005-12-07 02:56:17 +03:00
|
|
|
SetInputValue(stateString);
|
|
|
|
return NS_OK;
|
2000-08-04 03:45:50 +04:00
|
|
|
}
|