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 TABMESSAGE_UTILS_H 8 #define TABMESSAGE_UTILS_H 9 10 #include "ipc/EnumSerializer.h" 11 #include "mozilla/RefPtr.h" 12 #include "mozilla/dom/Event.h" 13 #include "nsIRemoteTab.h" 14 #include "nsPIDOMWindow.h" 15 #include "nsCOMPtr.h" 16 #include "mozilla/dom/EffectsInfo.h" 17 #include "mozilla/layers/LayersMessageUtils.h" 18 #include "TabMessageTypes.h" 19 #include "X11UndefineNone.h" 20 21 namespace mozilla::dom { 22 23 bool ReadRemoteEvent(IPC::MessageReader* aReader, 24 mozilla::dom::RemoteDOMEvent* aResult); 25 26 } // namespace mozilla::dom 27 28 namespace IPC { 29 30 template <> 31 struct ParamTraits<mozilla::dom::RemoteDOMEvent> { 32 typedef mozilla::dom::RemoteDOMEvent paramType; 33 34 static void Write(MessageWriter* aWriter, const paramType& aParam) { 35 aParam.mEvent->Serialize(aWriter, true); 36 } 37 38 static bool Read(MessageReader* aReader, paramType* aResult) { 39 return mozilla::dom::ReadRemoteEvent(aReader, aResult); 40 } 41 42 static void Log(const paramType& aParam, std::wstring* aLog) {} 43 }; 44 45 template <> 46 struct ParamTraits<nsSizeMode> 47 : public ContiguousEnumSerializer<nsSizeMode, nsSizeMode_Normal, 48 nsSizeMode_Invalid> {}; 49 50 template <> 51 struct ParamTraits<UIStateChangeType> 52 : public ContiguousEnumSerializer<UIStateChangeType, 53 UIStateChangeType_NoChange, 54 UIStateChangeType_Invalid> {}; 55 56 template <> 57 struct ParamTraits<nsIRemoteTab::NavigationType> 58 : public ContiguousEnumSerializerInclusive< 59 nsIRemoteTab::NavigationType, 60 nsIRemoteTab::NavigationType::NAVIGATE_BACK, 61 nsIRemoteTab::NavigationType::NAVIGATE_URL> {}; 62 63 template <> 64 struct ParamTraits<mozilla::dom::EffectsInfo> { 65 typedef mozilla::dom::EffectsInfo paramType; 66 67 static void Write(MessageWriter* aWriter, const paramType& aParam) { 68 WriteParam(aWriter, aParam.mVisibleRect); 69 WriteParam(aWriter, aParam.mScaleX); 70 WriteParam(aWriter, aParam.mScaleY); 71 WriteParam(aWriter, aParam.mTransformToAncestorScale); 72 } 73 74 static bool Read(MessageReader* aReader, paramType* aResult) { 75 return ReadParam(aReader, &aResult->mVisibleRect) && 76 ReadParam(aReader, &aResult->mScaleX) && 77 ReadParam(aReader, &aResult->mScaleY) && 78 ReadParam(aReader, &aResult->mTransformToAncestorScale); 79 } 80 }; 81 82 template <> 83 struct ParamTraits<mozilla::WhenToScroll> 84 : public ContiguousEnumSerializerInclusive< 85 mozilla::WhenToScroll, mozilla::WhenToScroll::Always, 86 mozilla::WhenToScroll::IfNotFullyVisible> {}; 87 88 template <> 89 struct ParamTraits<mozilla::ScrollFlags> 90 : public BitFlagsEnumSerializer<mozilla::ScrollFlags, 91 mozilla::ScrollFlags::ALL_BITS> {}; 92 93 template <> 94 struct ParamTraits<mozilla::ScrollAxis> { 95 typedef mozilla::ScrollAxis paramType; 96 97 static void Write(MessageWriter* aWriter, const paramType& aParam) { 98 WriteParam(aWriter, aParam.mWhereToScroll); 99 WriteParam(aWriter, aParam.mWhenToScroll); 100 WriteParam(aWriter, aParam.mOnlyIfPerceivedScrollableDirection); 101 } 102 103 static bool Read(MessageReader* aReader, paramType* aResult) { 104 if (!ReadParam(aReader, &aResult->mWhereToScroll)) { 105 return false; 106 } 107 if (!ReadParam(aReader, &aResult->mWhenToScroll)) { 108 return false; 109 } 110 111 // We can't set mOnlyIfPerceivedScrollableDirection directly since it's 112 // a bitfield. 113 bool value; 114 if (!ReadParam(aReader, &value)) { 115 return false; 116 } 117 aResult->mOnlyIfPerceivedScrollableDirection = value; 118 119 return true; 120 } 121 }; 122 123 template <> 124 struct ParamTraits<mozilla::dom::EmbedderElementEventType> 125 : public ContiguousEnumSerializer< 126 mozilla::dom::EmbedderElementEventType, 127 mozilla::dom::EmbedderElementEventType::NoEvent, 128 mozilla::dom::EmbedderElementEventType::EndGuard_> {}; 129 130 } // namespace IPC 131 132 #endif // TABMESSAGE_UTILS_H 133