Bug 54488 - "[Mac] Non-draggable widgets in background windows should look disabled...
[mozilla-central.git] / layout / generic / nsAreaFrame.cpp
blobdaaf9c0d769bcb7ec521596f02c831081c161e8c
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
13 * License.
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.
22 * Contributor(s):
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"
49 #ifdef MOZ_XUL
50 #include "nsINameSpaceManager.h"
51 #include "nsIEventStateManager.h"
52 #endif
54 #undef NOISY_MAX_ELEMENT_SIZE
55 #undef NOISY_FINAL_SIZE
57 nsIFrame*
58 NS_NewAreaFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags)
60 nsAreaFrame* it = new (aPresShell) nsAreaFrame(aContext);
62 if (it != nsnull)
63 it->SetFlags(aFlags);
65 return it;
68 #ifdef MOZ_XUL
70 // If you make changes to this function, check its counterparts
71 // in nsBoxFrame and nsTextBoxFrame
72 nsresult
73 nsAreaFrame::RegUnregAccessKey(PRBool aDoReg)
75 // if we have no content, we can't do anything
76 if (!mContent)
77 return NS_ERROR_FAILURE;
79 // only support accesskeys for the following elements
80 if (!mContent->NodeInfo()->Equals(nsGkAtoms::label, kNameSpaceID_XUL))
81 return NS_OK;
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))
89 return NS_OK;
91 nsAutoString accessKey;
92 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
94 if (accessKey.IsEmpty())
95 return NS_OK;
97 // With a valid PresContext we can get the ESM
98 // and register the access key
99 nsIEventStateManager *esm = PresContext()->EventStateManager();
100 nsresult rv;
102 PRUint32 key = accessKey.First();
103 if (aDoReg)
104 rv = esm->RegisterAccessKey(mContent, key);
105 else
106 rv = esm->UnregisterAccessKey(mContent, key);
108 return rv;
110 #endif
112 /////////////////////////////////////////////////////////////////////////////
113 // nsIFrame
115 #ifdef MOZ_XUL
116 NS_IMETHODIMP
117 nsAreaFrame::Init(nsIContent* aContent,
118 nsIFrame* aParent,
119 nsIFrame* aPrevInFlow)
121 nsresult rv = nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
122 if (NS_FAILED(rv))
123 return rv;
125 // register access key
126 return RegUnregAccessKey(PR_TRUE);
129 void
130 nsAreaFrame::Destroy()
132 // unregister access key
133 RegUnregAccessKey(PR_FALSE);
134 nsBlockFrame::Destroy();
137 NS_IMETHODIMP
138 nsAreaFrame::AttributeChanged(PRInt32 aNameSpaceID,
139 nsIAtom* aAttribute,
140 PRInt32 aModType)
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);
150 return rv;
152 #endif
154 nsIAtom*
155 nsAreaFrame::GetType() const
157 return nsGkAtoms::areaFrame;
160 /////////////////////////////////////////////////////////////////////////////
161 // Diagnostics
163 #ifdef NS_DEBUG
164 NS_IMETHODIMP
165 nsAreaFrame::GetFrameName(nsAString& aResult) const
167 return MakeFrameName(NS_LITERAL_STRING("Area"), aResult);
169 #endif