void RenderFrame::layout() { FrameView* view = static_cast<FrameView*>(widget()); RenderView* root = view ? view->frame()->contentRenderer() : 0; // Do not expand frames which has zero width or height if (!width() || !height() || !root) { updateWidgetPosition(); if (view) view->layout(); setNeedsLayout(false); return; } HTMLFrameElementBase* element = static_cast<HTMLFrameElementBase*>(node()); if (element->scrollingMode() == ScrollbarAlwaysOff && !root->isFrameSet()) { setNeedsLayout(false); return; } // Update the dimensions to get the correct width and height updateWidgetPosition(); if (root->preferredLogicalWidthsDirty()) root->computePreferredLogicalWidths(); // Expand the frame by setting frame height = content height setWidth(max(view->contentsWidth() + borderAndPaddingWidth(), width())); setHeight(max(view->contentsHeight() + borderAndPaddingHeight(), height())); // Update one more time updateWidgetPosition(); setNeedsLayout(false); }
void RenderFrameBase::layoutWithFlattening(bool fixedWidth, bool fixedHeight) { FrameView* childFrameView = static_cast<FrameView*>(widget()); RenderView* childRoot = childFrameView ? static_cast<RenderView*>(childFrameView->frame()->contentRenderer()) : 0; // Do not expand frames which has zero width or height if (!width() || !height() || !childRoot) { updateWidgetPosition(); if (childFrameView) childFrameView->layout(); setNeedsLayout(false); return; } // need to update to calculate min/max correctly updateWidgetPosition(); if (childRoot->preferredLogicalWidthsDirty()) childRoot->computePreferredLogicalWidths(); // if scrollbars are off, and the width or height are fixed // we obey them and do not expand. With frame flattening // no subframe much ever become scrollable. HTMLFrameElementBase* element = static_cast<HTMLFrameElementBase*>(node()); bool isScrollable = element->scrollingMode() != ScrollbarAlwaysOff; // consider iframe inset border int hBorder = borderLeft() + borderRight(); int vBorder = borderTop() + borderBottom(); // make sure minimum preferred width is enforced if (isScrollable || !fixedWidth) { setWidth(max(width(), childRoot->minPreferredLogicalWidth() + hBorder)); // update again to pass the new width to the child frame updateWidgetPosition(); childFrameView->layout(); } // expand the frame by setting frame height = content height if (isScrollable || !fixedHeight || childRoot->isFrameSet()) setHeight(max(height(), childFrameView->contentsHeight() + vBorder)); if (isScrollable || !fixedWidth || childRoot->isFrameSet()) setWidth(max(width(), childFrameView->contentsWidth() + hBorder)); updateWidgetPosition(); ASSERT(!childFrameView->layoutPending()); ASSERT(!childRoot->needsLayout()); ASSERT(!childRoot->firstChild() || !childRoot->firstChild()->firstChild() || !childRoot->firstChild()->firstChild()->needsLayout()); setNeedsLayout(false); }
void RenderFrameBase::peformLayoutWithFlattening(bool hasFixedWidth, bool hasFixedHeight) { if (!childRenderView()) return; if (!shouldExpandFrame(width(), height(), hasFixedWidth, hasFixedHeight)) { if (updateWidgetPosition() == ChildWidgetState::Destroyed) return; childView()->layout(); return; } // need to update to calculate min/max correctly if (updateWidgetPosition() == ChildWidgetState::Destroyed) return; // if scrollbars are off, and the width or height are fixed // we obey them and do not expand. With frame flattening // no subframe much ever become scrollable. bool isScrollable = frameOwnerElement().scrollingMode() != ScrollbarAlwaysOff; // consider iframe inset border int hBorder = borderLeft() + borderRight(); int vBorder = borderTop() + borderBottom(); // make sure minimum preferred width is enforced if (isScrollable || !hasFixedWidth) { ASSERT(childRenderView()); setWidth(std::max(width(), childRenderView()->minPreferredLogicalWidth() + hBorder)); // update again to pass the new width to the child frame if (updateWidgetPosition() == ChildWidgetState::Destroyed) return; childView()->layout(); } ASSERT(childView()); // expand the frame by setting frame height = content height if (isScrollable || !hasFixedHeight || childRenderView()->isFrameSet()) setHeight(std::max<LayoutUnit>(height(), childView()->contentsHeight() + vBorder)); if (isScrollable || !hasFixedWidth || childRenderView()->isFrameSet()) setWidth(std::max<LayoutUnit>(width(), childView()->contentsWidth() + hBorder)); if (updateWidgetPosition() == ChildWidgetState::Destroyed) return; ASSERT(!childView()->layoutPending()); ASSERT(!childRenderView()->needsLayout()); ASSERT(!childRenderView()->firstChild() || !childRenderView()->firstChild()->firstChildSlow() || !childRenderView()->firstChild()->firstChildSlow()->needsLayout()); }
void QScrollAreaPrivate::updateScrollBars() { Q_Q(QScrollArea); if (!widget) return; QSize p = viewport->size(); QSize m = q->maximumViewportSize(); QSize min = qSmartMinSize(widget); QSize max = qSmartMaxSize(widget); if (resizable) { if ((widget->layout() ? widget->layout()->hasHeightForWidth() : widget->sizePolicy().hasHeightForWidth())) { QSize p_hfw = p.expandedTo(min).boundedTo(max); int h = widget->heightForWidth( p_hfw.width() ); min = QSize(p_hfw.width(), qMax(p_hfw.height(), h)); } } if ((resizable && m.expandedTo(min) == m && m.boundedTo(max) == m) || (!resizable && m.expandedTo(widget->size()) == m)) p = m; // no scroll bars needed if (resizable) widget->resize(p.expandedTo(min).boundedTo(max)); QSize v = widget->size(); hbar->setRange(0, v.width() - p.width()); hbar->setPageStep(p.width()); vbar->setRange(0, v.height() - p.height()); vbar->setPageStep(p.height()); updateWidgetPosition(); }
void AdvScrollArea::resizeEvent(QResizeEvent* e) { std::cout << "RESIZE TO: " << e->size().width() << ":"<< e->size().height() << std::endl; Q_UNUSED(e); // scrollbar size unsigned int scrS = 16; unsigned int top = (headerH.widget) ? (headerH.height) : (0); unsigned int left = (headerV.widget) ? (headerV.width) : (0); // area unsigned int areaW = width() - scrS - left; unsigned int areaH = height() - scrS - top; area->setGeometry(left, top, areaW, areaH); area->setMaximumSize(areaW, areaH); // scrollbar position scrollV->setGeometry(width()-scrS, top, scrS, height()-scrS-top); scrollH->setGeometry(left, height()-scrS, width()-scrS-left, scrS); // scrollbar values updateScrollBars(); // move the widget updateWidgetPosition(); }
void QScrollAreaPrivate::updateScrollBars() { Q_Q(QScrollArea); if (!widget) return; QSize p = viewport->size(); QSize m = q->maximumViewportSize(); QSize min = qSmartMinSize(widget); QSize max = qSmartMaxSize(widget); if ((resizable && m.expandedTo(min) == m && m.boundedTo(max) == m) || (!resizable && m.expandedTo(widget->size()) == m)) p = m; // no scroll bars needed if (resizable) widget->resize(p.expandedTo(min).boundedTo(max)); QSize v = widget->size(); hbar->setRange(0, v.width() - p.width()); hbar->setPageStep(p.width()); vbar->setRange(0, v.height() - p.height()); vbar->setPageStep(p.height()); updateWidgetPosition(); }
void QcScrollArea::updateScrollBars() { QSize areaSize = viewport()->size(); QSize widgetSize = scrollWidget->size(); verticalScrollBar()->setPageStep(widgetSize.height()); horizontalScrollBar()->setPageStep(widgetSize.width()); verticalScrollBar()->setRange(0, widgetSize.height() - areaSize.height()); horizontalScrollBar()->setRange(0, widgetSize.width() - areaSize.width()); updateWidgetPosition(); }
void MyScrollArea::updateArea() { //! [1] QSize areaSize = viewport()->size(); QSize widgetSize = widget->size(); verticalScrollBar()->setPageStep(areaSize.height()); horizontalScrollBar()->setPageStep(areaSize.width()); verticalScrollBar()->setRange(0, widgetSize.height() - areaSize.height()); horizontalScrollBar()->setRange(0, widgetSize.width() - areaSize.width()); updateWidgetPosition(); //! [1] }
AdvScrollArea::AdvScrollArea(QWidget* parent) : QWidget(parent), content(nullptr) { // both scrollbars scrollV = new QScrollBar(Qt::Vertical, this); scrollH = new QScrollBar(Qt::Horizontal, this); // connect events connect(scrollV, SIGNAL(valueChanged(int)), this, SLOT(onScrollV())); connect(scrollH, SIGNAL(valueChanged(int)), this, SLOT(onScrollH())); // the widget accepting the content area = new QWidget(this); updateScrollBars(); updateWidgetPosition(); }
void AdvScrollArea::onScrollH() { updateWidgetPosition(); }
void MyScrollArea::scrollContentsBy(int /*dx*/, int /*dy*/) { updateWidgetPosition(); }
void QcScrollArea::scrollContentsBy ( int dx, int dy ) { updateWidgetPosition(); }