Add NativeImage.IsTemplateImage method

* Rename internal function that determines template image filename patterns
* Add the new IsTemplateMethod
This commit is contained in:
Nishanth Shanmugham 2015-07-26 21:58:48 -07:00
parent 7ceca9f426
commit 9211109088
3 changed files with 11 additions and 2 deletions

View file

@ -113,7 +113,7 @@ bool PopulateImageSkiaRepsFromPath(gfx::ImageSkia* image,
}
#if defined(OS_MACOSX)
bool IsTemplateImage(const base::FilePath& path) {
bool IsTemplateFilename(const base::FilePath& path) {
return (MatchPattern(path.value(), "*Template.*") ||
MatchPattern(path.value(), "*Template@*x.*"));
}
@ -139,6 +139,7 @@ mate::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder(
.SetMethod("isEmpty", &NativeImage::IsEmpty)
.SetMethod("getSize", &NativeImage::GetSize)
.SetMethod("setTemplateImage", &NativeImage::SetTemplateImage)
.SetMethod("isTemplateImage", &NativeImage::IsTemplateImage)
.Build());
return mate::ObjectTemplateBuilder(
@ -180,6 +181,8 @@ gfx::Size NativeImage::GetSize() {
#if !defined(OS_MACOSX)
void NativeImage::SetTemplateImage(bool setAsTemplate) {
}
bool NativeImage::IsTemplateImage() {
}
#endif
// static
@ -217,7 +220,7 @@ mate::Handle<NativeImage> NativeImage::CreateFromPath(
gfx::Image image(image_skia);
mate::Handle<NativeImage> handle = Create(isolate, image);
#if defined(OS_MACOSX)
if (IsTemplateImage(path))
if (IsTemplateFilename(path))
handle->SetTemplateImage(true);
#endif
return handle;

View file

@ -67,6 +67,8 @@ class NativeImage : public mate::Wrappable {
// Mark the image as template image.
void SetTemplateImage(bool setAsTemplate);
// Determine if the image is a template image.
bool IsTemplateImage();
gfx::Image image_;

View file

@ -14,6 +14,10 @@ void NativeImage::SetTemplateImage(bool setAsTemplate) {
[image_.AsNSImage() setTemplate:setAsTemplate];
}
bool NativeImage::IsTemplateImage() {
return [image_.AsNSImage() isTemplate];
}
} // namespace api
} // namespace atom