2016-01-08 22:17:39 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
|
|
|
/* 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 "mozilla/layers/APZChild.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/TabChild.h"
|
|
|
|
#include "mozilla/layers/APZCCallbackHelper.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2016-08-25 00:15:35 +03:00
|
|
|
/**
|
|
|
|
* 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
|
2016-04-19 00:25:25 +03:00
|
|
|
{
|
2016-08-25 00:15:35 +03:00
|
|
|
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)
|
2016-01-08 22:17:39 +03:00
|
|
|
{
|
2016-08-25 00:15:35 +03:00
|
|
|
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);
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
2016-08-25 00:15:35 +03:00
|
|
|
return NS_OK;
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
|
2016-08-25 00:15:35 +03:00
|
|
|
APZChild*
|
|
|
|
APZChild::Create(const dom::TabId& aTabId)
|
2016-01-08 22:17:39 +03:00
|
|
|
{
|
2016-08-25 00:15:35 +03:00
|
|
|
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);
|
|
|
|
}
|
2016-08-11 02:51:45 +03:00
|
|
|
|
2016-08-25 00:15:35 +03:00
|
|
|
return apz.forget();
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
|
2016-08-25 00:15:35 +03:00
|
|
|
APZChild::APZChild()
|
|
|
|
: mDestroyed(false)
|
2016-01-08 22:17:39 +03:00
|
|
|
{
|
2016-08-11 02:51:45 +03:00
|
|
|
}
|
|
|
|
|
2016-08-25 00:15:35 +03:00
|
|
|
APZChild::~APZChild()
|
2016-08-11 02:51:45 +03:00
|
|
|
{
|
2016-08-25 00:15:35 +03:00
|
|
|
if (mObserver) {
|
|
|
|
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
|
|
|
os->RemoveObserver(mObserver, "tab-child-created");
|
|
|
|
} else if (mBrowser) {
|
|
|
|
mBrowser->SetAPZChild(nullptr);
|
|
|
|
}
|
2016-08-11 02:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-31 22:39:00 +03:00
|
|
|
APZChild::RecvRequestContentRepaint(const FrameMetrics& aFrameMetrics)
|
2016-08-11 02:51:45 +03:00
|
|
|
{
|
2016-08-25 00:15:35 +03:00
|
|
|
return mBrowser->UpdateFrame(aFrameMetrics);
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
|
2016-08-02 09:59:00 +03:00
|
|
|
bool
|
2016-08-25 00:15:35 +03:00
|
|
|
APZChild::RecvHandleTap(const TapType& aType,
|
|
|
|
const LayoutDevicePoint& aPoint,
|
|
|
|
const Modifiers& aModifiers,
|
|
|
|
const ScrollableLayerGuid& aGuid,
|
|
|
|
const uint64_t& aInputBlockId,
|
|
|
|
const bool& aCallTakeFocusForClickFromTap)
|
2016-08-11 02:51:45 +03:00
|
|
|
{
|
2016-08-25 00:15:44 +03:00
|
|
|
mBrowser->HandleTap(aType, aPoint, aModifiers, aGuid,
|
2016-08-25 00:15:35 +03:00
|
|
|
aInputBlockId, aCallTakeFocusForClickFromTap);
|
2016-08-11 02:51:45 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-08 22:17:39 +03:00
|
|
|
bool
|
2016-08-25 00:15:35 +03:00
|
|
|
APZChild::RecvNotifyAPZStateChange(const ViewID& aViewId,
|
2016-01-08 22:17:39 +03:00
|
|
|
const APZStateChange& aChange,
|
|
|
|
const int& aArg)
|
|
|
|
{
|
2016-08-25 00:15:35 +03:00
|
|
|
return mBrowser->NotifyAPZStateChange(aViewId, aChange, aArg);
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
APZChild::RecvNotifyFlushComplete()
|
|
|
|
{
|
2016-08-25 00:15:35 +03:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
if (nsCOMPtr<nsIDocument> doc = mBrowser->GetDocument()) {
|
|
|
|
shell = doc->GetShell();
|
|
|
|
}
|
|
|
|
APZCCallbackHelper::NotifyFlushComplete(shell.get());
|
2016-01-08 22:17:39 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-19 00:25:25 +03:00
|
|
|
bool
|
|
|
|
APZChild::RecvDestroy()
|
|
|
|
{
|
2016-08-25 00:15:35 +03:00
|
|
|
mDestroyed = true;
|
|
|
|
if (mBrowser) {
|
|
|
|
mBrowser->SetAPZChild(nullptr);
|
|
|
|
mBrowser = nullptr;
|
|
|
|
}
|
2016-08-25 00:15:44 +03:00
|
|
|
PAPZChild::Send__delete__(this);
|
2016-04-19 00:25:25 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-25 00:15:35 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2016-01-08 22:17:39 +03:00
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|