Back to index

lightning-sunbird  0.9+nobinonly
nsProgressMeterFrame.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 Communicator client 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 
00038 //
00039 // David Hyatt & Eric Vaughan
00040 // Netscape Communications
00041 //
00042 // See documentation in associated header file
00043 //
00044 
00045 #include "nsProgressMeterFrame.h"
00046 #include "nsCSSRendering.h"
00047 #include "nsIContent.h"
00048 #include "nsPresContext.h"
00049 #include "nsHTMLAtoms.h"
00050 #include "nsXULAtoms.h"
00051 #include "nsINameSpaceManager.h"
00052 #include "nsCOMPtr.h"
00053 #include "nsBoxLayoutState.h"
00054 //
00055 // NS_NewToolbarFrame
00056 //
00057 // Creates a new Toolbar frame and returns it in |aNewFrame|
00058 //
00059 nsresult
00060 NS_NewProgressMeterFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
00061 {
00062   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00063   if (nsnull == aNewFrame) {
00064     return NS_ERROR_NULL_POINTER;
00065   }
00066   nsProgressMeterFrame* it = new (aPresShell) nsProgressMeterFrame(aPresShell);
00067   if (nsnull == it)
00068     return NS_ERROR_OUT_OF_MEMORY;
00069 
00070   *aNewFrame = it;
00071   return NS_OK;
00072   
00073 } // NS_NewProgressMeterFrame
00074 
00075 //
00076 // nsProgressMeterFrame cntr
00077 //
00078 // Init, if necessary
00079 //
00080 nsProgressMeterFrame :: nsProgressMeterFrame (nsIPresShell* aPresShell)
00081 :nsBoxFrame(aPresShell)
00082 {
00083 }
00084 
00085 //
00086 // nsProgressMeterFrame dstr
00087 //
00088 // Cleanup, if necessary
00089 //
00090 nsProgressMeterFrame :: ~nsProgressMeterFrame ( )
00091 {
00092 }
00093 
00094 NS_IMETHODIMP
00095 nsProgressMeterFrame::SetInitialChildList(nsPresContext* aPresContext,
00096                                      nsIAtom*        aListName,
00097                                      nsIFrame*       aChildList)
00098 { 
00099   // Set up our initial flexes.
00100   nsresult rv = nsBoxFrame::SetInitialChildList(aPresContext, aListName, aChildList);
00101   AttributeChanged(mContent, kNameSpaceID_None, nsHTMLAtoms::value, 0);
00102   return rv;
00103 }
00104 
00105 NS_IMETHODIMP
00106 nsProgressMeterFrame::AttributeChanged(nsIContent* aChild,
00107                                        PRInt32 aNameSpaceID,
00108                                        nsIAtom* aAttribute,
00109                                        PRInt32 aModType)
00110 {
00111   nsresult rv = nsBoxFrame::AttributeChanged(aChild, aNameSpaceID,
00112                                              aAttribute, aModType);
00113   if (NS_OK != rv) {
00114     return rv;
00115   }
00116 
00117   // did the progress change?
00118   if (nsHTMLAtoms::value == aAttribute) {
00119     nsIFrame* barChild = GetFirstChild(nsnull);
00120     if (!barChild) return NS_OK;
00121     nsIFrame* remainderChild = barChild->GetNextSibling();
00122     if (!remainderChild) return NS_OK;
00123     nsCOMPtr<nsIContent> remainderContent = remainderChild->GetContent();
00124     if (!remainderContent) return NS_OK;
00125 
00126     nsAutoString value;
00127     mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::value, value);
00128 
00129     PRInt32 error;
00130     PRInt32 flex = value.ToInteger(&error);
00131     if (flex < 0) flex = 0;
00132     if (flex > 100) flex = 100;
00133 
00134     PRInt32 remainder = 100 - flex;
00135 
00136     nsAutoString leftFlex, rightFlex;
00137     leftFlex.AppendInt(flex);
00138     rightFlex.AppendInt(remainder);
00139     nsWeakFrame weakFrame(this);
00140     barChild->GetContent()->SetAttr(kNameSpaceID_None, nsXULAtoms::flex, leftFlex, PR_TRUE);
00141     remainderContent->SetAttr(kNameSpaceID_None, nsXULAtoms::flex, rightFlex, PR_TRUE);
00142 
00143     if (weakFrame.IsAlive()) {
00144       nsBoxLayoutState state(GetPresContext());
00145       MarkDirty(state);
00146     }
00147   }
00148   return NS_OK;
00149 }
00150 
00151 #ifdef NS_DEBUG
00152 NS_IMETHODIMP
00153 nsProgressMeterFrame::GetFrameName(nsAString& aResult) const
00154 {
00155   return MakeFrameName(NS_LITERAL_STRING("ProgressMeter"), aResult);
00156 }
00157 #endif