Back to index

lightning-sunbird  0.9+nobinonly
nsScrollbarFrame.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 // Eric Vaughan
00040 // Netscape Communications
00041 //
00042 // See documentation in associated header file
00043 //
00044 
00045 #include "nsScrollbarFrame.h"
00046 #include "nsScrollbarButtonFrame.h"
00047 #include "nsXULAtoms.h"
00048 #include "nsIScrollableFrame.h"
00049 #include "nsIView.h"
00050 #include "nsIViewManager.h"
00051 #include "nsIScrollbarMediator.h"
00052 
00053 //
00054 // NS_NewToolbarFrame
00055 //
00056 // Creates a new Toolbar frame and returns it in |aNewFrame|
00057 //
00058 nsresult
00059 NS_NewScrollbarFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
00060 {
00061   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00062   if (nsnull == aNewFrame) {
00063     return NS_ERROR_NULL_POINTER;
00064   }
00065   nsScrollbarFrame* it = new (aPresShell) nsScrollbarFrame (aPresShell);
00066   if (nsnull == it)
00067     return NS_ERROR_OUT_OF_MEMORY;
00068 
00069   *aNewFrame = it;
00070   return NS_OK;
00071   
00072 } // NS_NewScrollbarFrame
00073 
00074 //
00075 // QueryInterface
00076 //
00077 NS_INTERFACE_MAP_BEGIN(nsScrollbarFrame)
00078   NS_INTERFACE_MAP_ENTRY(nsIScrollbarFrame)
00079 NS_INTERFACE_MAP_END_INHERITING(nsBoxFrame)
00080 
00081 
00082 NS_IMETHODIMP
00083 nsScrollbarFrame::Init(nsPresContext*  aPresContext,
00084               nsIContent*      aContent,
00085               nsIFrame*        aParent,
00086               nsStyleContext*  aContext,
00087               nsIFrame*        aPrevInFlow)
00088 {
00089   nsresult  rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
00090   CreateViewForFrame(aPresContext,this,aContext,PR_TRUE);
00091   nsIView* view = GetView();
00092   view->GetViewManager()->SetViewContentTransparency(view, PR_TRUE);
00093 
00094   // We want to be a reflow root since we use reflows to move the
00095   // slider.  Any reflow inside the scrollbar frame will be a reflow to
00096   // move the slider and will thus not change anything outside of the
00097   // scrollbar or change the size of the scrollbar frame.
00098   mState |= NS_FRAME_REFLOW_ROOT;
00099 
00100   return rv;
00101 }
00102 
00103 NS_IMETHODIMP
00104 nsScrollbarFrame::Reflow(nsPresContext*          aPresContext,
00105                          nsHTMLReflowMetrics&     aDesiredSize,
00106                          const nsHTMLReflowState& aReflowState,
00107                          nsReflowStatus&          aStatus)
00108 {
00109   nsresult rv = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
00110   NS_ENSURE_SUCCESS(rv, rv);
00111 
00112   // nsGfxScrollFrame may have told us to shrink to nothing. If so, make sure our
00113   // desired size agrees.
00114   if (aReflowState.availableWidth == 0) {
00115     aDesiredSize.width = 0;
00116   }
00117   if (aReflowState.availableHeight == 0) {
00118     aDesiredSize.height = 0;
00119   }
00120 
00121   return NS_OK;
00122 }
00123 
00124 /* virtual */ PRBool
00125 nsScrollbarFrame::IsContainingBlock() const
00126 {
00127   // Return true so that the nsHTMLReflowState code is happy with us
00128   // being a reflow root.
00129   return PR_TRUE;
00130 }
00131 
00132 NS_IMETHODIMP
00133 nsScrollbarFrame::AttributeChanged(nsIContent* aChild,
00134                                    PRInt32 aNameSpaceID,
00135                                    nsIAtom* aAttribute,
00136                                    PRInt32 aModType)
00137 {
00138   nsresult rv = nsBoxFrame::AttributeChanged(aChild, aNameSpaceID,
00139                                              aAttribute, aModType);
00140 
00141   // if the current position changes, notify any nsGfxScrollFrame
00142   // parent we may have
00143   if (aAttribute != nsXULAtoms::curpos)
00144     return rv;
00145 
00146   nsIFrame* parent = GetParent();
00147   if (!parent)
00148     return rv;
00149 
00150   nsIScrollableFrame* scrollable = nsnull;
00151   parent->QueryInterface(NS_GET_IID(nsIScrollableFrame), (void**)&scrollable);
00152   if (!scrollable)
00153     return rv;
00154 
00155   scrollable->CurPosAttributeChanged(aChild, aModType);
00156   return rv;
00157 }
00158 
00159 NS_IMETHODIMP
00160 nsScrollbarFrame::HandlePress(nsPresContext* aPresContext, 
00161                      nsGUIEvent*     aEvent,
00162                      nsEventStatus*  aEventStatus)
00163 {
00164   return NS_OK;
00165 }
00166 
00167 NS_IMETHODIMP
00168 nsScrollbarFrame::HandleMultiplePress(nsPresContext* aPresContext, 
00169                      nsGUIEvent*     aEvent,
00170                      nsEventStatus*  aEventStatus)
00171 {
00172   return NS_OK;
00173 }
00174 
00175 NS_IMETHODIMP 
00176 nsScrollbarFrame::HandleDrag(nsPresContext* aPresContext, 
00177                               nsGUIEvent*     aEvent,
00178                               nsEventStatus*  aEventStatus)
00179 {
00180   return NS_OK;
00181 }
00182 
00183 NS_IMETHODIMP 
00184 nsScrollbarFrame::HandleRelease(nsPresContext* aPresContext, 
00185                                  nsGUIEvent*     aEvent,
00186                                  nsEventStatus*  aEventStatus)
00187 {
00188   return NS_OK;
00189 }
00190 
00191 NS_IMETHODIMP
00192 nsScrollbarFrame::SetScrollbarMediator(nsIScrollbarMediator* aMediator)
00193 {
00194   nsIFrame* f = nsnull;
00195   if (aMediator) {
00196     CallQueryInterface(aMediator, &f);
00197   }
00198   if (f) {
00199     mScrollbarMediator = f->GetContent();
00200   } else {
00201     mScrollbarMediator = nsnull;
00202   }
00203   return NS_OK;
00204 }
00205 
00206 NS_IMETHODIMP
00207 nsScrollbarFrame::GetScrollbarMediator(nsIScrollbarMediator** aResult)
00208 {
00209   *aResult = nsnull;
00210   if (!mScrollbarMediator)
00211     return NS_OK;
00212   nsIFrame* f;
00213   nsresult rv = GetPresContext()->PresShell()->GetPrimaryFrameFor(mScrollbarMediator, &f);
00214   if (NS_FAILED(rv) || !f)
00215     return rv;
00216 
00217   // check if the frame is a scroll frame. If so, get the scrollable frame
00218   // inside it.
00219   nsIScrollableFrame* scrollFrame;
00220   CallQueryInterface(f, &scrollFrame);
00221   if (scrollFrame) {
00222     f = scrollFrame->GetScrolledFrame();
00223     if (!f)
00224       return NS_ERROR_FAILURE;
00225   }
00226 
00227   CallQueryInterface(f, aResult);
00228   return NS_OK;
00229 }