Messagelib

webhittestresult.cpp
1 /*
2  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 /* ============================================================
8  * QupZilla - QtWebEngine based browser
9  * SPDX-FileCopyrightText: 2015 David Rosca <[email protected]>
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 
27 using namespace WebEngineViewer;
28 
29 class WebEngineViewer::WebHitTestResultPrivate
30 {
31 public:
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 
57 void 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 
91 WebHitTestResult::WebHitTestResult()
92  : d(new WebHitTestResultPrivate)
93 {
94 }
95 
96 WebHitTestResult::WebHitTestResult(const QPoint &pos, const QUrl &pageUrl, const QVariant &result)
97  : d(new WebHitTestResultPrivate(pos, pageUrl, result))
98 {
99 }
100 
101 WebHitTestResult::WebHitTestResult(const WebHitTestResult &other)
102  : d(new WebHitTestResultPrivate)
103 {
104  (*this) = other;
105 }
106 
107 WebHitTestResult::~WebHitTestResult() = default;
108 
109 WebHitTestResult &WebHitTestResult::operator=(const WebHitTestResult &other)
110 {
111  if (this != &other) {
112  *d = *(other.d);
113  }
114  return *this;
115 }
116 
117 QString WebHitTestResult::alternateText() const
118 {
119  return d->mAlternateText;
120 }
121 
122 QRect WebHitTestResult::boundingRect() const
123 {
124  return d->mBoundingRect;
125 }
126 
127 QUrl WebHitTestResult::imageUrl() const
128 {
129  return d->mImageUrl;
130 }
131 
132 bool WebHitTestResult::isContentEditable() const
133 {
134  return d->mIsContentEditable;
135 }
136 
137 bool WebHitTestResult::isContentSelected() const
138 {
139  return d->mIsContentSelected;
140 }
141 
142 bool WebHitTestResult::isNull() const
143 {
144  return d->mIsNull;
145 }
146 
147 QString WebHitTestResult::linkTitle() const
148 {
149  return d->mLinkTitle;
150 }
151 
152 QUrl WebHitTestResult::linkUrl() const
153 {
154  return d->mLinkUrl;
155 }
156 
157 QUrl WebHitTestResult::mediaUrl() const
158 {
159  return d->mMediaUrl;
160 }
161 
162 bool WebHitTestResult::mediaPaused() const
163 {
164  return d->mMediaPaused;
165 }
166 
167 bool WebHitTestResult::mediaMuted() const
168 {
169  return d->mMediaMuted;
170 }
171 
172 QPoint WebHitTestResult::pos() const
173 {
174  return d->mPos;
175 }
176 
177 QString WebHitTestResult::tagName() const
178 {
179  return d->mTagName;
180 }
181 
182 QUrl WebHitTestResult::pageUrl() const
183 {
184  return d->mPageUrl;
185 }
The WebHitTestResult class.
QCA_EXPORT void init()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 23:04:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.