Files
palemoon27/layout/ipc/RenderFrameParent.cpp
T
roytam1 fc21d5d094 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1140148 - Update reftest manifests for Android 4.3 emulator; r=dminor (69b7ed099)
- Bug 742176 - Remove/reduce fuzz annotations for tests that no longer appear to be affected by bad overflow areas. r=ehsan (8fac68e26)
- pieces of older patches (6d4b30aed)
- Bug 1153574 - Re-enable Mulet reftests taskcluster-specific disables. r=ahal, a=test-only (72ed7dbc2)
- part of Bug 1138442 - Disable reftests on Mulet in parity with B2G/B2G (8baf07b3c)
- Bug 1073209 - Eliminate usage of CreateSamplingRestrictedDrawable on OS X. r=jrmuizel (86bee3fbc)
- Bug 1148889 - Fuzz some android tests. r=mstange (f63be045e)
- Mark unaccelerated antialiasing reftest failures with APZ as fuzzy. (bug 1157716, r=mstange) (4c0c0f034)
- Bug 1156197. Just use the return value of the cols DOM property for determining the default number of rendered columns for a textarea. r=ms2ger (16ab3064f)
- uniform emoji tests here (5a1e9802c)
- mulet was missing (433a50d93)
- Bug 1141511 - Disable some gtk2Widget-dependant reftests on Mulet. r=ahal (80d3cef05)
- Bug 1141607. Fix the initial value of outline-color to actually be correct. r=dbaron (309275f24)
- part of Bug 1138442 - Disable reftests on Mulet in parity with B2G/B2G (b7a3bb189)
- Bug 1141511 - Disable some gtk2Widget-dependant reftests on Mulet. r=ahal (1afac0742)
- Bug 1153845 - For CSS filters, make the primitive subregions big enough to contain the whole pre-filter visual overflow rect. r=roc (6d56dd6f9)
- annotate (090064379)
- boh (39f7c5aba)
- Bug 1170158 - Apply GTK2 reftest exceptions to GTK3. r=karlt (1f1299503)
- Bug 1165185 - Try to avoid invalidations when scrolling transformed elements. r=roc (d4693eb11)
- Bug 1165185 - Nudge layer prescale to integers. r=roc (2ac6881fc)
- remove spurious file (58fc9059b)
- Bug 1145730 - Restrict the async transforms applied to mask layers to those caused by fixed-position adjustment. r=kats (ebdcc1223)
- Bug 1146024 - Fix up input routing for APZ on Fennec. r=kats (85e8b249b)
- Bug 1146024 - Followup to fix non-android bustage on a CLOSED TREE. r=bustage (1ccd4a58f)
- Bug 1133905. Add some reftests. (89c9f9c8c)
- Bug 1133905. Make layout place scrollbars at the scroll position clamping scrollport size when one is set so that scrollbars are positioned properly on b2g. r=mstange (841279606)
- Bug 1155359 - Add a reftest; r=gw280 (a6e7aeb78)
- Bug 1155359 follow-up: Disable the test on B2G and Mulet (d709b7c54)
- Bug 1157726: Updated algorithm to match ICU implementation of support for bidi isolates. r=smontagu (96d9801e1)
- Bug 1154892 - mozinstall fails to install on Mac with paths which contain white spaces. r=chmanchester (1bddadcdd)
- Bug 1151908 - Updating our character property data with new Bidi info from Unicode 6.3. r=smontagu (c34f88172)
- Bug 817406 part 2 - Tests for propagating 'direction' to the viewport. (3bc7bfa40)
- Bug 1139306. Adjust heights of scrollable area so scrollbar sizes almost match in reftests now that RTL scrollbars correctly show in these reftests. r=smontagu (9c77c96ed)
- Bug 817406 part 3 - Increase the fuzz factors slightly on a few tests for bug 1133905. (22d8a4cbc)
- Bug 1148582. Part 3 follow up. Properly test if a scroll frame uses async scrolling when determining if it needs its clip put on its layer. r=mstange (13beb6a24)
- Fix tests that depend on synchronous scrolling. (bug 1140293, r=mstange,masayuki,kgilbert) (578d2ff1e)
- fix order because of mispatch (75279e185)
- Bug 1162009 - Add TOUCH_CANCEL sending on e10s. r=kats (0fc5574ac)
- Bug 1162179 - Don't create APZCTreeManagers for windows which aren't multiprocess. r=dvander (135d115e0)
- Enable APZ for all Desktop windows if E10s is enabled. (bug 1163115, r=kats) (354729297)
- Fix wheel events not applying root scroll delta overrides. (bug 1147223 part 1, r=kats) (6d650c449)
- fix patch order (08b9ad9bd)
- Improve bad APZ wheel pref detection in about:support. (bug 1147223 part 2, r=kats) (292fa3634)
- Bug 1151890 - Explicitly set a null MessageLoop for the APZ controller thread on OS X. r=mstange (a4fe37d78)
- Bug 1148868 - Put the APZ event thread on Mac behind a pref layers.async-pan-zoom.separate-event-thread that defaults to false. r=dvander (827a7cca7)
- Backed out changeset c5af69669855 (bug 1124084) for various regressions. (28d328c8d)
- Bug 1141819 - Don't implicitly dispatch a runnable to the main thread in RasterImage::StartDecoding. r=baku (1d1233319)
- Bug 1124088 - Rename decode-on-draw to decode-only-on-draw. r=tn (83c24cdb7)
- Bug 1149893 - Add a pref that makes us decode all images immediately. r=baku (6432ae587)
- Bug 1156401 - Fix ContextMenu handling when building Fennec with C++ APZ. r=kats, r=botond (dd784945c)
- Bug 1168629. Always make sure that there is at least one layer with the metrics for the root scroll frame/root element. r=botond,kats (06f19aef3)
- Bug 1154478 - Rename gfxPrefs::LayoutEventRegionsEnabled to LayoutEventRegionsEnabledDoNotUseDirectly. r=kats (68790b756)
- Don't expand displayports beyond the maximum texture size. (bug 1135907, r=kats) (805866f66)
- Bug 1138444 - Add Mulet detection for reftests. r=jgriffin (cc9378556)
- Use widgets for APZ checks, rather than gfxPrefs. (bug 1162064, r=kats,mstange) (40d2823a5)
- Bug 1151993 - Apply shrink-wrapping to block frames that are orthogonal to their containing block. r=smontagu (9fdd76008)
- Bug 1156021 - Use containing block inline-size (as appropriate for writing mode) to compute text-indent when specified as percentage. r=dbaron (c7fcb4193)
- Bug 1152941 - Always use unconstrained block-size when reflowing an orthogonal child block, to avoid incomplete reflow across orthogonal boundary. r=dbaron (5f4748c5a)
- Bug 1163238 - Don't set available block-size to unconstrained for orthogonal-block reflow state until after InitConstraints etc. r=dholbert (07ca784bf)
- Bug 1155798: Drop end-of-line whitespace from C++ files in layout/tables. (whitespace-only, no review, DONTBUILD) (6ad9c50d8)
- Bug 1155880 part 1: Rename nsITableLayoutStrategy::ComputeColumnWidths and associated comments to use "ISize" instead of "Width". r=jfkthame (c3bec937b)
- Bug 1155880 part 2: Rename nsTableColFrame Get/Set/ResetFinalWidth methods to use ISize instead of Width. r=jfkthame (1d2bfd990)
- Bug 1155880 part 3: Rename nsTableFrame::GetColumnWidth to use "ISize" instead of "Width". r=jfkthame (8a0d7a3c8)
- Bug 1159101 part 1 - Alter dependencies among headers of table struct frames. r=roc (b943ee1c3)
- Bug 1159101 part 2 - Add GetTableFrame() for table inner frames. r=roc (6641affa7)
- Bug 1145036 part 1 - Rename mBorderSpacingX/Y to mBorderSpacingCol/Row. r=heycam (7e91504af)
- Bug 1145036 part 2 - Rename nsTableFrame::GetCellSpacingX/Y to GetCol/RowSpacing. r=roc (b439569de)
- Bug 1159101 part 3 - Replace most of nsTableFrame::GetTableFrame() usage with new GetTableFrame() methods. r=roc (4bdf27d00)
- Bug 1159990 - Add TableArea struct and replace nsIntRect with it for table damage area. r=roc (ebca44c12)
2020-12-21 13:33:23 +08:00

709 lines
24 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/. */
#include "base/basictypes.h"
#include "BasicLayers.h"
#include "gfxPrefs.h"
#ifdef MOZ_ENABLE_D3D9_LAYER
# include "LayerManagerD3D9.h"
#endif //MOZ_ENABLE_D3D9_LAYER
#include "mozilla/BrowserElementParent.h"
#include "mozilla/EventForwards.h" // for Modifiers
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/layers/APZCTreeManager.h"
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/LayerTransactionParent.h"
#include "nsContentUtils.h"
#include "nsFocusManager.h"
#include "nsFrameLoader.h"
#include "nsIObserver.h"
#include "nsStyleStructInlines.h"
#include "nsSubDocumentFrame.h"
#include "nsView.h"
#include "nsViewportFrame.h"
#include "RenderFrameParent.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/CompositorChild.h"
#include "ClientLayerManager.h"
#include "FrameLayerBuilder.h"
using namespace mozilla::dom;
using namespace mozilla::gfx;
using namespace mozilla::layers;
namespace mozilla {
namespace layout {
typedef FrameMetrics::ViewID ViewID;
/**
* Gets the layer-pixel offset of aContainerFrame's content rect top-left
* from the nearest display item reference frame (which we assume will be inducing
* a ContainerLayer).
*/
static nsIntPoint
GetContentRectLayerOffset(nsIFrame* aContainerFrame, nsDisplayListBuilder* aBuilder)
{
nscoord auPerDevPixel = aContainerFrame->PresContext()->AppUnitsPerDevPixel();
// Offset to the content rect in case we have borders or padding
// Note that aContainerFrame could be a reference frame itself, so
// we need to be careful here to ensure that we call ToReferenceFrame
// on aContainerFrame and not its parent.
nsPoint frameOffset = aBuilder->ToReferenceFrame(aContainerFrame) +
aContainerFrame->GetContentRectRelativeToSelf().TopLeft();
return frameOffset.ToNearestPixels(auPerDevPixel);
}
// Return true iff |aManager| is a "temporary layer manager". They're
// used for small software rendering tasks, like drawWindow. That's
// currently implemented by a BasicLayerManager without a backing
// widget, and hence in non-retained mode.
inline static bool
IsTempLayerManager(LayerManager* aManager)
{
return (mozilla::layers::LayersBackend::LAYERS_BASIC == aManager->GetBackendType() &&
!static_cast<BasicLayerManager*>(aManager)->IsRetained());
}
already_AddRefed<LayerManager>
GetFrom(nsFrameLoader* aFrameLoader)
{
nsIDocument* doc = aFrameLoader->GetOwnerDoc();
if (!doc) {
return nullptr;
}
return nsContentUtils::LayerManagerForDocument(doc);
}
class RemoteContentController : public GeckoContentController {
public:
explicit RemoteContentController(RenderFrameParent* aRenderFrame)
: mUILoop(MessageLoop::current())
, mRenderFrame(aRenderFrame)
, mHaveZoomConstraints(false)
{ }
virtual void RequestContentRepaint(const FrameMetrics& aFrameMetrics) override
{
MOZ_ASSERT(NS_IsMainThread());
if (mRenderFrame) {
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
browser->UpdateFrame(aFrameMetrics);
}
}
virtual void RequestFlingSnap(const FrameMetrics::ViewID& aScrollId,
const mozilla::CSSPoint& aDestination) override
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::RequestFlingSnap,
aScrollId, aDestination));
return;
}
if (mRenderFrame) {
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
browser->RequestFlingSnap(aScrollId, aDestination);
}
}
virtual void AcknowledgeScrollUpdate(const FrameMetrics::ViewID& aScrollId,
const uint32_t& aScrollGeneration) override
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::AcknowledgeScrollUpdate,
aScrollId, aScrollGeneration));
return;
}
if (mRenderFrame) {
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
browser->AcknowledgeScrollUpdate(aScrollId, aScrollGeneration);
}
}
virtual void HandleDoubleTap(const CSSPoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid) override
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::HandleDoubleTap,
aPoint, aModifiers, aGuid));
return;
}
if (mRenderFrame) {
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
browser->HandleDoubleTap(aPoint, aModifiers, aGuid);
}
}
virtual void HandleSingleTap(const CSSPoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid) override
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::HandleSingleTap,
aPoint, aModifiers, aGuid));
return;
}
if (mRenderFrame) {
mRenderFrame->TakeFocusForClick();
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
browser->HandleSingleTap(aPoint, aModifiers, aGuid);
}
}
virtual void HandleLongTap(const CSSPoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId) override
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::HandleLongTap,
aPoint, aModifiers, aGuid, aInputBlockId));
return;
}
if (mRenderFrame) {
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
browser->HandleLongTap(aPoint, aModifiers, aGuid, aInputBlockId);
}
}
virtual void HandleLongTapUp(const CSSPoint& aPoint,
Modifiers aModifiers,
const ScrollableLayerGuid& aGuid) override
{
if (MessageLoop::current() != mUILoop) {
// We have to send this message from the "UI thread" (main
// thread).
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::HandleLongTapUp,
aPoint, aModifiers, aGuid));
return;
}
if (mRenderFrame) {
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
browser->HandleLongTapUp(aPoint, aModifiers, aGuid);
}
}
void ClearRenderFrame() { mRenderFrame = nullptr; }
virtual void SendAsyncScrollDOMEvent(bool aIsRoot,
const CSSRect& aContentRect,
const CSSSize& aContentSize) override
{
if (MessageLoop::current() != mUILoop) {
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this,
&RemoteContentController::SendAsyncScrollDOMEvent,
aIsRoot, aContentRect, aContentSize));
return;
}
if (mRenderFrame && aIsRoot) {
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
BrowserElementParent::DispatchAsyncScrollEvent(browser, aContentRect,
aContentSize);
}
}
virtual void PostDelayedTask(Task* aTask, int aDelayMs) override
{
MessageLoop::current()->PostDelayedTask(FROM_HERE, aTask, aDelayMs);
}
virtual bool GetRootZoomConstraints(ZoomConstraints* aOutConstraints) override
{
if (mHaveZoomConstraints && aOutConstraints) {
*aOutConstraints = mZoomConstraints;
}
return mHaveZoomConstraints;
}
virtual bool GetTouchSensitiveRegion(CSSRect* aOutRegion) override
{
if (mTouchSensitiveRegion.IsEmpty())
return false;
*aOutRegion = CSSRect::FromAppUnits(mTouchSensitiveRegion.GetBounds());
return true;
}
virtual void NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
APZStateChange aChange,
int aArg) override
{
if (MessageLoop::current() != mUILoop) {
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::NotifyAPZStateChange,
aGuid, aChange, aArg));
return;
}
if (mRenderFrame) {
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
browser->NotifyAPZStateChange(aGuid.mScrollId, aChange, aArg);
}
}
void NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrollId, const nsString& aEvent) override {
if (MessageLoop::current() != mUILoop) {
mUILoop->PostTask(
FROM_HERE,
NewRunnableMethod(this, &RemoteContentController::NotifyMozMouseScrollEvent, aScrollId, aEvent));
return;
}
if (mRenderFrame) {
TabParent* browser = TabParent::GetFrom(mRenderFrame->Manager());
browser->NotifyMouseScrollTestEvent(aScrollId, aEvent);
}
}
// Methods used by RenderFrameParent to set fields stored here.
void SaveZoomConstraints(const ZoomConstraints& aConstraints)
{
mHaveZoomConstraints = true;
mZoomConstraints = aConstraints;
}
void SetTouchSensitiveRegion(const nsRegion& aRegion)
{
mTouchSensitiveRegion = aRegion;
}
private:
MessageLoop* mUILoop;
RenderFrameParent* mRenderFrame;
bool mHaveZoomConstraints;
ZoomConstraints mZoomConstraints;
nsRegion mTouchSensitiveRegion;
};
RenderFrameParent::RenderFrameParent(nsFrameLoader* aFrameLoader,
TextureFactoryIdentifier* aTextureFactoryIdentifier,
uint64_t* aId,
bool* aSuccess)
: mLayersId(0)
, mFrameLoader(aFrameLoader)
, mFrameLoaderDestroyed(false)
, mBackgroundColor(gfxRGBA(1, 1, 1))
, mAsyncPanZoomEnabled(false)
{
*aSuccess = false;
if (!mFrameLoader) {
return;
}
*aId = 0;
nsRefPtr<LayerManager> lm = GetFrom(mFrameLoader);
mAsyncPanZoomEnabled = lm && lm->AsyncPanZoomEnabled();
// Perhaps the document containing this frame currently has no presentation?
if (lm && lm->GetBackendType() == LayersBackend::LAYERS_CLIENT) {
*aTextureFactoryIdentifier =
static_cast<ClientLayerManager*>(lm.get())->GetTextureFactoryIdentifier();
} else {
*aTextureFactoryIdentifier = TextureFactoryIdentifier();
}
if (XRE_GetProcessType() == GeckoProcessType_Default) {
// Our remote frame will push layers updates to the compositor,
// and we'll keep an indirect reference to that tree.
*aId = mLayersId = CompositorParent::AllocateLayerTreeId();
if (lm && lm->GetBackendType() == LayersBackend::LAYERS_CLIENT) {
ClientLayerManager *clientManager =
static_cast<ClientLayerManager*>(lm.get());
clientManager->GetRemoteRenderer()->SendNotifyChildCreated(mLayersId);
}
if (mAsyncPanZoomEnabled) {
mContentController = new RemoteContentController(this);
CompositorParent::SetControllerForLayerTree(mLayersId, mContentController);
}
} else if (XRE_GetProcessType() == GeckoProcessType_Content) {
ContentChild::GetSingleton()->SendAllocateLayerTreeId(aId);
mLayersId = *aId;
CompositorChild::Get()->SendNotifyChildCreated(mLayersId);
}
// Set a default RenderFrameParent
mFrameLoader->SetCurrentRemoteFrame(this);
*aSuccess = true;
}
APZCTreeManager*
RenderFrameParent::GetApzcTreeManager()
{
// We can't get a ref to the APZCTreeManager until after the child is
// created and the static getter knows which CompositorParent is
// instantiated with this layers ID. That's why try to fetch it when
// we first need it and cache the result.
if (!mApzcTreeManager && mAsyncPanZoomEnabled) {
mApzcTreeManager = CompositorParent::GetAPZCTreeManager(mLayersId);
}
return mApzcTreeManager.get();
}
RenderFrameParent::~RenderFrameParent()
{}
void
RenderFrameParent::Destroy()
{
mFrameLoaderDestroyed = true;
}
already_AddRefed<Layer>
RenderFrameParent::BuildLayer(nsDisplayListBuilder* aBuilder,
nsIFrame* aFrame,
LayerManager* aManager,
const nsIntRect& aVisibleRect,
nsDisplayItem* aItem,
const ContainerLayerParameters& aContainerParameters)
{
MOZ_ASSERT(aFrame,
"makes no sense to have a shadow tree without a frame");
MOZ_ASSERT(!mContainer ||
IsTempLayerManager(aManager) ||
mContainer->Manager() == aManager,
"retaining manager changed out from under us ... HELP!");
if (IsTempLayerManager(aManager) ||
(mContainer && mContainer->Manager() != aManager)) {
// This can happen if aManager is a "temporary" manager, or if the
// widget's layer manager changed out from under us. We need to
// FIXME handle the former case somehow, probably with an API to
// draw a manager's subtree. The latter is bad bad bad, but the the
// MOZ_ASSERT() above will flag it. Returning nullptr here will just
// cause the shadow subtree not to be rendered.
NS_WARNING("Remote iframe not rendered");
return nullptr;
}
uint64_t id = GetLayerTreeId();
if (!id) {
return nullptr;
}
nsRefPtr<Layer> layer =
(aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, aItem));
if (!layer) {
layer = aManager->CreateRefLayer();
}
if (!layer) {
// Probably a temporary layer manager that doesn't know how to
// use ref layers.
return nullptr;
}
static_cast<RefLayer*>(layer.get())->SetReferentId(id);
nsIntPoint offset = GetContentRectLayerOffset(aFrame, aBuilder);
// We can only have an offset if we're a child of an inactive
// container, but our display item is LAYER_ACTIVE_FORCE which
// forces all layers above to be active.
MOZ_ASSERT(aContainerParameters.mOffset == nsIntPoint());
gfx::Matrix4x4 m = gfx::Matrix4x4::Translation(offset.x, offset.y, 0.0);
// Remote content can't be repainted by us, so we multiply down
// the resolution that our container expects onto our container.
m.PreScale(aContainerParameters.mXScale, aContainerParameters.mYScale, 1.0);
layer->SetBaseTransform(m);
return layer.forget();
}
void
RenderFrameParent::OwnerContentChanged(nsIContent* aContent)
{
MOZ_ASSERT(mFrameLoader->GetOwnerContent() == aContent,
"Don't build new map if owner is same!");
nsRefPtr<LayerManager> lm = GetFrom(mFrameLoader);
// Perhaps the document containing this frame currently has no presentation?
if (lm && lm->GetBackendType() == LayersBackend::LAYERS_CLIENT) {
ClientLayerManager *clientManager =
static_cast<ClientLayerManager*>(lm.get());
clientManager->GetRemoteRenderer()->SendAdoptChild(mLayersId);
}
}
void
RenderFrameParent::ActorDestroy(ActorDestroyReason why)
{
if (mLayersId != 0) {
if (XRE_GetProcessType() == GeckoProcessType_Content) {
ContentChild::GetSingleton()->SendDeallocateLayerTreeId(mLayersId);
} else {
CompositorParent::DeallocateLayerTreeId(mLayersId);
}
if (mContentController) {
// Stop our content controller from requesting repaints of our
// content.
mContentController->ClearRenderFrame();
// TODO: notify the compositor?
}
}
if (mFrameLoader && mFrameLoader->GetCurrentRemoteFrame() == this) {
// XXX this might cause some weird issues ... we'll just not
// redraw the part of the window covered by this until the "next"
// remote frame has a layer-tree transaction. For
// why==NormalShutdown, we'll definitely want to do something
// better, especially as nothing guarantees another Update() from
// the "next" remote layer tree.
mFrameLoader->SetCurrentRemoteFrame(nullptr);
}
mFrameLoader = nullptr;
}
bool
RenderFrameParent::RecvNotifyCompositorTransaction()
{
TriggerRepaint();
return true;
}
bool
RenderFrameParent::RecvUpdateHitRegion(const nsRegion& aRegion)
{
mTouchRegion = aRegion;
if (mContentController) {
// Tell the content controller about the touch-sensitive region, so
// that it can provide it to APZ. This is required for APZ to do
// correct hit testing for a remote 'mozpasspointerevents' iframe
// until bug 928833 is fixed.
mContentController->SetTouchSensitiveRegion(aRegion);
}
return true;
}
void
RenderFrameParent::TriggerRepaint()
{
mFrameLoader->SetCurrentRemoteFrame(this);
nsIFrame* docFrame = mFrameLoader->GetPrimaryFrameOfOwningContent();
if (!docFrame) {
// Bad, but nothing we can do about it (XXX/cjones: or is there?
// maybe bug 589337?). When the new frame is created, we'll
// probably still be the current render frame and will get to draw
// our content then. Or, we're shutting down and this update goes
// to /dev/null.
return;
}
docFrame->InvalidateLayer(nsDisplayItem::TYPE_REMOTE);
}
uint64_t
RenderFrameParent::GetLayerTreeId() const
{
return mLayersId;
}
void
RenderFrameParent::BuildDisplayList(nsDisplayListBuilder* aBuilder,
nsSubDocumentFrame* aFrame,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists)
{
// We're the subdoc for <browser remote="true"> and it has
// painted content. Display its shadow layer tree.
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
nsPoint offset = aBuilder->ToReferenceFrame(aFrame);
nsRect bounds = aFrame->EnsureInnerView()->GetBounds() + offset;
clipState.ClipContentDescendants(bounds);
aLists.Content()->AppendToTop(
new (aBuilder) nsDisplayRemote(aBuilder, aFrame, this));
}
void
RenderFrameParent::ZoomToRect(uint32_t aPresShellId, ViewID aViewId,
const CSSRect& aRect)
{
if (GetApzcTreeManager()) {
GetApzcTreeManager()->ZoomToRect(ScrollableLayerGuid(mLayersId, aPresShellId, aViewId),
aRect);
}
}
void
RenderFrameParent::ContentReceivedInputBlock(const ScrollableLayerGuid& aGuid,
uint64_t aInputBlockId,
bool aPreventDefault)
{
if (aGuid.mLayersId != mLayersId) {
// Guard against bad data from hijacked child processes
NS_ERROR("Unexpected layers id in ContentReceivedInputBlock; dropping message...");
return;
}
if (GetApzcTreeManager()) {
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
GetApzcTreeManager(), &APZCTreeManager::ContentReceivedInputBlock,
aInputBlockId, aPreventDefault));
}
}
void
RenderFrameParent::SetTargetAPZC(uint64_t aInputBlockId,
const nsTArray<ScrollableLayerGuid>& aTargets)
{
for (size_t i = 0; i < aTargets.Length(); i++) {
if (aTargets[i].mLayersId != mLayersId) {
// Guard against bad data from hijacked child processes
NS_ERROR("Unexpected layers id in SetTargetAPZC; dropping message...");
return;
}
}
if (GetApzcTreeManager()) {
// need a local var to disambiguate between the SetTargetAPZC overloads.
void (APZCTreeManager::*setTargetApzcFunc)(uint64_t, const nsTArray<ScrollableLayerGuid>&)
= &APZCTreeManager::SetTargetAPZC;
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
GetApzcTreeManager(), setTargetApzcFunc,
aInputBlockId, aTargets));
}
}
void
RenderFrameParent::SetAllowedTouchBehavior(uint64_t aInputBlockId,
const nsTArray<TouchBehaviorFlags>& aFlags)
{
if (GetApzcTreeManager()) {
APZThreadUtils::RunOnControllerThread(NewRunnableMethod(
GetApzcTreeManager(), &APZCTreeManager::SetAllowedTouchBehavior,
aInputBlockId, aFlags));
}
}
void
RenderFrameParent::UpdateZoomConstraints(uint32_t aPresShellId,
ViewID aViewId,
bool aIsRoot,
const ZoomConstraints& aConstraints)
{
if (mContentController && aIsRoot) {
mContentController->SaveZoomConstraints(aConstraints);
}
if (GetApzcTreeManager()) {
GetApzcTreeManager()->UpdateZoomConstraints(ScrollableLayerGuid(mLayersId, aPresShellId, aViewId),
aConstraints);
}
}
bool
RenderFrameParent::HitTest(const nsRect& aRect)
{
return mTouchRegion.Contains(aRect);
}
void
RenderFrameParent::GetTextureFactoryIdentifier(TextureFactoryIdentifier* aTextureFactoryIdentifier)
{
nsRefPtr<LayerManager> lm = GetFrom(mFrameLoader);
// Perhaps the document containing this frame currently has no presentation?
if (lm && lm->GetBackendType() == LayersBackend::LAYERS_CLIENT) {
*aTextureFactoryIdentifier =
static_cast<ClientLayerManager*>(lm.get())->GetTextureFactoryIdentifier();
} else {
*aTextureFactoryIdentifier = TextureFactoryIdentifier();
}
}
void
RenderFrameParent::TakeFocusForClick()
{
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (!fm) {
return;
}
nsCOMPtr<nsIContent> owner = mFrameLoader->GetOwnerContent();
if (!owner) {
return;
}
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(owner);
if (!element) {
return;
}
fm->SetFocus(element, nsIFocusManager::FLAG_BYMOUSE |
nsIFocusManager::FLAG_NOSCROLL);
}
} // namespace layout
} // namespace mozilla
nsDisplayRemote::nsDisplayRemote(nsDisplayListBuilder* aBuilder,
nsSubDocumentFrame* aFrame,
RenderFrameParent* aRemoteFrame)
: nsDisplayItem(aBuilder, aFrame)
, mRemoteFrame(aRemoteFrame)
, mEventRegionsOverride(EventRegionsOverride::NoOverride)
{
if (aBuilder->IsBuildingLayerEventRegions()) {
bool frameIsPointerEventsNone = !aFrame->PassPointerEventsToChildren()
&& (aFrame->StyleVisibility()->GetEffectivePointerEvents(aFrame) == NS_STYLE_POINTER_EVENTS_NONE);
if (aBuilder->IsInsidePointerEventsNoneDoc() || frameIsPointerEventsNone) {
mEventRegionsOverride |= EventRegionsOverride::ForceEmptyHitRegion;
}
if (nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(aFrame->PresContext()->PresShell())) {
mEventRegionsOverride |= EventRegionsOverride::ForceDispatchToContent;
}
}
}
already_AddRefed<Layer>
nsDisplayRemote::BuildLayer(nsDisplayListBuilder* aBuilder,
LayerManager* aManager,
const ContainerLayerParameters& aContainerParameters)
{
int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
nsIntRect visibleRect = GetVisibleRect().ToNearestPixels(appUnitsPerDevPixel);
visibleRect += aContainerParameters.mOffset;
nsRefPtr<Layer> layer = mRemoteFrame->BuildLayer(aBuilder, mFrame, aManager, visibleRect, this, aContainerParameters);
if (layer && layer->AsContainerLayer()) {
layer->AsContainerLayer()->SetEventRegionsOverride(mEventRegionsOverride);
}
return layer.forget();
}
void
nsDisplayRemote::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
{
if (mRemoteFrame->HitTest(aRect)) {
aOutFrames->AppendElement(mFrame);
}
}