1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : /* derived class of nsBlockFrame used for xul:label elements */
39 :
40 : #include "nsXULLabelFrame.h"
41 : #include "nsHTMLParts.h"
42 : #include "nsINameSpaceManager.h"
43 : #include "nsEventStateManager.h"
44 :
45 : nsIFrame*
46 0 : NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
47 : {
48 0 : nsXULLabelFrame* it = new (aPresShell) nsXULLabelFrame(aContext);
49 :
50 0 : if (it)
51 0 : it->SetFlags(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT);
52 :
53 0 : return it;
54 : }
55 :
56 0 : NS_IMPL_FRAMEARENA_HELPERS(nsXULLabelFrame)
57 :
58 : // If you make changes to this function, check its counterparts
59 : // in nsBoxFrame and nsTextBoxFrame
60 : nsresult
61 0 : nsXULLabelFrame::RegUnregAccessKey(bool aDoReg)
62 : {
63 : // if we have no content, we can't do anything
64 0 : if (!mContent)
65 0 : return NS_ERROR_FAILURE;
66 :
67 : // To filter out <label>s without a control attribute.
68 : // XXXjag a side-effect is that we filter out anonymous <label>s
69 : // in e.g. <menu>, <menuitem>, <button>. These <label>s inherit
70 : // |accesskey| and would otherwise register themselves, overwriting
71 : // the content we really meant to be registered.
72 0 : if (!mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::control))
73 0 : return NS_OK;
74 :
75 0 : nsAutoString accessKey;
76 0 : mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
77 :
78 0 : if (accessKey.IsEmpty())
79 0 : return NS_OK;
80 :
81 : // With a valid PresContext we can get the ESM
82 : // and register the access key
83 0 : nsEventStateManager *esm = PresContext()->EventStateManager();
84 :
85 0 : PRUint32 key = accessKey.First();
86 0 : if (aDoReg)
87 0 : esm->RegisterAccessKey(mContent, key);
88 : else
89 0 : esm->UnregisterAccessKey(mContent, key);
90 :
91 0 : return NS_OK;
92 : }
93 :
94 : /////////////////////////////////////////////////////////////////////////////
95 : // nsIFrame
96 :
97 : NS_IMETHODIMP
98 0 : nsXULLabelFrame::Init(nsIContent* aContent,
99 : nsIFrame* aParent,
100 : nsIFrame* aPrevInFlow)
101 : {
102 0 : nsresult rv = nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
103 0 : if (NS_FAILED(rv))
104 0 : return rv;
105 :
106 : // register access key
107 0 : return RegUnregAccessKey(true);
108 : }
109 :
110 : void
111 0 : nsXULLabelFrame::DestroyFrom(nsIFrame* aDestructRoot)
112 : {
113 : // unregister access key
114 0 : RegUnregAccessKey(false);
115 0 : nsBlockFrame::DestroyFrom(aDestructRoot);
116 0 : }
117 :
118 : NS_IMETHODIMP
119 0 : nsXULLabelFrame::AttributeChanged(PRInt32 aNameSpaceID,
120 : nsIAtom* aAttribute,
121 : PRInt32 aModType)
122 : {
123 : nsresult rv = nsBlockFrame::AttributeChanged(aNameSpaceID,
124 0 : aAttribute, aModType);
125 :
126 : // If the accesskey changed, register for the new value
127 : // The old value has been unregistered in nsXULElement::SetAttr
128 0 : if (aAttribute == nsGkAtoms::accesskey || aAttribute == nsGkAtoms::control)
129 0 : RegUnregAccessKey(true);
130 :
131 0 : return rv;
132 : }
133 :
134 : nsIAtom*
135 0 : nsXULLabelFrame::GetType() const
136 : {
137 0 : return nsGkAtoms::XULLabelFrame;
138 : }
139 :
140 : /////////////////////////////////////////////////////////////////////////////
141 : // Diagnostics
142 :
143 : #ifdef NS_DEBUG
144 : NS_IMETHODIMP
145 0 : nsXULLabelFrame::GetFrameName(nsAString& aResult) const
146 : {
147 0 : return MakeFrameName(NS_LITERAL_STRING("XULLabel"), aResult);
148 : }
149 : #endif
|