2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-18 20:54:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1998-12-18 20:54:54 +03: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.
|
1998-12-18 20:54:54 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-12-18 20:54:54 +03:00
|
|
|
#include "nsAreaFrame.h"
|
1999-04-10 21:30:46 +04:00
|
|
|
#include "nsBlockBandData.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1998-12-18 20:54:54 +03:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsHTMLValue.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
|
2002-02-21 16:39:39 +03:00
|
|
|
#ifdef INCLUDE_XUL
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsXULAtoms.h"
|
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#endif
|
|
|
|
|
1999-07-14 21:26:12 +04:00
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
1999-09-18 03:15:53 +04:00
|
|
|
#undef NOISY_FINAL_SIZE
|
1998-12-18 20:54:54 +03:00
|
|
|
|
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewAreaFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRUint32 aFlags)
|
1998-12-18 20:54:54 +03:00
|
|
|
{
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
nsAreaFrame* it = new (aPresShell) nsAreaFrame;
|
1998-12-18 20:54:54 +03:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
it->SetFlags(aFlags);
|
1999-05-12 02:03:29 +04:00
|
|
|
*aNewFrame = it;
|
1998-12-18 20:54:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAreaFrame::nsAreaFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-02-21 16:39:39 +03:00
|
|
|
#ifdef INCLUDE_XUL
|
|
|
|
|
|
|
|
// If you make changes to this function, check its counterparts
|
|
|
|
// in nsBoxFrame and nsTextBoxFrame
|
|
|
|
nsresult
|
|
|
|
nsAreaFrame::RegUnregAccessKey(nsIPresContext* aPresContext,
|
|
|
|
PRBool aDoReg)
|
|
|
|
{
|
|
|
|
// if we have no content, we can't do anything
|
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRBool isXUL = mContent->IsContentOfType(nsIContent::eXUL);
|
|
|
|
if (!isXUL)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// find out what type of element this is
|
|
|
|
nsCOMPtr<nsIAtom> atom;
|
|
|
|
nsresult rv = mContent->GetTag(*getter_AddRefs(atom));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// only support accesskeys for the following elements
|
|
|
|
if (atom != nsXULAtoms::label)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// To filter out <label>s without a control attribute.
|
|
|
|
// XXXjag a side-effect is that we filter out anonymous <label>s
|
|
|
|
// in e.g. <menu>, <menuitem>, <button>. These <label>s inherit
|
|
|
|
// |accesskey| and would otherwise register themselves, overwriting
|
|
|
|
// the content we really meant to be registered.
|
|
|
|
if (!mContent->HasAttr(kNameSpaceID_None, nsXULAtoms::control))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsAutoString accessKey;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsXULAtoms::accesskey, accessKey);
|
|
|
|
|
|
|
|
if (accessKey.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// With a valid PresContext we can get the ESM
|
|
|
|
// and register the access key
|
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
|
|
|
aPresContext->GetEventStateManager(getter_AddRefs(esm));
|
|
|
|
|
|
|
|
rv = NS_OK;
|
|
|
|
|
|
|
|
if (esm) {
|
|
|
|
PRUint32 key = accessKey.First();
|
|
|
|
if (aDoReg)
|
2002-05-22 04:14:51 +04:00
|
|
|
rv = esm->RegisterAccessKey(mContent, key);
|
2002-02-21 16:39:39 +03:00
|
|
|
else
|
2002-05-22 04:14:51 +04:00
|
|
|
rv = esm->UnregisterAccessKey(mContent, key);
|
2002-02-21 16:39:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIFrame
|
|
|
|
|
2002-02-21 16:39:39 +03:00
|
|
|
#ifdef INCLUDE_XUL
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::Init(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aContext,
|
2002-02-21 16:39:39 +03:00
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBlockFrame::Init(aPresContext,
|
|
|
|
aContent,
|
|
|
|
aParent,
|
|
|
|
aContext,
|
|
|
|
aPrevInFlow);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// register access key
|
|
|
|
return RegUnregAccessKey(aPresContext, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::Destroy(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
// unregister access key
|
|
|
|
RegUnregAccessKey(aPresContext, PR_FALSE);
|
|
|
|
|
|
|
|
return nsBlockFrame::Destroy(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBlockFrame::AttributeChanged(aPresContext, aChild,
|
|
|
|
aNameSpaceID, aAttribute,
|
|
|
|
aModType, aHint);
|
|
|
|
|
|
|
|
// If the accesskey changed, register for the new value
|
|
|
|
// The old value has been unregistered in nsXULElement::SetAttr
|
|
|
|
if (aAttribute == nsXULAtoms::accesskey || aAttribute == nsXULAtoms::control)
|
|
|
|
RegUnregAccessKey(aPresContext, PR_TRUE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-02-14 06:47:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::areaFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Diagnostics
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef NS_DEBUG
|
1998-12-18 20:54:54 +03:00
|
|
|
NS_IMETHODIMP
|
2001-11-14 04:33:42 +03:00
|
|
|
nsAreaFrame::GetFrameName(nsAString& aResult) const
|
1998-12-18 20:54:54 +03:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Area"), aResult);
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|