Bug 1516258 - Part 2 - Remove XULScrollElement. r=NeilDeakin

There is still styling associated with the "scrollbox" element, but eventually those instances can be replaced with simple boxes.

Differential Revision: https://phabricator.services.mozilla.com/D15298

--HG--
extra : rebase_source : 1ff8502e01df16e791c06b9cdcbe38fb2b55ccd7
This commit is contained in:
Paolo Amadini 2019-01-10 11:50:31 +00:00
parent d7ba788184
commit 788354b1e7
8 changed files with 0 additions and 249 deletions

View File

@ -67,7 +67,6 @@
#include "mozilla/dom/WorkerScope.h"
#include "mozilla/dom/XrayExpandoClass.h"
#include "mozilla/dom/WindowProxyHolder.h"
#include "mozilla/dom/XULScrollElementBinding.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
#include "ipc/ErrorIPCUtils.h"
#include "mozilla/UseCounter.h"
@ -3619,8 +3618,6 @@ bool HTMLConstructor(JSContext* aCx, unsigned aArgc, JS::Value* aVp,
} else if (definition->mLocalName == nsGkAtoms::menu ||
definition->mLocalName == nsGkAtoms::menulist) {
cb = XULMenuElement_Binding::GetConstructorObject;
} else if (definition->mLocalName == nsGkAtoms::scrollbox) {
cb = XULScrollElement_Binding::GetConstructorObject;
} else if (definition->mLocalName == nsGkAtoms::tree) {
cb = XULTreeElement_Binding::GetConstructorObject;
} else {

View File

@ -1,15 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
[HTMLConstructor, Func="IsChromeOrXBL"]
interface XULScrollElement : XULElement {
[Throws]
void scrollToElement(Element child);
[Throws]
void scrollByIndex(long aIndexes);
[Throws]
void ensureElementIsVisible(Element child);
};

View File

@ -58,7 +58,6 @@ WEBIDL_FILES = [
'WindowGlobalActors.webidl',
'XULFrameElement.webidl',
'XULMenuElement.webidl',
'XULScrollElement.webidl',
'XULTextElement.webidl',
'XULTreeElement.webidl'
]

View File

@ -1279,8 +1279,6 @@ var interfaceNamesInGlobalScope =
{name: "XULMenuElement", insecureContext: true, xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "XULPopupElement", insecureContext: true, xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "XULScrollElement", insecureContext: true, xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "XULTextElement", insecureContext: true, xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!

View File

@ -1,186 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsCOMPtr.h"
#include "nsIPresShell.h"
#include "nsIContent.h"
#include "nsPresContext.h"
#include "nsBox.h"
#include "nsIScrollableFrame.h"
#include "mozilla/dom/XULScrollElement.h"
#include "mozilla/dom/XULScrollElementBinding.h"
namespace mozilla {
namespace dom {
JSObject* XULScrollElement::WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return XULScrollElement_Binding::Wrap(aCx, this, aGivenProto);
}
void XULScrollElement::ScrollByIndex(int32_t aIndex, ErrorResult& aRv) {
nsIScrollableFrame* sf = GetScrollFrame();
if (!sf) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
nsIFrame* scrolledFrame = sf->GetScrolledFrame();
if (!scrolledFrame) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
nsRect rect;
// now get the element's first child
nsIFrame* child = nsBox::GetChildXULBox(scrolledFrame);
bool horiz = scrolledFrame->IsXULHorizontal();
nsPoint cp = sf->GetScrollPosition();
nscoord diff = 0;
int32_t curIndex = 0;
bool isLTR = scrolledFrame->IsXULNormalDirection();
nscoord frameWidth = 0;
if (!isLTR && horiz) {
nsCOMPtr<Document> doc = GetComposedDoc();
nsCOMPtr<nsIPresShell> shell = doc->GetShell();
if (!shell) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
nsRect rcFrame = nsLayoutUtils::GetAllInFlowRectsUnion(
GetPrimaryFrame(), shell->GetRootFrame());
frameWidth = rcFrame.width;
}
// first find out what index we are currently at
while (child) {
rect = child->GetRect();
if (horiz) {
// In the left-to-right case we break from the loop when the center of
// the current child rect is greater than the scrolled position of
// the left edge of the scrollbox
// In the right-to-left case we break when the center of the current
// child rect is less than the scrolled position of the right edge of
// the scrollelement.
diff =
rect.x + rect.width / 2; // use the center, to avoid rounding errors
if ((isLTR && diff > cp.x) || (!isLTR && diff < cp.x + frameWidth)) {
break;
}
} else {
diff =
rect.y + rect.height / 2; // use the center, to avoid rounding errors
if (diff > cp.y) {
break;
}
}
child = nsBox::GetNextXULBox(child);
curIndex++;
}
int32_t count = 0;
if (aIndex == 0) return;
if (aIndex > 0) {
while (child) {
child = nsBox::GetNextXULBox(child);
if (child) {
rect = child->GetRect();
}
count++;
if (count >= aIndex) {
break;
}
}
} else if (aIndex < 0) {
child = nsBox::GetChildXULBox(scrolledFrame);
while (child) {
rect = child->GetRect();
if (count >= curIndex + aIndex) {
break;
}
count++;
child = nsBox::GetNextXULBox(child);
}
}
nscoord csspixel = nsPresContext::CSSPixelsToAppUnits(1);
if (horiz) {
// In the left-to-right case we scroll so that the left edge of the
// selected child is scrolled to the left edge of the scrollbox.
// In the right-to-left case we scroll so that the right edge of the
// selected child is scrolled to the right edge of the scrollbox.
nsPoint pt(isLTR ? rect.x : rect.x + rect.width - frameWidth, cp.y);
// Use a destination range that ensures the left edge (or right edge,
// for RTL) will indeed be visible. Also ensure that the top edge
// is visible.
nsRect range(pt.x, pt.y, csspixel, 0);
if (isLTR) {
range.x -= csspixel;
}
sf->ScrollTo(pt, nsIScrollableFrame::INSTANT, &range);
} else {
// Use a destination range that ensures the top edge will be visible.
nsRect range(cp.x, rect.y - csspixel, 0, csspixel);
sf->ScrollTo(nsPoint(cp.x, rect.y), nsIScrollableFrame::INSTANT, &range);
}
}
void XULScrollElement::ScrollToElement(Element& child, ErrorResult& aRv) {
nsCOMPtr<Document> doc = GetComposedDoc();
if (!doc) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
nsCOMPtr<nsIPresShell> shell = doc->GetShell();
if (!shell) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
shell->ScrollContentIntoView(
&child,
nsIPresShell::ScrollAxis(nsIPresShell::SCROLL_TOP,
nsIPresShell::SCROLL_ALWAYS),
nsIPresShell::ScrollAxis(nsIPresShell::SCROLL_LEFT,
nsIPresShell::SCROLL_ALWAYS),
nsIPresShell::SCROLL_FIRST_ANCESTOR_ONLY |
nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
}
void XULScrollElement::EnsureElementIsVisible(Element& aChild,
ErrorResult& aRv) {
nsCOMPtr<Document> doc = GetComposedDoc();
if (!doc) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
nsCOMPtr<nsIPresShell> shell = doc->GetShell();
if (!shell) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
shell->ScrollContentIntoView(&aChild, nsIPresShell::ScrollAxis(),
nsIPresShell::ScrollAxis(),
nsIPresShell::SCROLL_FIRST_ANCESTOR_ONLY |
nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
}
} // namespace dom
} // namespace mozilla

View File

@ -1,35 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef XULScrollElement_h__
#define XULScrollElement_h__
#include "nsXULElement.h"
#include "Units.h"
namespace mozilla {
namespace dom {
class XULScrollElement final : public nsXULElement {
public:
explicit XULScrollElement(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
: nsXULElement(std::move(aNodeInfo)) {}
MOZ_CAN_RUN_SCRIPT void ScrollByIndex(int32_t aIndex, ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void EnsureElementIsVisible(Element& aChild,
ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void ScrollToElement(Element& child, ErrorResult& aRv);
protected:
virtual ~XULScrollElement() {}
JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
};
} // namespace dom
} // namespace mozilla
#endif // XULScrollElement_h

View File

@ -27,7 +27,6 @@ if CONFIG['MOZ_XUL']:
'XULMenuElement.h',
'XULPersist.h',
'XULPopupElement.h',
'XULScrollElement.h',
'XULTextElement.h',
'XULTooltipElement.h',
'XULTreeElement.h',
@ -48,7 +47,6 @@ if CONFIG['MOZ_XUL']:
'XULMenuElement.cpp',
'XULPersist.cpp',
'XULPopupElement.cpp',
'XULScrollElement.cpp',
'XULTextElement.cpp',
'XULTooltipElement.cpp',
'XULTreeElement.cpp',

View File

@ -77,7 +77,6 @@
#include "XULFrameElement.h"
#include "XULMenuElement.h"
#include "XULPopupElement.h"
#include "XULScrollElement.h"
#include "XULTreeElement.h"
#include "mozilla/dom/XULElementBinding.h"
@ -167,10 +166,6 @@ nsXULElement* nsXULElement::Construct(
return new XULMenuElement(nodeInfo.forget());
}
if (nodeInfo->Equals(nsGkAtoms::scrollbox)) {
return new XULScrollElement(nodeInfo.forget());
}
if (nodeInfo->Equals(nsGkAtoms::tree)) {
return new XULTreeElement(nodeInfo.forget());
}