tor-browser

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

RelativeTo.h (2233B)


      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 #ifndef mozilla_RelativeTo_h
      8 #define mozilla_RelativeTo_h
      9 
     10 #include <ostream>
     11 
     12 class nsIFrame;
     13 
     14 namespace mozilla {
     15 
     16 // A flag that can be used to distinguish between the visual and layout
     17 // viewports. In layout code, this is often used to annotate coordinates
     18 // relative to the viewport frame as being in layout or visual coordinates.
     19 // However, it may also be used to e.g. specify whether a scroll operation
     20 // should apply to the layout or visual viewport.
     21 enum class ViewportType { Layout, Visual };
     22 
     23 // A struct that combines a frame with a ViewportType annotation. The
     24 // combination completely describes what a set of coordinates is "relative to".
     25 // Notes on expected usage:
     26 //  - The boundary between visual and layout coordinates is approximately
     27 //    at the root content document (RCD)'s ViewportFrame, which we'll
     28 //    call "RCD-VF".
     29 //  - Coordinates relative to the RCD-VF's descendants (other than the
     30 //    RCD's viewport scrollbar frames) should be in layout coordinates.
     31 //  - Coordinates relative to the RCD-VF's ancestors should be in visual
     32 //    coordinates (note that in an e10s setup, the RCD-VF doesn't
     33 //    typically have in-process ancestors).
     34 //  - Coordinates relative to the RCD-VF itself can be in either layout
     35 //    or visual coordinates.
     36 struct RelativeTo {
     37  const nsIFrame* mFrame = nullptr;
     38  // Choose ViewportType::Layout as the default as this is what the vast
     39  // majority of layout code deals with.
     40  ViewportType mViewportType = ViewportType::Layout;
     41  bool operator==(const RelativeTo&) const = default;
     42  friend std::ostream& operator<<(std::ostream& aOs, const RelativeTo& aR) {
     43    return aOs << "{" << aR.mFrame << ", "
     44               << (aR.mViewportType == ViewportType::Visual ? "visual"
     45                                                            : "layout")
     46               << "}";
     47  }
     48 };
     49 
     50 }  // namespace mozilla
     51 
     52 #endif  // mozilla_RelativeTo_h