mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Backed out changeset 41bb2af34a9b
This commit is contained in:
parent
54bbd7aa51
commit
ff76aa071d
@ -87,6 +87,7 @@
|
||||
// Interfaces Needed
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIContentViewerEdit.h"
|
||||
#include "nsIDocShell.h"
|
||||
@ -5982,6 +5983,65 @@ nsGlobalWindow::UpdateCommands(const nsAString& anAction)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGlobalWindow::ConvertCharset(const nsAString& aStr, char** aDest)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsCOMPtr<nsIUnicodeEncoder> encoder;
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager>
|
||||
ccm(do_GetService(kCharsetConverterManagerCID));
|
||||
NS_ENSURE_TRUE(ccm, NS_ERROR_FAILURE);
|
||||
|
||||
// Get the document character set
|
||||
nsCAutoString charset(NS_LITERAL_CSTRING("UTF-8")); // default to utf-8
|
||||
if (mDoc) {
|
||||
charset = mDoc->GetDocumentCharacterSet();
|
||||
}
|
||||
|
||||
// Get an encoder for the character set
|
||||
result = ccm->GetUnicodeEncoderRaw(charset.get(),
|
||||
getter_AddRefs(encoder));
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
result = encoder->Reset();
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
PRInt32 maxByteLen, srcLen;
|
||||
srcLen = aStr.Length();
|
||||
|
||||
const nsPromiseFlatString& flatSrc = PromiseFlatString(aStr);
|
||||
const PRUnichar* src = flatSrc.get();
|
||||
|
||||
// Get the expected length of result string
|
||||
result = encoder->GetMaxLength(src, srcLen, &maxByteLen);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
// Allocate a buffer of the maximum length
|
||||
*aDest = (char *) nsMemory::Alloc(maxByteLen + 1);
|
||||
PRInt32 destLen2, destLen = maxByteLen;
|
||||
if (!*aDest)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// Convert from unicode to the character set
|
||||
result = encoder->Convert(src, &srcLen, *aDest, &destLen);
|
||||
if (NS_FAILED(result)) {
|
||||
nsMemory::Free(*aDest);
|
||||
*aDest = nsnull;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Allow the encoder to finish the conversion
|
||||
destLen2 = maxByteLen - destLen;
|
||||
encoder->Finish(*aDest + destLen, &destLen2);
|
||||
(*aDest)[destLen + destLen2] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsGlobalWindow::GetBlurSuppression()
|
||||
{
|
||||
|
@ -572,6 +572,8 @@ protected:
|
||||
|
||||
static PRBool CanMoveResizeWindows();
|
||||
|
||||
nsresult ConvertCharset(const nsAString& aStr, char** aDest);
|
||||
|
||||
PRBool GetBlurSuppression();
|
||||
|
||||
// If aDoFlush is true, we'll flush our own layout; otherwise we'll try to
|
||||
|
Loading…
Reference in New Issue
Block a user