Bug 1315660 - Fixed upscaling of drag and drop thumbnail. r=spohl

MozReview-Commit-ID: 9M2zIrce3Lj

--HG--
extra : rebase_source : 8f92ecd3095d71b0de03d7c43a2374f501193ea4
This commit is contained in:
Moritz Brunner 2017-10-18 19:16:03 +02:00
Родитель 82905af7f5
Коммит 2d522890a3
2 изменённых файлов: 19 добавлений и 12 удалений

Просмотреть файл

@ -4975,7 +4975,7 @@ PresShell::PaintRangePaintInfo(const nsTArray<UniquePtr<RangePaintInfo>>& aItems
// use the rectangle to create the surface
nsIntRect pixelArea = aArea.ToOutsidePixels(pc->AppUnitsPerDevPixel());
// if the image should not be resized, the scale, relative to the original image, must be 1
// if the image should not be resized, scale must be 1
float scale = 1.0;
nsIntRect rootScreenRect =
GetRootFrame()->GetScreenRectInAppUnits().ToNearestPixels(
@ -4997,21 +4997,23 @@ PresShell::PaintRangePaintInfo(const nsTArray<UniquePtr<RangePaintInfo>>& aItems
// get best height/width relative to screensize
float bestHeight = float(maxHeight)*RELATIVE_SCALEFACTOR;
float bestWidth = float(maxWidth)*RELATIVE_SCALEFACTOR;
// get scalefactor to reach bestWidth
scale = bestWidth / float(pixelArea.width);
// calculate scale for bestWidth
float adjustedScale = bestWidth / float(pixelArea.width);
// get the worst height (height when width is perfect)
float worstHeight = float(pixelArea.height)*scale;
float worstHeight = float(pixelArea.height)*adjustedScale;
// get the difference of best and worst height
float difference = bestHeight - worstHeight;
// half the difference and add it to worstHeight,
// then get scalefactor to reach this
scale = (worstHeight + difference / 2) / float(pixelArea.height);
// halve the difference and add it to worstHeight to get
// the best compromise between bestHeight and bestWidth,
// then calculate the corresponding scale factor
adjustedScale = (worstHeight + difference / 2) / float(pixelArea.height);
// prevent upscaling
scale = std::min(scale, adjustedScale);
} else {
// get half of max screensize
nscoord maxWidth = pc->AppUnitsToDevPixels(maxSize.width >> 1);
nscoord maxHeight = pc->AppUnitsToDevPixels(maxSize.height >> 1);
if (pixelArea.width > maxWidth || pixelArea.height > maxHeight) {
scale = 1.0;
// divide the maximum size by the image size in both directions. Whichever
// direction produces the smallest result determines how much should be
// scaled.

Просмотреть файл

@ -667,17 +667,22 @@ nsBaseDragService::DrawDrag(nsIDOMNode* aDOMNode,
uint32_t count = 0;
nsAutoString childNodeName;
if (NS_SUCCEEDED(dragNode->GetChildNodes(getter_AddRefs(childList))) &&
// check if the dragged node itself is an img element
if (NS_SUCCEEDED(dragNode->GetNodeName(childNodeName)) &&
childNodeName.LowerCaseEqualsLiteral("img")) {
renderFlags = renderFlags | nsIPresShell::RENDER_IS_IMAGE;
} else if (
NS_SUCCEEDED(dragNode->GetChildNodes(getter_AddRefs(childList))) &&
NS_SUCCEEDED(childList->GetLength(&length))) {
// check every childnode for being a img-tag
// check every childnode for being an img element
while (count < length) {
if (NS_FAILED(childList->Item(count, getter_AddRefs(child))) ||
NS_FAILED(child->GetNodeName(childNodeName))) {
break;
}
// here the node is checked for being a img-tag
// here the node is checked for being an img element
if (childNodeName.LowerCaseEqualsLiteral("img")) {
// if the dragnnode contains a image, set RENDER_IS_IMAGE flag
// if the dragnode contains an image, set RENDER_IS_IMAGE flag
renderFlags = renderFlags | nsIPresShell::RENDER_IS_IMAGE;
break;
}