Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Bug 750901 - Elm to mc migration work - metro related changes to Wind…
Browse files Browse the repository at this point in the history
…ows widget src to support building metro winrt bits (nsWidgetFactory, nsWindowGfx, nsToolkit, WinUtils). Also landing nsIWinMetroUtils.idl. r=bbondy
  • Loading branch information
jmathies committed Nov 2, 2012
1 parent be94b44 commit 0abe4a5
Show file tree
Hide file tree
Showing 19 changed files with 367 additions and 91 deletions.
4 changes: 4 additions & 0 deletions widget/Makefile.in
Expand Up @@ -141,6 +141,10 @@ XPIDLSRCS += nsIPrintSettingsWin.idl \
$(NULL) $(NULL)
endif endif


ifdef MOZ_METRO
XPIDLSRCS += nsIWinMetroUtils.idl
endif

ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa) ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
XPIDLSRCS += nsIMacDockSupport.idl \ XPIDLSRCS += nsIMacDockSupport.idl \
nsIStandaloneNativeMenu.idl \ nsIStandaloneNativeMenu.idl \
Expand Down
122 changes: 122 additions & 0 deletions widget/nsIWinMetroUtils.idl
@@ -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);
};
4 changes: 4 additions & 0 deletions widget/nsWidgetsCID.h
Expand Up @@ -113,6 +113,10 @@
#define NS_WIN_JUMPLISTBUILDER_CID \ #define NS_WIN_JUMPLISTBUILDER_CID \
{ 0x73a5946f, 0x608d, 0x454f, { 0x9d, 0x33, 0xb, 0x8f, 0x8c, 0x72, 0x94, 0xb6 } } { 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} // {2B9A1F2C-27CE-45b6-8D4E-755D0E34F8DB}
#define NS_WIN_JUMPLISTITEM_CID \ #define NS_WIN_JUMPLISTITEM_CID \
{ 0x2b9a1f2c, 0x27ce, 0x45b6, { 0x8d, 0x4e, 0x75, 0x5d, 0x0e, 0x34, 0xf8, 0xdb } } { 0x2b9a1f2c, 0x27ce, 0x45b6, { 0x8d, 0x4e, 0x75, 0x5d, 0x0e, 0x34, 0xf8, 0xdb } }
Expand Down
3 changes: 3 additions & 0 deletions widget/windows/AudioSession.h
Expand Up @@ -4,6 +4,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "nsAutoPtr.h"
#include "nsString.h"

namespace mozilla { namespace mozilla {
namespace widget { namespace widget {


Expand Down
4 changes: 4 additions & 0 deletions widget/windows/Makefile.in
Expand Up @@ -18,6 +18,10 @@ RESFILE = widget.res
MODULE_NAME = nsWidgetWinModule MODULE_NAME = nsWidgetWinModule
LIBXUL_LIBRARY = 1 LIBXUL_LIBRARY = 1


ifdef MOZ_METRO
DIRS = winrt
endif

CPPSRCS = \ CPPSRCS = \
nsWindow.cpp \ nsWindow.cpp \
nsWindowGfx.cpp \ nsWindowGfx.cpp \
Expand Down
5 changes: 5 additions & 0 deletions widget/windows/WinTaskbar.cpp
Expand Up @@ -240,6 +240,11 @@ WinTaskbar::~WinTaskbar() {
// static // static
bool bool
WinTaskbar::GetAppUserModelID(nsAString & aDefaultGroupId) { 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 // 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. // instead of the install path hash setup by the installer.
bool useProfile = bool useProfile =
Expand Down
39 changes: 39 additions & 0 deletions widget/windows/WinUtils.cpp
Expand Up @@ -900,5 +900,44 @@ WinUtils::GetShellItemPath(IShellItem* aItem,
return !aResultString.IsEmpty(); 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 widget
} // namespace mozilla } // namespace mozilla
18 changes: 18 additions & 0 deletions widget/windows/WinUtils.h
Expand Up @@ -11,6 +11,8 @@
#include <shobjidl.h> #include <shobjidl.h>
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsString.h" #include "nsString.h"
#include "nsRegion.h"
#include "nsRect.h"


#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsICryptoHash.h" #include "nsICryptoHash.h"
Expand Down Expand Up @@ -202,6 +204,22 @@ class WinUtils {
static bool GetShellItemPath(IShellItem* aItem, static bool GetShellItemPath(IShellItem* aItem,
nsString& aResultString); 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: private:
typedef HRESULT (WINAPI * SHCreateItemFromParsingNamePtr)(PCWSTR pszPath, typedef HRESULT (WINAPI * SHCreateItemFromParsingNamePtr)(PCWSTR pszPath,
IBindCtx *pbc, IBindCtx *pbc,
Expand Down
11 changes: 7 additions & 4 deletions widget/windows/nsAppShell.cpp
Expand Up @@ -22,12 +22,9 @@
const PRUnichar* kAppShellEventId = L"nsAppShell:EventID"; const PRUnichar* kAppShellEventId = L"nsAppShell:EventID";
const PRUnichar* kTaskbarButtonEventId = L"TaskbarButtonCreated"; 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 sMsgId;


static UINT sTaskbarButtonCreatedMsg; UINT sTaskbarButtonCreatedMsg;


/* static */ /* static */
UINT nsAppShell::GetTaskbarButtonCreatedMessage() { UINT nsAppShell::GetTaskbarButtonCreatedMessage() {
Expand Down Expand Up @@ -241,6 +238,12 @@ nsAppShell::Run(void)


#endif #endif


NS_IMETHODIMP
nsAppShell::Exit(void)
{
return nsBaseAppShell::Exit();
}

void void
nsAppShell::DoProcessMoreGeckoEvents() nsAppShell::DoProcessMoreGeckoEvents()
{ {
Expand Down
4 changes: 4 additions & 0 deletions widget/windows/nsAppShell.h
Expand Up @@ -10,6 +10,9 @@
#include <windows.h> #include <windows.h>
#include "mozilla/TimeStamp.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 * Native Win32 Application shell wrapper
*/ */
Expand All @@ -31,6 +34,7 @@ class nsAppShell : public nsBaseAppShell
#if defined(_MSC_VER) && defined(_M_IX86) #if defined(_MSC_VER) && defined(_M_IX86)
NS_IMETHOD Run(); NS_IMETHOD Run();
#endif #endif
NS_IMETHOD Exit();
virtual void ScheduleNativeEventCallback(); virtual void ScheduleNativeEventCallback();
virtual bool ProcessNextNativeEvent(bool mayWait); virtual bool ProcessNextNativeEvent(bool mayWait);
virtual ~nsAppShell(); virtual ~nsAppShell();
Expand Down
10 changes: 6 additions & 4 deletions widget/windows/nsClipboard.cpp
Expand Up @@ -272,8 +272,10 @@ nsresult nsClipboard::GetGlobalData(HGLOBAL aHGBL, void ** aData, uint32_t * aLe


result = NS_OK; result = NS_OK;
} }
} } else {
else { #ifdef MOZ_METRO
return result;
#endif
// We really shouldn't ever get here // We really shouldn't ever get here
// but just in case // but just in case
*aData = nullptr; *aData = nullptr;
Expand Down Expand Up @@ -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; HGLOBAL hglb;
nsresult result = NS_ERROR_FAILURE; 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)) { if (::OpenClipboard(nativeWin)) {
hglb = ::GetClipboardData(aFormat); hglb = ::GetClipboardData(aFormat);
result = GetGlobalData(hglb, aData, aLen); result = GetGlobalData(hglb, aData, aLen);
Expand Down
1 change: 0 additions & 1 deletion widget/windows/nsLookAndFeel.cpp
Expand Up @@ -6,7 +6,6 @@
#include "nsLookAndFeel.h" #include "nsLookAndFeel.h"
#include <windows.h> #include <windows.h>
#include <shellapi.h> #include <shellapi.h>
#include "nsWindow.h"
#include "nsStyleConsts.h" #include "nsStyleConsts.h"
#include "nsUXThemeData.h" #include "nsUXThemeData.h"
#include "nsUXThemeConstants.h" #include "nsUXThemeConstants.h"
Expand Down
3 changes: 0 additions & 3 deletions widget/windows/nsNativeThemeWin.h
Expand Up @@ -104,6 +104,3 @@ class nsNativeThemeWin : private nsNativeTheme,


bool IsMenuActive(nsIFrame* aFrame, uint8_t aWidgetType); bool IsMenuActive(nsIFrame* aFrame, uint8_t aWidgetType);
}; };

// Creator function
extern NS_METHOD NS_NewNativeThemeWin(nsISupports *aOuter, REFNSIID aIID, void **aResult);
22 changes: 14 additions & 8 deletions widget/windows/nsToolkit.cpp
Expand Up @@ -27,7 +27,9 @@ static const unsigned long kD3DUsageDelay = 5000;
static void static void
StartAllowingD3D9(nsITimer *aTimer, void *aClosure) StartAllowingD3D9(nsITimer *aTimer, void *aClosure)
{ {
nsWindow::StartAllowingD3D9(true); if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
nsWindow::StartAllowingD3D9(true);
}
} }


MouseTrailer* nsToolkit::gMouseTrailer; MouseTrailer* nsToolkit::gMouseTrailer;
Expand All @@ -47,11 +49,13 @@ nsToolkit::nsToolkit()


gMouseTrailer = &mMouseTrailer; gMouseTrailer = &mMouseTrailer;


mD3D9Timer = do_CreateInstance("@mozilla.org/timer;1"); if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
mD3D9Timer->InitWithFuncCallback(::StartAllowingD3D9, mD3D9Timer = do_CreateInstance("@mozilla.org/timer;1");
NULL, mD3D9Timer->InitWithFuncCallback(::StartAllowingD3D9,
kD3DUsageDelay, NULL,
nsITimer::TYPE_ONE_SHOT); kD3DUsageDelay,
nsITimer::TYPE_ONE_SHOT);
}
} }




Expand Down Expand Up @@ -83,8 +87,10 @@ nsToolkit::Shutdown()
void void
nsToolkit::StartAllowingD3D9() nsToolkit::StartAllowingD3D9()
{ {
nsToolkit::GetToolkit()->mD3D9Timer->Cancel(); if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
nsWindow::StartAllowingD3D9(false); nsToolkit::GetToolkit()->mD3D9Timer->Cancel();
nsWindow::StartAllowingD3D9(false);
}
} }


//------------------------------------------------------------------------- //-------------------------------------------------------------------------
Expand Down

0 comments on commit 0abe4a5

Please sign in to comment.