refactor: add gin_helper::Dictionary::ValueOrDefault()
(#46968)
* feat: add gin_helper::Dictionary::ValueOrDefault() A convenience function for using a default value if the specified key isn't present in the dictionary. Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: use ValueOrDefault() in native_window.cc Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: use ValueOrDefault() in native_window_mac.mm Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: use ValueOrDefault() in native_window_views.cc Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: use ValueOrDefault() in electron_api_native_image.cc Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
7779b6a4ad
commit
366daf192a
5 changed files with 48 additions and 54 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue