Files
palemoon27/widget/PuppetWidget.h
T
roytam1 e9ba40cf6b import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1178833 - Fix for unified builds when a new file is added to layout/base. r=mstange (bf961c00fd)
- Bug 1178847 - Add a MobileViewportManager to manage setting the CSS viewport on B2G. r=botond,tn (937ba486fa)
- Bug 1178847 - Don't use the MobileViewportManager code on Mulet or Fennec yet. r=botond (3061b2c617)
- Bug 1168950. Add the document to DoProcessRestyles profile label. r=dbaron (2347b76411)
- Bug 1187792 - Don't set the SPCSPS unless meta-viewport or zooming is enabled. r=botond (a8f5ed1006)
- Bug 1193062 - Don't double-send target APZC confirmations that might race each other. r=kats (de48467401)
- Bug 1186004 - Add a pref to enable/disable APZ zooming behaviour. r=botond (fc3653c979)
- Bug 1193062 - Add a PAN_MOMENTUM state. r=kats (10c8bb1a5e)
- Bug 1148350 - Have ConvertToGecko use a live screen-to-apzc transform to avoid transform mismatches. r=botond (9eee9ea6f2)
- Bug 1169844 - Remove incorrect assertion and properly untransform wheel events for overscroll situations. r=botond (9b101b53bb)
- Bug 1169690 - Accelerate flings correctly in the presence of overscroll handoff. r=kats (49d55c05f4)
- Bug 1158424 - Extract a BreadthFirstSearch() helper function. r=kats (6a49498185)
- Bug 1158424 - Add APZCTreeManager::FindRootContentApzcForLayersId(). r=kats (d6c7ecf781)
- Bug 1158424 - Fix APZCTreeManager::GetMultitouchTarget(). r=kats (bf8571a4ca)
- Bug 1174205 - Make sure to acquire the tree lock before finding the multitouch target. r=botond (bdbd98f2c7)
- Bug 1211660 - Remove dead obj argument from two functions. r=Waldo. (efba5a2f8d)
- Bug 1158424 - Undeprecate HasNoParentWithSameLayersId(). r=kats (d994ea28f8)
- Fix AsyncCompositionManager not comparing layer tree IDs when finding scrollbar targets. (bug 1151169, r=kats) (c7dbc4776a)
- Bug 1163259. Make sure we don't look at the parent ref layer when looking for a layer with the frame metrics for a scrollbar. r=kats (8b99d2c830)
- Bug 1164340. Convert the scrollbar thumb ratio to a unitless ratio properly for non-zoomable scrollframes. r=botond (27f56cab56)
- Bug 1164340. Fix up some scrollbar related comments in AsyncCompositionManager. r=botond (b9d540bea9)
- Bug 1164767. Modify async scrollbar positioning code to deal with containerless root scrollables. r=botond (501d07592e)
- Bug 1158424 - Remove FrameMetrics::IsRootScrollable() (it just duplicated IsRootContent()). r=kats (672fd034b3)
- Bug 1120683 - Properly handle unapplying 3D projective transforms throughout APZ code. r=botond (a46612811a)
- Bug 1148868 - Make APZ wheel handling handle pixel scrolling on OS X. r=dvander, r=kats (da3bd34135)
- Bug 1193062 - Add fields to PanGestureInput and ScrollWheelInput. r=kats (716ba34e18)
- Bug 1189565 - Send resize events when backing scale factor changes. r=mstange (4e81a7bbf7)
- Bug 1193062 - Add nsCocoaUtils::ModifiersForEvent. r=smichaud (da67b22ff7)
- Bug 1016035 - Remove the ability to swipe vertically. r=kats (fa315e0b97)
- Bug 1016035 - Refactor the code that decides whether we want to start a swipe. r=kats (3091961328)
- Bug 1016035 - Make the threshold in AxisPhysicsMSDModel::IsFinished controllable by the caller. r=kip (76df4d85a2)
- Bug 1016035 - More swipe refactoring. r=kats (2abcd05b33)
- Bug 1016035 - Implement the swipe animation ourselves instead of calling the NSEvent trackSwipe API. r=kats (4842b2a728)
- Bug 1016035 - Move swipe tracking code into DispatchAPZWheelInputEvent. r=kats (bb1052b87c)
- Bug 1016035 - Also mark widgetWheelEvents that are handled by APZ with mCanStartSwipe. r=kats (21809b902d)
- Bug 1016035 - Put PanGestureInput events into a queue if they can end up as a swipe. r=kats (2ebac59047)
- Bug 1016035 - Split up MaybeTrackScrollEventAsSwipe into SendMayStartSwipe and TrackScrollEventAsSwipe. r=kats (ced10d9671)
- Bug 1016035 - Send MayStartSwipe event before sending the wheel event. r=kats (b3346b81fb)
- Fix some fields missing in the widget event IPC glue. (bug 1139711, r=kats) (1298b25705)
- Bug 1016035 - Add mCanTriggerSwipe and TriggersSwipe(). r=masayuki (664a059972)
- Bug 1016035 - Make APZEventState report defaultPrevented=true when the event started a swipe. r=kats (128d627ac7)
- Bug 1016035 - Set scroll overflow information on potential swipe start events that have been processed by APZ. r=masayuki (b5931f6320)
- Bug 1206801 - fix broken CONFIG['DEBUG'] checks in moz.build files; r=mshal (292d5ac709)
- Bug 1186424: Refactor AsmJSValidate.cpp in preparation for parallelization; r=luke (4868bc66ca)
- Bug 1129267 - Fix by backing out patch for bug 1118615. r=mstange (ea8aaba04e)
- Bug 1182411 Part 1: Make plugin quirks available to the Parent as well as the Child. r=jimm (1f2551a6b7)
- Bug 1228462 - "PluginQuirks.* uses DOS CRLF". r=jmathies (b569a6c6c8)
- Bug 1152300 - When focus shifts from a native plugin window to content, content needs to forward the request for focus change to chrome. r=enn (5bd811fadd)
- Bug 1185529: On Windows, ensure that NPAPI child window has the correct parent before setwindow is called. r=jimm (9d94fdf2ff)
- Bug 1182411 Part 2: Change winless popup surrogate to have its parent set in the chrome process. r=jimm (adee9bb012)
2022-02-02 12:04:50 +08:00

416 lines
15 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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/. */
/**
* 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__
#include "mozilla/gfx/2D.h"
#include "mozilla/RefPtr.h"
#include "nsBaseScreen.h"
#include "nsBaseWidget.h"
#include "nsIScreenManager.h"
#include "nsThreadUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/ContentCache.h"
#include "mozilla/EventForwards.h"
namespace mozilla {
namespace dom {
class TabChild;
} // namespace dom
namespace widget {
struct AutoCacheNativeKeyCommands;
class PuppetWidget : public nsBaseWidget
{
typedef mozilla::dom::TabChild TabChild;
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef nsBaseWidget Base;
// The width and height of the "widget" are clamped to this.
static const size_t kMaxDimension;
public:
explicit PuppetWidget(TabChild* aTabChild);
protected:
virtual ~PuppetWidget();
public:
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const nsIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;
void InitIMEState();
virtual already_AddRefed<nsIWidget>
CreateChild(const nsIntRect &aRect,
nsWidgetInitData *aInitData = nullptr,
bool aForceUseIWidgetParent = false) override;
NS_IMETHOD Destroy() override;
NS_IMETHOD Show(bool aState) override;
virtual bool IsVisible() const override
{ return mVisible; }
NS_IMETHOD ConstrainPosition(bool /*ignored aAllowSlop*/,
int32_t* aX,
int32_t* aY) override
{ *aX = kMaxDimension; *aY = kMaxDimension; return NS_OK; }
// Widget position is controlled by the parent process via TabChild.
NS_IMETHOD Move(double aX, double aY) override
{ return NS_OK; }
NS_IMETHOD Resize(double aWidth,
double aHeight,
bool aRepaint) override;
NS_IMETHOD Resize(double aX,
double aY,
double aWidth,
double aHeight,
bool aRepaint) override
{
if (mBounds.x != aX || mBounds.y != aY) {
NotifyWindowMoved(aX, aY);
}
mBounds.x = aX;
mBounds.y = aY;
return Resize(aWidth, aHeight, aRepaint);
}
// XXX/cjones: copying gtk behavior here; unclear what disabling a
// widget is supposed to entail
NS_IMETHOD Enable(bool aState) override
{ mEnabled = aState; return NS_OK; }
virtual bool IsEnabled() const override
{ return mEnabled; }
NS_IMETHOD SetFocus(bool aRaise = false) override;
virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) override;
NS_IMETHOD Invalidate(const nsIntRect& aRect) override;
// 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.
virtual void* GetNativeData(uint32_t aDataType) override;
#if defined(XP_WIN)
void SetNativeData(uint32_t aDataType, uintptr_t aVal) override;
#endif
NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) override
{ return NS_ERROR_UNEXPECTED; }
// PuppetWidgets don't have any concept of titles.
NS_IMETHOD SetTitle(const nsAString& aTitle) override
{ return NS_ERROR_UNEXPECTED; }
virtual mozilla::LayoutDeviceIntPoint WidgetToScreenOffset() override
{ return LayoutDeviceIntPoint::FromUntyped(GetWindowPosition() + GetChromeDimensions()); }
void InitEvent(WidgetGUIEvent& aEvent, nsIntPoint* aPoint = nullptr);
NS_IMETHOD DispatchEvent(WidgetGUIEvent* aEvent, nsEventStatus& aStatus) override;
nsEventStatus DispatchAPZAwareEvent(WidgetInputEvent* aEvent) override;
nsEventStatus DispatchInputEvent(WidgetInputEvent* aEvent) override;
void SetConfirmedTargetAPZC(uint64_t aInputBlockId,
const nsTArray<ScrollableLayerGuid>& aTargets) const override;
void UpdateZoomConstraints(const uint32_t& aPresShellId,
const FrameMetrics::ViewID& aViewId,
const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
bool AsyncPanZoomEnabled() const override;
NS_IMETHOD CaptureRollupEvents(nsIRollupListener* aListener,
bool aDoCapture) override
{ return NS_ERROR_UNEXPECTED; }
NS_IMETHOD_(bool)
ExecuteNativeKeyBinding(NativeKeyBindingsType aType,
const mozilla::WidgetKeyboardEvent& aEvent,
DoCommandCallback aCallback,
void* aCallbackData) override;
friend struct AutoCacheNativeKeyCommands;
//
// nsBaseWidget methods we override
//
// 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.
virtual nsTransparencyMode GetTransparencyMode() override
{ return eTransparencyTransparent; }
virtual LayerManager*
GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
bool* aAllowRetaining = nullptr) override;
NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
const InputContextAction& aAction) override;
NS_IMETHOD_(InputContext) GetInputContext() override;
virtual nsIMEUpdatePreference GetIMEUpdatePreference() override;
NS_IMETHOD SetCursor(nsCursor aCursor) override;
NS_IMETHOD SetCursor(imgIContainer* aCursor,
uint32_t aHotspotX, uint32_t aHotspotY) override;
virtual void ClearCachedCursor() override;
// 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() override;
virtual double GetDefaultScaleInternal() override;
virtual bool NeedsPaint() override;
virtual TabChild* GetOwningTabChild() override { return mTabChild; }
virtual void ClearBackingScaleCache()
{
mDPI = -1;
mDefaultScale = -1;
}
nsIntSize GetScreenDimensions();
// Get the size of the chrome of the window that this tab belongs to.
nsIntPoint GetChromeDimensions();
// Get the screen position of the application window.
nsIntPoint GetWindowPosition();
NS_IMETHOD GetScreenBounds(nsIntRect &aRect) override;
NS_IMETHOD StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent,
int32_t aPanelX, int32_t aPanelY,
nsString& aCommitted) override;
NS_IMETHOD SetPluginFocused(bool& aFocused) override;
virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
int32_t aNativeKeyCode,
uint32_t aModifierFlags,
const nsAString& aCharacters,
const nsAString& aUnmodifiedCharacters,
nsIObserver* aObserver) override;
virtual nsresult SynthesizeNativeMouseEvent(mozilla::LayoutDeviceIntPoint aPoint,
uint32_t aNativeMessage,
uint32_t aModifierFlags,
nsIObserver* aObserver) override;
virtual nsresult SynthesizeNativeMouseMove(mozilla::LayoutDeviceIntPoint aPoint,
nsIObserver* aObserver) override;
virtual nsresult SynthesizeNativeMouseScrollEvent(mozilla::LayoutDeviceIntPoint aPoint,
uint32_t aNativeMessage,
double aDeltaX,
double aDeltaY,
double aDeltaZ,
uint32_t aModifierFlags,
uint32_t aAdditionalFlags,
nsIObserver* aObserver) override;
virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
TouchPointerState aPointerState,
nsIntPoint aPointerScreenPoint,
double aPointerPressure,
uint32_t aPointerOrientation,
nsIObserver* aObserver) override;
virtual nsresult SynthesizeNativeTouchTap(nsIntPoint aPointerScreenPoint,
bool aLongTap,
nsIObserver* aObserver) override;
virtual nsresult ClearNativeTouchSequence(nsIObserver* aObserver) override;
virtual uint32_t GetMaxTouchPoints() const override;
protected:
bool mEnabled;
bool mVisible;
virtual nsresult NotifyIMEInternal(
const IMENotification& aIMENotification) override;
private:
nsresult Paint();
void SetChild(PuppetWidget* aChild);
nsresult IMEEndComposition(bool aCancel);
nsresult NotifyIMEOfFocusChange(const IMENotification& aIMENotification);
nsresult NotifyIMEOfSelectionChange(const IMENotification& aIMENotification);
nsresult NotifyIMEOfCompositionUpdate(const IMENotification& aIMENotification);
nsresult NotifyIMEOfTextChange(const IMENotification& aIMENotification);
nsresult NotifyIMEOfMouseButtonEvent(const IMENotification& aIMENotification);
nsresult NotifyIMEOfPositionChange(const IMENotification& aIMENotification);
bool CacheEditorRect();
bool CacheCompositionRects(uint32_t& aStartOffset,
nsTArray<mozilla::LayoutDeviceIntRect>& aRectArray,
uint32_t& aTargetCauseOffset);
bool GetCaretRect(mozilla::LayoutDeviceIntRect& aCaretRect, uint32_t aCaretOffset);
uint32_t GetCaretOffset();
nsIWidgetListener* GetCurrentWidgetListener();
class PaintTask : public nsRunnable {
public:
NS_DECL_NSIRUNNABLE
explicit PaintTask(PuppetWidget* widget) : mWidget(widget) {}
void Revoke() { mWidget = nullptr; }
private:
PuppetWidget* mWidget;
};
class MemoryPressureObserver : public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
explicit MemoryPressureObserver(PuppetWidget* aWidget) : mWidget(aWidget) {}
void Remove();
private:
virtual ~MemoryPressureObserver() {}
PuppetWidget* mWidget;
};
friend class MemoryPressureObserver;
// TabChild normally holds a strong reference to this PuppetWidget
// 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;
// The "widget" to which we delegate events if we don't have an
// event handler.
nsRefPtr<PuppetWidget> mChild;
nsIntRegion mDirtyRegion;
nsRevocableEventPtr<PaintTask> mPaintTask;
nsRefPtr<MemoryPressureObserver> mMemoryPressureObserver;
// XXX/cjones: keeping this around until we teach LayerManager to do
// retained-content-only transactions
mozilla::RefPtr<DrawTarget> mDrawTarget;
// IME
nsIMEUpdatePreference mIMEPreferenceOfParent;
ContentCacheInChild mContentCache;
bool mNeedIMEStateInit;
// The DPI of the screen corresponding to this widget
float mDPI;
double mDefaultScale;
// Precomputed answers for ExecuteNativeKeyBinding
bool mNativeKeyCommandsValid;
InfallibleTArray<mozilla::CommandInt> mSingleLineCommands;
InfallibleTArray<mozilla::CommandInt> mMultiLineCommands;
InfallibleTArray<mozilla::CommandInt> mRichTextCommands;
nsCOMPtr<imgIContainer> mCustomCursor;
uint32_t mCursorHotspotX, mCursorHotspotY;
};
struct AutoCacheNativeKeyCommands
{
explicit AutoCacheNativeKeyCommands(PuppetWidget* aWidget)
: mWidget(aWidget)
{
mSavedValid = mWidget->mNativeKeyCommandsValid;
mSavedSingleLine = mWidget->mSingleLineCommands;
mSavedMultiLine = mWidget->mMultiLineCommands;
mSavedRichText = mWidget->mRichTextCommands;
}
void Cache(const InfallibleTArray<mozilla::CommandInt>& aSingleLineCommands,
const InfallibleTArray<mozilla::CommandInt>& aMultiLineCommands,
const InfallibleTArray<mozilla::CommandInt>& aRichTextCommands)
{
mWidget->mNativeKeyCommandsValid = true;
mWidget->mSingleLineCommands = aSingleLineCommands;
mWidget->mMultiLineCommands = aMultiLineCommands;
mWidget->mRichTextCommands = aRichTextCommands;
}
void CacheNoCommands()
{
mWidget->mNativeKeyCommandsValid = true;
mWidget->mSingleLineCommands.Clear();
mWidget->mMultiLineCommands.Clear();
mWidget->mRichTextCommands.Clear();
}
~AutoCacheNativeKeyCommands()
{
mWidget->mNativeKeyCommandsValid = mSavedValid;
mWidget->mSingleLineCommands = mSavedSingleLine;
mWidget->mMultiLineCommands = mSavedMultiLine;
mWidget->mRichTextCommands = mSavedRichText;
}
private:
PuppetWidget* mWidget;
bool mSavedValid;
InfallibleTArray<mozilla::CommandInt> mSavedSingleLine;
InfallibleTArray<mozilla::CommandInt> mSavedMultiLine;
InfallibleTArray<mozilla::CommandInt> mSavedRichText;
};
class PuppetScreen : public nsBaseScreen
{
public:
explicit PuppetScreen(void* nativeScreen);
~PuppetScreen();
NS_IMETHOD GetId(uint32_t* aId) override;
NS_IMETHOD GetRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight) override;
NS_IMETHOD GetAvailRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight) override;
NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth) override;
NS_IMETHOD GetColorDepth(int32_t* aColorDepth) override;
NS_IMETHOD GetRotation(uint32_t* aRotation) override;
NS_IMETHOD SetRotation(uint32_t aRotation) override;
};
class PuppetScreenManager final : public nsIScreenManager
{
~PuppetScreenManager();
public:
PuppetScreenManager();
NS_DECL_ISUPPORTS
NS_DECL_NSISCREENMANAGER
protected:
nsCOMPtr<nsIScreen> mOneScreen;
};
} // namespace widget
} // namespace mozilla
#endif // mozilla_widget_PuppetWidget_h__