2012-04-27 23:19:06 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/renderer/dom_node_impl.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2012-04-27 23:19:06 +02:00
|
|
|
#include "libcef/common/tracker.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "libcef/renderer/blink_glue.h"
|
2012-04-27 23:19:06 +02:00
|
|
|
#include "libcef/renderer/browser_impl.h"
|
|
|
|
#include "libcef/renderer/dom_document_impl.h"
|
|
|
|
#include "libcef/renderer/thread_util.h"
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/platform/web_string.h"
|
|
|
|
#include "third_party/blink/public/web/web_document.h"
|
|
|
|
#include "third_party/blink/public/web/web_dom_event.h"
|
|
|
|
#include "third_party/blink/public/web/web_element.h"
|
|
|
|
#include "third_party/blink/public/web/web_form_control_element.h"
|
|
|
|
#include "third_party/blink/public/web/web_input_element.h"
|
|
|
|
#include "third_party/blink/public/web/web_node.h"
|
|
|
|
#include "third_party/blink/public/web/web_select_element.h"
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2013-11-08 22:28:56 +01:00
|
|
|
using blink::WebDocument;
|
|
|
|
using blink::WebDOMEvent;
|
|
|
|
using blink::WebElement;
|
|
|
|
using blink::WebFormControlElement;
|
|
|
|
using blink::WebInputElement;
|
|
|
|
using blink::WebNode;
|
|
|
|
using blink::WebSelectElement;
|
|
|
|
using blink::WebString;
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
CefDOMNodeImpl::CefDOMNodeImpl(CefRefPtr<CefDOMDocumentImpl> document,
|
2013-11-08 22:28:56 +01:00
|
|
|
const blink::WebNode& node)
|
2017-05-17 11:29:28 +02:00
|
|
|
: document_(document), node_(node) {}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
CefDOMNodeImpl::~CefDOMNodeImpl() {
|
|
|
|
CEF_REQUIRE_RT();
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (document_.get() && !node_.IsNull()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
// Remove the node from the document.
|
|
|
|
document_->RemoveNode(node_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefDOMNodeImpl::Type CefDOMNodeImpl::GetType() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return DOM_NODE_TYPE_UNSUPPORTED;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
return blink_glue::GetNodeType(node_);
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDOMNodeImpl::IsText() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return node_.IsTextNode();
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDOMNodeImpl::IsElement() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return node_.IsElementNode();
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
2012-06-11 17:52:49 +02:00
|
|
|
// Logic copied from RenderViewImpl::IsEditableNode.
|
|
|
|
bool CefDOMNodeImpl::IsEditable() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-06-11 17:52:49 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (node_.IsContentEditable()) {
|
2012-06-11 17:52:49 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (node_.IsElementNode()) {
|
2022-02-21 23:23:40 +01:00
|
|
|
const WebElement& element = node_.To<WebElement>();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (blink_glue::IsTextControlElement(element)) {
|
2012-06-11 17:52:49 +02:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
|
|
|
|
// Also return true if it has an ARIA role of 'textbox'.
|
2017-04-20 21:28:17 +02:00
|
|
|
for (unsigned i = 0; i < element.AttributeCount(); ++i) {
|
2022-06-17 15:28:55 +02:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(element.AttributeLocalName(i).Utf8(),
|
|
|
|
"role")) {
|
|
|
|
if (base::EqualsCaseInsensitiveASCII(element.AttributeValue(i).Utf8(),
|
|
|
|
"textbox")) {
|
2012-06-11 17:52:49 +02:00
|
|
|
return true;
|
2015-08-14 16:41:08 +02:00
|
|
|
}
|
2012-06-11 17:52:49 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-27 23:19:06 +02:00
|
|
|
bool CefDOMNodeImpl::IsFormControlElement() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (node_.IsElementNode()) {
|
2022-02-21 23:23:40 +01:00
|
|
|
const WebElement& element = node_.To<WebElement>();
|
2017-04-20 21:28:17 +02:00
|
|
|
return element.IsFormControlElement();
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDOMNodeImpl::GetFormControlElementType() {
|
|
|
|
CefString str;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (node_.IsElementNode()) {
|
2022-02-21 23:23:40 +01:00
|
|
|
const WebElement& element = node_.To<WebElement>();
|
2017-04-20 21:28:17 +02:00
|
|
|
if (element.IsFormControlElement()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
// Retrieve the type from the form control element.
|
|
|
|
const WebFormControlElement& formElement =
|
2022-02-21 23:23:40 +01:00
|
|
|
node_.To<WebFormControlElement>();
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& form_control_type =
|
2017-04-20 21:28:17 +02:00
|
|
|
formElement.FormControlType().Utf16();
|
2012-04-27 23:19:06 +02:00
|
|
|
str = form_control_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDOMNodeImpl::IsSame(CefRefPtr<CefDOMNode> that) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
CefDOMNodeImpl* impl = static_cast<CefDOMNodeImpl*>(that.get());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!impl || !impl->VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return node_.Equals(impl->node_);
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDOMNodeImpl::GetName() {
|
|
|
|
CefString str;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
const WebString& name = blink_glue::GetNodeName(node_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!name.IsNull()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
str = name.Utf16();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDOMNodeImpl::GetValue() {
|
|
|
|
CefString str;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (node_.IsElementNode()) {
|
2022-02-21 23:23:40 +01:00
|
|
|
const WebElement& element = node_.To<WebElement>();
|
2017-04-20 21:28:17 +02:00
|
|
|
if (element.IsFormControlElement()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
// Retrieve the value from the form control element.
|
|
|
|
const WebFormControlElement& formElement =
|
2022-02-21 23:23:40 +01:00
|
|
|
node_.To<WebFormControlElement>();
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string value;
|
|
|
|
const std::u16string& form_control_type =
|
2017-04-20 21:28:17 +02:00
|
|
|
formElement.FormControlType().Utf16();
|
2021-04-21 00:52:34 +02:00
|
|
|
if (form_control_type == u"text") {
|
2012-04-27 23:19:06 +02:00
|
|
|
const WebInputElement& input_element =
|
2022-02-21 23:23:40 +01:00
|
|
|
formElement.To<WebInputElement>();
|
2017-04-20 21:28:17 +02:00
|
|
|
value = input_element.Value().Utf16();
|
2021-04-21 00:52:34 +02:00
|
|
|
} else if (form_control_type == u"select-one") {
|
2012-04-27 23:19:06 +02:00
|
|
|
const WebSelectElement& select_element =
|
2022-02-21 23:23:40 +01:00
|
|
|
formElement.To<WebSelectElement>();
|
2017-04-20 21:28:17 +02:00
|
|
|
value = select_element.Value().Utf16();
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
base::TrimWhitespace(value, base::TRIM_LEADING, &value);
|
2012-04-27 23:19:06 +02:00
|
|
|
str = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str.empty()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
const WebString& value = node_.NodeValue();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!value.IsNull()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
str = value.Utf16();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDOMNodeImpl::SetValue(const CefString& value) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (node_.IsElementNode()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
return blink_glue::SetNodeValue(node_,
|
|
|
|
WebString::FromUTF16(value.ToString16()));
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDOMNodeImpl::GetAsMarkup() {
|
|
|
|
CefString str;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
const WebString& markup = blink_glue::CreateNodeMarkup(node_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!markup.IsNull()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
str = markup.Utf16();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDOMDocument> CefDOMNodeImpl::GetDocument() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
return document_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDOMNode> CefDOMNodeImpl::GetParent() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return document_->GetOrCreateNode(node_.ParentNode());
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDOMNode> CefDOMNodeImpl::GetPreviousSibling() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return document_->GetOrCreateNode(node_.PreviousSibling());
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDOMNode> CefDOMNodeImpl::GetNextSibling() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return document_->GetOrCreateNode(node_.NextSibling());
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDOMNodeImpl::HasChildren() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return !node_.FirstChild().IsNull();
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDOMNode> CefDOMNodeImpl::GetFirstChild() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return document_->GetOrCreateNode(node_.FirstChild());
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDOMNode> CefDOMNodeImpl::GetLastChild() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
return document_->GetOrCreateNode(node_.LastChild());
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDOMNodeImpl::GetElementTagName() {
|
|
|
|
CefString str;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!node_.IsElementNode()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
const WebElement& element = node_.To<blink::WebElement>();
|
2017-04-20 21:28:17 +02:00
|
|
|
const WebString& tagname = element.TagName();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!tagname.IsNull()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
str = tagname.Utf16();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDOMNodeImpl::HasElementAttributes() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!node_.IsElementNode()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
const WebElement& element = node_.To<blink::WebElement>();
|
2017-04-20 21:28:17 +02:00
|
|
|
return (element.AttributeCount() > 0);
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDOMNodeImpl::HasElementAttribute(const CefString& attrName) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!node_.IsElementNode()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
const WebElement& element = node_.To<blink::WebElement>();
|
2018-03-20 21:15:08 +01:00
|
|
|
return element.HasAttribute(WebString::FromUTF16(attrName.ToString16()));
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDOMNodeImpl::GetElementAttribute(const CefString& attrName) {
|
|
|
|
CefString str;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!node_.IsElementNode()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
const WebElement& element = node_.To<blink::WebElement>();
|
2018-03-20 21:15:08 +01:00
|
|
|
const WebString& attr =
|
|
|
|
element.GetAttribute(WebString::FromUTF16(attrName.ToString16()));
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!attr.IsNull()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
str = attr.Utf16();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefDOMNodeImpl::GetElementAttributes(AttributeMap& attrMap) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!node_.IsElementNode()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2012-04-27 23:19:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-21 23:23:40 +01:00
|
|
|
const WebElement& element = node_.To<blink::WebElement>();
|
2017-04-20 21:28:17 +02:00
|
|
|
unsigned int len = element.AttributeCount();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (len == 0) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < len; ++i) {
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string name = element.AttributeLocalName(i).Utf16();
|
|
|
|
std::u16string value = element.AttributeValue(i).Utf16();
|
2012-04-27 23:19:06 +02:00
|
|
|
attrMap.insert(std::make_pair(name, value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDOMNodeImpl::SetElementAttribute(const CefString& attrName,
|
|
|
|
const CefString& value) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!node_.IsElementNode()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
WebElement element = node_.To<blink::WebElement>();
|
2018-03-20 21:15:08 +01:00
|
|
|
element.SetAttribute(WebString::FromUTF16(attrName.ToString16()),
|
|
|
|
WebString::FromUTF16(value.ToString16()));
|
2016-05-25 01:35:43 +02:00
|
|
|
return true;
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefDOMNodeImpl::GetElementInnerText() {
|
|
|
|
CefString str;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!node_.IsElementNode()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2012-04-27 23:19:06 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
WebElement element = node_.To<blink::WebElement>();
|
|
|
|
const WebString& text = element.TextContent();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!text.IsNull()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
str = text.Utf16();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-27 23:19:06 +02:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2016-09-09 20:02:57 +02:00
|
|
|
CefRect CefDOMNodeImpl::GetElementBounds() {
|
|
|
|
CefRect rect;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyContext()) {
|
2016-09-09 20:02:57 +02:00
|
|
|
return rect;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-09-09 20:02:57 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
if (!node_.IsElementNode()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2016-09-09 20:02:57 +02:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
WebElement element = node_.To<blink::WebElement>();
|
2022-09-26 21:30:45 +02:00
|
|
|
const auto& rc = element.BoundsInWidget();
|
2021-03-04 23:36:57 +01:00
|
|
|
rect.Set(rc.x(), rc.y(), rc.width(), rc.height());
|
2016-09-09 20:02:57 +02:00
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2012-04-27 23:19:06 +02:00
|
|
|
void CefDOMNodeImpl::Detach() {
|
2020-01-15 14:36:24 +01:00
|
|
|
document_ = nullptr;
|
2017-04-20 21:28:17 +02:00
|
|
|
node_.Assign(WebNode());
|
2012-04-27 23:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefDOMNodeImpl::VerifyContext() {
|
|
|
|
if (!document_.get()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!document_->VerifyContext()) {
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-04-20 21:28:17 +02:00
|
|
|
if (node_.IsNull()) {
|
2023-05-08 17:19:38 +02:00
|
|
|
DCHECK(false);
|
2012-04-27 23:19:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|