OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/platform_util.h" | 5 #include "chrome/common/platform_util.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/l10n_util_mac.h" | 10 #include "app/l10n_util_mac.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/mac_util.h" | 13 #include "base/mac_util.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 #include "chrome/browser/cocoa/tab_window_controller.h" | |
16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
17 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
18 | 17 |
19 namespace platform_util { | 18 namespace platform_util { |
20 | 19 |
21 void ShowItemInFolder(const FilePath& full_path) { | 20 void ShowItemInFolder(const FilePath& full_path) { |
22 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); | 21 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); |
23 NSString* path_string = base::SysUTF8ToNSString(full_path.value()); | 22 NSString* path_string = base::SysUTF8ToNSString(full_path.value()); |
24 if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string | 23 if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string |
25 inFileViewerRootedAtPath:nil]) | 24 inFileViewerRootedAtPath:nil]) |
(...skipping 12 matching lines...) Expand all Loading... |
38 NSString* url_string = base::SysUTF8ToNSString(url.spec()); | 37 NSString* url_string = base::SysUTF8ToNSString(url.spec()); |
39 NSURL* ns_url = [NSURL URLWithString:url_string]; | 38 NSURL* ns_url = [NSURL URLWithString:url_string]; |
40 if (!ns_url || ![[NSWorkspace sharedWorkspace] openURL:ns_url]) | 39 if (!ns_url || ![[NSWorkspace sharedWorkspace] openURL:ns_url]) |
41 LOG(WARNING) << "NSWorkspace failed to open URL " << url; | 40 LOG(WARNING) << "NSWorkspace failed to open URL " << url; |
42 } | 41 } |
43 | 42 |
44 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { | 43 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { |
45 return [view window]; | 44 return [view window]; |
46 } | 45 } |
47 | 46 |
48 string16 GetWindowTitle(gfx::NativeWindow window) { | |
49 NSString* title = nil; | |
50 if ([[window delegate] isKindOfClass:[TabWindowController class]]) { | |
51 TabWindowController* delegate = | |
52 reinterpret_cast<TabWindowController*>([window delegate]); | |
53 title = [delegate selectedTabTitle]; | |
54 } else { | |
55 title = [window title]; | |
56 } | |
57 // If we don't yet have a title, use "Untitled". | |
58 if (![title length]) | |
59 return WideToUTF16(l10n_util::GetString( | |
60 IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED)); | |
61 | |
62 return base::SysNSStringToUTF16(title); | |
63 } | |
64 | |
65 bool IsWindowActive(gfx::NativeWindow window) { | 47 bool IsWindowActive(gfx::NativeWindow window) { |
66 return [window isKeyWindow] || [window isMainWindow]; | 48 return [window isKeyWindow] || [window isMainWindow]; |
67 } | 49 } |
68 | 50 |
69 bool IsVisible(gfx::NativeView view) { | 51 bool IsVisible(gfx::NativeView view) { |
70 // A reasonable approximation of how you'd expect this to behave. | 52 // A reasonable approximation of how you'd expect this to behave. |
71 return (view && | 53 return (view && |
72 ![view isHiddenOrHasHiddenAncestor] && | 54 ![view isHiddenOrHasHiddenAncestor] && |
73 [view window] && | 55 [view window] && |
74 [[view window] isVisible]); | 56 [[view window] isVisible]); |
(...skipping 23 matching lines...) Expand all Loading... |
98 channel = @"unknown"; | 80 channel = @"unknown"; |
99 } | 81 } |
100 | 82 |
101 return base::SysNSStringToUTF16(channel); | 83 return base::SysNSStringToUTF16(channel); |
102 #else | 84 #else |
103 return string16(); | 85 return string16(); |
104 #endif | 86 #endif |
105 } | 87 } |
106 | 88 |
107 } // namespace platform_util | 89 } // namespace platform_util |
OLD | NEW |