Changeset 168327 in webkit
- Timestamp:
- May 5, 2014 4:35:38 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r168322 r168327 1 2014-05-05 Benjamin Poulain <benjamin@webkit.org> 2 3 Clean up Image Document and tweak the layout and viewport 4 https://bugs.webkit.org/show_bug.cgi?id=132552 5 6 Reviewed by Anders Carlsson. 7 8 * svg/custom/anchor-on-use-expected.svg: 9 1 10 2014-05-05 Christophe Dumez <ch.dumez@samsung.com> 2 11 -
trunk/LayoutTests/svg/custom/anchor-on-use-expected.svg
r114750 r168327 1 1 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 2 <image x=" 0" y="0" width="503" height="410" xlink:href="resources/green-checker.png"/>2 <image x="50%" y="0" transform="translate(-251,0)" width="503" height="410" xlink:href="resources/green-checker.png"/> 3 3 </svg> 4 4 -
trunk/Source/WebCore/ChangeLog
r168325 r168327 1 2014-05-05 Benjamin Poulain <benjamin@webkit.org> 2 3 Clean up Image Document and tweak the layout and viewport 4 https://bugs.webkit.org/show_bug.cgi?id=132552 5 6 Reviewed by Sam Weinig. 7 8 The #ifdef in every function was making quite a mess. A lot of that code does 9 not make sense on iOS. 10 11 This patch make a clean split between mouse related stuff and iOS. 12 13 Also: 14 -Change the viewport to be only width based, and avoid scaling in portrait. 15 -Center the image horizontally in the view. 16 17 * html/ImageDocument.cpp: 18 (WebCore::ImageDocument::ImageDocument): 19 (WebCore::ImageDocument::createDocumentStructure): 20 (WebCore::ImageDocument::imageUpdated): 21 (WebCore::ImageDocument::scale): 22 (WebCore::ImageDocument::resizeImageToFit): 23 (WebCore::ImageDocument::imageFitsInWindow): 24 (WebCore::ImageDocument::windowSizeChanged): 25 (WebCore::ImageDocument::imageClicked): 26 * html/ImageDocument.h: 27 1 28 2014-05-05 Beth Dakin <bdakin@apple.com> 2 29 -
trunk/Source/WebCore/html/ImageDocument.cpp
r168316 r168327 27 27 28 28 #include "CachedImage.h" 29 #include "Chrome.h" 29 30 #include "DocumentLoader.h" 30 31 #include "EventListener.h" … … 51 52 using namespace HTMLNames; 52 53 54 #if !PLATFORM(IOS) 53 55 class ImageEventListener final : public EventListener { 54 56 public: … … 67 69 ImageDocument& m_document; 68 70 }; 69 71 #endif 72 70 73 class ImageDocumentParser final : public RawDataDocumentParser { 71 74 public: … … 192 195 , m_imageElement(nullptr) 193 196 , m_imageSizeIsKnown(false) 197 #if !PLATFORM(IOS) 194 198 , m_didShrinkImage(false) 199 #endif 195 200 , m_shouldShrinkImage(frame.settings().shrinksStandaloneImagesToFit() && frame.isMainFrame()) 196 201 { … … 217 222 218 223 RefPtr<ImageDocumentElement> imageElement = ImageDocumentElement::create(*this); 219 imageElement->setAttribute(styleAttr, "-webkit-user-select: none"); 224 if (m_shouldShrinkImage) 225 imageElement->setAttribute(styleAttr, "-webkit-user-select:none; display:block; margin:auto;"); 226 else 227 imageElement->setAttribute(styleAttr, "-webkit-user-select:none;"); 220 228 imageElement->setLoadManually(true); 221 229 imageElement->setSrc(url().string()); … … 223 231 224 232 if (m_shouldShrinkImage) { 233 #if PLATFORM(IOS) 234 // Set the viewport to be in device pixels (rather than the default of 980). 235 processViewport(ASCIILiteral("width=device-width"), ViewportArguments::ImageDocument); 236 #else 225 237 RefPtr<EventListener> listener = ImageEventListener::create(*this); 226 238 if (DOMWindow* window = this->domWindow()) 227 239 window->addEventListener("resize", listener, false); 228 240 imageElement->addEventListener("click", listener.release(), false); 229 241 #endif 242 } 243 244 m_imageElement = imageElement.get(); 245 } 246 247 void ImageDocument::imageUpdated() 248 { 249 ASSERT(m_imageElement); 250 251 if (m_imageSizeIsKnown) 252 return; 253 254 LayoutSize imageSize = this->imageSize(); 255 if (imageSize.isEmpty()) 256 return; 257 258 m_imageSizeIsKnown = true; 259 260 if (m_shouldShrinkImage) { 230 261 #if PLATFORM(IOS) 231 // Set the viewport to be in device pixels (rather than the default of 980). 232 processViewport(ASCIILiteral("width=device-width"), ViewportArguments::ImageDocument); 262 FloatSize screenSize = page()->chrome().screenSize(); 263 if (imageSize.width() > screenSize.width()) 264 processViewport(String::format("width=%u", static_cast<unsigned>(imageSize.width().toInt())), ViewportArguments::ImageDocument); 265 #else 266 // Call windowSizeChanged for its side effect of sizing the image. 267 windowSizeChanged(); 233 268 #endif 234 269 } 235 236 m_imageElement = imageElement.get(); 237 } 238 270 } 271 272 #if !PLATFORM(IOS) 239 273 float ImageDocument::scale() 240 274 { 241 #if PLATFORM(IOS)242 // On iOS big images are subsampled to make them smaller. So, don't resize them.243 return 1;244 #else245 275 if (!m_imageElement) 246 276 return 1; … … 256 286 257 287 return std::min(widthScale, heightScale); 258 #endif259 288 } 260 289 261 290 void ImageDocument::resizeImageToFit() 262 291 { 263 #if PLATFORM(IOS)264 // On iOS big images are subsampled to make them smaller. So, don't resize them.265 #else266 292 if (!m_imageElement) 267 293 return; … … 274 300 275 301 m_imageElement->setInlineStyleProperty(CSSPropertyCursor, CSSValueWebkitZoomIn); 276 #endif277 }278 279 void ImageDocument::imageClicked(int x, int y)280 {281 #if PLATFORM(IOS)282 // On iOS big images are subsampled to make them smaller. So, don't resize them.283 UNUSED_PARAM(x);284 UNUSED_PARAM(y);285 #else286 if (!m_imageSizeIsKnown || imageFitsInWindow())287 return;288 289 m_shouldShrinkImage = !m_shouldShrinkImage;290 291 if (m_shouldShrinkImage) {292 // Call windowSizeChanged for its side effect of sizing the image.293 windowSizeChanged();294 } else {295 restoreImageSize();296 297 updateLayout();298 299 float scale = this->scale();300 301 int scrollX = static_cast<int>(x / scale - view()->width() / 2.0f);302 int scrollY = static_cast<int>(y / scale - view()->height() / 2.0f);303 304 view()->setScrollPosition(IntPoint(scrollX, scrollY));305 }306 #endif307 }308 309 void ImageDocument::imageUpdated()310 {311 ASSERT(m_imageElement);312 313 if (m_imageSizeIsKnown)314 return;315 316 if (imageSize().isEmpty())317 return;318 319 m_imageSizeIsKnown = true;320 321 if (m_shouldShrinkImage) {322 // Call windowSizeChanged for its side effect of sizing the image.323 windowSizeChanged();324 }325 302 } 326 303 … … 352 329 353 330 LayoutSize imageSize = this->imageSize(); 354 #if PLATFORM(IOS)355 LayoutSize windowSize = view->contentsToScreen(view->visibleContentRect()).size();356 #else357 331 LayoutSize windowSize = LayoutSize(view->width(), view->height()); 358 #endif359 332 return imageSize.width() <= windowSize.width() && imageSize.height() <= windowSize.height(); 360 333 } 361 334 335 362 336 void ImageDocument::windowSizeChanged() 363 337 { … … 367 341 bool fitsInWindow = imageFitsInWindow(); 368 342 369 #if PLATFORM(IOS)370 if (fitsInWindow)371 return;372 373 LayoutSize imageSize = this->imageSize();374 LayoutRect visibleScreenSize = view()->contentsToScreen(view()->visibleContentRect());375 376 float widthScale = static_cast<float>(visibleScreenSize.width()) / imageSize.width();377 float heightScale = static_cast<float>(visibleScreenSize.height()) / imageSize.height();378 if (widthScale < heightScale)379 processViewport(String::format("width=%d", imageSize.width().toInt()), ViewportArguments::ImageDocument);380 else381 processViewport(String::format("width=%d", static_cast<int>(1.0f + (1.0f - heightScale)) * imageSize.width().toInt()), ViewportArguments::ImageDocument);382 #else383 343 // If the image has been explicitly zoomed in, restore the cursor if the image fits 384 344 // and set it to a zoom out cursor if the image doesn't fit … … 405 365 } 406 366 } 407 #endif 367 } 368 369 void ImageDocument::imageClicked(int x, int y) 370 { 371 if (!m_imageSizeIsKnown || imageFitsInWindow()) 372 return; 373 374 m_shouldShrinkImage = !m_shouldShrinkImage; 375 376 if (m_shouldShrinkImage) { 377 // Call windowSizeChanged for its side effect of sizing the image. 378 windowSizeChanged(); 379 } else { 380 restoreImageSize(); 381 382 updateLayout(); 383 384 float scale = this->scale(); 385 386 int scrollX = static_cast<int>(x / scale - view()->width() / 2.0f); 387 int scrollY = static_cast<int>(y / scale - view()->height() / 2.0f); 388 389 view()->setScrollPosition(IntPoint(scrollX, scrollY)); 390 } 408 391 } 409 392 … … 423 406 return other.type() == ImageEventListenerType; 424 407 } 408 #endif 425 409 426 410 // -------- -
trunk/Source/WebCore/html/ImageDocument.h
r168316 r168327 47 47 void disconnectImageElement() { m_imageElement = nullptr; } 48 48 49 #if !PLATFORM(IOS) 49 50 void windowSizeChanged(); 50 51 void imageClicked(int x, int y); 52 #endif 51 53 52 54 private: … … 58 60 59 61 void createDocumentStructure(); 62 #if !PLATFORM(IOS) 60 63 void resizeImageToFit(); 61 64 void restoreImageSize(); 62 65 bool imageFitsInWindow(); 63 66 float scale(); 67 #endif 64 68 65 69 void imageUpdated(); … … 70 74 bool m_imageSizeIsKnown; 71 75 76 #if !PLATFORM(IOS) 72 77 // Whether the image is shrunk to fit or not. 73 78 bool m_didShrinkImage; 79 #endif 74 80 75 81 // Whether the image should be shrunk or not. -
trunk/Tools/ChangeLog
r168304 r168327 1 2014-05-05 Benjamin Poulain <benjamin@webkit.org> 2 3 Clean up Image Document and tweak the layout and viewport 4 https://bugs.webkit.org/show_bug.cgi?id=132552 5 6 Reviewed by Anders Carlsson. 7 8 * DumpRenderTree/mac/DumpRenderTree.mm: 9 (resetWebPreferencesToConsistentValues): 10 Update the default settings to have something consistent with WebKit2. 11 1 12 2014-05-05 Martin Robinson <mrobinson@igalia.com> 2 13 -
trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm
r168044 r168327 840 840 [preferences setPrivateBrowsingEnabled:NO]; 841 841 [preferences setAuthorAndUserStylesEnabled:YES]; 842 [preferences setShrinksStandaloneImagesToFit:YES]; 842 843 [preferences setJavaScriptCanOpenWindowsAutomatically:YES]; 843 844 [preferences setJavaScriptCanAccessClipboard:YES];
Note: See TracChangeset
for help on using the changeset viewer.