void ScrollAnchor::adjust() { if (!m_queued) return; m_queued = false; DCHECK(m_scroller); if (!m_anchorObject) return; IntSize adjustment = computeAdjustment(); if (adjustment.isZero()) return; if (m_scrollAnchorDisablingStyleChanged) { // Note that we only clear if the adjustment would have been non-zero. // This minimizes redundant calls to findAnchor. // TODO(skobes): add UMA metric for this. clearSelf(); DEFINE_STATIC_LOCAL(EnumerationHistogram, suppressedBySanaclapHistogram, ("Layout.ScrollAnchor.SuppressedBySanaclap", 2)); suppressedBySanaclapHistogram.count(1); return; } m_scroller->setScrollOffset( m_scroller->getScrollOffset() + FloatSize(adjustment), AnchoringScroll); // Update UMA metric. DEFINE_STATIC_LOCAL(EnumerationHistogram, adjustedOffsetHistogram, ("Layout.ScrollAnchor.AdjustedScrollOffset", 2)); adjustedOffsetHistogram.count(1); UseCounter::count(scrollerLayoutBox(m_scroller)->document(), UseCounter::ScrollAnchored); }
void ScrollAnchor::setScroller(ScrollableArea* scroller) { DCHECK(m_scroller != scroller); DCHECK(scroller); DCHECK(scroller->isRootFrameViewport() || scroller->isFrameView() || scroller->isPaintLayerScrollableArea()); m_scroller = scroller; clearSelf(); }
void ScrollAnchor::notifyBeforeLayout() { if (m_queued) { m_scrollAnchorDisablingStyleChanged |= computeScrollAnchorDisablingStyleChanged(); return; } DCHECK(m_scroller); ScrollOffset scrollOffset = m_scroller->getScrollOffset(); float blockDirectionScrollOffset = scrollerLayoutBox(m_scroller)->isHorizontalWritingMode() ? scrollOffset.height() : scrollOffset.width(); if (blockDirectionScrollOffset == 0) { clearSelf(); return; } if (!m_anchorObject) { findAnchor(); if (!m_anchorObject) return; m_anchorObject->setIsScrollAnchorObject(); m_savedRelativeOffset = computeRelativeOffset(m_anchorObject, m_scroller, m_corner); } m_scrollAnchorDisablingStyleChanged = computeScrollAnchorDisablingStyleChanged(); FrameView* frameView = scrollerLayoutBox(m_scroller)->frameView(); ScrollableArea* owningScroller = m_scroller->isRootFrameViewport() ? &toRootFrameViewport(m_scroller)->layoutViewport() : m_scroller.get(); frameView->enqueueScrollAnchoringAdjustment(owningScroller); m_queued = true; }
//自定义 右键菜单 void MusicList::contextMenuEvent(QContextMenuEvent *event) { //播放列表右键菜单 if (this->currentItem() == this->topLevelItem(0)) { QMenu menu_rootDir; menu_rootDir.addAction(tr("清空所有列表"), this, SLOT(clearAll())); menu_rootDir.exec(event ->globalPos()); return; } for (int i=0; i<this->topLevelItemCount(); i++) { if (this->currentItem() == this->topLevelItem(i)) { //创建节点菜单 QMenu menu_rootDir; menu_rootDir.addAction(tr("删除"), this, SLOT(remove_rootDir())); menu_rootDir.addAction(tr("重命名"), this, SLOT(renameToplevel(QTreeWidgetItem *item))); menu_rootDir.addAction(tr("清空所有列表"), this, SLOT(clearAll())); menu_rootDir.exec(event ->globalPos()); return; } } //音乐右键菜单 QStringList otherToplevel; // 选中列表外的其他列表(用于添加到其他列表) QString activedToplevel = this->topLevelItem(get_current_rootDir())->text(0); // 被右键选中的列表的名字 for(int i=0; i<this->topLevelItemCount(); i++) // 遍历选中之外的其他列表的名字 { QString toplevelText = this->topLevelItem(i)->text(0); if (toplevelText == activedToplevel) { continue; } otherToplevel.append(toplevelText); } //创建二级菜单 QMenu menu_child; menu_child.setIcon(QIcon(":/Images/menu_add.png")); menu_child.setTitle(tr("添加到...")); for (int i=0; i<this->topLevelItemCount(); ++i) { if (this->topLevelItem(i) != this->topLevelItem(get_current_rootDir())) { menu_child.addAction(musicMenuActionList[i]); } } connect(&menu_child, SIGNAL(triggered(QAction*)), this, SLOT(add_otherMusicList(QAction*))); // for (int i=0; i<otherToplevel.count(); i++) // { // menu_child.addAction(otherToplevel.at(i), this, SLOT(add_otherMusicList())); // } //创建项目菜单 QMenu menu_item; menu_item.addAction(QIcon(":/Images/menu_play.png"), tr("立即播放"), this, SLOT(rightBtnPlay())); menu_item.addMenu(&menu_child); menu_item.addAction(QIcon(":/Images/miniWindow_hover.png"), tr("移出列表"), this, SLOT(removeSelection())); menu_item.addAction(QIcon(":/Images/closeWindow_hover.png"), tr("删除歌曲及文件"), this, SLOT(deleteSelection())); menu_item.addAction(QIcon(":/Images/menu_clear.png"), tr("清空本列表"), this, SLOT(clearSelf())); menu_item.exec(event ->globalPos()); return; }
void ScrollAnchor::notifyRemoved(LayoutObject* layoutObject) { if (m_anchorObject == layoutObject) clearSelf(); }