LCOV - code coverage report
Current view: directory - layout/xul/base/src - nsRootBoxFrame.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 89 0 0.0 %
Date: 2012-06-02 Functions: 23 0 0.0 %

       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
       4                 :  *
       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/
       9                 :  *
      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.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      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.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      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.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #include "nsHTMLParts.h"
      39                 : #include "nsIDocument.h"
      40                 : #include "nsGUIEvent.h"
      41                 : #include "nsStyleConsts.h"
      42                 : #include "nsGkAtoms.h"
      43                 : #include "nsIPresShell.h"
      44                 : #include "nsBoxFrame.h"
      45                 : #include "nsStackLayout.h"
      46                 : #include "nsIRootBox.h"
      47                 : #include "nsIContent.h"
      48                 : #include "nsXULTooltipListener.h"
      49                 : #include "nsFrameManager.h"
      50                 : 
      51                 : // Interface IDs
      52                 : 
      53                 : //#define DEBUG_REFLOW
      54                 : 
      55                 : // static
      56                 : nsIRootBox*
      57               0 : nsIRootBox::GetRootBox(nsIPresShell* aShell)
      58                 : {
      59               0 :   if (!aShell) {
      60               0 :     return nsnull;
      61                 :   }
      62               0 :   nsIFrame* rootFrame = aShell->FrameManager()->GetRootFrame();
      63               0 :   if (!rootFrame) {
      64               0 :     return nsnull;
      65                 :   }
      66                 : 
      67               0 :   if (rootFrame) {
      68               0 :     rootFrame = rootFrame->GetFirstPrincipalChild();
      69                 :   }
      70                 : 
      71               0 :   nsIRootBox* rootBox = do_QueryFrame(rootFrame);
      72               0 :   return rootBox;
      73                 : }
      74                 : 
      75               0 : class nsRootBoxFrame : public nsBoxFrame, public nsIRootBox {
      76                 : public:
      77                 : 
      78                 :   friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
      79                 : 
      80                 :   nsRootBoxFrame(nsIPresShell* aShell, nsStyleContext *aContext);
      81                 : 
      82                 :   NS_DECL_QUERYFRAME
      83                 :   NS_DECL_FRAMEARENA_HELPERS
      84                 : 
      85                 :   virtual nsPopupSetFrame* GetPopupSetFrame();
      86                 :   virtual void SetPopupSetFrame(nsPopupSetFrame* aPopupSet);
      87                 :   virtual nsIContent* GetDefaultTooltip();
      88                 :   virtual void SetDefaultTooltip(nsIContent* aTooltip);
      89                 :   virtual nsresult AddTooltipSupport(nsIContent* aNode);
      90                 :   virtual nsresult RemoveTooltipSupport(nsIContent* aNode);
      91                 : 
      92                 :   NS_IMETHOD AppendFrames(ChildListID     aListID,
      93                 :                           nsFrameList&    aFrameList);
      94                 :   NS_IMETHOD InsertFrames(ChildListID     aListID,
      95                 :                           nsIFrame*       aPrevFrame,
      96                 :                           nsFrameList&    aFrameList);
      97                 :   NS_IMETHOD RemoveFrame(ChildListID     aListID,
      98                 :                          nsIFrame*       aOldFrame);
      99                 : 
     100                 :   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
     101                 :                     nsHTMLReflowMetrics&     aDesiredSize,
     102                 :                     const nsHTMLReflowState& aReflowState,
     103                 :                     nsReflowStatus&          aStatus);
     104                 :   NS_IMETHOD HandleEvent(nsPresContext* aPresContext, 
     105                 :                          nsGUIEvent*     aEvent,
     106                 :                          nsEventStatus*  aEventStatus);
     107                 : 
     108                 :   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
     109                 :                               const nsRect&           aDirtyRect,
     110                 :                               const nsDisplayListSet& aLists);
     111                 : 
     112                 :   /**
     113                 :    * Get the "type" of the frame
     114                 :    *
     115                 :    * @see nsGkAtoms::rootFrame
     116                 :    */
     117                 :   virtual nsIAtom* GetType() const;
     118                 : 
     119               0 :   virtual bool IsFrameOfType(PRUint32 aFlags) const
     120                 :   {
     121                 :     // Override bogus IsFrameOfType in nsBoxFrame.
     122               0 :     if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
     123               0 :       return false;
     124               0 :     return nsBoxFrame::IsFrameOfType(aFlags);
     125                 :   }
     126                 :   
     127                 : #ifdef DEBUG
     128                 :   NS_IMETHOD GetFrameName(nsAString& aResult) const;
     129                 : #endif
     130                 : 
     131                 :   nsPopupSetFrame* mPopupSetFrame;
     132                 : 
     133                 : protected:
     134                 :   nsIContent* mDefaultTooltip;
     135                 : };
     136                 : 
     137                 : //----------------------------------------------------------------------
     138                 : 
     139                 : nsIFrame*
     140               0 : NS_NewRootBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
     141                 : {
     142               0 :   return new (aPresShell) nsRootBoxFrame (aPresShell, aContext);
     143                 : }
     144                 : 
     145               0 : NS_IMPL_FRAMEARENA_HELPERS(nsRootBoxFrame)
     146                 : 
     147               0 : nsRootBoxFrame::nsRootBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext):
     148               0 :   nsBoxFrame(aShell, aContext, true)
     149                 : {
     150               0 :   mPopupSetFrame = nsnull;
     151                 : 
     152               0 :   nsCOMPtr<nsBoxLayout> layout;
     153               0 :   NS_NewStackLayout(aShell, layout);
     154               0 :   SetLayoutManager(layout);
     155               0 : }
     156                 : 
     157                 : NS_IMETHODIMP
     158               0 : nsRootBoxFrame::AppendFrames(ChildListID     aListID,
     159                 :                              nsFrameList&    aFrameList)
     160                 : {
     161                 :   nsresult  rv;
     162                 : 
     163               0 :   NS_ASSERTION(aListID == kPrincipalList, "unexpected child list ID");
     164               0 :   NS_PRECONDITION(mFrames.IsEmpty(), "already have a child frame");
     165               0 :   if (aListID != kPrincipalList) {
     166                 :     // We only support the principal child list.
     167               0 :     rv = NS_ERROR_INVALID_ARG;
     168               0 :   } else if (!mFrames.IsEmpty()) {
     169                 :     // We only allow a single child frame.
     170               0 :     rv = NS_ERROR_FAILURE;
     171                 :   } else {
     172               0 :     rv = nsBoxFrame::AppendFrames(aListID, aFrameList);
     173                 :   }
     174                 : 
     175               0 :   return rv;
     176                 : }
     177                 : 
     178                 : NS_IMETHODIMP
     179               0 : nsRootBoxFrame::InsertFrames(ChildListID     aListID,
     180                 :                              nsIFrame*       aPrevFrame,
     181                 :                              nsFrameList&    aFrameList)
     182                 : {
     183                 :   nsresult  rv;
     184                 : 
     185                 :   // Because we only support a single child frame inserting is the same
     186                 :   // as appending.
     187               0 :   NS_PRECONDITION(!aPrevFrame, "unexpected previous sibling frame");
     188               0 :   if (aPrevFrame) {
     189               0 :     rv = NS_ERROR_UNEXPECTED;
     190                 :   } else {
     191               0 :     rv = AppendFrames(aListID, aFrameList);
     192                 :   }
     193                 : 
     194               0 :   return rv;
     195                 : }
     196                 : 
     197                 : NS_IMETHODIMP
     198               0 : nsRootBoxFrame::RemoveFrame(ChildListID     aListID,
     199                 :                             nsIFrame*       aOldFrame)
     200                 : {
     201                 :   nsresult  rv;
     202                 : 
     203               0 :   NS_ASSERTION(aListID == kPrincipalList, "unexpected child list ID");
     204               0 :   if (aListID != kPrincipalList) {
     205                 :     // We only support the principal child list.
     206               0 :     rv = NS_ERROR_INVALID_ARG;
     207               0 :   } else if (aOldFrame == mFrames.FirstChild()) {
     208               0 :     rv = nsBoxFrame::RemoveFrame(aListID, aOldFrame);
     209                 :   } else {
     210               0 :     rv = NS_ERROR_FAILURE;
     211                 :   }
     212                 : 
     213               0 :   return rv;
     214                 : }
     215                 : 
     216                 : #ifdef DEBUG_REFLOW
     217                 : PRInt32 gReflows = 0;
     218                 : #endif
     219                 : 
     220                 : NS_IMETHODIMP
     221               0 : nsRootBoxFrame::Reflow(nsPresContext*           aPresContext,
     222                 :                        nsHTMLReflowMetrics&     aDesiredSize,
     223                 :                        const nsHTMLReflowState& aReflowState,
     224                 :                        nsReflowStatus&          aStatus)
     225                 : {
     226               0 :   DO_GLOBAL_REFLOW_COUNT("nsRootBoxFrame");
     227                 : 
     228                 : #ifdef DEBUG_REFLOW
     229                 :   gReflows++;
     230                 :   printf("----Reflow %d----\n", gReflows);
     231                 : #endif
     232               0 :   return nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
     233                 : }
     234                 : 
     235                 : nsresult
     236               0 : nsRootBoxFrame::BuildDisplayList(nsDisplayListBuilder*   aBuilder,
     237                 :                                  const nsRect&           aDirtyRect,
     238                 :                                  const nsDisplayListSet& aLists)
     239                 : {
     240                 :   // root boxes don't need a debug border/outline or a selection overlay...
     241                 :   // They *may* have a background propagated to them, so force creation
     242                 :   // of a background display list element.
     243               0 :   nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists, true);
     244               0 :   NS_ENSURE_SUCCESS(rv, rv);
     245                 : 
     246               0 :   return BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
     247                 : }
     248                 : 
     249                 : NS_IMETHODIMP
     250               0 : nsRootBoxFrame::HandleEvent(nsPresContext* aPresContext, 
     251                 :                        nsGUIEvent* aEvent,
     252                 :                        nsEventStatus* aEventStatus)
     253                 : {
     254               0 :   NS_ENSURE_ARG_POINTER(aEventStatus);
     255               0 :   if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
     256               0 :     return NS_OK;
     257                 :   }
     258                 : 
     259               0 :   if (aEvent->message == NS_MOUSE_BUTTON_UP) {
     260               0 :     nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
     261                 :   }
     262                 : 
     263               0 :   return NS_OK;
     264                 : }
     265                 : 
     266                 : // REVIEW: The override here was doing nothing since nsBoxFrame is our
     267                 : // parent class
     268                 : nsIAtom*
     269               0 : nsRootBoxFrame::GetType() const
     270                 : {
     271               0 :   return nsGkAtoms::rootFrame;
     272                 : }
     273                 : 
     274                 : nsPopupSetFrame*
     275               0 : nsRootBoxFrame::GetPopupSetFrame()
     276                 : {
     277               0 :   return mPopupSetFrame;
     278                 : }
     279                 : 
     280                 : void
     281               0 : nsRootBoxFrame::SetPopupSetFrame(nsPopupSetFrame* aPopupSet)
     282                 : {
     283                 :   // Under normal conditions this should only be called once.  However,
     284                 :   // if something triggers ReconstructDocElementHierarchy, we will
     285                 :   // destroy this frame's child (the nsDocElementBoxFrame), but not this
     286                 :   // frame.  This will cause the popupset to remove itself by calling
     287                 :   // |SetPopupSetFrame(nsnull)|, and then we'll be able to accept a new
     288                 :   // popupset.  Since the anonymous content is associated with the
     289                 :   // nsDocElementBoxFrame, we'll get a new popupset when the new doc
     290                 :   // element box frame is created.
     291               0 :   if (!mPopupSetFrame || !aPopupSet) {
     292               0 :     mPopupSetFrame = aPopupSet;
     293                 :   } else {
     294               0 :     NS_NOTREACHED("Popup set is already defined! Only 1 allowed.");
     295                 :   }
     296               0 : }
     297                 : 
     298                 : nsIContent*
     299               0 : nsRootBoxFrame::GetDefaultTooltip()
     300                 : {
     301               0 :   return mDefaultTooltip;
     302                 : }
     303                 : 
     304                 : void
     305               0 : nsRootBoxFrame::SetDefaultTooltip(nsIContent* aTooltip)
     306                 : {
     307               0 :   mDefaultTooltip = aTooltip;
     308               0 : }
     309                 : 
     310                 : nsresult
     311               0 : nsRootBoxFrame::AddTooltipSupport(nsIContent* aNode)
     312                 : {
     313               0 :   NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
     314                 : 
     315               0 :   nsXULTooltipListener *listener = nsXULTooltipListener::GetInstance();
     316               0 :   if (!listener)
     317               0 :     return NS_ERROR_OUT_OF_MEMORY;
     318                 : 
     319               0 :   return listener->AddTooltipSupport(aNode);
     320                 : }
     321                 : 
     322                 : nsresult
     323               0 : nsRootBoxFrame::RemoveTooltipSupport(nsIContent* aNode)
     324                 : {
     325                 :   // XXjh yuck, I'll have to implement a way to get at
     326                 :   // the tooltip listener for a given node to make 
     327                 :   // this work.  Not crucial, we aren't removing 
     328                 :   // tooltips from any nodes in the app just yet.
     329               0 :   return NS_ERROR_NOT_IMPLEMENTED;
     330                 : }
     331                 : 
     332               0 : NS_QUERYFRAME_HEAD(nsRootBoxFrame)
     333               0 :   NS_QUERYFRAME_ENTRY(nsIRootBox)
     334               0 : NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
     335                 : 
     336                 : #ifdef DEBUG
     337                 : NS_IMETHODIMP
     338               0 : nsRootBoxFrame::GetFrameName(nsAString& aResult) const
     339                 : {
     340               0 :   return MakeFrameName(NS_LITERAL_STRING("RootBox"), aResult);
     341                 : }
     342                 : #endif

Generated by: LCOV version 1.7