2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
2008-12-29 18:07:38 +03:00
|
|
|
/* derived class of nsBlockFrame used for xul:label elements */
|
1998-12-18 20:54:54 +03:00
|
|
|
|
2008-12-29 18:07:38 +03:00
|
|
|
#include "nsXULLabelFrame.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
|
|
|
|
#include "mozilla/EventStateManager.h"
|
|
|
|
#include "mozilla/PresShell.h"
|
2008-12-29 18:07:38 +03:00
|
|
|
#include "nsHTMLParts.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
1998-12-18 20:54:54 +03:00
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsIFrame* NS_NewXULLabelFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
nsXULLabelFrame* it =
|
|
|
|
new (aPresShell) nsXULLabelFrame(aStyle, aPresShell->GetPresContext());
|
2016-12-23 21:11:04 +03:00
|
|
|
it->AddStateBits(NS_BLOCK_FORMATTING_CONTEXT_STATE_BITS);
|
2005-10-27 01:46:39 +04:00
|
|
|
return it;
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsXULLabelFrame)
|
|
|
|
|
2002-02-21 16:39:39 +03:00
|
|
|
// If you make changes to this function, check its counterparts
|
|
|
|
// in nsBoxFrame and nsTextBoxFrame
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult nsXULLabelFrame::RegUnregAccessKey(bool aDoReg) {
|
2002-02-21 16:39:39 +03:00
|
|
|
// 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.
|
2017-12-07 21:13:50 +03:00
|
|
|
if (!mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::control))
|
2002-02-21 16:39:39 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsAutoString accessKey;
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey,
|
|
|
|
accessKey);
|
2002-02-21 16:39:39 +03:00
|
|
|
|
|
|
|
if (accessKey.IsEmpty()) return NS_OK;
|
|
|
|
|
|
|
|
// With a valid PresContext we can get the ESM
|
|
|
|
// and register the access key
|
2014-04-01 08:09:23 +04:00
|
|
|
EventStateManager* esm = PresContext()->EventStateManager();
|
2004-02-27 20:17:37 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t key = accessKey.First();
|
2004-02-27 20:17:37 +03:00
|
|
|
if (aDoReg)
|
2017-12-07 21:13:50 +03:00
|
|
|
esm->RegisterAccessKey(mContent->AsElement(), key);
|
2004-02-27 20:17:37 +03:00
|
|
|
else
|
2017-12-07 21:13:50 +03:00
|
|
|
esm->UnregisterAccessKey(mContent->AsElement(), key);
|
2002-02-21 16:39:39 +03:00
|
|
|
|
2011-04-21 21:35:52 +04:00
|
|
|
return NS_OK;
|
2002-02-21 16:39:39 +03:00
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIFrame
|
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsXULLabelFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2013-03-20 05:47:48 +04:00
|
|
|
nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
|
2002-02-21 16:39:39 +03:00
|
|
|
|
|
|
|
// register access key
|
2013-03-20 05:47:48 +04:00
|
|
|
RegUnregAccessKey(true);
|
2002-02-21 16:39:39 +03:00
|
|
|
}
|
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
void nsXULLabelFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) {
|
2002-02-21 16:39:39 +03:00
|
|
|
// unregister access key
|
2011-10-17 18:59:28 +04:00
|
|
|
RegUnregAccessKey(false);
|
2017-11-07 03:20:33 +03:00
|
|
|
nsBlockFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
2002-02-21 16:39:39 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsXULLabelFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType) {
|
2005-09-07 20:49:21 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsBlockFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2002-02-21 16:39:39 +03:00
|
|
|
|
|
|
|
// If the accesskey changed, register for the new value
|
|
|
|
// The old value has been unregistered in nsXULElement::SetAttr
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::accesskey || aAttribute == nsGkAtoms::control)
|
2011-10-17 18:59:28 +04:00
|
|
|
RegUnregAccessKey(true);
|
2002-02-21 16:39:39 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Diagnostics
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2008-12-29 18:07:38 +03:00
|
|
|
nsresult nsXULLabelFrame::GetFrameName(nsAString& aResult) const {
|
2020-07-01 11:29:29 +03:00
|
|
|
return MakeFrameName(u"XULLabel"_ns, aResult);
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|