Esempio n. 1
0
OpBitmap* IconUtils::GetBitmap(const UINT8* buffer, UINT32 buffer_size, int width, int height)
{
	FileImageContentProvider provider;
	Image image;

	provider.LoadFromBuffer(buffer, buffer_size, image);

	OpBitmap* loaded_bitmap = image.GetBitmap(NULL);
	if (!loaded_bitmap)
	{
		image.DecVisible(null_image_listener);
		return 0;
	}

	int src_width  = loaded_bitmap->Width();
	int src_height = loaded_bitmap->Height();
	if (src_width <= 0 || src_height <= 0)
	{
		image.DecVisible(null_image_listener);
		return 0;
	}
	if (width<=0)
		width = src_width;

	if (height<=0)
		height = src_height;

	OpBitmap* bitmap = 0;
	OP_STATUS rc = OpBitmap::Create(&bitmap, width, height, loaded_bitmap->IsTransparent(), loaded_bitmap->HasAlpha(), 0, 0, TRUE);
	if (OpStatus::IsError(rc))
	{
		image.ReleaseBitmap();
		image.DecVisible(null_image_listener);
		return 0;
	}

	OpPainter* painter = bitmap->GetPainter();
	if (!painter)
	{
		image.ReleaseBitmap();
		image.DecVisible(null_image_listener);
		OP_DELETE(bitmap);
		return 0;
	}

	painter->ClearRect(OpRect(0,0,width,height));
	painter->DrawBitmapScaled(loaded_bitmap, OpRect(0,0,src_width,src_height), OpRect(0,0,width,height));

	bitmap->ReleasePainter();

	image.ReleaseBitmap();
	image.DecVisible(null_image_listener);
	return bitmap;
}
Esempio n. 2
0
void HEListElm::Undisplay()
{
	if (GetImageVisible())
	{
		Image img = GetImage();

#ifdef HAS_ATVEF_SUPPORT
		if (img.IsAtvefImage())
		{
			if (g_tvManager)
			{
				URL tv_url = GetElm()->GetImageURL(FALSE, doc->GetLogicalDocument());
				g_tvManager->OnTvWindowAvailable(&tv_url, FALSE);
			}

			SetImageVisible(FALSE);
			return;
		}
#endif

		if (!img.IsEmpty())
		{
			if (animation_handler)
			{
				animation_handler->DecRef(this);
				animation_handler = NULL;
			}

			image_last_decoded_height = 0;
			img.DecVisible(this);
		}
	}

	SetImageVisible(FALSE);
}
Esempio n. 3
0
OP_STATUS HEListElm::SendImageFinishedLoadingEvent(FramesDocument* doc)
{
	OP_ASSERT(doc);
	OP_ASSERT(!GetEventSent());

	if (inline_type == IMAGE_INLINE && HElm()->GetInserted() == HE_INSERTED_BY_PARSE_AHEAD)
	{
		HElm()->SetSpecialBoolAttr(ATTR_JS_DELAYED_ONLOAD, TRUE, SpecialNs::NS_LOGDOC);
		return OpStatus::OK;
	}

	// Since this requires decoding the image, skip it if there are no event listeners
	if (inline_type == IMAGE_INLINE &&
		(GetElm()->HasEventHandler(doc, ONLOAD) || GetElm()->HasEventHandler(doc, ONERROR)))
	{
		LoadInlineElm* lie = GetLoadInlineElm();
		OP_ASSERT(lie);
		URLStatus url_status = lie->GetUrl()->Status(TRUE);
		if (url_status == URL_LOADED)
		{
#ifdef SVG_SUPPORT
			// If it is an svg image wait with sending onerror or
			// onload until it has been parsed.
			if (lie->GetUrl()->ContentType() == URL_SVG_CONTENT)
				return OpStatus::OK;
#endif // SVG_SUPPORT

			Image img = GetImage();
			// IsAnimated() implies that the first frame is decoded which is good enough for us.
			if (img.ImageDecoded() || img.IsAnimated())
				return OnLoad();

			if (GetUrlContentProvider() && !GetImageVisible())
			{
				/* Force image decoding, so that we can send onload or onerror as appropriate. */
				OP_STATUS status = img.IncVisible(this);
				if (OpStatus::IsSuccess(status))
				{
					// Scripts might load image in a hidden place and move
					// on load, in which case we don't want image to be
					// re-decoded.
					ImageManager::GraceTimeLock lock(imgManager);

					// This will send onload or onerror through the ImageListener callbacks (OnError and OnPortionDecoded).
					// except for animated images since only the first frame will be decoded.
					status = img.OnLoadAll(GetUrlContentProvider());
					img.DecVisible(this);
					OP_ASSERT(GetEventSent());
				}
				return status;
			}
		}
		else if (url_status == URL_LOADING_FAILURE)
			SendOnError();
	}
	return OpStatus::OK;
}