Bug 715024 - Remove duplicate functions on nsCocoaFeatures and nsToolkit. r=bgirard

This commit is contained in:
Cameron McCormack 2012-05-17 17:53:20 +10:00
Родитель d814848599
Коммит c24ba0581d
15 изменённых файлов: 39 добавлений и 65 удалений

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

@ -44,7 +44,7 @@
#include "GfxInfo.h"
#include "nsUnicharUtils.h"
#include "mozilla/FunctionTimer.h"
#include "nsToolkit.h"
#include "nsCocoaFeatures.h"
#include "mozilla/Preferences.h"
#import <Foundation/Foundation.h>
@ -176,7 +176,7 @@ GfxInfo::Init()
AddCrashReportAnnotations();
mOSXVersion = nsToolkit::OSXVersion();
mOSXVersion = nsCocoaFeatures::OSXVersion();
return rv;
}
@ -404,7 +404,7 @@ GfxInfo::GetFeatureStatusImpl(PRInt32 aFeature,
// * bug 631258: WebGL shader paints using textures belonging to other processes on Mac OS 10.5
// * bug 618848: Post process shaders and texture mapping crash OS X 10.5
if (aFeature == nsIGfxInfo::FEATURE_WEBGL_OPENGL &&
!nsToolkit::OnSnowLeopardOrLater()) {
!nsCocoaFeatures::OnSnowLeopardOrLater()) {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_OS_VERSION;
return NS_OK;
}

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

@ -58,6 +58,7 @@
#include "nsIInterfaceRequestor.h"
#include "nsIWebBrowserChrome.h"
#include "nsObjCExceptions.h"
#include "nsCocoaFeatures.h"
#include "nsCocoaUtils.h"
#include "nsChildView.h"
#include "nsToolkit.h"
@ -371,7 +372,7 @@ nsAppShell::Init()
nsToolkit::SwizzleMethods([NSApplication class], @selector(terminate:),
@selector(nsAppShell_NSApplication_terminate:));
}
if (!nsToolkit::OnSnowLeopardOrLater()) {
if (!nsCocoaFeatures::OnSnowLeopardOrLater()) {
dlopen("/System/Library/Frameworks/Carbon.framework/Frameworks/Print.framework/Versions/Current/Plugins/PrintCocoaUI.bundle/Contents/MacOS/PrintCocoaUI",
RTLD_LAZY);
Class PDEPluginCallbackClass = ::NSClassFromString(@"PDEPluginCallback");

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

@ -74,6 +74,7 @@
#include "nsClipboard.h"
#include "nsCursorManager.h"
#include "nsWindowMap.h"
#include "nsCocoaFeatures.h"
#include "nsCocoaUtils.h"
#include "nsMenuUtilsX.h"
#include "nsMenuBarX.h"
@ -306,7 +307,7 @@ nsresult nsChildView::Create(nsIWidget *aParent,
nsToolkit::SwizzleMethods([NSView class], @selector(mouseDownCanMoveWindow),
@selector(nsChildView_NSView_mouseDownCanMoveWindow));
#ifdef __LP64__
if (nsToolkit::OnLionOrLater()) {
if (nsCocoaFeatures::OnLionOrLater()) {
nsToolkit::SwizzleMethods([NSEvent class], @selector(addLocalMonitorForEventsMatchingMask:handler:),
@selector(nsChildView_NSEvent_addLocalMonitorForEventsMatchingMask:handler:),
true);
@ -3053,7 +3054,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
- (void)maybeTrackScrollEventAsSwipe:(NSEvent *)anEvent
scrollOverflow:(PRInt32)overflow
{
if (!nsToolkit::OnLionOrLater()) {
if (!nsCocoaFeatures::OnLionOrLater()) {
return;
}
// This method checks whether the AppleEnableSwipeNavigateWithScrolls global
@ -3960,7 +3961,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
static_cast<nsMouseEvent_base*>(outGeckoEvent);
mouseEvent->buttons = 0;
NSUInteger mouseButtons =
nsToolkit::OnSnowLeopardOrLater() ? [NSEvent pressedMouseButtons] : 0;
nsCocoaFeatures::OnSnowLeopardOrLater() ? [NSEvent pressedMouseButtons] : 0;
if (mouseButtons & 0x01) {
mouseEvent->buttons |= nsMouseEvent::eLeftButtonFlag;

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

@ -44,11 +44,10 @@
class nsCocoaFeatures {
public:
static PRInt32 OSXVersion();
static bool OnSnowLeopardOrLater();
static bool OnLionOrLater();
static bool SupportCoreAnimationPlugins();
private:
static PRInt32 mOSXVersion;
};

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

@ -45,6 +45,7 @@
#include "nsCocoaFeatures.h"
#include "nsDebug.h"
#include "nsObjCExceptions.h"
#import <Cocoa/Cocoa.h>
@ -53,6 +54,8 @@ PRInt32 nsCocoaFeatures::mOSXVersion = 0;
/* static */ PRInt32
nsCocoaFeatures::OSXVersion()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
if (!mOSXVersion) {
// minor version is not accurate, use gestaltSystemVersionMajor,
// gestaltSystemVersionMinor, gestaltSystemVersionBugFix for these
@ -65,6 +68,8 @@ nsCocoaFeatures::OSXVersion()
mOSXVersion &= MAC_OS_X_VERSION_MASK;
}
return mOSXVersion;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
}
/* static */ bool

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

@ -484,7 +484,7 @@ nsCocoaUtils::GetCurrentModifiers()
{
// NOTE: [[NSApp currentEvent] modifiers] isn't useful because it sometime 0
// and we cannot check if it's actual state.
if (nsToolkit::OnSnowLeopardOrLater()) {
if (nsCocoaFeatures::OnSnowLeopardOrLater()) {
// XXX [NSEvent modifierFlags] returns "current" modifier state, so,
// it's not event-queue-synchronized. GetCurrentEventKeyModifiers()
// might be better, but it's Carbon API, we shouldn't use it as far as

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

@ -61,6 +61,7 @@
#include "nsStyleConsts.h"
#include "nsNativeThemeColors.h"
#include "nsChildView.h"
#include "nsCocoaFeatures.h"
#include "gfxPlatform.h"
#include "qcms.h"
@ -2384,7 +2385,7 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton";
// We work around this problem by only returning AXChildren that are
// mozAccessible object or are one of the titlebar's buttons (which
// instantiate subclasses of NSButtonCell).
if (nsToolkit::OnLionOrLater() && [retval isKindOfClass:[NSArray class]] &&
if (nsCocoaFeatures::OnLionOrLater() && [retval isKindOfClass:[NSArray class]] &&
[attribute isEqualToString:@"AXChildren"]) {
NSMutableArray *holder = [NSMutableArray arrayWithCapacity:10];
[holder addObjectsFromArray:(NSArray *)retval];
@ -2689,7 +2690,7 @@ DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
nil],
nil);
if (nsToolkit::OnLionOrLater()) {
if (nsCocoaFeatures::OnLionOrLater()) {
// On Lion the call to CUIDraw doesn't draw the top pixel strip at some
// window widths. We don't want to have a flickering transparent line, so
// we overdraw it.

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

@ -53,8 +53,8 @@
#include "nsIURL.h"
#include "nsArrayEnumerator.h"
#include "nsIStringBundle.h"
#include "nsCocoaFeatures.h"
#include "nsCocoaUtils.h"
#include "nsToolkit.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
@ -356,7 +356,7 @@ nsFilePicker::GetLocalFiles(const nsString& inTitle, bool inAllowMultiple, nsCOM
// are not available on 10.5 and without using them it happens to be buggy.
int result;
nsCocoaUtils::PrepareForNativeAppModalDialog();
if (mFilters.Length() > 1 && nsToolkit::OnSnowLeopardOrLater()) {
if (mFilters.Length() > 1 && nsCocoaFeatures::OnSnowLeopardOrLater()) {
// [NSURL initWithString:] (below) throws an exception if URLString is nil.
if (!theDir) {
theDir = @"";

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

@ -37,6 +37,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsLookAndFeel.h"
#include "nsCocoaFeatures.h"
#include "nsObjCExceptions.h"
#include "nsIServiceManager.h"
#include "nsNativeThemeColors.h"
@ -260,7 +261,7 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
aColor = NS_RGB(0xA3,0xA3,0xA3);
break;
case eColorID__moz_mac_menutextdisable:
aColor = nsToolkit::OnSnowLeopardOrLater() ?
aColor = nsCocoaFeatures::OnSnowLeopardOrLater() ?
NS_RGB(0x88,0x88,0x88) : NS_RGB(0x98,0x98,0x98);
break;
case eColorID__moz_mac_menutextselect:
@ -349,7 +350,7 @@ nsLookAndFeel::GetIntImpl(IntID aID, PRInt32 &aResult)
aResult = 4;
break;
case eIntID_ScrollArrowStyle:
if (nsToolkit::OnLionOrLater()) {
if (nsCocoaFeatures::OnLionOrLater()) {
// OS X Lion's scrollbars have no arrows
aResult = eScrollArrow_None;
} else {
@ -396,7 +397,7 @@ nsLookAndFeel::GetIntImpl(IntID aID, PRInt32 &aResult)
aResult = [NSColor currentControlTint] == NSGraphiteControlTint;
break;
case eIntID_MacLionTheme:
aResult = nsToolkit::OnLionOrLater();
aResult = nsCocoaFeatures::OnLionOrLater();
break;
case eIntID_TabFocusModel:
{

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

@ -43,9 +43,9 @@
#include "nsMenuX.h"
#include "nsMenuItemX.h"
#include "nsMenuUtilsX.h"
#include "nsCocoaFeatures.h"
#include "nsCocoaUtils.h"
#include "nsCocoaWindow.h"
#include "nsToolkit.h"
#include "nsChildView.h"
#include "nsCOMPtr.h"
@ -365,7 +365,7 @@ nsMenuX* nsMenuBarX::GetXULHelpMenu()
// This resolves bugs 489196 and 539317.
void nsMenuBarX::SetSystemHelpMenu()
{
if (!nsToolkit::OnSnowLeopardOrLater())
if (!nsCocoaFeatures::OnSnowLeopardOrLater())
return;
nsMenuX* xulHelpMenu = GetXULHelpMenu();
if (xulHelpMenu) {

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

@ -47,6 +47,7 @@
#include "nsObjCExceptions.h"
#include "nsToolkit.h"
#include "nsCocoaFeatures.h"
#include "nsCocoaUtils.h"
#include "nsCOMPtr.h"
#include "prinrval.h"
@ -139,7 +140,7 @@ nsMenuX::nsMenuX()
// SCTGRLIndex class) is loaded on demand, whenever the user first opens
// a menu (which normally hasn't happened yet). So we need to load it
// here explicitly.
if (nsToolkit::OnSnowLeopardOrLater())
if (nsCocoaFeatures::OnSnowLeopardOrLater())
dlopen("/System/Library/PrivateFrameworks/Shortcut.framework/Shortcut", RTLD_LAZY);
Class SCTGRLIndexClass = ::NSClassFromString(@"SCTGRLIndex");
nsToolkit::SwizzleMethods(SCTGRLIndexClass, @selector(indexMenuBarDynamically),

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

@ -56,7 +56,7 @@
#include "nsINameSpaceManager.h"
#include "nsPresContext.h"
#include "nsGkAtoms.h"
#include "nsToolkit.h"
#include "nsCocoaFeatures.h"
#include "nsCocoaWindow.h"
#include "nsNativeThemeColors.h"
#include "nsIScrollableFrame.h"
@ -1625,7 +1625,7 @@ nsNativeThemeCocoa::GetScrollbarDrawInfo(HIThemeTrackDrawInfo& aTdi, nsIFrame *a
// creating a TrackDrawInfo to determine the size of the thumb. There's
// also no reason to do this on Lion or later, whose scrollbars have no
// arrow buttons.
if (aShouldGetButtonStates && !nsToolkit::OnLionOrLater()) {
if (aShouldGetButtonStates && !nsCocoaFeatures::OnLionOrLater()) {
nsEventStates buttonStates[4];
GetScrollbarPressStates(aFrame, buttonStates);
NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
@ -2325,7 +2325,7 @@ nsNativeThemeCocoa::GetWidgetBorder(nsDeviceContext* aContext,
case NS_THEME_SCROLLBAR_TRACK_VERTICAL:
{
// On Lion and later, scrollbars have no arrows.
if (!nsToolkit::OnLionOrLater()) {
if (!nsCocoaFeatures::OnLionOrLater()) {
// There's only an endcap to worry about when both arrows are on the bottom
NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];
if (!buttonPlacement || [buttonPlacement isEqualToString:@"DoubleMax"]) {

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

@ -38,7 +38,7 @@
#ifndef nsNativeThemeColors_h_
#define nsNativeThemeColors_h_
#include "nsToolkit.h"
#include "nsCocoaFeatures.h"
#import <Cocoa/Cocoa.h>
extern "C" {
@ -83,10 +83,10 @@ static const int sLionThemeColors[][2] = {
__attribute__((unused))
static int NativeGreyColorAsInt(ColorName name, BOOL isMain)
{
if (nsToolkit::OnLionOrLater())
if (nsCocoaFeatures::OnLionOrLater())
return sLionThemeColors[name][isMain ? 0 : 1];
if (nsToolkit::OnSnowLeopardOrLater())
if (nsCocoaFeatures::OnSnowLeopardOrLater())
return sSnowLeopardThemeColors[name][isMain ? 0 : 1];
return sLeopardThemeColors[name][isMain ? 0 : 1];

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

@ -40,33 +40,26 @@
#define nsToolkit_h_
#include "nscore.h"
#include "nsCocoaFeatures.h"
#import <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
#import <objc/Object.h>
#import <IOKit/IOKitLib.h>
#define MAC_OS_X_VERSION_10_5_HEX 0x00001050
#define MAC_OS_X_VERSION_10_6_HEX 0x00001060
#define MAC_OS_X_VERSION_10_7_HEX 0x00001070
class nsToolkit
{
public:
nsToolkit();
virtual ~nsToolkit();
static nsToolkit* GetToolkit();
static nsToolkit* GetToolkit();
static void Shutdown() {
delete gToolkit;
gToolkit = nsnull;
}
static PRInt32 OSXVersion();
static bool OnSnowLeopardOrLater();
static bool OnLionOrLater();
static void PostSleepWakeNotification(const char* aNotification);
static nsresult SwizzleMethods(Class aClass, SEL orgMethod, SEL posedMethod,
@ -82,7 +75,7 @@ protected:
protected:
static nsToolkit* gToolkit;
static nsToolkit* gToolkit;
CFRunLoopSourceRef mSleepWakeNotificationRLS;
io_object_t mPowerNotifier;

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

@ -314,34 +314,6 @@ nsToolkit* nsToolkit::GetToolkit()
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsnull);
}
PRInt32 nsToolkit::OSXVersion()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
static PRInt32 gOSXVersion = 0x0;
if (gOSXVersion == 0x0) {
OSErr err = ::Gestalt(gestaltSystemVersion, (SInt32*)&gOSXVersion);
if (err != noErr) {
// This should probably be changed when our minimum version changes
NS_ERROR("Couldn't determine OS X version, assuming 10.5");
gOSXVersion = MAC_OS_X_VERSION_10_5_HEX;
}
}
return gOSXVersion;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
}
bool nsToolkit::OnSnowLeopardOrLater()
{
return (OSXVersion() >= MAC_OS_X_VERSION_10_6_HEX);
}
bool nsToolkit::OnLionOrLater()
{
return (OSXVersion() >= MAC_OS_X_VERSION_10_7_HEX);
}
// An alternative to [NSObject poseAsClass:] that isn't deprecated on OS X
// Leopard and is available to 64-bit binaries on Leopard and above. Based on
// ideas and code from http://www.cocoadev.com/index.pl?MethodSwizzling.
@ -516,7 +488,7 @@ OSStatus Hooked_InstallEventLoopIdleTimer(
void HookImportedFunctions()
{
// We currently only need to do anything on Tiger or Leopard.
if (nsToolkit::OnSnowLeopardOrLater())
if (nsCocoaFeatures::OnSnowLeopardOrLater())
return;
// _dyld_register_func_for_add_image() makes the dynamic linker runtime call