Add support for requiring a platform-specific stylesheet

Add a getPlatform method to the native object that
is used for requiring the platform stylesheet from
within window.coffee after the atom.css is required.

This is used to provide non-native scrollbars on Linux
for an improved look and feel.
This commit is contained in:
Kevin Sawicki
2012-08-01 15:10:17 -07:00
parent dcd42316aa
commit f778345b3a
5 changed files with 33 additions and 2 deletions

View File

@@ -57,7 +57,8 @@ NativeHandler::NativeHandler() :
"absolute", "list", "isFile", "isDirectory", "remove", "asyncList",
"open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard",
"showDevTools", "newWindow", "saveDialog", "exit", "watchPath",
"unwatchPath", "makeDirectory", "move", "moveToTrash", "md5ForPath" };
"unwatchPath", "makeDirectory", "move", "moveToTrash", "md5ForPath",
"getPlatform" };
int arrayLength = sizeof(functionNames) / sizeof(const char *);
for (int i = 0; i < arrayLength; i++) {
const char *functionName = functionNames[i];
@@ -513,6 +514,8 @@ bool NativeHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object,
UnwatchPath(name, object, arguments, retval, exception);
else if (name == "md5ForPath")
Digest(name, object, arguments, retval, exception);
else if (name == "getPlatform")
retval = CefV8Value::CreateString("linux");
else
cout << "Unhandled -> " + name.ToString() << " : "
<< arguments[0]->GetStringValue().ToString() << endl;

View File

@@ -33,7 +33,7 @@ void throwException(const CefRefPtr<CefV8Value>& global, CefRefPtr<CefV8Exceptio
NativeHandler::NativeHandler() : CefV8Handler() {
std::string extensionCode = "var $native = {}; (function() {";
const char *functionNames[] = {"exists", "alert", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "toggleDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath", "makeDirectory", "move", "moveToTrash", "reload", "lastModified", "md5ForPath", "exec"};
const char *functionNames[] = {"exists", "alert", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "toggleDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath", "makeDirectory", "move", "moveToTrash", "reload", "lastModified", "md5ForPath", "exec", "getPlatform"};
NSUInteger arrayLength = sizeof(functionNames) / sizeof(const char *);
for (NSUInteger i = 0; i < arrayLength; i++) {
std::string functionName = std::string(functionNames[i]);
@@ -525,5 +525,11 @@ bool NativeHandler::Execute(const CefString& name,
return true;
}
else if (name == "getPlatform") {
NSString *platform = @"mac";
retval = CefV8Value::CreateString([platform UTF8String]);
return true;
}
return false;
};

View File

@@ -0,0 +1,7 @@
describe 'Native', ->
describe '$native.getPlatform()', ->
it 'returns a non-empty value', ->
platform = $native.getPlatform()
expect(platform).not.toBe ''
expect(platform.length).toBeGreaterThan(0)

View File

@@ -56,6 +56,7 @@ windowAdditions =
requireStylesheet: (path) ->
fullPath = require.resolve(path)
return unless fs.isFile(fullPath)
window.applyStylesheet(fullPath, fs.read(fullPath))
applyStylesheet: (id, text) ->
@@ -106,3 +107,4 @@ require 'underscore-extensions'
requireStylesheet 'reset.css'
requireStylesheet 'atom.css'
requireStylesheet "#{$native.getPlatform()}.css"

13
static/linux.css Normal file
View File

@@ -0,0 +1,13 @@
::-webkit-scrollbar-corner {
background-color: transparent;
}
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-thumb {
-webkit-border-radius: 2px;
background: rgba(150, 150, 150, .33);
}