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"
|
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"
|
|
|
|
#include "nsRenderingContext.h"
|
2013-10-02 01:01:49 +04:00
|
|
|
#include "nsIContent.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*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewScrollbarFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-04-21 01:39:52 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsScrollbarFrame (aPresShell, 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.
|
|
|
|
mState |= 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,
|
2004-01-09 22:21:20 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2014-05-13 04:47:52 +04:00
|
|
|
nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, 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.
|
2013-12-27 21:59:21 +04:00
|
|
|
if (aReflowState.AvailableWidth() == 0) {
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.Width() = 0;
|
2004-01-09 22:21:20 +03:00
|
|
|
}
|
2013-12-27 21:59:21 +04:00
|
|
|
if (aReflowState.AvailableHeight() == 0) {
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.Height() = 0;
|
2004-01-09 22:21:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-11 04:25:11 +04:00
|
|
|
nsIAtom*
|
|
|
|
nsScrollbarFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::scrollbarFrame;
|
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScrollbarFrame::AttributeChanged(int32_t aNameSpaceID,
|
2003-07-12 01:16:12 +04:00
|
|
|
nsIAtom* 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;
|
|
|
|
|
2013-08-09 02:04:59 +04:00
|
|
|
nsCOMPtr<nsIContent> kungFuDeathGrip(mContent);
|
2009-09-01 08:11:11 +04:00
|
|
|
scrollable->CurPosAttributeChanged(mContent);
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-03 07:39:02 +04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
if (!mScrollbarMediator)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-12-25 00:20:06 +03:00
|
|
|
nsIFrame* f = mScrollbarMediator->GetPrimaryFrame();
|
2006-12-30 20:18:15 +03:00
|
|
|
|
|
|
|
// check if the frame is a scroll frame. If so, get the scrollable frame
|
|
|
|
// inside it.
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIScrollableFrame* scrollFrame = do_QueryFrame(f);
|
2006-12-30 20:18:15 +03:00
|
|
|
if (scrollFrame) {
|
|
|
|
f = scrollFrame->GetScrolledFrame();
|
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIScrollbarMediator* sbm = do_QueryFrame(f);
|
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
|
2013-06-27 08:00:41 +04:00
|
|
|
nsScrollbarFrame::GetMargin(nsMargin& aMargin)
|
|
|
|
{
|
|
|
|
aMargin.SizeTo(0,0,0,0);
|
|
|
|
|
|
|
|
if (LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0) {
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
nsITheme* theme = presContext->GetTheme();
|
|
|
|
if (theme) {
|
|
|
|
nsIntSize size;
|
|
|
|
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);
|
|
|
|
if (IsHorizontal()) {
|
|
|
|
aMargin.top = -presContext->DevPixelsToAppUnits(size.height);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
|
|
|
aMargin.right = -presContext->DevPixelsToAppUnits(size.width);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aMargin.left = -presContext->DevPixelsToAppUnits(size.width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsBox::GetMargin(aMargin);
|
|
|
|
}
|