From 1af6ce1ff77e09e2c2a9920b5b09b206ae9d3d3c Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Fri, 2 Nov 2012 06:54:44 -0500 Subject: [PATCH] Bug 750901 - Elm to mc migration work - metro related changes to Windows widget src to support building metro winrt bits (nsWidgetFactory, nsWindowGfx, nsToolkit, WinUtils). Also landing nsIWinMetroUtils.idl. r=bbondy --- widget/Makefile.in | 4 + widget/nsIWinMetroUtils.idl | 122 +++++++++++++++++++++ widget/nsWidgetsCID.h | 4 + widget/windows/AudioSession.h | 3 + widget/windows/Makefile.in | 4 + widget/windows/WinTaskbar.cpp | 5 + widget/windows/WinUtils.cpp | 39 +++++++ widget/windows/WinUtils.h | 18 ++++ widget/windows/nsAppShell.cpp | 11 +- widget/windows/nsAppShell.h | 4 + widget/windows/nsClipboard.cpp | 10 +- widget/windows/nsLookAndFeel.cpp | 1 - widget/windows/nsNativeThemeWin.h | 3 - widget/windows/nsToolkit.cpp | 22 ++-- widget/windows/nsWidgetFactory.cpp | 142 +++++++++++++++++++------ widget/windows/nsWindow.cpp | 2 +- widget/windows/nsWindowGfx.cpp | 36 +------ widget/windows/nsWindowGfx.h | 8 -- widget/xpwidgets/nsAppShellSingleton.h | 26 ++++- 19 files changed, 370 insertions(+), 94 deletions(-) create mode 100644 widget/nsIWinMetroUtils.idl diff --git a/widget/Makefile.in b/widget/Makefile.in index ec3baa494c60..199f42fc443b 100644 --- a/widget/Makefile.in +++ b/widget/Makefile.in @@ -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 \ diff --git a/widget/nsIWinMetroUtils.idl b/widget/nsIWinMetroUtils.idl new file mode 100644 index 000000000000..7b81e5dafbb6 --- /dev/null +++ b/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); +}; diff --git a/widget/nsWidgetsCID.h b/widget/nsWidgetsCID.h index 961447f90873..dc814949960f 100644 --- a/widget/nsWidgetsCID.h +++ b/widget/nsWidgetsCID.h @@ -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 } } diff --git a/widget/windows/AudioSession.h b/widget/windows/AudioSession.h index aca49661e104..21296cbda06c 100644 --- a/widget/windows/AudioSession.h +++ b/widget/windows/AudioSession.h @@ -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 { diff --git a/widget/windows/Makefile.in b/widget/windows/Makefile.in index 3c7d051d7309..a6b2f216c38a 100644 --- a/widget/windows/Makefile.in +++ b/widget/windows/Makefile.in @@ -18,6 +18,10 @@ RESFILE = widget.res MODULE_NAME = nsWidgetWinModule LIBXUL_LIBRARY = 1 +ifdef MOZ_METRO +DIRS = winrt +endif + CPPSRCS = \ nsWindow.cpp \ nsWindowGfx.cpp \ diff --git a/widget/windows/WinTaskbar.cpp b/widget/windows/WinTaskbar.cpp index 07107f532c6e..c70b24239303 100644 --- a/widget/windows/WinTaskbar.cpp +++ b/widget/windows/WinTaskbar.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 = diff --git a/widget/windows/WinUtils.cpp b/widget/windows/WinUtils.cpp index 2428eb076086..99b80e735c57 100644 --- a/widget/windows/WinUtils.cpp +++ b/widget/windows/WinUtils.cpp @@ -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 buffer; + if (!buffer.SetLength(size)) + return rgn; + + RGNDATA* data = reinterpret_cast(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(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 diff --git a/widget/windows/WinUtils.h b/widget/windows/WinUtils.h index 7dac0bceadaa..e2f0dbdee49b 100644 --- a/widget/windows/WinUtils.h +++ b/widget/windows/WinUtils.h @@ -11,6 +11,8 @@ #include #include "nsAutoPtr.h" #include "nsString.h" +#include "nsRegion.h" +#include "nsRect.h" #include "nsThreadUtils.h" #include "nsICryptoHash.h" @@ -202,6 +204,22 @@ public: 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, diff --git a/widget/windows/nsAppShell.cpp b/widget/windows/nsAppShell.cpp index f12dc866f53d..de9d721bd14a 100644 --- a/widget/windows/nsAppShell.cpp +++ b/widget/windows/nsAppShell.cpp @@ -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() { diff --git a/widget/windows/nsAppShell.h b/widget/windows/nsAppShell.h index fc9b126eb521..feafe166b18e 100644 --- a/widget/windows/nsAppShell.h +++ b/widget/windows/nsAppShell.h @@ -10,6 +10,9 @@ #include #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 @@ protected: #if defined(_MSC_VER) && defined(_M_IX86) NS_IMETHOD Run(); #endif + NS_IMETHOD Exit(); virtual void ScheduleNativeEventCallback(); virtual bool ProcessNextNativeEvent(bool mayWait); virtual ~nsAppShell(); diff --git a/widget/windows/nsClipboard.cpp b/widget/windows/nsClipboard.cpp index 8f27a33f2c85..ff51ed904531 100644 --- a/widget/windows/nsClipboard.cpp +++ b/widget/windows/nsClipboard.cpp @@ -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); diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index a3210764884b..c1110f624058 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -6,7 +6,6 @@ #include "nsLookAndFeel.h" #include #include -#include "nsWindow.h" #include "nsStyleConsts.h" #include "nsUXThemeData.h" #include "nsUXThemeConstants.h" diff --git a/widget/windows/nsNativeThemeWin.h b/widget/windows/nsNativeThemeWin.h index f178e3e1c4e8..28edc72c9eb8 100644 --- a/widget/windows/nsNativeThemeWin.h +++ b/widget/windows/nsNativeThemeWin.h @@ -104,6 +104,3 @@ protected: bool IsMenuActive(nsIFrame* aFrame, uint8_t aWidgetType); }; - -// Creator function -extern NS_METHOD NS_NewNativeThemeWin(nsISupports *aOuter, REFNSIID aIID, void **aResult); diff --git a/widget/windows/nsToolkit.cpp b/widget/windows/nsToolkit.cpp index c5830556e23a..a66913084f66 100644 --- a/widget/windows/nsToolkit.cpp +++ b/widget/windows/nsToolkit.cpp @@ -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); + } } //------------------------------------------------------------------------- diff --git a/widget/windows/nsWidgetFactory.cpp b/widget/windows/nsWidgetFactory.cpp index 8c3906e5de37..6cb6c81a9a14 100644 --- a/widget/windows/nsWidgetFactory.cpp +++ b/widget/windows/nsWidgetFactory.cpp @@ -8,35 +8,46 @@ #include "nsISupports.h" #include "nsdefs.h" #include "nsWidgetsCID.h" - #include "nsAppShell.h" #include "nsAppShellSingleton.h" -#include "nsFilePicker.h" #include "mozilla/ModuleUtils.h" #include "nsIServiceManager.h" #include "nsIdleServiceWin.h" #include "nsLookAndFeel.h" -#include "nsNativeThemeWin.h" #include "nsScreenManagerWin.h" #include "nsSound.h" -#include "nsWindow.h" #include "WinMouseScrollHandler.h" -#include "WinTaskbar.h" -#include "JumpListBuilder.h" -#include "JumpListItem.h" #include "GfxInfo.h" #include "nsToolkit.h" +// Modules that switch out based on the environment +#include "nsXULAppAPI.h" +// Desktop +#include "nsFilePicker.h" // needs to be included before other shobjidl.h includes +#include "nsNativeThemeWin.h" +#include "nsWindow.h" +// Content processes +#include "nsFilePickerProxy.h" +// Metro +#ifdef MOZ_METRO +#include "winrt/MetroAppShell.h" +#include "winrt/MetroWidget.h" +#include "winrt/nsMetroFilePicker.h" +#include "winrt/nsWinMetroUtils.h" +#endif + // Drag & Drop, Clipboard - #include "nsClipboardHelper.h" - #include "nsClipboard.h" #include "nsBidiKeyboard.h" #include "nsDragService.h" #include "nsTransferable.h" #include "nsHTMLFormatConverter.h" +#include "WinTaskbar.h" +#include "JumpListBuilder.h" +#include "JumpListItem.h" + #ifdef NS_PRINTING #include "nsDeviceContextSpecWin.h" #include "nsPrintOptionsWin.h" @@ -45,21 +56,98 @@ using namespace mozilla::widget; -NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow) -NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker) +static nsresult +WindowConstructor(nsISupports *aOuter, REFNSIID aIID, + void **aResult) +{ + *aResult = nullptr; + if (aOuter != nullptr) { + return NS_ERROR_NO_AGGREGATION; + } + nsCOMPtr widget; + + if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { +#ifdef MOZ_METRO + widget = new MetroWidget; +#else + NS_RUNTIMEABORT("build does not support metro."); +#endif + } else { + widget = new nsWindow; + } + + return widget->QueryInterface(aIID, aResult); +} + +static nsresult +ChildWindowConstructor(nsISupports *aOuter, REFNSIID aIID, + void **aResult) +{ + *aResult = nullptr; + if (aOuter != nullptr) { + return NS_ERROR_NO_AGGREGATION; + } + nsCOMPtr widget; + + if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { + return NS_NOINTERFACE; + } else { + widget = new ChildWindow; + } + + return widget->QueryInterface(aIID, aResult); +} + +static nsresult +FilePickerConstructor(nsISupports *aOuter, REFNSIID aIID, + void **aResult) +{ + *aResult = nullptr; + if (aOuter != nullptr) { + return NS_ERROR_NO_AGGREGATION; + } + nsCOMPtr picker; + + if (XRE_GetProcessType() == GeckoProcessType_Content) { + picker = new nsFilePickerProxy(); + } else { + if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { +#ifdef MOZ_METRO + picker = new nsMetroFilePicker; +#else + NS_RUNTIMEABORT("build does not support metro."); +#endif + } else { + picker = new nsFilePicker; + } + } + return picker->QueryInterface(aIID, aResult); +} + NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerWin) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIdleServiceWin, nsIdleServiceWin::GetInstance) NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) - NS_GENERIC_FACTORY_CONSTRUCTOR(WinTaskbar) NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListBuilder) NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListItem) NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListSeparator) NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListLink) NS_GENERIC_FACTORY_CONSTRUCTOR(JumpListShortcut) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) +#ifdef MOZ_METRO +NS_GENERIC_FACTORY_CONSTRUCTOR(nsWinMetroUtils) +#endif +#ifdef NS_PRINTING +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsWin, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorWin) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecWin) +#endif namespace mozilla { namespace widget { @@ -68,18 +156,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxInfo, Init); } } -NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) - -#ifdef NS_PRINTING -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsWin, Init) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorWin) -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecWin) -#endif - NS_DEFINE_NAMED_CID(NS_WINDOW_CID); NS_DEFINE_NAMED_CID(NS_CHILD_CID); NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID); @@ -93,17 +169,17 @@ NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID); NS_DEFINE_NAMED_CID(NS_SOUND_CID); NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID); NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID); - NS_DEFINE_NAMED_CID(NS_WIN_TASKBAR_CID); NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTBUILDER_CID); NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTITEM_CID); NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTSEPARATOR_CID); NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTLINK_CID); NS_DEFINE_NAMED_CID(NS_WIN_JUMPLISTSHORTCUT_CID); - +#ifdef MOZ_METRO +NS_DEFINE_NAMED_CID(NS_WIN_METROUTILS_CID); +#endif NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID); NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID); - #ifdef NS_PRINTING NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID); NS_DEFINE_NAMED_CID(NS_PRINTER_ENUMERATOR_CID); @@ -113,9 +189,9 @@ NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID); static const mozilla::Module::CIDEntry kWidgetCIDs[] = { - { &kNS_WINDOW_CID, false, NULL, nsWindowConstructor }, + { &kNS_WINDOW_CID, false, NULL, WindowConstructor }, { &kNS_CHILD_CID, false, NULL, ChildWindowConstructor }, - { &kNS_FILEPICKER_CID, false, NULL, nsFilePickerConstructor }, + { &kNS_FILEPICKER_CID, false, NULL, FilePickerConstructor }, { &kNS_APPSHELL_CID, false, NULL, nsAppShellConstructor }, { &kNS_SCREENMANAGER_CID, false, NULL, nsScreenManagerWinConstructor }, { &kNS_GFXINFO_CID, false, NULL, GfxInfoConstructor }, @@ -134,6 +210,9 @@ static const mozilla::Module::CIDEntry kWidgetCIDs[] = { { &kNS_WIN_JUMPLISTSHORTCUT_CID, false, NULL, JumpListShortcutConstructor }, { &kNS_DRAGSERVICE_CID, false, NULL, nsDragServiceConstructor }, { &kNS_BIDIKEYBOARD_CID, false, NULL, nsBidiKeyboardConstructor }, +#ifdef MOZ_METRO + { &kNS_WIN_METROUTILS_CID, false, NULL, nsWinMetroUtilsConstructor }, +#endif #ifdef NS_PRINTING { &kNS_PRINTSETTINGSSERVICE_CID, false, NULL, nsPrintOptionsWinConstructor }, { &kNS_PRINTER_ENUMERATOR_CID, false, NULL, nsPrinterEnumeratorWinConstructor }, @@ -165,6 +244,9 @@ static const mozilla::Module::ContractIDEntry kWidgetContracts[] = { { "@mozilla.org/windows-jumplistshortcut;1", &kNS_WIN_JUMPLISTSHORTCUT_CID }, { "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID }, { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID }, +#ifdef MOZ_METRO + { "@mozilla.org/windows-metroutils;1", &kNS_WIN_METROUTILS_CID }, +#endif #ifdef NS_PRINTING { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID }, { "@mozilla.org/gfx/printerenumerator;1", &kNS_PRINTER_ENUMERATOR_CID }, diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 67b2a9ed492d..1f11854f12cf 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -1953,7 +1953,7 @@ nsWindow::ResetLayout() // Send a gecko size event to trigger reflow. RECT clientRc = {0}; GetClientRect(mWnd, &clientRc); - nsIntRect evRect(nsWindowGfx::ToIntRect(clientRc)); + nsIntRect evRect(WinUtils::ToIntRect(clientRc)); OnResize(evRect); // Invalidate and update diff --git a/widget/windows/nsWindowGfx.cpp b/widget/windows/nsWindowGfx.cpp index 64f944f15355..b9b5541026a7 100644 --- a/widget/windows/nsWindowGfx.cpp +++ b/widget/windows/nsWindowGfx.cpp @@ -105,36 +105,6 @@ IsRenderMode(gfxWindowsPlatform::RenderMode rmode) return gfxWindowsPlatform::GetPlatform()->GetRenderMode() == rmode; } -nsIntRegion -nsWindowGfx::ConvertHRGNToRegion(HRGN aRgn) -{ - NS_ASSERTION(aRgn, "Don't pass NULL region here"); - - nsIntRegion rgn; - - DWORD size = ::GetRegionData(aRgn, 0, NULL); - nsAutoTArray buffer; - if (!buffer.SetLength(size)) - return rgn; - - RGNDATA* data = reinterpret_cast(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(data->Buffer); - for (uint32_t i = 0; i < data->rdh.nCount; ++i) { - RECT* r = rects + i; - rgn.Or(rgn, ToIntRect(*r)); - } - - return rgn; -} - /************************************************************** ************************************************************** ** @@ -152,7 +122,7 @@ nsIntRegion nsWindow::GetRegionToPaint(bool aForceFullRepaint, if (aForceFullRepaint) { RECT paintRect; ::GetClientRect(mWnd, &paintRect); - return nsIntRegion(nsWindowGfx::ToIntRect(paintRect)); + return nsIntRegion(WinUtils::ToIntRect(paintRect)); } HRGN paintRgn = ::CreateRectRgn(0, 0, 0, 0); @@ -163,11 +133,11 @@ nsIntRegion nsWindow::GetRegionToPaint(bool aForceFullRepaint, ::MapWindowPoints(NULL, mWnd, &pt, 1); ::OffsetRgn(paintRgn, pt.x, pt.y); } - nsIntRegion rgn(nsWindowGfx::ConvertHRGNToRegion(paintRgn)); + nsIntRegion rgn(WinUtils::ConvertHRGNToRegion(paintRgn)); ::DeleteObject(paintRgn); return rgn; } - return nsIntRegion(nsWindowGfx::ToIntRect(ps.rcPaint)); + return nsIntRegion(WinUtils::ToIntRect(ps.rcPaint)); } #define WORDSSIZE(x) ((x).width * (x).height) diff --git a/widget/windows/nsWindowGfx.h b/widget/windows/nsWindowGfx.h index 83d656d3ecfe..7969b67452e0 100644 --- a/widget/windows/nsWindowGfx.h +++ b/widget/windows/nsWindowGfx.h @@ -20,14 +20,6 @@ class nsWindowGfx { public: - static nsIntRect ToIntRect(const RECT& aRect) - { - return nsIntRect(aRect.left, aRect.top, - aRect.right - aRect.left, aRect.bottom - aRect.top); - } - - static nsIntRegion ConvertHRGNToRegion(HRGN aRgn); - enum IconSizeType { kSmallIcon, kRegularIcon diff --git a/widget/xpwidgets/nsAppShellSingleton.h b/widget/xpwidgets/nsAppShellSingleton.h index cc6cc244d2ad..84702c02803b 100644 --- a/widget/xpwidgets/nsAppShellSingleton.h +++ b/widget/xpwidgets/nsAppShellSingleton.h @@ -27,19 +27,41 @@ * method for the nsAppShell class. */ -static nsAppShell *sAppShell; +#include "nsXULAppAPI.h" +#if defined(MOZ_METRO) && defined(XP_WIN) +#include "winrt/MetroAppShell.h" +#endif + +static nsIAppShell *sAppShell; static nsresult nsAppShellInit() { NS_ASSERTION(!sAppShell, "already initialized"); +#if !defined(MOZ_METRO) || !defined(XP_WIN) sAppShell = new nsAppShell(); +#else + if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { + sAppShell = new MetroAppShell(); + } else { + sAppShell = new nsAppShell(); + } +#endif if (!sAppShell) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(sAppShell); - nsresult rv = sAppShell->Init(); + nsresult rv; +#if !defined(MOZ_METRO) || !defined(XP_WIN) + rv = static_cast(sAppShell)->Init(); +#else + if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { + rv = static_cast(sAppShell)->Init(); + } else { + rv = static_cast(sAppShell)->Init(); + } +#endif if (NS_FAILED(rv)) { NS_RELEASE(sAppShell); return rv;