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