Browse Source

Issue #1629 - Part 1: Implement basic logic in HTMLLinkElement.

So basically, I'm trying to adapt this to UXP:

https://bugzilla.mozilla.org/show_bug.cgi?id=1281135

The earliest source of difficulty while adapting Bug 1281135 to our codebase was simply getting the new ErrorResult flag added to the SetDisabled function to play nice with the SetMozDisabled function. At this point, the implementation can actually have a stylesheet be disabled by default but there are supposedly issues with alternate stylesheets.

At first I played around with the return type of SetMozDisabled to no avail, but I found another solution fairly quickly.

https://bugzilla.mozilla.org/show_bug.cgi?id=846972
https://bugzilla.mozilla.org/show_bug.cgi?id=1157898

Essentially, the way around the problem of the number of return arguments not matching up is to declare a local variable within SetMozDisabled called ErrorResult rv, and using that to store the return value of the ErrorResult argument from SetDisabled. After that, because ErrorCode was removed, you would return rv.StealNSResult() in order to report success or failure to any consumer that calls on SetMozDisabled.
pull/24/head
athenian200 2 years ago committed by Roy Tam
parent
commit
4e15e4c252
  1. 26
      dom/html/HTMLLinkElement.cpp
  2. 4
      dom/html/HTMLLinkElement.h
  3. 2
      dom/html/HTMLStyleElement.cpp
  4. 2
      dom/html/HTMLStyleElement.h
  5. 2
      dom/webidl/HTMLLinkElement.webidl

26
dom/html/HTMLLinkElement.cpp

@ -93,8 +93,10 @@ NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
NS_IMPL_ELEMENT_CLONE(HTMLLinkElement)
bool
HTMLLinkElement::Disabled()
HTMLLinkElement::Disabled() const
{
return GetBoolAttr(nsGkAtoms::disabled);
StyleSheet* ss = GetSheet();
return ss && ss->Disabled();
}
@ -107,8 +109,10 @@ HTMLLinkElement::GetMozDisabled(bool* aDisabled)
}
void
HTMLLinkElement::SetDisabled(bool aDisabled)
HTMLLinkElement::SetDisabled(bool aDisabled, ErrorResult& aRv)
{
return SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aRv);
if (StyleSheet* ss = GetSheet()) {
ss->SetDisabled(aDisabled);
}
@ -117,8 +121,9 @@ HTMLLinkElement::SetDisabled(bool aDisabled)
NS_IMETHODIMP
HTMLLinkElement::SetMozDisabled(bool aDisabled)
{
SetDisabled(aDisabled);
return NS_OK;
ErrorResult rv;
SetDisabled(aDisabled, rv);
return rv.StealNSResult();
}
@ -370,7 +375,8 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
aName == nsGkAtoms::rel ||
aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type)) {
aName == nsGkAtoms::type ||
aName == nsGkAtoms::disabled)) {
bool dropSheet = false;
if (aName == nsGkAtoms::rel) {
nsAutoString value;
@ -397,7 +403,8 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
dropSheet ||
(aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type));
aName == nsGkAtoms::type ||
aName == nsGkAtoms::disabled));
}
} else {
// Since removing href or rel makes us no longer link to a
@ -407,7 +414,8 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
aName == nsGkAtoms::rel ||
aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type) {
aName == nsGkAtoms::type ||
aName == nsGkAtoms::disabled) {
UpdateStyleSheetInternal(nullptr, nullptr, true);
}
if (aName == nsGkAtoms::href ||
@ -516,6 +524,10 @@ HTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle,
return;
}
if (Disabled()) {
return;
}
nsAutoString title;
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
title.CompressWhitespace();

4
dom/html/HTMLLinkElement.h

@ -86,8 +86,8 @@ public:
virtual bool HasDeferredDNSPrefetchRequest() override;
// WebIDL
bool Disabled();
void SetDisabled(bool aDisabled);
bool Disabled() const;
void SetDisabled(bool aDisabled, ErrorResult& aRv);
// XPCOM GetHref is fine.
void SetHref(const nsAString& aHref, ErrorResult& aRv)
{

2
dom/html/HTMLStyleElement.cpp

@ -66,7 +66,7 @@ HTMLStyleElement::GetMozDisabled(bool* aDisabled)
}
bool
HTMLStyleElement::Disabled()
HTMLStyleElement::Disabled() const
{
StyleSheet* ss = GetSheet();
return ss && ss->Disabled();

2
dom/html/HTMLStyleElement.h

@ -59,7 +59,7 @@ public:
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
bool Disabled();
bool Disabled() const;
void SetDisabled(bool aDisabled);
void SetMedia(const nsAString& aMedia, ErrorResult& aError)
{

2
dom/webidl/HTMLLinkElement.webidl

@ -14,7 +14,7 @@
// http://www.whatwg.org/specs/web-apps/current-work/#the-link-element
[HTMLConstructor]
interface HTMLLinkElement : HTMLElement {
[Pure]
[CEReactions, SetterThrows, Pure]
attribute boolean disabled;
[CEReactions, SetterThrows, Pure]
attribute DOMString href;

Loading…
Cancel
Save