Messagelib

webhittestresult.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7/* ============================================================
8 * QupZilla - QtWebEngine based browser
9 * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * ============================================================ */
24#include "webhittestresult.h"
25#include <QDebug>
26
27using namespace WebEngineViewer;
28
29class WebEngineViewer::WebHitTestResultPrivate
30{
31public:
32 WebHitTestResultPrivate(const QPoint &pos = QPoint(), const QUrl &url = QUrl(), const QVariant &result = QVariant())
33 : mPos(pos)
34 , mPageUrl(url)
35 {
36 init(result.toMap());
37 }
38
39 void init(const QVariantMap &map);
40
41 QPoint mPos;
42 QRect mBoundingRect;
43 QUrl mImageUrl;
44 QUrl mLinkUrl;
45 QUrl mMediaUrl;
46 QUrl mPageUrl;
47 QString mTagName;
48 QString mLinkTitle;
49 QString mAlternateText;
50 bool mIsContentEditable = false;
51 bool mIsContentSelected = false;
52 bool mMediaPaused = false;
53 bool mMediaMuted = false;
54 bool mIsNull = true;
55};
56
57void WebHitTestResultPrivate::init(const QVariantMap &map)
58{
59 if (map.isEmpty()) {
60 return;
61 }
62 // qDebug()<<" void WebHitTestResult::init(const QVariantMap &map)"<<map;
63 mAlternateText = map.value(QStringLiteral("alternateText")).toString();
64 mImageUrl = map.value(QStringLiteral("imageUrl")).toUrl();
65 mIsContentEditable = map.value(QStringLiteral("contentEditable")).toBool();
66 mIsContentSelected = map.value(QStringLiteral("contentSelected")).toBool();
67 mLinkTitle = map.value(QStringLiteral("linkTitle")).toString();
68 mLinkUrl = map.value(QStringLiteral("linkUrl")).toUrl();
69 mMediaUrl = map.value(QStringLiteral("mediaUrl")).toUrl();
70 mMediaPaused = map.value(QStringLiteral("mediaPaused")).toBool();
71 mMediaMuted = map.value(QStringLiteral("mediaMuted")).toBool();
72 mTagName = map.value(QStringLiteral("tagName")).toString();
73
74 const QVariantList &rect = map.value(QStringLiteral("boundingRect")).toList();
75 if (rect.size() == 4) {
76 mBoundingRect = QRect(rect.at(0).toInt(), rect.at(1).toInt(), rect.at(2).toInt(), rect.at(3).toInt());
77 }
78
79 if (!mImageUrl.isEmpty()) {
80 mImageUrl = mPageUrl.resolved(mImageUrl);
81 }
82 if (!mLinkUrl.isEmpty()) {
83 mLinkUrl = mPageUrl.resolved(mLinkUrl);
84 }
85 if (!mMediaUrl.isEmpty()) {
86 mMediaUrl = mPageUrl.resolved(mMediaUrl);
87 }
88 mIsNull = false;
89}
90
91WebHitTestResult::WebHitTestResult()
92 : d(new WebHitTestResultPrivate)
93{
94}
95
96WebHitTestResult::WebHitTestResult(const QPoint &pos, const QUrl &pageUrl, const QVariant &result)
97 : d(new WebHitTestResultPrivate(pos, pageUrl, result))
98{
99}
100
101WebHitTestResult::WebHitTestResult(const WebHitTestResult &other)
102 : d(new WebHitTestResultPrivate)
103{
104 (*this) = other;
105}
106
107WebHitTestResult::~WebHitTestResult() = default;
108
109WebHitTestResult &WebHitTestResult::operator=(const WebHitTestResult &other)
110{
111 if (this != &other) {
112 *d = *(other.d);
113 }
114 return *this;
115}
116
117QString WebHitTestResult::alternateText() const
118{
119 return d->mAlternateText;
120}
121
122QRect WebHitTestResult::boundingRect() const
123{
124 return d->mBoundingRect;
125}
126
127QUrl WebHitTestResult::imageUrl() const
128{
129 return d->mImageUrl;
130}
131
132bool WebHitTestResult::isContentEditable() const
133{
134 return d->mIsContentEditable;
135}
136
137bool WebHitTestResult::isContentSelected() const
138{
139 return d->mIsContentSelected;
140}
141
142bool WebHitTestResult::isNull() const
143{
144 return d->mIsNull;
145}
146
147QString WebHitTestResult::linkTitle() const
148{
149 return d->mLinkTitle;
150}
151
152QUrl WebHitTestResult::linkUrl() const
153{
154 return d->mLinkUrl;
155}
156
157QUrl WebHitTestResult::mediaUrl() const
158{
159 return d->mMediaUrl;
160}
161
162bool WebHitTestResult::mediaPaused() const
163{
164 return d->mMediaPaused;
165}
166
167bool WebHitTestResult::mediaMuted() const
168{
169 return d->mMediaMuted;
170}
171
172QPoint WebHitTestResult::pos() const
173{
174 return d->mPos;
175}
176
177QString WebHitTestResult::tagName() const
178{
179 return d->mTagName;
180}
181
182QUrl WebHitTestResult::pageUrl() const
183{
184 return d->mPageUrl;
185}
The WebHitTestResult class.
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
bool isEmpty() const const
QUrl resolved(const QUrl &relative) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.