1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*
* Copyright (C) 2018 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "WebKitDOMElement.h"
#include "DOMObjectCache.h"
#include "WebKitDOMElementPrivate.h"
#include "WebKitDOMNodePrivate.h"
#include "WebKitDOMPrivate.h"
#include <WebCore/HTMLInputElement.h>
#include <WebCore/HTMLTextAreaElement.h>
#if PLATFORM(GTK)
#include "WebKitDOMEventTarget.h"
#endif
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
namespace WebKit {
WebKitDOMElement* kit(WebCore::Element* obj)
{
return WEBKIT_DOM_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
}
WebCore::Element* core(WebKitDOMElement* element)
{
return element ? static_cast<WebCore::Element*>(webkitDOMNodeGetCoreObject(WEBKIT_DOM_NODE(element))) : nullptr;
}
WebKitDOMElement* wrapElement(WebCore::Element* coreObject)
{
ASSERT(coreObject);
#if PLATFORM(GTK)
return WEBKIT_DOM_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_ELEMENT, "core-object", coreObject, nullptr));
#else
auto* element = WEBKIT_DOM_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_ELEMENT, nullptr));
webkitDOMNodeSetCoreObject(WEBKIT_DOM_NODE(element), static_cast<WebCore::Node*>(coreObject));
return element;
#endif
}
} // namespace WebKit
#if PLATFORM(GTK)
G_DEFINE_TYPE_WITH_CODE(WebKitDOMElement, webkit_dom_element, WEBKIT_DOM_TYPE_NODE, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkitDOMElementDOMEventTargetInit))
#else
G_DEFINE_TYPE(WebKitDOMElement, webkit_dom_element, WEBKIT_DOM_TYPE_NODE)
#endif
static void webkit_dom_element_class_init(WebKitDOMElementClass* elementClass)
{
#if PLATFORM(GTK)
GObjectClass* gobjectClass = G_OBJECT_CLASS(elementClass);
webkitDOMElementInstallProperties(gobjectClass);
#endif
}
static void webkit_dom_element_init(WebKitDOMElement*)
{
}
/**
* webkit_dom_element_html_input_element_is_user_edited:
* @element: a #WebKitDOMElement
*
* Get whether @element is an HTML text input element that has been edited by a user action.
*
* Returns: whether @element has been edited by a user action.
*
* Since: 2.22
*
* Deprecated: 2.40: Use webkit_web_form_manager_input_element_is_user_edited() instead.
*/
gboolean webkit_dom_element_html_input_element_is_user_edited(WebKitDOMElement* element)
{
g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(element), FALSE);
auto* node = webkitDOMNodeGetCoreObject(WEBKIT_DOM_NODE(element));
if (is<WebCore::HTMLInputElement>(node))
return downcast<WebCore::HTMLInputElement>(*node).lastChangeWasUserEdit();
if (is<WebCore::HTMLTextAreaElement>(node))
return downcast<WebCore::HTMLTextAreaElement>(*node).lastChangeWasUserEdit();
return FALSE;
}
/**
* webkit_dom_element_html_input_element_get_auto_filled:
* @element: a #WebKitDOMElement
*
* Get whether the element is an HTML input element that has been filled automatically.
*
* Returns: whether @element has been filled automatically.
*
* Since: 2.22
*
* Deprecated: 2.40: Use webkit_web_form_manager_input_element_is_auto_filled() instead.
*/
gboolean webkit_dom_element_html_input_element_get_auto_filled(WebKitDOMElement* element)
{
g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(element), FALSE);
auto* node = webkitDOMNodeGetCoreObject(WEBKIT_DOM_NODE(element));
if (!is<WebCore::HTMLInputElement>(node))
return false;
return downcast<WebCore::HTMLInputElement>(*node).isAutoFilled();
}
/**
* webkit_dom_element_html_input_element_set_auto_filled:
* @element: a #WebKitDOMElement
* @auto_filled: value to set
*
* Set whether the element is an HTML input element that has been filled automatically.
* If @element is not an HTML input element this function does nothing.
*
* Since: 2.22
*
* Deprecated: 2.40: Use webkit_web_form_manager_input_element_auto_fill() instead.
*/
void webkit_dom_element_html_input_element_set_auto_filled(WebKitDOMElement* element, gboolean autoFilled)
{
g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(element));
auto* node = webkitDOMNodeGetCoreObject(WEBKIT_DOM_NODE(element));
if (!is<WebCore::HTMLInputElement>(node))
return;
downcast<WebCore::HTMLInputElement>(*node).setAutoFilled(autoFilled);
}
/**
* webkit_dom_element_html_input_element_set_editing_value:
* @element: a #WebKitDOMElement
* @value: the text to set
*
* Set the value of an HTML input element as if it had been edited by
* the user, triggering a change event. If @element is not an HTML input
* element this function does nothing.
*
* Since: 2.22
*
* Deprecated: 2.40: Use webkit_web_form_manager_input_element_auto_fill() instead.
*/
void webkit_dom_element_html_input_element_set_editing_value(WebKitDOMElement* element, const char* value)
{
g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(element));
auto* node = webkitDOMNodeGetCoreObject(WEBKIT_DOM_NODE(element));
if (!is<WebCore::HTMLInputElement>(node))
return;
downcast<WebCore::HTMLInputElement>(*node).setValueForUser(String::fromUTF8(value));
}
G_GNUC_END_IGNORE_DEPRECATIONS;
|