LCOV - code coverage report
Current view: directory - widget/xpwidgets - PuppetWidget.h (source / functions) Found Hit Coverage
Test: app.info Lines: 27 0 0.0 %
Date: 2012-06-02 Functions: 16 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  * vim: sw=2 ts=8 et :
       3                 :  */
       4                 : /* ***** BEGIN LICENSE BLOCK *****
       5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       6                 :  *
       7                 :  * The contents of this file are subject to the Mozilla Public License Version
       8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       9                 :  * the License. You may obtain a copy of the License at:
      10                 :  * http://www.mozilla.org/MPL/
      11                 :  *
      12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      14                 :  * for the specific language governing rights and limitations under the
      15                 :  * License.
      16                 :  *
      17                 :  * The Original Code is Mozilla Code.
      18                 :  *
      19                 :  * The Initial Developer of the Original Code is
      20                 :  *   The Mozilla Foundation
      21                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      22                 :  * the Initial Developer. All Rights Reserved.
      23                 :  *
      24                 :  * Contributor(s):
      25                 :  *   Chris Jones <jones.chris.g@gmail.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      29                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : /**
      42                 :  * This "puppet widget" isn't really a platform widget.  It's intended
      43                 :  * to be used in widgetless rendering contexts, such as sandboxed
      44                 :  * content processes.  If any "real" widgetry is needed, the request
      45                 :  * is forwarded to and/or data received from elsewhere.
      46                 :  */
      47                 : 
      48                 : #ifndef mozilla_widget_PuppetWidget_h__
      49                 : #define mozilla_widget_PuppetWidget_h__
      50                 : 
      51                 : #include "nsBaseWidget.h"
      52                 : #include "nsThreadUtils.h"
      53                 : #include "nsWeakReference.h"
      54                 : 
      55                 : class gfxASurface;
      56                 : 
      57                 : namespace mozilla {
      58                 : namespace widget {
      59                 : 
      60                 : class PuppetWidget : public nsBaseWidget, public nsSupportsWeakReference
      61                 : {
      62                 :   typedef nsBaseWidget Base;
      63                 : 
      64                 :   // The width and height of the "widget" are clamped to this.
      65                 :   static const size_t kMaxDimension;
      66                 : 
      67                 : public:
      68                 :   PuppetWidget(PBrowserChild *aTabChild);
      69                 :   virtual ~PuppetWidget();
      70                 : 
      71                 :   NS_DECL_ISUPPORTS_INHERITED
      72                 : 
      73                 :   NS_IMETHOD Create(nsIWidget*        aParent,
      74                 :                     nsNativeWidget    aNativeParent,
      75                 :                     const nsIntRect&  aRect,
      76                 :                     EVENT_CALLBACK    aHandleEventFunction,
      77                 :                     nsDeviceContext*  aContext,
      78                 :                     nsWidgetInitData* aInitData = nsnull);
      79                 : 
      80                 :   virtual already_AddRefed<nsIWidget>
      81                 :   CreateChild(const nsIntRect  &aRect,
      82                 :               EVENT_CALLBACK   aHandleEventFunction,
      83                 :               nsDeviceContext  *aContext,
      84                 :               nsWidgetInitData *aInitData = nsnull,
      85                 :               bool             aForceUseIWidgetParent = false);
      86                 : 
      87                 :   NS_IMETHOD Destroy();
      88                 : 
      89                 :   NS_IMETHOD Show(bool aState);
      90               0 :   NS_IMETHOD IsVisible(bool& aState)
      91               0 :   { aState = mVisible; return NS_OK; }
      92                 : 
      93               0 :   NS_IMETHOD ConstrainPosition(bool     /*ignored aAllowSlop*/,
      94                 :                                PRInt32* aX,
      95                 :                                PRInt32* aY)
      96               0 :   { *aX = kMaxDimension;  *aY = kMaxDimension;  return NS_OK; }
      97                 : 
      98                 :   // We're always at <0, 0>, and so ignore move requests.
      99               0 :   NS_IMETHOD Move(PRInt32 aX, PRInt32 aY)
     100               0 :   { return NS_OK; }
     101                 : 
     102                 :   NS_IMETHOD Resize(PRInt32 aWidth,
     103                 :                     PRInt32 aHeight,
     104                 :                     bool    aRepaint);
     105               0 :   NS_IMETHOD Resize(PRInt32 aX,
     106                 :                     PRInt32 aY,
     107                 :                     PRInt32 aWidth,
     108                 :                     PRInt32 aHeight,
     109                 :                     bool    aRepaint)
     110                 :   // (we're always at <0, 0>)
     111               0 :   { return Resize(aWidth, aHeight, aRepaint); }
     112                 : 
     113                 :   // XXX/cjones: copying gtk behavior here; unclear what disabling a
     114                 :   // widget is supposed to entail
     115               0 :   NS_IMETHOD Enable(bool aState)
     116               0 :   { mEnabled = aState;  return NS_OK; }
     117               0 :   NS_IMETHOD IsEnabled(bool *aState)
     118               0 :   { *aState = mEnabled;  return NS_OK; }
     119                 : 
     120                 :   NS_IMETHOD SetFocus(bool aRaise = false);
     121                 : 
     122                 :   // PuppetWidgets don't care about children.
     123               0 :   virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
     124               0 :   { return NS_OK; }
     125                 : 
     126                 :   NS_IMETHOD Invalidate(const nsIntRect& aRect);
     127                 : 
     128                 :   // This API is going away, steer clear.
     129               0 :   virtual void Scroll(const nsIntPoint& aDelta,
     130                 :                       const nsTArray<nsIntRect>& aDestRects,
     131                 :                       const nsTArray<Configuration>& aReconfigureChildren)
     132               0 :   { /* dead man walking */ }
     133                 : 
     134                 :   // PuppetWidgets don't have native data, as they're purely nonnative.
     135                 :   virtual void* GetNativeData(PRUint32 aDataType);
     136               0 :   NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent)
     137               0 :   { return NS_ERROR_UNEXPECTED; }
     138                 : 
     139                 :   // PuppetWidgets don't have any concept of titles. 
     140               0 :   NS_IMETHOD SetTitle(const nsAString& aTitle)
     141               0 :   { return NS_ERROR_UNEXPECTED; }
     142                 :   
     143                 :   // PuppetWidgets are always at <0, 0>.
     144               0 :   virtual nsIntPoint WidgetToScreenOffset()
     145               0 :   { return nsIntPoint(0, 0); }
     146                 : 
     147                 :   void InitEvent(nsGUIEvent& event, nsIntPoint* aPoint = nsnull);
     148                 : 
     149                 :   NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus);
     150                 : 
     151               0 :   NS_IMETHOD CaptureRollupEvents(nsIRollupListener* aListener,
     152                 :                                  bool aDoCapture, bool aConsumeRollupEvent)
     153               0 :   { return NS_ERROR_UNEXPECTED; }
     154                 : 
     155                 :   //
     156                 :   // nsBaseWidget methods we override
     157                 :   //
     158                 : 
     159                 : //NS_IMETHOD              CaptureMouse(bool aCapture);
     160                 :   virtual LayerManager*
     161                 :   GetLayerManager(PLayersChild* aShadowManager = nsnull,
     162                 :                   LayersBackend aBackendHint = LayerManager::LAYERS_NONE,
     163                 :                   LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
     164                 :                   bool* aAllowRetaining = nsnull);
     165                 : //  virtual nsDeviceContext* GetDeviceContext();
     166                 :   virtual gfxASurface*      GetThebesSurface();
     167                 : 
     168                 :   NS_IMETHOD ResetInputState();
     169                 :   NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
     170                 :                                     const InputContextAction& aAction);
     171                 :   NS_IMETHOD_(InputContext) GetInputContext();
     172                 :   NS_IMETHOD CancelComposition();
     173                 :   NS_IMETHOD OnIMEFocusChange(bool aFocus);
     174                 :   NS_IMETHOD OnIMETextChange(PRUint32 aOffset, PRUint32 aEnd,
     175                 :                              PRUint32 aNewEnd);
     176                 :   NS_IMETHOD OnIMESelectionChange(void);
     177                 : 
     178                 :   NS_IMETHOD SetCursor(nsCursor aCursor);
     179                 : 
     180                 :   // Gets the DPI of the screen corresponding to this widget.
     181                 :   // Contacts the parent process which gets the DPI from the
     182                 :   // proper widget there. TODO: Handle DPI changes that happen
     183                 :   // later on.
     184                 :   virtual float GetDPI();
     185                 : 
     186                 : private:
     187                 :   nsresult DispatchPaintEvent();
     188                 :   nsresult DispatchResizeEvent();
     189                 : 
     190                 :   void SetChild(PuppetWidget* aChild);
     191                 : 
     192                 :   nsresult IMEEndComposition(bool aCancel);
     193                 : 
     194               0 :   class PaintTask : public nsRunnable {
     195                 :   public:
     196                 :     NS_DECL_NSIRUNNABLE
     197               0 :     PaintTask(PuppetWidget* widget) : mWidget(widget) {}
     198               0 :     void Revoke() { mWidget = nsnull; }
     199                 :   private:
     200                 :     PuppetWidget* mWidget;
     201                 :   };
     202                 : 
     203                 :   // TabChild normally holds a strong reference to this PuppetWidget
     204                 :   // or its root ancestor, but each PuppetWidget also needs a reference
     205                 :   // back to TabChild (e.g. to delegate nsIWidget IME calls to chrome)
     206                 :   // So we hold a weak reference to TabChild (PBrowserChild) here.
     207                 :   // Since it's possible for TabChild to outlive the PuppetWidget,
     208                 :   // we clear this weak reference in Destroy()
     209                 :   PBrowserChild *mTabChild;
     210                 :   // The "widget" to which we delegate events if we don't have an
     211                 :   // event handler.
     212                 :   nsRefPtr<PuppetWidget> mChild;
     213                 :   nsIntRegion mDirtyRegion;
     214                 :   nsRevocableEventPtr<PaintTask> mPaintTask;
     215                 :   bool mEnabled;
     216                 :   bool mVisible;
     217                 :   // XXX/cjones: keeping this around until we teach LayerManager to do
     218                 :   // retained-content-only transactions
     219                 :   nsRefPtr<gfxASurface> mSurface;
     220                 :   // IME
     221                 :   nsIMEUpdatePreference mIMEPreference;
     222                 :   bool mIMEComposing;
     223                 :   // Latest seqno received through events
     224                 :   PRUint32 mIMELastReceivedSeqno;
     225                 :   // Chrome's seqno value when last blur occurred
     226                 :   // arriving events with seqno up to this should be discarded
     227                 :   // Note that if seqno overflows (~50 days at 1 ms increment rate),
     228                 :   // events will be discarded until new focus/blur occurs
     229                 :   PRUint32 mIMELastBlurSeqno;
     230                 : 
     231                 :   // The DPI of the screen corresponding to this widget
     232                 :   float mDPI;
     233                 : };
     234                 : 
     235                 : }  // namespace widget
     236                 : }  // namespace mozilla
     237                 : 
     238                 : #endif  // mozilla_widget_PuppetWidget_h__

Generated by: LCOV version 1.7