mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 38447 store hotspot information from .cur files on the imgIContainer; and
support storing arbitrary information on image containers (via nsIProperties) r=pavlov sr=tor
This commit is contained in:
parent
7660d9cd78
commit
2d5fec5c1a
@ -48,6 +48,9 @@
|
||||
|
||||
#include "imgILoad.h"
|
||||
|
||||
#include "nsIProperties.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsICODecoder, imgIDecoder)
|
||||
@ -227,6 +230,8 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) {
|
||||
return NS_OK;
|
||||
|
||||
while (aCount && (mPos < ICONCOUNTOFFSET)) { // Skip to the # of icons.
|
||||
if (mPos == 2) // if the third byte is 2: This is a cursor
|
||||
mIsCursor = (*aBuffer == 2);
|
||||
mPos++; aBuffer++; aCount--;
|
||||
}
|
||||
|
||||
@ -308,6 +313,23 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) {
|
||||
|
||||
nsresult rv = mImage->Init(mDirEntry.mWidth, mDirEntry.mHeight, mObserver);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mIsCursor) {
|
||||
nsCOMPtr<nsIProperties> props(do_QueryInterface(mImage));
|
||||
if (props) {
|
||||
nsCOMPtr<nsISupportsPRUint32> intwrapx = do_CreateInstance("@mozilla.org/supports-PRUint32;1");
|
||||
nsCOMPtr<nsISupportsPRUint32> intwrapy = do_CreateInstance("@mozilla.org/supports-PRUint32;1");
|
||||
|
||||
if (intwrapx && intwrapy) {
|
||||
intwrapx->SetData(mDirEntry.mXHotspot);
|
||||
intwrapy->SetData(mDirEntry.mYHotspot);
|
||||
|
||||
props->Set("hotspotX", intwrapx);
|
||||
props->Set("hotspotY", intwrapy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rv = mObserver->OnStartContainer(nsnull, mImage);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -64,8 +64,14 @@ struct IconDirEntry
|
||||
PRUint8 mHeight;
|
||||
PRUint8 mColorCount;
|
||||
PRUint8 mReserved;
|
||||
PRUint16 mPlanes;
|
||||
PRUint16 mBitCount;
|
||||
union {
|
||||
PRUint16 mPlanes; // ICO
|
||||
PRUint16 mXHotspot; // CUR
|
||||
};
|
||||
union {
|
||||
PRUint16 mBitCount; // ICO
|
||||
PRUint16 mYHotspot; // CUR
|
||||
};
|
||||
PRUint32 mBytesInRes;
|
||||
PRUint32 mImageOffset;
|
||||
};
|
||||
@ -123,6 +129,7 @@ private:
|
||||
|
||||
PRUint8* mDecodedBuffer;
|
||||
PRUint8* mAlphaBuffer;
|
||||
PRPackedBool mIsCursor;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
@ -40,15 +39,18 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsComponentManagerUtils.h"
|
||||
|
||||
#include "imgContainer.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(imgContainer, imgIContainer)
|
||||
NS_IMPL_ISUPPORTS2(imgContainer, imgIContainer, nsIProperties)
|
||||
|
||||
//******************************************************************************
|
||||
imgContainer::imgContainer() :
|
||||
mSize(0,0),
|
||||
mFrame(nsnull)
|
||||
{
|
||||
mProperties = do_CreateInstance("@mozilla.org/properties;1");
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
|
@ -44,21 +44,23 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "gfxIImageFrame.h"
|
||||
#include "nsIProperties.h"
|
||||
|
||||
|
||||
#define NS_IMGCONTAINER_CID \
|
||||
{ /* 5e04ec5e-1dd2-11b2-8fda-c4db5fb666e0 */ \
|
||||
0x5e04ec5e, \
|
||||
0x1dd2, \
|
||||
0x11b2, \
|
||||
{0x8f, 0xda, 0xc4, 0xdb, 0x5f, 0xb6, 0x66, 0xe0} \
|
||||
{ /* 27f0682c-ff64-4dd2-ae7a-668e59f2fd38 */ \
|
||||
0x27f0682c, \
|
||||
0xff64, \
|
||||
0x4dd2, \
|
||||
{0xae, 0x7a, 0x66, 0x8e, 0x59, 0xf2, 0xfd, 0x38} \
|
||||
}
|
||||
|
||||
class imgContainer : public imgIContainer
|
||||
class imgContainer : public imgIContainer, public nsIProperties
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IMGICONTAINER
|
||||
NS_FORWARD_SAFE_NSIPROPERTIES(mProperties)
|
||||
|
||||
imgContainer();
|
||||
virtual ~imgContainer();
|
||||
@ -66,6 +68,7 @@ public:
|
||||
private:
|
||||
nsIntSize mSize;
|
||||
nsCOMPtr<gfxIImageFrame> mFrame;
|
||||
nsCOMPtr<nsIProperties> mProperties;
|
||||
};
|
||||
|
||||
#endif /* __imgContainer_h__ */
|
||||
|
@ -781,7 +781,9 @@ nsresult imgLoader::GetMimeTypeFromContent(const char* aContents, PRUint32 aLeng
|
||||
}
|
||||
|
||||
// ICOs always begin with a 2-byte 0 followed by a 2-byte 1.
|
||||
else if (aLength >= 4 && !memcmp(aContents, "\000\000\001\000", 4)) {
|
||||
// CURs begin with 2-byte 0 followed by 2-byte 2.
|
||||
else if (aLength >= 4 && (!memcmp(aContents, "\000\000\001\000", 4) ||
|
||||
!memcmp(aContents, "\000\000\002\000", 4))) {
|
||||
aContentType.AssignLiteral("image/x-icon");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user