mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
refactor: add gin_helper::Dictionary::ValueOrDefault() (#46939)
* feat: add gin_helper::Dictionary::ValueOrDefault() A convenience function for using a default value if the specified key isn't present in the dictionary. * refactor: use ValueOrDefault() in native_window.cc * refactor: use ValueOrDefault() in native_window_mac.mm * refactor: use ValueOrDefault() in native_window_views.cc * refactor: use ValueOrDefault() in electron_api_native_image.cc
This commit is contained in:
@@ -382,12 +382,9 @@ gin::Handle<NativeImage> NativeImage::Crop(v8::Isolate* isolate,
|
||||
}
|
||||
|
||||
void NativeImage::AddRepresentation(const gin_helper::Dictionary& options) {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
float scale_factor = 1.0f;
|
||||
options.Get("width", &width);
|
||||
options.Get("height", &height);
|
||||
options.Get("scaleFactor", &scale_factor);
|
||||
const int width = options.ValueOrDefault("width", 0);
|
||||
const int height = options.ValueOrDefault("height", 0);
|
||||
const float scale_factor = options.ValueOrDefault("scaleFactor", 1.0F);
|
||||
|
||||
bool skia_rep_added = false;
|
||||
gfx::ImageSkia image_skia = image_.AsImageSkia();
|
||||
@@ -515,8 +512,7 @@ gin::Handle<NativeImage> NativeImage::CreateFromBitmap(
|
||||
bitmap.allocN32Pixels(width, height, false);
|
||||
bitmap.writePixels({info, buffer_data.data(), bitmap.rowBytes()});
|
||||
|
||||
float scale_factor = 1.0F;
|
||||
options.Get("scaleFactor", &scale_factor);
|
||||
const float scale_factor = options.ValueOrDefault("scaleFactor", 1.0F);
|
||||
gfx::ImageSkia image_skia =
|
||||
gfx::ImageSkia::CreateFromBitmap(bitmap, scale_factor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user