Bug 658705 widget/src/cocoa should use new pref utilities r=roc

This commit is contained in:
Masayuki Nakano 2011-05-27 17:15:20 +09:00
Родитель 5dbe0fcb94
Коммит 0e91f57c92
6 изменённых файлов: 44 добавлений и 86 удалений

Просмотреть файл

@ -26,9 +26,10 @@
*/
#import "ComplexTextInputPanel.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
#define kInputWindowHeight 20
@ -91,12 +92,10 @@
return;
}
if (sDoCancel < 0) {
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
NS_ENSURE_TRUE(prefs, );
PRBool cancelComposition = PR_FALSE;
nsresult rv =
prefs->GetBoolPref("ui.plugin.cancel_composition_at_input_source_changed",
&cancelComposition);
static const char* kPrefName =
"ui.plugin.cancel_composition_at_input_source_changed";
nsresult rv = Preferences::GetBool(kPrefName, &cancelComposition);
NS_ENSURE_SUCCESS(rv, );
sDoCancel = cancelComposition ? 1 : 0;
}

Просмотреть файл

@ -55,15 +55,12 @@
#include "nsCOMPtr.h"
#include "nsToolkit.h"
#include "nsCRT.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsFontMetrics.h"
#include "nsIRegion.h"
#include "nsIRollupListener.h"
#include "nsIViewManager.h"
#include "nsIInterfaceRequestor.h"
#include "nsIServiceManager.h"
#include "nsILocalFile.h"
#include "nsILocalFileMac.h"
#include "nsGfxCIID.h"
@ -90,6 +87,8 @@
#include "LayerManagerOGL.h"
#include "GLContext.h"
#include "mozilla/Preferences.h"
#include <dlfcn.h>
#include <ApplicationServices/ApplicationServices.h>
@ -97,6 +96,7 @@
using namespace mozilla::layers;
using namespace mozilla::gl;
using namespace mozilla::widget;
using namespace mozilla;
#undef DEBUG_IME
#undef DEBUG_UPDATE
@ -2938,12 +2938,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!gRollupWidget)
return;
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRBool useNativeContextMenus;
nsresult rv = prefs->GetBoolPref("ui.use_native_popup_windows", &useNativeContextMenus);
if (NS_SUCCEEDED(rv) && useNativeContextMenus)
return;
if (Preferences::GetBool("ui.use_native_popup_windows", PR_FALSE)) {
return;
}
NSWindow *popupWindow = (NSWindow*)gRollupWidget->GetNativeData(NS_NATIVE_WINDOW);
@ -3766,11 +3762,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
float scrollDelta = 0;
float scrollDeltaPixels = 0;
PRBool checkPixels = PR_TRUE;
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs)
prefs->GetBoolPref("mousewheel.enable_pixel_scrolling", &checkPixels);
PRBool checkPixels =
Preferences::GetBool("mousewheel.enable_pixel_scrolling", PR_TRUE);
// Calling deviceDeltaX or deviceDeltaY on theEvent will trigger a Cocoa
// assertion and an Objective-C NSInternalInconsistencyException if the

Просмотреть файл

@ -52,11 +52,8 @@
#include "nsIBaseWindow.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIXULWindow.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsToolkit.h"
#include "nsPrintfCString.h"
#include "nsIServiceManager.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMElement.h"
@ -71,12 +68,15 @@
#include "gfxPlatform.h"
#include "qcms.h"
#include "mozilla/Preferences.h"
namespace mozilla {
namespace layers {
class LayerManager;
}
}
using namespace mozilla::layers;
using namespace mozilla;
// defined in nsAppShell.mm
extern nsCocoaAppModalWindowList *gCocoaAppModalWindowList;
@ -227,13 +227,7 @@ static void FitRectToVisibleAreaForScreen(nsIntRect &aRect, NSScreen *screen)
// (native context menus, native tooltips)
static PRBool UseNativePopupWindows()
{
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs)
return PR_FALSE;
PRBool useNativePopupWindows;
nsresult rv = prefs->GetBoolPref("ui.use_native_popup_windows", &useNativePopupWindows);
return (NS_SUCCEEDED(rv) && useNativePopupWindows);
return Preferences::GetBool("ui.use_native_popup_windows", PR_FALSE);
}
nsresult nsCocoaWindow::Create(nsIWidget *aParent,

Просмотреть файл

@ -53,10 +53,11 @@
#include "nsIURL.h"
#include "nsArrayEnumerator.h"
#include "nsIStringBundle.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsCocoaUtils.h"
#include "nsToolkit.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
const float kAccessoryViewPadding = 5;
const int kSaveTypeControlTag = 1;
@ -92,11 +93,8 @@ static void SetShowHiddenFileState(NSSavePanel* panel)
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
PRBool show = PR_FALSE;
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
nsresult rv = prefs->GetBoolPref(kShowHiddenFilesPref, &show);
if (NS_SUCCEEDED(rv))
gCallSecretHiddenFileAPI = PR_TRUE;
if (NS_SUCCEEDED(Preferences::GetBool(kShowHiddenFilesPref, &show))) {
gCallSecretHiddenFileAPI = PR_TRUE;
}
if (gCallSecretHiddenFileAPI) {
@ -147,12 +145,8 @@ nsFilePicker::InitNative(nsIWidget *aParent, const nsAString& aTitle,
mMode = aMode;
// read in initial type index from prefs
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
int prefIndex;
if (NS_SUCCEEDED(prefs->GetIntPref(kLastTypeIndexPref, &prefIndex)))
mSelectedTypeIndex = prefIndex;
}
mSelectedTypeIndex =
Preferences::GetInt(kLastTypeIndexPref, mSelectedTypeIndex);
}
NSView* nsFilePicker::GetAccessoryView()
@ -512,9 +506,7 @@ nsFilePicker::PutLocalFile(const nsString& inTitle, const nsString& inDefaultNam
if (popupButton) {
mSelectedTypeIndex = [popupButton indexOfSelectedItem];
// save out to prefs for initializing other file picker instances
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs)
prefs->SetIntPref(kLastTypeIndexPref, mSelectedTypeIndex);
Preferences::SetInt(kLastTypeIndexPref, mSelectedTypeIndex);
}
NSURL* fileURL = [thePanel URL];

Просмотреть файл

@ -40,17 +40,16 @@
#include "nsPrintSettingsX.h"
#include "nsObjCExceptions.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsServiceManagerUtils.h"
#include "plbase64.h"
#include "plstr.h"
#include "nsCocoaUtils.h"
#define PRINTING_PREF_BRANCH "print."
#define MAC_OS_X_PAGE_SETUP_PREFNAME "macosx.pagesetup-2"
#include "mozilla/Preferences.h"
using namespace mozilla;
#define MAC_OS_X_PAGE_SETUP_PREFNAME "print.macosx.pagesetup-2"
NS_IMPL_ISUPPORTS_INHERITED1(nsPrintSettingsX, nsPrintSettings, nsPrintSettingsX)
@ -136,19 +135,12 @@ NS_IMETHODIMP nsPrintSettingsX::ReadPageFormatFromPrefs()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsresult rv;
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch(PRINTING_PREF_BRANCH, getter_AddRefs(prefBranch));
if (NS_FAILED(rv))
return rv;
nsXPIDLCString encodedData;
rv = prefBranch->GetCharPref(MAC_OS_X_PAGE_SETUP_PREFNAME, getter_Copies(encodedData));
if (NS_FAILED(rv))
nsCAutoString encodedData;
nsresult rv =
Preferences::GetCString(MAC_OS_X_PAGE_SETUP_PREFNAME, &encodedData);
if (NS_FAILED(rv)) {
return rv;
}
// decode the base64
char* decodedData = PL_Base64Decode(encodedData.get(), encodedData.Length(), nsnull);
@ -176,26 +168,17 @@ NS_IMETHODIMP nsPrintSettingsX::WritePageFormatToPrefs()
if (pageFormat == kPMNoPageFormat)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch(PRINTING_PREF_BRANCH, getter_AddRefs(prefBranch));
if (NS_FAILED(rv))
return rv;
NSData* data = nil;
OSStatus err = ::PMPageFormatCreateDataRepresentation(pageFormat, (CFDataRef*)&data, kPMDataFormatXMLDefault);
if (err != noErr)
return NS_ERROR_FAILURE;
nsXPIDLCString encodedData;
nsCAutoString encodedData;
encodedData.Adopt(PL_Base64Encode((char*)[data bytes], [data length], nsnull));
if (!encodedData.get())
return NS_ERROR_OUT_OF_MEMORY;
return prefBranch->SetCharPref(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData);
return Preferences::SetCString(MAC_OS_X_PAGE_SETUP_PREFNAME, encodedData);
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}

Просмотреть файл

@ -69,8 +69,10 @@ extern "C" {
#include "nsIObserverService.h"
#include "nsIServiceManager.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
// defined in nsChildView.mm
extern nsIRollupListener * gRollupListener;
@ -269,13 +271,8 @@ nsToolkit::RegisterForAllProcessMouseEvents()
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
// Don't do this for apps that (like Camino) use native context menus.
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRBool useNativeContextMenus;
nsresult rv = prefs->GetBoolPref("ui.use_native_popup_windows",
&useNativeContextMenus);
if (NS_SUCCEEDED(rv) && useNativeContextMenus)
return;
if (Preferences::GetBool("ui.use_native_popup_windows", PR_FALSE)) {
return;
}
if (!mEventMonitorHandler) {
EventTypeSpec kEvents[] = {{kEventClassMouse, kEventMouseMoved}};