Back to index

lightning-sunbird  0.9+nobinonly
nsAreaFrame.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #include "nsAreaFrame.h"
00038 #include "nsBlockBandData.h"
00039 #include "nsStyleContext.h"
00040 #include "nsStyleConsts.h"
00041 #include "nsPresContext.h"
00042 #include "nsIViewManager.h"
00043 #include "nsINodeInfo.h"
00044 #include "nsHTMLAtoms.h"
00045 #include "nsIView.h"
00046 #include "nsHTMLParts.h"
00047 #include "nsLayoutAtoms.h"
00048 
00049 #ifdef MOZ_XUL
00050 #include "nsINameSpaceManager.h"
00051 #include "nsXULAtoms.h"
00052 #include "nsIEventStateManager.h"
00053 #endif
00054 
00055 #undef NOISY_MAX_ELEMENT_SIZE
00056 #undef NOISY_FINAL_SIZE
00057 
00058 nsresult
00059 NS_NewAreaFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRUint32 aFlags)
00060 {
00061   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00062   if (nsnull == aNewFrame) {
00063     return NS_ERROR_NULL_POINTER;
00064   }
00065   nsAreaFrame* it = new (aPresShell) nsAreaFrame;
00066   if (nsnull == it) {
00067     return NS_ERROR_OUT_OF_MEMORY;
00068   }
00069   it->SetFlags(aFlags);
00070   *aNewFrame = it;
00071   return NS_OK;
00072 }
00073 
00074 nsAreaFrame::nsAreaFrame()
00075 {
00076 }
00077 
00078 #ifdef MOZ_XUL
00079 
00080 // If you make changes to this function, check its counterparts 
00081 // in nsBoxFrame and nsTextBoxFrame
00082 nsresult
00083 nsAreaFrame::RegUnregAccessKey(nsPresContext* aPresContext,
00084                                PRBool aDoReg)
00085 {
00086   // if we have no content, we can't do anything
00087   if (!mContent)
00088     return NS_ERROR_FAILURE;
00089 
00090   nsINodeInfo *ni = mContent->GetNodeInfo();
00091 
00092   // only support accesskeys for the following elements
00093   if (!ni || !ni->Equals(nsXULAtoms::label, kNameSpaceID_XUL))
00094     return NS_OK;
00095 
00096   // To filter out <label>s without a control attribute.
00097   // XXXjag a side-effect is that we filter out anonymous <label>s
00098   // in e.g. <menu>, <menuitem>, <button>. These <label>s inherit
00099   // |accesskey| and would otherwise register themselves, overwriting
00100   // the content we really meant to be registered.
00101   if (!mContent->HasAttr(kNameSpaceID_None, nsXULAtoms::control))
00102     return NS_OK;
00103 
00104   nsAutoString accessKey;
00105   mContent->GetAttr(kNameSpaceID_None, nsXULAtoms::accesskey, accessKey);
00106 
00107   if (accessKey.IsEmpty())
00108     return NS_OK;
00109 
00110   // With a valid PresContext we can get the ESM 
00111   // and register the access key
00112   nsIEventStateManager *esm = aPresContext->EventStateManager();
00113   nsresult rv;
00114 
00115   PRUint32 key = accessKey.First();
00116   if (aDoReg)
00117     rv = esm->RegisterAccessKey(mContent, key);
00118   else
00119     rv = esm->UnregisterAccessKey(mContent, key);
00120 
00121   return rv;
00122 }
00123 #endif
00124 
00126 // nsIFrame
00127 
00128 #ifdef MOZ_XUL
00129 NS_IMETHODIMP
00130 nsAreaFrame::Init(nsPresContext*  aPresContext,
00131                   nsIContent*      aContent,
00132                   nsIFrame*        aParent,
00133                   nsStyleContext*  aContext,
00134                   nsIFrame*        aPrevInFlow)
00135 {
00136   nsresult rv = nsBlockFrame::Init(aPresContext,
00137                                    aContent,
00138                                    aParent,
00139                                    aContext,
00140                                    aPrevInFlow);
00141   if (NS_FAILED(rv))
00142     return rv;
00143 
00144   // register access key
00145   return RegUnregAccessKey(aPresContext, PR_TRUE);
00146 }
00147 
00148 NS_IMETHODIMP
00149 nsAreaFrame::Destroy(nsPresContext* aPresContext)
00150 {
00151   // unregister access key
00152   RegUnregAccessKey(aPresContext, PR_FALSE);
00153 
00154   return nsBlockFrame::Destroy(aPresContext);
00155 } 
00156 
00157 NS_IMETHODIMP
00158 nsAreaFrame::AttributeChanged(nsIContent* aChild,
00159                               PRInt32 aNameSpaceID,
00160                               nsIAtom* aAttribute,
00161                               PRInt32 aModType)
00162 {
00163   nsresult rv = nsBlockFrame::AttributeChanged(aChild, aNameSpaceID, 
00164                                                aAttribute, aModType);
00165 
00166   // If the accesskey changed, register for the new value
00167   // The old value has been unregistered in nsXULElement::SetAttr
00168   if (aAttribute == nsXULAtoms::accesskey || aAttribute == nsXULAtoms::control)
00169     RegUnregAccessKey(GetPresContext(), PR_TRUE);
00170 
00171   return rv;
00172 }
00173 #endif
00174 
00175 nsIAtom*
00176 nsAreaFrame::GetType() const
00177 {
00178   return nsLayoutAtoms::areaFrame;
00179 }
00180 
00182 // Diagnostics
00183 
00184 #ifdef NS_DEBUG
00185 NS_IMETHODIMP
00186 nsAreaFrame::GetFrameName(nsAString& aResult) const
00187 {
00188   return MakeFrameName(NS_LITERAL_STRING("Area"), aResult);
00189 }
00190 #endif