1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* derived class of nsBlockFrame used for xul:label elements */
8 #include "mozilla/EventStateManager.h"
9 #include "nsXULLabelFrame.h"
10 #include "nsHTMLParts.h"
11 #include "nsNameSpaceManager.h"
13 using namespace mozilla
;
16 NS_NewXULLabelFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
18 nsXULLabelFrame
* it
= new (aPresShell
) nsXULLabelFrame(aContext
);
20 it
->SetFlags(NS_BLOCK_FLOAT_MGR
| NS_BLOCK_MARGIN_ROOT
);
25 NS_IMPL_FRAMEARENA_HELPERS(nsXULLabelFrame
)
27 // If you make changes to this function, check its counterparts
28 // in nsBoxFrame and nsTextBoxFrame
30 nsXULLabelFrame::RegUnregAccessKey(bool aDoReg
)
32 // if we have no content, we can't do anything
34 return NS_ERROR_FAILURE
;
36 // To filter out <label>s without a control attribute.
37 // XXXjag a side-effect is that we filter out anonymous <label>s
38 // in e.g. <menu>, <menuitem>, <button>. These <label>s inherit
39 // |accesskey| and would otherwise register themselves, overwriting
40 // the content we really meant to be registered.
41 if (!mContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::control
))
44 nsAutoString accessKey
;
45 mContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::accesskey
, accessKey
);
47 if (accessKey
.IsEmpty())
50 // With a valid PresContext we can get the ESM
51 // and register the access key
52 EventStateManager
* esm
= PresContext()->EventStateManager();
54 uint32_t key
= accessKey
.First();
56 esm
->RegisterAccessKey(mContent
, key
);
58 esm
->UnregisterAccessKey(mContent
, key
);
63 /////////////////////////////////////////////////////////////////////////////
67 nsXULLabelFrame::Init(nsIContent
* aContent
,
68 nsContainerFrame
* aParent
,
69 nsIFrame
* aPrevInFlow
)
71 nsBlockFrame::Init(aContent
, aParent
, aPrevInFlow
);
73 // register access key
74 RegUnregAccessKey(true);
78 nsXULLabelFrame::DestroyFrom(nsIFrame
* aDestructRoot
)
80 // unregister access key
81 RegUnregAccessKey(false);
82 nsBlockFrame::DestroyFrom(aDestructRoot
);
86 nsXULLabelFrame::AttributeChanged(int32_t aNameSpaceID
,
90 nsresult rv
= nsBlockFrame::AttributeChanged(aNameSpaceID
,
91 aAttribute
, aModType
);
93 // If the accesskey changed, register for the new value
94 // The old value has been unregistered in nsXULElement::SetAttr
95 if (aAttribute
== nsGkAtoms::accesskey
|| aAttribute
== nsGkAtoms::control
)
96 RegUnregAccessKey(true);
102 nsXULLabelFrame::GetType() const
104 return nsGkAtoms::XULLabelFrame
;
107 /////////////////////////////////////////////////////////////////////////////
110 #ifdef DEBUG_FRAME_DUMP
112 nsXULLabelFrame::GetFrameName(nsAString
& aResult
) const
114 return MakeFrameName(NS_LITERAL_STRING("XULLabel"), aResult
);