1/*
2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27
28#include "WebPopupItem.h"
29
30#include "ArgumentCoders.h"
31
32namespace WebKit {
33
34WebPopupItem::WebPopupItem()
35 : m_type(Item)
36 , m_textDirection(WebCore::TextDirection::LTR)
37 , m_hasTextDirectionOverride(false)
38 , m_isEnabled(true)
39 , m_isSelected(false)
40{
41}
42
43WebPopupItem::WebPopupItem(Type type)
44 : m_type(type)
45 , m_textDirection(WebCore::TextDirection::LTR)
46 , m_hasTextDirectionOverride(false)
47 , m_isEnabled(true)
48 , m_isLabel(false)
49 , m_isSelected(false)
50{
51}
52
53WebPopupItem::WebPopupItem(Type type, const String& text, WebCore::TextDirection textDirection, bool hasTextDirectionOverride, const String& toolTip, const String& accessibilityText, bool isEnabled, bool isLabel, bool isSelected)
54 : m_type(type)
55 , m_text(text)
56 , m_textDirection(textDirection)
57 , m_hasTextDirectionOverride(hasTextDirectionOverride)
58 , m_toolTip(toolTip)
59 , m_accessibilityText(accessibilityText)
60 , m_isEnabled(isEnabled)
61 , m_isLabel(isLabel)
62 , m_isSelected(isSelected)
63{
64}
65
66void WebPopupItem::encode(IPC::Encoder& encoder) const
67{
68 encoder.encodeEnum(m_type);
69 encoder << m_text;
70 encoder.encodeEnum(m_textDirection);
71 encoder << m_hasTextDirectionOverride;
72 encoder << m_toolTip;
73 encoder << m_accessibilityText;
74 encoder << m_isEnabled;
75 encoder << m_isLabel;
76 encoder << m_isSelected;
77}
78
79Optional<WebPopupItem> WebPopupItem::decode(IPC::Decoder& decoder)
80{
81 Type type;
82 if (!decoder.decodeEnum(type))
83 return WTF::nullopt;
84
85 String text;
86 if (!decoder.decode(text))
87 return WTF::nullopt;
88
89 WebCore::TextDirection textDirection;
90 if (!decoder.decodeEnum(textDirection))
91 return WTF::nullopt;
92
93 bool hasTextDirectionOverride;
94 if (!decoder.decode(hasTextDirectionOverride))
95 return WTF::nullopt;
96
97 String toolTip;
98 if (!decoder.decode(toolTip))
99 return WTF::nullopt;
100
101 String accessibilityText;
102 if (!decoder.decode(accessibilityText))
103 return WTF::nullopt;
104
105 bool isEnabled;
106 if (!decoder.decode(isEnabled))
107 return WTF::nullopt;
108
109 bool isLabel;
110 if (!decoder.decode(isLabel))
111 return WTF::nullopt;
112
113 bool isSelected;
114 if (!decoder.decode(isSelected))
115 return WTF::nullopt;
116
117 return {{ type, text, textDirection, hasTextDirectionOverride, toolTip, accessibilityText, isEnabled, isLabel, isSelected }};
118}
119
120} // namespace WebKit
121