|
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/. */ |
|
5 |
|
6 /* derived class of nsBlockFrame used for xul:label elements */ |
|
7 |
|
8 #include "mozilla/EventStateManager.h" |
|
9 #include "nsXULLabelFrame.h" |
|
10 #include "nsHTMLParts.h" |
|
11 #include "nsNameSpaceManager.h" |
|
12 |
|
13 using namespace mozilla; |
|
14 |
|
15 nsIFrame* |
|
16 NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
|
17 { |
|
18 nsXULLabelFrame* it = new (aPresShell) nsXULLabelFrame(aContext); |
|
19 |
|
20 it->SetFlags(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT); |
|
21 |
|
22 return it; |
|
23 } |
|
24 |
|
25 NS_IMPL_FRAMEARENA_HELPERS(nsXULLabelFrame) |
|
26 |
|
27 // If you make changes to this function, check its counterparts |
|
28 // in nsBoxFrame and nsTextBoxFrame |
|
29 nsresult |
|
30 nsXULLabelFrame::RegUnregAccessKey(bool aDoReg) |
|
31 { |
|
32 // if we have no content, we can't do anything |
|
33 if (!mContent) |
|
34 return NS_ERROR_FAILURE; |
|
35 |
|
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)) |
|
42 return NS_OK; |
|
43 |
|
44 nsAutoString accessKey; |
|
45 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey); |
|
46 |
|
47 if (accessKey.IsEmpty()) |
|
48 return NS_OK; |
|
49 |
|
50 // With a valid PresContext we can get the ESM |
|
51 // and register the access key |
|
52 EventStateManager* esm = PresContext()->EventStateManager(); |
|
53 |
|
54 uint32_t key = accessKey.First(); |
|
55 if (aDoReg) |
|
56 esm->RegisterAccessKey(mContent, key); |
|
57 else |
|
58 esm->UnregisterAccessKey(mContent, key); |
|
59 |
|
60 return NS_OK; |
|
61 } |
|
62 |
|
63 ///////////////////////////////////////////////////////////////////////////// |
|
64 // nsIFrame |
|
65 |
|
66 void |
|
67 nsXULLabelFrame::Init(nsIContent* aContent, |
|
68 nsIFrame* aParent, |
|
69 nsIFrame* aPrevInFlow) |
|
70 { |
|
71 nsBlockFrame::Init(aContent, aParent, aPrevInFlow); |
|
72 |
|
73 // register access key |
|
74 RegUnregAccessKey(true); |
|
75 } |
|
76 |
|
77 void |
|
78 nsXULLabelFrame::DestroyFrom(nsIFrame* aDestructRoot) |
|
79 { |
|
80 // unregister access key |
|
81 RegUnregAccessKey(false); |
|
82 nsBlockFrame::DestroyFrom(aDestructRoot); |
|
83 } |
|
84 |
|
85 nsresult |
|
86 nsXULLabelFrame::AttributeChanged(int32_t aNameSpaceID, |
|
87 nsIAtom* aAttribute, |
|
88 int32_t aModType) |
|
89 { |
|
90 nsresult rv = nsBlockFrame::AttributeChanged(aNameSpaceID, |
|
91 aAttribute, aModType); |
|
92 |
|
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); |
|
97 |
|
98 return rv; |
|
99 } |
|
100 |
|
101 nsIAtom* |
|
102 nsXULLabelFrame::GetType() const |
|
103 { |
|
104 return nsGkAtoms::XULLabelFrame; |
|
105 } |
|
106 |
|
107 ///////////////////////////////////////////////////////////////////////////// |
|
108 // Diagnostics |
|
109 |
|
110 #ifdef DEBUG_FRAME_DUMP |
|
111 nsresult |
|
112 nsXULLabelFrame::GetFrameName(nsAString& aResult) const |
|
113 { |
|
114 return MakeFrameName(NS_LITERAL_STRING("XULLabel"), aResult); |
|
115 } |
|
116 #endif |