Bug 1328512 followup 2 - Update expectation of style system tests for stylo. DONTBUILD
MozReview-Commit-ID: 1n2zN1tY79p
/* -*- Mode: C++; tab-width: 2; 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"nsPrintSettingsX.h"#include"nsObjCExceptions.h"#include"plbase64.h"#include"plstr.h"#include"nsCocoaUtils.h"#include"mozilla/Preferences.h"usingnamespacemozilla;#define MAC_OS_X_PAGE_SETUP_PREFNAME "print.macosx.pagesetup-2"#define COCOA_PAPER_UNITS_PER_INCH 72.0NS_IMPL_ISUPPORTS_INHERITED(nsPrintSettingsX,nsPrintSettings,nsPrintSettingsX)nsPrintSettingsX::nsPrintSettingsX(){NS_OBJC_BEGIN_TRY_ABORT_BLOCK;mPrintInfo=[[NSPrintInfosharedPrintInfo]copy];mWidthScale=COCOA_PAPER_UNITS_PER_INCH;mHeightScale=COCOA_PAPER_UNITS_PER_INCH;NS_OBJC_END_TRY_ABORT_BLOCK;}nsPrintSettingsX::nsPrintSettingsX(constnsPrintSettingsX&src){*this=src;}nsPrintSettingsX::~nsPrintSettingsX(){NS_OBJC_BEGIN_TRY_ABORT_BLOCK;[mPrintInforelease];NS_OBJC_END_TRY_ABORT_BLOCK;}nsPrintSettingsX&nsPrintSettingsX::operator=(constnsPrintSettingsX&rhs){NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;if(this==&rhs){return*this;}nsPrintSettings::operator=(rhs);[mPrintInforelease];mPrintInfo=[rhs.mPrintInfocopy];return*this;NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(*this);}nsresultnsPrintSettingsX::Init(){NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;InitUnwriteableMargin();InitAdjustedPaperSize();returnNS_OK;NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;}// Should be called whenever the page format changes.NS_IMETHODIMPnsPrintSettingsX::InitUnwriteableMargin(){NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;PMPaperpaper;PMPaperMarginspaperMargin;PMPageFormatpageFormat=GetPMPageFormat();::PMGetPageFormatPaper(pageFormat,&paper);::PMPaperGetMargins(paper,&paperMargin);mUnwriteableMargin.top=NS_POINTS_TO_INT_TWIPS(paperMargin.top);mUnwriteableMargin.left=NS_POINTS_TO_INT_TWIPS(paperMargin.left);mUnwriteableMargin.bottom=NS_POINTS_TO_INT_TWIPS(paperMargin.bottom);mUnwriteableMargin.right=NS_POINTS_TO_INT_TWIPS(paperMargin.right);returnNS_OK;NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;}NS_IMETHODIMPnsPrintSettingsX::InitAdjustedPaperSize(){NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;PMPageFormatpageFormat=GetPMPageFormat();PMRectpaperRect;::PMGetAdjustedPaperRect(pageFormat,&paperRect);mAdjustedPaperWidth=paperRect.right-paperRect.left;mAdjustedPaperHeight=paperRect.bottom-paperRect.top;returnNS_OK;NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;}voidnsPrintSettingsX::SetCocoaPrintInfo(NSPrintInfo*aPrintInfo){if(mPrintInfo!=aPrintInfo){[mPrintInforelease];mPrintInfo=[aPrintInforetain];}}NS_IMETHODIMPnsPrintSettingsX::ReadPageFormatFromPrefs(){NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;nsAutoCStringencodedData;nsresultrv=Preferences::GetCString(MAC_OS_X_PAGE_SETUP_PREFNAME,&encodedData);if(NS_FAILED(rv)){returnrv;}// decode the base64char*decodedData=PL_Base64Decode(encodedData.get(),encodedData.Length(),nullptr);NSData*data=[NSDatadataWithBytes:decodedDatalength:strlen(decodedData)];if(!data)returnNS_ERROR_FAILURE;PMPageFormatnewPageFormat;OSStatusstatus=::PMPageFormatCreateWithDataRepresentation((CFDataRef)data,&newPageFormat);if(status==noErr){SetPMPageFormat(newPageFormat);}InitUnwriteableMargin();returnNS_OK;NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;}NS_IMETHODIMPnsPrintSettingsX::WritePageFormatToPrefs(){NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;PMPageFormatpageFormat=GetPMPageFormat();if(pageFormat==kPMNoPageFormat)returnNS_ERROR_NOT_INITIALIZED;NSData*data=nil;OSStatuserr=::PMPageFormatCreateDataRepresentation(pageFormat,(CFDataRef*)&data,kPMDataFormatXMLDefault);if(err!=noErr)returnNS_ERROR_FAILURE;nsAutoCStringencodedData;encodedData.Adopt(PL_Base64Encode((char*)[databytes],[datalength],nullptr));if(!encodedData.get())returnNS_ERROR_OUT_OF_MEMORY;returnPreferences::SetCString(MAC_OS_X_PAGE_SETUP_PREFNAME,encodedData);NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;}nsresultnsPrintSettingsX::_Clone(nsIPrintSettings**_retval){NS_ENSURE_ARG_POINTER(_retval);*_retval=nullptr;nsPrintSettingsX*newSettings=newnsPrintSettingsX(*this);if(!newSettings)returnNS_ERROR_FAILURE;*_retval=newSettings;NS_ADDREF(*_retval);returnNS_OK;}NS_IMETHODIMPnsPrintSettingsX::_Assign(nsIPrintSettings*aPS){nsPrintSettingsX*printSettingsX=static_cast<nsPrintSettingsX*>(aPS);if(!printSettingsX)returnNS_ERROR_UNEXPECTED;*this=*printSettingsX;returnNS_OK;}PMPrintSettingsnsPrintSettingsX::GetPMPrintSettings(){returnstatic_cast<PMPrintSettings>([mPrintInfoPMPrintSettings]);}PMPrintSessionnsPrintSettingsX::GetPMPrintSession(){returnstatic_cast<PMPrintSession>([mPrintInfoPMPrintSession]);}PMPageFormatnsPrintSettingsX::GetPMPageFormat(){returnstatic_cast<PMPageFormat>([mPrintInfoPMPageFormat]);}voidnsPrintSettingsX::SetPMPageFormat(PMPageFormataPageFormat){PMPageFormatoldPageFormat=GetPMPageFormat();::PMCopyPageFormat(aPageFormat,oldPageFormat);[mPrintInfoupdateFromPMPageFormat];}voidnsPrintSettingsX::SetInchesScale(floataWidthScale,floataHeightScale){if(aWidthScale>0&&aHeightScale>0){mWidthScale=aWidthScale;mHeightScale=aHeightScale;}}voidnsPrintSettingsX::GetInchesScale(float*aWidthScale,float*aHeightScale){*aWidthScale=mWidthScale;*aHeightScale=mHeightScale;}NS_IMETHODIMPnsPrintSettingsX::SetPaperWidth(doubleaPaperWidth){mPaperWidth=aPaperWidth;mAdjustedPaperWidth=aPaperWidth*mWidthScale;returnNS_OK;}NS_IMETHODIMPnsPrintSettingsX::SetPaperHeight(doubleaPaperHeight){mPaperHeight=aPaperHeight;mAdjustedPaperHeight=aPaperHeight*mHeightScale;returnNS_OK;}NS_IMETHODIMPnsPrintSettingsX::GetEffectivePageSize(double*aWidth,double*aHeight){*aWidth=NS_INCHES_TO_TWIPS(mAdjustedPaperWidth/mWidthScale);*aHeight=NS_INCHES_TO_TWIPS(mAdjustedPaperHeight/mHeightScale);returnNS_OK;}voidnsPrintSettingsX::SetAdjustedPaperSize(doubleaWidth,doubleaHeight){mAdjustedPaperWidth=aWidth;mAdjustedPaperHeight=aHeight;}voidnsPrintSettingsX::GetAdjustedPaperSize(double*aWidth,double*aHeight){*aWidth=mAdjustedPaperWidth;*aHeight=mAdjustedPaperHeight;}