Skip to content

Commit

Permalink
Bug 1665955 - Stop including nsIScrollableFrame.h from Element.h. r=e…
Browse files Browse the repository at this point in the history
…milio

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
  • Loading branch information
staktrace committed Sep 18, 2020
1 parent 8d8fd2d commit 21fe409
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 69 deletions.
1 change: 1 addition & 0 deletions accessible/android/DocAccessibleWrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions dom/animation/KeyframeEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "nsDOMMutationObserver.h" // For nsAutoAnimationMutationBatch
#include "nsIFrame.h"
#include "nsIFrameInlines.h"
#include "nsIScrollableFrame.h"
#include "nsPresContextInlines.h"
#include "nsRefreshDriver.h"

Expand Down
32 changes: 32 additions & 0 deletions dom/base/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 6 additions & 29 deletions dom/base/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -38,6 +37,7 @@
class mozAutoDocUpdate;
class nsIFrame;
class nsIMozBrowserFrame;
class nsIScrollableFrame;
class nsIURI;
class nsAttrValueOrString;
class nsContentList;
Expand Down Expand Up @@ -75,6 +75,7 @@ struct ScrollIntoViewOptions;
struct ScrollToOptions;
struct FocusOptions;
struct ShadowRootInit;
struct ScrollOptions;
class BooleanOrScrollIntoViewOptions;
class DOMIntersectionObserver;
class DOMMatrixReadOnly;
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions dom/html/HTMLCanvasElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# include "mozilla/gfx/Rect.h"
# include "mozilla/layers/LayersTypes.h"

class nsDisplayListBuilder;
class nsICanvasRenderingContextInternal;
class nsITimerCallback;
enum class gfxAlphaType;
Expand Down
4 changes: 4 additions & 0 deletions layout/forms/nsComboboxControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions layout/forms/nsComboboxControlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions layout/inspector/InspectorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions layout/painting/ActiveLayerTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 43 additions & 0 deletions layout/painting/nsDisplayList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 3 additions & 37 deletions layout/painting/nsDisplayList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions widget/nsNativeTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 21fe409

Please sign in to comment.