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
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/
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
15 * The Original Code is mozilla.org code.
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.
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.
36 * ***** END LICENSE BLOCK ***** */
38 /* derived class of nsBlockFrame; distinction barely relevant anymore */
40 #include "nsAreaFrame.h"
41 #include "nsBlockBandData.h"
42 #include "nsStyleContext.h"
43 #include "nsStyleConsts.h"
44 #include "nsPresContext.h"
45 #include "nsINodeInfo.h"
46 #include "nsGkAtoms.h"
47 #include "nsHTMLParts.h"
50 #include "nsINameSpaceManager.h"
51 #include "nsIEventStateManager.h"
54 #undef NOISY_MAX_ELEMENT_SIZE
55 #undef NOISY_FINAL_SIZE
58 NS_NewAreaFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
, PRUint32 aFlags
)
60 nsAreaFrame
* it
= new (aPresShell
) nsAreaFrame(aContext
);
70 // If you make changes to this function, check its counterparts
71 // in nsBoxFrame and nsTextBoxFrame
73 nsAreaFrame::RegUnregAccessKey(PRBool aDoReg
)
75 // if we have no content, we can't do anything
77 return NS_ERROR_FAILURE
;
79 // only support accesskeys for the following elements
80 if (!mContent
->NodeInfo()->Equals(nsGkAtoms::label
, kNameSpaceID_XUL
))
83 // To filter out <label>s without a control attribute.
84 // XXXjag a side-effect is that we filter out anonymous <label>s
85 // in e.g. <menu>, <menuitem>, <button>. These <label>s inherit
86 // |accesskey| and would otherwise register themselves, overwriting
87 // the content we really meant to be registered.
88 if (!mContent
->HasAttr(kNameSpaceID_None
, nsGkAtoms::control
))
91 nsAutoString accessKey
;
92 mContent
->GetAttr(kNameSpaceID_None
, nsGkAtoms::accesskey
, accessKey
);
94 if (accessKey
.IsEmpty())
97 // With a valid PresContext we can get the ESM
98 // and register the access key
99 nsIEventStateManager
*esm
= PresContext()->EventStateManager();
102 PRUint32 key
= accessKey
.First();
104 rv
= esm
->RegisterAccessKey(mContent
, key
);
106 rv
= esm
->UnregisterAccessKey(mContent
, key
);
112 /////////////////////////////////////////////////////////////////////////////
117 nsAreaFrame::Init(nsIContent
* aContent
,
119 nsIFrame
* aPrevInFlow
)
121 nsresult rv
= nsBlockFrame::Init(aContent
, aParent
, aPrevInFlow
);
125 // register access key
126 return RegUnregAccessKey(PR_TRUE
);
130 nsAreaFrame::Destroy()
132 // unregister access key
133 RegUnregAccessKey(PR_FALSE
);
134 nsBlockFrame::Destroy();
138 nsAreaFrame::AttributeChanged(PRInt32 aNameSpaceID
,
142 nsresult rv
= nsBlockFrame::AttributeChanged(aNameSpaceID
,
143 aAttribute
, aModType
);
145 // If the accesskey changed, register for the new value
146 // The old value has been unregistered in nsXULElement::SetAttr
147 if (aAttribute
== nsGkAtoms::accesskey
|| aAttribute
== nsGkAtoms::control
)
148 RegUnregAccessKey(PR_TRUE
);
155 nsAreaFrame::GetType() const
157 return nsGkAtoms::areaFrame
;
160 /////////////////////////////////////////////////////////////////////////////
165 nsAreaFrame::GetFrameName(nsAString
& aResult
) const
167 return MakeFrameName(NS_LITERAL_STRING("Area"), aResult
);