LCOV - code coverage report
Current view: directory - widget/xpwidgets - nsBaseWidget.h (source / functions) Found Hit Coverage
Test: app.info Lines: 28 0 0.0 %
Date: 2012-06-02 Functions: 22 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 the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * 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                 : #ifndef nsBaseWidget_h__
      38                 : #define nsBaseWidget_h__
      39                 : 
      40                 : #include "nsRect.h"
      41                 : #include "nsIWidget.h"
      42                 : #include "nsWidgetsCID.h"
      43                 : #include "nsILocalFile.h"
      44                 : #include "nsString.h"
      45                 : #include "nsCOMPtr.h"
      46                 : #include "nsGUIEvent.h"
      47                 : #include "nsAutoPtr.h"
      48                 : #include "BasicLayers.h"
      49                 : 
      50                 : class nsIContent;
      51                 : class nsAutoRollup;
      52                 : class gfxContext;
      53                 : 
      54                 : namespace mozilla {
      55                 : namespace layers {
      56                 : class CompositorChild;
      57                 : class CompositorParent;
      58                 : }
      59                 : }
      60                 : 
      61                 : namespace base {
      62                 : class Thread;
      63                 : }
      64                 : 
      65                 : /**
      66                 :  * Common widget implementation used as base class for native
      67                 :  * or crossplatform implementations of Widgets. 
      68                 :  * All cross-platform behavior that all widgets need to implement 
      69                 :  * should be placed in this class. 
      70                 :  * (Note: widget implementations are not required to use this
      71                 :  * class, but it gives them a head start.)
      72                 :  */
      73                 : 
      74                 : class nsBaseWidget : public nsIWidget
      75                 : {
      76                 :   friend class nsAutoRollup;
      77                 : 
      78                 : protected:
      79                 :   typedef mozilla::layers::BasicLayerManager BasicLayerManager;
      80                 :   typedef mozilla::layers::CompositorChild CompositorChild;
      81                 :   typedef mozilla::layers::CompositorParent CompositorParent;
      82                 :   typedef base::Thread Thread;
      83                 : 
      84                 : public:
      85                 :   nsBaseWidget();
      86                 :   virtual ~nsBaseWidget();
      87                 :   
      88                 :   NS_DECL_ISUPPORTS
      89                 :   
      90                 :   // nsIWidget interface
      91                 :   NS_IMETHOD              CaptureMouse(bool aCapture);
      92                 :   NS_IMETHOD              GetClientData(void*& aClientData);
      93                 :   NS_IMETHOD              SetClientData(void* aClientData);
      94                 :   NS_IMETHOD              Destroy();
      95                 :   NS_IMETHOD              SetParent(nsIWidget* aNewParent);
      96                 :   virtual nsIWidget*      GetParent(void);
      97                 :   virtual nsIWidget*      GetTopLevelWidget();
      98                 :   virtual nsIWidget*      GetSheetWindowParent(void);
      99                 :   virtual float           GetDPI();
     100                 :   virtual double          GetDefaultScale();
     101                 :   virtual void            AddChild(nsIWidget* aChild);
     102                 :   virtual void            RemoveChild(nsIWidget* aChild);
     103                 : 
     104                 :   NS_IMETHOD              SetZIndex(PRInt32 aZIndex);
     105                 :   NS_IMETHOD              GetZIndex(PRInt32* aZIndex);
     106                 :   NS_IMETHOD              PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
     107                 :                                       nsIWidget *aWidget, bool aActivate);
     108                 : 
     109                 :   NS_IMETHOD              SetSizeMode(PRInt32 aMode);
     110                 :   NS_IMETHOD              GetSizeMode(PRInt32* aMode);
     111                 : 
     112                 :   virtual nscolor         GetForegroundColor(void);
     113                 :   NS_IMETHOD              SetForegroundColor(const nscolor &aColor);
     114                 :   virtual nscolor         GetBackgroundColor(void);
     115                 :   NS_IMETHOD              SetBackgroundColor(const nscolor &aColor);
     116                 :   virtual nsCursor        GetCursor();
     117                 :   NS_IMETHOD              SetCursor(nsCursor aCursor);
     118                 :   NS_IMETHOD              SetCursor(imgIContainer* aCursor,
     119                 :                                     PRUint32 aHotspotX, PRUint32 aHotspotY);
     120                 :   NS_IMETHOD              GetWindowType(nsWindowType& aWindowType);
     121                 :   virtual void            SetTransparencyMode(nsTransparencyMode aMode);
     122                 :   virtual nsTransparencyMode GetTransparencyMode();
     123                 :   virtual void            GetWindowClipRegion(nsTArray<nsIntRect>* aRects);
     124                 :   NS_IMETHOD              SetWindowShadowStyle(PRInt32 aStyle);
     125               0 :   virtual void            SetShowsToolbarButton(bool aShow) {}
     126               0 :   virtual void            SetWindowAnimationType(WindowAnimationType aType) {}
     127                 :   NS_IMETHOD              HideWindowChrome(bool aShouldHide);
     128                 :   NS_IMETHOD              MakeFullScreen(bool aFullScreen);
     129                 :   virtual nsDeviceContext* GetDeviceContext();
     130                 :   virtual LayerManager*   GetLayerManager(PLayersChild* aShadowManager = nsnull,
     131                 :                                           LayersBackend aBackendHint = LayerManager::LAYERS_NONE,
     132                 :                                           LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
     133                 :                                           bool* aAllowRetaining = nsnull);
     134                 : 
     135                 :   virtual void            CreateCompositor();
     136               0 :   virtual void            DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect) {}
     137               0 :   virtual void            UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) {}
     138                 :   virtual gfxASurface*    GetThebesSurface();
     139                 :   NS_IMETHOD              SetModal(bool aModal); 
     140                 :   NS_IMETHOD              SetWindowClass(const nsAString& xulWinType);
     141                 :   NS_IMETHOD              MoveClient(PRInt32 aX, PRInt32 aY);
     142                 :   NS_IMETHOD              ResizeClient(PRInt32 aWidth, PRInt32 aHeight, bool aRepaint);
     143                 :   NS_IMETHOD              ResizeClient(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, bool aRepaint);
     144                 :   NS_IMETHOD              SetBounds(const nsIntRect &aRect);
     145                 :   NS_IMETHOD              GetBounds(nsIntRect &aRect);
     146                 :   NS_IMETHOD              GetClientBounds(nsIntRect &aRect);
     147                 :   NS_IMETHOD              GetScreenBounds(nsIntRect &aRect);
     148                 :   NS_IMETHOD              GetNonClientMargins(nsIntMargin &margins);
     149                 :   NS_IMETHOD              SetNonClientMargins(nsIntMargin &margins);
     150                 :   virtual nsIntPoint      GetClientOffset();
     151                 :   NS_IMETHOD              EnableDragDrop(bool aEnable);
     152                 :   NS_IMETHOD              GetAttention(PRInt32 aCycleCount);
     153                 :   virtual bool            HasPendingInputEvent();
     154                 :   NS_IMETHOD              SetIcon(const nsAString &anIconSpec);
     155                 :   NS_IMETHOD              BeginSecureKeyboardInput();
     156                 :   NS_IMETHOD              EndSecureKeyboardInput();
     157                 :   NS_IMETHOD              SetWindowTitlebarColor(nscolor aColor, bool aActive);
     158               0 :   virtual void            SetDrawsInTitlebar(bool aState) {}
     159                 :   virtual bool            ShowsResizeIndicator(nsIntRect* aResizerRect);
     160               0 :   virtual void            FreeNativeData(void * data, PRUint32 aDataType) {}
     161                 :   NS_IMETHOD              BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical);
     162                 :   NS_IMETHOD              BeginMoveDrag(nsMouseEvent* aEvent);
     163               0 :   virtual nsresult        ActivateNativeMenuItemAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; }
     164               0 :   virtual nsresult        ForceUpdateNativeMenuAt(const nsAString& indexString) { return NS_ERROR_NOT_IMPLEMENTED; }
     165               0 :   NS_IMETHOD              ResetInputState() { return NS_OK; }
     166               0 :   NS_IMETHOD              CancelIMEComposition() { return NS_OK; }
     167                 :   NS_IMETHOD              SetAcceleratedRendering(bool aEnabled);
     168                 :   virtual bool            GetAcceleratedRendering();
     169                 :   virtual bool            GetShouldAccelerate();
     170               0 :   NS_IMETHOD              GetToggledKeyState(PRUint32 aKeyCode, bool* aLEDState) { return NS_ERROR_NOT_IMPLEMENTED; }
     171               0 :   NS_IMETHOD              OnIMEFocusChange(bool aFocus) { return NS_ERROR_NOT_IMPLEMENTED; }
     172               0 :   NS_IMETHOD              OnIMETextChange(PRUint32 aStart, PRUint32 aOldEnd, PRUint32 aNewEnd) { return NS_ERROR_NOT_IMPLEMENTED; }
     173               0 :   NS_IMETHOD              OnIMESelectionChange(void) { return NS_ERROR_NOT_IMPLEMENTED; }
     174               0 :   virtual nsIMEUpdatePreference GetIMEUpdatePreference() { return nsIMEUpdatePreference(false, false); }
     175               0 :   NS_IMETHOD              OnDefaultButtonLoaded(const nsIntRect &aButtonRect) { return NS_ERROR_NOT_IMPLEMENTED; }
     176                 :   NS_IMETHOD              OverrideSystemMouseScrollSpeed(PRInt32 aOriginalDelta, bool aIsHorizontal, PRInt32 &aOverriddenDelta);
     177                 :   virtual already_AddRefed<nsIWidget>
     178                 :   CreateChild(const nsIntRect  &aRect,
     179                 :               EVENT_CALLBACK   aHandleEventFunction,
     180                 :               nsDeviceContext *aContext,
     181                 :               nsWidgetInitData *aInitData = nsnull,
     182                 :               bool             aForceUseIWidgetParent = false);
     183                 :   NS_IMETHOD              SetEventCallback(EVENT_CALLBACK aEventFunction, nsDeviceContext *aContext);
     184                 :   NS_IMETHOD              AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction, nsDeviceContext *aContext);
     185                 :   virtual ViewWrapper*    GetAttachedViewPtr();
     186                 :   NS_IMETHOD              SetAttachedViewPtr(ViewWrapper* aViewWrapper);
     187                 :   NS_IMETHOD              RegisterTouchWindow();
     188                 :   NS_IMETHOD              UnregisterTouchWindow();
     189                 : 
     190                 :   nsPopupLevel PopupLevel() { return mPopupLevel; }
     191                 : 
     192               0 :   virtual nsIntSize       ClientToWindowSize(const nsIntSize& aClientSize)
     193                 :   {
     194               0 :     return aClientSize;
     195                 :   }
     196                 : 
     197                 :   // return true if this is a popup widget with a native titlebar
     198                 :   bool IsPopupWithTitleBar() const
     199                 :   {
     200                 :     return (mWindowType == eWindowType_popup && 
     201                 :             mBorderStyle != eBorderStyle_default &&
     202                 :             mBorderStyle & eBorderStyle_title);
     203                 :   }
     204                 : 
     205                 :   NS_IMETHOD              ReparentNativeWidget(nsIWidget* aNewParent) = 0;
     206                 : 
     207                 :   virtual PRUint32 GetGLFrameBufferFormat() MOZ_OVERRIDE;
     208                 : 
     209                 :   /**
     210                 :    * Use this when GetLayerManager() returns a BasicLayerManager
     211                 :    * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
     212                 :    * layer manager to temporarily render into aTarget.
     213                 :    */
     214                 :   class AutoLayerManagerSetup {
     215                 :   public:
     216                 :     AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
     217                 :                           BasicLayerManager::BufferMode aDoubleBuffering);
     218                 :     ~AutoLayerManagerSetup();
     219                 :   private:
     220                 :     nsBaseWidget* mWidget;
     221                 :   };
     222                 :   friend class AutoLayerManagerSetup;
     223                 : 
     224                 :   class AutoUseBasicLayerManager {
     225                 :   public:
     226                 :     AutoUseBasicLayerManager(nsBaseWidget* aWidget);
     227                 :     ~AutoUseBasicLayerManager();
     228                 :   private:
     229                 :     nsBaseWidget* mWidget;
     230                 :   };
     231                 :   friend class AutoUseBasicLayerManager;
     232                 : 
     233                 :   bool HasDestroyStarted() const 
     234                 :   {
     235                 :     return mOnDestroyCalled;
     236                 :   }
     237                 : 
     238               0 :   bool                    Destroyed() { return mOnDestroyCalled; }
     239                 : 
     240                 :   nsWindowType            GetWindowType() { return mWindowType; }
     241                 : 
     242                 : protected:
     243                 : 
     244                 :   virtual void            ResolveIconName(const nsAString &aIconName,
     245                 :                                           const nsAString &aIconSuffix,
     246                 :                                           nsILocalFile **aResult);
     247                 :   virtual void            OnDestroy();
     248                 :   virtual void            BaseCreate(nsIWidget *aParent,
     249                 :                                      const nsIntRect &aRect,
     250                 :                                      EVENT_CALLBACK aHandleEventFunction,
     251                 :                                      nsDeviceContext *aContext,
     252                 :                                      nsWidgetInitData *aInitData);
     253                 : 
     254               0 :   virtual nsIContent* GetLastRollup()
     255                 :   {
     256               0 :     return mLastRollup;
     257                 :   }
     258                 : 
     259               0 :   virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
     260                 :                                             PRInt32 aNativeKeyCode,
     261                 :                                             PRUint32 aModifierFlags,
     262                 :                                             const nsAString& aCharacters,
     263                 :                                             const nsAString& aUnmodifiedCharacters)
     264               0 :   { return NS_ERROR_UNEXPECTED; }
     265                 : 
     266               0 :   virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
     267                 :                                               PRUint32 aNativeMessage,
     268                 :                                               PRUint32 aModifierFlags)
     269               0 :   { return NS_ERROR_UNEXPECTED; }
     270                 : 
     271                 :   // Stores the clip rectangles in aRects into mClipRects. Returns true
     272                 :   // if the new rectangles are different from the old rectangles.
     273                 :   bool StoreWindowClipRegion(const nsTArray<nsIntRect>& aRects);
     274                 : 
     275                 :   virtual already_AddRefed<nsIWidget>
     276               0 :   AllocateChildPopupWidget()
     277                 :   {
     278                 :     static NS_DEFINE_IID(kCPopUpCID, NS_CHILD_CID);
     279               0 :     nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID);
     280               0 :     return widget.forget();
     281                 :   }
     282                 : 
     283                 :   BasicLayerManager* CreateBasicLayerManager();
     284                 : 
     285                 : protected:
     286                 :   void*             mClientData;
     287                 :   ViewWrapper*      mViewWrapperPtr;
     288                 :   EVENT_CALLBACK    mEventCallback;
     289                 :   EVENT_CALLBACK    mViewCallback;
     290                 :   nsDeviceContext* mContext;
     291                 :   nsRefPtr<LayerManager> mLayerManager;
     292                 :   nsRefPtr<LayerManager> mBasicLayerManager;
     293                 :   nsRefPtr<CompositorChild> mCompositorChild;
     294                 :   nsRefPtr<CompositorParent> mCompositorParent;
     295                 :   Thread*           mCompositorThread;
     296                 :   nscolor           mBackground;
     297                 :   nscolor           mForeground;
     298                 :   nsCursor          mCursor;
     299                 :   nsWindowType      mWindowType;
     300                 :   nsBorderStyle     mBorderStyle;
     301                 :   bool              mOnDestroyCalled;
     302                 :   bool              mUseAcceleratedRendering;
     303                 :   bool              mForceLayersAcceleration;
     304                 :   bool              mTemporarilyUseBasicLayerManager;
     305                 :   nsIntRect         mBounds;
     306                 :   nsIntRect*        mOriginalBounds;
     307                 :   // When this pointer is null, the widget is not clipped
     308                 :   nsAutoArrayPtr<nsIntRect> mClipRects;
     309                 :   PRUint32          mClipRectCount;
     310                 :   PRInt32           mZIndex;
     311                 :   nsSizeMode        mSizeMode;
     312                 :   nsPopupLevel      mPopupLevel;
     313                 : 
     314                 :   // the last rolled up popup. Only set this when an nsAutoRollup is in scope,
     315                 :   // so it can be cleared automatically.
     316                 :   static nsIContent* mLastRollup;
     317                 : 
     318                 : #ifdef DEBUG
     319                 : protected:
     320                 :   static nsAutoString debug_GuiEventToString(nsGUIEvent * aGuiEvent);
     321                 :   static bool debug_WantPaintFlashing();
     322                 : 
     323                 :   static void debug_DumpInvalidate(FILE *                aFileOut,
     324                 :                                    nsIWidget *           aWidget,
     325                 :                                    const nsIntRect *     aRect,
     326                 :                                    const nsCAutoString & aWidgetName,
     327                 :                                    PRInt32               aWindowID);
     328                 : 
     329                 :   static void debug_DumpEvent(FILE *                aFileOut,
     330                 :                               nsIWidget *           aWidget,
     331                 :                               nsGUIEvent *          aGuiEvent,
     332                 :                               const nsCAutoString & aWidgetName,
     333                 :                               PRInt32               aWindowID);
     334                 : 
     335                 :   static void debug_DumpPaintEvent(FILE *                aFileOut,
     336                 :                                    nsIWidget *           aWidget,
     337                 :                                    nsPaintEvent *        aPaintEvent,
     338                 :                                    const nsCAutoString & aWidgetName,
     339                 :                                    PRInt32               aWindowID);
     340                 : 
     341                 :   static bool debug_GetCachedBoolPref(const char* aPrefName);
     342                 : #endif
     343                 : };
     344                 : 
     345                 : // A situation can occur when a mouse event occurs over a menu label while the
     346                 : // menu popup is already open. The expected behaviour is to close the popup.
     347                 : // This happens by calling nsIRollupListener::Rollup before the mouse event is
     348                 : // processed. However, in cases where the mouse event is not consumed, this
     349                 : // event will then get targeted at the menu label causing the menu to open
     350                 : // again. To prevent this, we store in mLastRollup a reference to the popup
     351                 : // that was closed during the Rollup call, and prevent this popup from
     352                 : // reopening while processing the mouse event.
     353                 : // mLastRollup should only be set while an nsAutoRollup is in scope;
     354                 : // when it goes out of scope mLastRollup is cleared automatically.
     355                 : // As mLastRollup is static, it can be retrieved by calling
     356                 : // nsIWidget::GetLastRollup on any widget.
     357                 : class nsAutoRollup
     358                 : {
     359                 :   bool wasClear;
     360                 : 
     361                 :   public:
     362                 : 
     363                 :   nsAutoRollup();
     364                 :   ~nsAutoRollup();
     365                 : };
     366                 : 
     367                 : #endif // nsBaseWidget_h__

Generated by: LCOV version 1.7