tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AttributeStyles.h (2695B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /*
      8 * style sheet and style rule processor representing data from presentational
      9 * HTML attributes
     10 */
     11 
     12 #ifndef mozilla_AttributeStyles_h_
     13 #define mozilla_AttributeStyles_h_
     14 
     15 #include "PLDHashTable.h"
     16 #include "mozilla/MemoryReporting.h"
     17 #include "nsAtom.h"
     18 #include "nsCOMPtr.h"
     19 #include "nsColor.h"
     20 #include "nsString.h"
     21 #include "nsTHashMap.h"
     22 
     23 struct MiscContainer;
     24 namespace mozilla {
     25 struct StyleLockedDeclarationBlock;
     26 namespace dom {
     27 class Document;
     28 }  // namespace dom
     29 
     30 class AttributeStyles final {
     31 public:
     32  explicit AttributeStyles(dom::Document* aDocument);
     33  void SetOwningDocument(dom::Document* aDocument);
     34 
     35  NS_INLINE_DECL_REFCOUNTING(AttributeStyles)
     36 
     37  size_t DOMSizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
     38 
     39  void Reset();
     40  nsresult SetLinkColor(nscolor aColor);
     41  nsresult SetActiveLinkColor(nscolor aColor);
     42  nsresult SetVisitedLinkColor(nscolor aColor);
     43 
     44  const StyleLockedDeclarationBlock* GetServoUnvisitedLinkDecl() const {
     45    return mServoUnvisitedLinkDecl;
     46  }
     47  const StyleLockedDeclarationBlock* GetServoVisitedLinkDecl() const {
     48    return mServoVisitedLinkDecl;
     49  }
     50  const StyleLockedDeclarationBlock* GetServoActiveLinkDecl() const {
     51    return mServoActiveLinkDecl;
     52  }
     53 
     54  void CacheStyleAttr(const nsAString& aSerialized, MiscContainer* aValue) {
     55    mCachedStyleAttrs.InsertOrUpdate(aSerialized, aValue);
     56  }
     57  void EvictStyleAttr(const nsAString& aSerialized, MiscContainer* aValue) {
     58    NS_ASSERTION(LookupStyleAttr(aSerialized) == aValue,
     59                 "Cached value doesn't match?");
     60    mCachedStyleAttrs.Remove(aSerialized);
     61  }
     62  MiscContainer* LookupStyleAttr(const nsAString& aSerialized) {
     63    return mCachedStyleAttrs.Get(aSerialized);
     64  }
     65 
     66  AttributeStyles(const AttributeStyles& aCopy) = delete;
     67  AttributeStyles& operator=(const AttributeStyles& aCopy) = delete;
     68 
     69 private:
     70  ~AttributeStyles();
     71 
     72  // Implementation of SetLink/VisitedLink/ActiveLinkColor
     73  nsresult ImplLinkColorSetter(RefPtr<StyleLockedDeclarationBlock>& aDecl,
     74                               nscolor aColor);
     75 
     76  dom::Document* mDocument;
     77  RefPtr<StyleLockedDeclarationBlock> mServoUnvisitedLinkDecl;
     78  RefPtr<StyleLockedDeclarationBlock> mServoVisitedLinkDecl;
     79  RefPtr<StyleLockedDeclarationBlock> mServoActiveLinkDecl;
     80  nsTHashMap<nsStringHashKey, MiscContainer*> mCachedStyleAttrs;
     81 };
     82 
     83 }  // namespace mozilla
     84 
     85 #endif