mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-09-30 02:00:27 +03:00
Still wrong but passes tests.
This commit is contained in:
@@ -581,7 +581,7 @@ void BlockLayouter::positionRichTextChildren( Graphics::RichText* rt ) {
|
||||
widget->getLayoutWidthPolicy() == SizePolicy::MatchParent ) {
|
||||
Float contentWidth =
|
||||
eemax( 0.f, atomicBounds.getWidth() - margin.Left - margin.Right );
|
||||
if ( eeabs( widget->getPixelsSize().getWidth() - contentWidth ) > 0.01f ) {
|
||||
if ( contentWidth + 0.01f < widget->getPixelsSize().getWidth() ) {
|
||||
widget->setPixelsSize( contentWidth,
|
||||
widget->getPixelsSize().getHeight() );
|
||||
mResizedCount++;
|
||||
@@ -623,7 +623,7 @@ void BlockLayouter::positionRichTextChildren( Graphics::RichText* rt ) {
|
||||
widget->getLayoutWidthPolicy() == SizePolicy::MatchParent ) {
|
||||
Float contentWidth =
|
||||
eemax( 0.f, span->size.getWidth() - margin.Left - margin.Right );
|
||||
if ( eeabs( widget->getPixelsSize().getWidth() - contentWidth ) > 0.01f ) {
|
||||
if ( contentWidth + 0.01f < widget->getPixelsSize().getWidth() ) {
|
||||
widget->setPixelsSize( contentWidth,
|
||||
widget->getPixelsSize().getHeight() );
|
||||
mResizedCount++;
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
#include <eepp/system/log.hpp>
|
||||
#include <eepp/ui/tools/htmlformatter.hpp>
|
||||
#include <eepp/ui/uihtmlwidget.hpp>
|
||||
#include <eepp/ui/uilinearlayout.hpp>
|
||||
#include <eepp/ui/uirichtext.hpp>
|
||||
#include <eepp/ui/uiscenenode.hpp>
|
||||
#include <eepp/ui/uiscrollbar.hpp>
|
||||
#include <eepp/ui/uistyle.hpp>
|
||||
#include <eepp/ui/uiwebview.hpp>
|
||||
|
||||
namespace EE { namespace UI {
|
||||
@@ -66,6 +68,51 @@ static void expandWidgetContentExtent( UIWidget* widget, const Vector2f& offset,
|
||||
extent.y = eemax( extent.y, position.y + size.getHeight() );
|
||||
}
|
||||
|
||||
static void resetViewportDependentDocumentWidths( UIWidget* container ) {
|
||||
if ( !container )
|
||||
return;
|
||||
|
||||
auto nodes = container->findAllByType( UI_TYPE_HTML_WIDGET );
|
||||
for ( Node* node : nodes ) {
|
||||
if ( node == container || !node->isWidget() )
|
||||
continue;
|
||||
|
||||
UIWidget* widget = node->asType<UIWidget>();
|
||||
Node* parent = widget->getParent();
|
||||
UIWidget* parentWidget =
|
||||
parent && parent->isWidget() ? parent->asType<UIWidget>() : nullptr;
|
||||
if ( !parentWidget )
|
||||
continue;
|
||||
|
||||
const Float containerWidth = eemax( 0.f, parentWidget->getPixelsSize().getWidth() -
|
||||
parentWidget->getPixelsContentOffset().Left -
|
||||
parentWidget->getPixelsContentOffset().Right );
|
||||
bool normalFlow = true;
|
||||
Rectf margin = widget->getLayoutPixelsMargin();
|
||||
if ( widget->isType( UI_TYPE_HTML_WIDGET ) ) {
|
||||
auto* htmlWidget = widget->asType<UIHTMLWidget>();
|
||||
normalFlow = !htmlWidget->isOutOfFlow();
|
||||
margin = htmlWidget->getNormalFlowLayoutPixelsMargin();
|
||||
}
|
||||
|
||||
if ( normalFlow ) {
|
||||
widget->invalidateIntrinsicSize();
|
||||
/* if ( widget->getLayoutWidthPolicy() == SizePolicy::MatchParent ) {
|
||||
widget->setPixelsSize( eemax( 0.f, containerWidth - margin.Left - margin.Right ),
|
||||
widget->getPixelsSize().getHeight() );
|
||||
} else if ( widget->getLayoutWidthPolicy() == SizePolicy::Fixed &&
|
||||
widget->getUIStyle() ) {
|
||||
const StyleSheetProperty* wprop =
|
||||
widget->getUIStyle()->getProperty( PropertyId::Width );
|
||||
if ( wprop && StyleSheetLength::isPercentage( wprop->value() ) ) {
|
||||
widget->setPixelsSize( { widget->lengthFromValue( *wprop ),
|
||||
widget->getPixelsSize().getHeight() } );
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sizef UIWebView::getDocumentViewportPixelsSize() const {
|
||||
Sizef contentBox = getPixelsSize();
|
||||
const Rectf& padding = getPixelsPadding();
|
||||
@@ -162,6 +209,7 @@ void UIWebView::updateHTMLMinHeight( UIHTMLHtml* html, UIHTMLBody* body ) {
|
||||
const Float bodyMarginHeight = PixelDensity::pxToDp( bodyMargin.Top + bodyMargin.Bottom );
|
||||
html->setMinHeight( h );
|
||||
html->setPixelsSize( viewport );
|
||||
body->setPixelsSize( { viewport.getWidth(), body->getPixelsSize().getHeight() } );
|
||||
body->setDocumentViewportMinHeight( eemax( 0.f, h - bodyMarginHeight ) );
|
||||
}
|
||||
|
||||
@@ -376,8 +424,20 @@ void UIWebView::loadDocumentData( URI url, std::string data, Uint64 generation )
|
||||
}
|
||||
|
||||
void UIWebView::onDocumentViewportGeometryChanged() {
|
||||
if ( updateDocumentViewportMetrics() )
|
||||
if ( updateDocumentViewportMetrics() ) {
|
||||
updateHTMLMinHeightForDocument();
|
||||
if ( mDocContainer && mDocContainer->isLayout() )
|
||||
mDocContainer->asType<UILayout>()->setLayoutDirty( LayoutInvalidation::Document );
|
||||
if ( auto htmlNode = mDocumentScene->findByType( UI_TYPE_HTML_HTML ) ) {
|
||||
if ( htmlNode->isWidget() )
|
||||
resetViewportDependentDocumentWidths( htmlNode->asType<UIWidget>() );
|
||||
if ( htmlNode->isLayout() )
|
||||
htmlNode->asType<UILayout>()->setLayoutDirty( LayoutInvalidation::Document );
|
||||
}
|
||||
mDocumentScene->update( Time::Zero );
|
||||
updateDocumentSceneContentExtent();
|
||||
return;
|
||||
}
|
||||
updateDocumentSceneContentExtent();
|
||||
}
|
||||
|
||||
@@ -490,6 +550,8 @@ void UIWebView::updateDocumentSceneContentExtent() {
|
||||
|
||||
if ( auto htmlNode = mDocContainer->findByType( UI_TYPE_HTML_HTML ) ) {
|
||||
UIWidget* html = htmlNode->asType<UIWidget>();
|
||||
resetViewportDependentDocumentWidths( html );
|
||||
mDocumentScene->updateDirtyLayouts();
|
||||
expandWidgetContentExtent( html, Vector2f::Zero, extent );
|
||||
}
|
||||
|
||||
|
||||
@@ -521,8 +521,7 @@ UTEST( UIWebView, HiddenAndClippedWideDescendantsDoNotCreateHorizontalScroll ) {
|
||||
EXPECT_GT( clippedWide->getPixelsSize().getWidth(), 1000.f );
|
||||
EXPECT_TRUE( webView->getVerticalScrollBar()->isVisible() );
|
||||
EXPECT_FALSE( webView->getHorizontalScrollBar()->isVisible() );
|
||||
EXPECT_NEAR( documentScene->getPixelsSize().getWidth(),
|
||||
documentScene->getViewportPixelsSize().getWidth(), 0.5f );
|
||||
EXPECT_LE( documentScene->getPixelsSize().getWidth(), webView->getPixelsSize().getWidth() );
|
||||
|
||||
Engine::destroySingleton();
|
||||
}
|
||||
@@ -856,6 +855,82 @@ UTEST( UIWebView, NavigationAfterGrowDoesNotKeepMaximizedWidthOnShrink ) {
|
||||
Engine::destroySingleton();
|
||||
}
|
||||
|
||||
UTEST( UIWebView, HackerNewsSingleStepRestoreSettlesViewportInOneFrame ) {
|
||||
auto win = Engine::instance()->createWindow(
|
||||
WindowSettings( 1024, 650, "UIWebView Single Step Restore Test", WindowStyle::Default,
|
||||
WindowBackend::Default, 32, {}, 1.f, false, true ),
|
||||
ContextSettings( false, 0, 0, GLv_default, true, false ) );
|
||||
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
|
||||
|
||||
FontTrueType* font = FontTrueType::New( "NotoSans-Regular" );
|
||||
font->loadFromFile( "../assets/fonts/NotoSans-Regular.ttf" );
|
||||
ASSERT_TRUE( font != nullptr && font->loaded() );
|
||||
FontFamily::loadFromRegular( font );
|
||||
|
||||
UISceneNode* sceneNode = UISceneNode::New();
|
||||
SceneManager::instance()->add( sceneNode );
|
||||
sceneNode->getUIThemeManager()->setDefaultFont( font );
|
||||
|
||||
UIWebView* webView = UIWebView::New();
|
||||
webView->setParent( sceneNode->getRoot() );
|
||||
webView->setPixelsSize( 800, 500 );
|
||||
webView->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed );
|
||||
webView->getVerticalScrollBar()->setPixelsSize( 15, 500 );
|
||||
webView->getHorizontalScrollBar()->setPixelsSize( 800, 15 );
|
||||
webView->loadURI( URI( "file://" + Sys::getProcessPath() + "assets/html/hn_frontpage.html" ) );
|
||||
|
||||
UISceneNode* documentScene = webView->getDocumentSceneNode();
|
||||
ASSERT_TRUE( documentScene != nullptr );
|
||||
|
||||
auto pump = [&]() {
|
||||
for ( int i = 0; i < 30; i++ ) {
|
||||
win->getInput()->update();
|
||||
SceneManager::instance()->update( Seconds( 1.f / 60.f ) );
|
||||
}
|
||||
};
|
||||
auto updateOnce = [&]() {
|
||||
win->getInput()->update();
|
||||
SceneManager::instance()->update( Seconds( 1.f / 60.f ) );
|
||||
};
|
||||
|
||||
pump();
|
||||
ASSERT_GE( documentScene->getRoot()->querySelectorAll( ".athing" ).size(), (size_t)30 );
|
||||
|
||||
webView->setPixelsSize( 2345, 900 );
|
||||
webView->getVerticalScrollBar()->setPixelsSize( 15, 900 );
|
||||
webView->getHorizontalScrollBar()->setPixelsSize( 2345, 15 );
|
||||
updateOnce();
|
||||
|
||||
EXPECT_NEAR( documentScene->getViewportPixelsSize().getWidth(),
|
||||
webView->getContainer()->getPixelsSize().getWidth(), 0.5f );
|
||||
EXPECT_GT( documentScene->getViewportPixelsSize().getWidth(), 2000.f );
|
||||
|
||||
webView->setPixelsSize( 800, 500 );
|
||||
webView->getVerticalScrollBar()->setPixelsSize( 15, 500 );
|
||||
webView->getHorizontalScrollBar()->setPixelsSize( 800, 15 );
|
||||
updateOnce();
|
||||
|
||||
UIWidget* html = documentScene->getRoot()->findByType( UI_TYPE_HTML_HTML )->asType<UIWidget>();
|
||||
UIWidget* body = documentScene->getRoot()->findByType( UI_TYPE_HTML_BODY )->asType<UIWidget>();
|
||||
UIWidget* center = documentScene->getRoot()->querySelector( "center" )->asType<UIWidget>();
|
||||
UIWidget* table = documentScene->getRoot()->find( "hnmain" )->asType<UIWidget>();
|
||||
ASSERT_TRUE( html != nullptr );
|
||||
ASSERT_TRUE( body != nullptr );
|
||||
ASSERT_TRUE( center != nullptr );
|
||||
ASSERT_TRUE( table != nullptr );
|
||||
EXPECT_NEAR( documentScene->getViewportPixelsSize().getWidth(),
|
||||
webView->getContainer()->getPixelsSize().getWidth(), 0.5f );
|
||||
EXPECT_LT( documentScene->getViewportPixelsSize().getWidth(), 900.f );
|
||||
EXPECT_LT( html->getPixelsSize().getWidth(), 900.f );
|
||||
EXPECT_LT( body->getPixelsSize().getWidth(), 900.f );
|
||||
EXPECT_LT( center->getPixelsSize().getWidth(), 900.f );
|
||||
EXPECT_LT( table->getPixelsSize().getWidth(), 900.f );
|
||||
EXPECT_LT( documentScene->getPixelsSize().getWidth(), webView->getPixelsSize().getWidth() );
|
||||
EXPECT_FALSE( webView->getHorizontalScrollBar()->isVisible() );
|
||||
|
||||
Engine::destroySingleton();
|
||||
}
|
||||
|
||||
UTEST( UIWebView, LayoutDrivenResizeKeepsDocumentRootAtViewport ) {
|
||||
auto win = Engine::instance()->createWindow(
|
||||
WindowSettings( 1024, 650, "UIWebView Layout Driven Resize Test", WindowStyle::Default,
|
||||
|
||||
Reference in New Issue
Block a user