also format missing .cc files

This commit is contained in:
Shelley Vohr 2018-04-17 21:55:30 -04:00
parent 53bdf22c85
commit c6f4bbd143
No known key found for this signature in database
GPG key ID: F13993A75599653C
181 changed files with 4102 additions and 4254 deletions

View file

@ -50,18 +50,10 @@ struct ScaleFactorPair {
};
ScaleFactorPair kScaleFactorPairs[] = {
// The "@2x" is put as first one to make scale matching faster.
{ "@2x" , 2.0f },
{ "@3x" , 3.0f },
{ "@1x" , 1.0f },
{ "@4x" , 4.0f },
{ "@5x" , 5.0f },
{ "@1.25x" , 1.25f },
{ "@1.33x" , 1.33f },
{ "@1.4x" , 1.4f },
{ "@1.5x" , 1.5f },
{ "@1.8x" , 1.8f },
{ "@2.5x" , 2.5f },
// The "@2x" is put as first one to make scale matching faster.
{"@2x", 2.0f}, {"@3x", 3.0f}, {"@1x", 1.0f}, {"@4x", 4.0f},
{"@5x", 5.0f}, {"@1.25x", 1.25f}, {"@1.33x", 1.33f}, {"@1.4x", 1.4f},
{"@1.5x", 1.5f}, {"@1.8x", 1.8f}, {"@2.5x", 2.5f},
};
float GetScaleFactorFromPath(const base::FilePath& path) {
@ -117,7 +109,7 @@ bool AddImageSkiaRep(gfx::ImageSkia* image,
decoded.reset(new SkBitmap);
decoded->allocN32Pixels(width, height, false);
decoded->setPixels(
const_cast<void*>(reinterpret_cast<const void*>(data)));
const_cast<void*>(reinterpret_cast<const void*>(data)));
} else {
return false;
}
@ -154,9 +146,8 @@ bool PopulateImageSkiaRepsFromPath(gfx::ImageSkia* image,
succeed |= AddImageSkiaRep(image, path, 1.0f);
for (const ScaleFactorPair& pair : kScaleFactorPairs)
succeed |= AddImageSkiaRep(image,
path.InsertBeforeExtensionASCII(pair.name),
pair.scale);
succeed |= AddImageSkiaRep(
image, path.InsertBeforeExtensionASCII(pair.name), pair.scale);
return succeed;
}
@ -195,9 +186,9 @@ base::win::ScopedHICON ReadICOFromPath(int size, const base::FilePath& path) {
}
// Load the icon from file.
return base::win::ScopedHICON(static_cast<HICON>(
LoadImage(NULL, image_path.value().c_str(), IMAGE_ICON, size, size,
LR_LOADFROMFILE)));
return base::win::ScopedHICON(
static_cast<HICON>(LoadImage(NULL, image_path.value().c_str(), IMAGE_ICON,
size, size, LR_LOADFROMFILE)));
}
bool ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) {
@ -211,8 +202,7 @@ bool ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) {
}
#endif
void Noop(char*, void*) {
}
void Noop(char*, void*) {}
} // namespace
@ -221,7 +211,7 @@ NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image)
Init(isolate);
if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) {
isolate->AdjustAmountOfExternalAllocatedMemory(
image_.ToImageSkia()->bitmap()->computeByteSize());
image_.ToImageSkia()->bitmap()->computeByteSize());
}
}
@ -235,15 +225,15 @@ NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path)
Init(isolate);
if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) {
isolate->AdjustAmountOfExternalAllocatedMemory(
image_.ToImageSkia()->bitmap()->computeByteSize());
image_.ToImageSkia()->bitmap()->computeByteSize());
}
}
#endif
NativeImage::~NativeImage() {
if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) {
isolate()->AdjustAmountOfExternalAllocatedMemory(
-static_cast<int64_t>(image_.ToImageSkia()->bitmap()->computeByteSize()));
isolate()->AdjustAmountOfExternalAllocatedMemory(-static_cast<int64_t>(
image_.ToImageSkia()->bitmap()->computeByteSize()));
}
}
@ -262,8 +252,8 @@ HICON NativeImage::GetHICON(int size) {
// Then convert the image to ICO.
if (image_.IsEmpty())
return NULL;
hicons_[size] = std::move(
IconUtil::CreateHICONFromSkBitmap(image_.AsBitmap()));
hicons_[size] =
std::move(IconUtil::CreateHICONFromSkBitmap(image_.AsBitmap()));
return hicons_[size].get();
}
#endif
@ -300,7 +290,8 @@ v8::Local<v8::Value> NativeImage::ToBitmap(mate::Arguments* args) {
return node::Buffer::New(args->isolate(), 0).ToLocalChecked();
return node::Buffer::Copy(args->isolate(),
reinterpret_cast<const char*>(ref->pixels()),
bitmap.computeByteSize()).ToLocalChecked();
bitmap.computeByteSize())
.ToLocalChecked();
}
v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
@ -308,10 +299,10 @@ v8::Local<v8::Value> NativeImage::ToJPEG(v8::Isolate* isolate, int quality) {
gfx::JPEG1xEncodedDataFromImage(image_, quality, &output);
if (output.empty())
return node::Buffer::New(isolate, 0).ToLocalChecked();
return node::Buffer::Copy(
isolate,
reinterpret_cast<const char*>(&output.front()),
output.size()).ToLocalChecked();
return node::Buffer::Copy(isolate,
reinterpret_cast<const char*>(&output.front()),
output.size())
.ToLocalChecked();
}
std::string NativeImage::ToDataURL(mate::Arguments* args) {
@ -338,21 +329,20 @@ v8::Local<v8::Value> NativeImage::GetBitmap(mate::Arguments* args) {
return node::Buffer::New(args->isolate(), 0).ToLocalChecked();
return node::Buffer::New(args->isolate(),
reinterpret_cast<char*>(ref->pixels()),
bitmap.computeByteSize(),
&Noop,
nullptr).ToLocalChecked();
bitmap.computeByteSize(), &Noop, nullptr)
.ToLocalChecked();
}
v8::Local<v8::Value> NativeImage::GetNativeHandle(v8::Isolate* isolate,
mate::Arguments* args) {
#if defined(OS_MACOSX)
if (IsEmpty()) return node::Buffer::New(isolate, 0).ToLocalChecked();
if (IsEmpty())
return node::Buffer::New(isolate, 0).ToLocalChecked();
NSImage* ptr = image_.AsNSImage();
return node::Buffer::Copy(
isolate,
reinterpret_cast<char*>(ptr),
sizeof(void*)).ToLocalChecked();
return node::Buffer::Copy(isolate, reinterpret_cast<char*>(ptr),
sizeof(void*))
.ToLocalChecked();
#else
args->ThrowError("Not implemented");
return v8::Undefined(isolate);
@ -376,7 +366,8 @@ float NativeImage::GetAspectRatio() {
}
mate::Handle<NativeImage> NativeImage::Resize(
v8::Isolate* isolate, const base::DictionaryValue& options) {
v8::Isolate* isolate,
const base::DictionaryValue& options) {
gfx::Size size = GetSize();
int width = size.width();
int height = size.height();
@ -411,8 +402,8 @@ mate::Handle<NativeImage> NativeImage::Resize(
mate::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
const gfx::Rect& rect) {
gfx::ImageSkia cropped = gfx::ImageSkiaOperations::ExtractSubset(
image_.AsImageSkia(), rect);
gfx::ImageSkia cropped =
gfx::ImageSkiaOperations::ExtractSubset(image_.AsImageSkia(), rect);
return mate::CreateHandle(isolate,
new NativeImage(isolate, gfx::Image(cropped)));
}
@ -434,18 +425,15 @@ void NativeImage::AddRepresentation(const mate::Dictionary& options) {
AddImageSkiaRep(
&image_skia,
reinterpret_cast<unsigned char*>(node::Buffer::Data(buffer)),
node::Buffer::Length(buffer),
width, height, scale_factor);
node::Buffer::Length(buffer), width, height, scale_factor);
skia_rep_added = true;
} else if (options.Get("dataURL", &url)) {
std::string mime_type, charset, data;
if (net::DataURL::Parse(url, &mime_type, &charset, &data)) {
if (mime_type == "image/png" || mime_type == "image/jpeg") {
AddImageSkiaRep(
&image_skia,
reinterpret_cast<const unsigned char*>(data.c_str()),
data.size(),
width, height, scale_factor);
AddImageSkiaRep(&image_skia,
reinterpret_cast<const unsigned char*>(data.c_str()),
data.size(), width, height, scale_factor);
skia_rep_added = true;
}
}
@ -459,8 +447,7 @@ void NativeImage::AddRepresentation(const mate::Dictionary& options) {
}
#if !defined(OS_MACOSX)
void NativeImage::SetTemplateImage(bool setAsTemplate) {
}
void NativeImage::SetTemplateImage(bool setAsTemplate) {}
bool NativeImage::IsTemplateImage() {
return false;
@ -473,22 +460,24 @@ mate::Handle<NativeImage> NativeImage::CreateEmpty(v8::Isolate* isolate) {
}
// static
mate::Handle<NativeImage> NativeImage::Create(
v8::Isolate* isolate, const gfx::Image& image) {
mate::Handle<NativeImage> NativeImage::Create(v8::Isolate* isolate,
const gfx::Image& image) {
return mate::CreateHandle(isolate, new NativeImage(isolate, image));
}
// static
mate::Handle<NativeImage> NativeImage::CreateFromPNG(
v8::Isolate* isolate, const char* buffer, size_t length) {
mate::Handle<NativeImage> NativeImage::CreateFromPNG(v8::Isolate* isolate,
const char* buffer,
size_t length) {
gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(
reinterpret_cast<const unsigned char*>(buffer), length);
return Create(isolate, image);
}
// static
mate::Handle<NativeImage> NativeImage::CreateFromJPEG(
v8::Isolate* isolate, const char* buffer, size_t length) {
mate::Handle<NativeImage> NativeImage::CreateFromJPEG(v8::Isolate* isolate,
const char* buffer,
size_t length) {
gfx::Image image = gfx::ImageFrom1xJPEGEncodedData(
reinterpret_cast<const unsigned char*>(buffer), length);
return Create(isolate, image);
@ -496,12 +485,12 @@ mate::Handle<NativeImage> NativeImage::CreateFromJPEG(
// static
mate::Handle<NativeImage> NativeImage::CreateFromPath(
v8::Isolate* isolate, const base::FilePath& path) {
v8::Isolate* isolate,
const base::FilePath& path) {
base::FilePath image_path = NormalizePath(path);
#if defined(OS_WIN)
if (image_path.MatchesExtension(FILE_PATH_LITERAL(".ico"))) {
return mate::CreateHandle(isolate,
new NativeImage(isolate, image_path));
return mate::CreateHandle(isolate, new NativeImage(isolate, image_path));
}
#endif
gfx::ImageSkia image_skia;
@ -517,7 +506,8 @@ mate::Handle<NativeImage> NativeImage::CreateFromPath(
// static
mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
mate::Arguments* args, v8::Local<v8::Value> buffer) {
mate::Arguments* args,
v8::Local<v8::Value> buffer) {
int width = 0;
int height = 0;
double scale_factor = 1.;
@ -535,16 +525,13 @@ mate::Handle<NativeImage> NativeImage::CreateFromBuffer(
gfx::ImageSkia image_skia;
AddImageSkiaRep(&image_skia,
reinterpret_cast<unsigned char*>(node::Buffer::Data(buffer)),
node::Buffer::Length(buffer),
width,
height,
scale_factor);
node::Buffer::Length(buffer), width, height, scale_factor);
return Create(args->isolate(), gfx::Image(image_skia));
}
// static
mate::Handle<NativeImage> NativeImage::CreateFromDataURL(
v8::Isolate* isolate, const GURL& url) {
mate::Handle<NativeImage> NativeImage::CreateFromDataURL(v8::Isolate* isolate,
const GURL& url) {
std::string mime_type, charset, data;
if (net::DataURL::Parse(url, &mime_type, &charset, &data)) {
if (mime_type == "image/png")
@ -558,14 +545,15 @@ mate::Handle<NativeImage> NativeImage::CreateFromDataURL(
#if !defined(OS_MACOSX)
mate::Handle<NativeImage> NativeImage::CreateFromNamedImage(
mate::Arguments* args, const std::string& name) {
mate::Arguments* args,
const std::string& name) {
return CreateEmpty(args->isolate());
}
#endif
// static
void NativeImage::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
void NativeImage::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "NativeImage"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("toPNG", &NativeImage::ToPNG)
@ -597,7 +585,8 @@ v8::Local<v8::Value> Converter<mate::Handle<atom::api::NativeImage>>::ToV8(
}
bool Converter<mate::Handle<atom::api::NativeImage>>::FromV8(
v8::Isolate* isolate, v8::Local<v8::Value> val,
v8::Isolate* isolate,
v8::Local<v8::Value> val,
mate::Handle<atom::api::NativeImage>* out) {
// Try converting from file path.
base::FilePath path;
@ -607,8 +596,8 @@ bool Converter<mate::Handle<atom::api::NativeImage>>::FromV8(
return !(*out)->image().IsEmpty();
}
WrappableBase* wrapper = static_cast<WrappableBase*>(internal::FromV8Impl(
isolate, val));
WrappableBase* wrapper =
static_cast<WrappableBase*>(internal::FromV8Impl(isolate, val));
if (!wrapper)
return false;
@ -620,8 +609,10 @@ bool Converter<mate::Handle<atom::api::NativeImage>>::FromV8(
namespace {
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("createEmpty", &atom::api::NativeImage::CreateEmpty);
dict.SetMethod("createFromPath", &atom::api::NativeImage::CreateFromPath);