[M108 Migration][Text Selection] Selection handles & Caret Selection
[platform/framework/web/chromium-efl.git] / third_party / blink / public / common / context_menu_data / context_menu_data.h
1 /*
2  * Copyright (C) 2009, 2012 Google 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 are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
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_
33
34 #include <vector>
35
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"
44 #include "url/gurl.h"
45
46 namespace blink {
47
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;
53
54   // The x and y position of the mouse pointer (relative to the webview).
55   gfx::Point mouse_position;
56
57   // The absolute URL of the link that is in context.
58   GURL link_url;
59
60   // The absolute URL of the image/video/audio that is in context.
61   GURL src_url;
62
63   // Whether the image in context is a null.
64   bool has_image_contents;
65
66   // The encoding for the frame in context.
67   std::string frame_encoding;
68
69   enum MediaFlags {
70     kMediaNone = 0x0,
71     kMediaInError = 0x1,
72     kMediaPaused = 0x2,
73     kMediaMuted = 0x4,
74     kMediaLoop = 0x8,
75     kMediaCanSave = 0x10,
76     kMediaHasAudio = 0x20,
77     kMediaCanToggleControls = 0x40,
78     kMediaControls = 0x80,
79     kMediaCanPrint = 0x100,
80     kMediaCanRotate = 0x200,
81     kMediaCanPictureInPicture = 0x400,
82     kMediaPictureInPicture = 0x800,
83     kMediaCanLoop = 0x1000,
84   };
85
86   // Extra attributes describing media elements.
87   int media_flags;
88
89   // The text of the link that is in the context.
90   std::string link_text;
91
92   // If the node is a link, the impression declared by the link's conversion
93   // measurement attributes.
94   absl::optional<Impression> impression;
95
96   // The raw text of the selection in context.
97   std::string selected_text;
98
99   // Title attribute of the selection in context.
100   std::string title_text;
101
102   // Alt attribute of the selection in context.
103   std::string alt_text;
104
105   // Whether spell checking is enabled.
106   bool is_spell_checking_enabled;
107
108   // Suggested filename for saving file.
109   std::string suggested_filename;
110
111   // The editable (possibily) misspelled word.
112   std::u16string misspelled_word;
113
114   // If misspelledWord is not empty, holds suggestions from the dictionary.
115   std::vector<std::u16string> dictionary_suggestions;
116
117   // Whether context is editable.
118   bool is_editable;
119
120 #if BUILDFLAG(IS_EFL)
121   bool is_text_node;
122 #endif
123
124   // If this node is an input field, the type of that field.
125   blink::mojom::ContextMenuDataInputFieldType input_field_type;
126
127   enum CheckableMenuItemFlags {
128     kCheckableMenuItemDisabled = 0x0,
129     kCheckableMenuItemEnabled = 0x1,
130     kCheckableMenuItemChecked = 0x2,
131   };
132
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;
138
139   // Which edit operations are available in the context.
140   int edit_flags;
141
142   // The referrer policy applicable to this context.
143   network::mojom::ReferrerPolicy referrer_policy;
144
145   // Custom context menu items provided by the WebCore internals.
146   std::vector<MenuItemInfo> custom_items;
147
148   // Selection in viewport coordinates.
149   gfx::Rect selection_rect;
150
151   // TODO(https://crbug.com/781914): Remove this field after we done with Blink
152   // side tracking.
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;
158
159   WebMenuSourceType source_type;
160
161   // True when the context contains text selected by a text fragment. See
162   // TextFragmentAnchor.
163   bool opened_from_highlight = false;
164
165   // The form's renderer id if the context menu is triggered on the form.
166   absl::optional<uint64_t> form_renderer_id;
167
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;
171
172   ContextMenuData()
173       : media_type(blink::mojom::ContextMenuDataMediaType::kNone),
174         has_image_contents(false),
175         media_flags(kMediaNone),
176         is_spell_checking_enabled(false),
177         is_editable(false),
178 #if BUILDFLAG(IS_EFL)
179         is_text_node(false),
180 #endif
181         writing_direction_default(kCheckableMenuItemDisabled),
182         writing_direction_left_to_right(kCheckableMenuItemEnabled),
183         writing_direction_right_to_left(kCheckableMenuItemEnabled),
184         edit_flags(0) {}
185 };
186
187 }  // namespace blink
188
189 #endif  // THIRD_PARTY_BLINK_PUBLIC_COMMON_CONTEXT_MENU_DATA_CONTEXT_MENU_DATA_H_