Bug 1709347 - Add CanvasRenderingContext2D.reset(). r=lsalzman,webidl,smaug
[gecko.git] / layout / xul / nsScrollbarFrame.h
blob2539686f100329ca5b2820941cc1e29faf21362d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 //
8 // nsScrollbarFrame
9 //
11 #ifndef nsScrollbarFrame_h__
12 #define nsScrollbarFrame_h__
14 #include "mozilla/Attributes.h"
15 #include "mozilla/ScrollTypes.h"
16 #include "nsIAnonymousContentCreator.h"
17 #include "nsBoxFrame.h"
19 class nsIScrollbarMediator;
21 namespace mozilla {
22 class PresShell;
23 namespace dom {
24 class Element;
26 } // namespace mozilla
28 nsIFrame* NS_NewScrollbarFrame(mozilla::PresShell* aPresShell,
29 mozilla::ComputedStyle* aStyle);
31 class nsScrollbarFrame final : public nsBoxFrame,
32 public nsIAnonymousContentCreator {
33 using Element = mozilla::dom::Element;
35 public:
36 explicit nsScrollbarFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
37 : nsBoxFrame(aStyle, aPresContext, kClassID),
38 mSmoothScroll(false),
39 mScrollUnit(mozilla::ScrollUnit::DEVICE_PIXELS),
40 mDirection(0),
41 mIncrement(0),
42 mScrollbarMediator(nullptr),
43 mUpTopButton(nullptr),
44 mDownTopButton(nullptr),
45 mSlider(nullptr),
46 mThumb(nullptr),
47 mUpBottomButton(nullptr),
48 mDownBottomButton(nullptr) {}
50 NS_DECL_QUERYFRAME
51 NS_DECL_FRAMEARENA_HELPERS(nsScrollbarFrame)
53 #ifdef DEBUG_FRAME_DUMP
54 virtual nsresult GetFrameName(nsAString& aResult) const override {
55 return MakeFrameName(u"ScrollbarFrame"_ns, aResult);
57 #endif
59 // nsIFrame overrides
60 virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
61 int32_t aModType) override;
63 NS_IMETHOD HandlePress(nsPresContext* aPresContext,
64 mozilla::WidgetGUIEvent* aEvent,
65 nsEventStatus* aEventStatus) override;
67 NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext,
68 mozilla::WidgetGUIEvent* aEvent,
69 nsEventStatus* aEventStatus,
70 bool aControlHeld) override;
72 MOZ_CAN_RUN_SCRIPT
73 NS_IMETHOD HandleDrag(nsPresContext* aPresContext,
74 mozilla::WidgetGUIEvent* aEvent,
75 nsEventStatus* aEventStatus) override;
77 NS_IMETHOD HandleRelease(nsPresContext* aPresContext,
78 mozilla::WidgetGUIEvent* aEvent,
79 nsEventStatus* aEventStatus) override;
81 virtual void DestroyFrom(nsIFrame* aDestructRoot,
82 PostDestroyData& aPostDestroyData) override;
84 virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
85 nsIFrame* aPrevInFlow) override;
87 virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
88 const ReflowInput& aReflowInput,
89 nsReflowStatus& aStatus) override;
91 void SetScrollbarMediatorContent(nsIContent* aMediator);
92 nsIScrollbarMediator* GetScrollbarMediator();
94 // nsBox methods
96 /**
97 * Treat scrollbars as clipping their children; overflowing children
98 * will not be allowed to set an overflow rect on this
99 * frame. This means that when the scroll code decides to hide a
100 * scrollframe by setting its height or width to zero, that will
101 * hide the children too.
103 virtual bool DoesClipChildrenInBothAxes() override { return true; }
105 virtual nsresult GetXULMargin(nsMargin& aMargin) override;
108 * The following three methods set the value of mIncrement when a
109 * scrollbar button is pressed.
111 void SetIncrementToLine(int32_t aDirection);
112 void SetIncrementToPage(int32_t aDirection);
113 void SetIncrementToWhole(int32_t aDirection);
115 * If aImplementsScrollByUnit is Yes then this uses mSmoothScroll,
116 * mScrollUnit, and mDirection and calls ScrollByUnit on the
117 * nsIScrollbarMediator. The return value is 0. This is better because it is
118 * more modern and the scroll frame can perform the scroll via apz for
119 * example. The old way below is still supported for xul trees. If
120 * aImplementsScrollByUnit is No this adds mIncrement to the current
121 * position and updates the curpos attribute obeying mSmoothScroll.
122 * @returns The new position after clamping, in CSS Pixels
123 * @note This method might destroy the frame, pres shell, and other objects.
125 enum class ImplementsScrollByUnit { Yes, No };
126 int32_t MoveToNewPosition(ImplementsScrollByUnit aImplementsScrollByUnit);
127 int32_t GetIncrement() { return mIncrement; }
129 // nsIAnonymousContentCreator
130 virtual nsresult CreateAnonymousContent(
131 nsTArray<ContentInfo>& aElements) override;
132 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
133 uint32_t aFilter) override;
135 void UpdateChildrenAttributeValue(nsAtom* aAttribute, bool aNotify);
137 protected:
138 bool mSmoothScroll;
139 mozilla::ScrollUnit mScrollUnit;
140 // Direction and multiple to scroll
141 int32_t mDirection;
143 // Amount to scroll, in CSSPixels
144 // Ignored in favour of mScrollUnit/mDirection for regular scroll frames.
145 // Trees use this though.
146 int32_t mIncrement;
148 private:
149 nsCOMPtr<nsIContent> mScrollbarMediator;
151 nsCOMPtr<Element> mUpTopButton;
152 nsCOMPtr<Element> mDownTopButton;
153 nsCOMPtr<Element> mSlider;
154 nsCOMPtr<Element> mThumb;
155 nsCOMPtr<Element> mUpBottomButton;
156 nsCOMPtr<Element> mDownBottomButton;
157 }; // class nsScrollbarFrame
159 #endif