Bug 917595 (Part 1) - Respect image-orientation in zoomed image documents. r=smaug

This commit is contained in:
Seth Fowler 2013-11-06 18:50:42 -08:00
parent c3a9ac649b
commit dc24b0aeee
2 changed files with 41 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "nsIDOMKeyEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMEventListener.h"
#include "nsIFrame.h"
#include "nsGkAtoms.h"
#include "imgIRequest.h"
#include "imgILoader.h"
@ -209,6 +210,7 @@ ImageDocument::Destroy()
if (mImageContent) {
// Remove our event listener from the image content.
nsCOMPtr<EventTarget> target = do_QueryInterface(mImageContent);
target->RemoveEventListener(NS_LITERAL_STRING("load"), this, false);
target->RemoveEventListener(NS_LITERAL_STRING("click"), this, false);
// Break reference cycle with mImageContent, if we have one
@ -253,6 +255,7 @@ ImageDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic document");
target = do_QueryInterface(mImageContent);
target->AddEventListener(NS_LITERAL_STRING("load"), this, false);
target->AddEventListener(NS_LITERAL_STRING("click"), this, false);
}
@ -509,8 +512,11 @@ ImageDocument::SetModeClass(eModeClasses mode)
nsresult
ImageDocument::OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage)
{
// Styles have not yet been applied, so we don't know the final size. For now,
// default to the image's intrinsic size.
aImage->GetWidth(&mImageWidth);
aImage->GetHeight(&mImageHeight);
nsCOMPtr<nsIRunnable> runnable =
NS_NewRunnableMethod(this, &ImageDocument::DefaultCheckOverflowing);
nsContentUtils::AddScriptRunner(runnable);
@ -573,11 +579,44 @@ ImageDocument::HandleEvent(nsIDOMEvent* aEvent)
else if (mImageIsOverflowing) {
ShrinkToFit();
}
} else if (eventType.EqualsLiteral("load")) {
UpdateSizeFromLayout();
}
return NS_OK;
}
void
ImageDocument::UpdateSizeFromLayout()
{
// Pull an updated size from the content frame to account for any size
// change due to CSS properties like |image-orientation|.
Element* contentElement = mImageContent->AsElement();
if (!contentElement) {
return;
}
nsIFrame* contentFrame = contentElement->GetPrimaryFrame(Flush_Frames);
if (!contentFrame) {
return;
}
nsIntSize oldSize(mImageWidth, mImageHeight);
IntrinsicSize newSize = contentFrame->GetIntrinsicSize();
if (newSize.width.GetUnit() == eStyleUnit_Coord) {
mImageWidth = nsPresContext::AppUnitsToFloatCSSPixels(newSize.width.GetCoordValue());
}
if (newSize.height.GetUnit() == eStyleUnit_Coord) {
mImageHeight = nsPresContext::AppUnitsToFloatCSSPixels(newSize.height.GetCoordValue());
}
// Ensure that our information about overflow is up-to-date if needed.
if (mImageWidth != oldSize.width || mImageHeight != oldSize.height) {
CheckOverflowing(false);
}
}
nsresult
ImageDocument::CreateSyntheticDocument()
{

View File

@ -94,6 +94,8 @@ protected:
void ResetZoomLevel();
float GetZoomLevel();
void UpdateSizeFromLayout();
enum eModeClasses {
eNone,
eShrinkToFit,