tor-browser

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

nsQuoteList.h (3128B)


      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 /* implementation of quotes for the CSS 'content' property */
      8 
      9 #ifndef nsQuoteList_h___
     10 #define nsQuoteList_h___
     11 
     12 #include "nsGenConList.h"
     13 
     14 namespace mozilla {
     15 
     16 class ContainStyleScope;
     17 
     18 }  // namespace mozilla
     19 
     20 struct nsQuoteNode : public nsGenConNode {
     21  // open-quote, close-quote, no-open-quote, or no-close-quote
     22  const StyleContentType mType;
     23 
     24  // Quote depth before this quote, which is always non-negative.
     25  int32_t mDepthBefore;
     26 
     27  nsQuoteNode(StyleContentType aType, uint32_t aContentIndex)
     28      : nsGenConNode(aContentIndex), mType(aType), mDepthBefore(0) {
     29    NS_ASSERTION(aType == StyleContentType::OpenQuote ||
     30                     aType == StyleContentType::CloseQuote ||
     31                     aType == StyleContentType::NoOpenQuote ||
     32                     aType == StyleContentType::NoCloseQuote,
     33                 "incorrect type");
     34    NS_ASSERTION(aContentIndex <= INT32_MAX, "out of range");
     35  }
     36 
     37  virtual bool InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame,
     38                             nsIFrame* aTextFrame) override;
     39 
     40  // is this 'open-quote' or 'no-open-quote'?
     41  bool IsOpenQuote() {
     42    return mType == StyleContentType::OpenQuote ||
     43           mType == StyleContentType::NoOpenQuote;
     44  }
     45 
     46  // is this 'close-quote' or 'no-close-quote'?
     47  bool IsCloseQuote() { return !IsOpenQuote(); }
     48 
     49  // is this 'open-quote' or 'close-quote'?
     50  bool IsRealQuote() {
     51    return mType == StyleContentType::OpenQuote ||
     52           mType == StyleContentType::CloseQuote;
     53  }
     54 
     55  // Depth of the quote for *this* node.  Either non-negative or -1.
     56  // -1 means this is a closing quote that tried to decrement the
     57  // counter below zero (which means no quote should be rendered).
     58  int32_t Depth() { return IsOpenQuote() ? mDepthBefore : mDepthBefore - 1; }
     59 
     60  // always non-negative
     61  int32_t DepthAfter() {
     62    return IsOpenQuote() ? mDepthBefore + 1
     63                         : (mDepthBefore == 0 ? 0 : mDepthBefore - 1);
     64  }
     65 
     66  // The text that should be displayed for this quote.
     67  nsString Text();
     68 };
     69 
     70 class nsQuoteList : public nsGenConList {
     71 private:
     72  nsQuoteNode* FirstNode() {
     73    return static_cast<nsQuoteNode*>(mList.getFirst());
     74  }
     75 
     76 public:
     77  explicit nsQuoteList(mozilla::ContainStyleScope* aScope) : mScope(aScope) {}
     78 
     79  // assign the correct |mDepthBefore| value to a node that has been inserted
     80  // Should be called immediately after calling |Insert|.
     81  void Calc(nsQuoteNode* aNode);
     82 
     83  nsQuoteNode* Next(nsQuoteNode* aNode) {
     84    return static_cast<nsQuoteNode*>(nsGenConList::Next(aNode));
     85  }
     86  nsQuoteNode* Prev(nsQuoteNode* aNode) {
     87    return static_cast<nsQuoteNode*>(nsGenConList::Prev(aNode));
     88  }
     89 
     90  void RecalcAll();
     91 #ifdef DEBUG
     92  void PrintChain();
     93 #endif
     94 
     95 private:
     96  mozilla::ContainStyleScope* mScope;
     97 };
     98 
     99 #endif /* nsQuoteList_h___ */