summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorViktor Engelmann <Viktor.Engelmann@qt.io>2017-03-17 11:23:49 +0100
committerViktor Engelmann <viktor.engelmann@qt.io>2017-04-03 13:53:08 +0000
commit317270cdda436ca0ef7d28ce53de7b09deb9858f (patch)
tree0ba60c53fc452bd521d3cc1196be0dc275a525d2
parent534c6dd960dc627040aba0cf2039e70ac92fa73a (diff)
Add several QtWebKit WebActions
Add WebActions ToggleBold, ToggleItalic, ToggleUnderline, ToggleStrikethrough, AlignLeft, AlignCenter, AlignRight, AlignJustified, Indent, Outdent, InsertOrderedList and InsertUnorderedList. All use the javascript document.execCommand with parameters according to https://developer.mozilla.org/de/docs/Web/API/Document/execCommand Task-number: QTBUG-59221 Change-Id: Ife18d660fefa2073351c5ad959611ec47b680dc6 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
-rw-r--r--src/webengine/api/qquickwebengineview.cpp36
-rw-r--r--src/webengine/api/qquickwebengineview_p.h16
-rw-r--r--src/webengine/doc/src/webengineview.qdoc40
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp73
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h16
-rw-r--r--src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc40
6 files changed, 221 insertions, 0 deletions
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 6383f3468..8077e2c0b 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -1709,6 +1709,42 @@ void QQuickWebEngineView::triggerWebAction(WebAction action)
case ViewSource:
d->adapter->viewSource();
break;
+ case ToggleBold:
+ runJavaScript("document.execCommand('bold');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case ToggleItalic:
+ runJavaScript("document.execCommand('italic');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case ToggleUnderline:
+ runJavaScript("document.execCommand('underline');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case ToggleStrikethrough:
+ runJavaScript("document.execCommand('strikethrough');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case AlignLeft:
+ runJavaScript("document.execCommand('justifyLeft');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case AlignCenter:
+ runJavaScript("document.execCommand('justifyCenter');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case AlignRight:
+ runJavaScript("document.execCommand('justifyRight');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case AlignJustified:
+ runJavaScript("document.execCommand('justifyFull');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case Indent:
+ runJavaScript("document.execCommand('indent');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case Outdent:
+ runJavaScript("document.execCommand('outdent');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case InsertOrderedList:
+ runJavaScript("document.execCommand('insertOrderedList');", QQuickWebEngineScript::ApplicationWorld);
+ break;
+ case InsertUnorderedList:
+ runJavaScript("document.execCommand('insertUnorderedList');", QQuickWebEngineScript::ApplicationWorld);
+ break;
default:
Q_UNREACHABLE();
}
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index 92eb5d7de..f42720581 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -246,6 +246,22 @@ public:
Unselect,
SavePage,
ViewSource,
+
+ ToggleBold,
+ ToggleItalic,
+ ToggleUnderline,
+ ToggleStrikethrough,
+
+ AlignLeft,
+ AlignCenter,
+ AlignRight,
+ AlignJustified,
+ Indent,
+ Outdent,
+
+ InsertOrderedList,
+ InsertUnorderedList,
+
WebActionCount
};
Q_ENUM(WebAction)
diff --git a/src/webengine/doc/src/webengineview.qdoc b/src/webengine/doc/src/webengineview.qdoc
index 27c3d6920..e452746d9 100644
--- a/src/webengine/doc/src/webengineview.qdoc
+++ b/src/webengine/doc/src/webengineview.qdoc
@@ -793,6 +793,46 @@
\value WebEngineView.ViewSource
Show the source of the current page in a new tab. (Added in Qt 5.8)
+ \value WebEngineView.ToggleBold
+ Toggles boldness for the selection or at the cursor position.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value WebEngineView.ToggleItalic
+ Toggles italics for the selection or at the cursor position.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value WebEngineView.ToggleUnderline
+ Toggles underlining of the selection or at the cursor position.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value WebEngineView.ToggleStrikethrough
+ Toggles striking through the selection or at the cursor position.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+
+ \value WebEngineView.AlignLeft
+ Aligns the lines containing the selection or the cursor to the left.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value WebEngineView.AlignCenter
+ Aligns the lines containing the selection or the cursor at the center.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value WebEngineView.AlignRight
+ Aligns the lines containing the selection or the cursor to the right.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value WebEngineView.AlignJustified
+ Stretches the lines containing the selection or the cursor so that each
+ line has equal width.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value WebEngineView.Indent
+ Indents the lines containing the selection or the cursor.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value WebEngineView.Outdent
+ Outdents the lines containing the selection or the cursor.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+
+ \value WebEngineView.InsertOrderedList
+ Inserts an ordered list at the current cursor position, deleting the current selection.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value WebEngineView.InsertUnorderedList
+ Inserts an unordered list at the current cursor position,
+ deleting the current selection.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
\omitvalue WebActionCount
*/
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 8908af3c4..691a3f238 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -60,6 +60,7 @@
#include "render_widget_host_view_qt_delegate_widget.h"
#include "web_contents_adapter.h"
#include "web_engine_settings.h"
+#include "qwebenginescript.h"
#ifdef QT_UI_DELEGATES
#include "ui/messagebubblewidget_p.h"
@@ -1132,6 +1133,42 @@ QAction *QWebEnginePage::action(WebAction action) const
case ViewSource:
text = tr("&View Page Source");
break;
+ case ToggleBold:
+ text = tr("&Bold");
+ break;
+ case ToggleItalic:
+ text = tr("&Italic");
+ break;
+ case ToggleUnderline:
+ text = tr("&Underline");
+ break;
+ case ToggleStrikethrough:
+ text = tr("&Strikethrough");
+ break;
+ case AlignLeft:
+ text = tr("Align &Left");
+ break;
+ case AlignCenter:
+ text = tr("Align &Center");
+ break;
+ case AlignRight:
+ text = tr("Align &Right");
+ break;
+ case AlignJustified:
+ text = tr("Align &Justified");
+ break;
+ case Indent:
+ text = tr("&Indent");
+ break;
+ case Outdent:
+ text = tr("&Outdent");
+ break;
+ case InsertOrderedList:
+ text = tr("Insert &Ordered List");
+ break;
+ case InsertUnorderedList:
+ text = tr("Insert &Unordered List");
+ break;
case NoWebAction:
case WebActionCount:
Q_UNREACHABLE();
@@ -1333,6 +1370,42 @@ void QWebEnginePage::triggerAction(WebAction action, bool)
// the viewSource() call after the QMenu's destruction.
QTimer::singleShot(0, this, [d](){ d->adapter->viewSource(); });
break;
+ case ToggleBold:
+ runJavaScript("document.execCommand('bold');", QWebEngineScript::ApplicationWorld);
+ break;
+ case ToggleItalic:
+ runJavaScript("document.execCommand('italic');", QWebEngineScript::ApplicationWorld);
+ break;
+ case ToggleUnderline:
+ runJavaScript("document.execCommand('underline');", QWebEngineScript::ApplicationWorld);
+ break;
+ case ToggleStrikethrough:
+ runJavaScript("document.execCommand('strikethrough');", QWebEngineScript::ApplicationWorld);
+ break;
+ case AlignLeft:
+ runJavaScript("document.execCommand('justifyLeft');", QWebEngineScript::ApplicationWorld);
+ break;
+ case AlignCenter:
+ runJavaScript("document.execCommand('justifyCenter');", QWebEngineScript::ApplicationWorld);
+ break;
+ case AlignRight:
+ runJavaScript("document.execCommand('justifyRight');", QWebEngineScript::ApplicationWorld);
+ break;
+ case AlignJustified:
+ runJavaScript("document.execCommand('justifyFull');", QWebEngineScript::ApplicationWorld);
+ break;
+ case Indent:
+ runJavaScript("document.execCommand('indent');", QWebEngineScript::ApplicationWorld);
+ break;
+ case Outdent:
+ runJavaScript("document.execCommand('outdent');", QWebEngineScript::ApplicationWorld);
+ break;
+ case InsertOrderedList:
+ runJavaScript("document.execCommand('insertOrderedList');", QWebEngineScript::ApplicationWorld);
+ break;
+ case InsertUnorderedList:
+ runJavaScript("document.execCommand('insertUnorderedList');", QWebEngineScript::ApplicationWorld);
+ break;
case NoWebAction:
break;
case WebActionCount:
diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
index c7d5a19e3..37a59e88c 100644
--- a/src/webenginewidgets/api/qwebenginepage.h
+++ b/src/webenginewidgets/api/qwebenginepage.h
@@ -132,6 +132,22 @@ public:
SavePage,
OpenLinkInNewBackgroundTab,
ViewSource,
+
+ ToggleBold,
+ ToggleItalic,
+ ToggleUnderline,
+ ToggleStrikethrough,
+
+ AlignLeft,
+ AlignCenter,
+ AlignRight,
+ AlignJustified,
+ Indent,
+ Outdent,
+
+ InsertOrderedList,
+ InsertUnorderedList,
+
WebActionCount
};
Q_ENUM(WebAction)
diff --git a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
index 7616ebcee..8b4fb3823 100644
--- a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
@@ -158,6 +158,46 @@
the web page on disk. (Added in Qt 5.7)
\value ViewSource Show the source of the current page in a new tab. (Added in Qt 5.8)
+ \value ToggleBold
+ Toggles boldness for the selection or at the cursor position.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value ToggleItalic
+ Toggles italics for the selection or at the cursor position.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value ToggleUnderline
+ Toggles underlining of the selection or at the cursor position.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value ToggleStrikethrough
+ Toggles striking through the selection or at the cursor position.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+
+ \value AlignLeft
+ Aligns the lines containing the selection or the cursor to the left.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value AlignCenter
+ Aligns the lines containing the selection or the cursor at the center.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value AlignRight
+ Aligns the lines containing the selection or the cursor to the right.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value AlignJustified
+ Stretches the lines containing the selection or the cursor so that each
+ line has equal width.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value Indent
+ Indents the lines containing the selection or the cursor.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value Outdent
+ Outdents the lines containing the selection or the cursor.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+
+ \value InsertOrderedList
+ Inserts an ordered list at the current cursor position, deleting the current selection.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
+ \value InsertUnorderedList
+ Inserts an unordered list at the current cursor position,
+ deleting the current selection.
+ Requires \c contenteditable="true". (Added in Qt 5.10)
\omitvalue WebActionCount
*/