summaryrefslogtreecommitdiffstats
path: root/base/mac/mac_util.h
blob: 67151a7f8906dd4cb2912e824ba514e4bc9eada4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_MAC_MAC_UTIL_H_
#define BASE_MAC_MAC_UTIL_H_
#pragma once

#include <AvailabilityMacros.h>
#include <Carbon/Carbon.h>
#include <string>

#include "base/base_api.h"
#include "base/logging.h"

// TODO(rohitrao): Clean up sites that include mac_util.h and remove this line.
#include "base/mac/foundation_util.h"

#if defined(__OBJC__)
#import <Foundation/Foundation.h>
#else  // __OBJC__
class NSImage;
#endif  // __OBJC__

class FilePath;

namespace base {
namespace mac {

// Full screen modes, in increasing order of priority.  More permissive modes
// take predecence.
enum FullScreenMode {
  kFullScreenModeHideAll = 0,
  kFullScreenModeHideDock = 1,
  kFullScreenModeAutoHideAll = 2,
  kNumFullScreenModes = 3,

  // kFullScreenModeNormal is not a valid FullScreenMode, but it is useful to
  // other classes, so we include it here.
  kFullScreenModeNormal = 10,
};

BASE_API std::string PathFromFSRef(const FSRef& ref);
BASE_API bool FSRefFromPath(const std::string& path, FSRef* ref);

// Returns an sRGB color space.  The return value is a static value; do not
// release it!
BASE_API CGColorSpaceRef GetSRGBColorSpace();

// Returns the color space being used by the main display.  The return value
// is a static value; do not release it!
BASE_API CGColorSpaceRef GetSystemColorSpace();

// Add a full screen request for the given |mode|.  Must be paired with a
// ReleaseFullScreen() call for the same |mode|.  This does not by itself create
// a fullscreen window; rather, it manages per-application state related to
// hiding the dock and menubar.  Must be called on the main thread.
BASE_API void RequestFullScreen(FullScreenMode mode);

// Release a request for full screen mode.  Must be matched with a
// RequestFullScreen() call for the same |mode|.  As with RequestFullScreen(),
// this does not affect windows directly, but rather manages per-application
// state.  For example, if there are no other outstanding
// |kFullScreenModeAutoHideAll| requests, this will reshow the menu bar.  Must
// be called on main thread.
BASE_API void ReleaseFullScreen(FullScreenMode mode);

// Convenience method to switch the current fullscreen mode.  This has the same
// net effect as a ReleaseFullScreen(from_mode) call followed immediately by a
// RequestFullScreen(to_mode).  Must be called on the main thread.
BASE_API void SwitchFullScreenModes(FullScreenMode from_mode,
                                    FullScreenMode to_mode);

// Set the visibility of the cursor.
BASE_API void SetCursorVisibility(bool visible);

// Should windows miniaturize on a double-click (on the title bar)?
BASE_API bool ShouldWindowsMiniaturizeOnDoubleClick();

// Activates the process with the given PID.
BASE_API void ActivateProcess(pid_t pid);

// Returns true if this process is in the foreground, meaning that it's the
// frontmost process, the one whose menu bar is shown at the top of the main
// display.
BASE_API bool AmIForeground();

// Excludes the file given by |file_path| from being backed up by Time Machine.
BASE_API bool SetFileBackupExclusion(const FilePath& file_path);

// Sets the process name as displayed in Activity Monitor to process_name.
BASE_API void SetProcessName(CFStringRef process_name);

// Converts a NSImage to a CGImageRef.  Normally, the system frameworks can do
// this fine, especially on 10.6.  On 10.5, however, CGImage cannot handle
// converting a PDF-backed NSImage into a CGImageRef.  This function will
// rasterize the PDF into a bitmap CGImage.  The caller is responsible for
// releasing the return value.
BASE_API CGImageRef CopyNSImageToCGImage(NSImage* image);

// Checks if the current application is set as a Login Item, so it will launch
// on Login. If a non-NULL pointer to is_hidden is passed, the Login Item also
// is queried for the 'hide on launch' flag.
BASE_API bool CheckLoginItemStatus(bool* is_hidden);

// Adds current application to the set of Login Items with specified "hide"
// flag. This has the same effect as adding/removing the application in
// SystemPreferences->Accounts->LoginItems or marking Application in the Dock
// as "Options->Open on Login".
// Does nothing if the application is already set up as Login Item with
// specified hide flag.
BASE_API void AddToLoginItems(bool hide_on_startup);

// Removes the current application from the list Of Login Items.
BASE_API void RemoveFromLoginItems();

// Returns true if the current process was automatically launched as a
// 'Login Item' with 'hide on startup' flag. Used to suppress opening windows.
BASE_API bool WasLaunchedAsHiddenLoginItem();

// Run-time OS version checks. Use these instead of
// base::SysInfo::OperatingSystemVersionNumbers. Prefer the "OrEarlier" and
// "OrLater" variants to those that check for a specific version, unless you
// know for sure that you need to check for a specific version.

// Leopard is Mac OS X 10.5, Darwin 9.
BASE_API bool IsOSLeopard();
BASE_API bool IsOSLeopardOrEarlier();

// Snow Leopard is Mac OS X 10.6, Darwin 10.
BASE_API bool IsOSSnowLeopard();
BASE_API bool IsOSSnowLeopardOrEarlier();
BASE_API bool IsOSSnowLeopardOrLater();

// Lion is Mac OS X 10.7, Darwin 11.
BASE_API bool IsOSLion();
BASE_API bool IsOSLionOrLater();

// This should be infrequently used. It only makes sense to use this to avoid
// codepaths that are very likely to break on future (unreleased, untested,
// unborn) OS releases.
BASE_API bool IsOSLaterThanLion();

// When the deployment target is set, the code produced cannot run on earlier
// OS releases. That enables some of the IsOS* family to be implemented as
// constant-value inline functions. The MAC_OS_X_VERSION_MIN_REQUIRED macro
// contains the value of the deployment target.

#if defined(MAC_OS_X_VERSION_10_6) && \
    MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
#define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_6
inline bool IsOSLeopard() { return false; }
inline bool IsOSLeopardOrEarlier() { return false; }
inline bool IsOSSnowLeopardOrLater() { return true; }
#endif

#if defined(MAC_OS_X_VERSION_10_7) && \
    MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
#define BASE_MAC_MAC_UTIL_H_INLINED_GE_10_7
inline bool IsOSSnowLeopard() { return false; }
inline bool IsOSSnowLeopardOrEarlier() { return false; }
inline bool IsOSLionOrLater() { return true; }
#endif

#if defined(MAC_OS_X_VERSION_10_7) && \
    MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_7
#define BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7
inline bool IsOSLion() { return false; }
inline bool IsOSLaterThanLion() { return true; }
#endif

}  // namespace mac
}  // namespace base

#endif  // BASE_MAC_MAC_UTIL_H_