Bug 1665955 - Stop including nsIScrollableFrame.h from Element.h. r=emilio

Changes to nsIScrollableFrame.h cause the world to rebuild which I find annoying.
This removes the inclusion into Element.h which is responsible for the
world-rebuilding and is relatively easy to eliminate. A bunch of usages of
nsIScrollableFrame get moved from .h files into .cpp files and I include the
header into .cpp files as needed.

Differential Revision: https://phabricator.services.mozilla.com/D90735
This commit is contained in:
Kartikaya Gupta 2020-09-18 18:32:13 +00:00
parent 433b8b3f69
commit f38b3ecb1b
12 changed files with 95 additions and 69 deletions

View File

@ -9,6 +9,7 @@
#include "DocAccessibleChild.h"
#include "DocAccessibleWrap.h"
#include "nsIDocShell.h"
#include "nsIScrollableFrame.h"
#include "nsLayoutUtils.h"
#include "nsAccessibilityService.h"
#include "nsAccUtils.h"

View File

@ -35,6 +35,7 @@
#include "nsDOMMutationObserver.h" // For nsAutoAnimationMutationBatch
#include "nsIFrame.h"
#include "nsIFrameInlines.h"
#include "nsIScrollableFrame.h"
#include "nsPresContextInlines.h"
#include "nsRefreshDriver.h"

View File

@ -781,6 +781,38 @@ void Element::MozScrollSnap() {
}
}
int32_t Element::ScrollTopMin() {
nsIScrollableFrame* sf = GetScrollFrame();
if (!sf) {
return 0;
}
return CSSPixel::FromAppUnits(sf->GetScrollRange().y).Rounded();
}
int32_t Element::ScrollTopMax() {
nsIScrollableFrame* sf = GetScrollFrame();
if (!sf) {
return 0;
}
return CSSPixel::FromAppUnits(sf->GetScrollRange().YMost()).Rounded();
}
int32_t Element::ScrollLeftMin() {
nsIScrollableFrame* sf = GetScrollFrame();
if (!sf) {
return 0;
}
return CSSPixel::FromAppUnits(sf->GetScrollRange().x).Rounded();
}
int32_t Element::ScrollLeftMax() {
nsIScrollableFrame* sf = GetScrollFrame();
if (!sf) {
return 0;
}
return CSSPixel::FromAppUnits(sf->GetScrollRange().XMost()).Rounded();
}
static nsSize GetScrollRectSizeForOverflowVisibleFrame(nsIFrame* aFrame) {
if (!aFrame || aFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
return nsSize(0, 0);

View File

@ -19,7 +19,6 @@
#include "nsChangeHint.h"
#include "nsContentUtils.h"
#include "nsDOMAttributeMap.h"
#include "nsIScrollableFrame.h"
#include "nsRect.h"
#include "Units.h"
#include "mozilla/Attributes.h"
@ -38,6 +37,7 @@
class mozAutoDocUpdate;
class nsIFrame;
class nsIMozBrowserFrame;
class nsIScrollableFrame;
class nsIURI;
class nsAttrValueOrString;
class nsContentList;
@ -75,6 +75,7 @@ struct ScrollIntoViewOptions;
struct ScrollToOptions;
struct FocusOptions;
struct ShadowRootInit;
struct ScrollOptions;
class BooleanOrScrollIntoViewOptions;
class DOMIntersectionObserver;
class DOMMatrixReadOnly;
@ -1331,34 +1332,10 @@ class Element : public FragmentOrElement {
MOZ_CAN_RUN_SCRIPT int32_t ClientHeight() {
return CSSPixel::FromAppUnits(GetClientAreaRect().Height()).Rounded();
}
MOZ_CAN_RUN_SCRIPT int32_t ScrollTopMin() {
nsIScrollableFrame* sf = GetScrollFrame();
if (!sf) {
return 0;
}
return CSSPixel::FromAppUnits(sf->GetScrollRange().y).Rounded();
}
MOZ_CAN_RUN_SCRIPT int32_t ScrollTopMax() {
nsIScrollableFrame* sf = GetScrollFrame();
if (!sf) {
return 0;
}
return CSSPixel::FromAppUnits(sf->GetScrollRange().YMost()).Rounded();
}
MOZ_CAN_RUN_SCRIPT int32_t ScrollLeftMin() {
nsIScrollableFrame* sf = GetScrollFrame();
if (!sf) {
return 0;
}
return CSSPixel::FromAppUnits(sf->GetScrollRange().x).Rounded();
}
MOZ_CAN_RUN_SCRIPT int32_t ScrollLeftMax() {
nsIScrollableFrame* sf = GetScrollFrame();
if (!sf) {
return 0;
}
return CSSPixel::FromAppUnits(sf->GetScrollRange().XMost()).Rounded();
}
MOZ_CAN_RUN_SCRIPT int32_t ScrollTopMin();
MOZ_CAN_RUN_SCRIPT int32_t ScrollTopMax();
MOZ_CAN_RUN_SCRIPT int32_t ScrollLeftMin();
MOZ_CAN_RUN_SCRIPT int32_t ScrollLeftMax();
MOZ_CAN_RUN_SCRIPT double ClientHeightDouble() {
return CSSPixel::FromAppUnits(GetClientAreaRect().Height());

View File

@ -20,6 +20,7 @@
# include "mozilla/gfx/Rect.h"
# include "mozilla/layers/LayersTypes.h"
class nsDisplayListBuilder;
class nsICanvasRenderingContextInternal;
class nsITimerCallback;
enum class gfxAlphaType;

View File

@ -1346,6 +1346,10 @@ nsIFrame* nsComboboxControlFrame::CreateFrameForDisplayNode() {
return mDisplayFrame;
}
nsIScrollableFrame* nsComboboxControlFrame::GetScrollTargetFrame() {
return do_QueryFrame(mDropdownFrame);
}
void nsComboboxControlFrame::DestroyFrom(nsIFrame* aDestructRoot,
PostDestroyData& aPostDestroyData) {
if (sFocused == this) {

View File

@ -102,9 +102,7 @@ class nsComboboxControlFrame final : public nsBlockFrame,
aFlags & ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
}
virtual nsIScrollableFrame* GetScrollTargetFrame() override {
return do_QueryFrame(mDropdownFrame);
}
virtual nsIScrollableFrame* GetScrollTargetFrame() override;
#ifdef DEBUG_FRAME_DUMP
virtual nsresult GetFrameName(nsAString& aResult) const override;

View File

@ -13,6 +13,7 @@
#include "nsArray.h"
#include "nsString.h"
#include "nsIContentInlines.h"
#include "nsIScrollableFrame.h"
#include "mozilla/dom/Document.h"
#include "ChildIterator.h"
#include "nsComputedDOMStyle.h"

View File

@ -17,6 +17,7 @@
#include "nsExpirationTracker.h"
#include "nsContainerFrame.h"
#include "nsIContent.h"
#include "nsIScrollableFrame.h"
#include "nsRefreshDriver.h"
#include "nsPIDOMWindow.h"
#include "mozilla/dom/Document.h"

View File

@ -174,6 +174,34 @@ void UpdateDisplayItemData(nsPaintedDisplayItem* aItem) {
}
}
/* static */
already_AddRefed<ActiveScrolledRoot> ActiveScrolledRoot::CreateASRForFrame(
const ActiveScrolledRoot* aParent, nsIScrollableFrame* aScrollableFrame,
bool aIsRetained) {
nsIFrame* f = do_QueryFrame(aScrollableFrame);
RefPtr<ActiveScrolledRoot> asr;
if (aIsRetained) {
asr = f->GetProperty(ActiveScrolledRootCache());
}
if (!asr) {
asr = new ActiveScrolledRoot();
if (aIsRetained) {
RefPtr<ActiveScrolledRoot> ref = asr;
f->SetProperty(ActiveScrolledRootCache(), ref.forget().take());
}
}
asr->mParent = aParent;
asr->mScrollableFrame = aScrollableFrame;
asr->mViewId = Nothing();
asr->mDepth = aParent ? aParent->mDepth + 1 : 1;
asr->mRetained = aIsRetained;
return asr.forget();
}
/* static */
bool ActiveScrolledRoot::IsAncestor(const ActiveScrolledRoot* aAncestor,
const ActiveScrolledRoot* aDescendant) {
@ -207,6 +235,21 @@ nsCString ActiveScrolledRoot::ToString(
return std::move(str);
}
ViewID ActiveScrolledRoot::GetViewId() const {
if (!mViewId.isSome()) {
nsIContent* content = mScrollableFrame->GetScrolledFrame()->GetContent();
mViewId = Some(nsLayoutUtils::FindOrCreateIDFor(content));
}
return *mViewId;
}
ActiveScrolledRoot::~ActiveScrolledRoot() {
if (mScrollableFrame && mRetained) {
nsIFrame* f = do_QueryFrame(mScrollableFrame);
f->RemoveProperty(ActiveScrolledRootCache());
}
}
static uint64_t AddAnimationsForWebRender(
nsDisplayItem* aItem, mozilla::layers::RenderRootStateManager* aManager,
nsDisplayListBuilder* aDisplayListBuilder,

View File

@ -262,30 +262,7 @@ namespace mozilla {
struct ActiveScrolledRoot {
static already_AddRefed<ActiveScrolledRoot> CreateASRForFrame(
const ActiveScrolledRoot* aParent, nsIScrollableFrame* aScrollableFrame,
bool aIsRetained) {
nsIFrame* f = do_QueryFrame(aScrollableFrame);
RefPtr<ActiveScrolledRoot> asr;
if (aIsRetained) {
asr = f->GetProperty(ActiveScrolledRootCache());
}
if (!asr) {
asr = new ActiveScrolledRoot();
if (aIsRetained) {
RefPtr<ActiveScrolledRoot> ref = asr;
f->SetProperty(ActiveScrolledRootCache(), ref.forget().take());
}
}
asr->mParent = aParent;
asr->mScrollableFrame = aScrollableFrame;
asr->mViewId = Nothing();
asr->mDepth = aParent ? aParent->mDepth + 1 : 1;
asr->mRetained = aIsRetained;
return asr.forget();
}
bool aIsRetained);
static const ActiveScrolledRoot* PickAncestor(
const ActiveScrolledRoot* aOne, const ActiveScrolledRoot* aTwo) {
@ -312,13 +289,7 @@ struct ActiveScrolledRoot {
* Find the view ID (or generate a new one) for the content element
* corresponding to the ASR.
*/
mozilla::layers::ScrollableLayerGuid::ViewID GetViewId() const {
if (!mViewId.isSome()) {
nsIContent* content = mScrollableFrame->GetScrolledFrame()->GetContent();
mViewId = Some(nsLayoutUtils::FindOrCreateIDFor(content));
}
return *mViewId;
}
mozilla::layers::ScrollableLayerGuid::ViewID GetViewId() const;
RefPtr<const ActiveScrolledRoot> mParent;
nsIScrollableFrame* mScrollableFrame;
@ -329,12 +300,7 @@ struct ActiveScrolledRoot {
ActiveScrolledRoot()
: mScrollableFrame(nullptr), mDepth(0), mRetained(false) {}
~ActiveScrolledRoot() {
if (mScrollableFrame && mRetained) {
nsIFrame* f = do_QueryFrame(mScrollableFrame);
f->RemoveProperty(ActiveScrolledRootCache());
}
}
~ActiveScrolledRoot();
static void DetachASR(ActiveScrolledRoot* aASR) {
aASR->mParent = nullptr;

View File

@ -8,6 +8,7 @@
#include "mozilla/dom/Document.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsIScrollableFrame.h"
#include "nsNumberControlFrame.h"
#include "nsPresContext.h"
#include "nsString.h"