2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_CONTEXT_MENU_DATA_CONTEXT_MENU_DATA_H_
32 #define THIRD_PARTY_BLINK_PUBLIC_COMMON_CONTEXT_MENU_DATA_CONTEXT_MENU_DATA_H_
36 #include "services/network/public/mojom/referrer_policy.mojom-shared.h"
37 #include "third_party/abseil-cpp/absl/types/optional.h"
38 #include "third_party/blink/public/common/context_menu_data/menu_item_info.h"
39 #include "third_party/blink/public/common/input/web_menu_source_type.h"
40 #include "third_party/blink/public/common/navigation/impression.h"
41 #include "third_party/blink/public/mojom/context_menu/context_menu.mojom-shared.h"
42 #include "ui/gfx/geometry/point.h"
43 #include "ui/gfx/geometry/rect.h"
48 // This struct is passed to WebViewClient::ShowContextMenu.
49 struct ContextMenuData {
50 // The type of media the context menu is being invoked on.
51 // using MediaType = blink::mojom::ContextMenuDataMediaType;
52 blink::mojom::ContextMenuDataMediaType media_type;
54 // The x and y position of the mouse pointer (relative to the webview).
55 gfx::Point mouse_position;
57 // The absolute URL of the link that is in context.
60 // The absolute URL of the image/video/audio that is in context.
63 // Whether the image in context is a null.
64 bool has_image_contents;
66 // The encoding for the frame in context.
67 std::string frame_encoding;
76 kMediaHasAudio = 0x20,
77 kMediaCanToggleControls = 0x40,
78 kMediaControls = 0x80,
79 kMediaCanPrint = 0x100,
80 kMediaCanRotate = 0x200,
81 kMediaCanPictureInPicture = 0x400,
82 kMediaPictureInPicture = 0x800,
83 kMediaCanLoop = 0x1000,
86 // Extra attributes describing media elements.
89 // The text of the link that is in the context.
90 std::string link_text;
92 // If the node is a link, the impression declared by the link's conversion
93 // measurement attributes.
94 absl::optional<Impression> impression;
96 // The raw text of the selection in context.
97 std::string selected_text;
99 // Title attribute of the selection in context.
100 std::string title_text;
102 // Alt attribute of the selection in context.
103 std::string alt_text;
105 // Whether spell checking is enabled.
106 bool is_spell_checking_enabled;
108 // Suggested filename for saving file.
109 std::string suggested_filename;
111 // The editable (possibily) misspelled word.
112 std::u16string misspelled_word;
114 // If misspelledWord is not empty, holds suggestions from the dictionary.
115 std::vector<std::u16string> dictionary_suggestions;
117 // Whether context is editable.
120 #if BUILDFLAG(IS_EFL)
124 // If this node is an input field, the type of that field.
125 blink::mojom::ContextMenuDataInputFieldType input_field_type;
127 enum CheckableMenuItemFlags {
128 kCheckableMenuItemDisabled = 0x0,
129 kCheckableMenuItemEnabled = 0x1,
130 kCheckableMenuItemChecked = 0x2,
133 // Writing direction menu items - values are unions of
134 // CheckableMenuItemFlags.
135 int writing_direction_default;
136 int writing_direction_left_to_right;
137 int writing_direction_right_to_left;
139 // Which edit operations are available in the context.
142 // The referrer policy applicable to this context.
143 network::mojom::ReferrerPolicy referrer_policy;
145 // Custom context menu items provided by the WebCore internals.
146 std::vector<MenuItemInfo> custom_items;
148 // Selection in viewport coordinates.
149 gfx::Rect selection_rect;
151 // TODO(https://crbug.com/781914): Remove this field after we done with Blink
153 // Global index of start position for the current selection.
154 // If the current element is editable, then it starts from the first
155 // character within the element, otherwise, it starts from the beginning of
156 // the current webpage.
157 int selection_start_offset;
159 WebMenuSourceType source_type;
161 // True when the context contains text selected by a text fragment. See
162 // TextFragmentAnchor.
163 bool opened_from_highlight = false;
165 // The form's renderer id if the context menu is triggered on the form.
166 absl::optional<uint64_t> form_renderer_id;
168 // The field's renderer id if the context menu is triggered on an input
169 // field or a textarea field.
170 absl::optional<uint64_t> field_renderer_id;
173 : media_type(blink::mojom::ContextMenuDataMediaType::kNone),
174 has_image_contents(false),
175 media_flags(kMediaNone),
176 is_spell_checking_enabled(false),
178 #if BUILDFLAG(IS_EFL)
181 writing_direction_default(kCheckableMenuItemDisabled),
182 writing_direction_left_to_right(kCheckableMenuItemEnabled),
183 writing_direction_right_to_left(kCheckableMenuItemEnabled),
189 #endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_CONTEXT_MENU_DATA_CONTEXT_MENU_DATA_H_