summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtWebKitChatView.cpp')
-rw-r--r--Swift/QtUI/QtWebKitChatView.cpp51
1 files changed, 29 insertions, 22 deletions
diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
index 46e8763..aec8589 100644
--- a/Swift/QtUI/QtWebKitChatView.cpp
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -84,7 +84,6 @@ QtWebKitChatView::QtWebKitChatView(QtChatWindow* window, UIEventStream* eventStr
}
webView_->setPage(webPage_);
connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard()));
- connect(webPage_, SIGNAL(scrollRequested(int, int, const QRect&)), SLOT(handleScrollRequested(int, int, const QRect&)));
viewReady_ = false;
isAtBottom_ = true;
@@ -93,7 +92,7 @@ QtWebKitChatView::QtWebKitChatView(QtChatWindow* window, UIEventStream* eventStr
jsBridge = new QtChatWindowJSBridge();
addToJSEnvironment("chatwindow", jsBridge);
connect(jsBridge, SIGNAL(buttonClicked(QString,QString,QString,QString,QString,QString)), this, SLOT(handleHTMLButtonClicked(QString,QString,QString,QString,QString,QString)));
-
+ connect(jsBridge, SIGNAL(verticalScrollBarPositionChanged(double)), this, SLOT(handleVerticalScrollBarPositionChanged(double)));
}
QtWebKitChatView::~QtWebKitChatView() {
@@ -253,7 +252,9 @@ void QtWebKitChatView::displayReceiptInfo(const QString& id, bool showIt) {
}
void QtWebKitChatView::rememberScrolledToBottom() {
- isAtBottom_ = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) >= (webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical) - 1);
+ if (webPage_) {
+ isAtBottom_ = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) >= (webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical) - 1);
+ }
}
void QtWebKitChatView::scrollToBottom() {
@@ -339,6 +340,11 @@ void QtWebKitChatView::resetView() {
scrollToBottom();
connect(webPage_->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)), this, SLOT(handleFrameSizeChanged()), Qt::UniqueConnection);
+
+ // Hooking up to scroll bar update, because Qt does not provide a way to retrieve accurate scroll bar updates from C++ directly.
+ QWebElement body = document_.findFirst("body");
+ assert(!body.isNull());
+ body.setAttribute("onscroll", "chatwindow.verticalScrollBarPositionChanged(document.body.scrollTop / (document.body.scrollHeight - window.innerHeight))");
}
static QWebElement findElementWithID(QWebElement document, QString elementName, QString id) {
@@ -446,20 +452,6 @@ void QtWebKitChatView::askDesktopToOpenFile(const QString& filename) {
}
}
-void QtWebKitChatView::handleScrollRequested(int, int dy, const QRect&) {
- rememberScrolledToBottom();
-
- int pos = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) - dy;
- emit scrollRequested(pos);
-
- if (pos == 0) {
- emit scrollReachedTop();
- }
- else if (pos == webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical)) {
- emit scrollReachedBottom();
- }
-}
-
int QtWebKitChatView::getSnippetPositionByDate(const QDate& date) {
QWebElement message = webPage_->mainFrame()->documentElement().findFirst(".date" + date.toString(Qt::ISODate));
@@ -590,6 +582,16 @@ QString QtWebKitChatView::buildChatWindowButton(const QString& name, const QStri
return html;
}
+void QtWebKitChatView::resizeEvent(QResizeEvent* event) {
+ // This code ensures that if the user is scrolled all to the bottom of a chat view,
+ // the view stays scrolled to the bottom if the view is resized or if the message
+ // input widget becomes multi line.
+ if (isAtBottom_) {
+ scrollToBottom();
+ }
+ QWidget::resizeEvent(event);
+}
+
std::string QtWebKitChatView::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) {
SWIFT_LOG(debug) << "addFileTransfer" << std::endl;
QString ft_id = QString("ft%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
@@ -788,6 +790,16 @@ void QtWebKitChatView::handleHTMLButtonClicked(QString id, QString encodedArgume
}
}
+void QtWebKitChatView::handleVerticalScrollBarPositionChanged(double position) {
+ rememberScrolledToBottom();
+ if (position == 0) {
+ emit scrollReachedTop();
+ }
+ else if (position == 1) {
+ emit scrollReachedBottom();
+ }
+}
+
void QtWebKitChatView::addErrorMessage(const ChatWindow::ChatMessage& errorMessage) {
if (window_->isWidgetSelected()) {
window_->onAllMessagesRead();
@@ -968,9 +980,4 @@ ChatSnippet::Direction QtWebKitChatView::getActualDirection(const ChatWindow::Ch
}
}
-// void QtWebKitChatView::setShowEmoticons(bool value) {
-// showEmoticons_ = value;
-// }
-
-
}