https://bugs.webkit.org/show_bug.cgi?id=145022
<rdar://problem/
19790341>
Reviewed by Dean Jackson.
* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
(WebKit::WebPageProxy::setShouldScaleViewToFitDocument):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/DrawingArea.h:
(WebKit::DrawingArea::setShouldScaleViewToFitDocument):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
(WebKit::WebPage::setShouldScaleViewToFitDocument):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
Plumb shouldScaleViewToFitDocument through to the DrawingArea.
* UIProcess/mac/WKViewLayoutStrategy.mm:
(+[WKViewLayoutStrategy layoutStrategyWithPage:view:mode:]):
(-[WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy initWithPage:view:mode:]):
(-[WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy updateLayout]):
(-[WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy willChangeLayoutStrategy]):
* UIProcess/API/C/WKLayoutMode.h:
* UIProcess/API/Cocoa/_WKLayoutMode.h:
Add a new layout mode, which just turns on shouldScaleViewToFitDocument,
and otherwise behaves as normal.
* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::setShouldScaleViewToFitDocument):
(WebKit::TiledCoreAnimationDrawingArea::scaleViewToFitDocumentIfNeeded):
(WebKit::TiledCoreAnimationDrawingArea::flushLayers):
On every flush where either the document size or view size has changed,
or layout is outstanding, do a layout with fixed layout off to determine
whether the document fits inside the view. If it doesn't, scale it down
to fit. This will require an extra layout for every resize while in the
scaled-down state, but there is potential for future optimization.
* MiniBrowser/mac/BrowserWindow.xib:
* MiniBrowser/mac/BrowserWindowController.h:
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController toggleShrinkToFit:]):
(-[WK2BrowserWindowController toggleUseMinimumViewSize:]): Deleted.
Switch to _WKLayoutModeDynamicSizeComputedFromMinimumDocumentSize.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@184358
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2015-05-14 Timothy Horton <timothy_horton@apple.com>
+
+ Add a layout mode that scales down the view to try to fit the document
+ https://bugs.webkit.org/show_bug.cgi?id=145022
+ <rdar://problem/19790341>
+
+ Reviewed by Dean Jackson.
+
+ * Shared/WebPageCreationParameters.cpp:
+ (WebKit::WebPageCreationParameters::encode):
+ (WebKit::WebPageCreationParameters::decode):
+ * Shared/WebPageCreationParameters.h:
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::creationParameters):
+ (WebKit::WebPageProxy::setShouldScaleViewToFitDocument):
+ * UIProcess/WebPageProxy.h:
+ * WebProcess/WebPage/DrawingArea.h:
+ (WebKit::DrawingArea::setShouldScaleViewToFitDocument):
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::WebPage):
+ (WebKit::WebPage::setShouldScaleViewToFitDocument):
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+ Plumb shouldScaleViewToFitDocument through to the DrawingArea.
+
+ * UIProcess/mac/WKViewLayoutStrategy.mm:
+ (+[WKViewLayoutStrategy layoutStrategyWithPage:view:mode:]):
+ (-[WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy initWithPage:view:mode:]):
+ (-[WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy updateLayout]):
+ (-[WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy willChangeLayoutStrategy]):
+ * UIProcess/API/C/WKLayoutMode.h:
+ * UIProcess/API/Cocoa/_WKLayoutMode.h:
+ Add a new layout mode, which just turns on shouldScaleViewToFitDocument,
+ and otherwise behaves as normal.
+
+ * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
+ * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
+ (WebKit::TiledCoreAnimationDrawingArea::setShouldScaleViewToFitDocument):
+ (WebKit::TiledCoreAnimationDrawingArea::scaleViewToFitDocumentIfNeeded):
+ (WebKit::TiledCoreAnimationDrawingArea::flushLayers):
+ On every flush where either the document size or view size has changed,
+ or layout is outstanding, do a layout with fixed layout off to determine
+ whether the document fits inside the view. If it doesn't, scale it down
+ to fit. This will require an extra layout for every resize while in the
+ scaled-down state, but there is potential for future optimization.
+
2015-05-14 Anders Carlsson <andersca@apple.com>
Local storage origins should include origins with transient local storage
encoder << textAutosizingWidth;
#endif
encoder << appleMailPaginationQuirkEnabled;
+ encoder << shouldScaleViewToFitDocument;
}
bool WebPageCreationParameters::decode(IPC::ArgumentDecoder& decoder, WebPageCreationParameters& parameters)
if (!decoder.decode(parameters.appleMailPaginationQuirkEnabled))
return false;
+ if (!decoder.decode(parameters.shouldScaleViewToFitDocument))
+ return false;
+
return true;
}
float textAutosizingWidth;
#endif
bool appleMailPaginationQuirkEnabled;
+ bool shouldScaleViewToFitDocument;
};
} // namespace WebKit
kWKLayoutModeViewSize,
kWKLayoutModeFixedSize,
kWKLayoutModeDynamicSizeComputedFromViewScale,
- kWKLayoutModeDynamicSizeWithMinimumViewSize
+ kWKLayoutModeDynamicSizeWithMinimumViewSize,
+ kWKLayoutModeDynamicSizeComputedFromMinimumDocumentSize
};
typedef uint32_t WKLayoutMode;
return _WKLayoutModeDynamicSizeComputedFromViewScale;
case kWKLayoutModeDynamicSizeWithMinimumViewSize:
return _WKLayoutModeDynamicSizeWithMinimumViewSize;
+ case kWKLayoutModeDynamicSizeComputedFromMinimumDocumentSize:
+ return _WKLayoutModeDynamicSizeComputedFromMinimumDocumentSize;
case kWKLayoutModeViewSize:
default:
return _WKLayoutModeViewSize;
case _WKLayoutModeDynamicSizeWithMinimumViewSize:
wkViewLayoutMode = kWKLayoutModeDynamicSizeWithMinimumViewSize;
break;
+ case _WKLayoutModeDynamicSizeComputedFromMinimumDocumentSize:
+ wkViewLayoutMode = kWKLayoutModeDynamicSizeComputedFromMinimumDocumentSize;
+ break;
case _WKLayoutModeViewSize:
default:
wkViewLayoutMode = kWKLayoutModeViewSize;
_WKLayoutModeDynamicSizeComputedFromViewScale,
// Lay out the view at a heuristically-determined size based on the minimum view size.
- _WKLayoutModeDynamicSizeWithMinimumViewSize
+ _WKLayoutModeDynamicSizeWithMinimumViewSize,
+
+ // Lay out the view at a heuristically-determined size based on the minimum size of the document.
+ _WKLayoutModeDynamicSizeComputedFromMinimumDocumentSize,
} WK_ENUM_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
#else
parameters.appleMailPaginationQuirkEnabled = false;
#endif
+ parameters.shouldScaleViewToFitDocument = m_shouldScaleViewToFitDocument;
return parameters;
}
m_process->send(Messages::WebPage::ClearWheelEventTestTrigger(), m_pageID);
}
+void WebPageProxy::setShouldScaleViewToFitDocument(bool shouldScaleViewToFitDocument)
+{
+ if (m_shouldScaleViewToFitDocument == shouldScaleViewToFitDocument)
+ return;
+
+ m_shouldScaleViewToFitDocument = shouldScaleViewToFitDocument;
+
+ if (!isValid())
+ return;
+
+ m_process->send(Messages::WebPage::SetShouldScaleViewToFitDocument(shouldScaleViewToFitDocument), m_pageID);
+}
+
} // namespace WebKit
#if PLATFORM(COCOA)
void scaleViewAndUpdateGeometryFenced(double scale, WebCore::IntSize viewSize, std::function<void (const WebCore::MachSendRight&, CallbackBase::Error)>);
#endif
+ void setShouldScaleViewToFitDocument(bool);
float deviceScaleFactor() const;
void setIntrinsicDeviceScaleFactor(float);
bool m_mayStartMediaWhenInWindow;
bool m_waitingForDidUpdateViewState;
-
+
+ bool m_shouldScaleViewToFitDocument { false };
+
#if PLATFORM(COCOA)
HashMap<String, String> m_temporaryPDFFiles;
std::unique_ptr<WebCore::RunLoopObserver> m_viewStateChangeDispatcher;
}
@end
+@interface WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy : WKViewLayoutStrategy
+@end
+
@implementation WKViewLayoutStrategy
+ (instancetype)layoutStrategyWithPage:(WebPageProxy&)page view:(WKView *)wkView mode:(WKLayoutMode)mode
case kWKLayoutModeDynamicSizeWithMinimumViewSize:
strategy = [[WKViewDynamicSizeWithMinimumViewSizeLayoutStrategy alloc] initWithPage:page view:wkView mode:mode];
break;
+ case kWKLayoutModeDynamicSizeComputedFromMinimumDocumentSize:
+ strategy = [[WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy alloc] initWithPage:page view:wkView mode:mode];
+ break;
case kWKLayoutModeViewSize:
default:
strategy = [[WKViewViewSizeLayoutStrategy alloc] initWithPage:page view:wkView mode:mode];
@end
+@implementation WKViewDynamicSizeComputedFromMinimumDocumentSizeLayoutStrategy
+
+- (instancetype)initWithPage:(WebPageProxy&)page view:(WKView *)wkView mode:(WKLayoutMode)mode
+{
+ self = [super initWithPage:page view:wkView mode:mode];
+
+ if (!self)
+ return nil;
+
+ _page->setShouldScaleViewToFitDocument(true);
+
+ return self;
+}
+
+- (void)updateLayout
+{
+}
+
+- (void)willChangeLayoutStrategy
+{
+ _page->setShouldScaleViewToFitDocument(false);
+}
+
+@end
+
#endif // PLATFORM(MAC)
virtual void attachViewOverlayGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*) { }
+ virtual void setShouldScaleViewToFitDocument(bool) { }
+
#if PLATFORM(COCOA)
// Used by TiledCoreAnimationDrawingArea.
virtual void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition, bool flushSynchronously) { }
m_drawingArea = DrawingArea::create(*this, parameters);
m_drawingArea->setPaintingEnabled(false);
+ m_drawingArea->setShouldScaleViewToFitDocument(parameters.shouldScaleViewToFitDocument);
#if ENABLE(ASYNC_SCROLLING)
m_useAsyncScrolling = parameters.store.getBoolValueForKey(WebPreferencesKey::threadedScrollingEnabledKey());
m_page->clearTrigger();
}
+void WebPage::setShouldScaleViewToFitDocument(bool shouldScaleViewToFitDocument)
+{
+ if (!m_drawingArea)
+ return;
+
+ m_drawingArea->setShouldScaleViewToFitDocument(shouldScaleViewToFitDocument);
+}
+
} // namespace WebKit
void clearWheelEventTestTrigger();
+ void setShouldScaleViewToFitDocument(bool);
+
uint64_t m_pageID;
std::unique_ptr<WebCore::Page> m_page;
#endif
ClearWheelEventTestTrigger()
+ SetShouldScaleViewToFitDocument(bool shouldScaleViewToFitDocument)
}
virtual void setColorSpace(const ColorSpaceData&) override;
virtual void addFence(const WebCore::MachSendRight&) override;
+ virtual void setShouldScaleViewToFitDocument(bool) override;
+
virtual void adjustTransientZoom(double scale, WebCore::FloatPoint origin) override;
virtual void commitTransientZoom(double scale, WebCore::FloatPoint origin) override;
void applyTransientZoomToPage(double scale, WebCore::FloatPoint origin);
void updateIntrinsicContentSizeIfNeeded();
void updateScrolledExposedRect();
+ void scaleViewToFitDocumentIfNeeded();
bool m_layerTreeStateIsFrozen;
WebCore::LayerFlushScheduler m_layerFlushScheduler;
WebCore::GraphicsLayer* m_viewOverlayRootLayer;
Vector<uint64_t> m_fenceCallbacksForAfterNextFlush;
+ bool m_shouldScaleViewToFitDocument { false };
+
+ WebCore::IntSize m_lastViewSizeForScaleToFit;
+ WebCore::IntSize m_lastDocumentSizeForScaleToFit;
};
} // namespace WebKit
m_webPage.send(Messages::DrawingAreaProxy::IntrinsicContentSizeDidChange(contentSize));
}
+void TiledCoreAnimationDrawingArea::setShouldScaleViewToFitDocument(bool shouldScaleView)
+{
+ if (m_shouldScaleViewToFitDocument == shouldScaleView)
+ return;
+
+ m_shouldScaleViewToFitDocument = shouldScaleView;
+ scheduleCompositingLayerFlush();
+}
+
+void TiledCoreAnimationDrawingArea::scaleViewToFitDocumentIfNeeded()
+{
+ // FIXME: Defer scrollbar flashing until after the second layout.
+
+ const int maximumDocumentWidthForScaling = 1440;
+ const float minimumViewScale = 0.1;
+
+ if (!m_shouldScaleViewToFitDocument)
+ return;
+
+ if (!m_webPage.mainFrame()->view()->needsLayout() && m_lastDocumentSizeForScaleToFit == m_webPage.mainFrameView()->renderView()->unscaledDocumentRect().size() && m_lastViewSizeForScaleToFit == m_webPage.size())
+ return;
+
+ // Lay out at the view size.
+ m_webPage.setUseFixedLayout(false);
+ m_webPage.layoutIfNeeded();
+
+ IntSize documentSize = m_webPage.mainFrameView()->renderView()->unscaledDocumentRect().size();
+ m_lastViewSizeForScaleToFit = m_webPage.size();
+ m_lastDocumentSizeForScaleToFit = documentSize;
+
+ int documentWidth = documentSize.width();
+ int viewWidth = m_webPage.size().width();
+
+ float viewScale = 1;
+
+ // Avoid scaling down documents that don't fit in a certain width, to allow
+ // sites that want horizontal scrollbars to continue to have them.
+ if (documentWidth && documentWidth < maximumDocumentWidthForScaling && viewWidth < documentWidth) {
+ // If the document doesn't fit in the view, scale it down but lay out at the view size.
+ m_webPage.setUseFixedLayout(true);
+ viewScale = (float)viewWidth / (float)documentWidth;
+ viewScale = std::max(viewScale, minimumViewScale);
+ m_webPage.setFixedLayoutSize(IntSize(ceilf(m_webPage.size().width() / viewScale), m_webPage.size().height()));
+ }
+
+ m_webPage.scaleView(viewScale);
+}
+
void TiledCoreAnimationDrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()> function)
{
#if ENABLE(ASYNC_SCROLLING)
ASSERT(!m_layerTreeStateIsFrozen);
@autoreleasepool {
+ scaleViewToFitDocumentIfNeeded();
+
m_webPage.layoutIfNeeded();
updateIntrinsicContentSizeIfNeeded();
+2015-05-14 Timothy Horton <timothy_horton@apple.com>
+
+ Add a layout mode that scales down the view to try to fit the document
+ https://bugs.webkit.org/show_bug.cgi?id=145022
+ <rdar://problem/19790341>
+
+ Reviewed by Dean Jackson.
+
+ * MiniBrowser/mac/BrowserWindow.xib:
+ * MiniBrowser/mac/BrowserWindowController.h:
+ * MiniBrowser/mac/WK2BrowserWindowController.m:
+ (-[WK2BrowserWindowController toggleShrinkToFit:]):
+ (-[WK2BrowserWindowController toggleUseMinimumViewSize:]): Deleted.
+ Switch to _WKLayoutModeDynamicSizeComputedFromMinimumDocumentSize.
+
2015-05-14 Michael Catanzaro <mcatanzaro@igalia.com>
[CMake] Don't read the LOCATION property of targets
<outlet property="forwardButton" destination="42" id="47"/>
<outlet property="progressIndicator" destination="21" id="33"/>
<outlet property="reloadButton" destination="23" id="34"/>
- <outlet property="toggleUseMinimumViewSizeButton" destination="82" id="FTZ-YK-Ae5"/>
+ <outlet property="toggleUseShrinkToFitButton" destination="82" id="9w7-AB-Ye3"/>
<outlet property="toolbar" destination="48" id="67"/>
<outlet property="urlText" destination="10" id="32"/>
<outlet property="window" destination="1" id="3"/>
</connections>
</button>
</toolbarItem>
- <toolbarItem implicitItemIdentifier="76DCF2B0-1DDE-47D2-9212-705E6E310CCE" label="Use Minimum View Size" paletteLabel="Use Minimum View Size" image="NSEnterFullScreenTemplate" id="81" customClass="MBToolbarItem">
+ <toolbarItem implicitItemIdentifier="76DCF2B0-1DDE-47D2-9212-705E6E310CCE" label="Use Shrink To Fit" paletteLabel="Use Shrink To Fit" image="NSEnterFullScreenTemplate" id="81" customClass="MBToolbarItem">
<nil key="toolTip"/>
<size key="minSize" width="29" height="25"/>
<size key="maxSize" width="29" height="25"/>
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
+ <connections>
+ <action selector="toggleShrinkToFit:" target="-2" id="gp7-Vk-KTI"/>
+ </connections>
</button>
<connections>
<action selector="toggleUseMinimumViewSize:" target="-2" id="gZA-yS-7L4"/>
- (IBAction)setScale:(id)sender;
-- (IBAction)toggleUseMinimumViewSize:(id)sender;
+- (IBAction)toggleShrinkToFit:(id)sender;
- (IBAction)dumpSourceToConsole:(id)sender;
- (IBAction)find:(id)sender;
IBOutlet NSToolbar *toolbar;
IBOutlet NSTextField *urlText;
IBOutlet NSView *containerView;
- IBOutlet NSButton *toggleUseMinimumViewSizeButton;
+ IBOutlet NSButton *toggleUseShrinkToFitButton;
IBOutlet NSWindow *findPanelWindow;
_zoomTextOnly = !_zoomTextOnly;
}
-- (IBAction)toggleUseMinimumViewSize:(id)sender
+- (IBAction)toggleShrinkToFit:(id)sender
{
}
BOOL _zoomTextOnly;
BOOL _isPrivateBrowsingWindow;
- BOOL _useMinimumViewSize;
+ BOOL _useShrinkToFit;
}
- (void)awakeFromNib
return _zoomTextOnly ? (_webView._textZoomFactor != 1) : (_webView._pageZoomFactor != 1);
}
-- (IBAction)toggleUseMinimumViewSize:(id)sender
+- (IBAction)toggleShrinkToFit:(id)sender
{
- _useMinimumViewSize = !_useMinimumViewSize;
- toggleUseMinimumViewSizeButton.image = _useMinimumViewSize ? [NSImage imageNamed:@"NSExitFullScreenTemplate"] : [NSImage imageNamed:@"NSEnterFullScreenTemplate"];
- [_webView _setMinimumViewSize:CGSizeMake(1024, 0)];
- [_webView _setLayoutMode:_useMinimumViewSize ? _WKLayoutModeDynamicSizeWithMinimumViewSize : _WKLayoutModeViewSize];
+ _useShrinkToFit = !_useShrinkToFit;
+ toggleUseShrinkToFitButton.image = _useShrinkToFit ? [NSImage imageNamed:@"NSExitFullScreenTemplate"] : [NSImage imageNamed:@"NSEnterFullScreenTemplate"];
+ [_webView _setLayoutMode:_useShrinkToFit ? _WKLayoutModeDynamicSizeComputedFromMinimumDocumentSize : _WKLayoutModeViewSize];
}
- (IBAction)dumpSourceToConsole:(id)sender