2014-12-19 04:36:20 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-07-14 21:22:26 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2015-07-31 10:25:14 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2014-07-14 21:22:26 +04:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
|
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "ScreenManagerParent.h"
|
2015-02-03 11:03:28 +03:00
|
|
|
#include "ContentProcessManager.h"
|
2014-07-14 21:22:26 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
static const char *sScreenManagerContractID = "@mozilla.org/gfx/screenmanager;1";
|
|
|
|
|
|
|
|
ScreenManagerParent::ScreenManagerParent(uint32_t* aNumberOfScreens,
|
|
|
|
float* aSystemDefaultScale,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
mScreenMgr = do_GetService(sScreenManagerContractID);
|
|
|
|
if (!mScreenMgr) {
|
|
|
|
MOZ_CRASH("Couldn't get nsIScreenManager from ScreenManagerParent.");
|
|
|
|
}
|
|
|
|
|
2014-10-08 08:32:45 +04:00
|
|
|
unused << RecvRefresh(aNumberOfScreens, aSystemDefaultScale, aSuccess);
|
2014-07-14 21:22:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-10-08 08:32:45 +04:00
|
|
|
ScreenManagerParent::RecvRefresh(uint32_t* aNumberOfScreens,
|
|
|
|
float* aSystemDefaultScale,
|
|
|
|
bool* aSuccess)
|
2014-07-14 21:22:26 +04:00
|
|
|
{
|
|
|
|
*aSuccess = false;
|
|
|
|
|
|
|
|
nsresult rv = mScreenMgr->GetNumberOfScreens(aNumberOfScreens);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mScreenMgr->GetSystemDefaultScale(aSystemDefaultScale);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSuccess = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-10-08 08:32:45 +04:00
|
|
|
ScreenManagerParent::RecvScreenRefresh(const uint32_t& aId,
|
|
|
|
ScreenDetails* aRetVal,
|
|
|
|
bool* aSuccess)
|
2014-07-14 21:22:26 +04:00
|
|
|
{
|
|
|
|
*aSuccess = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
nsresult rv = mScreenMgr->ScreenForId(aId, getter_AddRefs(screen));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScreenDetails details;
|
|
|
|
unused << ExtractScreenDetails(screen, details);
|
|
|
|
|
|
|
|
*aRetVal = details;
|
|
|
|
*aSuccess = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-10-08 08:32:45 +04:00
|
|
|
ScreenManagerParent::RecvGetPrimaryScreen(ScreenDetails* aRetVal,
|
|
|
|
bool* aSuccess)
|
2014-07-14 21:22:26 +04:00
|
|
|
{
|
|
|
|
*aSuccess = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
nsresult rv = mScreenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
|
|
|
ScreenDetails details;
|
|
|
|
if (!ExtractScreenDetails(screen, details)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aRetVal = details;
|
|
|
|
*aSuccess = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-10-08 08:32:45 +04:00
|
|
|
ScreenManagerParent::RecvScreenForRect(const int32_t& aLeft,
|
|
|
|
const int32_t& aTop,
|
|
|
|
const int32_t& aWidth,
|
|
|
|
const int32_t& aHeight,
|
|
|
|
ScreenDetails* aRetVal,
|
|
|
|
bool* aSuccess)
|
2014-07-14 21:22:26 +04:00
|
|
|
{
|
|
|
|
*aSuccess = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
nsresult rv = mScreenMgr->ScreenForRect(aLeft, aTop, aWidth, aHeight, getter_AddRefs(screen));
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
|
|
|
ScreenDetails details;
|
|
|
|
if (!ExtractScreenDetails(screen, details)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aRetVal = details;
|
|
|
|
*aSuccess = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-02-03 11:03:28 +03:00
|
|
|
ScreenManagerParent::RecvScreenForBrowser(const TabId& aTabId,
|
2014-10-08 08:32:45 +04:00
|
|
|
ScreenDetails* aRetVal,
|
|
|
|
bool* aSuccess)
|
2014-07-14 21:22:26 +04:00
|
|
|
{
|
|
|
|
*aSuccess = false;
|
2014-11-18 11:29:12 +03:00
|
|
|
#ifdef MOZ_VALGRIND
|
|
|
|
// Zero this so that Valgrind doesn't complain when we send it to another
|
|
|
|
// process.
|
|
|
|
memset(aRetVal, 0, sizeof(ScreenDetails));
|
|
|
|
#endif
|
2014-07-14 21:22:26 +04:00
|
|
|
|
|
|
|
// Find the mWidget associated with the tabparent, and then return
|
|
|
|
// the nsIScreen it's on.
|
2015-02-03 11:03:28 +03:00
|
|
|
ContentParent* cp = static_cast<ContentParent*>(this->Manager());
|
|
|
|
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TabParent> tabParent =
|
2015-02-03 11:03:28 +03:00
|
|
|
cpm->GetTopLevelTabParentByProcessAndTabId(cp->ChildID(), aTabId);
|
|
|
|
if(!tabParent){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-14 21:22:26 +04:00
|
|
|
nsCOMPtr<nsIWidget> widget = tabParent->GetWidget();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
2014-12-19 04:36:20 +03:00
|
|
|
if (widget) {
|
|
|
|
if (widget->GetNativeData(NS_NATIVE_WINDOW)) {
|
|
|
|
mScreenMgr->ScreenForNativeWidget(widget->GetNativeData(NS_NATIVE_WINDOW),
|
|
|
|
getter_AddRefs(screen));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsresult rv = mScreenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-14 21:22:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(screen, true);
|
|
|
|
|
|
|
|
ScreenDetails details;
|
|
|
|
if (!ExtractScreenDetails(screen, details)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aRetVal = details;
|
|
|
|
*aSuccess = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ScreenManagerParent::ExtractScreenDetails(nsIScreen* aScreen, ScreenDetails &aDetails)
|
|
|
|
{
|
2015-08-27 01:33:16 +03:00
|
|
|
if (!aScreen) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-14 21:22:26 +04:00
|
|
|
uint32_t id;
|
|
|
|
nsresult rv = aScreen->GetId(&id);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
aDetails.id() = id;
|
|
|
|
|
|
|
|
nsIntRect rect;
|
|
|
|
rv = aScreen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
aDetails.rect() = rect;
|
|
|
|
|
2014-10-01 05:28:28 +04:00
|
|
|
nsIntRect rectDisplayPix;
|
|
|
|
rv = aScreen->GetRectDisplayPix(&rectDisplayPix.x, &rectDisplayPix.y,
|
|
|
|
&rectDisplayPix.width, &rectDisplayPix.height);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
aDetails.rectDisplayPix() = rectDisplayPix;
|
|
|
|
|
2014-07-14 21:22:26 +04:00
|
|
|
nsIntRect availRect;
|
|
|
|
rv = aScreen->GetAvailRect(&availRect.x, &availRect.y, &availRect.width,
|
|
|
|
&availRect.height);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
aDetails.availRect() = availRect;
|
|
|
|
|
2014-10-01 05:28:28 +04:00
|
|
|
nsIntRect availRectDisplayPix;
|
|
|
|
rv = aScreen->GetAvailRectDisplayPix(&availRectDisplayPix.x,
|
|
|
|
&availRectDisplayPix.y,
|
|
|
|
&availRectDisplayPix.width,
|
|
|
|
&availRectDisplayPix.height);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
aDetails.availRectDisplayPix() = availRectDisplayPix;
|
|
|
|
|
2014-07-14 21:22:26 +04:00
|
|
|
int32_t pixelDepth = 0;
|
|
|
|
rv = aScreen->GetPixelDepth(&pixelDepth);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
aDetails.pixelDepth() = pixelDepth;
|
|
|
|
|
|
|
|
int32_t colorDepth = 0;
|
|
|
|
rv = aScreen->GetColorDepth(&colorDepth);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
aDetails.colorDepth() = colorDepth;
|
|
|
|
|
|
|
|
double contentsScaleFactor = 1.0;
|
|
|
|
rv = aScreen->GetContentsScaleFactor(&contentsScaleFactor);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
aDetails.contentsScaleFactor() = contentsScaleFactor;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScreenManagerParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|