Backed out changeset 4bc6e2713327 (bug 1289650)

This commit is contained in:
Sebastian Hengst
2016-08-24 23:15:35 +02:00
parent dee4b7de13
commit 2c110674d6
14 changed files with 176 additions and 394 deletions

View File

@@ -5,37 +5,98 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/layers/APZChild.h"
#include "mozilla/layers/GeckoContentController.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/layers/APZCCallbackHelper.h"
#include "InputData.h" // for InputData
namespace mozilla {
namespace layers {
APZChild::APZChild(RefPtr<GeckoContentController> aController)
: mController(aController)
/**
* There are cases where we try to create the APZChild before the corresponding
* TabChild has been created, we use an observer for the "tab-child-created"
* topic to set the TabChild in the APZChild when it has been created.
*/
class TabChildCreatedObserver : public nsIObserver
{
public:
TabChildCreatedObserver(APZChild* aAPZChild, const dom::TabId& aTabId)
: mAPZChild(aAPZChild),
mTabId(aTabId)
{}
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
private:
virtual ~TabChildCreatedObserver()
{}
// TabChildCreatedObserver is owned by mAPZChild, and mAPZChild outlives its
// TabChildCreatedObserver, so the raw pointer is fine.
APZChild* mAPZChild;
dom::TabId mTabId;
};
NS_IMPL_ISUPPORTS(TabChildCreatedObserver, nsIObserver)
NS_IMETHODIMP
TabChildCreatedObserver::Observe(nsISupports* aSubject,
const char* aTopic,
const char16_t* aData)
{
MOZ_ASSERT(strcmp(aTopic, "tab-child-created") == 0);
nsCOMPtr<nsITabChild> tabChild(do_QueryInterface(aSubject));
NS_ENSURE_TRUE(tabChild, NS_ERROR_FAILURE);
dom::TabChild* browser = static_cast<dom::TabChild*>(tabChild.get());
if (browser->GetTabId() == mTabId) {
mAPZChild->SetBrowser(browser);
}
return NS_OK;
}
APZChild*
APZChild::Create(const dom::TabId& aTabId)
{
RefPtr<dom::TabChild> browser = dom::TabChild::FindTabChild(aTabId);
nsAutoPtr<APZChild> apz(new APZChild);
if (browser) {
apz->SetBrowser(browser);
} else {
RefPtr<TabChildCreatedObserver> observer =
new TabChildCreatedObserver(apz, aTabId);
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (!os ||
NS_FAILED(os->AddObserver(observer, "tab-child-created", false))) {
return nullptr;
}
apz->SetObserver(observer);
}
return apz.forget();
}
APZChild::APZChild()
: mDestroyed(false)
{
MOZ_ASSERT(mController);
}
APZChild::~APZChild()
{
if (mController) {
mController->Destroy();
mController = nullptr;
if (mObserver) {
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
os->RemoveObserver(mObserver, "tab-child-created");
} else if (mBrowser) {
mBrowser->SetAPZChild(nullptr);
}
}
bool
APZChild::RecvRequestContentRepaint(const FrameMetrics& aFrameMetrics)
{
MOZ_ASSERT(mController->IsRepaintThread());
mController->RequestContentRepaint(aFrameMetrics);
return true;
return mBrowser->UpdateFrame(aFrameMetrics);
}
bool
@@ -46,66 +107,77 @@ APZChild::RecvHandleTap(const TapType& aType,
const uint64_t& aInputBlockId,
const bool& aCallTakeFocusForClickFromTap)
{
mController->HandleTap(aType, aPoint, aModifiers, aGuid,
aInputBlockId);
mBrowser->HandleTap(aType, aPoint - mBrowser->GetChromeDisplacement(), aModifiers, aGuid,
aInputBlockId, aCallTakeFocusForClickFromTap);
return true;
}
bool
APZChild::RecvUpdateOverscrollVelocity(const float& aX, const float& aY, const bool& aIsRootContent)
{
mController->UpdateOverscrollVelocity(aX, aY, aIsRootContent);
return true;
}
bool
APZChild::RecvUpdateOverscrollOffset(const float& aX, const float& aY, const bool& aIsRootContent)
{
mController->UpdateOverscrollOffset(aX, aY, aIsRootContent);
return true;
}
bool
APZChild::RecvSetScrollingRootContent(const bool& aIsRootContent)
{
mController->SetScrollingRootContent(aIsRootContent);
return true;
}
bool
APZChild::RecvNotifyMozMouseScrollEvent(const ViewID& aScrollId,
APZChild::RecvNotifyMozMouseScrollEvent(const uint64_t& aLayersId,
const ViewID& aScrollId,
const nsString& aEvent)
{
mController->NotifyMozMouseScrollEvent(aScrollId, aEvent);
if (mBrowser) {
mBrowser->RecvMouseScrollTestEvent(aLayersId, aScrollId, aEvent);
}
return true;
}
bool
APZChild::RecvNotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
APZChild::RecvNotifyAPZStateChange(const ViewID& aViewId,
const APZStateChange& aChange,
const int& aArg)
{
mController->NotifyAPZStateChange(aGuid, aChange, aArg);
return true;
return mBrowser->NotifyAPZStateChange(aViewId, aChange, aArg);
}
bool
APZChild::RecvNotifyFlushComplete()
{
MOZ_ASSERT(mController->IsRepaintThread());
mController->NotifyFlushComplete();
nsCOMPtr<nsIPresShell> shell;
if (nsCOMPtr<nsIDocument> doc = mBrowser->GetDocument()) {
shell = doc->GetShell();
}
APZCCallbackHelper::NotifyFlushComplete(shell.get());
return true;
}
bool
APZChild::RecvDestroy()
{
// mController->Destroy will be called in the destructor
mDestroyed = true;
if (mBrowser) {
mBrowser->SetAPZChild(nullptr);
mBrowser = nullptr;
}
PAPZChild::Send__delete__(this);
return true;
}
void
APZChild::SetObserver(nsIObserver* aObserver)
{
MOZ_ASSERT(!mBrowser);
mObserver = aObserver;
}
void
APZChild::SetBrowser(dom::TabChild* aBrowser)
{
MOZ_ASSERT(!mBrowser);
if (mObserver) {
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
os->RemoveObserver(mObserver, "tab-child-created");
mObserver = nullptr;
}
// We might get the tab-child-created notification after we receive a
// Destroy message from the parent. In that case we don't want to install
// ourselves with the browser.
if (!mDestroyed) {
mBrowser = aBrowser;
mBrowser->SetAPZChild(this);
}
}
} // namespace layers
} // namespace mozilla