Permalink
Browse files

Bug 750901 - Elm to mc migration work - metro related changes to Wind…

…ows widget src to support building metro winrt bits (nsWidgetFactory, nsWindowGfx, nsToolkit, WinUtils). Also landing nsIWinMetroUtils.idl. r=bbondy
  • Loading branch information...
1 parent be94b44 commit 0abe4a549e18c2e0664305737d71ec9964612da2 @jmathies jmathies committed Nov 2, 2012
View
@@ -141,6 +141,10 @@ XPIDLSRCS += nsIPrintSettingsWin.idl \
$(NULL)
endif
+ifdef MOZ_METRO
+XPIDLSRCS += nsIWinMetroUtils.idl
+endif
+
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
XPIDLSRCS += nsIMacDockSupport.idl \
nsIStandaloneNativeMenu.idl \
View
@@ -0,0 +1,122 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 "nsISupports.idl"
+
+/**
+ * Integration with the "Metro"/"Modern" UI environment in Windows 8.
+ *
+ * Note: browser/metro/base/content/browser-scripts.js contains a stub
+ * implementation of this interface for non-Windows systems, for testing and
+ * development purposes only.
+ */
+[scriptable, uuid(45656788-B111-4317-B054-FFE881A0737E)]
+interface nsIWinMetroUtils : nsISupports
+{
+ /* Fullscreen landscape orientation */
+ const long fullScreenLandscape = 0;
+ /* Larger snapped state */
+ const long filled = 1;
+ /* Smaller snapped state */
+ const long snapped = 2;
+ /* Fullscreen portrait orientation */
+ const long fullScreenPortrait = 3;
+
+ /* return constants for the handPreference property */
+ const long handPreferenceLeft = 0;
+ const long handPreferenceRight = 1;
+
+ /**
+ * Determines the current snapped state.
+ */
+ readonly attribute long snappedState;
+
+ /**
+ * Determine if the current browser is running in the metro immersive
+ * environment.
+ */
+ readonly attribute boolean immersive;
+
+ /**
+ * Determine if the user prefers left handed or right handed input.
+ */
+ readonly attribute long handPreference;
+
+ /**
+ * Attempts to unsnap the application from snapped state to filled state
+ */
+ void unsnap();
+
+ /**
+ * Launches the specified application with the specified arguments and
+ * switches to Desktop mode if in metro mode.
+ */
+ void launchInDesktop(in AString aPath, in AString aArguments);
+
+ /**
+ * Secondary tiles are a Windows 8 specific feature for pinning new tiles
+ * to the start screen. Tiles can later be activated whether the browser is
+ * already opened or not.
+ */
+
+ /**
+ * Pins a new tile to the Windows 8 start screen.
+ *
+ * @param aTileID An ID which can later be used to remove the tile
+ * @param aShortName A short name for the tile
+ * @param aDiplayName The name that will be displayed on the tile
+ * @param aActivationArgs The arguments to pass to the browser upon
+ * activation of the tile
+ * @param aTileImage An image for the normal tile view
+ * @param aSmallTileImage An image for the small tile view
+ */
+ void pinTileAsync(in AString aTileID,
+ in AString aShortName,
+ in AString aDisplayName,
+ in AString aActivationArgs,
+ in AString aTileImage,
+ in AString aSmallTileImage);
+
+ /**
+ * Unpins a tile from the Windows 8 start screen.
+ *
+ * @param aTileID An existing ID which was previously pinned
+ */
+ void unpinTileAsync(in AString aTileID);
+
+ /**
+ * Determines if a tile is pinned to the Windows 8 start screen.
+ *
+ * @param aTileID An ID which may have been pinned with pinTileAsync
+ * @return true if the tile is pinned
+ */
+ bool isTilePinned(in AString aTileID);
+
+ /**
+ * Soft keyboard attributes. Used in unison with shown/hidden observer
+ * events sent via FrameworkView.
+ *
+ * keyboardVisible - returns true if the soft keyboard is currently
+ * displayed, false otherwise.
+ * keyboardX, keyboardY, keyboardWidth, keyboardHeight - occlude rect
+ * of the keyboard when displayed in device independent pixels.
+ */
+ readonly attribute boolean keyboardVisible;
+ readonly attribute unsigned long keyboardX;
+ readonly attribute unsigned long keyboardY;
+ readonly attribute unsigned long keyboardWidth;
+ readonly attribute unsigned long keyboardHeight;
+
+ /**
+ * Settings panel links. addSettingsPanelEntry adds an entry to
+ * the settings flyout panel that the user can invoke.
+ *
+ * @param aChromePanelId panel id invoked via nsIBrowserDOMWindow's
+ * ShowPanel api. Example: 'prefs-container'
+ * @param aLabel Localized string label displayed in the settings
+ * flyout panel for this option.
+ */
+ void addSettingsPanelEntry(in AString aChromePanelId, in AString aLabel);
+};
View
@@ -113,6 +113,10 @@
#define NS_WIN_JUMPLISTBUILDER_CID \
{ 0x73a5946f, 0x608d, 0x454f, { 0x9d, 0x33, 0xb, 0x8f, 0x8c, 0x72, 0x94, 0xb6 } }
+// {DE95B8C9-F0E8-4AD5-95A2-06C12F53EC2E}
+#define NS_WIN_METROUTILS_CID \
+{ 0xde95b8c9, 0xf0e8, 0x4ad5, { 0x95, 0xa2, 0x06, 0xc1, 0x2f, 0x53, 0xec, 0x2e }}
+
// {2B9A1F2C-27CE-45b6-8D4E-755D0E34F8DB}
#define NS_WIN_JUMPLISTITEM_CID \
{ 0x2b9a1f2c, 0x27ce, 0x45b6, { 0x8d, 0x4e, 0x75, 0x5d, 0x0e, 0x34, 0xf8, 0xdb } }
@@ -4,6 +4,9 @@
* 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 "nsAutoPtr.h"
+#include "nsString.h"
+
namespace mozilla {
namespace widget {
@@ -18,6 +18,10 @@ RESFILE = widget.res
MODULE_NAME = nsWidgetWinModule
LIBXUL_LIBRARY = 1
+ifdef MOZ_METRO
+DIRS = winrt
+endif
+
CPPSRCS = \
nsWindow.cpp \
nsWindowGfx.cpp \
@@ -240,6 +240,11 @@ WinTaskbar::~WinTaskbar() {
// static
bool
WinTaskbar::GetAppUserModelID(nsAString & aDefaultGroupId) {
+ // For win8 metro builds, we can't set this. The value is static
+ // for the app.
+ if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
+ return false;
+ }
// If marked as such in prefs, use a hash of the profile path for the id
// instead of the install path hash setup by the installer.
bool useProfile =
@@ -900,5 +900,44 @@ WinUtils::GetShellItemPath(IShellItem* aItem,
return !aResultString.IsEmpty();
}
+/* static */
+nsIntRegion
+WinUtils::ConvertHRGNToRegion(HRGN aRgn)
+{
+ NS_ASSERTION(aRgn, "Don't pass NULL region here");
+
+ nsIntRegion rgn;
+
+ DWORD size = ::GetRegionData(aRgn, 0, NULL);
+ nsAutoTArray<PRUint8,100> buffer;
+ if (!buffer.SetLength(size))
+ return rgn;
+
+ RGNDATA* data = reinterpret_cast<RGNDATA*>(buffer.Elements());
+ if (!::GetRegionData(aRgn, size, data))
+ return rgn;
+
+ if (data->rdh.nCount > MAX_RECTS_IN_REGION) {
+ rgn = ToIntRect(data->rdh.rcBound);
+ return rgn;
+ }
+
+ RECT* rects = reinterpret_cast<RECT*>(data->Buffer);
+ for (PRUint32 i = 0; i < data->rdh.nCount; ++i) {
+ RECT* r = rects + i;
+ rgn.Or(rgn, ToIntRect(*r));
+ }
+
+ return rgn;
+}
+
+nsIntRect
+WinUtils::ToIntRect(const RECT& aRect)
+{
+ return nsIntRect(aRect.left, aRect.top,
+ aRect.right - aRect.left,
+ aRect.bottom - aRect.top);
+}
+
} // namespace widget
} // namespace mozilla
View
@@ -11,6 +11,8 @@
#include <shobjidl.h>
#include "nsAutoPtr.h"
#include "nsString.h"
+#include "nsRegion.h"
+#include "nsRect.h"
#include "nsThreadUtils.h"
#include "nsICryptoHash.h"
@@ -202,6 +204,22 @@ class WinUtils {
static bool GetShellItemPath(IShellItem* aItem,
nsString& aResultString);
+ /**
+ * ConvertHRGNToRegion converts a Windows HRGN to an nsIntRegion.
+ *
+ * aRgn the HRGN to convert.
+ * returns the nsIntRegion.
+ */
+ static nsIntRegion ConvertHRGNToRegion(HRGN aRgn);
+
+ /**
+ * ToIntRect converts a Windows RECT to a nsIntRect.
+ *
+ * aRect the RECT to convert.
+ * returns the nsIntRect.
+ */
+ static nsIntRect ToIntRect(const RECT& aRect);
+
private:
typedef HRESULT (WINAPI * SHCreateItemFromParsingNamePtr)(PCWSTR pszPath,
IBindCtx *pbc,
@@ -22,12 +22,9 @@
const PRUnichar* kAppShellEventId = L"nsAppShell:EventID";
const PRUnichar* kTaskbarButtonEventId = L"TaskbarButtonCreated";
-// The maximum time we allow before forcing a native event callback
-#define NATIVE_EVENT_STARVATION_LIMIT mozilla::TimeDuration::FromSeconds(1)
-
static UINT sMsgId;
-static UINT sTaskbarButtonCreatedMsg;
+UINT sTaskbarButtonCreatedMsg;
/* static */
UINT nsAppShell::GetTaskbarButtonCreatedMessage() {
@@ -241,6 +238,12 @@ nsAppShell::Run(void)
#endif
+NS_IMETHODIMP
+nsAppShell::Exit(void)
+{
+ return nsBaseAppShell::Exit();
+}
+
void
nsAppShell::DoProcessMoreGeckoEvents()
{
@@ -10,6 +10,9 @@
#include <windows.h>
#include "mozilla/TimeStamp.h"
+// The maximum time we allow before forcing a native event callback
+#define NATIVE_EVENT_STARVATION_LIMIT mozilla::TimeDuration::FromSeconds(1)
+
/**
* Native Win32 Application shell wrapper
*/
@@ -31,6 +34,7 @@ class nsAppShell : public nsBaseAppShell
#if defined(_MSC_VER) && defined(_M_IX86)
NS_IMETHOD Run();
#endif
+ NS_IMETHOD Exit();
virtual void ScheduleNativeEventCallback();
virtual bool ProcessNextNativeEvent(bool mayWait);
virtual ~nsAppShell();
@@ -272,8 +272,10 @@ nsresult nsClipboard::GetGlobalData(HGLOBAL aHGBL, void ** aData, uint32_t * aLe
result = NS_OK;
}
- }
- else {
+ } else {
+#ifdef MOZ_METRO
+ return result;
+#endif
// We really shouldn't ever get here
// but just in case
*aData = nullptr;
@@ -301,12 +303,12 @@ nsresult nsClipboard::GetGlobalData(HGLOBAL aHGBL, void ** aData, uint32_t * aLe
}
//-------------------------------------------------------------------------
-nsresult nsClipboard::GetNativeDataOffClipboard(nsIWidget * aWindow, UINT /*aIndex*/, UINT aFormat, void ** aData, uint32_t * aLen)
+nsresult nsClipboard::GetNativeDataOffClipboard(nsIWidget * aWidget, UINT /*aIndex*/, UINT aFormat, void ** aData, uint32_t * aLen)
{
HGLOBAL hglb;
nsresult result = NS_ERROR_FAILURE;
- HWND nativeWin = nullptr;//(HWND)aWindow->GetNativeData(NS_NATIVE_WINDOW);
+ HWND nativeWin = (HWND)aWidget->GetNativeData(NS_NATIVE_WINDOW);
if (::OpenClipboard(nativeWin)) {
hglb = ::GetClipboardData(aFormat);
result = GetGlobalData(hglb, aData, aLen);
@@ -6,7 +6,6 @@
#include "nsLookAndFeel.h"
#include <windows.h>
#include <shellapi.h>
-#include "nsWindow.h"
#include "nsStyleConsts.h"
#include "nsUXThemeData.h"
#include "nsUXThemeConstants.h"
@@ -104,6 +104,3 @@ class nsNativeThemeWin : private nsNativeTheme,
bool IsMenuActive(nsIFrame* aFrame, uint8_t aWidgetType);
};
-
-// Creator function
-extern NS_METHOD NS_NewNativeThemeWin(nsISupports *aOuter, REFNSIID aIID, void **aResult);
@@ -27,7 +27,9 @@ static const unsigned long kD3DUsageDelay = 5000;
static void
StartAllowingD3D9(nsITimer *aTimer, void *aClosure)
{
- nsWindow::StartAllowingD3D9(true);
+ if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
+ nsWindow::StartAllowingD3D9(true);
+ }
}
MouseTrailer* nsToolkit::gMouseTrailer;
@@ -47,11 +49,13 @@ nsToolkit::nsToolkit()
gMouseTrailer = &mMouseTrailer;
- mD3D9Timer = do_CreateInstance("@mozilla.org/timer;1");
- mD3D9Timer->InitWithFuncCallback(::StartAllowingD3D9,
- NULL,
- kD3DUsageDelay,
- nsITimer::TYPE_ONE_SHOT);
+ if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
+ mD3D9Timer = do_CreateInstance("@mozilla.org/timer;1");
+ mD3D9Timer->InitWithFuncCallback(::StartAllowingD3D9,
+ NULL,
+ kD3DUsageDelay,
+ nsITimer::TYPE_ONE_SHOT);
+ }
}
@@ -83,8 +87,10 @@ nsToolkit::Shutdown()
void
nsToolkit::StartAllowingD3D9()
{
- nsToolkit::GetToolkit()->mD3D9Timer->Cancel();
- nsWindow::StartAllowingD3D9(false);
+ if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
+ nsToolkit::GetToolkit()->mD3D9Timer->Cancel();
+ nsWindow::StartAllowingD3D9(false);
+ }
}
//-------------------------------------------------------------------------
Oops, something went wrong.

0 comments on commit 0abe4a5

Please sign in to comment.