From 7cdfa1649e821fff80db5da2b12f886b82f6364d Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Thu, 29 Nov 2018 00:17:25 +0100 Subject: [PATCH] Bug 1509903 part 1 - Make nsTextFrame::IsFrameSelected() 'final' and inline nsIFrame::IsSelected() to de-virtualize the IsFrameSelected() call in some cases. r=emilio In particular, in nsCharClipDisplayItem::IsSelected() we know that the frame must be a nsTextFrame (or nsContinuingTextFrame) which means nsTextFrame::IsFrameSelected() can be called directly now. --- layout/generic/nsFrame.cpp | 7 ------- layout/generic/nsIFrame.h | 5 ++++- layout/generic/nsTextFrame.h | 2 +- layout/painting/nsDisplayList.cpp | 13 +++++++++++++ layout/painting/nsDisplayList.h | 9 +-------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index fbc143fe4050..add3e263ce00 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -11030,13 +11030,6 @@ nsIFrame::CreateOwnLayerIfNeeded(nsDisplayListBuilder* aBuilder, } } -bool -nsIFrame::IsSelected() const -{ - return (GetContent() && GetContent()->IsSelectionDescendant()) ? - IsFrameSelected() : false; -} - bool nsIFrame::IsStackingContext(EffectSet* aEffectSet, const nsStyleDisplay* aStyleDisplay, diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h index edc0822a5249..c11ae9741762 100644 --- a/layout/generic/nsIFrame.h +++ b/layout/generic/nsIFrame.h @@ -3232,7 +3232,10 @@ public: /** * @returns true if this frame is selected. */ - bool IsSelected() const; + bool IsSelected() const { + return (GetContent() && GetContent()->IsSelectionDescendant()) ? + IsFrameSelected() : false; + } /** * called to discover where this frame, or a parent frame has user-select style diff --git a/layout/generic/nsTextFrame.h b/layout/generic/nsTextFrame.h index 4f61cfac067e..e59850ea3e55 100644 --- a/layout/generic/nsTextFrame.h +++ b/layout/generic/nsTextFrame.h @@ -704,7 +704,7 @@ protected: * Return true if the frame is part of a Selection. * Helper method to implement the public IsSelected() API. */ - bool IsFrameSelected() const override; + bool IsFrameSelected() const final; mozilla::UniquePtr GetSelectionDetails(); diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index cdcd5f28e4d3..e7c762b06ec1 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -90,6 +90,7 @@ #include "nsSVGMaskFrame.h" #include "nsTableCellFrame.h" #include "nsTableColFrame.h" +#include "nsTextFrame.h" #include "nsSliderFrame.h" #include "ClientLayerManager.h" #include "mozilla/layers/StackingContextHelper.h" @@ -9604,6 +9605,18 @@ nsCharClipDisplayItem::ComputeInvalidationRegion( } } +bool +nsCharClipDisplayItem::IsSelected() const +{ + if (mIsFrameSelected.isNothing()) { + MOZ_ASSERT((nsTextFrame*)do_QueryFrame(mFrame)); + auto* f = static_cast(mFrame); + mIsFrameSelected.emplace(f->IsSelected()); + } + + return mIsFrameSelected.value(); +} + nsDisplayEffectsBase::nsDisplayEffectsBase( nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, diff --git a/layout/painting/nsDisplayList.h b/layout/painting/nsDisplayList.h index d47c52c518bf..0399a43f90a3 100644 --- a/layout/painting/nsDisplayList.h +++ b/layout/painting/nsDisplayList.h @@ -7798,14 +7798,7 @@ public: : nullptr; } - bool IsSelected() const - { - if (mIsFrameSelected.isNothing()) { - mIsFrameSelected.emplace(mFrame->IsSelected()); - } - - return mIsFrameSelected.value(); - } + bool IsSelected() const; // Lengths measured from the visual inline start and end sides // (i.e. left and right respectively in horizontal writing modes,