2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
1999-04-21 01:39:52 +04:00
|
|
|
|
1999-06-15 08:02:43 +04:00
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
1999-04-21 01:39:52 +04:00
|
|
|
|
|
|
|
#include "nsScrollbarFrame.h"
|
2014-02-05 05:30:34 +04:00
|
|
|
#include "nsSliderFrame.h"
|
1999-06-15 08:02:43 +04:00
|
|
|
#include "nsScrollbarButtonFrame.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2003-04-09 15:27:09 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2006-12-07 22:53:41 +03:00
|
|
|
#include "nsIScrollbarMediator.h"
|
2013-06-27 08:00:41 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
|
|
|
#include "nsThemeConstants.h"
|
2013-10-02 01:01:49 +04:00
|
|
|
#include "nsIContent.h"
|
2014-02-05 05:30:34 +04:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
2013-06-27 08:00:41 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
1999-08-20 02:16:23 +04:00
|
|
|
|
1999-04-21 01:39:52 +04:00
|
|
|
//
|
2013-06-27 08:00:41 +04:00
|
|
|
// NS_NewScrollbarFrame
|
1999-04-21 01:39:52 +04:00
|
|
|
//
|
2013-06-27 08:00:41 +04:00
|
|
|
// Creates a new scrollbar frame and returns it
|
1999-04-21 01:39:52 +04:00
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
nsIFrame*
|
2015-01-06 12:27:56 +03:00
|
|
|
NS_NewScrollbarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-04-21 01:39:52 +04:00
|
|
|
{
|
2015-01-06 12:27:56 +03:00
|
|
|
return new (aPresShell) nsScrollbarFrame(aContext);
|
2009-09-12 20:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsScrollbarFrame)
|
1999-04-21 01:39:52 +04:00
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsScrollbarFrame)
|
2011-07-11 18:05:09 +04:00
|
|
|
NS_QUERYFRAME_ENTRY(nsScrollbarFrame)
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
1999-12-21 22:28:15 +03:00
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsScrollbarFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-10-12 04:16:06 +04:00
|
|
|
{
|
2013-03-20 05:47:48 +04:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2006-03-27 01:30:36 +04:00
|
|
|
|
2002-07-10 06:17:54 +04:00
|
|
|
// We want to be a reflow root since we use reflows to move the
|
|
|
|
// slider. Any reflow inside the scrollbar frame will be a reflow to
|
|
|
|
// move the slider and will thus not change anything outside of the
|
|
|
|
// scrollbar or change the size of the scrollbar frame.
|
2017-08-24 14:09:42 +03:00
|
|
|
AddStateBits(NS_FRAME_REFLOW_ROOT);
|
1999-10-12 04:16:06 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsScrollbarFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2004-01-09 22:21:20 +03:00
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
|
2004-01-09 22:21:20 +03:00
|
|
|
|
|
|
|
// nsGfxScrollFrame may have told us to shrink to nothing. If so, make sure our
|
|
|
|
// desired size agrees.
|
2016-07-21 13:36:39 +03:00
|
|
|
if (aReflowInput.AvailableWidth() == 0) {
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.Width() = 0;
|
2004-01-09 22:21:20 +03:00
|
|
|
}
|
2016-07-21 13:36:39 +03:00
|
|
|
if (aReflowInput.AvailableHeight() == 0) {
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.Height() = 0;
|
2004-01-09 22:21:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScrollbarFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
1999-04-21 01:39:52 +04:00
|
|
|
{
|
2005-09-07 20:49:21 +04:00
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
1999-04-21 01:39:52 +04:00
|
|
|
|
2003-04-09 15:27:09 +04:00
|
|
|
// if the current position changes, notify any nsGfxScrollFrame
|
|
|
|
// parent we may have
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute != nsGkAtoms::curpos)
|
2003-04-09 15:27:09 +04:00
|
|
|
return rv;
|
|
|
|
|
2011-07-11 18:05:09 +04:00
|
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(GetParent());
|
2003-04-09 15:27:09 +04:00
|
|
|
if (!scrollable)
|
|
|
|
return rv;
|
|
|
|
|
2016-07-18 19:37:11 +03:00
|
|
|
nsCOMPtr<nsIContent> content(mContent);
|
|
|
|
scrollable->CurPosAttributeChanged(content);
|
1999-06-15 08:02:43 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1999-07-01 02:17:43 +04:00
|
|
|
|
1999-08-20 02:16:23 +04:00
|
|
|
NS_IMETHODIMP
|
2013-10-02 07:46:03 +04:00
|
|
|
nsScrollbarFrame::HandlePress(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-10-02 07:46:03 +04:00
|
|
|
nsScrollbarFrame::HandleMultiplePress(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aControlHeld)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
2013-10-02 07:46:03 +04:00
|
|
|
nsScrollbarFrame::HandleDrag(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2011-08-03 07:39:02 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
2013-10-02 07:46:03 +04:00
|
|
|
nsScrollbarFrame::HandleRelease(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2011-08-03 07:39:02 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-12-07 22:53:41 +03:00
|
|
|
void
|
|
|
|
nsScrollbarFrame::SetScrollbarMediatorContent(nsIContent* aMediator)
|
|
|
|
{
|
|
|
|
mScrollbarMediator = aMediator;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIScrollbarMediator*
|
|
|
|
nsScrollbarFrame::GetScrollbarMediator()
|
|
|
|
{
|
2014-02-05 05:33:18 +04:00
|
|
|
if (!mScrollbarMediator) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-02-05 05:33:18 +04:00
|
|
|
}
|
2009-12-25 00:20:06 +03:00
|
|
|
nsIFrame* f = mScrollbarMediator->GetPrimaryFrame();
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIScrollableFrame* scrollFrame = do_QueryFrame(f);
|
2014-02-05 05:33:18 +04:00
|
|
|
nsIScrollbarMediator* sbm;
|
|
|
|
|
2006-12-30 20:18:15 +03:00
|
|
|
if (scrollFrame) {
|
2014-02-05 05:33:18 +04:00
|
|
|
nsIFrame* scrolledFrame = scrollFrame->GetScrolledFrame();
|
|
|
|
sbm = do_QueryFrame(scrolledFrame);
|
|
|
|
if (sbm) {
|
|
|
|
return sbm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sbm = do_QueryFrame(f);
|
|
|
|
if (f && !sbm) {
|
|
|
|
f = f->PresContext()->PresShell()->GetRootScrollFrame();
|
|
|
|
if (f && f->GetContent() == mScrollbarMediator) {
|
|
|
|
return do_QueryFrame(f);
|
|
|
|
}
|
2006-12-30 20:18:15 +03:00
|
|
|
}
|
2006-12-07 22:53:41 +03:00
|
|
|
return sbm;
|
|
|
|
}
|
2013-06-27 08:00:41 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2016-04-21 07:28:33 +03:00
|
|
|
nsScrollbarFrame::GetXULMargin(nsMargin& aMargin)
|
2013-06-27 08:00:41 +04:00
|
|
|
{
|
2015-05-12 11:49:25 +03:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2013-06-27 08:00:41 +04:00
|
|
|
aMargin.SizeTo(0,0,0,0);
|
|
|
|
|
|
|
|
if (LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0) {
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
nsITheme* theme = presContext->GetTheme();
|
2017-09-05 17:47:01 +03:00
|
|
|
if (theme && theme->ThemeSupportsWidget(presContext, this, NS_THEME_SCROLLBAR)) {
|
2015-03-30 18:36:14 +03:00
|
|
|
LayoutDeviceIntSize size;
|
2013-06-27 08:00:41 +04:00
|
|
|
bool isOverridable;
|
2014-06-27 13:19:00 +04:00
|
|
|
theme->GetMinimumWidgetSize(presContext, this, NS_THEME_SCROLLBAR, &size,
|
2013-06-27 08:00:41 +04:00
|
|
|
&isOverridable);
|
2016-04-21 07:28:34 +03:00
|
|
|
if (IsXULHorizontal()) {
|
2013-06-27 08:00:41 +04:00
|
|
|
aMargin.top = -presContext->DevPixelsToAppUnits(size.height);
|
2017-09-05 17:47:01 +03:00
|
|
|
} else {
|
2015-05-12 11:49:25 +03:00
|
|
|
aMargin.left = -presContext->DevPixelsToAppUnits(size.width);
|
2013-06-27 08:00:41 +04:00
|
|
|
}
|
2015-05-12 11:49:25 +03:00
|
|
|
rv = NS_OK;
|
2013-06-27 08:00:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-12 11:49:25 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2016-04-21 07:28:33 +03:00
|
|
|
rv = nsBox::GetXULMargin(aMargin);
|
2015-05-12 11:49:25 +03:00
|
|
|
}
|
|
|
|
|
2016-04-21 07:28:34 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && !IsXULHorizontal()) {
|
2015-05-12 11:49:25 +03:00
|
|
|
nsIScrollbarMediator* scrollFrame = GetScrollbarMediator();
|
|
|
|
if (scrollFrame && !scrollFrame->IsScrollbarOnRight()) {
|
|
|
|
Swap(aMargin.left, aMargin.right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2013-06-27 08:00:41 +04:00
|
|
|
}
|
2014-02-05 05:30:34 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsScrollbarFrame::SetIncrementToLine(int32_t aDirection)
|
|
|
|
{
|
|
|
|
// get the scrollbar's content node
|
|
|
|
nsIContent* content = GetContent();
|
|
|
|
mSmoothScroll = true;
|
|
|
|
mIncrement = aDirection * nsSliderFrame::GetIncrement(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScrollbarFrame::SetIncrementToPage(int32_t aDirection)
|
|
|
|
{
|
|
|
|
// get the scrollbar's content node
|
|
|
|
nsIContent* content = GetContent();
|
|
|
|
mSmoothScroll = true;
|
|
|
|
mIncrement = aDirection * nsSliderFrame::GetPageIncrement(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScrollbarFrame::SetIncrementToWhole(int32_t aDirection)
|
|
|
|
{
|
|
|
|
// get the scrollbar's content node
|
|
|
|
nsIContent* content = GetContent();
|
|
|
|
if (aDirection == -1)
|
|
|
|
mIncrement = -nsSliderFrame::GetCurrentPosition(content);
|
|
|
|
else
|
|
|
|
mIncrement = nsSliderFrame::GetMaxPosition(content) -
|
|
|
|
nsSliderFrame::GetCurrentPosition(content);
|
|
|
|
// Don't repeat or use smooth scrolling if scrolling to beginning or end
|
|
|
|
// of a page.
|
|
|
|
mSmoothScroll = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
nsScrollbarFrame::MoveToNewPosition()
|
|
|
|
{
|
|
|
|
// get the scrollbar's content node
|
|
|
|
nsCOMPtr<nsIContent> content = GetContent();
|
|
|
|
|
|
|
|
// get the current pos
|
|
|
|
int32_t curpos = nsSliderFrame::GetCurrentPosition(content);
|
|
|
|
|
|
|
|
// get the max pos
|
|
|
|
int32_t maxpos = nsSliderFrame::GetMaxPosition(content);
|
|
|
|
|
|
|
|
// increment the given amount
|
|
|
|
if (mIncrement) {
|
|
|
|
curpos += mIncrement;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure the current position is between the current and max positions
|
|
|
|
if (curpos < 0) {
|
|
|
|
curpos = 0;
|
|
|
|
} else if (curpos > maxpos) {
|
|
|
|
curpos = maxpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the current position of the slider.
|
|
|
|
nsAutoString curposStr;
|
|
|
|
curposStr.AppendInt(curpos);
|
|
|
|
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame weakFrame(this);
|
2014-02-05 05:30:34 +04:00
|
|
|
if (mSmoothScroll) {
|
|
|
|
content->SetAttr(kNameSpaceID_None, nsGkAtoms::smooth, NS_LITERAL_STRING("true"), false);
|
|
|
|
}
|
|
|
|
content->SetAttr(kNameSpaceID_None, nsGkAtoms::curpos, curposStr, false);
|
|
|
|
// notify the nsScrollbarFrame of the change
|
|
|
|
AttributeChanged(kNameSpaceID_None, nsGkAtoms::curpos, nsIDOMMutationEvent::MODIFICATION);
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return curpos;
|
|
|
|
}
|
|
|
|
// notify all nsSliderFrames of the change
|
|
|
|
nsIFrame::ChildListIterator childLists(this);
|
|
|
|
for (; !childLists.IsDone(); childLists.Next()) {
|
|
|
|
nsFrameList::Enumerator childFrames(childLists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
|
|
|
nsIFrame* f = childFrames.get();
|
|
|
|
nsSliderFrame* sliderFrame = do_QueryFrame(f);
|
|
|
|
if (sliderFrame) {
|
|
|
|
sliderFrame->AttributeChanged(kNameSpaceID_None, nsGkAtoms::curpos, nsIDOMMutationEvent::MODIFICATION);
|
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return curpos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
content->UnsetAttr(kNameSpaceID_None, nsGkAtoms::smooth, false);
|
|
|
|
return curpos;
|
|
|
|
}
|