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_layers_FocusTarget_h 8 #define mozilla_layers_FocusTarget_h 9 10 #include <stdint.h> // for int32_t, uint32_t 11 12 #include "mozilla/DefineEnum.h" // for MOZ_DEFINE_ENUM 13 #include "mozilla/layers/ScrollableLayerGuid.h" // for ViewID 14 #include "mozilla/Variant.h" // for Variant 15 #include "mozilla/Maybe.h" // for Maybe 16 17 namespace mozilla { 18 19 class PresShell; 20 21 namespace layers { 22 23 /** 24 * This class is used for communicating information about the currently focused 25 * element of a document and the scrollable frames to use when keyboard 26 * scrolling it. It is created on the main thread at paint-time, but is then 27 * passed over IPC to the compositor/APZ code. 28 */ 29 class FocusTarget final { 30 public: 31 struct ScrollTargets { 32 ScrollableLayerGuid::ViewID mHorizontal; 33 ScrollableLayerGuid::ViewID mVertical; 34 35 bool operator==(const ScrollTargets& aRhs) const { 36 return (mHorizontal == aRhs.mHorizontal && mVertical == aRhs.mVertical); 37 } 38 }; 39 40 // We need this to represent the case where mData has no focus target data 41 // because we can't have an empty variant 42 struct NoFocusTarget { 43 bool operator==(const NoFocusTarget& aRhs) const { return true; } 44 }; 45 46 FocusTarget(); 47 48 /** 49 * Construct a focus target for the specified top level PresShell 50 */ 51 FocusTarget(PresShell* aRootPresShell, uint64_t aFocusSequenceNumber); 52 53 bool operator==(const FocusTarget& aRhs) const; 54 55 const char* Type() const; 56 57 public: 58 // The content sequence number recorded at the time of this class's creation 59 uint64_t mSequenceNumber; 60 61 // Whether there are keydown, keypress, or keyup event listeners 62 // in the event target chain of the focused element 63 bool mFocusHasKeyEventListeners; 64 65 mozilla::Variant<LayersId, ScrollTargets, NoFocusTarget> mData; 66 }; 67 68 } // namespace layers 69 } // namespace mozilla 70 71 #endif // mozilla_layers_FocusTarget_h 72