2010-08-20 23:24:40 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-08-20 23:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This "puppet widget" isn't really a platform widget. It's intended
|
|
|
|
* to be used in widgetless rendering contexts, such as sandboxed
|
|
|
|
* content processes. If any "real" widgetry is needed, the request
|
|
|
|
* is forwarded to and/or data received from elsewhere.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef mozilla_widget_PuppetWidget_h__
|
|
|
|
#define mozilla_widget_PuppetWidget_h__
|
|
|
|
|
2012-05-08 21:36:07 +00:00
|
|
|
#include "nsBaseScreen.h"
|
2010-08-20 23:24:40 +00:00
|
|
|
#include "nsBaseWidget.h"
|
2012-05-08 21:36:07 +00:00
|
|
|
#include "nsIScreenManager.h"
|
2010-08-20 23:24:40 +00:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsWeakReference.h"
|
2012-06-19 01:28:00 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-08-20 23:24:40 +00:00
|
|
|
|
|
|
|
class gfxASurface;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2012-07-17 23:59:45 +00:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class TabChild;
|
|
|
|
}
|
|
|
|
|
2010-08-20 23:24:40 +00:00
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
class PuppetWidget : public nsBaseWidget, public nsSupportsWeakReference
|
|
|
|
{
|
2012-07-17 23:59:45 +00:00
|
|
|
typedef mozilla::dom::TabChild TabChild;
|
2010-08-20 23:24:40 +00:00
|
|
|
typedef nsBaseWidget Base;
|
|
|
|
|
2010-08-20 23:24:40 +00:00
|
|
|
// The width and height of the "widget" are clamped to this.
|
|
|
|
static const size_t kMaxDimension;
|
|
|
|
|
|
|
|
public:
|
2012-07-17 23:59:45 +00:00
|
|
|
PuppetWidget(TabChild* aTabChild);
|
2010-08-20 23:24:40 +00:00
|
|
|
virtual ~PuppetWidget();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
NS_IMETHOD Create(nsIWidget* aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect& aRect,
|
2011-10-25 15:05:32 +00:00
|
|
|
nsDeviceContext* aContext,
|
2012-07-30 14:20:58 +00:00
|
|
|
nsWidgetInitData* aInitData = nullptr);
|
2010-08-20 23:24:40 +00:00
|
|
|
|
2012-08-29 15:26:18 +00:00
|
|
|
void InitIMEState();
|
|
|
|
|
2010-08-20 23:24:40 +00:00
|
|
|
virtual already_AddRefed<nsIWidget>
|
|
|
|
CreateChild(const nsIntRect &aRect,
|
2011-10-25 15:05:32 +00:00
|
|
|
nsDeviceContext *aContext,
|
2012-07-30 14:20:58 +00:00
|
|
|
nsWidgetInitData *aInitData = nullptr,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aForceUseIWidgetParent = false);
|
2010-08-20 23:24:40 +00:00
|
|
|
|
2010-08-20 23:24:40 +00:00
|
|
|
NS_IMETHOD Destroy();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD Show(bool aState);
|
2012-07-19 08:57:50 +00:00
|
|
|
|
|
|
|
virtual bool IsVisible() const
|
|
|
|
{ return mVisible; }
|
2010-08-20 23:24:40 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD ConstrainPosition(bool /*ignored aAllowSlop*/,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t* aX,
|
|
|
|
int32_t* aY)
|
2010-08-20 23:24:40 +00:00
|
|
|
{ *aX = kMaxDimension; *aY = kMaxDimension; return NS_OK; }
|
|
|
|
|
|
|
|
// We're always at <0, 0>, and so ignore move requests.
|
2012-12-12 09:57:38 +00:00
|
|
|
NS_IMETHOD Move(double aX, double aY)
|
2010-08-20 23:24:40 +00:00
|
|
|
{ return NS_OK; }
|
|
|
|
|
2012-12-12 09:57:38 +00:00
|
|
|
NS_IMETHOD Resize(double aWidth,
|
|
|
|
double aHeight,
|
|
|
|
bool aRepaint);
|
|
|
|
NS_IMETHOD Resize(double aX,
|
|
|
|
double aY,
|
|
|
|
double aWidth,
|
|
|
|
double aHeight,
|
|
|
|
bool aRepaint)
|
2010-08-20 23:24:40 +00:00
|
|
|
// (we're always at <0, 0>)
|
|
|
|
{ return Resize(aWidth, aHeight, aRepaint); }
|
|
|
|
|
|
|
|
// XXX/cjones: copying gtk behavior here; unclear what disabling a
|
|
|
|
// widget is supposed to entail
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD Enable(bool aState)
|
2010-08-20 23:24:40 +00:00
|
|
|
{ mEnabled = aState; return NS_OK; }
|
2012-07-23 05:19:08 +00:00
|
|
|
virtual bool IsEnabled() const
|
|
|
|
{ return mEnabled; }
|
2010-08-20 23:24:40 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHOD SetFocus(bool aRaise = false);
|
2010-08-20 23:24:40 +00:00
|
|
|
|
|
|
|
// PuppetWidgets don't care about children.
|
|
|
|
virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
|
|
|
|
{ return NS_OK; }
|
|
|
|
|
2011-12-24 03:52:21 +00:00
|
|
|
NS_IMETHOD Invalidate(const nsIntRect& aRect);
|
2010-08-20 23:24:40 +00:00
|
|
|
|
|
|
|
// This API is going away, steer clear.
|
|
|
|
virtual void Scroll(const nsIntPoint& aDelta,
|
|
|
|
const nsTArray<nsIntRect>& aDestRects,
|
|
|
|
const nsTArray<Configuration>& aReconfigureChildren)
|
|
|
|
{ /* dead man walking */ }
|
|
|
|
|
|
|
|
// PuppetWidgets don't have native data, as they're purely nonnative.
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual void* GetNativeData(uint32_t aDataType);
|
2010-09-18 11:28:50 +00:00
|
|
|
NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent)
|
|
|
|
{ return NS_ERROR_UNEXPECTED; }
|
2010-08-20 23:24:40 +00:00
|
|
|
|
|
|
|
// PuppetWidgets don't have any concept of titles.
|
|
|
|
NS_IMETHOD SetTitle(const nsAString& aTitle)
|
|
|
|
{ return NS_ERROR_UNEXPECTED; }
|
|
|
|
|
|
|
|
// PuppetWidgets are always at <0, 0>.
|
|
|
|
virtual nsIntPoint WidgetToScreenOffset()
|
|
|
|
{ return nsIntPoint(0, 0); }
|
|
|
|
|
2013-10-02 03:46:03 +00:00
|
|
|
void InitEvent(WidgetGUIEvent& aEvent, nsIntPoint* aPoint = nullptr);
|
2010-09-24 03:28:15 +00:00
|
|
|
|
2013-10-02 03:46:03 +00:00
|
|
|
NS_IMETHOD DispatchEvent(WidgetGUIEvent* aEvent, nsEventStatus& aStatus);
|
2010-08-20 23:24:40 +00:00
|
|
|
|
2011-11-08 19:59:07 +00:00
|
|
|
NS_IMETHOD CaptureRollupEvents(nsIRollupListener* aListener,
|
2012-10-26 13:15:22 +00:00
|
|
|
bool aDoCapture)
|
2010-08-20 23:24:40 +00:00
|
|
|
{ return NS_ERROR_UNEXPECTED; }
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsBaseWidget methods we override
|
|
|
|
//
|
|
|
|
|
2013-11-25 20:12:20 +00:00
|
|
|
// Documents loaded in child processes are always subdocuments of
|
|
|
|
// other docs in an ancestor process. To ensure that the
|
|
|
|
// backgrounds of those documents are painted like those of
|
|
|
|
// same-process subdocuments, we force the widget here to be
|
|
|
|
// transparent, which in turn will cause layout to use a transparent
|
|
|
|
// backstop background color.
|
2012-09-05 16:23:45 +00:00
|
|
|
virtual nsTransparencyMode GetTransparencyMode() MOZ_OVERRIDE
|
2013-11-25 20:12:20 +00:00
|
|
|
{ return eTransparencyTransparent; }
|
2012-09-05 16:23:45 +00:00
|
|
|
|
2011-08-09 19:38:26 +00:00
|
|
|
virtual LayerManager*
|
2013-04-24 18:42:40 +00:00
|
|
|
GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
|
2012-07-18 16:31:40 +00:00
|
|
|
LayersBackend aBackendHint = mozilla::layers::LAYERS_NONE,
|
2011-08-09 19:38:26 +00:00
|
|
|
LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
|
2012-07-30 14:20:58 +00:00
|
|
|
bool* aAllowRetaining = nullptr);
|
2010-08-20 23:24:40 +00:00
|
|
|
virtual gfxASurface* GetThebesSurface();
|
|
|
|
|
2013-03-06 06:14:31 +00:00
|
|
|
NS_IMETHOD NotifyIME(NotificationToIME aNotification) MOZ_OVERRIDE;
|
2011-11-27 11:51:52 +00:00
|
|
|
NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction);
|
|
|
|
NS_IMETHOD_(InputContext) GetInputContext();
|
2013-03-06 06:14:34 +00:00
|
|
|
NS_IMETHOD NotifyIMEOfTextChange(uint32_t aOffset, uint32_t aEnd,
|
|
|
|
uint32_t aNewEnd) MOZ_OVERRIDE;
|
2012-11-13 13:04:44 +00:00
|
|
|
virtual nsIMEUpdatePreference GetIMEUpdatePreference();
|
2010-09-24 03:28:15 +00:00
|
|
|
|
2011-06-22 00:32:43 +00:00
|
|
|
NS_IMETHOD SetCursor(nsCursor aCursor);
|
2012-05-08 21:36:07 +00:00
|
|
|
NS_IMETHOD SetCursor(imgIContainer* aCursor,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aHotspotX, uint32_t aHotspotY)
|
2012-05-08 21:36:07 +00:00
|
|
|
{
|
|
|
|
return nsBaseWidget::SetCursor(aCursor, aHotspotX, aHotspotY);
|
|
|
|
}
|
2011-06-22 00:32:43 +00:00
|
|
|
|
2010-12-03 01:24:04 +00:00
|
|
|
// Gets the DPI of the screen corresponding to this widget.
|
|
|
|
// Contacts the parent process which gets the DPI from the
|
|
|
|
// proper widget there. TODO: Handle DPI changes that happen
|
|
|
|
// later on.
|
|
|
|
virtual float GetDPI();
|
2013-05-01 23:06:19 +00:00
|
|
|
virtual double GetDefaultScaleInternal();
|
2010-12-03 01:24:04 +00:00
|
|
|
|
2012-11-08 03:51:55 +00:00
|
|
|
virtual bool NeedsPaint() MOZ_OVERRIDE;
|
|
|
|
|
2012-09-25 04:15:18 +00:00
|
|
|
virtual TabChild* GetOwningTabChild() MOZ_OVERRIDE { return mTabChild; }
|
|
|
|
|
2010-08-20 23:24:40 +00:00
|
|
|
private:
|
2012-08-15 18:52:42 +00:00
|
|
|
nsresult Paint();
|
2010-08-20 23:24:40 +00:00
|
|
|
|
|
|
|
void SetChild(PuppetWidget* aChild);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult IMEEndComposition(bool aCancel);
|
2013-03-06 06:14:31 +00:00
|
|
|
nsresult NotifyIMEOfFocusChange(bool aFocus);
|
|
|
|
nsresult NotifyIMEOfSelectionChange();
|
2010-09-24 03:28:15 +00:00
|
|
|
|
2010-08-20 23:24:40 +00:00
|
|
|
class PaintTask : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
PaintTask(PuppetWidget* widget) : mWidget(widget) {}
|
2012-07-30 14:20:58 +00:00
|
|
|
void Revoke() { mWidget = nullptr; }
|
2010-08-20 23:24:40 +00:00
|
|
|
private:
|
|
|
|
PuppetWidget* mWidget;
|
|
|
|
};
|
|
|
|
|
2010-09-24 03:28:15 +00:00
|
|
|
// TabChild normally holds a strong reference to this PuppetWidget
|
2012-07-17 23:59:45 +00:00
|
|
|
// or its root ancestor, but each PuppetWidget also needs a
|
|
|
|
// reference back to TabChild (e.g. to delegate nsIWidget IME calls
|
|
|
|
// to chrome) So we hold a weak reference to TabChild here. Since
|
|
|
|
// it's possible for TabChild to outlive the PuppetWidget, we clear
|
|
|
|
// this weak reference in Destroy()
|
|
|
|
TabChild* mTabChild;
|
2010-08-20 23:24:40 +00:00
|
|
|
// The "widget" to which we delegate events if we don't have an
|
|
|
|
// event handler.
|
|
|
|
nsRefPtr<PuppetWidget> mChild;
|
|
|
|
nsIntRegion mDirtyRegion;
|
|
|
|
nsRevocableEventPtr<PaintTask> mPaintTask;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mEnabled;
|
|
|
|
bool mVisible;
|
2010-08-20 23:24:40 +00:00
|
|
|
// XXX/cjones: keeping this around until we teach LayerManager to do
|
|
|
|
// retained-content-only transactions
|
|
|
|
nsRefPtr<gfxASurface> mSurface;
|
2010-09-24 03:28:15 +00:00
|
|
|
// IME
|
|
|
|
nsIMEUpdatePreference mIMEPreference;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mIMEComposing;
|
2010-10-01 14:17:37 +00:00
|
|
|
// Latest seqno received through events
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mIMELastReceivedSeqno;
|
2010-10-01 14:17:37 +00:00
|
|
|
// Chrome's seqno value when last blur occurred
|
|
|
|
// arriving events with seqno up to this should be discarded
|
|
|
|
// Note that if seqno overflows (~50 days at 1 ms increment rate),
|
|
|
|
// events will be discarded until new focus/blur occurs
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mIMELastBlurSeqno;
|
2012-08-29 15:26:18 +00:00
|
|
|
bool mNeedIMEStateInit;
|
2010-12-03 01:24:04 +00:00
|
|
|
|
|
|
|
// The DPI of the screen corresponding to this widget
|
|
|
|
float mDPI;
|
2013-05-01 23:06:19 +00:00
|
|
|
double mDefaultScale;
|
2010-08-20 23:24:40 +00:00
|
|
|
};
|
|
|
|
|
2012-05-08 21:36:07 +00:00
|
|
|
class PuppetScreen : public nsBaseScreen
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PuppetScreen(void* nativeScreen);
|
|
|
|
~PuppetScreen();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHOD GetRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD GetAvailRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD GetColorDepth(int32_t* aColorDepth) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD GetRotation(uint32_t* aRotation) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD SetRotation(uint32_t aRotation) MOZ_OVERRIDE;
|
2012-05-08 21:36:07 +00:00
|
|
|
};
|
|
|
|
|
2012-06-19 01:28:00 +00:00
|
|
|
class PuppetScreenManager MOZ_FINAL : public nsIScreenManager
|
2012-05-08 21:36:07 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PuppetScreenManager();
|
|
|
|
~PuppetScreenManager();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISCREENMANAGER
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIScreen> mOneScreen;
|
|
|
|
};
|
|
|
|
|
2010-08-20 23:24:40 +00:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_widget_PuppetWidget_h__
|