2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2018-04-09 17:01:02 +03:00
|
|
|
#include "nsContentCreatorFunctions.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"
|
2018-07-25 16:03:45 +03:00
|
|
|
#include "nsStyleConsts.h"
|
2013-10-02 01:01:49 +04:00
|
|
|
#include "nsIContent.h"
|
2019-04-06 09:02:28 +03:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
|
|
|
#include "mozilla/PresShell.h"
|
2018-02-09 19:17:10 +03:00
|
|
|
#include "mozilla/dom/MutationEventBinding.h"
|
2013-06-27 08:00:41 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2019-11-29 23:39:36 +03:00
|
|
|
using mozilla::dom::Element;
|
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
|
|
|
//
|
2019-04-16 10:24:49 +03:00
|
|
|
nsIFrame* NS_NewScrollbarFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell)
|
|
|
|
nsScrollbarFrame(aStyle, aPresShell->GetPresContext());
|
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)
|
2018-12-07 23:00:18 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsScrollbarFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
1999-12-21 22:28:15 +03:00
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsScrollbarFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
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
|
|
|
}
|
|
|
|
|
2018-04-09 17:01:02 +03:00
|
|
|
void nsScrollbarFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) {
|
|
|
|
aPostDestroyData.AddAnonymousContent(mUpTopButton.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mDownTopButton.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mSlider.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mUpBottomButton.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mDownBottomButton.forget());
|
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
void 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult 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) {
|
2005-09-07 20:49:21 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
1999-04-21 01:39:52 +04:00
|
|
|
|
2018-04-09 17:01:02 +03:00
|
|
|
// Update value in our children
|
|
|
|
UpdateChildrenAttributeValue(aAttribute, true);
|
|
|
|
|
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) return rv;
|
2003-04-09 15:27:09 +04:00
|
|
|
|
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) {
|
2017-11-09 05:00:48 +03:00
|
|
|
f = f->PresShell()->GetRootScrollFrame();
|
2014-02-05 05:33:18 +04:00
|
|
|
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
|
|
|
|
2016-04-21 07:28:33 +03:00
|
|
|
nsresult nsScrollbarFrame::GetXULMargin(nsMargin& aMargin) {
|
2013-06-27 08:00:41 +04:00
|
|
|
aMargin.SizeTo(0, 0, 0, 0);
|
|
|
|
|
2020-03-03 23:30:52 +03:00
|
|
|
const bool overlayScrollbars =
|
|
|
|
!!LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars);
|
|
|
|
|
|
|
|
const bool horizontal = IsXULHorizontal();
|
|
|
|
bool didSetMargin = false;
|
|
|
|
|
|
|
|
if (overlayScrollbars) {
|
|
|
|
nsSize minSize;
|
|
|
|
bool widthSet = false;
|
|
|
|
bool heightSet = false;
|
|
|
|
AddXULMinSize(this, minSize, widthSet, heightSet);
|
|
|
|
if (horizontal) {
|
|
|
|
if (heightSet) {
|
|
|
|
aMargin.top = -minSize.height;
|
|
|
|
didSetMargin = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (widthSet) {
|
|
|
|
aMargin.left = -minSize.width;
|
|
|
|
didSetMargin = true;
|
2013-06-27 08:00:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 23:30:52 +03:00
|
|
|
if (!didSetMargin) {
|
2020-04-18 15:06:09 +03:00
|
|
|
DebugOnly<nsresult> rv = nsIFrame::GetXULMargin(aMargin);
|
2020-03-03 23:30:52 +03:00
|
|
|
// TODO(emilio): Should probably not be fallible, it's not like anybody
|
|
|
|
// cares about the return value anyway.
|
2020-04-18 15:06:09 +03:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv), "nsIFrame::GetXULMargin can't really fail");
|
2015-05-12 11:49:25 +03:00
|
|
|
}
|
|
|
|
|
2020-03-03 23:30:52 +03:00
|
|
|
if (!horizontal) {
|
2015-05-12 11:49:25 +03:00
|
|
|
nsIScrollbarMediator* scrollFrame = GetScrollbarMediator();
|
|
|
|
if (scrollFrame && !scrollFrame->IsScrollbarOnRight()) {
|
2020-01-20 19:17:06 +03:00
|
|
|
std::swap(aMargin.left, aMargin.right);
|
2015-05-12 11:49:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 23:30:52 +03:00
|
|
|
return NS_OK;
|
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
|
2017-12-05 20:05:51 +03:00
|
|
|
RefPtr<Element> content = GetContent()->AsElement();
|
2014-02-05 05:30:34 +04:00
|
|
|
|
|
|
|
// 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
|
2018-02-09 19:17:10 +03:00
|
|
|
AttributeChanged(kNameSpaceID_None, nsGkAtoms::curpos,
|
2018-06-26 00:20:54 +03:00
|
|
|
dom::MutationEvent_Binding::MODIFICATION);
|
2014-02-05 05:30:34 +04:00
|
|
|
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) {
|
2018-02-09 19:17:10 +03:00
|
|
|
sliderFrame->AttributeChanged(kNameSpaceID_None, nsGkAtoms::curpos,
|
2018-06-26 00:20:54 +03:00
|
|
|
dom::MutationEvent_Binding::MODIFICATION);
|
2014-02-05 05:30:34 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return curpos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
content->UnsetAttr(kNameSpaceID_None, nsGkAtoms::smooth, false);
|
|
|
|
return curpos;
|
|
|
|
}
|
2018-04-09 17:01:02 +03:00
|
|
|
|
2019-06-27 10:22:22 +03:00
|
|
|
static already_AddRefed<Element> MakeScrollbarButton(
|
|
|
|
dom::NodeInfo* aNodeInfo, bool aVertical, bool aBottom, bool aDown,
|
|
|
|
AnonymousContentKey& aKey) {
|
|
|
|
MOZ_ASSERT(aNodeInfo);
|
|
|
|
MOZ_ASSERT(
|
|
|
|
aNodeInfo->Equals(nsGkAtoms::scrollbarbutton, nullptr, kNameSpaceID_XUL));
|
|
|
|
|
|
|
|
static constexpr nsLiteralString kSbattrValues[2][2] = {
|
|
|
|
{
|
|
|
|
NS_LITERAL_STRING("scrollbar-up-top"),
|
|
|
|
NS_LITERAL_STRING("scrollbar-up-bottom"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NS_LITERAL_STRING("scrollbar-down-top"),
|
|
|
|
NS_LITERAL_STRING("scrollbar-down-bottom"),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr nsLiteralString kTypeValues[2] = {
|
|
|
|
NS_LITERAL_STRING("decrement"),
|
|
|
|
NS_LITERAL_STRING("increment"),
|
|
|
|
};
|
|
|
|
|
|
|
|
aKey = AnonymousContentKey::Type_ScrollbarButton;
|
|
|
|
if (aVertical) {
|
|
|
|
aKey |= AnonymousContentKey::Flag_Vertical;
|
|
|
|
}
|
|
|
|
if (aBottom) {
|
|
|
|
aKey |= AnonymousContentKey::Flag_ScrollbarButton_Bottom;
|
|
|
|
}
|
|
|
|
if (aDown) {
|
|
|
|
aKey |= AnonymousContentKey::Flag_ScrollbarButton_Down;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Element> e;
|
|
|
|
NS_TrustedNewXULElement(getter_AddRefs(e), do_AddRef(aNodeInfo));
|
|
|
|
e->SetAttr(kNameSpaceID_None, nsGkAtoms::sbattr,
|
|
|
|
kSbattrValues[aDown][aBottom], false);
|
|
|
|
e->SetAttr(kNameSpaceID_None, nsGkAtoms::type, kTypeValues[aDown], false);
|
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:01:02 +03:00
|
|
|
nsresult nsScrollbarFrame::CreateAnonymousContent(
|
|
|
|
nsTArray<ContentInfo>& aElements) {
|
|
|
|
nsNodeInfoManager* nodeInfoManager = mContent->NodeInfo()->NodeInfoManager();
|
|
|
|
|
|
|
|
Element* el(GetContent()->AsElement());
|
|
|
|
|
|
|
|
// If there are children already in the node, don't create any anonymous
|
|
|
|
// content (this only apply to crashtests/369038-1.xhtml)
|
|
|
|
if (el->HasChildren()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString orient;
|
|
|
|
el->GetAttr(kNameSpaceID_None, nsGkAtoms::orient, orient);
|
2019-06-27 10:22:22 +03:00
|
|
|
bool vertical = orient.EqualsLiteral("vertical");
|
2018-04-09 17:01:02 +03:00
|
|
|
|
2019-06-27 10:22:22 +03:00
|
|
|
RefPtr<dom::NodeInfo> sbbNodeInfo =
|
2018-04-09 17:01:02 +03:00
|
|
|
nodeInfoManager->GetNodeInfo(nsGkAtoms::scrollbarbutton, nullptr,
|
2019-06-27 10:22:22 +03:00
|
|
|
kNameSpaceID_XUL, nsINode::ELEMENT_NODE);
|
|
|
|
|
|
|
|
{
|
|
|
|
AnonymousContentKey key;
|
|
|
|
mUpTopButton =
|
|
|
|
MakeScrollbarButton(sbbNodeInfo, vertical, /* aBottom */ false,
|
|
|
|
/* aDown */ false, key);
|
|
|
|
aElements.AppendElement(ContentInfo(mUpTopButton, key));
|
2018-04-09 17:01:02 +03:00
|
|
|
}
|
|
|
|
|
2019-06-27 10:22:22 +03:00
|
|
|
{
|
|
|
|
AnonymousContentKey key;
|
|
|
|
mDownTopButton =
|
|
|
|
MakeScrollbarButton(sbbNodeInfo, vertical, /* aBottom */ false,
|
|
|
|
/* aDown */ true, key);
|
|
|
|
aElements.AppendElement(ContentInfo(mDownTopButton, key));
|
2018-04-09 17:01:02 +03:00
|
|
|
}
|
|
|
|
|
2019-06-27 10:22:22 +03:00
|
|
|
{
|
|
|
|
AnonymousContentKey key = AnonymousContentKey::Type_Slider;
|
|
|
|
if (vertical) {
|
|
|
|
key |= AnonymousContentKey::Flag_Vertical;
|
|
|
|
}
|
2018-04-09 17:01:02 +03:00
|
|
|
|
2019-06-27 10:22:22 +03:00
|
|
|
NS_TrustedNewXULElement(
|
|
|
|
getter_AddRefs(mSlider),
|
|
|
|
nodeInfoManager->GetNodeInfo(nsGkAtoms::slider, nullptr,
|
|
|
|
kNameSpaceID_XUL, nsINode::ELEMENT_NODE));
|
|
|
|
mSlider->SetAttr(kNameSpaceID_None, nsGkAtoms::orient, orient, false);
|
|
|
|
mSlider->SetAttr(kNameSpaceID_None, nsGkAtoms::flex, NS_LITERAL_STRING("1"),
|
|
|
|
false);
|
|
|
|
|
|
|
|
aElements.AppendElement(ContentInfo(mSlider, key));
|
|
|
|
|
|
|
|
NS_TrustedNewXULElement(
|
|
|
|
getter_AddRefs(mThumb),
|
|
|
|
nodeInfoManager->GetNodeInfo(nsGkAtoms::thumb, nullptr,
|
|
|
|
kNameSpaceID_XUL, nsINode::ELEMENT_NODE));
|
|
|
|
mThumb->SetAttr(kNameSpaceID_None, nsGkAtoms::orient, orient, false);
|
|
|
|
mSlider->AppendChildTo(mThumb, false);
|
2018-04-09 17:01:02 +03:00
|
|
|
}
|
|
|
|
|
2019-06-27 10:22:22 +03:00
|
|
|
{
|
|
|
|
AnonymousContentKey key;
|
|
|
|
mUpBottomButton =
|
|
|
|
MakeScrollbarButton(sbbNodeInfo, vertical, /* aBottom */ true,
|
|
|
|
/* aDown */ false, key);
|
|
|
|
aElements.AppendElement(ContentInfo(mUpBottomButton, key));
|
2019-06-27 03:25:03 +03:00
|
|
|
}
|
|
|
|
|
2019-06-27 10:22:22 +03:00
|
|
|
{
|
|
|
|
AnonymousContentKey key;
|
|
|
|
mDownBottomButton =
|
|
|
|
MakeScrollbarButton(sbbNodeInfo, vertical, /* aBottom */ true,
|
|
|
|
/* aDown */ true, key);
|
|
|
|
aElements.AppendElement(ContentInfo(mDownBottomButton, key));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't cache styles if we are inside a <select> element, since we have
|
|
|
|
// some UA style sheet rules that depend on the <select>'s attributes.
|
|
|
|
if (GetContent()->GetParent() &&
|
|
|
|
GetContent()->GetParent()->IsHTMLElement(nsGkAtoms::select)) {
|
|
|
|
for (auto& info : aElements) {
|
|
|
|
info.mKey = AnonymousContentKey::None;
|
|
|
|
}
|
2018-04-09 17:01:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UpdateChildrenAttributeValue(nsGkAtoms::curpos, false);
|
|
|
|
UpdateChildrenAttributeValue(nsGkAtoms::maxpos, false);
|
|
|
|
UpdateChildrenAttributeValue(nsGkAtoms::disabled, false);
|
|
|
|
UpdateChildrenAttributeValue(nsGkAtoms::pageincrement, false);
|
|
|
|
UpdateChildrenAttributeValue(nsGkAtoms::increment, false);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsScrollbarFrame::UpdateChildrenAttributeValue(nsAtom* aAttribute,
|
|
|
|
bool aNotify) {
|
|
|
|
Element* el(GetContent()->AsElement());
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
el->GetAttr(kNameSpaceID_None, aAttribute, value);
|
|
|
|
|
|
|
|
if (!el->HasAttr(kNameSpaceID_None, aAttribute)) {
|
|
|
|
if (mUpTopButton) {
|
|
|
|
mUpTopButton->UnsetAttr(kNameSpaceID_None, aAttribute, aNotify);
|
|
|
|
}
|
|
|
|
if (mDownTopButton) {
|
|
|
|
mDownTopButton->UnsetAttr(kNameSpaceID_None, aAttribute, aNotify);
|
|
|
|
}
|
|
|
|
if (mSlider) {
|
|
|
|
mSlider->UnsetAttr(kNameSpaceID_None, aAttribute, aNotify);
|
|
|
|
}
|
|
|
|
if (mThumb && aAttribute == nsGkAtoms::disabled) {
|
|
|
|
mThumb->UnsetAttr(kNameSpaceID_None, nsGkAtoms::collapsed, aNotify);
|
|
|
|
}
|
|
|
|
if (mUpBottomButton) {
|
|
|
|
mUpBottomButton->UnsetAttr(kNameSpaceID_None, aAttribute, aNotify);
|
|
|
|
}
|
|
|
|
if (mDownBottomButton) {
|
|
|
|
mDownBottomButton->UnsetAttr(kNameSpaceID_None, aAttribute, aNotify);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::curpos || aAttribute == nsGkAtoms::maxpos) {
|
|
|
|
if (mUpTopButton) {
|
|
|
|
mUpTopButton->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
if (mDownTopButton) {
|
|
|
|
mDownTopButton->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
if (mSlider) {
|
|
|
|
mSlider->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
if (mUpBottomButton) {
|
|
|
|
mUpBottomButton->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
if (mDownBottomButton) {
|
|
|
|
mDownBottomButton->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
} else if (aAttribute == nsGkAtoms::disabled) {
|
|
|
|
if (mUpTopButton) {
|
|
|
|
mUpTopButton->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
if (mDownTopButton) {
|
|
|
|
mDownTopButton->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
if (mSlider) {
|
|
|
|
mSlider->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
// Set the value on "collapsed" attribute.
|
|
|
|
if (mThumb) {
|
|
|
|
mThumb->SetAttr(kNameSpaceID_None, nsGkAtoms::collapsed, value, aNotify);
|
|
|
|
}
|
|
|
|
if (mUpBottomButton) {
|
|
|
|
mUpBottomButton->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
if (mDownBottomButton) {
|
|
|
|
mDownBottomButton->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
} else if (aAttribute == nsGkAtoms::pageincrement ||
|
|
|
|
aAttribute == nsGkAtoms::increment) {
|
|
|
|
if (mSlider) {
|
|
|
|
mSlider->SetAttr(kNameSpaceID_None, aAttribute, value, aNotify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsScrollbarFrame::AppendAnonymousContentTo(
|
|
|
|
nsTArray<nsIContent*>& aElements, uint32_t aFilter) {
|
|
|
|
if (mUpTopButton) {
|
|
|
|
aElements.AppendElement(mUpTopButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDownTopButton) {
|
|
|
|
aElements.AppendElement(mDownTopButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSlider) {
|
|
|
|
aElements.AppendElement(mSlider);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mUpBottomButton) {
|
|
|
|
aElements.AppendElement(mUpBottomButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDownBottomButton) {
|
|
|
|
aElements.AppendElement(mDownBottomButton);
|
|
|
|
}
|
|
|
|
}
|