MCPcopy Create free account
hub / github.com/SpartanJ/eepp / loadCSS

Method loadCSS

src/eepp/ui/uiscenenode.cpp:1168–1208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1166}
1167
1168void UISceneNode::loadCSS( URI uri ) {
1169 uri = solveRelativePath( uri );
1170 std::string url = uri.toString();
1171 Log::debug( "UISceneNode::loadCSS: %s", url );
1172
1173 if ( "file" == uri.getScheme() ||
1174 ( uri.getScheme().empty() && FileSystem::fileExists( uri.getFSPath() ) ) ) {
1175 std::string filePath( uri.getFSPath() );
1176 std::string css;
1177 if ( FileSystem::fileExists( filePath ) && FileSystem::fileGet( filePath, css ) ) {
1178 combineStyleSheet( css, true, String::hash( url ), getURIFromURL( url ) );
1179 Log::debug( "UISceneNode::loadCSS: Loaded - %s", url );
1180 }
1181 } else if ( "http" == uri.getScheme() || "https" == uri.getScheme() ) {
1182 Http::getAsync(
1183 [this, url]( const Http&, Http::Request&, Http::Response& response ) {
1184 if ( !response.getBody().empty() &&
1185 response.getStatus() == Http::Response::Status::Ok ) {
1186 std::string css( response.getBody() );
1187 runOnMainThread( [css = std::move( css ), url = std::move( url ), this] {
1188 combineStyleSheet( css, true, String::hash( url ), getURIFromURL( url ) );
1189 Log::debug( "UISceneNode::loadCSS: Loaded - %s", url );
1190 } );
1191 } else {
1192 Log::debug( "UISceneNode::loadCSS: Failed to load %s - %s", url,
1193 response.getStatusDescription() );
1194 }
1195 },
1196 uri, Seconds( 5 ) );
1197 } else if ( VFS::instance()->fileExists( uri.getPath() ) ) {
1198 IOStream* stream = VFS::instance()->getFileFromPath( uri.getPath() );
1199 CSS::StyleSheetParser parser;
1200 if ( parser.loadFromStream( *stream ) ) {
1201 parser.getStyleSheet().setMarker( String::hash( url ) );
1202 combineStyleSheet( parser.getStyleSheet() );
1203 Log::debug( "UISceneNode::loadCSS: Loaded - %s", url );
1204 }
1205 } else {
1206 Log::debug( "UISceneNode::loadCSS: Failed to load %s - Unknown scheme", url );
1207 }
1208}
1209
1210void UISceneNode::setInternalPixelsSize( const Sizef& size ) {
1211 Sizef s( size );

Callers

nothing calls this directly

Calls 13

debugFunction · 0.85
hashFunction · 0.85
SecondsFunction · 0.85
getFSPathMethod · 0.80
getStatusDescriptionMethod · 0.80
getFileFromPathMethod · 0.80
toStringMethod · 0.45
emptyMethod · 0.45
getBodyMethod · 0.45
getStatusMethod · 0.45
fileExistsMethod · 0.45
loadFromStreamMethod · 0.45

Tested by

no test coverage detected