diff options
Diffstat (limited to 'WebCore/platform/qt')
37 files changed, 1802 insertions, 2045 deletions
diff --git a/WebCore/platform/qt/ClipboardQt.cpp b/WebCore/platform/qt/ClipboardQt.cpp index f7c420f..b0a1402 100644 --- a/WebCore/platform/qt/ClipboardQt.cpp +++ b/WebCore/platform/qt/ClipboardQt.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 2007 Apple Inc. All rights reserved. * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. - * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,7 +30,6 @@ #include "CachedImage.h" #include "CSSHelper.h" -#include "DeprecatedString.h" #include "Document.h" #include "Element.h" #include "Frame.h" @@ -70,10 +69,12 @@ ClipboardQt::ClipboardQt(ClipboardAccessPolicy policy, bool forDragging) { Q_ASSERT(policy == ClipboardReadable || policy == ClipboardWritable || policy == ClipboardNumb); +#ifndef QT_NO_CLIPBOARD if (policy != ClipboardWritable) { Q_ASSERT(!forDragging); m_readableData = QApplication::clipboard()->mimeData(); } +#endif } ClipboardQt::~ClipboardQt() @@ -112,8 +113,10 @@ void ClipboardQt::clearData(const String& type) m_writableData = 0; } } +#ifndef QT_NO_CLIPBOARD if (!isForDragging()) QApplication::clipboard()->setMimeData(m_writableData); +#endif } void ClipboardQt::clearAllData() @@ -121,9 +124,11 @@ void ClipboardQt::clearAllData() if (policy() != ClipboardWritable) return; +#ifndef QT_NO_CLIPBOARD if (!isForDragging()) QApplication::clipboard()->setMimeData(0); else +#endif delete m_writableData; m_writableData = 0; } @@ -152,8 +157,10 @@ bool ClipboardQt::setData(const String& type, const String& data) QByteArray array(reinterpret_cast<const char*>(data.characters()), data.length()*2); m_writableData->setData(QString(type), array); +#ifndef QT_NO_CLIPBOARD if (!isForDragging()) QApplication::clipboard()->setMimeData(m_writableData); +#endif return true; } @@ -187,10 +194,10 @@ void ClipboardQt::setDragImage(CachedImage* image, Node *node, const IntPoint &l return; if (m_dragImage) - m_dragImage->deref(this); + m_dragImage->removeClient(this); m_dragImage = image; if (m_dragImage) - m_dragImage->ref(this); + m_dragImage->addClient(this); m_dragLoc = loc; m_dragImageElement = node; @@ -201,7 +208,7 @@ DragImageRef ClipboardQt::createDragImage(IntPoint& dragLoc) const if (!m_dragImage) return 0; dragLoc = m_dragLoc; - return m_dragImage->image()->getPixmap(); + return m_dragImage->image()->nativeImageForCurrentFrame(); } @@ -233,7 +240,7 @@ void ClipboardQt::declareAndWriteDragImage(Element* element, const KURL& url, co CachedImage* cachedImage = getCachedImage(element); if (!cachedImage || !cachedImage->image() || !cachedImage->isLoaded()) return; - QPixmap *pixmap = cachedImage->image()->getPixmap(); + QPixmap *pixmap = cachedImage->image()->nativeImageForCurrentFrame(); if (pixmap) m_writableData->setImageData(pixmap); @@ -241,16 +248,18 @@ void ClipboardQt::declareAndWriteDragImage(Element* element, const KURL& url, co if (imageURL.isEmpty()) return; - String fullURL = frame->document()->completeURL(parseURL(imageURL)); + KURL fullURL = frame->document()->completeURL(parseURL(imageURL)); if (fullURL.isEmpty()) return; QList<QUrl> urls; - urls.append(QUrl(fullURL)); + urls.append(fullURL); m_writableData->setUrls(urls); +#ifndef QT_NO_CLIPBOARD if (!isForDragging()) QApplication::clipboard()->setMimeData(m_writableData); +#endif } void ClipboardQt::writeURL(const KURL& url, const String&, Frame* frame) @@ -258,12 +267,14 @@ void ClipboardQt::writeURL(const KURL& url, const String&, Frame* frame) ASSERT(frame); QList<QUrl> urls; - urls.append(QUrl(frame->document()->completeURL(url.deprecatedString()))); + urls.append(frame->document()->completeURL(url.string())); if (!m_writableData) m_writableData = new QMimeData; m_writableData->setUrls(urls); +#ifndef QT_NO_CLIPBOARD if (!isForDragging()) QApplication::clipboard()->setMimeData(m_writableData); +#endif } void ClipboardQt::writeRange(Range* range, Frame* frame) @@ -277,8 +288,10 @@ void ClipboardQt::writeRange(Range* range, Frame* frame) text.replace(QChar(0xa0), QLatin1Char(' ')); m_writableData->setText(text); m_writableData->setHtml(createMarkup(range, 0, AnnotateForInterchange)); +#ifndef QT_NO_CLIPBOARD if (!isForDragging()) QApplication::clipboard()->setMimeData(m_writableData); +#endif } bool ClipboardQt::hasData() diff --git a/WebCore/platform/qt/ClipboardQt.h b/WebCore/platform/qt/ClipboardQt.h index 6e54bcd..caf040f 100644 --- a/WebCore/platform/qt/ClipboardQt.h +++ b/WebCore/platform/qt/ClipboardQt.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,9 +28,10 @@ #include "Clipboard.h" #include "CachedResourceClient.h" -#include "ClipboardAccessPolicy.h" +QT_BEGIN_NAMESPACE class QMimeData; +QT_END_NAMESPACE namespace WebCore { @@ -39,11 +40,15 @@ namespace WebCore { // State available during IE's events for drag and drop and copy/paste class ClipboardQt : public Clipboard, public CachedResourceClient { public: - ClipboardQt(ClipboardAccessPolicy policy, const QMimeData* readableClipboard); - - // Clipboard is writable so it will create its own QMimeData object - ClipboardQt(ClipboardAccessPolicy policy, bool forDragging = false); - ~ClipboardQt(); + static PassRefPtr<ClipboardQt> create(ClipboardAccessPolicy policy, const QMimeData* readableClipboard) + { + return adoptRef(new ClipboardQt(policy, readableClipboard)); + } + static PassRefPtr<ClipboardQt> create(ClipboardAccessPolicy policy, bool forDragging = false) + { + return adoptRef(new ClipboardQt(policy, forDragging)); + } + virtual ~ClipboardQt(); void clearData(const String& type); void clearAllData(); @@ -67,7 +72,12 @@ namespace WebCore { void invalidateWritableData() { m_writableData = 0; } private: - void setDragImage(CachedImage* image, Node *node, const IntPoint &loc); + ClipboardQt(ClipboardAccessPolicy, const QMimeData* readableClipboard); + + // Clipboard is writable so it will create its own QMimeData object + ClipboardQt(ClipboardAccessPolicy, bool forDragging); + + void setDragImage(CachedImage*, Node*, const IntPoint& loc); const QMimeData* m_readableData; QMimeData* m_writableData; diff --git a/WebCore/platform/qt/CookieJarQt.cpp b/WebCore/platform/qt/CookieJarQt.cpp index 4138ab7..43be75a 100644 --- a/WebCore/platform/qt/CookieJarQt.cpp +++ b/WebCore/platform/qt/CookieJarQt.cpp @@ -28,7 +28,6 @@ #include "config.h" #include "CookieJar.h" -#include "DeprecatedString.h" #include "KURL.h" #include "PlatformString.h" @@ -92,7 +91,8 @@ String cookies(const Document* document, const KURL& url) QStringList resultCookies; foreach (QNetworkCookie networkCookie, cookies) - resultCookies.append(networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly)); + resultCookies.append(QString::fromAscii( + networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData())); return resultCookies.join(QLatin1String("; ")); #else diff --git a/WebCore/platform/qt/CursorQt.cpp b/WebCore/platform/qt/CursorQt.cpp index 6d05397..0d7e100 100644 --- a/WebCore/platform/qt/CursorQt.cpp +++ b/WebCore/platform/qt/CursorQt.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> * Copyright (C) 2006 George Staikos <staikos@kde.org> * Copyright (C) 2006 Charles Samuels <charles@kde.org> + * Copyright (C) 2008 Holger Hans Peter Freyther * * All rights reserved. * @@ -33,12 +34,13 @@ #include "Image.h" #include "IntPoint.h" -#include "DeprecatedString.h" #include "NotImplemented.h" #include <stdio.h> #include <stdlib.h> +#undef CopyCursor + namespace WebCore { Cursor::Cursor(PlatformCursor p) @@ -57,7 +59,7 @@ Cursor::~Cursor() Cursor::Cursor(Image* image, const IntPoint& hotspot) #ifndef QT_NO_CURSOR - : m_impl(*(image->getPixmap()), hotspot.x(), hotspot.y()) + : m_impl(*(image->nativeImageForCurrentFrame()), hotspot.x(), hotspot.y()) #endif { } @@ -75,20 +77,30 @@ class Cursors { protected: Cursors() #ifndef QT_NO_CURSOR - : CrossCursor(QCursor(Qt::CrossCursor)) - , MoveCursor(QCursor(Qt::SizeAllCursor)) - , PointerCursor(QCursor(Qt::ArrowCursor)) - , PointingHandCursor(QCursor(Qt::PointingHandCursor)) - , IBeamCursor(QCursor(Qt::IBeamCursor)) - , WaitCursor(QCursor(Qt::WaitCursor)) - , WhatsThisCursor(QCursor(Qt::WhatsThisCursor)) - , SizeHorCursor(QCursor(Qt::SizeHorCursor)) - , SizeVerCursor(QCursor(Qt::SizeVerCursor)) - , SizeFDiagCursor(QCursor(Qt::SizeFDiagCursor)) - , SizeBDiagCursor(QCursor(Qt::SizeBDiagCursor)) - , SplitHCursor(QCursor(Qt::SplitHCursor)) - , SplitVCursor(QCursor(Qt::SplitVCursor)) - , BlankCursor(QCursor(Qt::BlankCursor)) + : CrossCursor(Qt::CrossCursor) + , MoveCursor(Qt::SizeAllCursor) + , PointerCursor(Qt::ArrowCursor) + , PointingHandCursor(Qt::PointingHandCursor) + , IBeamCursor(Qt::IBeamCursor) + , WaitCursor(Qt::WaitCursor) + , WhatsThisCursor(Qt::WhatsThisCursor) + , SizeHorCursor(Qt::SizeHorCursor) + , SizeVerCursor(Qt::SizeVerCursor) + , SizeFDiagCursor(Qt::SizeFDiagCursor) + , SizeBDiagCursor(Qt::SizeBDiagCursor) + , SplitHCursor(Qt::SplitHCursor) + , SplitVCursor(Qt::SplitVCursor) + , NoDropCursor(Qt::ForbiddenCursor) + , BlankCursor(Qt::BlankCursor) + , ZoomInCursor(QPixmap(QLatin1String(":/webkit/resources/zoomInCursor.png"))) + , ZoomOutCursor(QPixmap(QLatin1String(":/webkit/resources/zoomOutCursor.png"))) + , VerticalTextCursor(QPixmap(QLatin1String(":/webkit/resources/verticalTextCursor.png"))) + , CellCursor(QPixmap(QLatin1String(":/webkit/resources/cellCursor.png"))) + , ContextMenuCursor(QPixmap(QLatin1String(":/webkit/resources/contextMenuCursor.png"))) + , CopyCursor(QPixmap(QLatin1String(":/webkit/resources/copyCursor.png"))) + , ProgressCursor(QPixmap(QLatin1String(":/webkit/resources/progressCursor.png"))) + , AliasCursor(QPixmap(QLatin1String(":/webkit/resources/aliasCursor.png"))) + #endif { } @@ -114,7 +126,16 @@ public: Cursor SizeBDiagCursor; Cursor SplitHCursor; Cursor SplitVCursor; + Cursor NoDropCursor; Cursor BlankCursor; + Cursor ZoomInCursor; + Cursor ZoomOutCursor; + Cursor VerticalTextCursor; + Cursor CellCursor; + Cursor ContextMenuCursor; + Cursor CopyCursor; + Cursor ProgressCursor; + Cursor AliasCursor; }; Cursors* Cursors::s_self = 0; @@ -233,40 +254,85 @@ const Cursor& rowResizeCursor() { return Cursors::self()->SplitVCursor; } + +const Cursor& middlePanningCursor() +{ + return moveCursor(); +} + +const Cursor& eastPanningCursor() +{ + return eastResizeCursor(); +} + +const Cursor& northPanningCursor() +{ + return northResizeCursor(); +} + +const Cursor& northEastPanningCursor() +{ + return northEastResizeCursor(); +} + +const Cursor& northWestPanningCursor() +{ + return northWestResizeCursor(); +} + +const Cursor& southPanningCursor() +{ + return southResizeCursor(); +} + +const Cursor& southEastPanningCursor() +{ + return southEastResizeCursor(); +} + +const Cursor& southWestPanningCursor() +{ + return southWestResizeCursor(); +} + +const Cursor& westPanningCursor() +{ + return westResizeCursor(); +} const Cursor& verticalTextCursor() { - return Cursors::self()->PointerCursor; + return Cursors::self()->VerticalTextCursor; } const Cursor& cellCursor() { - return Cursors::self()->PointerCursor; + return Cursors::self()->CellCursor; } const Cursor& contextMenuCursor() { - return Cursors::self()->PointerCursor; + return Cursors::self()->ContextMenuCursor; } const Cursor& noDropCursor() { - return Cursors::self()->PointerCursor; + return Cursors::self()->NoDropCursor; } const Cursor& copyCursor() { - return Cursors::self()->PointerCursor; + return Cursors::self()->CopyCursor; } const Cursor& progressCursor() { - return Cursors::self()->PointerCursor; + return Cursors::self()->ProgressCursor; } const Cursor& aliasCursor() { - return Cursors::self()->PointerCursor; + return Cursors::self()->AliasCursor; } const Cursor& noneCursor() @@ -276,17 +342,28 @@ const Cursor& noneCursor() const Cursor& notAllowedCursor() { - // FIXME: Build fix -- what is correct here? - return Cursors::self()->BlankCursor; + return Cursors::self()->NoDropCursor; } const Cursor& zoomInCursor() { - return Cursors::self()->PointerCursor; + return Cursors::self()->ZoomInCursor; } const Cursor& zoomOutCursor() { + return Cursors::self()->ZoomOutCursor; +} + +const Cursor& grabCursor() +{ + notImplemented(); + return Cursors::self()->PointerCursor; +} + +const Cursor& grabbingCursor() +{ + notImplemented(); return Cursors::self()->PointerCursor; } diff --git a/WebCore/platform/qt/DragDataQt.cpp b/WebCore/platform/qt/DragDataQt.cpp index 5e79801..9d95373 100644 --- a/WebCore/platform/qt/DragDataQt.cpp +++ b/WebCore/platform/qt/DragDataQt.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -102,9 +102,9 @@ Color DragData::asColor() const return qvariant_cast<QColor>(m_platformDragData->colorData()); } -Clipboard* DragData::createClipboard(ClipboardAccessPolicy policy) const +PassRefPtr<Clipboard> DragData::createClipboard(ClipboardAccessPolicy policy) const { - return new ClipboardQt(policy, m_platformDragData); + return ClipboardQt::create(policy, m_platformDragData); } bool DragData::containsCompatibleContent() const diff --git a/WebCore/platform/qt/EventLoopQt.cpp b/WebCore/platform/qt/EventLoopQt.cpp new file mode 100644 index 0000000..39bb54c --- /dev/null +++ b/WebCore/platform/qt/EventLoopQt.cpp @@ -0,0 +1,32 @@ +/* + Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" +#include "EventLoop.h" + +#include <QCoreApplication> + +namespace WebCore { + +void EventLoop::cycle() +{ + QCoreApplication::processEvents(); +} + +} // namespace WebCore diff --git a/WebCore/platform/qt/FileChooserQt.cpp b/WebCore/platform/qt/FileChooserQt.cpp index c19301f..b468dbe 100644 --- a/WebCore/platform/qt/FileChooserQt.cpp +++ b/WebCore/platform/qt/FileChooserQt.cpp @@ -21,47 +21,15 @@ #include "config.h" #include "FileChooser.h" -#include "Document.h" -#include "Frame.h" -#include "FrameLoaderClientQt.h" -#include "Icon.h" -#include "Page.h" - +#include "Font.h" #include <QFontMetrics> namespace WebCore { -FileChooser::FileChooser(FileChooserClient* client, const String& filename) - : m_client(client) - , m_filename(filename) - , m_icon(chooseIcon(filename)) -{ -} - -FileChooser::~FileChooser() -{ -} - -void FileChooser::openFileChooser(Document* doc) -{ - Page *page = doc->page(); - Frame *frame = doc->frame(); - if (!page || !frame) - return; - - FrameLoaderClientQt *fl = static_cast<FrameLoaderClientQt*>(frame->loader()->client()); - if (!fl) - return; - - QString f = fl->chooseFile(m_filename); - if (!f.isEmpty()) - chooseFile(f); -} - String FileChooser::basenameForWidth(const Font& f, int width) const { QFontMetrics fm(f.font()); - return fm.elidedText(m_filename, Qt::ElideLeft, width); + return fm.elidedText(m_filenames[0], Qt::ElideLeft, width); } } diff --git a/WebCore/platform/qt/FileSystemQt.cpp b/WebCore/platform/qt/FileSystemQt.cpp index 7a25591..6b56070 100644 --- a/WebCore/platform/qt/FileSystemQt.cpp +++ b/WebCore/platform/qt/FileSystemQt.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2007 Staikos Computing Services Inc. * Copyright (C) 2007 Holger Hans Peter Freyther * Copyright (C) 2008 Apple, Inc. All rights reserved. + * Copyright (C) 2008 Collabora, Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,10 +29,18 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" +#include "FileSystem.h" + +#include "CString.h" #include "NotImplemented.h" #include "PlatformString.h" + +#include <QDateTime> #include <QFile> +#include <QTemporaryFile> #include <QFileInfo> +#include <QDateTime> #include <QDir> namespace WebCore { @@ -59,10 +68,11 @@ bool getFileSize(const String& path, long long& result) return info.exists(); } -bool getFileModificationTime(const String&, time_t&) +bool getFileModificationTime(const String& path, time_t& result) { - notImplemented(); - return false; + QFileInfo info(path); + result = info.lastModified().toTime_t(); + return info.exists(); } bool makeAllDirectories(const String& path) @@ -75,6 +85,91 @@ String pathByAppendingComponent(const String& path, const String& component) return QDir(path).filePath(component); } +String homeDirectoryPath() +{ + return QDir::homePath(); +} + +String pathGetFileName(const String& path) +{ + return QFileInfo(path).fileName(); +} + +String directoryName(const String& path) +{ + return String(QFileInfo(path).baseName()); +} + +Vector<String> listDirectory(const String& path, const String& filter) +{ + Vector<String> entries; + + QStringList nameFilters; + if (!filter.isEmpty()) + nameFilters.append(filter); + QFileInfoList fileInfoList = QDir(path).entryInfoList(nameFilters, QDir::AllEntries | QDir::NoDotAndDotDot); + foreach (const QFileInfo fileInfo, fileInfoList) { + String entry = String(fileInfo.canonicalFilePath()); + entries.append(entry); + } + + return entries; +} + +CString openTemporaryFile(const char* prefix, PlatformFileHandle& handle) +{ + QFile *temp = new QTemporaryFile(QString(prefix)); + if (temp->open(QIODevice::ReadWrite)) { + handle = temp; + return String(temp->fileName()).utf8(); + } + handle = invalidPlatformFileHandle; + return 0; +} + +void closeFile(PlatformFileHandle& handle) +{ + if (handle) { + handle->close(); + delete handle; + } +} + +int writeToFile(PlatformFileHandle handle, const char* data, int length) +{ + if (handle && handle->exists() && handle->isWritable()) + return handle->write(data, length); + + return 0; +} + +#if defined(Q_WS_X11) || defined(Q_WS_QWS) +bool unloadModule(PlatformModule module) +{ + if (module->unload()) { + delete module; + return true; + } + + return false; +} +#endif + +#if defined(Q_WS_MAC) +bool unloadModule(PlatformModule module) +{ + CFRelease(module); + return true; +} +#endif + +#if defined(Q_OS_WIN32) +bool unloadModule(PlatformModule module) +{ + return ::FreeLibrary(module); +} +#endif + } // vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/KURLQt.cpp b/WebCore/platform/qt/KURLQt.cpp index ce0d53d..cdc4f48 100644 --- a/WebCore/platform/qt/KURLQt.cpp +++ b/WebCore/platform/qt/KURLQt.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,17 +19,20 @@ */ #include "config.h" #include "KURL.h" +#include "CString.h" #include "NotImplemented.h" #include "qurl.h" namespace WebCore { +#if QT_VERSION < 0x040500 static const char hexnumbers[] = "0123456789ABCDEF"; static inline char toHex(char c) { return hexnumbers[c & 0xf]; } +#endif KURL::KURL(const QUrl& url) { @@ -38,30 +41,52 @@ KURL::KURL(const QUrl& url) KURL::operator QUrl() const { +#if QT_VERSION < 0x040500 + unsigned length = m_string.length(); + QByteArray ba; - ba.reserve(urlString.length()); + ba.reserve(length); + + int path = -1; + int host = m_string.find("://"); + if (host != -1) { + host += 3; + + path = m_string.find('/', host); + } - for (const char *src = urlString.ascii(); *src; ++src) { - const char chr = *src; + for (unsigned i = 0; i < length; ++i) { + const char chr = static_cast<char>(m_string[i]); switch (chr) { + encode: case '{': case '}': case '|': case '\\': case '^': - case '[': - case ']': case '`': ba.append('%'); ba.append(toHex((chr & 0xf0) >> 4)); ba.append(toHex(chr & 0xf)); break; + case '[': + case ']': + // special case: if this is the host part, don't encode + // otherwise, encode + if (host == -1 || (path != -1 && i >= path)) + goto encode; + // fall through default: ba.append(chr); break; } } +#else + // Qt 4.5 or later + // No need for special encoding + QByteArray ba = m_string.utf8().data(); +#endif QUrl url = QUrl::fromEncoded(ba); return url; diff --git a/WebCore/platform/qt/KeyboardCodes.h b/WebCore/platform/qt/KeyboardCodes.h index 86ee48c..21d3c67 100644 --- a/WebCore/platform/qt/KeyboardCodes.h +++ b/WebCore/platform/qt/KeyboardCodes.h @@ -28,8 +28,11 @@ #ifndef KeyboardCodes_h #define KeyboardCodes_h +#include <wtf/Platform.h> + namespace WebCore { +#if !PLATFORM(WIN_OS) // VK_LBUTTON (01) Left mouse button // VK_RBUTTON (02) Right mouse button // VK_CANCEL (03) Control-break processing @@ -146,6 +149,8 @@ const int VK_DELETE = 0x2E; // VK_HELP (2F) HELP key const int VK_HELP = 0x2F; +#endif // PLATFORM(WIN_OS) + // (30) 0 key const int VK_0 = 0x30; @@ -255,6 +260,8 @@ const int VK_Y = 0x59; // (5A) Z key const int VK_Z = 0x5A; +#if !PLATFORM(WIN_OS) + // VK_LWIN (5B) Left Windows key (Microsoft Natural keyboard) const int VK_LWIN = 0x5B; @@ -539,6 +546,8 @@ const int VK_OEM_CLEAR = 0xFE; const int VK_UNKNOWN = 0; +#endif // PLATFORM(WIN_OS) + } #endif diff --git a/WebCore/platform/qt/Localizations.cpp b/WebCore/platform/qt/Localizations.cpp index 67bba22..b49b880 100644 --- a/WebCore/platform/qt/Localizations.cpp +++ b/WebCore/platform/qt/Localizations.cpp @@ -28,9 +28,10 @@ #include "config.h" -#include "PlatformString.h" +#include "IntSize.h" #include "LocalizedStrings.h" #include "NotImplemented.h" +#include "PlatformString.h" #include <QCoreApplication> @@ -58,7 +59,7 @@ String defaultLanguage() String searchableIndexIntroduction() { - return QCoreApplication::translate("QWebPage", "Searchable Index", "text that appears at the start of nearly-obsolete web pages in the form of a 'searchable index'"); + return QCoreApplication::translate("QWebPage", "This is a searchable index. Enter search keywords: ", "text that appears at the start of nearly-obsolete web pages in the form of a 'searchable index'"); } String fileButtonChooseFileLabel() @@ -292,10 +293,60 @@ String AXHeadingText() return String(); } +String AXDefinitionListTermText() +{ + return String(); +} + +String AXDefinitionListDefinitionText() +{ + return String(); +} + +String AXButtonActionVerb() +{ + return String(); +} + +String AXRadioButtonActionVerb() +{ + return String(); +} + +String AXTextFieldActionVerb() +{ + return String(); +} + +String AXCheckedCheckBoxActionVerb() +{ + return String(); +} + +String AXUncheckedCheckBoxActionVerb() +{ + return String(); +} + +String AXLinkActionVerb() +{ + return String(); +} + +String multipleFileUploadText(unsigned) +{ + return String(); +} + String unknownFileSizeText() { return QCoreApplication::translate("QWebPage", "Unknown", "Unknown filesize FTP directory listing item"); } +String imageTitle(const String& filename, const IntSize& size) +{ + return QCoreApplication::translate("QWebPage", "%1 (%2x%3 pixels)", "Title string for images").arg(filename).arg(size.width()).arg(size.height()); +} + } // vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/LoggingQt.cpp b/WebCore/platform/qt/LoggingQt.cpp new file mode 100644 index 0000000..5f6720a --- /dev/null +++ b/WebCore/platform/qt/LoggingQt.cpp @@ -0,0 +1,90 @@ +/* + Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" +#include "Logging.h" + +#include <QDebug> +#include <QStringList> + +namespace WebCore { + +#if !defined(NDEBUG) +static WTFLogChannel* getChannelFromName(const QString& channelName) +{ + if (!channelName.length() >= 2) + return 0; + + if (channelName == QLatin1String("BackForward")) return &LogBackForward; + if (channelName == QLatin1String("Editing")) return &LogEditing; + if (channelName == QLatin1String("Events")) return &LogEvents; + if (channelName == QLatin1String("Frames")) return &LogFrames; + if (channelName == QLatin1String("FTP")) return &LogFTP; + if (channelName == QLatin1String("History")) return &LogHistory; + if (channelName == QLatin1String("IconDatabase")) return &LogIconDatabase; + if (channelName == QLatin1String("Loading")) return &LogLoading; + if (channelName == QLatin1String("Media")) return &LogMedia; + if (channelName == QLatin1String("Network")) return &LogNetwork; + if (channelName == QLatin1String("NotYetImplemented")) return &LogNotYetImplemented; + if (channelName == QLatin1String("PageCache")) return &LogPageCache; + if (channelName == QLatin1String("PlatformLeaks")) return &LogPlatformLeaks; + if (channelName == QLatin1String("Plugin")) return &LogPlugin; + if (channelName == QLatin1String("PopupBlocking")) return &LogPopupBlocking; + if (channelName == QLatin1String("SpellingAndGrammar")) return &LogSpellingAndGrammar; + if (channelName == QLatin1String("SQLDatabase")) return &LogSQLDatabase; + if (channelName == QLatin1String("StorageAPI")) return &LogStorageAPI; + if (channelName == QLatin1String("TextConversion")) return &LogTextConversion; + if (channelName == QLatin1String("Threading")) return &LogThreading; + + return 0; +} +#endif + +void InitializeLoggingChannelsIfNecessary() +{ + static bool haveInitializedLoggingChannels = false; + if (haveInitializedLoggingChannels) + return; + + haveInitializedLoggingChannels = true; + + QString loggingEnv = qgetenv("QT_WEBKIT_LOG"); + if (loggingEnv.isEmpty()) + return; + +#if defined(NDEBUG) + qWarning("This is a release build. Setting QT_WEBKIT_LOG will have no effect."); +#else + QStringList channels = loggingEnv.split(","); + QStringListIterator iter(channels); + + while (iter.hasNext()) { + QString channelName = iter.next(); + WTFLogChannel* channel = getChannelFromName(channelName); + if (!channel) continue; + channel->state = WTFLogChannelOn; + } + + // By default we log calls to notImplemented(). This can be turned + // off by setting the environment variable DISABLE_NI_WARNING to 1 + LogNotYetImplemented.state = WTFLogChannelOn; +#endif +} + +} // namespace WebCore diff --git a/WebCore/platform/qt/MIMETypeRegistryQt.cpp b/WebCore/platform/qt/MIMETypeRegistryQt.cpp index 6b3e243..9f4a786 100644 --- a/WebCore/platform/qt/MIMETypeRegistryQt.cpp +++ b/WebCore/platform/qt/MIMETypeRegistryQt.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 2006 Zack Rusin <zack@kde.org> * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,11 +28,6 @@ #include "config.h" #include "MIMETypeRegistry.h" -#include "NotImplemented.h" -#if QT_VERSION < 0x040400 -#include "qwebobjectplugin_p.h" -#endif - namespace WebCore { struct ExtensionMap { @@ -42,6 +37,7 @@ struct ExtensionMap { static const ExtensionMap extensionMap [] = { { "bmp", "image/bmp" }, + { "css", "text/css" }, { "gif", "image/gif" }, { "html", "text/html" }, { "htm", "text/html" }, @@ -79,12 +75,6 @@ String MIMETypeRegistry::getMIMETypeForExtension(const String &ext) return e->mimeType; ++e; } - // ### FIXME: Qt 4.4 -#if QT_VERSION < 0x040400 - QString type = QWebFactoryLoader::self()->mimeTypeForExtension(ext); - if (!type.isEmpty()) - return type; -#endif return "application/octet-stream"; } diff --git a/WebCore/platform/qt/PasteboardQt.cpp b/WebCore/platform/qt/PasteboardQt.cpp index 22806ea..b535a74 100644 --- a/WebCore/platform/qt/PasteboardQt.cpp +++ b/WebCore/platform/qt/PasteboardQt.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 2006 Zack Rusin <zack@kde.org> * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. - * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,6 +30,7 @@ #include "DocumentFragment.h" #include "Editor.h" +#include "Frame.h" #include "Image.h" #include "markup.h" #include "RenderImage.h" @@ -43,8 +44,9 @@ #define methodDebug() qDebug() << "PasteboardQt: " << __FUNCTION__; namespace WebCore { - -Pasteboard::Pasteboard() + +Pasteboard::Pasteboard() + : m_selectionMode(false) { } @@ -62,8 +64,16 @@ void Pasteboard::writeSelection(Range* selectedRange, bool, Frame* frame) QString text = frame->selectedText(); text.replace(QChar(0xa0), QLatin1Char(' ')); md->setText(text); - md->setHtml(createMarkup(selectedRange, 0, AnnotateForInterchange)); - QApplication::clipboard()->setMimeData(md); + + QString html = QLatin1String("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body>"); + html += createMarkup(selectedRange, 0, AnnotateForInterchange); + html += QLatin1String("</body></html>"); + md->setHtml(html); + +#ifndef QT_NO_CLIPBOARD + QApplication::clipboard()->setMimeData(md, m_selectionMode ? + QClipboard::Selection : QClipboard::Clipboard); +#endif } bool Pasteboard::canSmartReplace() @@ -73,13 +83,20 @@ bool Pasteboard::canSmartReplace() String Pasteboard::plainText(Frame*) { - return QApplication::clipboard()->text(); +#ifndef QT_NO_CLIPBOARD + return QApplication::clipboard()->text(m_selectionMode ? + QClipboard::Selection : QClipboard::Clipboard); +#else + return String(); +#endif } PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) { - const QMimeData* mimeData = QApplication::clipboard()->mimeData(); +#ifndef QT_NO_CLIPBOARD + const QMimeData* mimeData = QApplication::clipboard()->mimeData( + m_selectionMode ? QClipboard::Selection : QClipboard::Clipboard); chosePlainText = false; @@ -98,7 +115,7 @@ PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefP if (fragment) return fragment.release(); } - +#endif return 0; } @@ -106,32 +123,50 @@ void Pasteboard::writeURL(const KURL& _url, const String&, Frame*) { ASSERT(!_url.isEmpty()); +#ifndef QT_NO_CLIPBOARD QMimeData* md = new QMimeData; QString url = _url.string(); md->setText(url); md->setUrls(QList<QUrl>() << QUrl(url)); - QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard); + QApplication::clipboard()->setMimeData(md, m_selectionMode ? + QClipboard::Selection : QClipboard::Clipboard); +#endif } void Pasteboard::writeImage(Node* node, const KURL&, const String&) { ASSERT(node && node->renderer() && node->renderer()->isImage()); +#ifndef QT_NO_CLIPBOARD CachedImage* cachedImage = static_cast<RenderImage*>(node->renderer())->cachedImage(); ASSERT(cachedImage); Image* image = cachedImage->image(); ASSERT(image); - QPixmap* pixmap = image->getPixmap(); + QPixmap* pixmap = image->nativeImageForCurrentFrame(); ASSERT(pixmap); QApplication::clipboard()->setPixmap(*pixmap, QClipboard::Clipboard); +#endif } +/* This function is called from Editor::tryDHTMLCopy before actually set the clipboard + * It introduce a race condition with klipper, which will try to grab the clipboard + * It's not required to clear it anyway, since QClipboard take care about replacing the clipboard + */ void Pasteboard::clear() { - QApplication::clipboard()->clear(); +} + +bool Pasteboard::isSelectionMode() const +{ + return m_selectionMode; +} + +void Pasteboard::setSelectionMode(bool selectionMode) +{ + m_selectionMode = selectionMode; } } diff --git a/WebCore/platform/qt/PlatformKeyboardEventQt.cpp b/WebCore/platform/qt/PlatformKeyboardEventQt.cpp index 5a54d8a..76342ab 100644 --- a/WebCore/platform/qt/PlatformKeyboardEventQt.cpp +++ b/WebCore/platform/qt/PlatformKeyboardEventQt.cpp @@ -31,6 +31,8 @@ #include "KeyboardCodes.h" #include "NotImplemented.h" +#include <ctype.h> + #include <QKeyEvent> namespace WebCore { @@ -444,8 +446,10 @@ PlatformKeyboardEvent::PlatformKeyboardEvent(QKeyEvent* event) m_altKey = (state & Qt::AltModifier) != 0; m_metaKey = (state & Qt::MetaModifier) != 0; m_windowsVirtualKeyCode = windowsKeyCodeForKeyEvent(event->key()); + m_nativeVirtualKeyCode = event->nativeVirtualKey(); m_isKeypad = (state & Qt::KeypadModifier) != 0; m_shiftKey = (state & Qt::ShiftModifier) != 0 || event->key() == Qt::Key_Backtab; // Simulate Shift+Tab with Key_Backtab + m_qtEvent = event; } void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool) diff --git a/WebCore/platform/qt/PlatformMouseEventQt.cpp b/WebCore/platform/qt/PlatformMouseEventQt.cpp index ce7375b..afc7452 100644 --- a/WebCore/platform/qt/PlatformMouseEventQt.cpp +++ b/WebCore/platform/qt/PlatformMouseEventQt.cpp @@ -45,6 +45,7 @@ PlatformMouseEvent::PlatformMouseEvent(QInputEvent* event, int clickCount) m_eventType = MouseEventMoved; me = static_cast<QMouseEvent *>(event); break; + case QEvent::MouseButtonDblClick: case QEvent::MouseButtonPress: m_eventType = MouseEventPressed; me = static_cast<QMouseEvent *>(event); @@ -53,6 +54,7 @@ PlatformMouseEvent::PlatformMouseEvent(QInputEvent* event, int clickCount) m_eventType = MouseEventReleased; me = static_cast<QMouseEvent *>(event); break; +#ifndef QT_NO_CONTEXTMENU case QEvent::ContextMenu: { m_eventType = MouseEventPressed; QContextMenuEvent *ce = static_cast<QContextMenuEvent *>(event); @@ -61,6 +63,7 @@ PlatformMouseEvent::PlatformMouseEvent(QInputEvent* event, int clickCount) m_button = RightButton; break; } +#endif // QT_NO_CONTEXTMENU default: m_eventType = MouseEventMoved; } @@ -83,7 +86,7 @@ PlatformMouseEvent::PlatformMouseEvent(QInputEvent* event, int clickCount) m_shiftKey = (event->modifiers() & Qt::ShiftModifier) != 0; m_ctrlKey = (event->modifiers() & Qt::ControlModifier) != 0; m_altKey = (event->modifiers() & Qt::AltModifier) != 0; - m_metaKey = (event->modifiers() & Qt::MetaModifier) != 0; + m_metaKey = (event->modifiers() & Qt::MetaModifier) != 0; } } diff --git a/WebCore/platform/qt/PlatformScreenQt.cpp b/WebCore/platform/qt/PlatformScreenQt.cpp index 4792a51..5bc86d0 100644 --- a/WebCore/platform/qt/PlatformScreenQt.cpp +++ b/WebCore/platform/qt/PlatformScreenQt.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2007 Apple Inc. All rights reserved. - * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,6 +33,7 @@ #include "FloatRect.h" #include "Frame.h" #include "FrameView.h" +#include "HostWindow.h" #include "Widget.h" #include <QApplication> #include <QDesktopWidget> @@ -42,34 +43,34 @@ namespace WebCore { int screenDepth(Widget* w) { QDesktopWidget* d = QApplication::desktop(); - QWidget *view = w->containingWindow(); + QWidget *view = w->root()->hostWindow()->platformWindow(); int screenNumber = view ? d->screenNumber(view) : 0; return d->screen(screenNumber)->depth(); } int screenDepthPerComponent(Widget* w) { - QWidget *view = w->containingWindow(); + QWidget *view = w->root()->hostWindow()->platformWindow(); return view ? view->depth() : QApplication::desktop()->screen(0)->depth(); } bool screenIsMonochrome(Widget* w) { QDesktopWidget* d = QApplication::desktop(); - QWidget *view = w->containingWindow(); + QWidget *view = w->root()->hostWindow()->platformWindow(); int screenNumber = view ? d->screenNumber(view) : 0; return d->screen(screenNumber)->numColors() < 2; } FloatRect screenRect(Widget* w) { - QRect r = QApplication::desktop()->screenGeometry(w->containingWindow()); + QRect r = QApplication::desktop()->screenGeometry(w->root()->hostWindow()->platformWindow()); return FloatRect(r.x(), r.y(), r.width(), r.height()); } FloatRect screenAvailableRect(Widget* w) { - QRect r = QApplication::desktop()->availableGeometry(w->containingWindow()); + QRect r = QApplication::desktop()->availableGeometry(w->root()->hostWindow()->platformWindow()); return FloatRect(r.x(), r.y(), r.width(), r.height()); } diff --git a/WebCore/platform/qt/PlatformScrollBar.h b/WebCore/platform/qt/PlatformScrollBar.h deleted file mode 100644 index cc0037b..0000000 --- a/WebCore/platform/qt/PlatformScrollBar.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. - * Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net> - * Copyright (C) 2007 Trolltech ASA - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef PlatformScrollbar_h -#define PlatformScrollbar_h - -#include "Widget.h" -#include "ScrollBar.h" -#include "Timer.h" - -#include <QStyleOptionSlider> - -namespace WebCore { - -class PlatformScrollbar : public Widget, public Scrollbar { -public: - PlatformScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize); - virtual ~PlatformScrollbar(); - - virtual bool isWidget() const { return true; } - virtual int width() const; - virtual int height() const; - virtual void setRect(const IntRect&); - - virtual IntRect frameGeometry() const; - virtual void setFrameGeometry(const IntRect& r); - - virtual void setEnabled(bool); - virtual void paint(GraphicsContext*, const IntRect& damageRect); - - virtual bool handleMouseMoveEvent(const PlatformMouseEvent&); - virtual bool handleMouseOutEvent(const PlatformMouseEvent&); - virtual bool handleMousePressEvent(const PlatformMouseEvent&); - virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&); - - bool isEnabled() const; - - static int horizontalScrollbarHeight(ScrollbarControlSize size = RegularScrollbar); - static int verticalScrollbarWidth(ScrollbarControlSize size = RegularScrollbar); - - void autoscrollTimerFired(Timer<PlatformScrollbar>*); - void invalidate(); - -protected: - virtual void updateThumbPosition(); - virtual void updateThumbProportion(); - -private: - int thumbPosition() const; - int thumbLength() const; - int trackLength() const; - - void startTimerIfNeeded(double delay); - void stopTimerIfNeeded(); - void autoscrollPressedPart(double delay); - ScrollDirection pressedPartScrollDirection(); - ScrollGranularity pressedPartScrollGranularity(); - - bool thumbUnderMouse(); - - int m_pressedPos; - QStyle::SubControl m_pressedPart; - QStyle::SubControl m_hoveredPart; - Timer<PlatformScrollbar> m_scrollTimer; - QStyleOptionSlider m_opt; -}; - -} - -#endif // PlatformScrollbar_h - diff --git a/WebCore/platform/qt/PlatformScrollBarQt.cpp b/WebCore/platform/qt/PlatformScrollBarQt.cpp deleted file mode 100644 index 0839db8..0000000 --- a/WebCore/platform/qt/PlatformScrollBarQt.cpp +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Copyright (C) 2007 Apple Inc. All rights reserved. - * Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net> - * Copyright (C) 2007 Trolltech ASA - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#include "PlatformScrollBar.h" - -#include "EventHandler.h" -#include "FrameView.h" -#include "Frame.h" -#include "GraphicsContext.h" -#include "IntRect.h" -#include "PlatformMouseEvent.h" - -#include <QApplication> -#include <QDebug> -#include <QPainter> -#include <QStyle> - -using namespace std; - -namespace WebCore { - -const double cInitialTimerDelay = 0.25; -const double cNormalTimerDelay = 0.05; - -PlatformScrollbar::PlatformScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size) - : Scrollbar(client, orientation, size) - , m_pressedPos(0) - , m_pressedPart(QStyle::SC_None) - , m_hoveredPart(QStyle::SC_None) - , m_scrollTimer(this, &PlatformScrollbar::autoscrollTimerFired) -{ - QStyle *s = QApplication::style(); - - m_opt.state = QStyle::State_Active | QStyle::State_Enabled; - m_opt.sliderValue = m_opt.sliderPosition = 0; - m_opt.upsideDown = false; - setEnabled(true); - if (size != RegularScrollbar) - m_opt.state |= QStyle::State_Mini; - if (orientation == HorizontalScrollbar) { - m_opt.rect.setHeight(horizontalScrollbarHeight(size)); - m_opt.orientation = Qt::Horizontal; - m_opt.state |= QStyle::State_Horizontal; - } else { - m_opt.rect.setWidth(verticalScrollbarWidth(size)); - m_opt.orientation = Qt::Vertical; - m_opt.state &= ~QStyle::State_Horizontal; - } -} - -PlatformScrollbar::~PlatformScrollbar() -{ - stopTimerIfNeeded(); -} - -void PlatformScrollbar::updateThumbPosition() -{ - invalidate(); -} - -void PlatformScrollbar::updateThumbProportion() -{ - invalidate(); -} - -int PlatformScrollbar::width() const -{ - return m_opt.rect.width(); -} - -int PlatformScrollbar::height() const -{ - return m_opt.rect.height(); -} - -void PlatformScrollbar::setRect(const IntRect& rect) -{ - setFrameGeometry(rect); -} - -IntRect PlatformScrollbar::frameGeometry() const -{ - return m_opt.rect; -} - -void PlatformScrollbar::setFrameGeometry(const IntRect& rect) -{ - m_opt.rect = rect; -} - -bool PlatformScrollbar::isEnabled() const -{ - return m_opt.state & QStyle::State_Enabled; -} - -void PlatformScrollbar::setEnabled(bool enabled) -{ - if (enabled != isEnabled()) { - if (enabled) { - m_opt.state |= QStyle::State_Enabled; - } else { - m_opt.state &= ~QStyle::State_Enabled; - } - invalidate(); - } -} - -void PlatformScrollbar::paint(GraphicsContext* graphicsContext, const IntRect& damageRect) -{ - if (controlSize() != RegularScrollbar) { - m_opt.state |= QStyle::State_Mini; - } else { - m_opt.state &= ~QStyle::State_Mini; - } - m_opt.orientation = (orientation() == VerticalScrollbar) ? Qt::Vertical : Qt::Horizontal; - QStyle *s = QApplication::style(); - if (orientation() == HorizontalScrollbar) { - m_opt.rect.setHeight(horizontalScrollbarHeight(controlSize())); - m_opt.state |= QStyle::State_Horizontal; - } else { - m_opt.rect.setWidth(verticalScrollbarWidth(controlSize())); - m_opt.state &= ~QStyle::State_Horizontal; - } - - if (graphicsContext->paintingDisabled() || !m_opt.rect.isValid()) - return; - - QRect clip = m_opt.rect.intersected(damageRect); - // Don't paint anything if the scrollbar doesn't intersect the damage rect. - if (clip.isEmpty()) - return; - - QPainter *p = graphicsContext->platformContext(); - p->save(); - p->setClipRect(clip); - m_opt.sliderValue = value(); - m_opt.sliderPosition = value(); - m_opt.pageStep = m_visibleSize; - m_opt.singleStep = m_lineStep; - m_opt.minimum = 0; - m_opt.maximum = qMax(0, m_totalSize - m_visibleSize); - if (m_pressedPart != QStyle::SC_None) { - m_opt.activeSubControls = m_pressedPart; - } else { - m_opt.activeSubControls = m_hoveredPart; - } - - const QPoint topLeft = m_opt.rect.topLeft(); - p->translate(topLeft); - m_opt.rect.moveTo(QPoint(0, 0)); - QApplication::style()->drawComplexControl(QStyle::CC_ScrollBar, &m_opt, p, 0); - m_opt.rect.moveTo(topLeft); - p->restore(); -} - -int PlatformScrollbar::thumbPosition() const -{ - if (isEnabled()) - return (int)((float)m_currentPos * (trackLength() - thumbLength()) / (m_totalSize - m_visibleSize)); - return 0; -} - -int PlatformScrollbar::thumbLength() const -{ - IntRect thumb = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &m_opt, QStyle::SC_ScrollBarSlider, 0); - return m_orientation == HorizontalScrollbar ? thumb.width() : thumb.height(); -} - -int PlatformScrollbar::trackLength() const -{ - IntRect track = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &m_opt, QStyle::SC_ScrollBarGroove, 0); - return m_orientation == HorizontalScrollbar ? track.width() : track.height(); -} - -bool PlatformScrollbar::handleMouseMoveEvent(const PlatformMouseEvent& evt) -{ - const QPoint pos = convertFromContainingWindow(evt.pos()); - //qDebug() << "PlatformScrollbar::handleMouseMoveEvent" << m_opt.rect << pos << evt.pos(); - - m_opt.state |= QStyle::State_MouseOver; - const QPoint topLeft = m_opt.rect.topLeft(); - m_opt.rect.moveTo(QPoint(0, 0)); - QStyle::SubControl sc = QApplication::style()->hitTestComplexControl(QStyle::CC_ScrollBar, &m_opt, pos, 0); - m_opt.rect.moveTo(topLeft); - - if (sc == m_pressedPart) { - m_opt.state |= QStyle::State_Sunken; - } else { - m_opt.state &= ~QStyle::State_Sunken; - } - - if (m_pressedPart == QStyle::SC_ScrollBarSlider) { - // Drag the thumb. - int thumbPos = thumbPosition(); - int thumbLen = thumbLength(); - int trackLen = trackLength(); - int maxPos = trackLen - thumbLen; - int delta = 0; - if (m_orientation == HorizontalScrollbar) - delta = pos.x() - m_pressedPos; - else - delta = pos.y() - m_pressedPos; - - if (delta > 0) - // The mouse moved down/right. - delta = min(maxPos - thumbPos, delta); - else if (delta < 0) - // The mouse moved up/left. - delta = max(-thumbPos, delta); - - if (delta != 0) { - setValue((int)((float)(thumbPos + delta) * (m_totalSize - m_visibleSize) / (trackLen - thumbLen))); - m_pressedPos += thumbPosition() - thumbPos; - } - - return true; - } - - if (m_pressedPart != QStyle::SC_None) - m_pressedPos = m_orientation == HorizontalScrollbar ? pos.x() : pos.y(); - - if (sc != m_hoveredPart) { - if (m_pressedPart != QStyle::SC_None) { - if (sc == m_pressedPart) { - // The mouse is moving back over the pressed part. We - // need to start up the timer action again. - startTimerIfNeeded(cNormalTimerDelay); - invalidate(); - } else if (m_hoveredPart == m_pressedPart) { - // The mouse is leaving the pressed part. Kill our timer - // if needed. - stopTimerIfNeeded(); - invalidate(); - } - } else { - invalidate(); - } - m_hoveredPart = sc; - } - - return true; -} - -bool PlatformScrollbar::handleMouseOutEvent(const PlatformMouseEvent& evt) -{ - m_opt.state &= ~QStyle::State_MouseOver; - m_opt.state &= ~QStyle::State_Sunken; - invalidate(); - return true; -} - -bool PlatformScrollbar::handleMousePressEvent(const PlatformMouseEvent& evt) -{ - const QPoint pos = convertFromContainingWindow(evt.pos()); - //qDebug() << "PlatformScrollbar::handleMousePressEvent" << m_opt.rect << pos << evt.pos(); - - const QPoint topLeft = m_opt.rect.topLeft(); - m_opt.rect.moveTo(QPoint(0, 0)); - QStyle::SubControl sc = QApplication::style()->hitTestComplexControl(QStyle::CC_ScrollBar, &m_opt, pos, 0); - m_opt.rect.moveTo(topLeft); - switch (sc) { - case QStyle::SC_ScrollBarAddLine: - case QStyle::SC_ScrollBarSubLine: - case QStyle::SC_ScrollBarSlider: - m_opt.state |= QStyle::State_Sunken; - case QStyle::SC_ScrollBarAddPage: - case QStyle::SC_ScrollBarSubPage: - case QStyle::SC_ScrollBarGroove: - m_pressedPart = sc; - break; - default: - m_pressedPart = QStyle::SC_None; - return false; - } - m_pressedPos = m_orientation == HorizontalScrollbar ? pos.x() : pos.y(); - autoscrollPressedPart(cInitialTimerDelay); - invalidate(); - return true; -} - -bool PlatformScrollbar::handleMouseReleaseEvent(const PlatformMouseEvent&) -{ - m_opt.state &= ~QStyle::State_Sunken; - m_pressedPart = QStyle::SC_None; - m_pressedPos = 0; - stopTimerIfNeeded(); - invalidate(); - return true; -} - -void PlatformScrollbar::startTimerIfNeeded(double delay) -{ - // Don't do anything for the thumb. - if (m_pressedPart == QStyle::SC_ScrollBarSlider) - return; - - // Handle the track. We halt track scrolling once the thumb is level - // with us. - if (m_pressedPart == QStyle::SC_ScrollBarGroove && thumbUnderMouse()) { - invalidate(); - m_hoveredPart = QStyle::SC_ScrollBarSlider; - return; - } - - // We can't scroll if we've hit the beginning or end. - ScrollDirection dir = pressedPartScrollDirection(); - if (dir == ScrollUp || dir == ScrollLeft) { - if (m_currentPos == 0) - return; - } else { - if (m_currentPos == m_totalSize - m_visibleSize) - return; - } - - m_scrollTimer.startOneShot(delay); -} - -void PlatformScrollbar::stopTimerIfNeeded() -{ - if (m_scrollTimer.isActive()) - m_scrollTimer.stop(); -} - -void PlatformScrollbar::autoscrollPressedPart(double delay) -{ - // Don't do anything for the thumb or if nothing was pressed. - if (m_pressedPart == QStyle::SC_ScrollBarSlider || m_pressedPart == QStyle::SC_None) - return; - - // Handle the track. - if (m_pressedPart == QStyle::SC_ScrollBarGroove && thumbUnderMouse()) { - invalidate(); - m_hoveredPart = QStyle::SC_ScrollBarSlider; - return; - } - - // Handle the arrows and track. - if (scroll(pressedPartScrollDirection(), pressedPartScrollGranularity())) - startTimerIfNeeded(delay); -} - -void PlatformScrollbar::autoscrollTimerFired(Timer<PlatformScrollbar>*) -{ - autoscrollPressedPart(cNormalTimerDelay); -} - -ScrollDirection PlatformScrollbar::pressedPartScrollDirection() -{ - if (m_orientation == HorizontalScrollbar) { - if (m_pressedPart == QStyle::SC_ScrollBarSubLine || m_pressedPart == QStyle::SC_ScrollBarSubPage) - return ScrollLeft; - return ScrollRight; - } else { - if (m_pressedPart == QStyle::SC_ScrollBarSubLine || m_pressedPart == QStyle::SC_ScrollBarSubPage) - return ScrollUp; - return ScrollDown; - } -} - -ScrollGranularity PlatformScrollbar::pressedPartScrollGranularity() -{ - if (m_pressedPart == QStyle::SC_ScrollBarSubLine || m_pressedPart == QStyle::SC_ScrollBarAddLine) - return ScrollByLine; - return ScrollByPage; -} - -bool PlatformScrollbar::thumbUnderMouse() -{ - // Construct a rect. - IntRect thumb = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &m_opt, QStyle::SC_ScrollBarSlider, 0); - thumb.move(-m_opt.rect.x(), -m_opt.rect.y()); - int begin = (m_orientation == HorizontalScrollbar) ? thumb.x() : thumb.y(); - int end = (m_orientation == HorizontalScrollbar) ? thumb.right() : thumb.bottom(); - return (begin <= m_pressedPos && m_pressedPos < end); -} - -int PlatformScrollbar::horizontalScrollbarHeight(ScrollbarControlSize controlSize) -{ - QStyle *s = QApplication::style(); - QStyleOptionSlider o; - o.orientation = Qt::Horizontal; - o.state |= QStyle::State_Horizontal; - if (controlSize != RegularScrollbar) - o.state |= QStyle::State_Mini; - return s->pixelMetric(QStyle::PM_ScrollBarExtent, &o, 0); -} - -int PlatformScrollbar::verticalScrollbarWidth(ScrollbarControlSize controlSize) -{ - QStyle *s = QApplication::style(); - QStyleOptionSlider o; - o.orientation = Qt::Vertical; - o.state &= ~QStyle::State_Horizontal; - if (controlSize != RegularScrollbar) - o.state |= QStyle::State_Mini; - return s->pixelMetric(QStyle::PM_ScrollBarExtent, &o, 0); -} - -void PlatformScrollbar::invalidate() -{ - // Get the root widget. - ScrollView* outermostView = topLevel(); - if (!outermostView) - return; - - IntRect windowRect = convertToContainingWindow(IntRect(0, 0, width(), height())); - outermostView->addToDirtyRegion(windowRect); -} - -} - -// vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/PlugInInfoStoreQt.cpp b/WebCore/platform/qt/PlugInInfoStoreQt.cpp deleted file mode 100644 index 57cc3a9..0000000 --- a/WebCore/platform/qt/PlugInInfoStoreQt.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - Copyright (C) 2007 Trolltech ASA - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - This class provides all functionality needed for loading images, style sheets and html - pages from the web. It has a memory cache for these objects. -*/ -#include "PluginInfoStore.h" -#include "qdebug.h" -#if QT_VERSION < 0x040400 -#include "qwebobjectplugin_p.h" -#endif -#include "NotImplemented.h" - -namespace WebCore { - -PluginInfo* PluginInfoStore::createPluginInfoForPluginAtIndex(unsigned i) -{ - //qDebug() << ">>>>>>>>>>> PluginInfoStore::createPluginInfoForPluginAtIndex(" << i << ")"; - -#if QT_VERSION < 0x040400 - QWebFactoryLoader *loader = QWebFactoryLoader::self(); - if (i > loader->m_pluginInfo.count()) - return 0; - const QWebFactoryLoader::Info &qinfo = loader->m_pluginInfo.at(i); - PluginInfo *info = new PluginInfo; - info->name = qinfo.name; - info->desc = qinfo.description; - foreach (const QWebFactoryLoader::MimeInfo &m, qinfo.mimes) { - MimeClassInfo *mime = new MimeClassInfo; - mime->type = m.type; - mime->plugin = info; - foreach (QString ext, m.extensions) - mime->suffixes.append(ext); - info->mimes.append(mime); - } - return info; -#else - return 0; // ### FIXME -#endif -} - -unsigned PluginInfoStore::pluginCount() const -{ -#if QT_VERSION < 0x040400 - //qDebug() << ">>>>>>>>>>> PluginInfoStore::count =" << QWebFactoryLoader::self()->keys().count(); - return QWebFactoryLoader::self()->keys().count(); -#else - return 0; -#endif -} - -String PluginInfoStore::pluginNameForMIMEType(const String& mimeType) -{ - // FIXME: This method is stubbed out and should really return the name of a plug-in package for - // a given MIME type. - return String(); -} - -bool PluginInfoStore::supportsMIMEType(const WebCore::String& string) -{ -#if QT_VERSION < 0x040400 - bool supports = QWebFactoryLoader::self()->supportsMimeType(string); -#else - bool supports = false; -#endif - //qDebug() << ">>>>>>>>>>> PluginInfoStore::supportsMIMEType(" << string << ") =" << supports; - return supports; -} - -void refreshPlugins(bool) { - notImplemented(); -} - -} diff --git a/WebCore/platform/qt/PopupMenuQt.cpp b/WebCore/platform/qt/PopupMenuQt.cpp index add4d84..76728fa 100644 --- a/WebCore/platform/qt/PopupMenuQt.cpp +++ b/WebCore/platform/qt/PopupMenuQt.cpp @@ -1,7 +1,7 @@ /* * This file is part of the popup menu implementation for <select> elements in WebCore. * - * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2006 Apple Computer, Inc. * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com * Coypright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> @@ -28,6 +28,7 @@ #include "Frame.h" #include "FrameView.h" +#include "HostWindow.h" #include "PopupMenuClient.h" #include "NotImplemented.h" #include "QWebPopup.h" @@ -70,7 +71,7 @@ void PopupMenu::populate(const IntRect& r) m_popup->insertItem(i, QString::fromLatin1("---")); } else { - //RenderStyle* style = client()->itemStyle(i); + //PopupMenuStyle style = client()->itemStyle(i); m_popup->insertItem(i, client()->itemText(i)); #if 0 item = new QListWidgetItem(client()->itemText(i)); @@ -89,13 +90,14 @@ void PopupMenu::populate(const IntRect& r) void PopupMenu::show(const IntRect& r, FrameView* v, int index) { + QWidget* window = v->hostWindow()->platformWindow(); populate(r); QRect rect = r; rect.moveTopLeft(v->contentsToWindow(r.topLeft())); - QRect global(v->containingWindow()->mapToGlobal(QPoint(rect.x(), rect.y())), - QSize(rect.width(), m_popup->sizeHint().height())); + rect.setHeight(m_popup->sizeHint().height()); - m_popup->setGeometry(global); + m_popup->setParent(window); + m_popup->setGeometry(rect); m_popup->setCurrentIndex(index); m_popup->exec(); } diff --git a/WebCore/platform/qt/QWebPopup.cpp b/WebCore/platform/qt/QWebPopup.cpp index dfc430f..ae5c24e 100644 --- a/WebCore/platform/qt/QWebPopup.cpp +++ b/WebCore/platform/qt/QWebPopup.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,7 +20,7 @@ */ #include "config.h" #include "QWebPopup.h" -#include "RenderStyle.h" +#include "PopupMenuStyle.h" #include <QCoreApplication> #include <QMouseEvent> @@ -33,7 +33,7 @@ QWebPopup::QWebPopup(PopupMenuClient* client) { Q_ASSERT(m_client); - setFont(m_client->clientStyle()->font().font()); + setFont(m_client->menuStyle().font().font()); connect(this, SIGNAL(activated(int)), SLOT(activeChanged(int))); } diff --git a/WebCore/platform/qt/QWebPopup.h b/WebCore/platform/qt/QWebPopup.h index 083cfdb..36d6781 100644 --- a/WebCore/platform/qt/QWebPopup.h +++ b/WebCore/platform/qt/QWebPopup.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2007 Trolltech ASA + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -25,8 +25,6 @@ #include "PopupMenuClient.h" -class QHideEvent; - namespace WebCore { class QWebPopup : public QComboBox { diff --git a/WebCore/platform/qt/RenderThemeQt.cpp b/WebCore/platform/qt/RenderThemeQt.cpp index dbf080f..2a33e45 100644 --- a/WebCore/platform/qt/RenderThemeQt.cpp +++ b/WebCore/platform/qt/RenderThemeQt.cpp @@ -1,6 +1,8 @@ /* * This file is part of the WebKit project. * + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * * Copyright (C) 2006 Zack Rusin <zack@kde.org> * 2006 Dirk Mueller <mueller@kde.org> * 2006 Nikolas Zimmermann <zimmermann@kde.org> @@ -34,21 +36,71 @@ #include <QApplication> #include <QColor> #include <QDebug> -#include <QStyle> +#include <QFile> #include <QWidget> #include <QPainter> +#include <QPushButton> +#include <QStyleFactory> #include <QStyleOptionButton> #include <QStyleOptionFrameV2> #include "Color.h" +#include "CSSStyleSheet.h" #include "Document.h" #include "Page.h" #include "Font.h" #include "RenderTheme.h" #include "GraphicsContext.h" +#include "HTMLMediaElement.h" +#include "HTMLNames.h" namespace WebCore { +using namespace HTMLNames; + + +StylePainter::StylePainter(const RenderObject::PaintInfo& paintInfo) +{ + init(paintInfo.context ? paintInfo.context : 0); +} + +StylePainter::StylePainter(GraphicsContext* context) +{ + init(context); +} + +void StylePainter::init(GraphicsContext* context) +{ + painter = static_cast<QPainter*>(context->platformContext()); + widget = 0; + QPaintDevice* dev = 0; + if (painter) + dev = painter->device(); + if (dev && dev->devType() == QInternal::Widget) + widget = static_cast<QWidget*>(dev); + style = (widget ? widget->style() : QApplication::style()); + + if (painter) { + // the styles often assume being called with a pristine painter where no brush is set, + // so reset it manually + oldBrush = painter->brush(); + painter->setBrush(Qt::NoBrush); + + // painting the widget with anti-aliasing will make it blurry + // disable it here and restore it later + oldAntialiasing = painter->testRenderHint(QPainter::Antialiasing); + painter->setRenderHint(QPainter::Antialiasing, false); + } +} + +StylePainter::~StylePainter() +{ + if (painter) { + painter->setBrush(oldBrush); + painter->setRenderHints(QPainter::Antialiasing, oldAntialiasing); + } +} + RenderTheme* theme() { static RenderThemeQt rt; @@ -58,6 +110,33 @@ RenderTheme* theme() RenderThemeQt::RenderThemeQt() : RenderTheme() { + QPushButton button; + button.setAttribute(Qt::WA_MacSmallSize); + QFont defaultButtonFont = QApplication::font(&button); + QFontInfo fontInfo(defaultButtonFont); + m_buttonFontFamily = defaultButtonFont.family(); +#ifdef Q_WS_MAC + m_buttonFontPixelSize = fontInfo.pixelSize(); +#endif + + m_fallbackStyle = 0; +} + +RenderThemeQt::~RenderThemeQt() +{ + delete m_fallbackStyle; +} + +// for some widget painting, we need to fallback to Windows style +QStyle* RenderThemeQt::fallbackStyle() +{ + if(!m_fallbackStyle) + m_fallbackStyle = QStyleFactory::create(QLatin1String("windows")); + + if(!m_fallbackStyle) + m_fallbackStyle = QApplication::style(); + + return m_fallbackStyle; } bool RenderThemeQt::supportsHover(const RenderStyle*) const @@ -67,13 +146,13 @@ bool RenderThemeQt::supportsHover(const RenderStyle*) const bool RenderThemeQt::supportsFocusRing(const RenderStyle* style) const { - return supportsFocus(style->appearance()); + return true; // Qt provides this through the style } -short RenderThemeQt::baselinePosition(const RenderObject* o) const +int RenderThemeQt::baselinePosition(const RenderObject* o) const { - if (o->style()->appearance() == CheckboxAppearance || - o->style()->appearance() == RadioAppearance) + if (o->style()->appearance() == CheckboxPart || + o->style()->appearance() == RadioPart) return o->marginTop() + o->height() - 2; // Same as in old khtml return RenderTheme::baselinePosition(o); } @@ -84,7 +163,7 @@ bool RenderThemeQt::controlSupportsTints(const RenderObject* o) const return false; // Checkboxes only have tint when checked. - if (o->style()->appearance() == CheckboxAppearance) + if (o->style()->appearance() == CheckboxPart) return isChecked(o); // For now assume other controls have tint if enabled. @@ -96,20 +175,42 @@ bool RenderThemeQt::supportsControlTints() const return true; } +static QRect inflateButtonRect(const QRect& originalRect) +{ + QStyleOptionButton option; + option.state |= QStyle::State_Small; + option.rect = originalRect; + + QRect layoutRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLayoutItem, + &option, 0); + if (!layoutRect.isNull()) { + int paddingLeft = layoutRect.left() - originalRect.left(); + int paddingRight = originalRect.right() - layoutRect.right(); + int paddingTop = layoutRect.top() - originalRect.top(); + int paddingBottom = originalRect.bottom() - layoutRect.bottom(); + + return originalRect.adjusted(-paddingLeft, -paddingTop, paddingRight, paddingBottom); + } else { + return originalRect; + } +} + void RenderThemeQt::adjustRepaintRect(const RenderObject* o, IntRect& r) { switch (o->style()->appearance()) { - case CheckboxAppearance: { + case CheckboxPart: { break; } - case RadioAppearance: { + case RadioPart: { break; } - case PushButtonAppearance: - case ButtonAppearance: { + case PushButtonPart: + case ButtonPart: { + QRect inflatedRect = inflateButtonRect(r); + r = IntRect(inflatedRect.x(), inflatedRect.y(), inflatedRect.width(), inflatedRect.height()); break; } - case MenulistAppearance: { + case MenulistPart: { break; } default: @@ -118,19 +219,17 @@ void RenderThemeQt::adjustRepaintRect(const RenderObject* o, IntRect& r) } bool RenderThemeQt::isControlStyled(const RenderStyle* style, const BorderData& border, - const BackgroundLayer& background, const Color& backgroundColor) const + const FillLayer& background, const Color& backgroundColor) const { - if (style->appearance() == TextFieldAppearance || style->appearance() == TextAreaAppearance) + if (style->appearance() == TextFieldPart + || style->appearance() == TextAreaPart + || style->appearance() == ListboxPart) { return style->border() != border; + } return RenderTheme::isControlStyled(style, border, background, backgroundColor); } -void RenderThemeQt::paintResizeControl(GraphicsContext*, const IntRect&) -{ -} - - Color RenderThemeQt::platformActiveSelectionBackgroundColor() const { QPalette pal = QApplication::palette(); @@ -166,43 +265,111 @@ int RenderThemeQt::minimumMenuListSize(RenderStyle*) const return 7 * fm.width(QLatin1Char('x')); } -void RenderThemeQt::adjustSliderThumbSize(RenderObject* o) const +static void computeSizeBasedOnStyle(RenderStyle* renderStyle) { - RenderTheme::adjustSliderThumbSize(o); -} + // If the width and height are both specified, then we have nothing to do. + if (!renderStyle->width().isIntrinsicOrAuto() && !renderStyle->height().isAuto()) + return; -bool RenderThemeQt::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) -{ - return paintButton(o, i, r); + QSize size(0, 0); + const QFontMetrics fm(renderStyle->font().font()); + QStyle* applicationStyle = QApplication::style(); + + switch (renderStyle->appearance()) { + case CheckboxPart: { + QStyleOption styleOption; + styleOption.state |= QStyle::State_Small; + int checkBoxWidth = applicationStyle->pixelMetric(QStyle::PM_IndicatorWidth, + &styleOption); + size = QSize(checkBoxWidth, checkBoxWidth); + break; + } + case RadioPart: { + QStyleOption styleOption; + styleOption.state |= QStyle::State_Small; + int radioWidth = applicationStyle->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, + &styleOption); + size = QSize(radioWidth, radioWidth); + break; + } + case PushButtonPart: + case ButtonPart: { + QStyleOptionButton styleOption; + styleOption.state |= QStyle::State_Small; + QSize contentSize = fm.size(Qt::TextShowMnemonic, QString::fromLatin1("X")); + QSize pushButtonSize = applicationStyle->sizeFromContents(QStyle::CT_PushButton, + &styleOption, + contentSize, + 0); + styleOption.rect = QRect(0, 0, pushButtonSize.width(), pushButtonSize.height()); + QRect layoutRect = applicationStyle->subElementRect(QStyle::SE_PushButtonLayoutItem, + &styleOption, + 0); + // If the style supports layout rects we use that, and + // compensate accordingly in paintButton() below. + if (!layoutRect.isNull()) { + size.setHeight(layoutRect.height()); + } else { + size.setHeight(pushButtonSize.height()); + } + + break; + } + case MenulistPart: { + QStyleOptionComboBox styleOption; + styleOption.state |= QStyle::State_Small; + int contentHeight = qMax(fm.lineSpacing(), 14) + 2; + QSize menuListSize = applicationStyle->sizeFromContents(QStyle::CT_ComboBox, + &styleOption, + QSize(0, contentHeight), + 0); + size.setHeight(menuListSize.height()); + break; + } + case TextFieldPart: { + const int verticalMargin = 1; + const int horizontalMargin = 2; + int h = qMax(fm.lineSpacing(), 14) + 2*verticalMargin; + int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin; + QStyleOptionFrameV2 opt; + opt.lineWidth = applicationStyle->pixelMetric(QStyle::PM_DefaultFrameWidth, + &opt, 0); + QSize sz = applicationStyle->sizeFromContents(QStyle::CT_LineEdit, + &opt, + QSize(w, h).expandedTo(QApplication::globalStrut()), + 0); + size.setHeight(sz.height()); + break; + } + default: + break; + } + + // FIXME: Check is flawed, since it doesn't take min-width/max-width into account. + if (renderStyle->width().isIntrinsicOrAuto() && size.width() > 0) + renderStyle->setWidth(Length(size.width(), Fixed)); + if (renderStyle->height().isAuto() && size.height() > 0) + renderStyle->setHeight(Length(size.height(), Fixed)); } void RenderThemeQt::setCheckboxSize(RenderStyle* style) const { - // If the width and height are both specified, then we have nothing to do. - if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto()) - return; - - // FIXME: A hard-coded size of 13 is used. This is wrong but necessary for now. It matches Firefox. - // At different DPI settings on Windows, querying the theme gives you a larger size that accounts for - // the higher DPI. Until our entire engine honors a DPI setting other than 96, we can't rely on the theme's - // metrics. - const int ff = 13; - if (style->width().isIntrinsicOrAuto()) - style->setWidth(Length(ff, Fixed)); - - if (style->height().isAuto()) - style->setHeight(Length(ff, Fixed)); + computeSizeBasedOnStyle(style); } -bool RenderThemeQt::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) +bool RenderThemeQt::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) { return paintButton(o, i, r); } void RenderThemeQt::setRadioSize(RenderStyle* style) const { - // This is the same as checkboxes. - setCheckboxSize(style); + computeSizeBasedOnStyle(style); +} + +bool RenderThemeQt::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) +{ + return paintButton(o, i, r); } void RenderThemeQt::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const @@ -216,72 +383,140 @@ void RenderThemeQt::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* s // White-space is locked to pre style->setWhiteSpace(PRE); - setButtonSize(style); + FontDescription fontDescription = style->fontDescription(); + fontDescription.setIsAbsoluteSize(true); + +#ifdef Q_WS_MAC // Use fixed font size and family on Mac (like Safari does) + fontDescription.setSpecifiedSize(m_buttonFontPixelSize); + fontDescription.setComputedSize(m_buttonFontPixelSize); +#else + fontDescription.setSpecifiedSize(style->fontSize()); + fontDescription.setComputedSize(style->fontSize()); +#endif + FontFamily fontFamily; + fontFamily.setFamily(m_buttonFontFamily); + fontDescription.setFamily(fontFamily); + style->setFontDescription(fontDescription); + style->setLineHeight(RenderStyle::initialLineHeight()); + + setButtonSize(style); setButtonPadding(style); + + style->setColor(QApplication::palette().text().color()); } -bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) +void RenderThemeQt::setButtonSize(RenderStyle* style) const { - QStyle* style = 0; - QPainter* painter = 0; - QWidget* widget = 0; + computeSizeBasedOnStyle(style); +} - if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget)) - return true; +void RenderThemeQt::setButtonPadding(RenderStyle* style) const +{ + QStyleOptionButton styleOption; + styleOption.state |= QStyle::State_Small; + + // Fake a button rect here, since we're just computing deltas + QRect originalRect = QRect(0, 0, 100, 30); + styleOption.rect = originalRect; + + // Default padding is based on the button margin pixel metric + int buttonMargin = QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin, + &styleOption, 0); + int paddingLeft = buttonMargin; + int paddingRight = buttonMargin; + int paddingTop = 1; + int paddingBottom = 0; + + // Then check if the style uses layout margins + QRect layoutRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLayoutItem, + &styleOption, 0); + if (!layoutRect.isNull()) { + QRect contentsRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonContents, + &styleOption, 0); + paddingLeft = contentsRect.left() - layoutRect.left(); + paddingRight = layoutRect.right() - contentsRect.right(); + paddingTop = contentsRect.top() - layoutRect.top(); + + // Can't use this right now because we don't have the baseline to compensate + // paddingBottom = layoutRect.bottom() - contentsRect.bottom(); + } - QStyleOptionButton option; - if (widget) - option.initFrom(widget); - option.rect = r; + style->setPaddingLeft(Length(paddingLeft, Fixed)); + style->setPaddingRight(Length(paddingRight, Fixed)); + style->setPaddingTop(Length(paddingTop, Fixed)); + style->setPaddingBottom(Length(paddingBottom, Fixed)); +} - // Get the correct theme data for a button - EAppearance appearance = applyTheme(option, o); +bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) +{ + StylePainter p(i); + if (!p.isValid()) + return true; - if(appearance == PushButtonAppearance || appearance == ButtonAppearance) - style->drawControl(QStyle::CE_PushButton, &option, painter); - else if(appearance == RadioAppearance) - style->drawPrimitive(QStyle::PE_IndicatorRadioButton, &option, painter, widget); - else if(appearance == CheckboxAppearance) - style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &option, painter, widget); + QStyleOptionButton option; + if (p.widget) + option.initFrom(p.widget); + + option.rect = r; + option.state |= QStyle::State_Small; + + ControlPart appearance = applyTheme(option, o); + if(appearance == PushButtonPart || appearance == ButtonPart) { + option.rect = inflateButtonRect(option.rect); + p.drawControl(QStyle::CE_PushButton, option); + } else if(appearance == RadioPart) { + p.drawControl(QStyle::CE_RadioButton, option); + } else if(appearance == CheckboxPart) { + p.drawControl(QStyle::CE_CheckBox, option); + } return false; } -void RenderThemeQt::setButtonSize(RenderStyle* style) const +void RenderThemeQt::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const { - setPrimitiveSize(style); + style->setBackgroundColor(Color::transparent); + style->setColor(QApplication::palette().text().color()); } bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) { - QStyle* style = 0; - QPainter* painter = 0; - QWidget* widget = 0; - - if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget)) + StylePainter p(i); + if (!p.isValid()) return true; QStyleOptionFrameV2 panel; - if (widget) - panel.initFrom(widget); + if (p.widget) + panel.initFrom(p.widget); + panel.rect = r; + panel.lineWidth = p.style->pixelMetric(QStyle::PM_DefaultFrameWidth, &panel, p.widget); panel.state |= QStyle::State_Sunken; panel.features = QStyleOptionFrameV2::None; - // Get the correct theme data for a button - EAppearance appearance = applyTheme(panel, o); - Q_ASSERT(appearance == TextFieldAppearance || appearance == SearchFieldAppearance); + // Get the correct theme data for a text field + ControlPart appearance = applyTheme(panel, o); + if (appearance != TextFieldPart + && appearance != SearchFieldPart + && appearance != TextAreaPart + && appearance != ListboxPart) + return true; // Now paint the text field. - style->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, painter, widget); - style->drawPrimitive(QStyle::PE_FrameLineEdit, &panel, painter, widget); - + p.drawPrimitive(QStyle::PE_PanelLineEdit, panel); + return false; } -void RenderThemeQt::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const +void RenderThemeQt::adjustTextAreaStyle(CSSStyleSelector* selector, RenderStyle* style, Element* element) const +{ + adjustTextFieldStyle(selector, style, element); +} + +bool RenderThemeQt::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) { + return paintTextField(o, i, r); } void RenderThemeQt::adjustMenuListStyle(CSSStyleSelector*, RenderStyle* style, Element*) const @@ -294,55 +529,91 @@ void RenderThemeQt::adjustMenuListStyle(CSSStyleSelector*, RenderStyle* style, E // White-space is locked to pre style->setWhiteSpace(PRE); - setPrimitiveSize(style); + computeSizeBasedOnStyle(style); // Add in the padding that we'd like to use. setPopupPadding(style); - // Our font is locked to the appropriate system font size for the control. To clarify, we first use the CSS-specified font to figure out - // a reasonable control size, but once that control size is determined, we throw that font away and use the appropriate - // system font for the control size instead. - //setFontFromControlSize(selector, style); + style->setColor(QApplication::palette().text().color()); } -bool RenderThemeQt::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) +void RenderThemeQt::setPopupPadding(RenderStyle* style) const { - QStyle* style = 0; - QPainter* painter = 0; - QWidget* widget = 0; + const int padding = 8; + style->setPaddingLeft(Length(padding, Fixed)); - if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget)) + QStyleOptionComboBox opt; + int w = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize, &opt, 0); + style->setPaddingRight(Length(padding + w, Fixed)); + + style->setPaddingTop(Length(2, Fixed)); + style->setPaddingBottom(Length(0, Fixed)); +} + + +bool RenderThemeQt::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) +{ + StylePainter p(i); + if (!p.isValid()) return true; QStyleOptionComboBox opt; - if (widget) - opt.initFrom(widget); - EAppearance appearance = applyTheme(opt, o); + if (p.widget) + opt.initFrom(p.widget); + ControlPart appearance = applyTheme(opt, o); + const QPoint topLeft = r.topLeft(); - painter->translate(topLeft); + p.painter->translate(topLeft); opt.rect.moveTo(QPoint(0,0)); opt.rect.setSize(r.size()); opt.frame = false; - style->drawComplexControl(QStyle::CC_ComboBox, &opt, painter, widget); - painter->translate(-topLeft); + p.drawComplexControl(QStyle::CC_ComboBox, opt); + p.painter->translate(-topLeft); return false; } - -bool RenderThemeQt::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& pi, - const IntRect& r) +void RenderThemeQt::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, + Element* e) const { - notImplemented(); - return RenderTheme::paintMenuListButton(o, pi, r); + // WORKAROUND because html4.css specifies -webkit-border-radius for <select> so we override it here + // see also http://bugs.webkit.org/show_bug.cgi?id=18399 + style->resetBorderRadius(); + + // Height is locked to auto. + style->setHeight(Length(Auto)); + + // White-space is locked to pre + style->setWhiteSpace(PRE); + + computeSizeBasedOnStyle(style); + + // Add in the padding that we'd like to use. + setPopupPadding(style); + + style->setColor(QApplication::palette().text().color()); } -void RenderThemeQt::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, - Element* e) const +bool RenderThemeQt::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, + const IntRect& r) { - notImplemented(); - RenderTheme::adjustMenuListButtonStyle(selector, style, e); + StylePainter p(i); + if (!p.isValid()) + return true; + + QStyleOptionComboBox option; + if (p.widget) + option.initFrom(p.widget); + applyTheme(option, o); + option.rect = r; + + // for drawing the combo box arrow, rely only on the fallback style + p.style = fallbackStyle(); + option.subControls = QStyle::SC_ComboBoxArrow; + p.drawComplexControl(QStyle::CC_ComboBox, option); + + return false; } bool RenderThemeQt::paintSliderTrack(RenderObject* o, const RenderObject::PaintInfo& pi, @@ -415,37 +686,24 @@ bool RenderThemeQt::paintSearchFieldResultsDecoration(RenderObject* o, const Ren return RenderTheme::paintSearchFieldResultsDecoration(o, pi, r); } -bool RenderThemeQt::supportsFocus(EAppearance appearance) const +bool RenderThemeQt::supportsFocus(ControlPart appearance) const { switch (appearance) { - case PushButtonAppearance: - case ButtonAppearance: - case TextFieldAppearance: - case MenulistAppearance: - case RadioAppearance: - case CheckboxAppearance: + case PushButtonPart: + case ButtonPart: + case TextFieldPart: + case TextAreaPart: + case ListboxPart: + case MenulistPart: + case RadioPart: + case CheckboxPart: return true; default: // No for all others... return false; } } -bool RenderThemeQt::getStylePainterAndWidgetFromPaintInfo(const RenderObject::PaintInfo& i, QStyle*& style, - QPainter*& painter, QWidget*& widget) const -{ - painter = (i.context ? static_cast<QPainter*>(i.context->platformContext()) : 0); - widget = 0; - QPaintDevice* dev = 0; - if (painter) - dev = painter->device(); - if (dev && dev->devType() == QInternal::Widget) - widget = static_cast<QWidget*>(dev); - style = (widget ? widget->style() : QApplication::style()); - - return (painter && style); -} - -EAppearance RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) const +ControlPart RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) const { // Default bits: no focus, no mouse over option.state &= ~(QStyle::State_HasFocus | QStyle::State_MouseOver); @@ -463,32 +721,26 @@ EAppearance RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) con if (isHovered(o)) option.state |= QStyle::State_MouseOver; - EAppearance result = o->style()->appearance(); + ControlPart result = o->style()->appearance(); switch (result) { - case PushButtonAppearance: - case SquareButtonAppearance: - case ButtonAppearance: - case ButtonBevelAppearance: - case ListItemAppearance: - case MenulistButtonAppearance: - case ScrollbarButtonLeftAppearance: - case ScrollbarButtonRightAppearance: - case ScrollbarTrackHorizontalAppearance: - case ScrollbarTrackVerticalAppearance: - case ScrollbarThumbHorizontalAppearance: - case ScrollbarThumbVerticalAppearance: - case SearchFieldResultsButtonAppearance: - case SearchFieldCancelButtonAppearance: { + case PushButtonPart: + case SquareButtonPart: + case ButtonPart: + case ButtonBevelPart: + case ListItemPart: + case MenulistButtonPart: + case SearchFieldResultsButtonPart: + case SearchFieldCancelButtonPart: { if (isPressed(o)) option.state |= QStyle::State_Sunken; - else if (result == PushButtonAppearance) + else if (result == PushButtonPart) option.state |= QStyle::State_Raised; break; } } - if(result == RadioAppearance || result == CheckboxAppearance) + if(result == RadioPart || result == CheckboxPart) option.state |= (isChecked(o) ? QStyle::State_On : QStyle::State_Off); // If the webview has a custom palette, use it @@ -502,95 +754,192 @@ EAppearance RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) con return result; } -void RenderThemeQt::setSizeFromFont(RenderStyle* style) const +void RenderTheme::adjustDefaultStyleSheet(CSSStyleSheet* style) { - // FIXME: Check is flawed, since it doesn't take min-width/max-width into account. - IntSize size = sizeForFont(style); - if (style->width().isIntrinsicOrAuto() && size.width() > 0) - style->setWidth(Length(size.width(), Fixed)); - if (style->height().isAuto() && size.height() > 0) - style->setHeight(Length(size.height(), Fixed)); + QFile platformStyleSheet(":/webcore/resources/html4-adjustments-qt.css"); + if (platformStyleSheet.open(QFile::ReadOnly)) { + QByteArray sheetData = platformStyleSheet.readAll(); + style->parseString(QString::fromUtf8(sheetData.constData(), sheetData.length())); + } } -IntSize RenderThemeQt::sizeForFont(RenderStyle* style) const +#if ENABLE(VIDEO) + +// Helper class to transform the painter's world matrix to the object's content area, scaled to 0,0,100,100 +class WorldMatrixTransformer { - const QFontMetrics fm(style->font().font()); - QSize size(0, 0); - switch (style->appearance()) { - case CheckboxAppearance: { - break; +public: + WorldMatrixTransformer(QPainter* painter, RenderObject* renderObject, const IntRect& r) : m_painter(painter) { + RenderStyle* style = renderObject->style(); + m_originalTransform = m_painter->transform(); + m_painter->translate(r.x() + style->paddingLeft().value(), r.y() + style->paddingTop().value()); + m_painter->scale((r.width() - style->paddingLeft().value() - style->paddingRight().value()) / 100.0, + (r.height() - style->paddingTop().value() - style->paddingBottom().value()) / 100.0); } - case RadioAppearance: { - break; - } - case PushButtonAppearance: - case ButtonAppearance: { - QSize sz = fm.size(Qt::TextShowMnemonic, QString::fromLatin1("X")); - QStyleOptionButton opt; - sz = QApplication::style()->sizeFromContents(QStyle::CT_PushButton, - &opt, sz, 0); - size.setHeight(sz.height()); - break; - } - case MenulistAppearance: { - QSize sz; - sz.setHeight(qMax(fm.lineSpacing(), 14) + 2); - QStyleOptionComboBox opt; - sz = QApplication::style()->sizeFromContents(QStyle::CT_ComboBox, - &opt, sz, 0); - size.setHeight(sz.height()); - break; - } - case TextFieldAppearance: { - const int verticalMargin = 1; - const int horizontalMargin = 2; - int h = qMax(fm.lineSpacing(), 14) + 2*verticalMargin; - int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin; - QStyleOptionFrameV2 opt; - opt.lineWidth = QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth, - &opt, 0); - QSize sz = QApplication::style()->sizeFromContents(QStyle::CT_LineEdit, - &opt, - QSize(w, h).expandedTo(QApplication::globalStrut()), - 0); - size.setHeight(sz.height()); - break; + + ~WorldMatrixTransformer() { m_painter->setTransform(m_originalTransform); } + +private: + QPainter* m_painter; + QTransform m_originalTransform; +}; + +HTMLMediaElement* RenderThemeQt::getMediaElementFromRenderObject(RenderObject* o) const +{ + Node* node = o->element(); + Node* mediaNode = node ? node->shadowAncestorNode() : 0; + if (!mediaNode || (!mediaNode->hasTagName(videoTag) && !mediaNode->hasTagName(audioTag))) + return 0; + + return static_cast<HTMLMediaElement*>(mediaNode); +} + +void RenderThemeQt::paintMediaBackground(QPainter* painter, const IntRect& r) const +{ + painter->setPen(Qt::NoPen); + static QColor transparentBlack(0,0,0,100); + painter->setBrush(transparentBlack); + painter->drawRoundedRect(r.x(), r.y(), r.width(), r.height(), 5.0, 5.0); +} + +QColor RenderThemeQt::getMediaControlForegroundColor(RenderObject* o) const +{ + QColor fgColor = platformActiveSelectionBackgroundColor(); + if (o && o->element()->active()) + fgColor = fgColor.lighter(); + return fgColor; +} + +bool RenderThemeQt::paintMediaFullscreenButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) +{ + return RenderTheme::paintMediaFullscreenButton(o, paintInfo, r); +} + +bool RenderThemeQt::paintMediaMuteButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) +{ + HTMLMediaElement* mediaElement = getMediaElementFromRenderObject(o); + if (!mediaElement) + return false; + + StylePainter p(paintInfo); + if (!p.isValid()) + return true; + + p.painter->setRenderHint(QPainter::Antialiasing, true); + + paintMediaBackground(p.painter, r); + + WorldMatrixTransformer transformer(p.painter, o, r); + const QPointF speakerPolygon[6] = { QPointF(20, 30), QPointF(50, 30), QPointF(80, 0), + QPointF(80, 100), QPointF(50, 70), QPointF(20, 70)}; + + p.painter->setBrush(getMediaControlForegroundColor(o)); + p.painter->drawPolygon(speakerPolygon, 6); + + if (mediaElement->muted()) { + p.painter->setPen(Qt::red); + p.painter->drawLine(0, 100, 100, 0); } - default: - break; + + return false; +} + +bool RenderThemeQt::paintMediaPlayButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) +{ + HTMLMediaElement* mediaElement = getMediaElementFromRenderObject(o); + if (!mediaElement) + return false; + + StylePainter p(paintInfo); + if (!p.isValid()) + return true; + + p.painter->setRenderHint(QPainter::Antialiasing, true); + + paintMediaBackground(p.painter, r); + + WorldMatrixTransformer transformer(p.painter, o, r); + p.painter->setBrush(getMediaControlForegroundColor(o)); + if (mediaElement->canPlay()) { + const QPointF playPolygon[3] = { QPointF(0, 0), QPointF(100, 50), QPointF(0, 100)}; + p.painter->drawPolygon(playPolygon, 3); + } else { + p.painter->drawRect(0, 0, 30, 100); + p.painter->drawRect(70, 0, 30, 100); } - return size; + + return false; } -void RenderThemeQt::setButtonPadding(RenderStyle* style) const +bool RenderThemeQt::paintMediaSeekBackButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) { - const int padding = 8; - style->setPaddingLeft(Length(padding, Fixed)); - style->setPaddingRight(Length(padding, Fixed)); - style->setPaddingTop(Length(0, Fixed)); - style->setPaddingBottom(Length(0, Fixed)); + // We don't want to paint this at the moment. + return false; } -void RenderThemeQt::setPopupPadding(RenderStyle* style) const +bool RenderThemeQt::paintMediaSeekForwardButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) { - const int padding = 8; - style->setPaddingLeft(Length(padding, Fixed)); - QStyleOptionComboBox opt; - int w = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize, &opt, 0); - style->setPaddingRight(Length(padding + w, Fixed)); + // We don't want to paint this at the moment. + return false; +} - style->setPaddingTop(Length(1, Fixed)); - style->setPaddingBottom(Length(0, Fixed)); +bool RenderThemeQt::paintMediaSliderTrack(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) +{ + HTMLMediaElement* mediaElement = getMediaElementFromRenderObject(o); + if (!mediaElement) + return false; + + StylePainter p(paintInfo); + if (!p.isValid()) + return true; + + p.painter->setRenderHint(QPainter::Antialiasing, true); + + paintMediaBackground(p.painter, r); + + if (MediaPlayer* player = mediaElement->player()) { + if (player->totalBytesKnown()) { + float percentLoaded = static_cast<float>(player->bytesLoaded()) / player->totalBytes(); + + WorldMatrixTransformer transformer(p.painter, o, r); + p.painter->setBrush(getMediaControlForegroundColor()); + p.painter->drawRect(0, 37, 100 * percentLoaded, 26); + } + } + + return false; } -void RenderThemeQt::setPrimitiveSize(RenderStyle* style) const +bool RenderThemeQt::paintMediaSliderThumb(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) { - // If the width and height are both specified, then we have nothing to do. - if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto()) - return; + HTMLMediaElement* mediaElement = getMediaElementFromRenderObject(o->parent()); + if (!mediaElement) + return false; + + StylePainter p(paintInfo); + if (!p.isValid()) + return true; + + p.painter->setRenderHint(QPainter::Antialiasing, true); - // Use the font size to determine the intrinsic width of the control. - setSizeFromFont(style); + p.painter->setPen(Qt::NoPen); + p.painter->setBrush(getMediaControlForegroundColor(o)); + p.painter->drawRect(r.x(), r.y(), r.width(), r.height()); + + return false; +} +#endif + +void RenderThemeQt::adjustSliderThumbSize(RenderObject* o) const +{ + if (o->style()->appearance() == MediaSliderThumbPart) { + RenderStyle* parentStyle = o->parent()->style(); + Q_ASSERT(parentStyle); + + int parentHeight = parentStyle->height().value(); + o->style()->setWidth(Length(parentHeight / 3, Fixed)); + o->style()->setHeight(Length(parentHeight, Fixed)); + } } } diff --git a/WebCore/platform/qt/RenderThemeQt.h b/WebCore/platform/qt/RenderThemeQt.h index 053d825..76e1855 100644 --- a/WebCore/platform/qt/RenderThemeQt.h +++ b/WebCore/platform/qt/RenderThemeQt.h @@ -24,24 +24,28 @@ #include "RenderTheme.h" -class QStyle; +#include <QStyle> + +QT_BEGIN_NAMESPACE class QPainter; class QWidget; -class QStyleOption; +QT_END_NAMESPACE namespace WebCore { class RenderStyle; +class HTMLMediaElement; class RenderThemeQt : public RenderTheme { public: RenderThemeQt(); + virtual ~RenderThemeQt(); virtual bool supportsHover(const RenderStyle*) const; virtual bool supportsFocusRing(const RenderStyle* style) const; - virtual short baselinePosition(const RenderObject* o) const; + virtual int baselinePosition(const RenderObject* o) const; // A method asking if the control changes its tint when the window has focus or not. virtual bool controlSupportsTints(const RenderObject*) const; @@ -52,9 +56,7 @@ public: virtual void adjustRepaintRect(const RenderObject* o, IntRect& r); virtual bool isControlStyled(const RenderStyle*, const BorderData&, - const BackgroundLayer&, const Color&) const; - - virtual void paintResizeControl(GraphicsContext*, const IntRect&); + const FillLayer&, const Color&) const; // The platform selection color. virtual Color platformActiveSelectionBackgroundColor() const; @@ -82,6 +84,9 @@ protected: virtual bool paintTextField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const; + virtual bool paintTextArea(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); + virtual void adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const; + virtual bool paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r); virtual void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const; @@ -102,17 +107,66 @@ protected: virtual void adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle*, Element*) const; virtual bool paintSearchFieldResultsDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); + +#if ENABLE(VIDEO) + virtual bool paintMediaFullscreenButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); + virtual bool paintMediaPlayButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); + virtual bool paintMediaMuteButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); + virtual bool paintMediaSeekBackButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); + virtual bool paintMediaSeekForwardButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); + virtual bool paintMediaSliderTrack(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); + virtual bool paintMediaSliderThumb(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); + private: - bool supportsFocus(EAppearance) const; + HTMLMediaElement* getMediaElementFromRenderObject(RenderObject* o) const; + void paintMediaBackground(QPainter* painter, const IntRect& r) const; + QColor getMediaControlForegroundColor(RenderObject* o = 0) const; +#endif - bool getStylePainterAndWidgetFromPaintInfo(const RenderObject::PaintInfo&, QStyle*&, QPainter*&, QWidget*&) const; - EAppearance applyTheme(QStyleOption&, RenderObject*) const; +private: + bool supportsFocus(ControlPart) const; + + ControlPart applyTheme(QStyleOption&, RenderObject*) const; - void setSizeFromFont(RenderStyle*) const; - IntSize sizeForFont(RenderStyle*) const; void setButtonPadding(RenderStyle*) const; void setPopupPadding(RenderStyle*) const; - void setPrimitiveSize(RenderStyle*) const; + +#ifdef Q_WS_MAC + int m_buttonFontPixelSize; +#endif + QString m_buttonFontFamily; + + QStyle* m_fallbackStyle; + QStyle* fallbackStyle(); +}; + +class StylePainter +{ +public: + explicit StylePainter(const RenderObject::PaintInfo& paintInfo); + explicit StylePainter(GraphicsContext* context); + ~StylePainter(); + + bool isValid() const { return painter && style; } + + QPainter* painter; + QWidget* widget; + QStyle* style; + + void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption& opt) + { style->drawPrimitive(pe, &opt, painter, widget); } + void drawControl(QStyle::ControlElement ce, const QStyleOption& opt) + { style->drawControl(ce, &opt, painter, widget); } + void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex& opt) + { style->drawComplexControl(cc, &opt, painter, widget); } + +private: + void init(GraphicsContext* context); + + QBrush oldBrush; + bool oldAntialiasing; + + Q_DISABLE_COPY(StylePainter) }; } diff --git a/WebCore/platform/qt/ScrollViewQt.cpp b/WebCore/platform/qt/ScrollViewQt.cpp index 6cd92bf..76d9f01 100644 --- a/WebCore/platform/qt/ScrollViewQt.cpp +++ b/WebCore/platform/qt/ScrollViewQt.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> * Copyright (C) 2006 Zack Rusin <zack@kde.org> * Copyright (C) 2006 George Staikos <staikos@kde.org> @@ -31,751 +31,30 @@ #include "config.h" #include "ScrollView.h" -#include "FrameView.h" -#include "FloatRect.h" -#include "FocusController.h" -#include "IntPoint.h" -#include "PlatformMouseEvent.h" -#include "PlatformWheelEvent.h" -#include "NotImplemented.h" -#include "Frame.h" -#include "Page.h" -#include "GraphicsContext.h" -#include "PlatformScrollBar.h" - -#include <QDebug> -#include <QWidget> -#include <QPainter> - -#ifdef Q_WS_MAC -#include <Carbon/Carbon.h> -#endif - -#include "qwebframe.h" -#include "qwebpage.h" - -// #define DEBUG_SCROLLVIEW namespace WebCore { -class ScrollView::ScrollViewPrivate : public ScrollbarClient -{ -public: - ScrollViewPrivate(ScrollView* view) - : m_view(view) - , m_hasStaticBackground(false) - , m_scrollbarsSuppressed(false) - , m_inUpdateScrollbars(false) - , m_scrollbarsAvoidingResizer(0) - , m_vScrollbarMode(ScrollbarAuto) - , m_hScrollbarMode(ScrollbarAuto) - { - } - - ~ScrollViewPrivate() - { - setHasHorizontalScrollbar(false); - setHasVerticalScrollbar(false); - } - - void setHasHorizontalScrollbar(bool hasBar); - void setHasVerticalScrollbar(bool hasBar); - - virtual void valueChanged(Scrollbar*); - virtual IntRect windowClipRect() const; - virtual bool isActive() const; - - void scrollBackingStore(const IntSize& scrollDelta); - - ScrollView* m_view; - IntSize m_scrollOffset; - IntSize m_contentsSize; - bool m_hasStaticBackground; - bool m_scrollbarsSuppressed; - bool m_inUpdateScrollbars; - int m_scrollbarsAvoidingResizer; - ScrollbarMode m_vScrollbarMode; - ScrollbarMode m_hScrollbarMode; - RefPtr<PlatformScrollbar> m_vBar; - RefPtr<PlatformScrollbar> m_hBar; - HashSet<Widget*> m_children; -}; - -void ScrollView::ScrollViewPrivate::setHasHorizontalScrollbar(bool hasBar) -{ - if (Scrollbar::hasPlatformScrollbars()) { - if (hasBar && !m_hBar) { - m_hBar = new PlatformScrollbar(this, HorizontalScrollbar, RegularScrollbar); - m_view->addChild(m_hBar.get()); - } else if (!hasBar && m_hBar) { - m_view->removeChild(m_hBar.get());; - m_hBar = 0; - } - } -} - -void ScrollView::ScrollViewPrivate::setHasVerticalScrollbar(bool hasBar) -{ - if (Scrollbar::hasPlatformScrollbars()) { - if (hasBar && !m_vBar) { - m_vBar = new PlatformScrollbar(this, VerticalScrollbar, RegularScrollbar); - m_view->addChild(m_vBar.get()); - } else if (!hasBar && m_vBar) { - m_view->removeChild(m_vBar.get()); - m_vBar = 0; - } - } -} - -void ScrollView::ScrollViewPrivate::valueChanged(Scrollbar* bar) -{ - // Figure out if we really moved. - IntSize newOffset = m_scrollOffset; - if (bar) { - if (bar == m_hBar) - newOffset.setWidth(bar->value()); - else if (bar == m_vBar) - newOffset.setHeight(bar->value()); - } - IntSize scrollDelta = newOffset - m_scrollOffset; - if (scrollDelta == IntSize()) - return; - m_scrollOffset = newOffset; - - if (m_scrollbarsSuppressed) - return; - - scrollBackingStore(scrollDelta); - static_cast<FrameView*>(m_view)->frame()->sendScrollEvent(); -} - -void ScrollView::ScrollViewPrivate::scrollBackingStore(const IntSize& scrollDelta) -{ - // Since scrolling is double buffered, we will be blitting the scroll view's intersection - // with the clip rect every time to keep it smooth. - IntRect clipRect = m_view->windowClipRect(); - IntRect scrollViewRect = m_view->convertToContainingWindow(IntRect(0, 0, m_view->visibleWidth(), m_view->visibleHeight())); - - IntRect updateRect = clipRect; - updateRect.intersect(scrollViewRect); - - if (!m_hasStaticBackground) { - m_view->scrollBackingStore(-scrollDelta.width(), -scrollDelta.height(), - scrollViewRect, clipRect); - } else { - // We need to go ahead and repaint the entire backing store. Do it now before moving the - // plugins. - m_view->addToDirtyRegion(updateRect); - m_view->updateBackingStore(); - } - - m_view->geometryChanged(); -} - -IntRect ScrollView::ScrollViewPrivate::windowClipRect() const -{ - return static_cast<const FrameView*>(m_view)->windowClipRect(false); -} - -bool ScrollView::ScrollViewPrivate::isActive() const -{ - Page* page = static_cast<const FrameView*>(m_view)->frame()->page(); - return page && page->focusController()->isActive(); -} - -ScrollView::ScrollView() - : m_data(new ScrollViewPrivate(this)) -{ -} - -ScrollView::~ScrollView() -{ - delete m_data; -} - -PlatformScrollbar *ScrollView::horizontalScrollBar() const -{ - return m_data->m_hBar.get(); -} - -PlatformScrollbar *ScrollView::verticalScrollBar() const -{ - return m_data->m_vBar.get(); -} - -void ScrollView::updateContents(const IntRect& rect, bool now) -{ - if (rect.isEmpty()) - return; - - IntPoint windowPoint = contentsToWindow(rect.location()); - IntRect containingWindowRect = rect; - containingWindowRect.setLocation(windowPoint); - - // Cache the dirty spot. - addToDirtyRegion(containingWindowRect); - - if (now) - updateBackingStore(); -} - -void ScrollView::update() -{ - QWidget* native = nativeWidget(); - if (native) { - native->update(); - return; - } - updateContents(IntRect(0, 0, width(), height())); -} - -int ScrollView::visibleWidth() const -{ - return width() - (m_data->m_vBar ? m_data->m_vBar->width() : 0); -} - -int ScrollView::visibleHeight() const -{ - return height() - (m_data->m_hBar ? m_data->m_hBar->height() : 0); -} - -FloatRect ScrollView::visibleContentRect() const -{ - return FloatRect(contentsX(), contentsY(), visibleWidth(), visibleHeight()); -} - -FloatRect ScrollView::visibleContentRectConsideringExternalScrollers() const -{ - // external scrollers not supported for now - return visibleContentRect(); -} - -void ScrollView::setContentsPos(int newX, int newY) -{ - int dx = newX - contentsX(); - int dy = newY - contentsY(); - scrollBy(dx, dy); -} - -void ScrollView::resizeContents(int w, int h) -{ - IntSize newContentsSize(w, h); - if (m_data->m_contentsSize != newContentsSize) { - m_data->m_contentsSize = newContentsSize; - updateScrollbars(m_data->m_scrollOffset); - } -} - -void ScrollView::setFrameGeometry(const IntRect& newGeometry) -{ - IntRect oldGeometry = frameGeometry(); - Widget::setFrameGeometry(newGeometry); - - if (newGeometry == oldGeometry) - return; - - if (newGeometry.width() != oldGeometry.width() || newGeometry.height() != oldGeometry.height()) { - updateScrollbars(m_data->m_scrollOffset); - static_cast<FrameView*>(this)->setNeedsLayout(); - } - - geometryChanged(); -} - -HashSet<Widget*>* ScrollView::children() -{ - return &(m_data->m_children); -} - -void ScrollView::geometryChanged() const -{ - HashSet<Widget*>::const_iterator end = m_data->m_children.end(); - for (HashSet<Widget*>::const_iterator current = m_data->m_children.begin(); current != end; ++current) - (*current)->geometryChanged(); -} - - -int ScrollView::contentsX() const -{ - return scrollOffset().width(); -} - -int ScrollView::contentsY() const -{ - return scrollOffset().height(); -} - -int ScrollView::contentsWidth() const -{ - return m_data->m_contentsSize.width(); -} - -int ScrollView::contentsHeight() const -{ - return m_data->m_contentsSize.height(); -} - -IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const -{ - IntPoint viewPoint = convertFromContainingWindow(windowPoint); - return viewPoint + scrollOffset(); -} - -IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const -{ - IntPoint viewPoint = contentsPoint - scrollOffset(); - return convertToContainingWindow(viewPoint); -} - -IntPoint ScrollView::convertChildToSelf(const Widget* child, const IntPoint& point) const -{ - IntPoint newPoint = point; - if (child != m_data->m_hBar && child != m_data->m_vBar) - newPoint = point - scrollOffset(); - return Widget::convertChildToSelf(child, newPoint); -} - -IntPoint ScrollView::convertSelfToChild(const Widget* child, const IntPoint& point) const -{ - IntPoint newPoint = point; - if (child != m_data->m_hBar && child != m_data->m_vBar) - newPoint = point + scrollOffset(); - return Widget::convertSelfToChild(child, newPoint); -} - -IntSize ScrollView::scrollOffset() const -{ - return m_data->m_scrollOffset; -} - -IntSize ScrollView::maximumScroll() const -{ - IntSize delta = (m_data->m_contentsSize - IntSize(visibleWidth(), visibleHeight())) - scrollOffset(); - delta.clampNegativeToZero(); - return delta; -} - -void ScrollView::scrollBy(int dx, int dy) -{ - IntSize scrollOffset = m_data->m_scrollOffset; - IntSize newScrollOffset = scrollOffset + IntSize(dx, dy).shrunkTo(maximumScroll()); - newScrollOffset.clampNegativeToZero(); - - if (newScrollOffset == scrollOffset) - return; - - updateScrollbars(newScrollOffset); -} - -void ScrollView::scrollRectIntoViewRecursively(const IntRect& r) -{ - IntPoint p(max(0, r.x()), max(0, r.y())); - ScrollView* view = this; - while (view) { - view->setContentsPos(p.x(), p.y()); - p.move(view->x() - view->scrollOffset().width(), view->y() - view->scrollOffset().height()); - view = static_cast<ScrollView*>(parent()); - } -} - -WebCore::ScrollbarMode ScrollView::hScrollbarMode() const -{ - return m_data->m_hScrollbarMode; -} - -WebCore::ScrollbarMode ScrollView::vScrollbarMode() const -{ - return m_data->m_vScrollbarMode; -} - -void ScrollView::suppressScrollbars(bool suppressed, bool repaintOnSuppress) +void ScrollView::platformInit() { - m_data->m_scrollbarsSuppressed = suppressed; - if (repaintOnSuppress && !suppressed) { - if (m_data->m_hBar) - m_data->m_hBar->invalidate(); - if (m_data->m_vBar) - m_data->m_vBar->invalidate(); - - // Invalidate the scroll corner too on unsuppress. - IntRect hCorner; - if (m_data->m_hBar && width() - m_data->m_hBar->width() > 0) { - hCorner = IntRect(m_data->m_hBar->width(), - height() - m_data->m_hBar->height(), - width() - m_data->m_hBar->width(), - m_data->m_hBar->height()); - invalidateRect(hCorner); - } - - if (m_data->m_vBar && height() - m_data->m_vBar->height() > 0) { - IntRect vCorner(width() - m_data->m_vBar->width(), - m_data->m_vBar->height(), - m_data->m_vBar->width(), - height() - m_data->m_vBar->height()); - if (vCorner != hCorner) - invalidateRect(vCorner); - } - } + m_widgetsThatPreventBlitting = 0; } -void ScrollView::setHScrollbarMode(ScrollbarMode newMode) +void ScrollView::platformDestroy() { - if (m_data->m_hScrollbarMode != newMode) { - m_data->m_hScrollbarMode = newMode; - updateScrollbars(m_data->m_scrollOffset); - } } -void ScrollView::setVScrollbarMode(ScrollbarMode newMode) +void ScrollView::platformAddChild(Widget* child) { - if (m_data->m_vScrollbarMode != newMode) { - m_data->m_vScrollbarMode = newMode; - updateScrollbars(m_data->m_scrollOffset); - } + root()->m_widgetsThatPreventBlitting++; + if (parent()) + parent()->platformAddChild(child); } -void ScrollView::setScrollbarsMode(ScrollbarMode newMode) +void ScrollView::platformRemoveChild(Widget* child) { - if (m_data->m_hScrollbarMode != newMode || - m_data->m_vScrollbarMode != newMode) { - m_data->m_hScrollbarMode = m_data->m_vScrollbarMode = newMode; - updateScrollbars(m_data->m_scrollOffset); - } -} - -void ScrollView::setStaticBackground(bool flag) -{ - m_data->m_hasStaticBackground = flag; -} - -bool ScrollView::inWindow() const -{ - return true; -} - -void ScrollView::updateScrollbars(const IntSize& desiredOffset) -{ - // Don't allow re-entrancy into this function. - if (m_data->m_inUpdateScrollbars) - return; - - // FIXME: This code is here so we don't have to fork FrameView.h/.cpp. - // In the end, FrameView should just merge with ScrollView. - if (static_cast<const FrameView*>(this)->frame()->prohibitsScrolling()) - return; - - m_data->m_inUpdateScrollbars = true; - - bool hasVerticalScrollbar = m_data->m_vBar; - bool hasHorizontalScrollbar = m_data->m_hBar; - bool oldHasVertical = hasVerticalScrollbar; - bool oldHasHorizontal = hasHorizontalScrollbar; - ScrollbarMode hScroll = m_data->m_hScrollbarMode; - ScrollbarMode vScroll = m_data->m_vScrollbarMode; - - const int cVerticalWidth = PlatformScrollbar::verticalScrollbarWidth(); - const int cHorizontalHeight = PlatformScrollbar::horizontalScrollbarHeight(); - - for (int pass = 0; pass < 2; pass++) { - bool scrollsVertically; - bool scrollsHorizontally; - - if (!m_data->m_scrollbarsSuppressed && (hScroll == ScrollbarAuto || vScroll == ScrollbarAuto)) { - // Do a layout if pending before checking if scrollbars are needed. - if (hasVerticalScrollbar != oldHasVertical || hasHorizontalScrollbar != oldHasHorizontal) - static_cast<FrameView*>(this)->layout(); - - scrollsVertically = (vScroll == ScrollbarAlwaysOn) || (vScroll == ScrollbarAuto && contentsHeight() > height()); - if (scrollsVertically) - scrollsHorizontally = (hScroll == ScrollbarAlwaysOn) || (hScroll == ScrollbarAuto && contentsWidth() + cVerticalWidth > width()); - else { - scrollsHorizontally = (hScroll == ScrollbarAlwaysOn) || (hScroll == ScrollbarAuto && contentsWidth() > width()); - if (scrollsHorizontally) - scrollsVertically = (vScroll == ScrollbarAlwaysOn) || (vScroll == ScrollbarAuto && contentsHeight() + cHorizontalHeight > height()); - } - } - else { - scrollsHorizontally = (hScroll == ScrollbarAuto) ? hasHorizontalScrollbar : (hScroll == ScrollbarAlwaysOn); - scrollsVertically = (vScroll == ScrollbarAuto) ? hasVerticalScrollbar : (vScroll == ScrollbarAlwaysOn); - } - - if (hasVerticalScrollbar != scrollsVertically) { - m_data->setHasVerticalScrollbar(scrollsVertically); - hasVerticalScrollbar = scrollsVertically; - } - - if (hasHorizontalScrollbar != scrollsHorizontally) { - m_data->setHasHorizontalScrollbar(scrollsHorizontally); - hasHorizontalScrollbar = scrollsHorizontally; - } - } - - // Set up the range (and page step/line step). - IntSize maxScrollPosition(contentsWidth() - visibleWidth(), contentsHeight() - visibleHeight()); - IntSize scroll = desiredOffset.shrunkTo(maxScrollPosition); - scroll.clampNegativeToZero(); - - QPoint scrollbarOffset; -#ifdef Q_WS_MAC - // On Mac, offset the scrollbars so they don't cover the grow box. Check if the window - // has a grow box, and then check if the bottom-right corner of the scroll view - // intersercts it. The calculations are done in global coordinates. - QWidget* contentWidget = containingWindow(); - if (contentWidget) { - QWidget* windowWidget = contentWidget->window(); - if (windowWidget) { - HIViewRef growBox = 0; - HIViewFindByID(HIViewGetRoot(HIViewGetWindow(HIViewRef(contentWidget->winId()))), kHIViewWindowGrowBoxID, &growBox); - const QPoint contentBr = contentWidget->mapToGlobal(QPoint(0,0)) + contentWidget->size(); - const QPoint windowBr = windowWidget->mapToGlobal(QPoint(0,0)) + windowWidget->size(); - const QPoint contentOffset = (windowBr - contentBr); - const int growBoxSize = 15; - const bool enableOffset = (growBox != 0 && contentOffset.x() >= 0 && contentOffset. y() >= 0); - scrollbarOffset = enableOffset ? QPoint(growBoxSize - qMin(contentOffset.x(), growBoxSize), - growBoxSize - qMin(contentOffset.y(), growBoxSize)) - : QPoint(0,0); - } - } -#endif - - if (m_data->m_hBar) { - int clientWidth = visibleWidth(); - m_data->m_hBar->setEnabled(contentsWidth() > clientWidth); - int pageStep = (clientWidth - PAGE_KEEP); - if (pageStep < 0) pageStep = clientWidth; - IntRect oldRect(m_data->m_hBar->frameGeometry()); - IntRect hBarRect = IntRect(0, - height() - m_data->m_hBar->height(), - width() - (m_data->m_vBar ? m_data->m_vBar->width() : scrollbarOffset.x()), - m_data->m_hBar->height()); - m_data->m_hBar->setRect(hBarRect); - if (!m_data->m_scrollbarsSuppressed && oldRect != m_data->m_hBar->frameGeometry()) - m_data->m_hBar->invalidate(); - - if (m_data->m_scrollbarsSuppressed) - m_data->m_hBar->setSuppressInvalidation(true); - m_data->m_hBar->setSteps(LINE_STEP, pageStep); - m_data->m_hBar->setProportion(clientWidth, contentsWidth()); - m_data->m_hBar->setValue(scroll.width()); - if (m_data->m_scrollbarsSuppressed) - m_data->m_hBar->setSuppressInvalidation(false); - } - - if (m_data->m_vBar) { - int clientHeight = visibleHeight(); - m_data->m_vBar->setEnabled(contentsHeight() > clientHeight); - int pageStep = (clientHeight - PAGE_KEEP); - if (pageStep < 0) pageStep = clientHeight; - IntRect oldRect(m_data->m_vBar->frameGeometry()); - IntRect vBarRect = IntRect(width() - m_data->m_vBar->width(), - 0, - m_data->m_vBar->width(), - height() - (m_data->m_hBar ? m_data->m_hBar->height() : scrollbarOffset.y())); - m_data->m_vBar->setRect(vBarRect); - if (!m_data->m_scrollbarsSuppressed && oldRect != m_data->m_vBar->frameGeometry()) - m_data->m_vBar->invalidate(); - - if (m_data->m_scrollbarsSuppressed) - m_data->m_vBar->setSuppressInvalidation(true); - m_data->m_vBar->setSteps(LINE_STEP, pageStep); - m_data->m_vBar->setProportion(clientHeight, contentsHeight()); - m_data->m_vBar->setValue(scroll.height()); - if (m_data->m_scrollbarsSuppressed) - m_data->m_vBar->setSuppressInvalidation(false); - } - - if (oldHasVertical != (m_data->m_vBar != 0) || oldHasHorizontal != (m_data->m_hBar != 0)) - geometryChanged(); - - // See if our offset has changed in a situation where we might not have scrollbars. - // This can happen when editing a body with overflow:hidden and scrolling to reveal selection. - // It can also happen when maximizing a window that has scrollbars (but the new maximized result - // does not). - IntSize scrollDelta = scroll - m_data->m_scrollOffset; - if (scrollDelta != IntSize()) { - m_data->m_scrollOffset = scroll; - m_data->scrollBackingStore(scrollDelta); - } - - m_data->m_inUpdateScrollbars = false; -} - -PlatformScrollbar* ScrollView::scrollbarUnderMouse(const PlatformMouseEvent& mouseEvent) -{ - IntPoint viewPoint = convertFromContainingWindow(mouseEvent.pos()); - if (m_data->m_hBar && m_data->m_hBar->frameGeometry().contains(viewPoint)) - return m_data->m_hBar.get(); - if (m_data->m_vBar && m_data->m_vBar->frameGeometry().contains(viewPoint)) - return m_data->m_vBar.get(); - return 0; -} - -void ScrollView::addChild(Widget* child) -{ - child->setParent(this); - m_data->m_children.add(child); -} - -void ScrollView::removeChild(Widget* child) -{ - child->setParent(0); + ASSERT(root()->m_widgetsThatPreventBlitting); + root()->m_widgetsThatPreventBlitting--; child->hide(); - m_data->m_children.remove(child); -} - -void ScrollView::paint(GraphicsContext* context, const IntRect& rect) -{ - // FIXME: This code is here so we don't have to fork FrameView.h/.cpp. - // In the end, FrameView should just merge with ScrollView. - ASSERT(isFrameView()); - - if (context->paintingDisabled()) - return; - - IntRect documentDirtyRect = rect; - - context->save(); - - context->translate(x(), y()); - documentDirtyRect.move(-x(), -y()); - - context->translate(-contentsX(), -contentsY()); - documentDirtyRect.move(contentsX(), contentsY()); - - documentDirtyRect.intersect(enclosingIntRect(visibleContentRect())); - context->clip(documentDirtyRect); - - static_cast<const FrameView*>(this)->frame()->paint(context, documentDirtyRect); - - context->restore(); - - // Now paint the scrollbars. - if (!m_data->m_scrollbarsSuppressed && (m_data->m_hBar || m_data->m_vBar)) { - context->save(); - IntRect scrollViewDirtyRect = rect; - scrollViewDirtyRect.intersect(frameGeometry()); - context->translate(x(), y()); - scrollViewDirtyRect.move(-x(), -y()); - if (m_data->m_hBar) - m_data->m_hBar->paint(context, scrollViewDirtyRect); - if (m_data->m_vBar) - m_data->m_vBar->paint(context, scrollViewDirtyRect); - - // Fill the scroll corner with white. - IntRect hCorner; - if (m_data->m_hBar && width() - m_data->m_hBar->width() > 0) { - hCorner = IntRect(m_data->m_hBar->width(), - height() - m_data->m_hBar->height(), - width() - m_data->m_hBar->width(), - m_data->m_hBar->height()); - if (hCorner.intersects(scrollViewDirtyRect)) - context->fillRect(hCorner, Color::white); - } - - if (m_data->m_vBar && height() - m_data->m_vBar->height() > 0) { - IntRect vCorner(width() - m_data->m_vBar->width(), - m_data->m_vBar->height(), - m_data->m_vBar->width(), - height() - m_data->m_vBar->height()); - if (vCorner != hCorner && vCorner.intersects(scrollViewDirtyRect)) - context->fillRect(vCorner, Color::white); - } - - context->restore(); - } -} - -void ScrollView::wheelEvent(PlatformWheelEvent& e) -{ - // Determine how much we want to scroll. If we can move at all, we will accept the event. - IntSize maxScrollDelta = maximumScroll(); - if ((e.deltaX() < 0 && maxScrollDelta.width() > 0) || - (e.deltaX() > 0 && scrollOffset().width() > 0) || - (e.deltaY() < 0 && maxScrollDelta.height() > 0) || - (e.deltaY() > 0 && scrollOffset().height() > 0)) - e.accept(); - - scrollBy(-e.deltaX() * LINE_STEP, -e.deltaY() * LINE_STEP); -} - -bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity) -{ - if (direction == ScrollUp || direction == ScrollDown) { - if (m_data->m_vBar) - return m_data->m_vBar->scroll(direction, granularity); - } else { - if (m_data->m_hBar) - return m_data->m_hBar->scroll(direction, granularity); - } - return false; -} - -IntRect ScrollView::windowResizerRect() -{ - ASSERT(isFrameView()); - const FrameView* frameView = static_cast<const FrameView*>(this); - Page* page = frameView->frame() ? frameView->frame()->page() : 0; - if (!page) - return IntRect(); - return page->chrome()->windowResizerRect(); -} - -bool ScrollView::resizerOverlapsContent() const -{ - return !m_data->m_scrollbarsAvoidingResizer; -} - -void ScrollView::adjustOverlappingScrollbarCount(int overlapDelta) -{ - int oldCount = m_data->m_scrollbarsAvoidingResizer; - m_data->m_scrollbarsAvoidingResizer += overlapDelta; - if (parent() && parent()->isFrameView()) - static_cast<FrameView*>(parent())->adjustOverlappingScrollbarCount(overlapDelta); - else if (!m_data->m_scrollbarsSuppressed) { - // If we went from n to 0 or from 0 to n and we're the outermost view, - // we need to invalidate the windowResizerRect(), since it will now need to paint - // differently. - if (oldCount > 0 && m_data->m_scrollbarsAvoidingResizer == 0 || - oldCount == 0 && m_data->m_scrollbarsAvoidingResizer > 0) - invalidateRect(windowResizerRect()); - } -} - -void ScrollView::setParent(ScrollView* parentView) -{ - if (!parentView && m_data->m_scrollbarsAvoidingResizer && parent() && parent()->isFrameView()) - static_cast<FrameView*>(parent())->adjustOverlappingScrollbarCount(false); - Widget::setParent(parentView); -} - -void ScrollView::addToDirtyRegion(const IntRect& containingWindowRect) -{ - ASSERT(isFrameView()); - const FrameView* frameView = static_cast<const FrameView*>(this); - Page* page = frameView->frame() ? frameView->frame()->page() : 0; - if (!page) - return; - page->chrome()->addToDirtyRegion(containingWindowRect); -} - -void ScrollView::scrollBackingStore(int dx, int dy, const IntRect& scrollViewRect, const IntRect& clipRect) -{ - ASSERT(isFrameView()); - const FrameView* frameView = static_cast<const FrameView*>(this); - Page* page = frameView->frame() ? frameView->frame()->page() : 0; - if (!page) - return; - page->chrome()->scrollBackingStore(dx, dy, scrollViewRect, clipRect); -} - -void ScrollView::updateBackingStore() -{ - ASSERT(isFrameView()); - const FrameView* frameView = static_cast<const FrameView*>(this); - Page* page = frameView->frame() ? frameView->frame()->page() : 0; - if (!page) - return; - page->chrome()->updateBackingStore(); } } diff --git a/WebCore/platform/qt/ScrollbarQt.cpp b/WebCore/platform/qt/ScrollbarQt.cpp new file mode 100644 index 0000000..2d65282 --- /dev/null +++ b/WebCore/platform/qt/ScrollbarQt.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net> + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "Scrollbar.h" + +#include "EventHandler.h" +#include "FrameView.h" +#include "Frame.h" +#include "GraphicsContext.h" +#include "IntRect.h" +#include "PlatformMouseEvent.h" +#include "ScrollbarTheme.h" + +#include <QApplication> +#include <QDebug> +#include <QPainter> +#include <QStyle> +#include <QMenu> + +using namespace std; + +namespace WebCore { + +bool Scrollbar::contextMenu(const PlatformMouseEvent& event) +{ +#ifndef QT_NO_CONTEXTMENU + bool horizontal = (m_orientation == HorizontalScrollbar); + + QMenu menu; + QAction* actScrollHere = menu.addAction(QCoreApplication::translate("QWebPage", "Scroll here")); + menu.addSeparator(); + + QAction* actScrollTop = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Left edge") : QCoreApplication::translate("QWebPage", "Top")); + QAction* actScrollBottom = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Right edge") : QCoreApplication::translate("QWebPage", "Bottom")); + menu.addSeparator(); + + QAction* actPageUp = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Page left") : QCoreApplication::translate("QWebPage", "Page up")); + QAction* actPageDown = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Page right") : QCoreApplication::translate("QWebPage", "Page down")); + menu.addSeparator(); + + QAction* actScrollUp = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Scroll left") : QCoreApplication::translate("QWebPage", "Scroll up")); + QAction* actScrollDown = menu.addAction(horizontal ? QCoreApplication::translate("QWebPage", "Scroll right") : QCoreApplication::translate("QWebPage", "Scroll down")); + + const QPoint globalPos = QPoint(event.globalX(), event.globalY()); + QAction* actionSelected = menu.exec(globalPos); + + if (actionSelected == 0) + /* Do nothing */ ; + else if (actionSelected == actScrollHere) { + const QPoint pos = convertFromContainingWindow(event.pos()); + moveThumb(horizontal ? pos.x() : pos.y()); + } else if (actionSelected == actScrollTop) + setValue(0); + else if (actionSelected == actScrollBottom) + setValue(maximum()); + else if (actionSelected == actPageUp) + scroll(horizontal ? ScrollLeft: ScrollUp, ScrollByPage, 1); + else if (actionSelected == actPageDown) + scroll(horizontal ? ScrollRight : ScrollDown, ScrollByPage, 1); + else if (actionSelected == actScrollUp) + scroll(horizontal ? ScrollLeft : ScrollUp, ScrollByLine, 1); + else if (actionSelected == actScrollDown) + scroll(horizontal ? ScrollRight : ScrollDown, ScrollByLine, 1); +#endif // QT_NO_CONTEXTMENU + return true; +} + +} + +// vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/ScrollbarThemeQt.cpp b/WebCore/platform/qt/ScrollbarThemeQt.cpp new file mode 100644 index 0000000..1995719 --- /dev/null +++ b/WebCore/platform/qt/ScrollbarThemeQt.cpp @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All Rights Reserved. + * Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net> + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScrollbarThemeQt.h" + +#include "GraphicsContext.h" +#include "PlatformMouseEvent.h" +#include "RenderThemeQt.h" +#include "Scrollbar.h" +#include "ScrollView.h" + +#include <QApplication> +#include <QDebug> +#include <QPainter> +#include <QStyle> +#include <QStyleOptionSlider> +#include <QMenu> + +namespace WebCore { + +ScrollbarTheme* ScrollbarTheme::nativeTheme() +{ + static ScrollbarThemeQt theme; + return &theme; +} + +ScrollbarThemeQt::~ScrollbarThemeQt() +{ +} + +static QStyle::SubControl scPart(const ScrollbarPart& part) +{ + switch (part) { + case NoPart: + return QStyle::SC_None; + case BackButtonStartPart: + case BackButtonEndPart: + return QStyle::SC_ScrollBarSubLine; + case BackTrackPart: + return QStyle::SC_ScrollBarSubPage; + case ThumbPart: + return QStyle::SC_ScrollBarSlider; + case ForwardTrackPart: + return QStyle::SC_ScrollBarAddPage; + case ForwardButtonStartPart: + case ForwardButtonEndPart: + return QStyle::SC_ScrollBarAddLine; + } + + return QStyle::SC_None; +} + +static ScrollbarPart scrollbarPart(const QStyle::SubControl& sc) +{ + switch (sc) { + case QStyle::SC_None: + return NoPart; + case QStyle::SC_ScrollBarSubLine: + return BackButtonStartPart; + case QStyle::SC_ScrollBarSubPage: + return BackTrackPart; + case QStyle::SC_ScrollBarSlider: + return ThumbPart; + case QStyle::SC_ScrollBarAddPage: + return ForwardTrackPart; + case QStyle::SC_ScrollBarAddLine: + return ForwardButtonStartPart; + } + return NoPart; +} + +static QStyleOptionSlider* styleOptionSlider(Scrollbar* scrollbar) +{ + static QStyleOptionSlider opt; + opt.rect = scrollbar->frameRect(); + opt.state = 0; + if (scrollbar->enabled()) + opt.state |= QStyle::State_Enabled; + if (scrollbar->controlSize() != RegularScrollbar) + opt.state |= QStyle::State_Mini; + opt.orientation = (scrollbar->orientation() == VerticalScrollbar) ? Qt::Vertical : Qt::Horizontal; + if (scrollbar->orientation() == HorizontalScrollbar) + opt.state |= QStyle::State_Horizontal; + opt.sliderValue = scrollbar->value(); + opt.sliderPosition = opt.sliderValue; + opt.pageStep = scrollbar->visibleSize(); + opt.singleStep = scrollbar->lineStep(); + opt.minimum = 0; + opt.maximum = qMax(0, scrollbar->maximum()); + ScrollbarPart pressedPart = scrollbar->pressedPart(); + ScrollbarPart hoveredPart = scrollbar->hoveredPart(); + if (pressedPart != NoPart) { + opt.activeSubControls = scPart(scrollbar->pressedPart()); + if (pressedPart == BackButtonStartPart || pressedPart == ForwardButtonStartPart || + pressedPart == BackButtonEndPart || pressedPart == ForwardButtonEndPart || + pressedPart == ThumbPart) + opt.state |= QStyle::State_Sunken; + } else + opt.activeSubControls = scPart(hoveredPart); + if (hoveredPart != NoPart) + opt.state |= QStyle::State_MouseOver; + return &opt; +} + +bool ScrollbarThemeQt::paint(Scrollbar* scrollbar, GraphicsContext* graphicsContext, const IntRect& damageRect) +{ + if (graphicsContext->updatingControlTints()) { + scrollbar->invalidateRect(damageRect); + return false; + } + + StylePainter p(graphicsContext); + if (!p.isValid()) + return true; + + p.painter->save(); + QStyleOptionSlider* opt = styleOptionSlider(scrollbar); + p.painter->setClipRect(opt->rect.intersected(damageRect)); + +#ifdef Q_WS_MAC + p.drawComplexControl(QStyle::CC_ScrollBar, *opt); +#else + const QPoint topLeft = opt->rect.topLeft(); + p.painter->translate(topLeft); + opt->rect.moveTo(QPoint(0, 0)); + + // The QStyle expects the background to be already filled + p.painter->fillRect(opt->rect, opt->palette.background()); + + p.drawComplexControl(QStyle::CC_ScrollBar, *opt); + opt->rect.moveTo(topLeft); +#endif + p.painter->restore(); + + return true; +} + +ScrollbarPart ScrollbarThemeQt::hitTest(Scrollbar* scrollbar, const PlatformMouseEvent& evt) +{ + QStyleOptionSlider* opt = styleOptionSlider(scrollbar); + const QPoint pos = scrollbar->convertFromContainingWindow(evt.pos()); + opt->rect.moveTo(QPoint(0, 0)); + QStyle::SubControl sc = QApplication::style()->hitTestComplexControl(QStyle::CC_ScrollBar, opt, pos, 0); + return scrollbarPart(sc); +} + +bool ScrollbarThemeQt::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt) +{ + // Middle click centers slider thumb (if supported) + return QApplication::style()->styleHint(QStyle::SH_ScrollBar_MiddleClickAbsolutePosition) && evt.button() == MiddleButton; +} + +void ScrollbarThemeQt::invalidatePart(Scrollbar* scrollbar, ScrollbarPart) +{ + // FIXME: Do more precise invalidation. + scrollbar->invalidate(); +} + +int ScrollbarThemeQt::scrollbarThickness(ScrollbarControlSize controlSize) +{ + QStyle* s = QApplication::style(); + QStyleOptionSlider o; + o.orientation = Qt::Vertical; + o.state &= ~QStyle::State_Horizontal; + if (controlSize != RegularScrollbar) + o.state |= QStyle::State_Mini; + return s->pixelMetric(QStyle::PM_ScrollBarExtent, &o, 0); +} + +int ScrollbarThemeQt::thumbPosition(Scrollbar* scrollbar) +{ + if (scrollbar->enabled()) + return (int)((float)scrollbar->currentPos() * (trackLength(scrollbar) - thumbLength(scrollbar)) / scrollbar->maximum()); + return 0; +} + +int ScrollbarThemeQt::thumbLength(Scrollbar* scrollbar) +{ + QStyleOptionSlider* opt = styleOptionSlider(scrollbar); + IntRect thumb = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, opt, QStyle::SC_ScrollBarSlider, 0); + return scrollbar->orientation() == HorizontalScrollbar ? thumb.width() : thumb.height(); +} + +int ScrollbarThemeQt::trackPosition(Scrollbar* scrollbar) +{ + QStyleOptionSlider* opt = styleOptionSlider(scrollbar); + IntRect track = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, opt, QStyle::SC_ScrollBarGroove, 0); + return scrollbar->orientation() == HorizontalScrollbar ? track.x() - scrollbar->x() : track.y() - scrollbar->y(); +} + +int ScrollbarThemeQt::trackLength(Scrollbar* scrollbar) +{ + QStyleOptionSlider* opt = styleOptionSlider(scrollbar); + IntRect track = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, opt, QStyle::SC_ScrollBarGroove, 0); + return scrollbar->orientation() == HorizontalScrollbar ? track.width() : track.height(); +} + +void ScrollbarThemeQt::paintScrollCorner(ScrollView* scrollView, GraphicsContext* context, const IntRect& rect) +{ + if (context->updatingControlTints()) { + scrollView->invalidateRect(rect); + return; + } + +#if QT_VERSION < 0x040500 + context->fillRect(rect, QApplication::palette().color(QPalette::Normal, QPalette::Window)); +#else + StylePainter p(context); + if (!p.isValid()) + return; + + QStyleOption option; + option.rect = rect; + p.drawPrimitive(QStyle::PE_PanelScrollAreaCorner, option); +#endif +} + +} + diff --git a/WebCore/platform/qt/ScrollbarThemeQt.h b/WebCore/platform/qt/ScrollbarThemeQt.h new file mode 100644 index 0000000..787b15a --- /dev/null +++ b/WebCore/platform/qt/ScrollbarThemeQt.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScrollbarThemeQt_h +#define ScrollbarThemeQt_h + +#include "ScrollbarTheme.h" + +namespace WebCore { + +class ScrollbarThemeQt : public ScrollbarTheme { +public: + virtual ~ScrollbarThemeQt(); + + virtual bool paint(Scrollbar*, GraphicsContext*, const IntRect& damageRect); + virtual void paintScrollCorner(ScrollView*, GraphicsContext*, const IntRect& cornerRect); + + virtual ScrollbarPart hitTest(Scrollbar*, const PlatformMouseEvent&); + + virtual bool shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent&); + + virtual void invalidatePart(Scrollbar*, ScrollbarPart); + + virtual int thumbPosition(Scrollbar*); + virtual int thumbLength(Scrollbar*); + virtual int trackPosition(Scrollbar*); + virtual int trackLength(Scrollbar*); + + virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar); +}; + +} +#endif diff --git a/WebCore/platform/qt/SharedBufferQt.cpp b/WebCore/platform/qt/SharedBufferQt.cpp new file mode 100644 index 0000000..38ba6d1 --- /dev/null +++ b/WebCore/platform/qt/SharedBufferQt.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2008 Holger Hans Peter Freyther + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "SharedBuffer.h" + +#include <QFile> + +namespace WebCore { + +PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& fileName) +{ + if (fileName.isEmpty()) + return 0; + + QFile file(fileName); + if (!file.exists() || !file.open(QFile::ReadOnly)) + return 0; + + + RefPtr<SharedBuffer> result = SharedBuffer::create(); + result->m_buffer.resize(file.size()); + if (result->m_buffer.size() != file.size()) + return 0; + + file.read(result->m_buffer.data(), result->m_buffer.size()); + return result.release(); +} + +} diff --git a/WebCore/platform/qt/SharedTimerQt.h b/WebCore/platform/qt/SharedTimerQt.h index 89b03e2..30e1e21 100644 --- a/WebCore/platform/qt/SharedTimerQt.h +++ b/WebCore/platform/qt/SharedTimerQt.h @@ -32,6 +32,7 @@ #include "SystemTime.h" #include <QTimer> +#include <QCoreApplication> namespace WebCore { @@ -51,10 +52,21 @@ protected: } public: + static void cleanup() + { + if (s_self->isActive()) + s_self->fire(); + + delete s_self; + s_self = 0; + } + static SharedTimerQt* inst() { - if (!s_self) + if (!s_self) { s_self = new SharedTimerQt(); + qAddPostRoutine(SharedTimerQt::cleanup); + } return s_self; } diff --git a/WebCore/platform/qt/TemporaryLinkStubs.cpp b/WebCore/platform/qt/TemporaryLinkStubs.cpp index 817491e..f262684 100644 --- a/WebCore/platform/qt/TemporaryLinkStubs.cpp +++ b/WebCore/platform/qt/TemporaryLinkStubs.cpp @@ -4,6 +4,7 @@ * Copyright (C) 2006 George Staikos <staikos@kde.org> * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Collabora, Ltd. * * All rights reserved. * @@ -32,6 +33,7 @@ #include "config.h" #include "AXObjectCache.h" +#include "DNS.h" #include "CString.h" #include "CachedResource.h" #include "CookieJar.h" @@ -48,7 +50,6 @@ #include "FileSystem.h" #include "FrameView.h" #include "GraphicsContext.h" -#include "GlobalHistory.h" #include "IconLoader.h" #include "IntPoint.h" #include "KURL.h" @@ -59,7 +60,9 @@ #include "NotImplemented.h" #include "Path.h" #include "PlatformMouseEvent.h" -#include "PluginInfoStore.h" +#include "PluginDatabase.h" +#include "PluginPackage.h" +#include "PluginView.h" #include "RenderTheme.h" #include "SharedBuffer.h" #include "SystemTime.h" @@ -67,24 +70,47 @@ #include "Widget.h" #include <stdio.h> #include <stdlib.h> +#include <float.h> using namespace WebCore; +#if !defined(Q_WS_X11) && !defined(Q_WS_WIN) + +bool PluginPackage::fetchInfo() { notImplemented(); return false; } +unsigned PluginPackage::hash() const { notImplemented(); return 0; } +bool PluginPackage::equal(const PluginPackage&, const PluginPackage&) { notImplemented(); return false; } +int PluginPackage::compareFileVersion(const PlatformModuleVersion&) const { notImplemented(); return -1; } + +void PluginView::setNPWindowRect(const IntRect&) { notImplemented(); } +const char* PluginView::userAgent() { notImplemented(); return 0; } +void PluginView::invalidateRect(NPRect*) { notImplemented(); } +void PluginView::invalidateRegion(NPRegion) { notImplemented(); } +void PluginView::forceRedraw() { notImplemented(); } +void PluginView::setFocus() { Widget::setFocus(); } +void PluginView::show() { Widget::show(); } +void PluginView::hide() { Widget::hide(); } +void PluginView::paint(GraphicsContext*, const IntRect&) { notImplemented(); } +void PluginView::setParent(ScrollView* view) { Widget::setParent(view); } +void PluginView::setParentVisible(bool) { notImplemented(); } +void PluginView::updatePluginWidget() const { notImplemented(); } +void PluginView::handleKeyboardEvent(KeyboardEvent*) { notImplemented(); } +void PluginView::handleMouseEvent(MouseEvent*) { notImplemented(); } +NPError PluginView::handlePostReadFile(Vector<char>&, uint32, const char*) { notImplemented(); return NPERR_GENERIC_ERROR; } +NPError PluginView::getValue(NPNVariable, void*) { notImplemented(); return NPERR_GENERIC_ERROR; } +PluginView::~PluginView() {} +#endif + namespace WebCore { -Vector<String> supportedKeySizes() { notImplemented(); return Vector<String>(); } +void getSupportedKeySizes(Vector<String>&) { notImplemented(); } String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String &challengeString, const KURL &url) { return String(); } -CString openTemporaryFile(const char* prefix, PlatformFileHandle& handle) { notImplemented(); handle = invalidPlatformFileHandle; return 0; } -void closeFile(PlatformFileHandle&) { notImplemented(); }; -int writeToFile(PlatformFileHandle, const char* data, int length) { return -1; }; - #if !defined(Q_OS_WIN) // defined in win/SystemTimeWin.cpp, which is compiled for the Qt/Windows port -float userIdleTime() { notImplemented(); return 0.0; } +float userIdleTime() { notImplemented(); return FLT_MAX; } // return an arbitrarily high userIdleTime so that releasing pages from the page cache isn't postponed #endif -PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String&) { notImplemented(); return 0; } +void prefetchDNS(const String& hostname) { notImplemented(); } } diff --git a/WebCore/platform/qt/ThreadingQt.cpp b/WebCore/platform/qt/ThreadingQt.cpp deleted file mode 100644 index 71cd17e..0000000 --- a/WebCore/platform/qt/ThreadingQt.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2007 Staikos Computing Services Inc. - * Copyright (C) 2007 Trolltech ASA - * Copyright (C) 2008 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "Threading.h" - -#include <QtCore/QObject> -#include <QtCore/QCoreApplication> - - -namespace WebCore { - -class PerformFunctionEvent : public QEvent { -public: - static const int EventType = 723; - - PerformFunctionEvent(MainThreadFunction*, void* context); - - void invoke(); - -private: - MainThreadFunction* m_function; - void* m_context; -}; - -class MainThreadInvoker : public QObject { - Q_OBJECT -public: - MainThreadInvoker(); - -protected: - bool event(QEvent*); -}; - -PerformFunctionEvent::PerformFunctionEvent(MainThreadFunction* function, void* context) - : QEvent(static_cast<QEvent::Type>(EventType)) - , m_function(function) - , m_context(context) -{ -} - -void PerformFunctionEvent::invoke() -{ - m_function(m_context); -} - -MainThreadInvoker::MainThreadInvoker() -{ - moveToThread(QCoreApplication::instance()->thread()); -} - -bool MainThreadInvoker::event(QEvent* event) -{ - if (event->type() == PerformFunctionEvent::EventType) - static_cast<PerformFunctionEvent*>(event)->invoke(); - - return QObject::event(event); -} - -Q_GLOBAL_STATIC(MainThreadInvoker, webkit_main_thread_invoker) - - -void callOnMainThread(MainThreadFunction* function, void* context) -{ - QCoreApplication::postEvent(webkit_main_thread_invoker(), new PerformFunctionEvent(function, context)); -} - -} - -#include "ThreadingQt.moc" diff --git a/WebCore/platform/qt/WebCoreResources.qrc b/WebCore/platform/qt/WebCoreResources.qrc new file mode 100644 index 0000000..e42cd7f --- /dev/null +++ b/WebCore/platform/qt/WebCoreResources.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/webcore/resources"> + <file>html4-adjustments-qt.css</file> +</qresource> +</RCC>
\ No newline at end of file diff --git a/WebCore/platform/qt/WheelEventQt.cpp b/WebCore/platform/qt/WheelEventQt.cpp index 307e007..135f15a 100644 --- a/WebCore/platform/qt/WheelEventQt.cpp +++ b/WebCore/platform/qt/WheelEventQt.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2007 Trolltech ASA + Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -15,9 +15,6 @@ along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - This class provides all functionality needed for loading images, style sheets and html - pages from the web. It has a memory cache for these objects. */ #include "config.h" @@ -29,15 +26,21 @@ namespace WebCore { + PlatformWheelEvent::PlatformWheelEvent(QWheelEvent* e) +#ifdef QT_NO_WHEELEVENT +{ + Q_UNUSED(e); +} +#else : m_position(e->pos()) , m_globalPosition(e->globalPos()) + , m_granularity(ScrollByLineWheelEvent) , m_isAccepted(false) , m_shiftKey(e->modifiers() & Qt::ShiftModifier) , m_ctrlKey(e->modifiers() & Qt::ControlModifier) , m_altKey(e->modifiers() & Qt::AltModifier) , m_metaKey(e->modifiers() & Qt::MetaModifier) - , m_isContinuous(false) { if (e->orientation() == Qt::Horizontal) { m_deltaX = (e->delta() / 120); @@ -46,6 +49,11 @@ PlatformWheelEvent::PlatformWheelEvent(QWheelEvent* e) m_deltaX = 0; m_deltaY = (e->delta() / 120); } + + // FIXME: retrieve the user setting for the number of lines to scroll on each wheel event + m_deltaX *= horizontalLineMultiplier(); + m_deltaY *= verticalLineMultiplier(); } +#endif // QT_NO_WHEELEVENT } // namespace WebCore diff --git a/WebCore/platform/qt/WidgetQt.cpp b/WebCore/platform/qt/WidgetQt.cpp index f73bc03..68cf383 100644 --- a/WebCore/platform/qt/WidgetQt.cpp +++ b/WebCore/platform/qt/WidgetQt.cpp @@ -3,6 +3,7 @@ * Copyright (C) 2006 George Stiakos <staikos@kde.org> * Copyright (C) 2006 Zack Rusin <zack@kde.org> * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Holger Hans Peter Freyther * * All rights reserved. * @@ -32,18 +33,18 @@ #include "Cursor.h" #include "Font.h" -#include "FrameView.h" #include "GraphicsContext.h" +#include "HostWindow.h" #include "IntRect.h" -#include "RenderObject.h" #include "ScrollView.h" #include "Widget.h" -#include "WidgetClient.h" -#include "PlatformScrollBar.h" #include "NotImplemented.h" #include "qwebframe.h" +#include "qwebframe_p.h" #include "qwebpage.h" + +#include <QCoreApplication> #include <QPainter> #include <QPaintEngine> @@ -51,61 +52,26 @@ namespace WebCore { -struct WidgetPrivate -{ - WidgetPrivate() - : m_client(0) - , enabled(true) - , suppressInvalidation(false) - , m_widget(0) - , m_webFrame(0) - , m_parentScrollView(0) { } - ~WidgetPrivate() { delete m_webFrame; } - - WidgetClient* m_client; - - bool enabled; - bool suppressInvalidation; - QRect m_geometry; - QWidget *m_widget; //for plugins - QWebFrame *m_webFrame; - ScrollView *m_parentScrollView; -}; - -Widget::Widget() - : data(new WidgetPrivate()) +Widget::Widget(QWidget* widget) { + init(widget); } Widget::~Widget() { Q_ASSERT(!parent()); - delete data; - data = 0; -} - -void Widget::setClient(WidgetClient* c) -{ - data->m_client = c; -} - -WidgetClient* Widget::client() const -{ - return data->m_client; } -IntRect Widget::frameGeometry() const +IntRect Widget::frameRect() const { - if (data->m_widget) - data->m_widget->geometry(); - return data->m_geometry; + return m_frame; } -void Widget::setFrameGeometry(const IntRect& r) +void Widget::setFrameRect(const IntRect& rect) { - if (data->m_widget) - data->m_widget->setGeometry(r); - data->m_geometry = r; + if (platformWidget()) + platformWidget()->setGeometry(convertToContainingWindow(IntRect(0, 0, rect.width(), rect.height()))); + m_frame = rect; } void Widget::setFocus() @@ -115,200 +81,32 @@ void Widget::setFocus() void Widget::setCursor(const Cursor& cursor) { #ifndef QT_NO_CURSOR - if (QWidget* widget = containingWindow()) - widget->setCursor(cursor.impl()); + if (QWidget* widget = root()->hostWindow()->platformWindow()) + QCoreApplication::postEvent(widget, new SetCursorEvent(cursor.impl())); #endif } void Widget::show() { - if (data->m_widget) - data->m_widget->show(); + if (platformWidget()) + platformWidget()->show(); } void Widget::hide() { - if (data->m_widget) - data->m_widget->hide(); -} - -QWebFrame* Widget::qwebframe() const -{ - return data->m_webFrame; -} - -void Widget::setQWebFrame(QWebFrame* webFrame) -{ - data->m_webFrame = webFrame; -} - -QWidget* Widget::nativeWidget() const -{ - return data->m_widget; -} - -void Widget::setNativeWidget(QWidget *widget) -{ - data->m_widget = widget; + if (platformWidget()) + platformWidget()->hide(); } void Widget::paint(GraphicsContext *, const IntRect &rect) { } -bool Widget::isEnabled() const -{ - if (data->m_widget) - return data->m_widget->isEnabled(); - return data->enabled; -} - -void Widget::setEnabled(bool e) -{ - if (data->m_widget) - data->m_widget->setEnabled(e); - - if (e != data->enabled) { - data->enabled = e; - invalidate(); - } -} - void Widget::setIsSelected(bool) { notImplemented(); } -bool Widget::suppressInvalidation() const -{ - return data->suppressInvalidation; -} - -void Widget::setSuppressInvalidation(bool suppress) -{ - data->suppressInvalidation = suppress; -} - -void Widget::invalidate() -{ - invalidateRect(IntRect(0, 0, width(), height())); -} - -void Widget::invalidateRect(const IntRect& r) -{ - if (data->suppressInvalidation) - return; - - if (data->m_widget) { //plugins - data->m_widget->update(r); - return; - } - - if (!parent()) { - if (isFrameView()) - static_cast<FrameView*>(this)->addToDirtyRegion(r); - return; - } - - // Get the root widget. - ScrollView* outermostView = topLevel(); - if (!outermostView) - return; - - IntRect windowRect = convertToContainingWindow(r); - - // Get our clip rect and intersect with it to ensure we don't invalidate too much. - IntRect clipRect = windowClipRect(); - windowRect.intersect(clipRect); - - outermostView->addToDirtyRegion(windowRect); -} - -void Widget::removeFromParent() -{ - if (parent()) - parent()->removeChild(this); -} - -void Widget::setParent(ScrollView* sv) -{ - data->m_parentScrollView = sv; -} - -ScrollView* Widget::parent() const -{ - return data->m_parentScrollView; -} - -ScrollView* Widget::topLevel() const -{ - if (!data->m_parentScrollView) - return isFrameView() ? const_cast<ScrollView*>(static_cast<const ScrollView*>(this)) : 0; - ScrollView* topLevel = data->m_parentScrollView; - while (topLevel->data->m_parentScrollView) - topLevel = topLevel->data->m_parentScrollView; - return topLevel; -} - -QWidget *Widget::containingWindow() const -{ - ScrollView *topLevel = this->topLevel(); - if (!topLevel) - return 0; - QWidget *view = 0; - if (topLevel->data->m_webFrame) - view = topLevel->data->m_webFrame->page()->view(); - if (!view) - view = data->m_widget; - return view; -} - - -void Widget::geometryChanged() const -{ -} - -IntPoint Widget::convertToContainingWindow(const IntPoint& point) const -{ - IntPoint windowPoint = point; - for (const Widget *parentWidget = parent(), *childWidget = this; - parentWidget; - childWidget = parentWidget, parentWidget = parentWidget->parent()) { - IntPoint oldPoint = windowPoint; - windowPoint = parentWidget->convertChildToSelf(childWidget, oldPoint); - } - return windowPoint; -} - -IntPoint Widget::convertFromContainingWindow(const IntPoint& point) const -{ - IntPoint widgetPoint = point; - for (const Widget *parentWidget = parent(), *childWidget = this; - parentWidget; - childWidget = parentWidget, parentWidget = parentWidget->parent()) { - IntPoint oldPoint = widgetPoint; - widgetPoint = parentWidget->convertSelfToChild(childWidget, oldPoint); - } - return widgetPoint; -} - -IntRect Widget::convertToContainingWindow(const IntRect& rect) const -{ - IntRect convertedRect = rect; - convertedRect.setLocation(convertToContainingWindow(convertedRect.location())); - return convertedRect; -} - -IntPoint Widget::convertChildToSelf(const Widget* child, const IntPoint& point) const -{ - return IntPoint(point.x() + child->x(), point.y() + child->y()); -} - -IntPoint Widget::convertSelfToChild(const Widget* child, const IntPoint& point) const -{ - return IntPoint(point.x() - child->x(), point.y() - child->y()); -} - } // vim: ts=4 sw=4 et diff --git a/WebCore/platform/qt/html4-adjustments-qt.css b/WebCore/platform/qt/html4-adjustments-qt.css new file mode 100644 index 0000000..129c164 --- /dev/null +++ b/WebCore/platform/qt/html4-adjustments-qt.css @@ -0,0 +1,96 @@ +/* + * QtWebKit specific style sheet. + * + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +audio { + height: 34px; + width: 400px; +} + +audio::-webkit-media-controls-mute-button, video::-webkit-media-controls-mute-button { + left: auto; + right: 5px; + width: 12px; + height: 12px; + padding: 6px; + margin: 5px 0px; +} + +audio::-webkit-media-controls-play-button, video::-webkit-media-controls-play-button { + left: 5px; + width: 9px; + height: 12px; + padding: 6px 12px 6px 11px; + margin: 5px 0px; +} + +audio::-webkit-media-controls-time-display, video::-webkit-media-controls-time-display { + /* Since MediaControlElements are always created with a renderer we have to hide + the controls we don't use, so they don't mess up activation and event handling */ + left: 0px; + top: 0px; + width: 0px; + height: 0px; + + display: none; +} + +audio::-webkit-media-controls-timeline, video::-webkit-media-controls-timeline { + left: 42px; + right: 34px; + height: 12px; + padding: 6px 8px; + margin: 5px 0px; +} + +audio::-webkit-media-controls-seek-back-button, video::-webkit-media-controls-seek-back-button { + /* Since MediaControlElements are always created with a renderer we have to hide + the controls we don't use, so they don't mess up activation and event handling */ + left: 0px; + top: 0px; + width: 0px; + height: 0px; + + display: none; +} + +audio::-webkit-media-controls-seek-forward-button, video::-webkit-media-controls-seek-forward-button { + /* Since MediaControlElements are always created with a renderer we have to hide + the controls we don't use, so they don't mess up activation and event handling */ + left: 0px; + top: 0px; + width: 0px; + height: 0px; + + display: none; +} + +audio::-webkit-media-controls-fullscreen-button, video::-webkit-media-controls-fullscreen-button { + /* Since MediaControlElements are always created with a renderer we have to hide + the controls we don't use, so they don't mess up activation and event handling */ + left: 0px; + top: 0px; + width: 0px; + height: 0px; + + display: none; +} + |