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