Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsSliderFrame_h__ |
michael@0 | 7 | #define nsSliderFrame_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "nsRepeatService.h" |
michael@0 | 11 | #include "nsBoxFrame.h" |
michael@0 | 12 | #include "nsIAtom.h" |
michael@0 | 13 | #include "nsCOMPtr.h" |
michael@0 | 14 | #include "nsITimer.h" |
michael@0 | 15 | #include "nsIDOMEventListener.h" |
michael@0 | 16 | |
michael@0 | 17 | class nsString; |
michael@0 | 18 | class nsITimer; |
michael@0 | 19 | class nsSliderFrame; |
michael@0 | 20 | |
michael@0 | 21 | nsIFrame* NS_NewSliderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
michael@0 | 22 | |
michael@0 | 23 | class nsSliderMediator : public nsIDOMEventListener |
michael@0 | 24 | { |
michael@0 | 25 | public: |
michael@0 | 26 | |
michael@0 | 27 | NS_DECL_ISUPPORTS |
michael@0 | 28 | |
michael@0 | 29 | nsSliderFrame* mSlider; |
michael@0 | 30 | |
michael@0 | 31 | nsSliderMediator(nsSliderFrame* aSlider) { mSlider = aSlider; } |
michael@0 | 32 | virtual ~nsSliderMediator() {} |
michael@0 | 33 | |
michael@0 | 34 | virtual void SetSlider(nsSliderFrame* aSlider) { mSlider = aSlider; } |
michael@0 | 35 | |
michael@0 | 36 | NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE; |
michael@0 | 37 | }; |
michael@0 | 38 | |
michael@0 | 39 | class nsSliderFrame : public nsBoxFrame |
michael@0 | 40 | { |
michael@0 | 41 | public: |
michael@0 | 42 | NS_DECL_FRAMEARENA_HELPERS |
michael@0 | 43 | |
michael@0 | 44 | friend class nsSliderMediator; |
michael@0 | 45 | |
michael@0 | 46 | nsSliderFrame(nsIPresShell* aShell, nsStyleContext* aContext); |
michael@0 | 47 | virtual ~nsSliderFrame(); |
michael@0 | 48 | |
michael@0 | 49 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 50 | virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { |
michael@0 | 51 | return MakeFrameName(NS_LITERAL_STRING("SliderFrame"), aResult); |
michael@0 | 52 | } |
michael@0 | 53 | #endif |
michael@0 | 54 | |
michael@0 | 55 | virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
michael@0 | 56 | virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
michael@0 | 57 | virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
michael@0 | 58 | NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
michael@0 | 59 | |
michael@0 | 60 | // nsIFrame overrides |
michael@0 | 61 | virtual nsresult AppendFrames(ChildListID aListID, |
michael@0 | 62 | nsFrameList& aFrameList) MOZ_OVERRIDE; |
michael@0 | 63 | |
michael@0 | 64 | virtual nsresult InsertFrames(ChildListID aListID, |
michael@0 | 65 | nsIFrame* aPrevFrame, |
michael@0 | 66 | nsFrameList& aFrameList) MOZ_OVERRIDE; |
michael@0 | 67 | |
michael@0 | 68 | virtual nsresult RemoveFrame(ChildListID aListID, |
michael@0 | 69 | nsIFrame* aOldFrame) MOZ_OVERRIDE; |
michael@0 | 70 | |
michael@0 | 71 | virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
michael@0 | 72 | |
michael@0 | 73 | virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, |
michael@0 | 74 | const nsRect& aDirtyRect, |
michael@0 | 75 | const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
michael@0 | 76 | |
michael@0 | 77 | virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
michael@0 | 78 | const nsRect& aDirtyRect, |
michael@0 | 79 | const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
michael@0 | 80 | |
michael@0 | 81 | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 82 | nsIAtom* aAttribute, |
michael@0 | 83 | int32_t aModType) MOZ_OVERRIDE; |
michael@0 | 84 | |
michael@0 | 85 | virtual void Init(nsIContent* aContent, |
michael@0 | 86 | nsIFrame* aParent, |
michael@0 | 87 | nsIFrame* asPrevInFlow) MOZ_OVERRIDE; |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | virtual nsresult HandleEvent(nsPresContext* aPresContext, |
michael@0 | 91 | mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 92 | nsEventStatus* aEventStatus) MOZ_OVERRIDE; |
michael@0 | 93 | |
michael@0 | 94 | virtual nsresult SetInitialChildList(ChildListID aListID, |
michael@0 | 95 | nsFrameList& aChildList) MOZ_OVERRIDE; |
michael@0 | 96 | |
michael@0 | 97 | virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
michael@0 | 98 | |
michael@0 | 99 | nsresult StartDrag(nsIDOMEvent* aEvent); |
michael@0 | 100 | |
michael@0 | 101 | static int32_t GetCurrentPosition(nsIContent* content); |
michael@0 | 102 | static int32_t GetMinPosition(nsIContent* content); |
michael@0 | 103 | static int32_t GetMaxPosition(nsIContent* content); |
michael@0 | 104 | static int32_t GetIncrement(nsIContent* content); |
michael@0 | 105 | static int32_t GetPageIncrement(nsIContent* content); |
michael@0 | 106 | static int32_t GetIntegerAttribute(nsIContent* content, nsIAtom* atom, int32_t defaultValue); |
michael@0 | 107 | void EnsureOrient(); |
michael@0 | 108 | |
michael@0 | 109 | NS_IMETHOD HandlePress(nsPresContext* aPresContext, |
michael@0 | 110 | mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 111 | nsEventStatus* aEventStatus) MOZ_OVERRIDE; |
michael@0 | 112 | |
michael@0 | 113 | NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext, |
michael@0 | 114 | mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 115 | nsEventStatus* aEventStatus, |
michael@0 | 116 | bool aControlHeld) MOZ_OVERRIDE |
michael@0 | 117 | { |
michael@0 | 118 | return NS_OK; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | NS_IMETHOD HandleDrag(nsPresContext* aPresContext, |
michael@0 | 122 | mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 123 | nsEventStatus* aEventStatus) MOZ_OVERRIDE |
michael@0 | 124 | { |
michael@0 | 125 | return NS_OK; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | NS_IMETHOD HandleRelease(nsPresContext* aPresContext, |
michael@0 | 129 | mozilla::WidgetGUIEvent* aEvent, |
michael@0 | 130 | nsEventStatus* aEventStatus) MOZ_OVERRIDE; |
michael@0 | 131 | |
michael@0 | 132 | private: |
michael@0 | 133 | |
michael@0 | 134 | bool GetScrollToClick(); |
michael@0 | 135 | nsIFrame* GetScrollbar(); |
michael@0 | 136 | bool ShouldScrollForEvent(mozilla::WidgetGUIEvent* aEvent); |
michael@0 | 137 | bool ShouldScrollToClickForEvent(mozilla::WidgetGUIEvent* aEvent); |
michael@0 | 138 | bool IsEventOverThumb(mozilla::WidgetGUIEvent* aEvent); |
michael@0 | 139 | |
michael@0 | 140 | void PageUpDown(nscoord change); |
michael@0 | 141 | void SetCurrentThumbPosition(nsIContent* aScrollbar, nscoord aNewPos, bool aIsSmooth, |
michael@0 | 142 | bool aMaySnap); |
michael@0 | 143 | void SetCurrentPosition(nsIContent* aScrollbar, int32_t aNewPos, bool aIsSmooth); |
michael@0 | 144 | void SetCurrentPositionInternal(nsIContent* aScrollbar, int32_t pos, |
michael@0 | 145 | bool aIsSmooth); |
michael@0 | 146 | void CurrentPositionChanged(); |
michael@0 | 147 | |
michael@0 | 148 | void DragThumb(bool aGrabMouseEvents); |
michael@0 | 149 | void AddListener(); |
michael@0 | 150 | void RemoveListener(); |
michael@0 | 151 | bool isDraggingThumb(); |
michael@0 | 152 | |
michael@0 | 153 | void StartRepeat() { |
michael@0 | 154 | nsRepeatService::GetInstance()->Start(Notify, this); |
michael@0 | 155 | } |
michael@0 | 156 | void StopRepeat() { |
michael@0 | 157 | nsRepeatService::GetInstance()->Stop(Notify, this); |
michael@0 | 158 | } |
michael@0 | 159 | void Notify(); |
michael@0 | 160 | static void Notify(void* aData) { |
michael@0 | 161 | (static_cast<nsSliderFrame*>(aData))->Notify(); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | nsPoint mDestinationPoint; |
michael@0 | 165 | nsRefPtr<nsSliderMediator> mMediator; |
michael@0 | 166 | |
michael@0 | 167 | float mRatio; |
michael@0 | 168 | |
michael@0 | 169 | nscoord mDragStart; |
michael@0 | 170 | nscoord mThumbStart; |
michael@0 | 171 | |
michael@0 | 172 | int32_t mCurPos; |
michael@0 | 173 | |
michael@0 | 174 | nscoord mChange; |
michael@0 | 175 | |
michael@0 | 176 | // true if an attribute change has been caused by the user manipulating the |
michael@0 | 177 | // slider. This allows notifications to tell how a slider's current position |
michael@0 | 178 | // was changed. |
michael@0 | 179 | bool mUserChanged; |
michael@0 | 180 | |
michael@0 | 181 | static bool gMiddlePref; |
michael@0 | 182 | static int32_t gSnapMultiplier; |
michael@0 | 183 | }; // class nsSliderFrame |
michael@0 | 184 | |
michael@0 | 185 | #endif |