forked from upstream/UXP-mirror
T-505 (the owner's "cheaper part pictures", 2026-11-03). A frame without its parts (flag 128) used to carry one signature of all its parts; when it moved, the parts pass composed and read every part. Now each rect of the parts list has a signature of its own: the outermost fixed or sticky layer's subtree as before, every subtree layer's last paint as the stamp of one counter that only goes up (CompositableTransactionParent stamps each compositable update's layer, part or not: a layer that becomes a part later carries it — review F2), the part's scale and the sub-pixel phase of its position, where it sits inside the rect and its size (review F3: a part wider than the frame moving sideways, or moving inside a merged rect, keeps the rect's size), and the rect's size; a rect no part's rect meets (a nested part's own) takes every part's with its index and place (review F6). The whole signature is the rects' and the global paint count, so a daemon with the one signature behaves as before (every part read when any moved). jihad_offscreen_compose_post3/start3 (jihad_offscreen_overview_ok answers 4) take the list of signatures the daemon holds pictures of; the pass packs and reads only the rects whose signature is not in it, in rect order, and the poll's 54 ints carry each rect's signature (49..52) and the rects read as a mask (53). post2/start2 keep their meaning. Measured by finger on desktop Wikipedia (its two sidebars; the contents panel, 310 of 340 KB, is the one that changes): the pass reads the panel alone, 10.4 -> 11.4 fps flowing; the long page unchanged. Verify 0 wrong rows over the scripted pans on both (docs/rounds/t505-2026-11-03/notes.txt). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
604 lines
27 KiB
C++
604 lines
27 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* 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/Mutex.h" // Jihad T-515
|
|
#include "mozilla/gfx/2D.h"
|
|
#include "mozilla/RefPtr.h"
|
|
#include "nsBaseScreen.h"
|
|
#include "nsBaseWidget.h"
|
|
#include <vector>
|
|
struct JihadReadJob; // T-502, PuppetWidget.cpp
|
|
#include "nsCOMArray.h"
|
|
#include "nsIKeyEventInPluginCallback.h"
|
|
#include "nsIScreenManager.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "mozilla/Attributes.h"
|
|
#include "mozilla/ContentCache.h"
|
|
#include "mozilla/EventForwards.h"
|
|
|
|
class nsIDocShell; // Jihad offscreen render (JihadRenderDocument)
|
|
|
|
namespace mozilla {
|
|
namespace layers { class CompositorBridgeParent; } // Jihad T-502
|
|
|
|
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;
|
|
typedef mozilla::CSSRect CSSRect;
|
|
|
|
// 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
|
|
|
|
// PuppetWidget creation is infallible, hence InfallibleCreate(), which
|
|
// Create() calls.
|
|
using nsBaseWidget::Create; // for Create signature not overridden here
|
|
virtual nsresult Create(nsIWidget* aParent,
|
|
nsNativeWidget aNativeParent,
|
|
const LayoutDeviceIntRect& aRect,
|
|
nsWidgetInitData* aInitData = nullptr)
|
|
override;
|
|
void InfallibleCreate(nsIWidget* aParent,
|
|
nsNativeWidget aNativeParent,
|
|
const LayoutDeviceIntRect& aRect,
|
|
nsWidgetInitData* aInitData = nullptr);
|
|
|
|
void InitIMEState();
|
|
|
|
virtual already_AddRefed<nsIWidget>
|
|
CreateChild(const LayoutDeviceIntRect& aRect,
|
|
nsWidgetInitData* aInitData = nullptr,
|
|
bool aForceUseIWidgetParent = false) override;
|
|
|
|
virtual void Destroy() override;
|
|
|
|
NS_IMETHOD Show(bool aState) override;
|
|
|
|
virtual bool IsVisible() const override
|
|
{ return mVisible; }
|
|
|
|
virtual void ConstrainPosition(bool /*ignored aAllowSlop*/,
|
|
int32_t* aX,
|
|
int32_t* aY) override
|
|
{ *aX = kMaxDimension; *aY = kMaxDimension; }
|
|
|
|
// 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 LayoutDeviceIntRect& aRect) override;
|
|
|
|
// 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
|
|
|
|
// PuppetWidgets don't have any concept of titles.
|
|
NS_IMETHOD SetTitle(const nsAString& aTitle) override
|
|
{ return NS_ERROR_UNEXPECTED; }
|
|
|
|
virtual LayoutDeviceIntPoint WidgetToScreenOffset() override
|
|
{ return LayoutDeviceIntPoint::FromUnknownPoint(GetWindowPosition() + GetChromeDimensions()); }
|
|
|
|
int32_t RoundsWidgetCoordinatesTo() override;
|
|
|
|
void InitEvent(WidgetGUIEvent& aEvent,
|
|
LayoutDeviceIntPoint* aPoint = nullptr);
|
|
|
|
NS_IMETHOD DispatchEvent(WidgetGUIEvent* aEvent, nsEventStatus& aStatus) 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_(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) override;
|
|
|
|
// This is used after a compositor reset.
|
|
LayerManager* RecreateLayerManager(PLayerTransactionChild* aShadowManager);
|
|
|
|
NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
|
|
const InputContextAction& aAction) override;
|
|
NS_IMETHOD_(InputContext) GetInputContext() override;
|
|
NS_IMETHOD_(NativeIMEContext) GetNativeIMEContext() 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;
|
|
|
|
// Paint the widget immediately if any paints are queued up.
|
|
void PaintNowIfNeeded();
|
|
|
|
// --- Jihad offscreen render support ---
|
|
// When the env var JIHAD_OFFSCREEN is set, a (null-TabChild) PuppetWidget
|
|
// renders through an in-process CPU BasicLayerManager into an in-memory
|
|
// DrawTarget (no compositor, no native window, no X/GTK), so a headless
|
|
// render daemon can read the pixels straight out. See the extern "C"
|
|
// jihad_offscreen_* entry points in PuppetWidget.cpp.
|
|
static bool JihadOffscreen();
|
|
void JihadEnsureDrawTarget();
|
|
already_AddRefed<mozilla::gfx::SourceSurface> JihadSnapshot();
|
|
// Render the docShell's document straight into mDrawTarget via the presShell
|
|
// (the canonical offscreen path, like canvas drawWindow / tab thumbnails). The
|
|
// widget Paint() path does NOT paint the embedded content into this widget, so
|
|
// relying on it produced a black frame; this renders the actual document.
|
|
bool JihadRenderDocument(nsIDocShell* aDocShell, double aZoom = 1.0,
|
|
double aPanX = 0.0, double aPanY = 0.0);
|
|
// Sticky invalidation flag for the render daemon (jihad_offscreen_take_dirty):
|
|
// set on every Invalidate() so the daemon knows CONTENT CHANGED and a repaint is
|
|
// due — the offscreen embedding has no compositor/paint-event feedback loop, so
|
|
// without this the daemon's frame delivery is input-driven only and JS/SPA DOM
|
|
// updates, async image decode, and incremental page render leave the shared
|
|
// buffer stale (the on-device "old page sticks around until you drag" bug).
|
|
// Deliberately separate from mDirtyRegion, which the PaintTask self-clears.
|
|
//
|
|
// DRAINS THE CHILD CHAIN: the embedding's view hierarchy does not paint through
|
|
// the top-level widget the daemon created — nsView::CreateWidgetForParent goes
|
|
// through PuppetWidget::CreateChild, which makes a SEPARATE child PuppetWidget
|
|
// (linked back via SetChild). Every Invalidate() from the view manager lands on
|
|
// that CHILD, setting the child's mJihadDirty, while the daemon polls the
|
|
// top-level parent — whose flag nothing ever set. That inert dirty loop is why
|
|
// anything that became visually ready after the last load/input-driven paint
|
|
// (async image decode — the about:addons icons — JS/SPA DOM updates) never
|
|
// appeared on the device: no repaint was ever triggered. Draining the chain
|
|
// here makes the poll see the child's invalidations.
|
|
bool JihadTakeDirty() {
|
|
bool d = mJihadDirty; mJihadDirty = false;
|
|
for (PuppetWidget* c = mChild.get(); c; c = c->mChild.get()) {
|
|
if (c->mJihadDirty) { d = true; c->mJihadDirty = false; }
|
|
}
|
|
return d;
|
|
}
|
|
|
|
// The BOUNDING BOX of everything invalidated since the last drain, in the widget's own
|
|
// device px, drained with the flag. A whole-viewport software repaint costs ~40 ms on this
|
|
// hardware, which caps anything animated at ~20 fps no matter how fast the source runs; a
|
|
// plugin animating in a 320x240 box only needs those rows. Accumulated as a bounding box
|
|
// rather than a region on purpose: the consumer can only issue rectangular renders, so a
|
|
// precise region would be discarded at the first use anyway.
|
|
bool JihadTakeDirtyRect(int32_t* aX, int32_t* aY, int32_t* aW, int32_t* aH) {
|
|
LayoutDeviceIntRect r = mJihadDirtyRect;
|
|
mJihadDirtyRect.SetEmpty();
|
|
for (PuppetWidget* c = mChild.get(); c; c = c->mChild.get()) {
|
|
if (!c->mJihadDirtyRect.IsEmpty()) {
|
|
r = r.IsEmpty() ? c->mJihadDirtyRect : r.Union(c->mJihadDirtyRect);
|
|
c->mJihadDirtyRect.SetEmpty();
|
|
}
|
|
}
|
|
if (r.IsEmpty()) {
|
|
return false;
|
|
}
|
|
if (aX) *aX = r.x;
|
|
if (aY) *aY = r.y;
|
|
if (aW) *aW = r.width;
|
|
if (aH) *aH = r.height;
|
|
return true;
|
|
}
|
|
|
|
// --- Jihad T-502: the GPU compositor spike ---
|
|
// With JIHAD_GPU_COMPOSITOR in the environment the offscreen widget creates an IN-PROCESS
|
|
// compositor (nsBaseWidget::CreateCompositor: CompositorOGL on an EGL pbuffer when
|
|
// MOZ_LAYERS_PREFER_OFFSCREEN is set) behind a ClientLayerManager, instead of painting on
|
|
// the CPU through a BasicLayerManager. A frame is then painted as layers (PresShell::Paint on
|
|
// the root view) and fetched over the upstream snapshot road: BeginTransactionWithTarget +
|
|
// EndEmptyTransaction -> SendMakeSnapshot (sync) -> ForceComposeToTarget -> glReadPixels into
|
|
// a shared surface the client draws into our target. Nothing below the export is ours.
|
|
static bool JihadGpuCompositor();
|
|
bool JihadComposeTo(nsIDocShell* aDocShell, void* aDest, int aStride,
|
|
int aWidth, int aHeight);
|
|
// The same frame in two halves, so the daemon's main thread does not sit out the compositor
|
|
// thread's read: Start paints the layers and posts the compose + read of rows [aRowLo, aRowHi)
|
|
// (0,0 = none asked for) joined with what the composite changed, and returns a token (0 =
|
|
// failed). Poll returns 1 when the frame is in aDest (aInvLo/aInvHi = the rows the composite
|
|
// changed), 0 while it is pending, -1 failed or unknown; with aWait it waits up to 3 s.
|
|
// Forget drops a token whose buffer went away.
|
|
uint32_t JihadComposeStart(nsIDocShell* aDocShell, void* aDest, int aStride,
|
|
int aWidth, int aHeight, int aRowLo, int aRowHi, int aRow2Lo = 0, int aRow2Hi = 0, int aShift = 0,
|
|
const void* aSrc = nullptr, int aSrcY = 0, int aFlags = 0, // aFlags: 1 engine shift, 2 verify, 4 columns
|
|
int aColX0 = 0, int aColX1 = 0, // T-511: the bands' stale columns (flag 4)
|
|
void* aPartsDest = nullptr, int aPartsCap = 0, uint32_t aPartsHave = 0, // T-505 (E2)
|
|
const uint32_t* aPartsHaveList = nullptr, int aNPartsHave = -1); // T-505 (per part)
|
|
// aOut (10 ints, may be null): the rows the tree changed, the rows fixed layers cover, the two
|
|
// bands read, the frame's position and its valid flag; 12 for a job posted with flag 4 (T-511):
|
|
// the columns the composite changed; aScrollOnly: the composite's only change was the card's scroll
|
|
int JihadComposePoll(uint32_t aToken, bool aWait, int* aOut, bool* aScrollOnly = nullptr, int aOutLen = 12);
|
|
// T-515: the frame's two halves on their own. PaintLayers (the main thread) flushes and paints the
|
|
// layers, as Start does first; Post (any thread: the express lane while the main thread runs the
|
|
// page's script) composes the layer tree as it stands and reads it, at the view given (aView:
|
|
// scale, offset x, offset y, scroll x, scroll y; null = the view last set) and aScrollValid. The
|
|
// token is polled and forgotten as any other.
|
|
bool JihadPaintLayers(nsIDocShell* aDocShell);
|
|
uint32_t JihadComposePost(void* aDest, int aStride, int aWidth, int aHeight, int aRowLo, int aRowHi,
|
|
int aRow2Lo, int aRow2Hi, int aShift, const void* aSrc, int aSrcY, int aFlags,
|
|
const float* aView, bool aScrollValid, int aColX0 = 0, int aColX1 = 0,
|
|
void* aPartsDest = nullptr, int aPartsCap = 0, uint32_t aPartsHave = 0, // T-505 (E2)
|
|
const uint32_t* aPartsHaveList = nullptr, int aNPartsHave = -1); // T-505 (per part)
|
|
void JihadComposeForget(uint32_t aToken);
|
|
// T-515: a job's state without taking its result: 1 done, 2 composed (being read), 0 pending, -1 unknown
|
|
int JihadComposePeek(uint32_t aToken);
|
|
void JihadComposeAbandonAll();
|
|
void JihadSetScroll(double aX, double aY, bool aValid) { mJihadScrollX = (float)aX; mJihadScrollY = (float)aY; mJihadScrollValid = aValid; }
|
|
mozilla::layers::CompositorBridgeParent* JihadBridge();
|
|
void JihadSetView(double aScale, double aOffsetX, double aOffsetY) {
|
|
mJihadScale = (aScale > 0.0) ? (float)aScale : 1.0f; mJihadOffX = (float)aOffsetX; mJihadOffY = (float)aOffsetY;
|
|
}
|
|
|
|
virtual TabChild* GetOwningTabChild() override { return mTabChild; }
|
|
|
|
void UpdateBackingScaleCache(float aDpi, int32_t aRounding, double aScale)
|
|
{
|
|
mDPI = aDpi;
|
|
mRounding = aRounding;
|
|
mDefaultScale = aScale;
|
|
}
|
|
|
|
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();
|
|
|
|
virtual LayoutDeviceIntRect GetScreenBounds() override;
|
|
|
|
NS_IMETHOD StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent,
|
|
int32_t aPanelX, int32_t aPanelY,
|
|
nsString& aCommitted) override;
|
|
|
|
virtual void SetPluginFocused(bool& aFocused) override;
|
|
virtual void DefaultProcOfPluginEvent(
|
|
const mozilla::WidgetPluginEvent& aEvent) 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(LayoutDeviceIntPoint aPoint,
|
|
uint32_t aNativeMessage,
|
|
uint32_t aModifierFlags,
|
|
nsIObserver* aObserver) override;
|
|
virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
|
|
nsIObserver* aObserver) override;
|
|
virtual nsresult SynthesizeNativeMouseScrollEvent(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,
|
|
LayoutDeviceIntPoint aPoint,
|
|
double aPointerPressure,
|
|
uint32_t aPointerOrientation,
|
|
nsIObserver* aObserver) override;
|
|
virtual nsresult SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint,
|
|
bool aLongTap,
|
|
nsIObserver* aObserver) override;
|
|
virtual nsresult ClearNativeTouchSequence(nsIObserver* aObserver) override;
|
|
virtual uint32_t GetMaxTouchPoints() const override;
|
|
virtual void GetPointerCapabilities(PointerCapabilities& aCaps) const override;
|
|
|
|
virtual void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
|
|
|
|
virtual void SetCandidateWindowForPlugin(
|
|
const CandidateWindowPosition& aPosition) override;
|
|
|
|
virtual void ZoomToRect(const uint32_t& aPresShellId,
|
|
const FrameMetrics::ViewID& aViewId,
|
|
const CSSRect& aRect,
|
|
const uint32_t& aFlags) override;
|
|
|
|
virtual bool HasPendingInputEvent() override;
|
|
|
|
void HandledWindowedPluginKeyEvent(const NativeEventData& aKeyEventData,
|
|
bool aIsConsumed);
|
|
virtual nsresult OnWindowedPluginKeyEvent(
|
|
const NativeEventData& aKeyEventData,
|
|
nsIKeyEventInPluginCallback* aCallback) override;
|
|
|
|
virtual void LookUpDictionary(
|
|
const nsAString& aText,
|
|
const nsTArray<mozilla::FontRange>& aFontRangeArray,
|
|
const bool aIsVertical,
|
|
const LayoutDeviceIntPoint& aPoint) override;
|
|
|
|
protected:
|
|
virtual nsresult NotifyIMEInternal(
|
|
const IMENotification& aIMENotification) override;
|
|
|
|
private:
|
|
nsresult Paint();
|
|
|
|
void SetChild(PuppetWidget* aChild);
|
|
|
|
nsresult RequestIMEToCommitComposition(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<LayoutDeviceIntRect>& aRectArray,
|
|
uint32_t& aTargetCauseOffset);
|
|
bool GetCaretRect(LayoutDeviceIntRect& aCaretRect, uint32_t aCaretOffset);
|
|
uint32_t GetCaretOffset();
|
|
|
|
nsIWidgetListener* GetCurrentWidgetListener();
|
|
|
|
class PaintTask : public Runnable {
|
|
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.
|
|
RefPtr<PuppetWidget> mChild;
|
|
LayoutDeviceIntRegion mDirtyRegion;
|
|
bool mJihadDirty = false; // sticky Invalidate() flag, drained by JihadTakeDirty()
|
|
bool mJihadLayersPainted = false; // T-527: JihadPaintLayers has painted this widget's layers once
|
|
float mJihadPaintedRes = 0.0f; // T-527: the pres shell's resolution at that paint (a change repaints)
|
|
bool mJihadCompositorTried = false; // T-502: CreateCompositor attempted once per widget
|
|
bool mJihadSharedLayerManager = false; // T-502: mLayerManager is the parent's (a child widget)
|
|
float mJihadScale = 1.0f; // T-502: the card's zoom, applied by the compositor
|
|
std::vector<::JihadReadJob*> mJihadJobs; // T-502: frames in flight on the compositor thread
|
|
mozilla::Mutex mJihadJobsLock{"jihad-compose-jobs"}; // T-515: the list from the main thread and the express lane
|
|
uint32_t JihadPostJob(void* aDest, int aStride, int aWidth, int aHeight, int aRowLo, int aRowHi, int aRow2Lo,
|
|
int aRow2Hi, int aShift, const void* aSrc, int aSrcY, int aFlags,
|
|
const float* aView = nullptr, bool aScrollValid = false, int aColX0 = 0, int aColX1 = 0,
|
|
void* aPartsDest = nullptr, int aPartsCap = 0, uint32_t aPartsHave = 0,
|
|
const uint32_t* aPartsHaveList = nullptr, int aNPartsHave = -1); // T-505 (per part)
|
|
uint32_t mJihadNextToken = 1;
|
|
float mJihadScrollX = 0.0f, mJihadScrollY = 0.0f; // T-502: the card's scroll for the compositor
|
|
bool mJihadScrollValid = false;
|
|
float mJihadOffX = 0.0f, mJihadOffY = 0.0f; // T-502: the residual visual offset, CSS px
|
|
// Bounding box of the same invalidations, drained by JihadTakeDirtyRect(). Kept beside the
|
|
// flag rather than replacing it: the flag answers "is anything dirty" for callers that do a
|
|
// full repaint, and must keep working unchanged if the rect is ignored.
|
|
LayoutDeviceIntRect mJihadDirtyRect;
|
|
nsRevocableEventPtr<PaintTask> mPaintTask;
|
|
RefPtr<MemoryPressureObserver> mMemoryPressureObserver;
|
|
// XXX/cjones: keeping this around until we teach LayerManager to do
|
|
// retained-content-only transactions
|
|
RefPtr<DrawTarget> mDrawTarget;
|
|
// IME
|
|
nsIMEUpdatePreference mIMEPreferenceOfParent;
|
|
InputContext mInputContext;
|
|
// mNativeIMEContext is initialized when this dispatches every composition
|
|
// event both from parent process's widget and TextEventDispatcher in same
|
|
// process. If it hasn't been started composition yet, this isn't necessary
|
|
// for XP code since there is no TextComposition instance which is caused by
|
|
// the PuppetWidget instance.
|
|
NativeIMEContext mNativeIMEContext;
|
|
ContentCacheInChild mContentCache;
|
|
|
|
// The DPI of the screen corresponding to this widget
|
|
float mDPI;
|
|
int32_t mRounding;
|
|
double mDefaultScale;
|
|
|
|
// Precomputed answers for ExecuteNativeKeyBinding
|
|
InfallibleTArray<mozilla::CommandInt> mSingleLineCommands;
|
|
InfallibleTArray<mozilla::CommandInt> mMultiLineCommands;
|
|
InfallibleTArray<mozilla::CommandInt> mRichTextCommands;
|
|
|
|
nsCOMPtr<imgIContainer> mCustomCursor;
|
|
uint32_t mCursorHotspotX, mCursorHotspotY;
|
|
|
|
nsCOMArray<nsIKeyEventInPluginCallback> mKeyEventInPluginCallbacks;
|
|
|
|
protected:
|
|
bool mEnabled;
|
|
bool mVisible;
|
|
|
|
private:
|
|
bool mNeedIMEStateInit;
|
|
bool mNativeKeyCommandsValid;
|
|
};
|
|
|
|
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__
|