mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add AtomController
This commit is contained in:
4
atom.gyp
4
atom.gyp
@@ -47,6 +47,8 @@
|
||||
'atom/main_mac.mm',
|
||||
'atom/atom_mac.h',
|
||||
'atom/atom_mac.mm',
|
||||
'atom/atom_controller.h',
|
||||
'atom/atom_controller.mm',
|
||||
'atom/client_handler_mac.mm',
|
||||
'atom/client_handler.cpp',
|
||||
'atom/client_handler.h',
|
||||
@@ -55,7 +57,7 @@
|
||||
'mac_bundle_resources': [
|
||||
'atom/mac/atom.icns',
|
||||
'atom/mac/English.lproj/MainMenu.xib',
|
||||
'atom/mac/info.plist',
|
||||
'atom/mac/English.lproj/AtomWindow.xib',
|
||||
],
|
||||
'xcode_settings': {
|
||||
'INFOPLIST_FILE': 'atom/mac/info.plist',
|
||||
|
||||
14
atom/atom_controller.h
Normal file
14
atom/atom_controller.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "include/cef_app.h"
|
||||
|
||||
class ClientHandler;
|
||||
|
||||
@interface AtomController : NSWindowController <NSWindowDelegate> {
|
||||
CefRefPtr<ClientHandler> _clientHandler;
|
||||
NSView *_webView;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) IBOutlet NSView *webView;
|
||||
|
||||
- (void)populateBrowserSettings:(CefBrowserSettings &)settings;
|
||||
|
||||
@end
|
||||
87
atom/atom_controller.mm
Normal file
87
atom/atom_controller.mm
Normal file
@@ -0,0 +1,87 @@
|
||||
#import "include/cef_application_mac.h"
|
||||
#import "atom/client_handler.h"
|
||||
#import "atom/atom_controller.h"
|
||||
|
||||
@implementation AtomController
|
||||
|
||||
@synthesize webView=_webView;
|
||||
|
||||
- (void)dealloc {
|
||||
[_webView release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
self = [super initWithWindowNibName:@"AtomWindow"];
|
||||
|
||||
_clientHandler = new ClientHandler();
|
||||
|
||||
CefWindowInfo window_info;
|
||||
CefBrowserSettings settings;
|
||||
|
||||
[self populateBrowserSettings:settings];
|
||||
|
||||
window_info.SetAsChild(self.webView, self.webView.bounds.origin.x, self.webView.bounds.origin.y, self.webView.bounds.size.width, self.webView.bounds.size.height);
|
||||
CefBrowserHost::CreateBrowser(window_info, _clientHandler.get(), "http://reddit.com", settings);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
# pragma mark NSWindowDelegate
|
||||
|
||||
- (void)windowDidBecomeKey:(NSNotification*)notification {
|
||||
if (_clientHandler.get() && _clientHandler->GetBrowserId()) {
|
||||
_clientHandler->GetBrowser()->GetHost()->SetFocus(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean ourselves up after clearing the stack of anything that might have the window on it.
|
||||
- (BOOL)windowShouldClose:(id)window {
|
||||
_clientHandler = NULL;
|
||||
|
||||
[window autorelease];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)populateBrowserSettings:(CefBrowserSettings &)settings {
|
||||
CefString(&settings.default_encoding) = "UTF-8";
|
||||
settings.remote_fonts_disabled = true;
|
||||
settings.encoding_detector_enabled = false;
|
||||
settings.javascript_disabled = false;
|
||||
settings.javascript_open_windows_disallowed = true;
|
||||
settings.javascript_close_windows_disallowed = false;
|
||||
settings.javascript_access_clipboard_disallowed = false;
|
||||
settings.dom_paste_disabled = true;
|
||||
settings.caret_browsing_enabled = false;
|
||||
settings.java_disabled = true;
|
||||
settings.plugins_disabled = true;
|
||||
settings.universal_access_from_file_urls_allowed = false;
|
||||
settings.file_access_from_file_urls_allowed = false;
|
||||
settings.web_security_disabled = false;
|
||||
settings.xss_auditor_enabled = true;
|
||||
settings.image_load_disabled = false;
|
||||
settings.shrink_standalone_images_to_fit = false;
|
||||
settings.site_specific_quirks_disabled = false;
|
||||
settings.text_area_resize_disabled = false;
|
||||
settings.page_cache_disabled = true;
|
||||
settings.tab_to_links_disabled = true;
|
||||
settings.hyperlink_auditing_disabled = true;
|
||||
settings.user_style_sheet_enabled = false;
|
||||
settings.author_and_user_styles_disabled = false;
|
||||
settings.local_storage_disabled = false;
|
||||
settings.databases_disabled = false;
|
||||
settings.application_cache_disabled = false;
|
||||
settings.webgl_disabled = false;
|
||||
settings.accelerated_compositing_disabled = false;
|
||||
settings.accelerated_layers_disabled = false;
|
||||
settings.accelerated_video_disabled = false;
|
||||
settings.accelerated_2d_canvas_disabled = false;
|
||||
settings.accelerated_painting_enabled = true;
|
||||
settings.accelerated_filters_enabled = true;
|
||||
settings.accelerated_plugins_disabled = false;
|
||||
settings.developer_tools_disabled = false;
|
||||
settings.fullscreen_enabled = true;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,12 +1,11 @@
|
||||
#include "include/cef_app.h"
|
||||
|
||||
@interface Atom : NSApplication <CefAppProtocol, NSWindowDelegate, NSApplicationDelegate> {
|
||||
@interface Atom : NSApplication <CefAppProtocol, NSApplicationDelegate> {
|
||||
@private
|
||||
BOOL handlingSendEvent_;
|
||||
}
|
||||
|
||||
+ (void)populateAppSettings:(CefSettings &)settings;
|
||||
- (void)createWindow;
|
||||
- (void)populateBrowserSettings:(CefBrowserSettings &)settings;
|
||||
|
||||
@end
|
||||
@@ -1,9 +1,7 @@
|
||||
#import "include/cef_application_mac.h"
|
||||
#import "atom/client_handler.h"
|
||||
#import "atom/atom_mac.h"
|
||||
|
||||
// The global ClientHandler reference.
|
||||
extern CefRefPtr<ClientHandler> g_handler;
|
||||
#import "atom/atom_controller.h"
|
||||
|
||||
@implementation Atom
|
||||
|
||||
@@ -33,85 +31,13 @@ extern CefRefPtr<ClientHandler> g_handler;
|
||||
|
||||
// Create the application on the UI thread.
|
||||
- (void)createWindow {
|
||||
// Create the main application window.
|
||||
NSRect window_rect = { {0, 0}, {800, 800} };
|
||||
NSWindow* mainWnd = [[UnderlayOpenGLHostingWindow alloc]
|
||||
initWithContentRect:window_rect
|
||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask )
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
[mainWnd setTitle:@"cefclient"];
|
||||
[mainWnd setDelegate:self];
|
||||
|
||||
// Rely on the window delegate to clean us up rather than immediately
|
||||
// releasing when the window gets closed. We use the delegate to do
|
||||
// everything from the autorelease pool so the window isn't on the stack
|
||||
// during cleanup (ie, a window close from javascript).
|
||||
[mainWnd setReleasedWhenClosed:NO];
|
||||
|
||||
NSView* contentView = [mainWnd contentView];
|
||||
|
||||
// Create the handler.
|
||||
g_handler = new ClientHandler();
|
||||
g_handler->SetMainHwnd(contentView);
|
||||
|
||||
// Create the browser view.
|
||||
CefWindowInfo window_info;
|
||||
CefBrowserSettings settings;
|
||||
|
||||
[self populateBrowserSettings:settings];
|
||||
|
||||
window_info.SetAsChild(contentView, window_rect.origin.x, window_rect.origin.y, window_rect.size.width, window_rect.size.height);
|
||||
CefBrowserHost::CreateBrowser(window_info, g_handler.get(), g_handler->GetStartupURL(), settings);
|
||||
|
||||
[mainWnd makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
- (void)populateBrowserSettings:(CefBrowserSettings &)settings {
|
||||
CefString(&settings.default_encoding) = "UTF-8";
|
||||
settings.remote_fonts_disabled = true;
|
||||
settings.encoding_detector_enabled = false;
|
||||
settings.javascript_disabled = false;
|
||||
settings.javascript_open_windows_disallowed = true;
|
||||
settings.javascript_close_windows_disallowed = false;
|
||||
settings.javascript_access_clipboard_disallowed = false;
|
||||
settings.dom_paste_disabled = true;
|
||||
settings.caret_browsing_enabled = false;
|
||||
settings.java_disabled = true;
|
||||
settings.plugins_disabled = true;
|
||||
settings.universal_access_from_file_urls_allowed = false;
|
||||
settings.file_access_from_file_urls_allowed = false;
|
||||
settings.web_security_disabled = false;
|
||||
settings.xss_auditor_enabled = true;
|
||||
settings.image_load_disabled = false;
|
||||
settings.shrink_standalone_images_to_fit = false;
|
||||
settings.site_specific_quirks_disabled = false;
|
||||
settings.text_area_resize_disabled = false;
|
||||
settings.page_cache_disabled = true;
|
||||
settings.tab_to_links_disabled = true;
|
||||
settings.hyperlink_auditing_disabled = true;
|
||||
settings.user_style_sheet_enabled = false;
|
||||
settings.author_and_user_styles_disabled = false;
|
||||
settings.local_storage_disabled = false;
|
||||
settings.databases_disabled = false;
|
||||
settings.application_cache_disabled = false;
|
||||
settings.webgl_disabled = false;
|
||||
settings.accelerated_compositing_disabled = false;
|
||||
settings.accelerated_layers_disabled = false;
|
||||
settings.accelerated_video_disabled = false;
|
||||
settings.accelerated_2d_canvas_disabled = false;
|
||||
settings.accelerated_painting_enabled = true;
|
||||
settings.accelerated_filters_enabled = true;
|
||||
settings.accelerated_plugins_disabled = false;
|
||||
settings.developer_tools_disabled = false;
|
||||
settings.fullscreen_enabled = true;
|
||||
AtomController *controller = [[AtomController alloc] init];
|
||||
}
|
||||
|
||||
# pragma mark NSApplicationDelegate
|
||||
|
||||
// Sent by the default notification center immediately before the application terminates.
|
||||
- (void)applicationWillTerminate:(NSNotification *)notification {
|
||||
g_handler = NULL; // Shut down CEF.
|
||||
CefShutdown();
|
||||
[self release];
|
||||
}
|
||||
@@ -131,22 +57,4 @@ extern CefRefPtr<ClientHandler> g_handler;
|
||||
[super sendEvent:event];
|
||||
}
|
||||
|
||||
# pragma mark NSWindowDelegate
|
||||
|
||||
- (void)windowDidBecomeKey:(NSNotification*)notification {
|
||||
if (g_handler.get() && g_handler->GetBrowserId()) {
|
||||
g_handler->GetBrowser()->GetHost()->SetFocus(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean ourselves up after clearing the stack of anything that might have the window on it.
|
||||
- (BOOL)windowShouldClose:(id)window {
|
||||
[window autorelease];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@end
|
||||
179
atom/mac/English.lproj/AtomWindow.xib
Normal file
179
atom/mac/English.lproj/AtomWindow.xib
Normal file
@@ -0,0 +1,179 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">1070</int>
|
||||
<string key="IBDocument.SystemVersion">11E53</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">2549</string>
|
||||
<string key="IBDocument.AppKitVersion">1138.47</string>
|
||||
<string key="IBDocument.HIToolboxVersion">569.00</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="NS.object.0">2549</string>
|
||||
</object>
|
||||
<array key="IBDocument.IntegratedClassDependencies">
|
||||
<string>NSCustomObject</string>
|
||||
<string>NSView</string>
|
||||
<string>NSWindowTemplate</string>
|
||||
</array>
|
||||
<array key="IBDocument.PluginDependencies">
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
</array>
|
||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
||||
<string key="NS.key.0">PluginDependencyRecalculationVersion</string>
|
||||
<integer value="1" key="NS.object.0"/>
|
||||
</object>
|
||||
<array class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
|
||||
<object class="NSCustomObject" id="1001">
|
||||
<string key="NSClassName">AtomController</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="1003">
|
||||
<string key="NSClassName">FirstResponder</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="1004">
|
||||
<string key="NSClassName">Atom</string>
|
||||
</object>
|
||||
<object class="NSWindowTemplate" id="1005">
|
||||
<int key="NSWindowStyleMask">15</int>
|
||||
<int key="NSWindowBacking">2</int>
|
||||
<string key="NSWindowRect">{{1688, 510}, {800, 800}}</string>
|
||||
<int key="NSWTFlags">1618478080</int>
|
||||
<string key="NSWindowTitle">Window</string>
|
||||
<string key="NSWindowClass">NSWindow</string>
|
||||
<nil key="NSViewClass"/>
|
||||
<nil key="NSUserInterfaceItemIdentifier"/>
|
||||
<object class="NSView" key="NSWindowView" id="1006">
|
||||
<reference key="NSNextResponder"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<string key="NSFrameSize">{800, 800}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
<reference key="NSWindow"/>
|
||||
</object>
|
||||
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
|
||||
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
|
||||
<int key="NSWindowCollectionBehavior">128</int>
|
||||
<bool key="NSWindowIsRestorable">NO</bool>
|
||||
</object>
|
||||
</array>
|
||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
||||
<array class="NSMutableArray" key="connectionRecords">
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">webView</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="1006"/>
|
||||
</object>
|
||||
<int key="connectionID">4</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">window</string>
|
||||
<reference key="source" ref="1001"/>
|
||||
<reference key="destination" ref="1005"/>
|
||||
</object>
|
||||
<int key="connectionID">5</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">delegate</string>
|
||||
<reference key="source" ref="1005"/>
|
||||
<reference key="destination" ref="1001"/>
|
||||
</object>
|
||||
<int key="connectionID">3</int>
|
||||
</object>
|
||||
</array>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<array key="orderedObjects">
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">0</int>
|
||||
<array key="object" id="0"/>
|
||||
<reference key="children" ref="1000"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-2</int>
|
||||
<reference key="object" ref="1001"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">File's Owner</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-1</int>
|
||||
<reference key="object" ref="1003"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">First Responder</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-3</int>
|
||||
<reference key="object" ref="1004"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">Application</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">1</int>
|
||||
<reference key="object" ref="1005"/>
|
||||
<array class="NSMutableArray" key="children">
|
||||
<reference ref="1006"/>
|
||||
</array>
|
||||
<reference key="parent" ref="0"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">2</int>
|
||||
<reference key="object" ref="1006"/>
|
||||
<reference key="parent" ref="1005"/>
|
||||
</object>
|
||||
</array>
|
||||
</object>
|
||||
<dictionary class="NSMutableDictionary" key="flattenedProperties">
|
||||
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<boolean value="YES" key="1.IBNSWindowAutoPositionCentersHorizontal"/>
|
||||
<boolean value="YES" key="1.IBNSWindowAutoPositionCentersVertical"/>
|
||||
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string key="1.IBWindowTemplateEditedContentRect">{{357, 418}, {480, 270}}</string>
|
||||
<integer value="1" key="1.NSWindowTemplate.visibleAtLaunch"/>
|
||||
<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
</dictionary>
|
||||
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
|
||||
<nil key="activeLocalization"/>
|
||||
<dictionary class="NSMutableDictionary" key="localizations"/>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">5</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">Atom</string>
|
||||
<string key="superclassName">NSApplication</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">./Classes/Atom.h</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">AtomController</string>
|
||||
<string key="superclassName">NSWindowController</string>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<string key="NS.key.0">webView</string>
|
||||
<string key="NS.object.0">NSView</string>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
|
||||
<string key="NS.key.0">webView</string>
|
||||
<object class="IBToOneOutletInfo" key="NS.object.0">
|
||||
<string key="name">webView</string>
|
||||
<string key="candidateClassName">NSView</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">./Classes/AtomController.h</string>
|
||||
</object>
|
||||
</object>
|
||||
</array>
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
|
||||
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
<bool key="IBDocument.UseAutolayout">YES</bool>
|
||||
</data>
|
||||
</archive>
|
||||
Reference in New Issue
Block a user