2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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-20 21:39:52 +00:00
|
|
|
|
1999-06-15 04:02:43 +00:00
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
1999-04-20 21:39:52 +00:00
|
|
|
|
|
|
|
#include "nsScrollbarFrame.h"
|
1999-06-15 04:02:43 +00:00
|
|
|
#include "nsScrollbarButtonFrame.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2003-04-09 11:27:09 +00:00
|
|
|
#include "nsIScrollableFrame.h"
|
2006-12-07 19:53:41 +00:00
|
|
|
#include "nsIScrollbarMediator.h"
|
2013-06-27 04:00:41 +00:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
|
|
|
#include "nsThemeConstants.h"
|
|
|
|
#include "nsRenderingContext.h"
|
2013-10-01 21:01:49 +00:00
|
|
|
#include "nsIContent.h"
|
2013-06-27 04:00:41 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
1999-08-19 22:16:23 +00:00
|
|
|
|
1999-04-20 21:39:52 +00:00
|
|
|
//
|
2013-06-27 04:00:41 +00:00
|
|
|
// NS_NewScrollbarFrame
|
1999-04-20 21:39:52 +00:00
|
|
|
//
|
2013-06-27 04:00:41 +00:00
|
|
|
// Creates a new scrollbar frame and returns it
|
1999-04-20 21:39:52 +00:00
|
|
|
//
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewScrollbarFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-04-20 21:39:52 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsScrollbarFrame (aPresShell, aContext);
|
2009-09-12 16:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsScrollbarFrame)
|
1999-04-20 21:39:52 +00:00
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsScrollbarFrame)
|
2011-07-11 14:05:09 +00:00
|
|
|
NS_QUERYFRAME_ENTRY(nsScrollbarFrame)
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
1999-12-21 19:28:15 +00:00
|
|
|
|
2013-03-20 01:47:48 +00:00
|
|
|
void
|
2014-05-24 22:20:40 +00:00
|
|
|
nsScrollbarFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-10-12 00:16:06 +00:00
|
|
|
{
|
2013-03-20 01:47:48 +00:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2006-03-26 21:30:36 +00:00
|
|
|
|
2002-07-10 02:17:54 +00: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 00:16:06 +00:00
|
|
|
}
|
|
|
|
|
2014-05-13 00:47:52 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsScrollbarFrame::Reflow(nsPresContext* aPresContext,
|
2004-01-09 19:21:20 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2014-05-13 00:47:52 +00:00
|
|
|
nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
2004-01-09 19:21:20 +00:00
|
|
|
|
|
|
|
// nsGfxScrollFrame may have told us to shrink to nothing. If so, make sure our
|
|
|
|
// desired size agrees.
|
2013-12-27 17:59:21 +00:00
|
|
|
if (aReflowState.AvailableWidth() == 0) {
|
2013-12-27 17:59:52 +00:00
|
|
|
aDesiredSize.Width() = 0;
|
2004-01-09 19:21:20 +00:00
|
|
|
}
|
2013-12-27 17:59:21 +00:00
|
|
|
if (aReflowState.AvailableHeight() == 0) {
|
2013-12-27 17:59:52 +00:00
|
|
|
aDesiredSize.Height() = 0;
|
2004-01-09 19:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-11 00:25:11 +00:00
|
|
|
nsIAtom*
|
|
|
|
nsScrollbarFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::scrollbarFrame;
|
|
|
|
}
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsScrollbarFrame::AttributeChanged(int32_t aNameSpaceID,
|
2003-07-11 21:16:12 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
1999-04-20 21:39:52 +00:00
|
|
|
{
|
2005-09-07 16:49:21 +00:00
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
1999-04-20 21:39:52 +00:00
|
|
|
|
2003-04-09 11:27:09 +00:00
|
|
|
// if the current position changes, notify any nsGfxScrollFrame
|
|
|
|
// parent we may have
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute != nsGkAtoms::curpos)
|
2003-04-09 11:27:09 +00:00
|
|
|
return rv;
|
|
|
|
|
2011-07-11 14:05:09 +00:00
|
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(GetParent());
|
2003-04-09 11:27:09 +00:00
|
|
|
if (!scrollable)
|
|
|
|
return rv;
|
|
|
|
|
2013-08-08 22:04:59 +00:00
|
|
|
nsCOMPtr<nsIContent> kungFuDeathGrip(mContent);
|
2009-09-01 04:11:11 +00:00
|
|
|
scrollable->CurPosAttributeChanged(mContent);
|
1999-06-15 04:02:43 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-06-30 22:17:43 +00:00
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
NS_IMETHODIMP
|
2013-10-02 03:46:03 +00:00
|
|
|
nsScrollbarFrame::HandlePress(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
1999-08-19 22:16:23 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-10-02 03:46:03 +00:00
|
|
|
nsScrollbarFrame::HandleMultiplePress(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aControlHeld)
|
1999-08-19 22:16:23 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-03 03:39:02 +00:00
|
|
|
NS_IMETHODIMP
|
2013-10-02 03:46:03 +00:00
|
|
|
nsScrollbarFrame::HandleDrag(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2011-08-03 03:39:02 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-10-02 03:46:03 +00:00
|
|
|
nsScrollbarFrame::HandleRelease(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2011-08-03 03:39:02 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-12-07 19:53:41 +00:00
|
|
|
void
|
|
|
|
nsScrollbarFrame::SetScrollbarMediatorContent(nsIContent* aMediator)
|
|
|
|
{
|
|
|
|
mScrollbarMediator = aMediator;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIScrollbarMediator*
|
|
|
|
nsScrollbarFrame::GetScrollbarMediator()
|
|
|
|
{
|
|
|
|
if (!mScrollbarMediator)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-12-24 21:20:06 +00:00
|
|
|
nsIFrame* f = mScrollbarMediator->GetPrimaryFrame();
|
2006-12-30 17:18:15 +00:00
|
|
|
|
|
|
|
// check if the frame is a scroll frame. If so, get the scrollable frame
|
|
|
|
// inside it.
|
2009-01-12 19:20:59 +00:00
|
|
|
nsIScrollableFrame* scrollFrame = do_QueryFrame(f);
|
2006-12-30 17:18:15 +00:00
|
|
|
if (scrollFrame) {
|
|
|
|
f = scrollFrame->GetScrolledFrame();
|
|
|
|
}
|
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
nsIScrollbarMediator* sbm = do_QueryFrame(f);
|
2006-12-07 19:53:41 +00:00
|
|
|
return sbm;
|
|
|
|
}
|
2013-06-27 04:00:41 +00:00
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2013-06-27 04:00:41 +00: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;
|
|
|
|
nsRefPtr<nsRenderingContext> rc =
|
2014-04-15 04:30:25 +00:00
|
|
|
presContext->PresShell()->CreateReferenceRenderingContext();
|
2013-06-27 04:00:41 +00:00
|
|
|
theme->GetMinimumWidgetSize(rc, this, NS_THEME_SCROLLBAR, &size,
|
|
|
|
&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);
|
|
|
|
}
|