1/*
2 * Copyright (C) 2014 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21#include "WebKitNavigationAction.h"
22
23#include "WebKitNavigationActionPrivate.h"
24#include <gdk/gdk.h>
25#include <wtf/gobject/GRefPtr.h>
26
27using namespace WebKit;
28
29G_DEFINE_BOXED_TYPE(WebKitNavigationAction, webkit_navigation_action, webkit_navigation_action_copy, webkit_navigation_action_free)
30
31WebKitNavigationAction* webkitNavigationActionCreate(WebKitURIRequest* request, const NavigationActionData& navigationActionData)
32{
33    WebKitNavigationAction* navigation = g_slice_new0(WebKitNavigationAction);
34    new (navigation) WebKitNavigationAction(request, navigationActionData);
35    return navigation;
36}
37
38/**
39 * webkit_navigation_action_copy:
40 * @navigation: a #WebKitNavigationAction
41 *
42 * Make a copy of @navigation.
43 *
44 * Returns: (transfer full): A copy of passed in #WebKitNavigationAction
45 *
46 * Since: 2.6
47 */
48WebKitNavigationAction* webkit_navigation_action_copy(WebKitNavigationAction* navigation)
49{
50    g_return_val_if_fail(navigation, nullptr);
51
52    WebKitNavigationAction* copy = g_slice_new0(WebKitNavigationAction);
53    new (copy) WebKitNavigationAction(navigation);
54    return copy;
55}
56
57/**
58 * webkit_navigation_action_free:
59 * @navigation: a #WebKitNavigationAction
60 *
61 * Free the #WebKitNavigationAction
62 *
63 * Since: 2.6
64 */
65void webkit_navigation_action_free(WebKitNavigationAction* navigation)
66{
67    g_return_if_fail(navigation);
68
69    navigation->~WebKitNavigationAction();
70    g_slice_free(WebKitNavigationAction, navigation);
71}
72
73/**
74 * webkit_navigation_action_get_navigation_type:
75 * @navigation: a #WebKitNavigationAction
76 *
77 * Rtuen the type of action that triggered the navigation.
78 *
79 * Returns: a #WebKitNavigationType
80 *
81 * Since: 2.6
82 */
83WebKitNavigationType webkit_navigation_action_get_navigation_type(WebKitNavigationAction* navigation)
84{
85    g_return_val_if_fail(navigation, WEBKIT_NAVIGATION_TYPE_OTHER);
86    return navigation->type;
87}
88
89/**
90 * webkit_navigation_action_get_mouse_button:
91 * @navigation: a #WebKitNavigationAction
92 *
93 * Return the number of the mouse button that triggered the navigation, or 0 if
94 * the navigation was not started by a mouse event.
95 *
96 * Returns: the mouse button number or 0
97 *
98 * Since: 2.6
99 */
100unsigned webkit_navigation_action_get_mouse_button(WebKitNavigationAction* navigation)
101{
102    g_return_val_if_fail(navigation, 0);
103    return navigation->mouseButton;
104}
105
106/**
107 * webkit_navigation_action_get_modifiers:
108 * @navigation: a #WebKitNavigationAction
109 *
110 * Return a bitmask of #GdkModifierType values describing the modifier keys that were in effect
111 * when the navigation was requested
112 *
113 * Returns: the modifier keys
114 *
115 * Since: 2.6
116 */
117unsigned webkit_navigation_action_get_modifiers(WebKitNavigationAction* navigation)
118{
119    g_return_val_if_fail(navigation, 0);
120    return navigation->modifiers;
121}
122
123/**
124 * webkit_navigation_action_get_request:
125 * @navigation: a #WebKitNavigationAction
126 *
127 * Return the navigation #WebKitURIRequest
128 *
129 * Returns: (transfer none): a #WebKitURIRequest
130 *
131 * Since: 2.6
132 */
133WebKitURIRequest* webkit_navigation_action_get_request(WebKitNavigationAction* navigation)
134{
135    g_return_val_if_fail(navigation, nullptr);
136    return navigation->request.get();
137}
138
139/**
140 * webkit_navigation_action_is_user_gesture:
141 * @navigation: a #WebKitNavigationAction
142 *
143 * Return whether the navigation was triggered by a user gesture like a mouse click.
144 *
145 * Returns: whether navigation action is a user gesture
146 *
147 * Since: 2.6
148 */
149gboolean webkit_navigation_action_is_user_gesture(WebKitNavigationAction* navigation)
150{
151    g_return_val_if_fail(navigation, FALSE);
152    return navigation->isUserGesture;
153}
154