summaryrefslogtreecommitdiffstats
path: root/layout/style/nsHTMLStyleSheet.h
blob: 62c1558e63230e223e6da6af308f360353ed03e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* -*- 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/. */

/*
 * style sheet and style rule processor representing data from presentational
 * HTML attributes
 */

#ifndef nsHTMLStyleSheet_h_
#define nsHTMLStyleSheet_h_

#include "nsColor.h"
#include "nsCOMPtr.h"
#include "nsAtom.h"
#include "PLDHashTable.h"
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"
#include "nsString.h"

class nsMappedAttributes;
struct RawServoDeclarationBlock;
namespace mozilla {
namespace dom {
class Document;
}  // namespace dom
}  // namespace mozilla

class nsHTMLStyleSheet final {
 public:
  explicit nsHTMLStyleSheet(mozilla::dom::Document* aDocument);

  void SetOwningDocument(mozilla::dom::Document* aDocument);

  NS_INLINE_DECL_REFCOUNTING(nsHTMLStyleSheet)

  size_t DOMSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;

  void Reset();
  nsresult SetLinkColor(nscolor aColor);
  nsresult SetActiveLinkColor(nscolor aColor);
  nsresult SetVisitedLinkColor(nscolor aColor);

  const RefPtr<RawServoDeclarationBlock>& GetServoUnvisitedLinkDecl() const {
    return mServoUnvisitedLinkDecl;
  }
  const RefPtr<RawServoDeclarationBlock>& GetServoVisitedLinkDecl() const {
    return mServoVisitedLinkDecl;
  }
  const RefPtr<RawServoDeclarationBlock>& GetServoActiveLinkDecl() const {
    return mServoActiveLinkDecl;
  }

  // Mapped Attribute management methods
  already_AddRefed<nsMappedAttributes> UniqueMappedAttributes(
      nsMappedAttributes* aMapped);
  void DropMappedAttributes(nsMappedAttributes* aMapped);
  // For each mapped presentation attribute in the cache, resolve
  // the attached DeclarationBlock by running the mapping
  // and converting the ruledata to Servo specified values.
  void CalculateMappedServoDeclarations();

 private:
  nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) = delete;
  nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) = delete;

  ~nsHTMLStyleSheet() = default;

  // Implementation of SetLink/VisitedLink/ActiveLinkColor
  nsresult ImplLinkColorSetter(RefPtr<RawServoDeclarationBlock>& aDecl,
                               nscolor aColor);

 public:  // for mLangRuleTable structures only
 private:
  mozilla::dom::Document* mDocument;
  RefPtr<RawServoDeclarationBlock> mServoUnvisitedLinkDecl;
  RefPtr<RawServoDeclarationBlock> mServoVisitedLinkDecl;
  RefPtr<RawServoDeclarationBlock> mServoActiveLinkDecl;

  PLDHashTable mMappedAttrTable;
  // Whether or not the mapped attributes table
  // has been changed since the last call to
  // CalculateMappedServoDeclarations()
  bool mMappedAttrsDirty;
};

#endif /* !defined(nsHTMLStyleSheet_h_) */