LCOV - code coverage report
Current view: directory - layout/forms - nsComboboxControlFrame.h (source / functions) Found Hit Coverage
Test: app.info Lines: 14 0 0.0 %
Date: 2012-06-02 Functions: 10 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                 :  *   Dean Tessman <dean_tessman@hotmail.com>
      24                 :  *   Mats Palmgren <matspal@gmail.com>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef nsComboboxControlFrame_h___
      41                 : #define nsComboboxControlFrame_h___
      42                 : 
      43                 : #ifdef DEBUG_evaughan
      44                 : //#define DEBUG_rods
      45                 : #endif
      46                 : 
      47                 : #ifdef DEBUG_rods
      48                 : //#define DO_REFLOW_DEBUG
      49                 : //#define DO_REFLOW_COUNTER
      50                 : //#define DO_UNCONSTRAINED_CHECK
      51                 : //#define DO_PIXELS
      52                 : //#define DO_NEW_REFLOW
      53                 : #endif
      54                 : 
      55                 : //Mark used to indicate when onchange has been fired for current combobox item
      56                 : #define NS_SKIP_NOTIFY_INDEX -2
      57                 : 
      58                 : #include "nsBlockFrame.h"
      59                 : #include "nsIFormControlFrame.h"
      60                 : #include "nsIComboboxControlFrame.h"
      61                 : #include "nsIAnonymousContentCreator.h"
      62                 : #include "nsISelectControlFrame.h"
      63                 : #include "nsIRollupListener.h"
      64                 : #include "nsPresState.h"
      65                 : #include "nsCSSFrameConstructor.h"
      66                 : #include "nsIStatefulFrame.h"
      67                 : #include "nsIScrollableFrame.h"
      68                 : #include "nsIDOMEventListener.h"
      69                 : #include "nsThreadUtils.h"
      70                 : 
      71                 : class nsIView;
      72                 : class nsStyleContext;
      73                 : class nsIListControlFrame;
      74                 : class nsComboboxDisplayFrame;
      75                 : 
      76                 : class nsComboboxControlFrame : public nsBlockFrame,
      77                 :                                public nsIFormControlFrame,
      78                 :                                public nsIComboboxControlFrame,
      79                 :                                public nsIAnonymousContentCreator,
      80                 :                                public nsISelectControlFrame,
      81                 :                                public nsIRollupListener,
      82                 :                                public nsIStatefulFrame
      83                 : {
      84                 : public:
      85                 :   friend nsIFrame* NS_NewComboboxControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRUint32 aFlags);
      86                 :   friend class nsComboboxDisplayFrame;
      87                 : 
      88                 :   nsComboboxControlFrame(nsStyleContext* aContext);
      89                 :   ~nsComboboxControlFrame();
      90                 : 
      91                 :   NS_DECL_QUERYFRAME
      92                 :   NS_DECL_FRAMEARENA_HELPERS
      93                 : 
      94                 :   // nsIAnonymousContentCreator
      95                 :   virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
      96                 :   virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
      97                 :                                         PRUint32 aFilter);
      98                 :   virtual nsIFrame* CreateFrameFor(nsIContent* aContent);
      99                 : 
     100                 : #ifdef ACCESSIBILITY
     101                 :   virtual already_AddRefed<nsAccessible> CreateAccessible();
     102                 : #endif
     103                 : 
     104                 :   virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext);
     105                 : 
     106                 :   virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext);
     107                 : 
     108                 :   NS_IMETHOD Reflow(nsPresContext*          aCX,
     109                 :                     nsHTMLReflowMetrics&     aDesiredSize,
     110                 :                     const nsHTMLReflowState& aReflowState,
     111                 :                     nsReflowStatus&          aStatus);
     112                 : 
     113                 :   NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
     114                 :                          nsGUIEvent* aEvent,
     115                 :                          nsEventStatus* aEventStatus);
     116                 : 
     117                 :   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
     118                 :                               const nsRect&           aDirtyRect,
     119                 :                               const nsDisplayListSet& aLists);
     120                 : 
     121                 :   void PaintFocus(nsRenderingContext& aRenderingContext, nsPoint aPt);
     122                 : 
     123                 :   // XXXbz this is only needed to prevent the quirk percent height stuff from
     124                 :   // leaking out of the combobox.  We may be able to get rid of this as more
     125                 :   // things move to IsFrameOfType.
     126                 :   virtual nsIAtom* GetType() const;
     127                 : 
     128               0 :   virtual bool IsFrameOfType(PRUint32 aFlags) const
     129                 :   {
     130                 :     return nsBlockFrame::IsFrameOfType(aFlags &
     131               0 :       ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
     132                 :   }
     133                 : 
     134               0 :   virtual nsIScrollableFrame* GetScrollTargetFrame() {
     135               0 :     return do_QueryFrame(mDropdownFrame);
     136                 :   }
     137                 : 
     138                 : #ifdef NS_DEBUG
     139                 :   NS_IMETHOD GetFrameName(nsAString& aResult) const;
     140                 : #endif
     141                 :   virtual void DestroyFrom(nsIFrame* aDestructRoot);
     142                 :   NS_IMETHOD SetInitialChildList(ChildListID     aListID,
     143                 :                                  nsFrameList&    aChildList);
     144                 :   virtual const nsFrameList& GetChildList(ChildListID aListID) const;
     145                 :   virtual void GetChildLists(nsTArray<ChildList>* aLists) const;
     146                 : 
     147                 :   virtual nsIFrame* GetContentInsertionFrame();
     148                 : 
     149                 :   // nsIFormControlFrame
     150                 :   virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue);
     151                 :   virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const; 
     152                 :   /**
     153                 :    * Inform the control that it got (or lost) focus.
     154                 :    * If it lost focus, the dropdown menu will be rolled up if needed,
     155                 :    * and FireOnChange() will be called.
     156                 :    * @param aOn true if got focus, false if lost focus.
     157                 :    * @param aRepaint if true then force repaint (NOTE: we always force repaint currently)
     158                 :    * @note This method might destroy |this|.
     159                 :    */
     160                 :   virtual void SetFocus(bool aOn, bool aRepaint);
     161                 : 
     162                 :   //nsIComboboxControlFrame
     163               0 :   virtual bool IsDroppedDown() { return mDroppedDown; }
     164                 :   /**
     165                 :    * @note This method might destroy |this|.
     166                 :    */
     167                 :   virtual void ShowDropDown(bool aDoDropDown);
     168                 :   virtual nsIFrame* GetDropDown();
     169                 :   virtual void SetDropDown(nsIFrame* aDropDownFrame);
     170                 :   /**
     171                 :    * @note This method might destroy |this|.
     172                 :    */
     173                 :   virtual void RollupFromList();
     174                 :   virtual void AbsolutelyPositionDropDown();
     175                 :   virtual PRInt32 GetIndexOfDisplayArea();
     176                 :   /**
     177                 :    * @note This method might destroy |this|.
     178                 :    */
     179                 :   NS_IMETHOD RedisplaySelectedText();
     180                 :   virtual PRInt32 UpdateRecentIndex(PRInt32 aIndex);
     181                 :   virtual void OnContentReset();
     182                 : 
     183                 :   // nsISelectControlFrame
     184                 :   NS_IMETHOD AddOption(PRInt32 index);
     185                 :   NS_IMETHOD RemoveOption(PRInt32 index);
     186                 :   NS_IMETHOD DoneAddingChildren(bool aIsDone);
     187                 :   NS_IMETHOD OnOptionSelected(PRInt32 aIndex, bool aSelected);
     188                 :   NS_IMETHOD OnSetSelectedIndex(PRInt32 aOldIndex, PRInt32 aNewIndex);
     189                 : 
     190                 :   //nsIRollupListener
     191                 :   /**
     192                 :    * Hide the dropdown menu and stop capturing mouse events.
     193                 :    * @note This method might destroy |this|.
     194                 :    */
     195                 :   virtual nsIContent* Rollup(PRUint32 aCount, bool aGetLastRolledUp = false);
     196                 : 
     197                 :   /**
     198                 :    * A combobox should roll up if a mousewheel event happens outside of
     199                 :    * the popup area.
     200                 :    */
     201               0 :   virtual bool ShouldRollupOnMouseWheelEvent()
     202               0 :     { return true; }
     203                 : 
     204                 :   /**
     205                 :    * A combobox should not roll up if activated by a mouse activate message
     206                 :    * (eg. X-mouse).
     207                 :    */
     208               0 :   virtual bool ShouldRollupOnMouseActivate()
     209               0 :     { return false; }
     210                 : 
     211               0 :   virtual PRUint32 GetSubmenuWidgetChain(nsTArray<nsIWidget*> *aWidgetChain)
     212               0 :     { return 0; }
     213                 : 
     214                 :   //nsIStatefulFrame
     215                 :   NS_IMETHOD SaveState(SpecialStateID aStateID, nsPresState** aState);
     216                 :   NS_IMETHOD RestoreState(nsPresState* aState);
     217                 : 
     218                 :   static bool ToolkitHasNativePopup();
     219                 : 
     220                 : protected:
     221                 : 
     222                 :   // Utilities
     223                 :   nsresult ReflowDropdown(nsPresContext*          aPresContext, 
     224                 :                           const nsHTMLReflowState& aReflowState);
     225                 : 
     226                 :   // Helper for GetMinWidth/GetPrefWidth
     227                 :   nscoord GetIntrinsicWidth(nsRenderingContext* aRenderingContext,
     228                 :                             nsLayoutUtils::IntrinsicWidthType aType);
     229                 : protected:
     230                 :   class RedisplayTextEvent;
     231                 :   friend class RedisplayTextEvent;
     232                 : 
     233               0 :   class RedisplayTextEvent : public nsRunnable {
     234                 :   public:
     235                 :     NS_DECL_NSIRUNNABLE
     236               0 :     RedisplayTextEvent(nsComboboxControlFrame *c) : mControlFrame(c) {}
     237               0 :     void Revoke() { mControlFrame = nsnull; }
     238                 :   private:
     239                 :     nsComboboxControlFrame *mControlFrame;
     240                 :   };
     241                 :   
     242                 :   /**
     243                 :    * Show or hide the dropdown list.
     244                 :    * @note This method might destroy |this|.
     245                 :    */
     246                 :   void ShowPopup(bool aShowPopup);
     247                 : 
     248                 :   /**
     249                 :    * Show or hide the dropdown list.
     250                 :    * @param aShowList true to show, false to hide the dropdown.
     251                 :    * @note This method might destroy |this|.
     252                 :    * @return false if this frame is destroyed, true if still alive.
     253                 :    */
     254                 :   bool ShowList(bool aShowList);
     255                 :   void CheckFireOnChange();
     256                 :   void FireValueChangeEvent();
     257                 :   nsresult RedisplayText(PRInt32 aIndex);
     258                 :   void HandleRedisplayTextEvent();
     259                 :   void ActuallyDisplayText(bool aNotify);
     260                 : 
     261                 : private:
     262                 :   // If our total transform to the root frame of the root document is only a 2d
     263                 :   // translation then return that translation, otherwise returns (0,0).
     264                 :   nsPoint GetCSSTransformTranslation();
     265                 : 
     266                 : protected:
     267                 :   nsFrameList              mPopupFrames;             // additional named child list
     268                 :   nsCOMPtr<nsIContent>     mDisplayContent;          // Anonymous content used to display the current selection
     269                 :   nsCOMPtr<nsIContent>     mButtonContent;           // Anonymous content for the button
     270                 :   nsIFrame*                mDisplayFrame;            // frame to display selection
     271                 :   nsIFrame*                mButtonFrame;             // button frame
     272                 :   nsIFrame*                mDropdownFrame;           // dropdown list frame
     273                 :   nsIListControlFrame *    mListControlFrame;        // ListControl Interface for the dropdown frame
     274                 : 
     275                 :   // The width of our display area.  Used by that frame's reflow to
     276                 :   // size to the full width except the drop-marker.
     277                 :   nscoord mDisplayWidth;
     278                 :   
     279                 :   bool                  mDroppedDown;             // Current state of the dropdown list, true is dropped down
     280                 :   bool                  mInRedisplayText;
     281                 : 
     282                 :   nsRevocableEventPtr<RedisplayTextEvent> mRedisplayTextEvent;
     283                 : 
     284                 :   PRInt32               mRecentSelectedIndex;
     285                 :   PRInt32               mDisplayedIndex;
     286                 :   nsString              mDisplayedOptionText;
     287                 : 
     288                 :   // make someone to listen to the button. If its programmatically pressed by someone like Accessibility
     289                 :   // then open or close the combo box.
     290                 :   nsCOMPtr<nsIDOMEventListener> mButtonListener;
     291                 : 
     292                 :   // static class data member for Bug 32920
     293                 :   // only one control can be focused at a time
     294                 :   static nsComboboxControlFrame * mFocused;
     295                 : 
     296                 : #ifdef DO_REFLOW_COUNTER
     297                 :   PRInt32 mReflowId;
     298                 : #endif
     299                 : };
     300                 : 
     301                 : #endif

Generated by: LCOV version 1.7