Skip to content

Commit

Permalink
[embedlite] Implement support for HTML5 Screen Orientation API.
Browse files Browse the repository at this point in the history
It's not enough to just transform the screen, we also need to make sure
we notify JS listeners about rotation change.
  • Loading branch information
tworaz committed Sep 29, 2015
1 parent 60d5378 commit b75956c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions embedding/embedlite/embedshared/EmbedLiteWindowBaseChild.cpp
Expand Up @@ -8,6 +8,12 @@
#include "EmbedLitePuppetWidget.h"
#include "EmbedLiteWindowBaseChild.h"
#include "mozilla/unused.h"
#include "Hal.h"
#include "ScreenOrientation.h"
#include "nsIScreen.h"
#include "nsIScreenManager.h"

using namespace mozilla::dom;

namespace mozilla {
namespace embedlite {
Expand Down Expand Up @@ -71,6 +77,45 @@ bool EmbedLiteWindowBaseChild::RecvSetContentOrientation(const mozilla::ScreenRo
widget->SetRotation(aRotation);
widget->UpdateSize();
}

nsresult rv;
nsCOMPtr<nsIScreenManager> screenMgr =
do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
if (NS_FAILED(rv)) {
NS_ERROR("Can't find nsIScreenManager!");
return true;
}

nsIntRect rect;
int32_t colorDepth, pixelDepth;
nsCOMPtr<nsIScreen> screen;

screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height);
screen->GetColorDepth(&colorDepth);
screen->GetPixelDepth(&pixelDepth);

ScreenOrientation orientation = eScreenOrientation_Default;
switch (aRotation) {
case ROTATION_0:
orientation = eScreenOrientation_PortraitPrimary;
break;
case ROTATION_90:
orientation = eScreenOrientation_LandscapePrimary;
break;
case ROTATION_180:
orientation = eScreenOrientation_PortraitSecondary;
break;
case ROTATION_270:
orientation = eScreenOrientation_LandscapeSecondary;
break;
default:
break;
}

hal::NotifyScreenConfigurationChange(hal::ScreenConfiguration(
rect, orientation, colorDepth, pixelDepth));

return true;
}

Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/moz.build
Expand Up @@ -95,6 +95,7 @@ LOCAL_INCLUDES += [
'/dom/ipc',
'/gfx/layers',
'/gfx/layers/apz/util',
'/hal',
'/js/xpconnect/src',
'/widget',
'/xpcom/base',
Expand Down

0 comments on commit b75956c

Please sign in to comment.