Commit b49bc3da authored by bdakin@apple.com's avatar bdakin@apple.com

Fix for https://bugs.webkit.org/show_bug.cgi?id=67819

Use high resolution platform images when the deviceScaleFactor > 1
-and corresponding-
<rdar://problem/10003098>

Reviewed by Darin Adler.

Add all of the new high resolution images. I also removed some tiffs from the 
project and replaced them with png equivalents (that are already checked into 
WebCore anyway). Since the high resolution images are pngs, it makes sense to use 
pngs for all of the images that load through Image::loadPlatformResource()
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/mac/ImageMac.mm:
(WebCore::Image::loadPlatformResource):

Load the @2x resource for deviceScaleFactors >= 2.
* editing/DeleteButtonController.cpp:
(WebCore::DeleteButtonController::createDeletionUI):

CachedImage::brokenImage() is no longer a static helper function, but a real 
member function. It also now loads the @2x resource for deviceScaleFactors >= 2 
and takes a parameter for the deviceScaleFactor. When CachedImage::image() returns 
the brokenImage(), it just returns the 1x version. brokenImage() has to be called 
directly to reliably return the deviceScaleFactor-appropriate resource.
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::brokenImage):
(WebCore::CachedImage::image):
* loader/cache/CachedImage.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::drawPlatformResizerImage):
(WebCore::RenderLayer::paintResizer):
* rendering/RenderLayer.h:

New static function to retrieve the deviceScaleFactor for callers that do not have 
direct access to a Page.
* page/Page.cpp:
(WebCore::Page::deviceScaleFactor):
* page/Page.h:

Call CachedImage::brokenImage() for the broken-image image at an accurate 
resolution.
* rendering/RenderImage.cpp:
(WebCore::RenderImage::imageSizeForError):
(WebCore::RenderImage::paintReplaced):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@94900 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5c610f60
2011-09-09 Beth Dakin <bdakin@apple.com>
Fix for https://bugs.webkit.org/show_bug.cgi?id=67819
Use high resolution platform images when the deviceScaleFactor > 1
-and corresponding-
<rdar://problem/10003098>
Reviewed by Darin Adler.
Add all of the new high resolution images. I also removed some tiffs from the
project and replaced them with png equivalents (that are already checked into
WebCore anyway). Since the high resolution images are pngs, it makes sense to use
pngs for all of the images that load through Image::loadPlatformResource()
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/mac/ImageMac.mm:
(WebCore::Image::loadPlatformResource):
Load the @2x resource for deviceScaleFactors >= 2.
* editing/DeleteButtonController.cpp:
(WebCore::DeleteButtonController::createDeletionUI):
CachedImage::brokenImage() is no longer a static helper function, but a real
member function. It also now loads the @2x resource for deviceScaleFactors >= 2
and takes a parameter for the deviceScaleFactor. When CachedImage::image() returns
the brokenImage(), it just returns the 1x version. brokenImage() has to be called
directly to reliably return the deviceScaleFactor-appropriate resource.
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::brokenImage):
(WebCore::CachedImage::image):
* loader/cache/CachedImage.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::drawPlatformResizerImage):
(WebCore::RenderLayer::paintResizer):
* rendering/RenderLayer.h:
New static function to retrieve the deviceScaleFactor for callers that do not have
direct access to a Page.
* page/Page.cpp:
(WebCore::Page::deviceScaleFactor):
* page/Page.h:
Call CachedImage::brokenImage() for the broken-image image at an accurate
resolution.
* rendering/RenderImage.cpp:
(WebCore::RenderImage::imageSizeForError):
(WebCore::RenderImage::paintReplaced):
2011-09-09 Erik Arvidsson <arv@chromium.org>
Move Element.contains to Node
......@@ -41,6 +41,7 @@
#include "HTMLNames.h"
#include "Image.h"
#include "Node.h"
#include "Page.h"
#include "Range.h"
#include "RemoveNodeCommand.h"
#include "RenderBox.h"
......@@ -240,7 +241,13 @@ void DeleteButtonController::createDeletionUI()
style->setProperty(CSSPropertyHeight, String::number(buttonHeight) + "px");
style->setProperty(CSSPropertyVisibility, CSSValueVisible);
RefPtr<Image> buttonImage = Image::loadPlatformResource("deleteButton");
float deviceScaleFactor = Page::deviceScaleFactor(m_frame);
RefPtr<Image> buttonImage;
if (deviceScaleFactor >= 2)
buttonImage = Image::loadPlatformResource("deleteButton@2x");
else
buttonImage = Image::loadPlatformResource("deleteButton");
if (buttonImage->isNull())
return;
......
......@@ -113,18 +113,27 @@ void CachedImage::allClientsRemoved()
m_decodedDataDeletionTimer.startOneShot(interval);
}
static Image* brokenImage()
Image* CachedImage::brokenImage(float deviceScaleFactor) const
{
DEFINE_STATIC_LOCAL(RefPtr<Image>, brokenImage, (Image::loadPlatformResource("missingImage")));
return brokenImage.get();
if (deviceScaleFactor >= 2) {
DEFINE_STATIC_LOCAL(Image*, brokenImageHiRes, (Image::loadPlatformResource("missingImage@2x").leakRef()));
return brokenImageHiRes;
}
DEFINE_STATIC_LOCAL(Image*, brokenImageLoRes, (Image::loadPlatformResource("missingImage").leakRef()));
return brokenImageLoRes;
}
Image* CachedImage::image() const
{
ASSERT(!isPurgeable());
if (errorOccurred() && m_shouldPaintBrokenImage)
return brokenImage();
if (errorOccurred() && m_shouldPaintBrokenImage) {
// Returning the 1x broken image is non-ideal, but we cannot reliably access the appropriate
// deviceScaleFactor from here. It is critical that callers use CachedImage::brokenImage()
// when they need the real, deviceScaleFactor-appropriate broken image icon.
return brokenImage(1);
}
if (m_image)
return m_image.get();
......
......@@ -47,6 +47,8 @@ public:
Image* image() const; // Returns the nullImage() if the image is not available yet.
bool hasImage() const { return m_image.get(); }
Image* brokenImage(float deviceScaleFactor) const;
bool canRender(float multiplier) const { return !errorOccurred() && !imageSize(multiplier).isEmpty(); }
// These are only used for SVGImage right now
......
......@@ -652,6 +652,16 @@ void Page::setDeviceScaleFactor(float scaleFactor)
backForward()->markPagesForFullStyleRecalc();
}
float Page::deviceScaleFactor(Frame* frame)
{
if (!frame)
return 1;
Page* page = frame->page();
if (!page)
return 1;
return page->deviceScaleFactor();
}
void Page::didMoveOnscreen()
{
for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
......
......@@ -249,6 +249,7 @@ namespace WebCore {
float deviceScaleFactor() const { return m_deviceScaleFactor; }
void setDeviceScaleFactor(float);
static float deviceScaleFactor(Frame*);
// Notifications when the Page starts and stops being presented via a native window.
void didMoveOnscreen();
......
......@@ -55,7 +55,7 @@ void BitmapImage::invalidatePlatformData()
PassRefPtr<Image> Image::loadPlatformResource(const char *name)
{
NSBundle *bundle = [NSBundle bundleForClass:[WebCoreBundleFinder class]];
NSString *imagePath = [bundle pathForResource:[NSString stringWithUTF8String:name] ofType:@"tiff"];
NSString *imagePath = [bundle pathForResource:[NSString stringWithUTF8String:name] ofType:@"png"];
NSData *namedImageData = [NSData dataWithContentsOfFile:imagePath];
if (namedImageData) {
RefPtr<Image> image = BitmapImage::create();
......
......@@ -84,9 +84,11 @@ IntSize RenderImage::imageSizeForError(CachedImage* newImage) const
ASSERT_ARG(newImage, newImage);
ASSERT_ARG(newImage, newImage->image());
Image* brokenImage = newImage->brokenImage(Page::deviceScaleFactor(frame()));
// imageSize() returns 0 for the error image. We need the true size of the
// error image, so we have to get it by grabbing image() directly.
return IntSize(paddingWidth + newImage->image()->width() * style()->effectiveZoom(), paddingHeight + newImage->image()->height() * style()->effectiveZoom());
return IntSize(paddingWidth + brokenImage->width() * style()->effectiveZoom(), paddingHeight + brokenImage->height() * style()->effectiveZoom());
}
// Sets the image height and width to fit the alt text. Returns true if the
......@@ -268,15 +270,21 @@ void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
RefPtr<Image> image = m_imageResource->image();
if (m_imageResource->errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
float deviceScaleFactor = Page::deviceScaleFactor(frame());
// Call brokenImage() explicitly to ensure we get the broken image icon at the appropriate resolution.
image = m_imageResource->cachedImage()->brokenImage(deviceScaleFactor);
IntSize imageSize = image->size();
if (deviceScaleFactor >= 2)
imageSize.scale(0.5);
// Center the error image, accounting for border and padding.
LayoutUnit centerX = (usableWidth - image->width()) / 2;
LayoutUnit centerX = (usableWidth - imageSize.width()) / 2;
if (centerX < 0)
centerX = 0;
LayoutUnit centerY = (usableHeight - image->height()) / 2;
LayoutUnit centerY = (usableHeight - imageSize.height()) / 2;
if (centerY < 0)
centerY = 0;
imageOffset = LayoutSize(leftBorder + leftPad + centerX + 1, topBorder + topPad + centerY + 1);
context->drawImage(image.get(), style()->colorSpace(), paintOffset + imageOffset);
context->drawImage(image.get(), style()->colorSpace(), IntRect(paintOffset + imageOffset, imageSize));
errorPictureDrawn = true;
}
......
......@@ -2414,6 +2414,28 @@ void RenderLayer::paintScrollCorner(GraphicsContext* context, const LayoutPoint&
context->fillRect(absRect, Color::white, box->style()->colorSpace());
}
void RenderLayer::drawPlatformResizerImage(GraphicsContext* context, LayoutRect resizerCornerRect)
{
float deviceScaleFactor = Page::deviceScaleFactor(renderer()->frame());
printf("RenderLayer deviceScaleFactor=%f\n", deviceScaleFactor);
RefPtr<Image> resizeCornerImage;
IntSize cornerResizerSize;
if (deviceScaleFactor >= 2) {
DEFINE_STATIC_LOCAL(Image*, resizeCornerImageHiRes, (Image::loadPlatformResource("textAreaResizeCorner@2x").leakRef()));
resizeCornerImage = resizeCornerImageHiRes;
cornerResizerSize = resizeCornerImage->size();
cornerResizerSize.scale(0.5);
} else {
DEFINE_STATIC_LOCAL(Image*, resizeCornerImageLoRes, (Image::loadPlatformResource("textAreaResizeCorner").leakRef()));
resizeCornerImage = resizeCornerImageLoRes;
cornerResizerSize = resizeCornerImage->size();
}
IntRect imageRect(resizerCornerRect.maxXMaxYCorner() - cornerResizerSize, cornerResizerSize);
context->drawImage(resizeCornerImage.get(), renderer()->style()->colorSpace(), imageRect);
}
void RenderLayer::paintResizer(GraphicsContext* context, const LayoutPoint& paintOffset, const LayoutRect& damageRect)
{
if (renderer()->style()->resize() == RESIZE_NONE)
......@@ -2437,10 +2459,7 @@ void RenderLayer::paintResizer(GraphicsContext* context, const LayoutPoint& pain
return;
}
// Paint the resizer control.
DEFINE_STATIC_LOCAL(RefPtr<Image>, resizeCornerImage, (Image::loadPlatformResource("textAreaResizeCorner")));
LayoutPoint imagePoint(absRect.maxX() - resizeCornerImage->width(), absRect.maxY() - resizeCornerImage->height());
context->drawImage(resizeCornerImage.get(), box->style()->colorSpace(), imagePoint);
drawPlatformResizerImage(context, absRect);
// Draw a frame around the resizer (1px grey line) if there are any scrollbars present.
// Clipping will exclude the right and bottom edges of this frame.
......
......@@ -611,6 +611,8 @@ private:
void updateScrollCornerStyle();
void updateResizerStyle();
void drawPlatformResizerImage(GraphicsContext*, LayoutRect resizerCornerRect);
void updatePagination();
bool isPaginated() const { return m_isPaginated; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment