зеркало из https://github.com/mozilla/pjs.git
Bug 716819 Move nsToolkit::VistaCreateItemFromParsingNameInit() and nsToolkit::createItemFromParsingName to WinUtils r=jimm
This commit is contained in:
Родитель
822c3f37ac
Коммит
3a02d5c569
|
@ -55,7 +55,7 @@
|
||||||
#include "mozIAsyncFavicons.h"
|
#include "mozIAsyncFavicons.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
#include "JumpListBuilder.h"
|
#include "JumpListBuilder.h"
|
||||||
#include "nsToolkit.h"
|
#include "WinUtils.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace widget {
|
namespace widget {
|
||||||
|
@ -738,13 +738,15 @@ nsresult JumpListLink::GetShellItem(nsCOMPtr<nsIJumpListItem>& item, nsRefPtr<IS
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// Load vista+ SHCreateItemFromParsingName
|
// Load vista+ SHCreateItemFromParsingName
|
||||||
if (!nsToolkit::VistaCreateItemFromParsingNameInit())
|
if (!WinUtils::VistaCreateItemFromParsingNameInit()) {
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
// Create the IShellItem
|
// Create the IShellItem
|
||||||
if (FAILED(nsToolkit::createItemFromParsingName(NS_ConvertASCIItoUTF16(spec).get(),
|
if (FAILED(WinUtils::SHCreateItemFromParsingName(
|
||||||
NULL, IID_PPV_ARGS(&psi))))
|
NS_ConvertASCIItoUTF16(spec).get(), NULL, IID_PPV_ARGS(&psi)))) {
|
||||||
return NS_ERROR_INVALID_ARG;
|
return NS_ERROR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the title
|
// Set the title
|
||||||
nsAutoString linkTitle;
|
nsAutoString linkTitle;
|
||||||
|
|
|
@ -65,6 +65,9 @@
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace widget {
|
namespace widget {
|
||||||
|
|
||||||
|
// SHCreateItemFromParsingName is only available on vista and up.
|
||||||
|
WinUtils::SHCreateItemFromParsingNamePtr WinUtils::sCreateItemFromParsingName = nsnull;
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
WinUtils::WinVersion
|
WinUtils::WinVersion
|
||||||
WinUtils::GetWindowsVersion()
|
WinUtils::GetWindowsVersion()
|
||||||
|
@ -363,5 +366,37 @@ WinUtils::InitMSG(UINT aMessage, WPARAM wParam, LPARAM lParam)
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
bool
|
||||||
|
WinUtils::VistaCreateItemFromParsingNameInit()
|
||||||
|
{
|
||||||
|
// Load and store Vista+ SHCreateItemFromParsingName
|
||||||
|
if (sCreateItemFromParsingName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
static HMODULE sShellDll = nsnull;
|
||||||
|
if (sShellDll) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
static const PRUnichar kSehllLibraryName[] = L"shell32.dll";
|
||||||
|
sShellDll = ::LoadLibraryW(kSehllLibraryName);
|
||||||
|
if (!sShellDll) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sCreateItemFromParsingName = (SHCreateItemFromParsingNamePtr)
|
||||||
|
GetProcAddress(sShellDll, "SHCreateItemFromParsingName");
|
||||||
|
return sCreateItemFromParsingName != nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
HRESULT
|
||||||
|
WinUtils::SHCreateItemFromParsingName(PCWSTR pszPath, IBindCtx *pbc,
|
||||||
|
REFIID riid, void **ppv)
|
||||||
|
{
|
||||||
|
NS_ENSURE_TRUE(sCreateItemFromParsingName, E_FAIL);
|
||||||
|
return sCreateItemFromParsingName(pszPath, pbc, riid, ppv);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace widget
|
} // namespace widget
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
|
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <shobjidl.h>
|
||||||
|
|
||||||
class nsWindow;
|
class nsWindow;
|
||||||
|
|
||||||
|
@ -198,6 +199,28 @@ public:
|
||||||
* mouse message handling.
|
* mouse message handling.
|
||||||
*/
|
*/
|
||||||
static PRUint16 GetMouseInputSource();
|
static PRUint16 GetMouseInputSource();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VistaCreateItemFromParsingNameInit() initializes the static pointer for
|
||||||
|
* SHCreateItemFromParsingName() API which is usable only on Vista and later.
|
||||||
|
* This returns TRUE if the API is available. Otherwise, FALSE.
|
||||||
|
*/
|
||||||
|
static bool VistaCreateItemFromParsingNameInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SHCreateItemFromParsingName() calls native SHCreateItemFromParsingName()
|
||||||
|
* API. Note that you must call VistaCreateItemFromParsingNameInit() before
|
||||||
|
* calling this. And the result must be TRUE. Otherwise, returns E_FAIL.
|
||||||
|
*/
|
||||||
|
static HRESULT SHCreateItemFromParsingName(PCWSTR pszPath, IBindCtx *pbc,
|
||||||
|
REFIID riid, void **ppv);
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef HRESULT (WINAPI * SHCreateItemFromParsingNamePtr)(PCWSTR pszPath,
|
||||||
|
IBindCtx *pbc,
|
||||||
|
REFIID riid,
|
||||||
|
void **ppv);
|
||||||
|
static SHCreateItemFromParsingNamePtr sCreateItemFromParsingName;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace widget
|
} // namespace widget
|
||||||
|
|
|
@ -619,11 +619,12 @@ nsFilePicker::ShowFolderPicker(const nsString& aInitialDir)
|
||||||
// initial strings
|
// initial strings
|
||||||
dialog->SetTitle(mTitle.get());
|
dialog->SetTitle(mTitle.get());
|
||||||
if (!aInitialDir.IsEmpty() &&
|
if (!aInitialDir.IsEmpty() &&
|
||||||
nsToolkit::VistaCreateItemFromParsingNameInit()) {
|
WinUtils::VistaCreateItemFromParsingNameInit()) {
|
||||||
nsRefPtr<IShellItem> folder;
|
nsRefPtr<IShellItem> folder;
|
||||||
if (SUCCEEDED(nsToolkit::createItemFromParsingName(aInitialDir.get(), NULL,
|
if (SUCCEEDED(
|
||||||
IID_IShellItem,
|
WinUtils::SHCreateItemFromParsingName(aInitialDir.get(), NULL,
|
||||||
getter_AddRefs(folder)))) {
|
IID_IShellItem,
|
||||||
|
getter_AddRefs(folder)))) {
|
||||||
dialog->SetFolder(folder);
|
dialog->SetFolder(folder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -944,11 +945,12 @@ nsFilePicker::ShowFilePicker(const nsString& aInitialDir)
|
||||||
|
|
||||||
// initial location
|
// initial location
|
||||||
if (!aInitialDir.IsEmpty() &&
|
if (!aInitialDir.IsEmpty() &&
|
||||||
nsToolkit::VistaCreateItemFromParsingNameInit()) {
|
WinUtils::VistaCreateItemFromParsingNameInit()) {
|
||||||
nsRefPtr<IShellItem> folder;
|
nsRefPtr<IShellItem> folder;
|
||||||
if (SUCCEEDED(nsToolkit::createItemFromParsingName(aInitialDir.get(), NULL,
|
if (SUCCEEDED(
|
||||||
IID_IShellItem,
|
WinUtils::SHCreateItemFromParsingName(aInitialDir.get(), NULL,
|
||||||
getter_AddRefs(folder)))) {
|
IID_IShellItem,
|
||||||
|
getter_AddRefs(folder)))) {
|
||||||
dialog->SetFolder(folder);
|
dialog->SetFolder(folder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,11 +57,6 @@ nsToolkit* nsToolkit::gToolkit = nsnull;
|
||||||
HINSTANCE nsToolkit::mDllInstance = 0;
|
HINSTANCE nsToolkit::mDllInstance = 0;
|
||||||
static const unsigned long kD3DUsageDelay = 5000;
|
static const unsigned long kD3DUsageDelay = 5000;
|
||||||
|
|
||||||
// SHCreateItemFromParsingName is only available on vista and up.
|
|
||||||
nsToolkit::SHCreateItemFromParsingNamePtr nsToolkit::createItemFromParsingName = nsnull;
|
|
||||||
const PRUnichar nsToolkit::kSehllLibraryName[] = L"shell32.dll";
|
|
||||||
HMODULE nsToolkit::sShellDll = nsnull;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
StartAllowingD3D9(nsITimer *aTimer, void *aClosure)
|
StartAllowingD3D9(nsITimer *aTimer, void *aClosure)
|
||||||
{
|
{
|
||||||
|
@ -125,24 +120,6 @@ nsToolkit::StartAllowingD3D9()
|
||||||
nsWindow::StartAllowingD3D9(false);
|
nsWindow::StartAllowingD3D9(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load and store Vista+ SHCreateItemFromParsingName
|
|
||||||
bool
|
|
||||||
nsToolkit::VistaCreateItemFromParsingNameInit()
|
|
||||||
{
|
|
||||||
if (createItemFromParsingName)
|
|
||||||
return true;
|
|
||||||
if (sShellDll)
|
|
||||||
return false;
|
|
||||||
sShellDll = LoadLibraryW(kSehllLibraryName);
|
|
||||||
if (!sShellDll)
|
|
||||||
return false;
|
|
||||||
createItemFromParsingName = (SHCreateItemFromParsingNamePtr)
|
|
||||||
GetProcAddress(sShellDll, "SHCreateItemFromParsingName");
|
|
||||||
if (createItemFromParsingName == nsnull)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Return the nsToolkit for the current thread. If a toolkit does not
|
// Return the nsToolkit for the current thread. If a toolkit does not
|
||||||
|
|
|
@ -44,8 +44,6 @@
|
||||||
#include "nsITimer.h"
|
#include "nsITimer.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shobjidl.h>
|
|
||||||
#include <imm.h>
|
|
||||||
|
|
||||||
// Avoid including windowsx.h to prevent macro pollution
|
// Avoid including windowsx.h to prevent macro pollution
|
||||||
#ifndef GET_X_LPARAM
|
#ifndef GET_X_LPARAM
|
||||||
|
@ -113,18 +111,12 @@ public:
|
||||||
static void Startup(HMODULE hModule);
|
static void Startup(HMODULE hModule);
|
||||||
static void Shutdown();
|
static void Shutdown();
|
||||||
static void StartAllowingD3D9();
|
static void StartAllowingD3D9();
|
||||||
static bool VistaCreateItemFromParsingNameInit();
|
|
||||||
|
|
||||||
typedef HRESULT (WINAPI * SHCreateItemFromParsingNamePtr)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv);
|
|
||||||
static SHCreateItemFromParsingNamePtr createItemFromParsingName;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static nsToolkit* gToolkit;
|
static nsToolkit* gToolkit;
|
||||||
|
|
||||||
nsCOMPtr<nsITimer> mD3D9Timer;
|
nsCOMPtr<nsITimer> mD3D9Timer;
|
||||||
MouseTrailer mMouseTrailer;
|
MouseTrailer mMouseTrailer;
|
||||||
static const PRUnichar kSehllLibraryName[];
|
|
||||||
static HMODULE sShellDll;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOOLKIT_H
|
#endif // TOOLKIT_H
|
||||||
|
|
Загрузка…
Ссылка в новой задаче