Files
palemoon27/view/nsViewManager.h
roytam1 4c9d88c9a4 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1246051 - have MediaQueue<T>::Peek/PeekFront return a RefPtr<> to avoid dangling pointers per comment 0. r=gerald. (00f334efb1)
- Bug 1264199: P1. Perform audio conversion in the MSDM taskqueue and ahead of use. r=kinetik (001936e3ea)
- Bug 1267983 - include MediaQueue.h; r=jwwang (036107d765)
- Bug 1264199: P0. Fix nsDequeue/MediaQueue methods constness. r=jwwang (9aa33dfcb5)
- Bug 1264199: P0.1. Export SaferMultDiv method. r=gerald (0b7a35ae4d)
- Bug 1264199: P2. Ensure the AudioStream only ever receive the same content format. r=kinetik (a180d09279)
- Bug 1264199: P3. Attempt to minimize audio quality loss and unnecessary processing. r=kinetik (29d57b5a33)
- Bug 1264199: P4. Add mono to stereo upmix to AudioConverter. r=rillian (49c029bd86)
- Bug 1264199: P5. Perform all downmixing operations in DecodedAudioDataSink. r=kinetik (05a479f095)
- Bug 1264199: P6. Drain resampler when changing format or reaching the end. r=kinetik (8639102a94)
- Bug 1264199: P8. Handle potential resampling errors. r=kinetik (1267e4e73d)
- Bug 1264199: P9. Include pending frames in HasUnplayedFrames calculation. r=jwwang (ce7097fc90)
- Bug 1263496 - Part 1: fix for @mozilla.org/nullprincipal;1 r=bholley (c4c462a1bc)
- Bug 1263496 - Part 2: fix for NS_NULLPRINCIPAL_CONTRACTID. r=bholley (c1504240ec)
- Bug 1263496 - Part 3: fix for nsNullPrincipal::Create (0196a5a3ce)
- Bug 1261009 - Remove the Data Store API, r=fabrice (b22e580107)
- Bug 1261405 - Rename PushPermissionDescriptor.userVisible to `userVisibleOnly`. r=baku (4de70267cc)
- Bug 1266821 - Remove PushPermissionDescriptor from the Permissions API. r=baku (196cd83442)
- Bug 1268393 - Some compilation issues in ServiceWorker code, r=ehsan (d9c2f2554b)
- Merge branch 'dev' of https://github.com/rmottola/Arctic-Fox into dev (6f6c606911)
- Bug 1267733 P1 Treat last-update-time as infinitely in the past when checking for service worker update after restart. r=jdm (255da0a9e2)
- Bug 1209095 - Accept opaqueredirection fetch results if the request redirection type is manual. r=bkelly (6fe92d1368)
- Bug 1267733 P2 Pass ServiceWorkerRegistrationInfo down to CancelChannelRunnable. r=jdm (0ec51f09ef)
- Bug 1267733 P3 Trigger service worker update after failed interception. r=jdm (f89a7998d4)
- Bug 1267733 P4 Add a wpt test that verifies a service worker update can recover from a broken navigation interception. r=jdm (9dc0ce97bd)
- Bug 1267691: Assert on failed attempts to shutdown a thread from itself r=froyd (0cbd1e458c)
- Bug 1180533 - Disable BackgroundHangMonitor on gonk (a2d666e741)
- Bug 1121216 - disable BackgroundHangMonitor for TSan builds; r=jchen (ef15d1016f)
- Bug 1265621 - Use StaticRefPtr in Omnijar.cpp; r=froydnj (81bc32836e)
- Bug 1265621 - Expose outer zip readers in Omnijar::GetReader; r=froydnj (ce3f82929e)
- Bug 1267021 - Use fallible allocation and move semantics for Push events. r=wchen (3a1ae23d8d)
- Bug 1222899 - Handle geolocation-device-events callback. r=kchen (a33bcf4297)
- Bug 1237831 - Update GonkGPSGeolocationProvider.cpp to use B2G-style. r=jst (d389eedf47)
- Bug 1245033 - Build break in dom/system/gonk/GonkGPSGeolocationProvider.cpp:541:126: error: format '%d' expects argument of type 'int', but argument 5 has type 'nsresult'. r=fabrice (ecde789edf)
- Bug 1264287: Convert Wifi to use |UniquePtr|, r=nfroyd (9bad7792bf)
- Bug 1267577 - Move nsRunnable to mozilla::Runnable. r=gsvelto (f58e2161f2)
- Bug 1210370 - Close wpa_supplicant before we shutdown nsIWifiProxyService. r=mrbkap (5cd4dce58f)
- Bug 1218629 - Save audio volume for each device to setting db r=alwu (2f1847dd6f)
- Bug 1249437 - Remove workaround of volume control r=alwu (13cd144a89)
- Bug 1268432: Replace |Task| with |Runnable| in B2G code r=fabrice (bcc768e9cb)
- Bug 1226483 - Add ASSERT check to AudioManager::SelectDeviceFromDevices() r=alwu (446e8f634e)
- Bug 1229234 - Enable audio_is_output_device() on ICS r=alwu (84aae07f23)
- Bug 1267369 - Only generate typelib data for scriptable interfaces; r=khuey (e49b44c9ce)
- Bug 1155969 - Make runtests.py flake8 compliant. r=ted (1de456b206)
- Bug 1266569 - Avoid including the ChromeUtils binding in Base64.h. r=froydnj (7ba39a7687)
- Bug 1267568 part 1 - Add a weak ptr to nsGlobalChromeWindow to remember the pres shell we set the fullscreen change flag. r=smaug (83995d5296)
- Bug 1267568 part 2 - Add helper method to nsIPresShell to get the RefreshDriver. r=smaug (c60589fb40)
- Bug 1267568 part 3 - Use an individual method for check whether resize should be delayed. r=smaug (f0ab5156d1)
- Bug 1267568 part 4 - Replace InFullscreenChange flag of PresShell with IsResizeSuppressed flag in RefreshDriver. r=smaug (0a54f5a08b)
- Bug 1267568 part 5 - Replace the old FullscreenChangePrepare class with a single function. r=smaug (4196e82852)
- Bug 1267568 part 6 - Send fullscreen message before triggering any potential reflow. r=dao (fe9133ca2d)
- Bug 1243352 - attribute a value for ProxyHandlerInfo::mPrefAction in ProxyHandlerInfo::SetPreferredAction. r=blassey (577c23e4cb)
- Bug 1266433 - Send Push observer notifications to parent and content processes. f=janx r=dragana (768c173c2c)
- Bug 1267493 - Replace isURIPotentiallyTrustworthy usage in Push with a testing pref. r=dragana (96434b90d9)
- Bug 1266433 - Send an observer notification when a push subscription is lost. f=janx r=dragana (a7c7277e02)
- Bug 1247685 - Send subscription keys to the Push server. r=mt (651fc0cad3)
- Bug 1266540 - Stub out Push error reporting for the GCM and H2 backends. r=wchen (fd00c311aa)
- Bug 1266623 - Up/down mix WASAPI capture streams when stream formats don't match. r=padenot (ca92ec20ab)
- Bug 1267930 - When the wasapi rendering loop is stuck and we're shuttin down, leak the thread and continue the shutdown process. r=kinetik (04419ad94d)
- Bug 1269692 - Update cubeb to revision 17e3048d0afa1152776fb1867cdb61c49fae69e4. (3de098f4bb)
- Bug 1251502 - Update cubeb's udpate.sh script to account for new files. r=kinetik (a3ae5f27c1)
- Bug 1243234 - Hide MP4Metadata behind an impl pointer. r=giles (1543bedf28)
- Bug 1243234 - Update rust mp4parse telemetry reporting. r=kinetik (bb5c999c06)
- Bug 1242807 - Fix mp4parse-rust's error reporting via telemetry. r=giles (a3ca1b133b)
- Bug 1243234 - Move mp4parse-rust code into MP4MetadataRust impl. r=giles (ec4d6bcf0e)
- Bug 1243234 - Remove now-unnecessary StagefrightPrivate wrapper. r=giles (1e2c54232b)
- Bug 1243234 - Move mp4parse-rust initialization into constructor and clean up try_rust. r=giles (291c01f45a)
- Bug 1243234 - Update rust mp4parse to v0.2.1. r=kinetik (d2774346cd)
- Bug 1264622: [MP4] Resync stagefright's updateAudioTrackInfoFromESDS_MPEG4Audio with upstream. r=kentuckyfriedtakahe (b4b596507b)
- Bug 1254721: Ensure consistency between Cenc offsets and sizes table. r=gerald (59bd7122d1)
- Bug 1151202 - libstagefright: Fix compilation for systems without <sys/cdefs.h>. r=cpearce (e219658c31)
- Bug 1255866 - stagefright: Fix unused variable warnings. r=ajones (62afc26384)
- Bug 1251821: increase UDP socket send buffer on Win 7 r=jdm,jesup (e0d6e545f4)
- Bug 929977: Add support for RFC 7675 ICE consent freshness. r=bwc,mt (ea8a565a65)
- Bug 1231981 - Part 1: Very basic test TURN server for running in CI. r=ahal,drno (c98a79810b)
- Bug 1231981 - Part 2: A websocket-to-process bridge script that can be used by JS to launch an ICE server for testing. r=ahal (5bdb00dfd1)
- Bug 1231981 - Part 2.1: Only run the websocket/process bridge for media tests. r=ahal (86f97e2eb6)
- Bug 1225729: Whitelist specific bad RTCP timestamp value r=drno (f0c8402fd0)
- Bug 1193045 - Check selected attribute for all calls. r=bwc (7eb4095c34)
- Bug 1213056 - update tests to use maplike getStats. r=bwc (d27f997290)
- Bug 1231981 - Part 3: Set up TURN server for webrtc mochitests, when configured to. r=drno (38e4455eec)
- Bug 1231975 - Part 1: Basic audio mochitests for NAT scenarios. r=drno (16efaf581e)
- Bug 1231975 - Part 2: Break a reference cycle between NrTcpSocketIpc and TCPSocketChild, in the same manner as the UDP case. r=mcmanus (1fa55e3e5f)
2024-08-28 22:57:14 +08:00

445 lines
15 KiB
C++

/* -*- Mode: C++; tab-width: 2; 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/. */
#ifndef nsViewManager_h___
#define nsViewManager_h___
#include "nscore.h"
#include "nsView.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsTArray.h"
#include "nsDeviceContext.h"
#include "nsTArray.h"
#include "mozilla/EventForwards.h"
class nsIWidget;
struct nsRect;
class nsRegion;
class nsDeviceContext;
class nsIPresShell;
class nsViewManager final
{
~nsViewManager();
public:
friend class nsView;
typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect;
typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion;
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_INLINE_DECL_REFCOUNTING(nsViewManager)
nsViewManager();
/**
* Initialize the ViewManager
* Note: this instance does not hold a reference to the presshell
* because it holds a reference to this instance.
* @result The result of the initialization, NS_OK if no errors
*/
nsresult Init(nsDeviceContext* aContext);
/**
* Create an ordinary view
* @param aBounds initial bounds for view
* XXX We should eliminate this parameter; you can set the bounds after CreateView
* @param aParent intended parent for view. this is not actually set in the
* nsView through this method. it is only used by the initialization
* code to walk up the view tree, if necessary, to find resources.
* XXX We should eliminate this parameter!
* @param aVisibilityFlag initial visibility state of view
* XXX We should eliminate this parameter; you can set it after CreateView
* @result The new view. Never null.
*/
nsView* CreateView(const nsRect& aBounds,
nsView* aParent,
nsViewVisibility aVisibilityFlag = nsViewVisibility_kShow);
/**
* Get the root of the view tree.
* @result the root view
*/
nsView* GetRootView() { return mRootView; }
/**
* Set the root of the view tree. Does not destroy the current root view.
* aView may have a parent view managed by a different view manager.
* aView may have a widget (anything but printing) or may not (printing).
* @param aView view to set as root
*/
void SetRootView(nsView *aView);
/**
* Get the dimensions of the root window. The dimensions are in
* twips
* @param aWidth out parameter for width of window in twips
* @param aHeight out parameter for height of window in twips
*/
void GetWindowDimensions(nscoord *aWidth, nscoord *aHeight);
/**
* Set the dimensions of the root window.
* Called if the root window is resized. The dimensions are in
* twips
* @param aWidth of window in twips
* @param aHeight of window in twips
*/
void SetWindowDimensions(nscoord aWidth, nscoord aHeight);
/**
* Do any resizes that are pending.
*/
void FlushDelayedResize(bool aDoReflow);
/**
* Called to inform the view manager that the entire area of a view
* is dirty and needs to be redrawn.
* @param aView view to paint. should be root view
*/
void InvalidateView(nsView *aView);
/**
* Called to inform the view manager that some portion of a view is dirty and
* needs to be redrawn. The rect passed in should be in the view's coordinate
* space. Does not check for paint suppression.
* @param aView view to paint. should be root view
* @param rect rect to mark as damaged
*/
void InvalidateViewNoSuppression(nsView *aView, const nsRect &aRect);
/**
* Called to inform the view manager that it should invalidate all views.
*/
void InvalidateAllViews();
/**
* Called to dispatch an event to the appropriate view. Often called
* as a result of receiving a mouse or keyboard event from the widget
* event system.
* @param aEvent event to dispatch
* @param aViewTarget dispatch the event to this view
* @param aStatus event handling status
*/
void DispatchEvent(mozilla::WidgetGUIEvent *aEvent,
nsView* aViewTarget,
nsEventStatus* aStatus);
/**
* Given a parent view, insert another view as its child.
* aSibling and aAbove control the "document order" for the insertion.
* If aSibling is null, the view is inserted at the end of the document order
* if aAfter is true, otherwise it is inserted at the beginning.
* If aSibling is non-null, then if aAfter is true, the view is inserted
* after the sibling in document order (appearing above the sibling unless
* overriden by z-order).
* If it is false, the view is inserted before the sibling.
* The view manager generates the appopriate dirty regions.
* @param aParent parent view
* @param aChild child view
* @param aSibling sibling view
* @param aAfter after or before in the document order
*/
void InsertChild(nsView *aParent, nsView *aChild, nsView *aSibling,
bool aAfter);
void InsertChild(nsView *aParent, nsView *aChild, int32_t aZIndex);
/**
* Remove a specific child view from its parent. This will NOT remove its placeholder
* if there is one.
* The view manager generates the appropriate dirty regions.
* @param aParent parent view
* @param aChild child view
*/
void RemoveChild(nsView *aChild);
/**
* Move a view to the specified position, provided in parent coordinates.
* The new position is the (0, 0) origin for the view's coordinate system.
* The view's bounds may extend above or to the left of this point.
* The view manager generates the appropriate dirty regions.
* @param aView view to move
* @param aX x value for new view position
* @param aY y value for new view position
*/
void MoveViewTo(nsView *aView, nscoord aX, nscoord aY);
/**
* Resize a view. In addition to setting the width and height, you can
* set the x and y of its bounds relative to its position. Negative x and y
* will let the view extend above and to the left of the (0,0) point in its
* coordinate system.
* The view manager generates the appropriate dirty regions.
* @param aView view to move
* @param the new bounds relative to the current position
* @param RepaintExposedAreaOnly
* if true Repaint only the expanded or contracted region,
* if false Repaint the union of the old and new rectangles.
*/
void ResizeView(nsView *aView, const nsRect &aRect,
bool aRepaintExposedAreaOnly = false);
/**
* Set the visibility of a view. Hidden views have the effect of hiding
* their descendants as well. This does not affect painting, so layout
* is responsible for ensuring that content in hidden views is not
* painted nor handling events. It does affect the visibility of widgets;
* if a view is hidden, descendant views with widgets have their widgets
* hidden.
* The view manager generates the appropriate dirty regions.
* @param aView view to change visibility state of
* @param visible new visibility state
*/
void SetViewVisibility(nsView *aView, nsViewVisibility aVisible);
/**
* Set the z-index of a view. Positive z-indices mean that a view
* is above its parent in z-order. Negative z-indices mean that a
* view is below its parent.
* The view manager generates the appropriate dirty regions.
* @param aAutoZIndex indicate that the z-index of a view is "auto". An "auto" z-index
* means that the view does not define a new stacking context,
* which means that the z-indicies of the view's children are
* relative to the view's siblings.
* @param aView view to change z depth of
* @param aZindex explicit z depth
*/
void SetViewZIndex(nsView *aView, bool aAutoZIndex, int32_t aZindex);
/**
* Set whether the view "floats" above all other views,
* which tells the compositor not to consider higher views in
* the view hierarchy that would geometrically intersect with
* this view. This is a hack, but it fixes some problems with
* views that need to be drawn in front of all other views.
*/
void SetViewFloating(nsView *aView, bool aFloatingView);
/**
* Set the presshell associated with this manager
* @param aPresShell - new presshell
*/
void SetPresShell(nsIPresShell *aPresShell) { mPresShell = aPresShell; }
/**
* Get the pres shell associated with this manager
*/
nsIPresShell* GetPresShell() { return mPresShell; }
/**
* Get the device context associated with this manager
*/
nsDeviceContext* GetDeviceContext() const
{
return mContext;
}
/**
* A stack class for disallowing changes that would enter painting. For
* example, popup widgets shouldn't be resized during reflow, since doing so
* might cause synchronous painting inside reflow which is forbidden.
* While refresh is disabled, widget geometry changes are deferred and will
* be handled later, either from the refresh driver or from an NS_WILL_PAINT
* event.
* We don't want to defer widget geometry changes all the time. Resizing a
* popup from script doesn't need to be deferred, for example, especially
* since popup widget geometry is observable from script and expected to
* update synchronously.
*/
class MOZ_STACK_CLASS AutoDisableRefresh {
public:
explicit AutoDisableRefresh(nsViewManager* aVM) {
if (aVM) {
mRootVM = aVM->IncrementDisableRefreshCount();
}
}
~AutoDisableRefresh() {
if (mRootVM) {
mRootVM->DecrementDisableRefreshCount();
}
}
private:
AutoDisableRefresh(const AutoDisableRefresh& aOther);
const AutoDisableRefresh& operator=(const AutoDisableRefresh& aOther);
RefPtr<nsViewManager> mRootVM;
};
private:
friend class AutoDisableRefresh;
nsViewManager* IncrementDisableRefreshCount();
void DecrementDisableRefreshCount();
public:
/**
* Retrieve the widget at the root of the nearest enclosing
* view manager whose root view has a widget.
*/
void GetRootWidget(nsIWidget **aWidget);
/**
* Indicate whether the viewmanager is currently painting
*
* @param aPainting true if the viewmanager is painting
* false otherwise
*/
void IsPainting(bool& aIsPainting);
/**
* Retrieve the time of the last user event. User events
* include mouse and keyboard events. The viewmanager
* saves the time of the last user event.
*
* @param aTime Last user event time in microseconds
*/
void GetLastUserEventTime(uint32_t& aTime);
/**
* Find the nearest display root view for the view aView. This is the view for
* the nearest enclosing popup or the root view for the root document.
*/
static nsView* GetDisplayRootFor(nsView* aView);
/**
* Flush the accumulated dirty region to the widget and update widget
* geometry.
*/
void ProcessPendingUpdates();
/**
* Just update widget geometry without flushing the dirty region
*/
void UpdateWidgetGeometry();
int32_t AppUnitsPerDevPixel() const
{
return mContext->AppUnitsPerDevPixel();
}
private:
static uint32_t gLastUserEventTime;
/* Update the cached RootViewManager pointer on this view manager. */
void InvalidateHierarchy();
void FlushPendingInvalidates();
void ProcessPendingUpdatesForView(nsView *aView,
bool aFlushDirtyRegion = true);
void ProcessPendingUpdatesRecurse(nsView* aView,
nsTArray<nsCOMPtr<nsIWidget> >& aWidgets);
void ProcessPendingUpdatesPaint(nsIWidget* aWidget);
void FlushDirtyRegionToWidget(nsView* aView);
/**
* Call WillPaint() on all view observers under this vm root.
*/
void CallWillPaintOnObservers();
void ReparentChildWidgets(nsView* aView, nsIWidget *aNewWidget);
void ReparentWidgets(nsView* aView, nsView *aParent);
void InvalidateWidgetArea(nsView *aWidgetView, const nsRegion &aDamagedRegion);
void InvalidateViews(nsView *aView);
// aView is the view for aWidget and aRegion is relative to aWidget.
void Refresh(nsView* aView, const LayoutDeviceIntRegion& aRegion);
// Utilities
bool IsViewInserted(nsView *aView);
/**
* Intersects aRect with aView's bounds and then transforms it from aView's
* coordinate system to the coordinate system of the widget attached to
* aView.
*/
LayoutDeviceIntRect ViewToWidget(nsView* aView, const nsRect& aRect) const;
void DoSetWindowDimensions(nscoord aWidth, nscoord aHeight);
bool ShouldDelayResize() const;
bool IsPainting() const {
return RootViewManager()->mPainting;
}
void SetPainting(bool aPainting) {
RootViewManager()->mPainting = aPainting;
}
void InvalidateView(nsView *aView, const nsRect &aRect);
nsViewManager* RootViewManager() const { return mRootViewManager; }
bool IsRootVM() const { return this == RootViewManager(); }
// Whether synchronous painting is allowed at the moment. For example,
// widget geometry changes can cause synchronous painting, so they need to
// be deferred while refresh is disabled.
bool IsPaintingAllowed() { return RootViewManager()->mRefreshDisableCount == 0; }
void WillPaintWindow(nsIWidget* aWidget);
bool PaintWindow(nsIWidget* aWidget, LayoutDeviceIntRegion aRegion);
void DidPaintWindow();
// Call this when you need to let the viewmanager know that it now has
// pending updates.
void PostPendingUpdate();
RefPtr<nsDeviceContext> mContext;
nsIPresShell *mPresShell;
// The size for a resize that we delayed until the root view becomes
// visible again.
nsSize mDelayedResize;
nsView *mRootView;
// mRootViewManager is a strong ref unless it equals |this|. It's
// never null (if we have no ancestors, it will be |this|).
nsViewManager *mRootViewManager;
// The following members should not be accessed directly except by
// the root view manager. Some have accessor functions to enforce
// this, as noted.
int32_t mRefreshDisableCount;
// Use IsPainting() and SetPainting() to access mPainting.
bool mPainting;
bool mRecursiveRefreshPending;
bool mHasPendingWidgetGeometryChanges;
//from here to public should be static and locked... MMP
//list of view managers
static nsTArray<nsViewManager*> *gViewManagers;
};
/**
Invalidation model:
1) Callers call into the view manager and ask it to invalidate a view.
2) The view manager finds the "right" widget for the view, henceforth called
the root widget.
3) The view manager traverses descendants of the root widget and for each
one that needs invalidation stores the rect to invalidate on the widget's
view (batching).
4) The dirty region is flushed to the right widget when
ProcessPendingUpdates is called from the RefreshDriver.
It's important to note that widgets associated to views outside this view
manager can end up being invalidated during step 3. Therefore, the end of a
view update batch really needs to traverse the entire view tree, to ensure
that those invalidates happen.
To cope with this, invalidation processing and should only happen on the
root viewmanager.
*/
#endif // nsViewManager_h___