michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsSliderFrame_h__ michael@0: #define nsSliderFrame_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsRepeatService.h" michael@0: #include "nsBoxFrame.h" michael@0: #include "nsIAtom.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsITimer.h" michael@0: #include "nsIDOMEventListener.h" michael@0: michael@0: class nsString; michael@0: class nsITimer; michael@0: class nsSliderFrame; michael@0: michael@0: nsIFrame* NS_NewSliderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: michael@0: class nsSliderMediator : public nsIDOMEventListener michael@0: { michael@0: public: michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: nsSliderFrame* mSlider; michael@0: michael@0: nsSliderMediator(nsSliderFrame* aSlider) { mSlider = aSlider; } michael@0: virtual ~nsSliderMediator() {} michael@0: michael@0: virtual void SetSlider(nsSliderFrame* aSlider) { mSlider = aSlider; } michael@0: michael@0: NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: class nsSliderFrame : public nsBoxFrame michael@0: { michael@0: public: michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: friend class nsSliderMediator; michael@0: michael@0: nsSliderFrame(nsIPresShell* aShell, nsStyleContext* aContext); michael@0: virtual ~nsSliderFrame(); michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { michael@0: return MakeFrameName(NS_LITERAL_STRING("SliderFrame"), aResult); michael@0: } michael@0: #endif michael@0: michael@0: virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: michael@0: // nsIFrame overrides michael@0: virtual nsresult AppendFrames(ChildListID aListID, michael@0: nsFrameList& aFrameList) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult InsertFrames(ChildListID aListID, michael@0: nsIFrame* aPrevFrame, michael@0: nsFrameList& aFrameList) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult RemoveFrame(ChildListID aListID, michael@0: nsIFrame* aOldFrame) MOZ_OVERRIDE; michael@0: michael@0: virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; michael@0: michael@0: virtual void BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) MOZ_OVERRIDE; michael@0: michael@0: virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) MOZ_OVERRIDE; michael@0: michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* asPrevInFlow) MOZ_OVERRIDE; michael@0: michael@0: michael@0: virtual nsresult HandleEvent(nsPresContext* aPresContext, michael@0: mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus* aEventStatus) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult SetInitialChildList(ChildListID aListID, michael@0: nsFrameList& aChildList) MOZ_OVERRIDE; michael@0: michael@0: virtual nsIAtom* GetType() const MOZ_OVERRIDE; michael@0: michael@0: nsresult StartDrag(nsIDOMEvent* aEvent); michael@0: michael@0: static int32_t GetCurrentPosition(nsIContent* content); michael@0: static int32_t GetMinPosition(nsIContent* content); michael@0: static int32_t GetMaxPosition(nsIContent* content); michael@0: static int32_t GetIncrement(nsIContent* content); michael@0: static int32_t GetPageIncrement(nsIContent* content); michael@0: static int32_t GetIntegerAttribute(nsIContent* content, nsIAtom* atom, int32_t defaultValue); michael@0: void EnsureOrient(); michael@0: michael@0: NS_IMETHOD HandlePress(nsPresContext* aPresContext, michael@0: mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus* aEventStatus) MOZ_OVERRIDE; michael@0: michael@0: NS_IMETHOD HandleMultiplePress(nsPresContext* aPresContext, michael@0: mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus* aEventStatus, michael@0: bool aControlHeld) MOZ_OVERRIDE michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHOD HandleDrag(nsPresContext* aPresContext, michael@0: mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus* aEventStatus) MOZ_OVERRIDE michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHOD HandleRelease(nsPresContext* aPresContext, michael@0: mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus* aEventStatus) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: michael@0: bool GetScrollToClick(); michael@0: nsIFrame* GetScrollbar(); michael@0: bool ShouldScrollForEvent(mozilla::WidgetGUIEvent* aEvent); michael@0: bool ShouldScrollToClickForEvent(mozilla::WidgetGUIEvent* aEvent); michael@0: bool IsEventOverThumb(mozilla::WidgetGUIEvent* aEvent); michael@0: michael@0: void PageUpDown(nscoord change); michael@0: void SetCurrentThumbPosition(nsIContent* aScrollbar, nscoord aNewPos, bool aIsSmooth, michael@0: bool aMaySnap); michael@0: void SetCurrentPosition(nsIContent* aScrollbar, int32_t aNewPos, bool aIsSmooth); michael@0: void SetCurrentPositionInternal(nsIContent* aScrollbar, int32_t pos, michael@0: bool aIsSmooth); michael@0: void CurrentPositionChanged(); michael@0: michael@0: void DragThumb(bool aGrabMouseEvents); michael@0: void AddListener(); michael@0: void RemoveListener(); michael@0: bool isDraggingThumb(); michael@0: michael@0: void StartRepeat() { michael@0: nsRepeatService::GetInstance()->Start(Notify, this); michael@0: } michael@0: void StopRepeat() { michael@0: nsRepeatService::GetInstance()->Stop(Notify, this); michael@0: } michael@0: void Notify(); michael@0: static void Notify(void* aData) { michael@0: (static_cast(aData))->Notify(); michael@0: } michael@0: michael@0: nsPoint mDestinationPoint; michael@0: nsRefPtr mMediator; michael@0: michael@0: float mRatio; michael@0: michael@0: nscoord mDragStart; michael@0: nscoord mThumbStart; michael@0: michael@0: int32_t mCurPos; michael@0: michael@0: nscoord mChange; michael@0: michael@0: // true if an attribute change has been caused by the user manipulating the michael@0: // slider. This allows notifications to tell how a slider's current position michael@0: // was changed. michael@0: bool mUserChanged; michael@0: michael@0: static bool gMiddlePref; michael@0: static int32_t gSnapMultiplier; michael@0: }; // class nsSliderFrame michael@0: michael@0: #endif