2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-29 07:07:38 -08:00
|
|
|
/* derived class of nsBlockFrame used for xul:label elements */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-29 07:07:38 -08:00
|
|
|
#include "nsXULLabelFrame.h"
|
|
|
|
#include "nsHTMLParts.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsINameSpaceManager.h"
|
2011-04-21 10:35:52 -07:00
|
|
|
#include "nsEventStateManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:33 -08:00
|
|
|
NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-29 07:07:38 -08:00
|
|
|
nsXULLabelFrame* it = new (aPresShell) nsXULLabelFrame(aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-02 21:11:06 -07:00
|
|
|
it->SetFlags(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsXULLabelFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If you make changes to this function, check its counterparts
|
|
|
|
// in nsBoxFrame and nsTextBoxFrame
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULLabelFrame::RegUnregAccessKey(bool aDoReg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// if we have no content, we can't do anything
|
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// 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, nsGkAtoms::control))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsAutoString accessKey;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
|
|
|
|
|
|
|
|
if (accessKey.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// With a valid PresContext we can get the ESM
|
|
|
|
// and register the access key
|
2011-04-21 10:35:52 -07:00
|
|
|
nsEventStateManager *esm = PresContext()->EventStateManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t key = accessKey.First();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aDoReg)
|
2011-04-21 10:35:52 -07:00
|
|
|
esm->RegisterAccessKey(mContent, key);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2011-04-21 10:35:52 -07:00
|
|
|
esm->UnregisterAccessKey(mContent, key);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIFrame
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2008-12-29 07:07:38 -08:00
|
|
|
nsXULLabelFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// register access key
|
2013-03-19 18:47:48 -07:00
|
|
|
RegUnregAccessKey(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsXULLabelFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// unregister access key
|
2011-10-17 07:59:28 -07:00
|
|
|
RegUnregAccessKey(false);
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBlockFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULLabelFrame::AttributeChanged(int32_t aNameSpaceID,
|
2008-12-29 07:07:38 -08:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsBlockFrame::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
|
|
|
|
// If the accesskey changed, register for the new value
|
|
|
|
// The old value has been unregistered in nsXULElement::SetAttr
|
|
|
|
if (aAttribute == nsGkAtoms::accesskey || aAttribute == nsGkAtoms::control)
|
2011-10-17 07:59:28 -07:00
|
|
|
RegUnregAccessKey(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
2008-12-29 07:07:38 -08:00
|
|
|
nsXULLabelFrame::GetType() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-29 07:07:38 -08:00
|
|
|
return nsGkAtoms::XULLabelFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Diagnostics
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2008-12-29 07:07:38 -08:00
|
|
|
nsXULLabelFrame::GetFrameName(nsAString& aResult) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-29 07:07:38 -08:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("XULLabel"), aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|