diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 18:28:41 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 18:28:41 -0800 |
commit | 648161bb0edfc3d43db63caed5cc5213bc6cb78f (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /WebCore/platform/win | |
parent | a65af38181ac7d34544586bdb5cd004de93897ad (diff) | |
download | external_webkit-648161bb0edfc3d43db63caed5cc5213bc6cb78f.zip external_webkit-648161bb0edfc3d43db63caed5cc5213bc6cb78f.tar.gz external_webkit-648161bb0edfc3d43db63caed5cc5213bc6cb78f.tar.bz2 |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'WebCore/platform/win')
49 files changed, 0 insertions, 7918 deletions
diff --git a/WebCore/platform/win/BString.cpp b/WebCore/platform/win/BString.cpp deleted file mode 100644 index 618ecf3..0000000 --- a/WebCore/platform/win/BString.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) 2006, 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 - * 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 "BString.h" - -#include "AtomicString.h" -#include "KURL.h" -#include "PlatformString.h" -#include <tchar.h> -#include <windows.h> - -#if PLATFORM(CF) -#include <CoreFoundation/CoreFoundation.h> -#endif - -using namespace JSC; - -namespace WebCore { - -BString::BString() - : m_bstr(0) -{ -} - -BString::BString(const wchar_t* characters) -{ - if (!characters) - m_bstr = 0; - else - m_bstr = SysAllocString(characters); -} - -BString::BString(const wchar_t* characters, size_t length) -{ - if (!characters) - m_bstr = 0; - else - m_bstr = SysAllocStringLen(characters, length); -} - -BString::BString(const String& s) -{ - if (s.isNull()) - m_bstr = 0; - else - m_bstr = SysAllocStringLen(s.characters(), s.length()); -} - -BString::BString(const KURL& url) -{ - if (url.isNull()) - m_bstr = 0; - else - m_bstr = SysAllocStringLen(url.string().characters(), url.string().length()); -} - -BString::BString(const AtomicString& s) -{ - if (s.isNull()) - m_bstr = 0; - else - m_bstr = SysAllocStringLen(s.characters(), s.length()); -} - -BString::BString(const UString& s) -{ - if (s.isNull()) - m_bstr = 0; - else - m_bstr = SysAllocStringLen(s.data(), s.size()); -} - -#if PLATFORM(CF) -BString::BString(CFStringRef cfstr) - : m_bstr(0) -{ - if (!cfstr) - return; - - const UniChar* uniChars = CFStringGetCharactersPtr(cfstr); - if (uniChars) { - m_bstr = SysAllocStringLen((LPCTSTR)uniChars, CFStringGetLength(cfstr)); - return; - } - - CFIndex length = CFStringGetLength(cfstr); - m_bstr = SysAllocStringLen(0, length); - CFStringGetCharacters(cfstr, CFRangeMake(0, length), (UniChar*)m_bstr); - m_bstr[length] = 0; -} -#endif - -BString::~BString() -{ - SysFreeString(m_bstr); -} - -BString::BString(const BString& other) -{ - if (!other.m_bstr) - m_bstr = 0; - else - m_bstr = SysAllocString(other.m_bstr); -} - -void BString::adoptBSTR(BSTR bstr) -{ - if (m_bstr) - SysFreeString(m_bstr); - m_bstr = bstr; -} - -BString& BString::operator=(const BString& other) -{ - if (this != &other) - *this = other.m_bstr; - return *this; -} - -BString& BString::operator=(const BSTR& other) -{ - if (other != m_bstr) { - SysFreeString(m_bstr); - m_bstr = other ? SysAllocString(other) : 0; - } - - return *this; -} - -bool operator ==(const BString& a, const BString& b) -{ - if (SysStringLen((BSTR)a) != SysStringLen((BSTR)b)) - return false; - if (!(BSTR)a && !(BSTR)b) - return true; - if (!(BSTR)a || !(BSTR)b) - return false; - return !_tcscmp((BSTR)a, (BSTR)b); -} - -bool operator !=(const BString& a, const BString& b) -{ - return !(a==b); -} - -bool operator ==(const BString& a, BSTR b) -{ - if (SysStringLen((BSTR)a) != SysStringLen(b)) - return false; - if (!(BSTR)a && !b) - return true; - if (!(BSTR)a || !b) - return false; - return !_tcscmp((BSTR)a, b); -} - -bool operator !=(const BString& a, BSTR b) -{ - return !(a==b); -} - -bool operator ==(BSTR a, const BString& b) -{ - if (SysStringLen(a) != SysStringLen((BSTR)b)) - return false; - if (!a && !(BSTR)b) - return true; - if (!a || !(BSTR)b) - return false; - return !_tcscmp(a, (BSTR)b); -} - -bool operator !=(BSTR a, const BString& b) -{ - return !(a==b); -} - -} diff --git a/WebCore/platform/win/BString.h b/WebCore/platform/win/BString.h deleted file mode 100644 index c32a49d..0000000 --- a/WebCore/platform/win/BString.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2006, 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 - * 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 BString_h -#define BString_h - -#if PLATFORM(CF) -typedef const struct __CFString * CFStringRef; -#endif - -typedef wchar_t* BSTR; - -namespace JSC { - class UString; -} - -namespace WebCore { - - class AtomicString; - class KURL; - class String; - - class BString { - public: - BString(); - BString(const wchar_t*); - BString(const wchar_t*, size_t length); - BString(const String&); - BString(const AtomicString&); - BString(const KURL&); - BString(const JSC::UString&); -#if PLATFORM(CF) - BString(CFStringRef); -#endif - ~BString(); - - void adoptBSTR(BSTR); - - BString(const BString&); - BString& operator=(const BString&); - BString& operator=(const BSTR&); - - operator BSTR() const { return m_bstr; } - - BSTR release() { BSTR result = m_bstr; m_bstr = 0; return result; } - - private: - BSTR m_bstr; - }; - - bool operator ==(const BString&, const BString&); - bool operator !=(const BString&, const BString&); - bool operator ==(const BString&, BSTR); - bool operator !=(const BString&, BSTR); - bool operator ==(BSTR, const BString&); - bool operator !=(BSTR, const BString&); - -} - -#endif diff --git a/WebCore/platform/win/COMPtr.h b/WebCore/platform/win/COMPtr.h deleted file mode 100644 index 784495a..0000000 --- a/WebCore/platform/win/COMPtr.h +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (C) 2007 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 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 COMPtr_h -#define COMPtr_h - -#define NOMINMAX - -#include <guiddef.h> -#include <unknwn.h> -#include <WTF/Assertions.h> -#include <WTF/HashTraits.h> - -typedef long HRESULT; - -// FIXME: Should we put this into the WebCore namespace and use "using" on it -// as we do with things in WTF? - -enum AdoptCOMTag { AdoptCOM }; -enum QueryTag { Query }; -enum CreateTag { Create }; - -template <typename T> class COMPtr { -public: - COMPtr() : m_ptr(0) { } - COMPtr(T* ptr) : m_ptr(ptr) { if (m_ptr) m_ptr->AddRef(); } - COMPtr(AdoptCOMTag, T* ptr) : m_ptr(ptr) { } - COMPtr(const COMPtr& o) : m_ptr(o.m_ptr) { if (T* ptr = m_ptr) ptr->AddRef(); } - - COMPtr(QueryTag, IUnknown* ptr) : m_ptr(copyQueryInterfaceRef(ptr)) { } - template <typename U> COMPtr(QueryTag, const COMPtr<U>& ptr) : m_ptr(copyQueryInterfaceRef(ptr.get())) { } - - COMPtr(CreateTag, const IID& clsid) : m_ptr(createInstance(clsid)) { } - - // Hash table deleted values, which are only constructed and never copied or destroyed. - COMPtr(WTF::HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { } - bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue(); } - - ~COMPtr() { if (m_ptr) m_ptr->Release(); } - - T* get() const { return m_ptr; } - T* releaseRef() { T* tmp = m_ptr; m_ptr = 0; return tmp; } - - T& operator*() const { return *m_ptr; } - T* operator->() const { return m_ptr; } - - T** operator&() { ASSERT(!m_ptr); return &m_ptr; } - - bool operator!() const { return !m_ptr; } - - // This conversion operator allows implicit conversion to bool but not to other integer types. - typedef T* (COMPtr::*UnspecifiedBoolType)() const; - operator UnspecifiedBoolType() const { return m_ptr ? &COMPtr::get : 0; } - - COMPtr& operator=(const COMPtr&); - COMPtr& operator=(T*); - template <typename U> COMPtr& operator=(const COMPtr<U>&); - - void query(IUnknown* ptr) { adoptRef(copyQueryInterfaceRef(ptr)); } - template <typename U> void query(const COMPtr<U>& ptr) { query(ptr.get()); } - - void create(const IID& clsid) { adoptRef(createInstance(clsid)); } - - template <typename U> HRESULT copyRefTo(U**); - void adoptRef(T*); - -private: - static T* copyQueryInterfaceRef(IUnknown*); - static T* createInstance(const IID& clsid); - static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } - - T* m_ptr; -}; - -template <typename T> inline T* COMPtr<T>::createInstance(const IID& clsid) -{ - T* result; - if (FAILED(CoCreateInstance(clsid, 0, CLSCTX_ALL, __uuidof(result), reinterpret_cast<void**>(&result)))) - return 0; - return result; -} - -template <typename T> inline T* COMPtr<T>::copyQueryInterfaceRef(IUnknown* ptr) -{ - if (!ptr) - return 0; - T* result; - if (FAILED(ptr->QueryInterface(&result))) - return 0; - return result; -} - -template <typename T> template <typename U> inline HRESULT COMPtr<T>::copyRefTo(U** ptr) -{ - if (!ptr) - return E_POINTER; - *ptr = m_ptr; - if (m_ptr) - m_ptr->AddRef(); - return S_OK; -} - -template <typename T> inline void COMPtr<T>::adoptRef(T *ptr) -{ - if (m_ptr) - m_ptr->Release(); - m_ptr = ptr; -} - -template <typename T> inline COMPtr<T>& COMPtr<T>::operator=(const COMPtr<T>& o) -{ - T* optr = o.get(); - if (optr) - optr->AddRef(); - T* ptr = m_ptr; - m_ptr = optr; - if (ptr) - ptr->Release(); - return *this; -} - -template <typename T> template <typename U> inline COMPtr<T>& COMPtr<T>::operator=(const COMPtr<U>& o) -{ - T* optr = o.get(); - if (optr) - optr->AddRef(); - T* ptr = m_ptr; - m_ptr = optr; - if (ptr) - ptr->Release(); - return *this; -} - -template <typename T> inline COMPtr<T>& COMPtr<T>::operator=(T* optr) -{ - if (optr) - optr->AddRef(); - T* ptr = m_ptr; - m_ptr = optr; - if (ptr) - ptr->Release(); - return *this; -} - -template <typename T, typename U> inline bool operator==(const COMPtr<T>& a, const COMPtr<U>& b) -{ - return a.get() == b.get(); -} - -template <typename T, typename U> inline bool operator==(const COMPtr<T>& a, U* b) -{ - return a.get() == b; -} - -template <typename T, typename U> inline bool operator==(T* a, const COMPtr<U>& b) -{ - return a == b.get(); -} - -template <typename T, typename U> inline bool operator!=(const COMPtr<T>& a, const COMPtr<U>& b) -{ - return a.get() != b.get(); -} - -template <typename T, typename U> inline bool operator!=(const COMPtr<T>& a, U* b) -{ - return a.get() != b; -} - -template <typename T, typename U> inline bool operator!=(T* a, const COMPtr<U>& b) -{ - return a != b.get(); -} - -namespace WTF { - - template<typename P> struct HashTraits<COMPtr<P> > : GenericHashTraits<COMPtr<P> > { - static const bool emptyValueIsZero = true; - static void constructDeletedValue(COMPtr<P>& slot) { slot.releaseRef(); *&slot = reinterpret_cast<P*>(-1); } - static bool isDeletedValue(const COMPtr<P>& value) { return value == reinterpret_cast<P*>(-1); } - }; - - template<typename P> struct PtrHash<COMPtr<P> > : PtrHash<P*> { - using PtrHash<P*>::hash; - static unsigned hash(const COMPtr<P>& key) { return hash(key.get()); } - using PtrHash<P*>::equal; - static bool equal(const COMPtr<P>& a, const COMPtr<P>& b) { return a == b; } - static bool equal(P* a, const COMPtr<P>& b) { return a == b; } - static bool equal(const COMPtr<P>& a, P* b) { return a == b; } - }; - - template<typename P> struct DefaultHash<COMPtr<P> > { typedef PtrHash<COMPtr<P> > Hash; }; -} - -#endif diff --git a/WebCore/platform/win/ClipboardUtilitiesWin.cpp b/WebCore/platform/win/ClipboardUtilitiesWin.cpp deleted file mode 100644 index 3762a1a..0000000 --- a/WebCore/platform/win/ClipboardUtilitiesWin.cpp +++ /dev/null @@ -1,452 +0,0 @@ -/* - * 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 - * 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 "ClipboardUtilitiesWin.h" - -#include "CString.h" -#include "DocumentFragment.h" -#include "KURL.h" -#include "PlatformString.h" -#include "TextEncoding.h" -#include "markup.h" -#include <CoreFoundation/CoreFoundation.h> -#include <wtf/RetainPtr.h> -#include <shlwapi.h> -#include <wininet.h> // for INTERNET_MAX_URL_LENGTH - -namespace WebCore { - -FORMATETC* cfHDropFormat() -{ - static FORMATETC urlFormat = {CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -static bool getWebLocData(IDataObject* dataObject, String& url, String* title) -{ - bool succeeded = false; - WCHAR filename[MAX_PATH]; - WCHAR urlBuffer[INTERNET_MAX_URL_LENGTH]; - - STGMEDIUM medium; - if (FAILED(dataObject->GetData(cfHDropFormat(), &medium))) - return false; - - HDROP hdrop = (HDROP)GlobalLock(medium.hGlobal); - - if (!hdrop) - return false; - - if (!DragQueryFileW(hdrop, 0, filename, ARRAYSIZE(filename))) - goto exit; - - if (_wcsicmp(PathFindExtensionW(filename), L".url")) - goto exit; - - if (!GetPrivateProfileStringW(L"InternetShortcut", L"url", 0, urlBuffer, ARRAYSIZE(urlBuffer), filename)) - goto exit; - - if (title) { - PathRemoveExtension(filename); - *title = String((UChar*)filename); - } - - url = String((UChar*)urlBuffer); - succeeded = true; - -exit: - // Free up memory. - DragFinish(hdrop); - GlobalUnlock(medium.hGlobal); - return succeeded; -} - -static String extractURL(const String &inURL, String* title) -{ - String url = inURL; - int splitLoc = url.find('\n'); - if (splitLoc > 0) { - if (title) - *title = url.substring(splitLoc+1); - url.truncate(splitLoc); - } else if (title) - *title = url; - return url; -} - -//Firefox text/html -static FORMATETC* texthtmlFormat() -{ - static UINT cf = RegisterClipboardFormat(L"text/html"); - static FORMATETC texthtmlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &texthtmlFormat; -} - -HGLOBAL createGlobalData(const KURL& url, const String& title) -{ - String mutableURL(url.string()); - String mutableTitle(title); - SIZE_T size = mutableURL.length() + mutableTitle.length() + 2; // +1 for "\n" and +1 for null terminator - HGLOBAL cbData = ::GlobalAlloc(GPTR, size * sizeof(UChar)); - - if (cbData) { - PWSTR buffer = (PWSTR)::GlobalLock(cbData); - swprintf_s(buffer, size, L"%s\n%s", mutableURL.charactersWithNullTermination(), mutableTitle.charactersWithNullTermination()); - ::GlobalUnlock(cbData); - } - return cbData; -} - -HGLOBAL createGlobalData(const String& str) -{ - HGLOBAL globalData = ::GlobalAlloc(GPTR, (str.length() + 1) * sizeof(UChar)); - if (!globalData) - return 0; - UChar* buffer = static_cast<UChar*>(::GlobalLock(globalData)); - memcpy(buffer, str.characters(), str.length() * sizeof(UChar)); - buffer[str.length()] = 0; - ::GlobalUnlock(globalData); - return globalData; -} - -HGLOBAL createGlobalData(const Vector<char>& vector) -{ - HGLOBAL globalData = ::GlobalAlloc(GPTR, vector.size() + 1); - if (!globalData) - return 0; - char* buffer = static_cast<char*>(::GlobalLock(globalData)); - memcpy(buffer, vector.data(), vector.size()); - buffer[vector.size()] = 0; - ::GlobalUnlock(globalData); - return globalData; -} - -static void append(Vector<char>& vector, const char* string) -{ - vector.append(string, strlen(string)); -} - -static void append(Vector<char>& vector, const CString& string) -{ - vector.append(string.data(), string.length()); -} - -// Documentation for the CF_HTML format is available at http://msdn.microsoft.com/workshop/networking/clipboard/htmlclipboard.asp -void markupToCF_HTML(const String& markup, const String& srcURL, Vector<char>& result) -{ - if (markup.isEmpty()) - return; - - #define MAX_DIGITS 10 - #define MAKE_NUMBER_FORMAT_1(digits) MAKE_NUMBER_FORMAT_2(digits) - #define MAKE_NUMBER_FORMAT_2(digits) "%0" #digits "u" - #define NUMBER_FORMAT MAKE_NUMBER_FORMAT_1(MAX_DIGITS) - - const char* header = "Version:0.9\n" - "StartHTML:" NUMBER_FORMAT "\n" - "EndHTML:" NUMBER_FORMAT "\n" - "StartFragment:" NUMBER_FORMAT "\n" - "EndFragment:" NUMBER_FORMAT "\n"; - const char* sourceURLPrefix = "SourceURL:"; - - const char* startMarkup = "<HTML>\n<BODY>\n<!--StartFragment-->\n"; - const char* endMarkup = "\n<!--EndFragment-->\n</BODY>\n</HTML>"; - - CString sourceURLUTF8 = srcURL == blankURL() ? "" : srcURL.utf8(); - CString markupUTF8 = markup.utf8(); - - // calculate offsets - unsigned startHTMLOffset = strlen(header) - strlen(NUMBER_FORMAT) * 4 + MAX_DIGITS * 4; - if (sourceURLUTF8.length()) - startHTMLOffset += strlen(sourceURLPrefix) + sourceURLUTF8.length() + 1; - unsigned startFragmentOffset = startHTMLOffset + strlen(startMarkup); - unsigned endFragmentOffset = startFragmentOffset + markupUTF8.length(); - unsigned endHTMLOffset = endFragmentOffset + strlen(endMarkup); - - append(result, String::format(header, startHTMLOffset, endHTMLOffset, startFragmentOffset, endFragmentOffset).utf8()); - if (sourceURLUTF8.length()) { - append(result, sourceURLPrefix); - append(result, sourceURLUTF8); - result.append('\n'); - } - append(result, startMarkup); - append(result, markupUTF8); - append(result, endMarkup); - - #undef MAX_DIGITS - #undef MAKE_NUMBER_FORMAT_1 - #undef MAKE_NUMBER_FORMAT_2 - #undef NUMBER_FORMAT -} - -String urlToMarkup(const KURL& url, const String& title) -{ - Vector<UChar> markup; - append(markup, "<a href=\""); - append(markup, url.string()); - append(markup, "\">"); - append(markup, title); - append(markup, "</a>"); - return String::adopt(markup); -} - -void replaceNewlinesWithWindowsStyleNewlines(String& str) -{ - static const UChar Newline = '\n'; - static const char* const WindowsNewline("\r\n"); - str.replace(Newline, WindowsNewline); -} - -void replaceNBSPWithSpace(String& str) -{ - static const UChar NonBreakingSpaceCharacter = 0xA0; - static const UChar SpaceCharacter = ' '; - str.replace(NonBreakingSpaceCharacter, SpaceCharacter); -} - -FORMATETC* urlWFormat() -{ - static UINT cf = RegisterClipboardFormat(L"UniformResourceLocatorW"); - static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -FORMATETC* urlFormat() -{ - static UINT cf = RegisterClipboardFormat(L"UniformResourceLocator"); - static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -FORMATETC* plainTextFormat() -{ - static FORMATETC textFormat = {CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &textFormat; -} - -FORMATETC* plainTextWFormat() -{ - static FORMATETC textFormat = {CF_UNICODETEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &textFormat; -} - -FORMATETC* filenameWFormat() -{ - static UINT cf = RegisterClipboardFormat(L"FileNameW"); - static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -FORMATETC* filenameFormat() -{ - static UINT cf = RegisterClipboardFormat(L"FileName"); - static FORMATETC urlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &urlFormat; -} - -//MSIE HTML Format -FORMATETC* htmlFormat() -{ - static UINT cf = RegisterClipboardFormat(L"HTML Format"); - static FORMATETC htmlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &htmlFormat; -} - -FORMATETC* smartPasteFormat() -{ - static UINT cf = RegisterClipboardFormat(L"WebKit Smart Paste Format"); - static FORMATETC htmlFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &htmlFormat; -} - -static bool urlFromPath(CFStringRef path, String& url) -{ - if (!path) - return false; - - RetainPtr<CFURLRef> cfURL(AdoptCF, CFURLCreateWithFileSystemPath(0, path, kCFURLWindowsPathStyle, false)); - if (!cfURL) - return false; - - url = String(CFURLGetString(cfURL.get())); - return true; -} - -String getURL(IDataObject* dataObject, bool& success, String* title) -{ - STGMEDIUM store; - String url; - success = false; - if (getWebLocData(dataObject, url, title)) { - success = true; - return url; - } else if (SUCCEEDED(dataObject->GetData(urlWFormat(), &store))) { - //URL using unicode - UChar* data = (UChar*)GlobalLock(store.hGlobal); - url = extractURL(String(data), title); - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - success = true; - } else if (SUCCEEDED(dataObject->GetData(urlFormat(), &store))) { - //URL using ascii - char* data = (char*)GlobalLock(store.hGlobal); - url = extractURL(String(data), title); - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - success = true; - } else if (SUCCEEDED(dataObject->GetData(filenameWFormat(), &store))) { - //file using unicode - wchar_t* data = (wchar_t*)GlobalLock(store.hGlobal); - if (data && data[0] && (PathFileExists(data) || PathIsUNC(data))) { - RetainPtr<CFStringRef> pathAsCFString(AdoptCF, CFStringCreateWithCharacters(kCFAllocatorDefault, (const UniChar*)data, wcslen(data))); - if (urlFromPath(pathAsCFString.get(), url)) { - if (title) - *title = url; - success = true; - } - } - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - } else if (SUCCEEDED(dataObject->GetData(filenameFormat(), &store))) { - //filename using ascii - char* data = (char*)GlobalLock(store.hGlobal); - if (data && data[0] && (PathFileExistsA(data) || PathIsUNCA(data))) { - RetainPtr<CFStringRef> pathAsCFString(AdoptCF, CFStringCreateWithCString(kCFAllocatorDefault, data, kCFStringEncodingASCII)); - if (urlFromPath(pathAsCFString.get(), url)) { - if (title) - *title = url; - success = true; - } - } - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - } - return url; -} - -String getPlainText(IDataObject* dataObject, bool& success) -{ - STGMEDIUM store; - String text; - success = false; - if (SUCCEEDED(dataObject->GetData(plainTextWFormat(), &store))) { - //unicode text - UChar* data = (UChar*)GlobalLock(store.hGlobal); - text = String(data); - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - success = true; - } else if (SUCCEEDED(dataObject->GetData(plainTextFormat(), &store))) { - //ascii text - char* data = (char*)GlobalLock(store.hGlobal); - text = String(data); - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - success = true; - } else { - //If a file is dropped on the window, it does not provide either of the - //plain text formats, so here we try to forcibly get a url. - text = getURL(dataObject, success); - success = true; - } - return text; -} - -PassRefPtr<DocumentFragment> fragmentFromFilenames(Document*, const IDataObject*) -{ - //FIXME: We should be able to create fragments from files - return 0; -} - -bool containsFilenames(const IDataObject*) -{ - //FIXME: We'll want to update this once we can produce fragments from files - return false; -} - -//Convert a String containing CF_HTML formatted text to a DocumentFragment -PassRefPtr<DocumentFragment> fragmentFromCF_HTML(Document* doc, const String& cf_html) -{ - // obtain baseURL if present - String srcURLStr("sourceURL:"); - String srcURL; - unsigned lineStart = cf_html.find(srcURLStr, 0, false); - if (lineStart != -1) { - unsigned srcEnd = cf_html.find("\n", lineStart, false); - unsigned srcStart = lineStart+srcURLStr.length(); - String rawSrcURL = cf_html.substring(srcStart, srcEnd-srcStart); - replaceNBSPWithSpace(rawSrcURL); - srcURL = rawSrcURL.stripWhiteSpace(); - } - - // find the markup between "<!--StartFragment -->" and "<!--EndFragment -->", accounting for browser quirks - unsigned markupStart = cf_html.find("<html", 0, false); - unsigned tagStart = cf_html.find("startfragment", markupStart, false); - unsigned fragmentStart = cf_html.find('>', tagStart) + 1; - unsigned tagEnd = cf_html.find("endfragment", fragmentStart, false); - unsigned fragmentEnd = cf_html.reverseFind('<', tagEnd); - String markup = cf_html.substring(fragmentStart, fragmentEnd - fragmentStart).stripWhiteSpace(); - - return createFragmentFromMarkup(doc, markup, srcURL); -} - - -PassRefPtr<DocumentFragment> fragmentFromHTML(Document* doc, IDataObject* data) -{ - if (!doc || !data) - return 0; - - STGMEDIUM store; - String html; - String srcURL; - if (SUCCEEDED(data->GetData(htmlFormat(), &store))) { - //MS HTML Format parsing - char* data = (char*)GlobalLock(store.hGlobal); - SIZE_T dataSize = ::GlobalSize(store.hGlobal); - String cf_html(UTF8Encoding().decode(data, dataSize)); - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - if (PassRefPtr<DocumentFragment> fragment = fragmentFromCF_HTML(doc, cf_html)) - return fragment; - } - if (SUCCEEDED(data->GetData(texthtmlFormat(), &store))) { - //raw html - UChar* data = (UChar*)GlobalLock(store.hGlobal); - html = String(data); - GlobalUnlock(store.hGlobal); - ReleaseStgMedium(&store); - return createFragmentFromMarkup(doc, html, srcURL); - } - - return 0; -} - -bool containsHTML(IDataObject* data) -{ - return SUCCEEDED(data->QueryGetData(texthtmlFormat())) || SUCCEEDED(data->QueryGetData(htmlFormat())); -} - -} // namespace WebCore diff --git a/WebCore/platform/win/ClipboardUtilitiesWin.h b/WebCore/platform/win/ClipboardUtilitiesWin.h deleted file mode 100644 index a92a4bf..0000000 --- a/WebCore/platform/win/ClipboardUtilitiesWin.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2007 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 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 ClipboardUtilitiesWin_h -#define ClipboardUtilitiesWin_h - -#include "DragData.h" -#include <windows.h> - -namespace WebCore { - -class Document; -class KURL; -class String; - -HGLOBAL createGlobalData(const String&); -HGLOBAL createGlobalData(const Vector<char>&); -HGLOBAL createGlobalData(const KURL& url, const String& title); - -FORMATETC* urlWFormat(); -FORMATETC* urlFormat(); -FORMATETC* plainTextWFormat(); -FORMATETC* plainTextFormat(); -FORMATETC* filenameWFormat(); -FORMATETC* filenameFormat(); -FORMATETC* htmlFormat(); -FORMATETC* cfHDropFormat(); -FORMATETC* smartPasteFormat(); - -void markupToCF_HTML(const String& markup, const String& srcURL, Vector<char>& result); -String urlToMarkup(const KURL& url, const String& title); - -void replaceNewlinesWithWindowsStyleNewlines(String&); -void replaceNBSPWithSpace(String&); - -bool containsFilenames(const IDataObject*); -bool containsHTML(IDataObject*); - -PassRefPtr<DocumentFragment> fragmentFromFilenames(Document*, const IDataObject*); -PassRefPtr<DocumentFragment> fragmentFromHTML(Document*, IDataObject*); -PassRefPtr<DocumentFragment> fragmentFromCF_HTML(Document*, const String& cf_html); - -String getURL(IDataObject*, bool& success, String* title = 0); -String getPlainText(IDataObject*, bool& success); - -} // namespace WebCore - -#endif // ClipboardUtilitiesWin_h
\ No newline at end of file diff --git a/WebCore/platform/win/ClipboardWin.cpp b/WebCore/platform/win/ClipboardWin.cpp deleted file mode 100644 index 129d881..0000000 --- a/WebCore/platform/win/ClipboardWin.cpp +++ /dev/null @@ -1,767 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "ClipboardWin.h" - -#include "CString.h" -#include "CachedImage.h" -#include "ClipboardUtilitiesWin.h" -#include "Document.h" -#include "DragData.h" -#include "Editor.h" -#include "Element.h" -#include "EventHandler.h" -#include "Frame.h" -#include "FrameLoader.h" -#include "FrameView.h" -#include "HTMLNames.h" -#include "Image.h" -#include "MIMETypeRegistry.h" -#include "Page.h" -#include "Pasteboard.h" -#include "PlatformMouseEvent.h" -#include "PlatformString.h" -#include "Range.h" -#include "RenderImage.h" -#include "ResourceResponse.h" -#include "StringHash.h" -#include "WCDataObject.h" -#include "csshelper.h" -#include "markup.h" - -#include <shlwapi.h> -#include <wininet.h> - -#include <wtf/RefPtr.h> - -using namespace std; - -namespace WebCore { - -using namespace HTMLNames; - -// format string for -static const char szShellDotUrlTemplate[] = "[InternetShortcut]\r\nURL=%s\r\n"; - -// We provide the IE clipboard types (URL and Text), and the clipboard types specified in the WHATWG Web Applications 1.0 draft -// see http://www.whatwg.org/specs/web-apps/current-work/ Section 6.3.5.3 - -enum ClipboardDataType { ClipboardDataTypeNone, ClipboardDataTypeURL, ClipboardDataTypeText }; - -static ClipboardDataType clipboardTypeFromMIMEType(const String& type) -{ - String qType = type.stripWhiteSpace().lower(); - - // two special cases for IE compatibility - if (qType == "text" || qType == "text/plain" || qType.startsWith("text/plain;")) - return ClipboardDataTypeText; - if (qType == "url" || qType == "text/uri-list") - return ClipboardDataTypeURL; - - return ClipboardDataTypeNone; -} - -static inline FORMATETC* fileDescriptorFormat() -{ - static UINT cf = RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR); - static FORMATETC fileDescriptorFormat = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - return &fileDescriptorFormat; -} - -static inline FORMATETC* fileContentFormatZero() -{ - static UINT cf = RegisterClipboardFormat(CFSTR_FILECONTENTS); - static FORMATETC fileContentFormat = {cf, 0, DVASPECT_CONTENT, 0, TYMED_HGLOBAL}; - return &fileContentFormat; -} - -static inline void pathRemoveBadFSCharacters(PWSTR psz, size_t length) -{ - size_t writeTo = 0; - size_t readFrom = 0; - while (readFrom < length) { - UINT type = PathGetCharType(psz[readFrom]); - if (psz[readFrom] == 0 || type & (GCT_LFNCHAR | GCT_SHORTCHAR)) { - psz[writeTo++] = psz[readFrom]; - } - - readFrom++; - } - psz[writeTo] = 0; -} - -static String filesystemPathFromUrlOrTitle(const String& url, const String& title, TCHAR* extension, bool isLink) -{ - bool usedURL = false; - WCHAR fsPathBuffer[MAX_PATH + 1]; - fsPathBuffer[0] = 0; - int extensionLen = extension ? lstrlen(extension) : 0; - - if (!title.isEmpty()) { - size_t len = min<size_t>(title.length(), MAX_PATH - extensionLen); - CopyMemory(fsPathBuffer, title.characters(), len * sizeof(UChar)); - fsPathBuffer[len] = 0; - pathRemoveBadFSCharacters(fsPathBuffer, len); - } - - if (!lstrlen(fsPathBuffer)) { - DWORD len = MAX_PATH; - String nullTermURL = url; - usedURL = true; - if (UrlIsFileUrl((LPCWSTR)nullTermURL.charactersWithNullTermination()) - && SUCCEEDED(PathCreateFromUrl((LPCWSTR)nullTermURL.charactersWithNullTermination(), fsPathBuffer, &len, 0))) { - // When linking to a file URL we can trivially find the file name - PWSTR fn = PathFindFileName(fsPathBuffer); - if (fn && fn != fsPathBuffer) - lstrcpyn(fsPathBuffer, fn, lstrlen(fn) + 1); - } else { - // The filename for any content based drag should be the last element of - // the path. If we can't find it, or we're coming up with the name for a link - // we just use the entire url. - KURL kurl(url); - String lastComponent; - if (!isLink && !(lastComponent = kurl.lastPathComponent()).isEmpty()) { - len = min<DWORD>(MAX_PATH, lastComponent.length()); - CopyMemory(fsPathBuffer, lastComponent.characters(), len * sizeof(UChar)); - } else { - len = min<DWORD>(MAX_PATH, nullTermURL.length()); - CopyMemory(fsPathBuffer, nullTermURL.characters(), len * sizeof(UChar)); - } - fsPathBuffer[len] = 0; - pathRemoveBadFSCharacters(fsPathBuffer, len); - } - } - - if (!extension) - return String((UChar*)fsPathBuffer); - - if (!isLink && usedURL) { - PathRenameExtension(fsPathBuffer, extension); - return String((UChar*)fsPathBuffer); - } - - String result((UChar*)fsPathBuffer); - result += String((UChar*)extension); - return result; -} - -static HGLOBAL createGlobalURLContent(const String& url, int estimatedFileSize) -{ - HRESULT hr = S_OK; - HGLOBAL memObj = 0; - - char* fileContents; - char ansiUrl[INTERNET_MAX_URL_LENGTH + 1]; - // Used to generate the buffer. This is null terminated whereas the fileContents won't be. - char contentGenerationBuffer[INTERNET_MAX_URL_LENGTH + ARRAYSIZE(szShellDotUrlTemplate) + 1]; - - if (estimatedFileSize > 0 && estimatedFileSize > ARRAYSIZE(contentGenerationBuffer)) - return 0; - - int ansiUrlSize = ::WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)url.characters(), url.length(), ansiUrl, ARRAYSIZE(ansiUrl) - 1, 0, 0); - if (!ansiUrlSize) - return 0; - - ansiUrl[ansiUrlSize] = 0; - - int fileSize = (int) (ansiUrlSize+strlen(szShellDotUrlTemplate)-2); // -2 to remove the %s - ASSERT(estimatedFileSize < 0 || fileSize == estimatedFileSize); - - memObj = GlobalAlloc(GPTR, fileSize); - if (!memObj) - return 0; - - fileContents = (PSTR)GlobalLock(memObj); - - sprintf_s(contentGenerationBuffer, ARRAYSIZE(contentGenerationBuffer), szShellDotUrlTemplate, ansiUrl); - CopyMemory(fileContents, contentGenerationBuffer, fileSize); - - GlobalUnlock(memObj); - - return memObj; -} - -static HGLOBAL createGlobalImageFileContent(SharedBuffer* data) -{ - HGLOBAL memObj = GlobalAlloc(GPTR, data->size()); - if (!memObj) - return 0; - - char* fileContents = (PSTR)GlobalLock(memObj); - - CopyMemory(fileContents, data->data(), data->size()); - - GlobalUnlock(memObj); - - return memObj; -} - -static HGLOBAL createGlobalHDropContent(const KURL& url, String& fileName, SharedBuffer* data) -{ - if (fileName.isEmpty() || !data ) - return 0; - - WCHAR filePath[MAX_PATH]; - - if (url.isLocalFile()) { - String localPath = url.path(); - // windows does not enjoy a leading slash on paths - if (localPath[0] == '/') - localPath = localPath.substring(1); - LPCTSTR localPathStr = localPath.charactersWithNullTermination(); - if (wcslen(localPathStr) + 1 < MAX_PATH) - wcscpy_s(filePath, MAX_PATH, localPathStr); - else - return 0; - } else { - WCHAR tempPath[MAX_PATH]; - WCHAR extension[MAX_PATH]; - if (!::GetTempPath(ARRAYSIZE(tempPath), tempPath)) - return 0; - if (!::PathAppend(tempPath, fileName.charactersWithNullTermination())) - return 0; - LPCWSTR foundExtension = ::PathFindExtension(tempPath); - if (foundExtension) { - if (wcscpy_s(extension, MAX_PATH, foundExtension)) - return 0; - } else - *extension = 0; - ::PathRemoveExtension(tempPath); - for (int i = 1; i < 10000; i++) { - if (swprintf_s(filePath, MAX_PATH, TEXT("%s-%d%s"), tempPath, i, extension) == -1) - return 0; - if (!::PathFileExists(filePath)) - break; - } - HANDLE tempFileHandle = CreateFile(filePath, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (tempFileHandle == INVALID_HANDLE_VALUE) - return 0; - - // Write the data to this temp file. - DWORD written; - BOOL tempWriteSucceeded = WriteFile(tempFileHandle, data->data(), data->size(), &written, 0); - CloseHandle(tempFileHandle); - if (!tempWriteSucceeded) - return 0; - } - - SIZE_T dropFilesSize = sizeof(DROPFILES) + (sizeof(WCHAR) * (wcslen(filePath) + 2)); - HGLOBAL memObj = GlobalAlloc(GHND | GMEM_SHARE, dropFilesSize); - if (!memObj) - return 0; - - DROPFILES* dropFiles = (DROPFILES*) GlobalLock(memObj); - dropFiles->pFiles = sizeof(DROPFILES); - dropFiles->fWide = TRUE; - wcscpy((LPWSTR)(dropFiles + 1), filePath); - GlobalUnlock(memObj); - - return memObj; -} - -static HGLOBAL createGlobalUrlFileDescriptor(const String& url, const String& title, int& /*out*/ estimatedSize) -{ - HRESULT hr = S_OK; - HGLOBAL memObj = 0; - String fsPath; - memObj = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR)); - if (!memObj) - return 0; - - FILEGROUPDESCRIPTOR* fgd = (FILEGROUPDESCRIPTOR*)GlobalLock(memObj); - memset(fgd, 0, sizeof(FILEGROUPDESCRIPTOR)); - fgd->cItems = 1; - fgd->fgd[0].dwFlags = FD_FILESIZE; - int fileSize = ::WideCharToMultiByte(CP_ACP, 0, url.characters(), url.length(), 0, 0, 0, 0); - fileSize += strlen(szShellDotUrlTemplate) - 2; // -2 is for getting rid of %s in the template string - fgd->fgd[0].nFileSizeLow = fileSize; - estimatedSize = fileSize; - fsPath = filesystemPathFromUrlOrTitle(url, title, L".URL", true); - - if (fsPath.length() <= 0) { - GlobalUnlock(memObj); - GlobalFree(memObj); - return 0; - } - - int maxSize = min(fsPath.length(), ARRAYSIZE(fgd->fgd[0].cFileName)); - CopyMemory(fgd->fgd[0].cFileName, (LPCWSTR)fsPath.characters(), maxSize * sizeof(UChar)); - GlobalUnlock(memObj); - - return memObj; -} - - -static HGLOBAL createGlobalImageFileDescriptor(const String& url, const String& title, CachedImage* image) -{ - ASSERT_ARG(image, image); - ASSERT(image->image()->data()); - - HRESULT hr = S_OK; - HGLOBAL memObj = 0; - String fsPath; - memObj = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR)); - if (!memObj) - return 0; - - FILEGROUPDESCRIPTOR* fgd = (FILEGROUPDESCRIPTOR*)GlobalLock(memObj); - memset(fgd, 0, sizeof(FILEGROUPDESCRIPTOR)); - fgd->cItems = 1; - fgd->fgd[0].dwFlags = FD_FILESIZE; - fgd->fgd[0].nFileSizeLow = image->image()->data()->size(); - - String extension("."); - extension += WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType(image->response().mimeType()); - const String& preferredTitle = title.isEmpty() ? image->response().suggestedFilename() : title; - fsPath = filesystemPathFromUrlOrTitle(url, preferredTitle, extension.length() ? (TCHAR*)extension.charactersWithNullTermination() : 0, false); - - if (fsPath.length() <= 0) { - GlobalUnlock(memObj); - GlobalFree(memObj); - return 0; - } - - int maxSize = min(fsPath.length(), ARRAYSIZE(fgd->fgd[0].cFileName)); - CopyMemory(fgd->fgd[0].cFileName, (LPCWSTR)fsPath.characters(), maxSize * sizeof(UChar)); - GlobalUnlock(memObj); - - return memObj; -} - - -// writeFileToDataObject takes ownership of fileDescriptor and fileContent -static HRESULT writeFileToDataObject(IDataObject* dataObject, HGLOBAL fileDescriptor, HGLOBAL fileContent, HGLOBAL hDropContent) -{ - HRESULT hr = S_OK; - FORMATETC* fe; - STGMEDIUM medium = {0}; - medium.tymed = TYMED_HGLOBAL; - - if (!fileDescriptor || !fileContent) - goto exit; - - // Descriptor - fe = fileDescriptorFormat(); - - medium.hGlobal = fileDescriptor; - - if (FAILED(hr = dataObject->SetData(fe, &medium, TRUE))) - goto exit; - - // Contents - fe = fileContentFormatZero(); - medium.hGlobal = fileContent; - if (FAILED(hr = dataObject->SetData(fe, &medium, TRUE))) - goto exit; - - // HDROP - if (hDropContent) { - medium.hGlobal = hDropContent; - hr = dataObject->SetData(cfHDropFormat(), &medium, TRUE); - } - -exit: - if (FAILED(hr)) { - if (fileDescriptor) - GlobalFree(fileDescriptor); - if (fileContent) - GlobalFree(fileContent); - if (hDropContent) - GlobalFree(hDropContent); - } - return hr; -} - -ClipboardWin::ClipboardWin(bool isForDragging, IDataObject* dataObject, ClipboardAccessPolicy policy) - : Clipboard(policy, isForDragging) - , m_dataObject(dataObject) - , m_writableDataObject(0) -{ -} - -ClipboardWin::ClipboardWin(bool isForDragging, WCDataObject* dataObject, ClipboardAccessPolicy policy) - : Clipboard(policy, isForDragging) - , m_dataObject(dataObject) - , m_writableDataObject(dataObject) -{ -} - -ClipboardWin::~ClipboardWin() -{ -} - -static bool writeURL(WCDataObject *data, const KURL& url, String title, bool withPlainText, bool withHTML) -{ - ASSERT(data); - - if (url.isEmpty()) - return false; - - if (title.isEmpty()) { - title = url.lastPathComponent(); - if (title.isEmpty()) - title = url.host(); - } - - STGMEDIUM medium = {0}; - medium.tymed = TYMED_HGLOBAL; - - medium.hGlobal = createGlobalData(url, title); - bool success = false; - if (medium.hGlobal && FAILED(data->SetData(urlWFormat(), &medium, TRUE))) - ::GlobalFree(medium.hGlobal); - else - success = true; - - if (withHTML) { - Vector<char> cfhtmlData; - markupToCF_HTML(urlToMarkup(url, title), "", cfhtmlData); - medium.hGlobal = createGlobalData(cfhtmlData); - if (medium.hGlobal && FAILED(data->SetData(htmlFormat(), &medium, TRUE))) - ::GlobalFree(medium.hGlobal); - else - success = true; - } - - if (withPlainText) { - medium.hGlobal = createGlobalData(url.string()); - if (medium.hGlobal && FAILED(data->SetData(plainTextWFormat(), &medium, TRUE))) - ::GlobalFree(medium.hGlobal); - else - success = true; - } - - return success; -} - -void ClipboardWin::clearData(const String& type) -{ - //FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941> - ASSERT(isForDragging()); - if (policy() != ClipboardWritable || !m_writableDataObject) - return; - - ClipboardDataType dataType = clipboardTypeFromMIMEType(type); - - if (dataType == ClipboardDataTypeURL) { - m_writableDataObject->clearData(urlWFormat()->cfFormat); - m_writableDataObject->clearData(urlFormat()->cfFormat); - } - if (dataType == ClipboardDataTypeText) { - m_writableDataObject->clearData(plainTextFormat()->cfFormat); - m_writableDataObject->clearData(plainTextWFormat()->cfFormat); - } - -} - -void ClipboardWin::clearAllData() -{ - //FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941> - ASSERT(isForDragging()); - if (policy() != ClipboardWritable) - return; - - m_writableDataObject = 0; - WCDataObject::createInstance(&m_writableDataObject); - m_dataObject = m_writableDataObject; -} - -String ClipboardWin::getData(const String& type, bool& success) const -{ - success = false; - if (policy() != ClipboardReadable || !m_dataObject) { - return ""; - } - - ClipboardDataType dataType = clipboardTypeFromMIMEType(type); - if (dataType == ClipboardDataTypeText) - return getPlainText(m_dataObject.get(), success); - else if (dataType == ClipboardDataTypeURL) - return getURL(m_dataObject.get(), success); - - return ""; -} - -bool ClipboardWin::setData(const String& type, const String& data) -{ - // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941> - ASSERT(isForDragging()); - if (policy() != ClipboardWritable || !m_writableDataObject) - return false; - - ClipboardDataType winType = clipboardTypeFromMIMEType(type); - - if (winType == ClipboardDataTypeURL) - return WebCore::writeURL(m_writableDataObject.get(), KURL(data), String(), false, true); - - if (winType == ClipboardDataTypeText) { - STGMEDIUM medium = {0}; - medium.tymed = TYMED_HGLOBAL; - medium.hGlobal = createGlobalData(data); - if (!medium.hGlobal) - return false; - - if (FAILED(m_writableDataObject->SetData(plainTextWFormat(), &medium, TRUE))) { - ::GlobalFree(medium.hGlobal); - return false; - } - return true; - } - - return false; -} - -static void addMimeTypesForFormat(HashSet<String>& results, FORMATETC& format) -{ - // URL and Text are provided for compatibility with IE's model - if (format.cfFormat == urlFormat()->cfFormat || format.cfFormat == urlWFormat()->cfFormat) { - results.add("URL"); - results.add("text/uri-list"); - } - - if (format.cfFormat == plainTextWFormat()->cfFormat || format.cfFormat == plainTextFormat()->cfFormat) { - results.add("Text"); - results.add("text/plain"); - } -} - -// extensions beyond IE's API -HashSet<String> ClipboardWin::types() const -{ - HashSet<String> results; - if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable) - return results; - - if (!m_dataObject) - return results; - - COMPtr<IEnumFORMATETC> itr; - - if (FAILED(m_dataObject->EnumFormatEtc(0, &itr))) - return results; - - if (!itr) - return results; - - FORMATETC data; - - while (SUCCEEDED(itr->Next(1, &data, 0))) { - addMimeTypesForFormat(results, data); - } - - return results; -} - -void ClipboardWin::setDragImage(CachedImage* image, Node *node, const IntPoint &loc) -{ - if (policy() != ClipboardImageWritable && policy() != ClipboardWritable) - return; - - if (m_dragImage) - m_dragImage->removeClient(this); - m_dragImage = image; - if (m_dragImage) - m_dragImage->addClient(this); - - m_dragLoc = loc; - m_dragImageElement = node; -} - -void ClipboardWin::setDragImage(CachedImage* img, const IntPoint &loc) -{ - setDragImage(img, 0, loc); -} - -void ClipboardWin::setDragImageElement(Node *node, const IntPoint &loc) -{ - setDragImage(0, node, loc); -} - -DragImageRef ClipboardWin::createDragImage(IntPoint& loc) const -{ - HBITMAP result = 0; - //FIXME: Need to be able to draw element <rdar://problem/5015942> - if (m_dragImage) { - result = createDragImageFromImage(m_dragImage->image()); - loc = m_dragLoc; - } - return result; -} - -static String imageToMarkup(const String& url) -{ - String markup("<img src=\""); - markup.append(url); - markup.append("\"/>"); - return markup; -} - -static CachedImage* getCachedImage(Element* element) -{ - // Attempt to pull CachedImage from element - ASSERT(element); - RenderObject* renderer = element->renderer(); - if (!renderer || !renderer->isImage()) - return 0; - - RenderImage* image = static_cast<RenderImage*>(renderer); - if (image->cachedImage() && !image->cachedImage()->errorOccurred()) - return image->cachedImage(); - - return 0; -} - -static void writeImageToDataObject(IDataObject* dataObject, Element* element, const KURL& url) -{ - // Shove image data into a DataObject for use as a file - CachedImage* cachedImage = getCachedImage(element); - if (!cachedImage || !cachedImage->image() || !cachedImage->isLoaded()) - return; - - SharedBuffer* imageBuffer = cachedImage->image()->data(); - if (!imageBuffer || !imageBuffer->size()) - return; - - HGLOBAL imageFileDescriptor = createGlobalImageFileDescriptor(url.string(), element->getAttribute(altAttr), cachedImage); - if (!imageFileDescriptor) - return; - - HGLOBAL imageFileContent = createGlobalImageFileContent(imageBuffer); - if (!imageFileContent) { - GlobalFree(imageFileDescriptor); - return; - } - - String fileName = cachedImage->response().suggestedFilename(); - HGLOBAL hDropContent = createGlobalHDropContent(url, fileName, imageBuffer); - if (!hDropContent) { - GlobalFree(hDropContent); - return; - } - - writeFileToDataObject(dataObject, imageFileDescriptor, imageFileContent, hDropContent); -} - -void ClipboardWin::declareAndWriteDragImage(Element* element, const KURL& url, const String& title, Frame* frame) -{ - // Order is important here for Explorer's sake - if (!m_writableDataObject) - return; - WebCore::writeURL(m_writableDataObject.get(), url, title, true, false); - - writeImageToDataObject(m_writableDataObject.get(), element, url); - - AtomicString imageURL = element->getAttribute(srcAttr); - if (imageURL.isEmpty()) - return; - - String fullURL = frame->document()->completeURL(parseURL(imageURL)).string(); - if (fullURL.isEmpty()) - return; - STGMEDIUM medium = {0}; - medium.tymed = TYMED_HGLOBAL; - ExceptionCode ec = 0; - - // Put img tag on the clipboard referencing the image - Vector<char> data; - markupToCF_HTML(imageToMarkup(fullURL), "", data); - medium.hGlobal = createGlobalData(data); - if (medium.hGlobal && FAILED(m_writableDataObject->SetData(htmlFormat(), &medium, TRUE))) - ::GlobalFree(medium.hGlobal); -} - -void ClipboardWin::writeURL(const KURL& kurl, const String& titleStr, Frame*) -{ - if (!m_writableDataObject) - return; - WebCore::writeURL(m_writableDataObject.get(), kurl, titleStr, true, true); - - int estimatedSize = 0; - String url = kurl.string(); - - HGLOBAL urlFileDescriptor = createGlobalUrlFileDescriptor(url, titleStr, estimatedSize); - if (!urlFileDescriptor) - return; - HGLOBAL urlFileContent = createGlobalURLContent(url, estimatedSize); - if (!urlFileContent) { - GlobalFree(urlFileDescriptor); - return; - } - writeFileToDataObject(m_writableDataObject.get(), urlFileDescriptor, urlFileContent, 0); -} - -void ClipboardWin::writeRange(Range* selectedRange, Frame* frame) -{ - ASSERT(selectedRange); - if (!m_writableDataObject) - return; - - STGMEDIUM medium = {0}; - medium.tymed = TYMED_HGLOBAL; - ExceptionCode ec = 0; - - Vector<char> data; - markupToCF_HTML(createMarkup(selectedRange, 0, AnnotateForInterchange), - selectedRange->startContainer(ec)->document()->url().string(), data); - medium.hGlobal = createGlobalData(data); - if (medium.hGlobal && FAILED(m_writableDataObject->SetData(htmlFormat(), &medium, TRUE))) - ::GlobalFree(medium.hGlobal); - - String str = frame->selectedText(); - replaceNewlinesWithWindowsStyleNewlines(str); - replaceNBSPWithSpace(str); - medium.hGlobal = createGlobalData(str); - if (medium.hGlobal && FAILED(m_writableDataObject->SetData(plainTextWFormat(), &medium, TRUE))) - ::GlobalFree(medium.hGlobal); - - medium.hGlobal = 0; - if (frame->editor()->canSmartCopyOrDelete()) - m_writableDataObject->SetData(smartPasteFormat(), &medium, TRUE); -} - -bool ClipboardWin::hasData() -{ - if (!m_dataObject) - return false; - - COMPtr<IEnumFORMATETC> itr; - if (FAILED(m_dataObject->EnumFormatEtc(0, &itr))) - return false; - - if (!itr) - return false; - - FORMATETC data; - - if (SUCCEEDED(itr->Next(1, &data, 0))) { - // There is at least one item in the IDataObject - return true; - } - - return false; -} - -} // namespace WebCore diff --git a/WebCore/platform/win/ClipboardWin.h b/WebCore/platform/win/ClipboardWin.h deleted file mode 100644 index 01f7332..0000000 --- a/WebCore/platform/win/ClipboardWin.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2006, 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 - * 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 ClipboardWin_h -#define ClipboardWin_h - -#include "CachedResourceClient.h" -#include "Clipboard.h" -#include "COMPtr.h" - -struct IDataObject; - -namespace WebCore { - - class CachedImage; - class IntPoint; - class WCDataObject; - - // State available during IE's events for drag and drop and copy/paste - class ClipboardWin : public Clipboard, public CachedResourceClient { - public: - static PassRefPtr<ClipboardWin> create(bool isForDragging, IDataObject* dataObject, ClipboardAccessPolicy policy) - { - return adoptRef(new ClipboardWin(isForDragging, dataObject, policy)); - } - static PassRefPtr<ClipboardWin> create(bool isForDragging, WCDataObject* dataObject, ClipboardAccessPolicy policy) - { - return adoptRef(new ClipboardWin(isForDragging, dataObject, policy)); - } - ~ClipboardWin(); - - void clearData(const String& type); - void clearAllData(); - String getData(const String& type, bool& success) const; - bool setData(const String& type, const String& data); - - // extensions beyond IE's API - HashSet<String> types() const; - - void setDragImage(CachedImage*, const IntPoint&); - void setDragImageElement(Node*, const IntPoint&); - - virtual DragImageRef createDragImage(IntPoint& dragLoc) const; - virtual void declareAndWriteDragImage(Element*, const KURL&, const String& title, Frame*); - virtual void writeURL(const KURL&, const String&, Frame*); - virtual void writeRange(Range*, Frame*); - - virtual bool hasData(); - - COMPtr<IDataObject> dataObject() { return m_dataObject; } - - private: - ClipboardWin(bool isForDragging, IDataObject*, ClipboardAccessPolicy); - ClipboardWin(bool isForDragging, WCDataObject*, ClipboardAccessPolicy); - - void resetFromClipboard(); - void setDragImage(CachedImage*, Node*, const IntPoint&); - - COMPtr<IDataObject> m_dataObject; - COMPtr<WCDataObject> m_writableDataObject; - Frame* m_frame; - }; - -} // namespace WebCore - -#endif // ClipboardWin_h diff --git a/WebCore/platform/win/ContextMenuItemWin.cpp b/WebCore/platform/win/ContextMenuItemWin.cpp deleted file mode 100644 index bd10c91..0000000 --- a/WebCore/platform/win/ContextMenuItemWin.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "ContextMenuItem.h" - -#include "ContextMenu.h" - -#include "CString.h" -#include <windows.h> - -namespace WebCore { - -ContextMenuItem::ContextMenuItem(LPMENUITEMINFO item) - : m_platformDescription(item) -{ -} - -ContextMenuItem::ContextMenuItem(ContextMenu* subMenu) -{ - m_platformDescription = (LPMENUITEMINFO)malloc(sizeof(MENUITEMINFO)); - if (!m_platformDescription) - return; - - memset(m_platformDescription, 0, sizeof(MENUITEMINFO)); - m_platformDescription->cbSize = sizeof(MENUITEMINFO); - - m_platformDescription->wID = ContextMenuItemTagNoAction; - if (subMenu) { - m_platformDescription->fMask |= MIIM_SUBMENU; - m_platformDescription->hSubMenu = subMenu->platformDescription(); - } -} - -ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu) -{ - m_platformDescription = (LPMENUITEMINFO)malloc(sizeof(MENUITEMINFO)); - if (!m_platformDescription) - return; - - memset(m_platformDescription, 0, sizeof(MENUITEMINFO)); - m_platformDescription->cbSize = sizeof(MENUITEMINFO); - m_platformDescription->fMask = MIIM_FTYPE; - - if (type == SeparatorType) { - m_platformDescription->fType = MFT_SEPARATOR; - return; - } - - if (subMenu) { - m_platformDescription->fMask |= MIIM_STRING | MIIM_SUBMENU; - m_platformDescription->hSubMenu = subMenu->platformDescription(); - } else - m_platformDescription->fMask |= MIIM_STRING | MIIM_ID; - - m_platformDescription->fType = MFT_STRING; - m_platformDescription->wID = action; - - String t = title; - m_platformDescription->cch = t.length(); - m_platformDescription->dwTypeData = wcsdup(t.charactersWithNullTermination()); -} - -ContextMenuItem::~ContextMenuItem() -{ - if (m_platformDescription) { - if (m_platformDescription->fType == MFT_STRING) - free(m_platformDescription->dwTypeData); - free(m_platformDescription); - } -} - -LPMENUITEMINFO ContextMenuItem::releasePlatformDescription() -{ - LPMENUITEMINFO info = m_platformDescription; - m_platformDescription = 0; - return info; -} - -ContextMenuItemType ContextMenuItem::type() const -{ - ContextMenuItemType type = ActionType; - - if ((m_platformDescription->fType & MFT_STRING) && m_platformDescription->hSubMenu) - type = SubmenuType; - else if (m_platformDescription->fType & MFT_SEPARATOR) - type = SeparatorType; - - return type; -} - -ContextMenuAction ContextMenuItem::action() const -{ - return static_cast<ContextMenuAction>(m_platformDescription->wID); -} - -String ContextMenuItem::title() const -{ - return String(m_platformDescription->dwTypeData, wcslen(m_platformDescription->dwTypeData)); -} - -PlatformMenuDescription ContextMenuItem::platformSubMenu() const -{ - return m_platformDescription->hSubMenu; -} - -void ContextMenuItem::setType(ContextMenuItemType type) -{ - if (type == SeparatorType) - m_platformDescription->fType = MFT_SEPARATOR; - else - m_platformDescription->fType = MFT_STRING; -} - -void ContextMenuItem::setAction(ContextMenuAction action) -{ - m_platformDescription->wID = action; -} - -void ContextMenuItem::setTitle(const String& title) -{ - if (m_platformDescription->dwTypeData) - free(m_platformDescription->dwTypeData); - - m_platformDescription->cch = title.length(); - String titleCopy = title; - m_platformDescription->dwTypeData = wcsdup(titleCopy.charactersWithNullTermination()); -} - -void ContextMenuItem::setSubMenu(ContextMenu* subMenu) -{ - if (subMenu->platformDescription() == m_platformDescription->hSubMenu) - return; - - if (m_platformDescription->hSubMenu) - ::DestroyMenu(m_platformDescription->hSubMenu); - - m_platformDescription->fMask |= MIIM_SUBMENU; - m_platformDescription->hSubMenu = subMenu->releasePlatformDescription(); -} - -void ContextMenuItem::setChecked(bool checked) -{ - m_platformDescription->fMask |= MIIM_STATE; - if (checked) { - m_platformDescription->fState &= ~MFS_UNCHECKED; - m_platformDescription->fState |= MFS_CHECKED; - } else { - m_platformDescription->fState &= ~MFS_CHECKED; - m_platformDescription->fState |= MFS_UNCHECKED; - } -} - -void ContextMenuItem::setEnabled(bool enabled) -{ - m_platformDescription->fMask |= MIIM_STATE; - if (enabled) { - m_platformDescription->fState &= ~MFS_DISABLED; - m_platformDescription->fState |= MFS_ENABLED; - } else { - m_platformDescription->fState &= ~MFS_ENABLED; - m_platformDescription->fState |= MFS_DISABLED; - } -} - -bool ContextMenuItem::enabled() const -{ - return m_platformDescription->fState & MFS_ENABLED; -} - -} diff --git a/WebCore/platform/win/ContextMenuWin.cpp b/WebCore/platform/win/ContextMenuWin.cpp deleted file mode 100644 index 26b081a..0000000 --- a/WebCore/platform/win/ContextMenuWin.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "ContextMenu.h" - -#include "CString.h" -#include "Document.h" -#include "Frame.h" -#include "FrameView.h" -#include "Node.h" -#include <tchar.h> -#include <windows.h> - -namespace WebCore { - -ContextMenu::ContextMenu(const HitTestResult& result) - : m_hitTestResult(result) - , m_platformDescription(0) -{ - setPlatformDescription(::CreatePopupMenu()); -} - -ContextMenu::ContextMenu(const HitTestResult& result, const PlatformMenuDescription menu) - : m_hitTestResult(result) - , m_platformDescription(0) -{ - setPlatformDescription(menu); -} - -ContextMenu::~ContextMenu() -{ - if (m_platformDescription) - ::DestroyMenu(m_platformDescription); -} - -unsigned ContextMenu::itemCount() const -{ - if (!m_platformDescription) - return 0; - - return ::GetMenuItemCount(m_platformDescription); -} - -void ContextMenu::insertItem(unsigned int position, ContextMenuItem& item) -{ - if (!m_platformDescription) - return; - - checkOrEnableIfNeeded(item); - ::InsertMenuItem(m_platformDescription, position, TRUE, item.releasePlatformDescription()); -} - -void ContextMenu::appendItem(ContextMenuItem& item) -{ - insertItem(itemCount(), item); -} - -static ContextMenuItem* contextMenuItemByIdOrPosition(HMENU menu, unsigned id, BOOL byPosition) -{ - if (!menu) - return 0; - LPMENUITEMINFO info = (LPMENUITEMINFO)malloc(sizeof(MENUITEMINFO)); - if (!info) - return 0; - - memset(info, 0, sizeof(MENUITEMINFO)); - - info->cbSize = sizeof(MENUITEMINFO); - - info->fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING; - - if (!::GetMenuItemInfo(menu, id, byPosition, info)) { - free(info); - return 0; - } - - UINT type = info->fType & ~(MFT_MENUBARBREAK | MFT_MENUBREAK | MFT_OWNERDRAW | MFT_RADIOCHECK | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY); - if (type == MFT_STRING) { - LPTSTR buffer = (LPTSTR)malloc(++info->cch * sizeof(TCHAR)); - if (!buffer) { - free(info); - return 0; - } - info->dwTypeData = buffer; - ::GetMenuItemInfo(menu, id, byPosition, info); - } - - return new ContextMenuItem(info); -} - -ContextMenuItem* ContextMenu::itemWithAction(unsigned action) -{ - return contextMenuItemByIdOrPosition(m_platformDescription, action, FALSE); -} - -ContextMenuItem* ContextMenu::itemAtIndex(unsigned index, const PlatformMenuDescription platformDescription) -{ - return contextMenuItemByIdOrPosition(platformDescription, index, TRUE); -} - -void ContextMenu::setPlatformDescription(HMENU menu) -{ - if (menu == m_platformDescription) - return; - - if (m_platformDescription) - ::DestroyMenu(m_platformDescription); - - m_platformDescription = menu; - if (!m_platformDescription) - return; - - MENUINFO menuInfo = {0}; - menuInfo.cbSize = sizeof(MENUINFO); - menuInfo.fMask = MIM_STYLE; - ::GetMenuInfo(m_platformDescription, &menuInfo); - menuInfo.fMask = MIM_STYLE; - menuInfo.dwStyle |= MNS_NOTIFYBYPOS; - ::SetMenuInfo(m_platformDescription, &menuInfo); -} - -HMENU ContextMenu::platformDescription() const -{ - return m_platformDescription; -} - -HMENU ContextMenu::releasePlatformDescription() -{ - HMENU description = m_platformDescription; - m_platformDescription = 0; - return description; -} - -} diff --git a/WebCore/platform/win/CursorWin.cpp b/WebCore/platform/win/CursorWin.cpp deleted file mode 100644 index e91e86b..0000000 --- a/WebCore/platform/win/CursorWin.cpp +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) - * Copyright (C) 2006, 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 - * 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 "Cursor.h" - -#include "Image.h" -#include "IntPoint.h" - -#include <wtf/OwnPtr.h> - -#include <windows.h> - -#define ALPHA_CURSORS - -namespace WebCore { - -Cursor::Cursor(const Cursor& other) - : m_impl(other.m_impl) -{ -} - -static inline bool supportsAlphaCursors() -{ - OSVERSIONINFO osinfo = {0}; - osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osinfo); - return osinfo.dwMajorVersion > 5 || (osinfo.dwMajorVersion == 5 && osinfo.dwMinorVersion > 0); -} - -Cursor::Cursor(Image* img, const IntPoint& hotspot) -{ - static bool doAlpha = supportsAlphaCursors(); - BITMAPINFO cursorImage = {0}; - cursorImage.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - cursorImage.bmiHeader.biWidth = img->width(); - cursorImage.bmiHeader.biHeight = img->height(); - cursorImage.bmiHeader.biPlanes = 1; - cursorImage.bmiHeader.biBitCount = 32; - cursorImage.bmiHeader.biCompression = BI_RGB; - HDC dc = GetDC(0); - HDC workingDC = CreateCompatibleDC(dc); - if (doAlpha) { - OwnPtr<HBITMAP> hCursor(CreateDIBSection(dc, (BITMAPINFO *)&cursorImage, DIB_RGB_COLORS, 0, 0, 0)); - ASSERT(hCursor); - - img->getHBITMAP(hCursor.get()); - HBITMAP hOldBitmap = (HBITMAP)SelectObject(workingDC, hCursor.get()); - SetBkMode(workingDC, TRANSPARENT); - SelectObject(workingDC, hOldBitmap); - - Vector<unsigned char, 128> maskBits; - maskBits.fill(0xff, (img->width() + 7) / 8 * img->height()); - OwnPtr<HBITMAP> hMask(CreateBitmap(img->width(), img->height(), 1, 1, maskBits.data())); - - ICONINFO ii; - ii.fIcon = FALSE; - ii.xHotspot = hotspot.x(); - ii.yHotspot = hotspot.y(); - ii.hbmMask = hMask.get(); - ii.hbmColor = hCursor.get(); - - m_impl = SharedCursor::create(CreateIconIndirect(&ii)); - } else { - // Platform doesn't support alpha blended cursors, so we need - // to create the mask manually - HDC andMaskDC = CreateCompatibleDC(dc); - HDC xorMaskDC = CreateCompatibleDC(dc); - OwnPtr<HBITMAP> hCursor(CreateDIBSection(dc, &cursorImage, DIB_RGB_COLORS, 0, 0, 0)); - ASSERT(hCursor); - img->getHBITMAP(hCursor.get()); - BITMAP cursor; - GetObject(hCursor.get(), sizeof(BITMAP), &cursor); - OwnPtr<HBITMAP> andMask(CreateBitmap(cursor.bmWidth, cursor.bmHeight, 1, 1, NULL)); - OwnPtr<HBITMAP> xorMask(CreateCompatibleBitmap(dc, cursor.bmWidth, cursor.bmHeight)); - HBITMAP oldCursor = (HBITMAP)SelectObject(workingDC, hCursor.get()); - HBITMAP oldAndMask = (HBITMAP)SelectObject(andMaskDC, andMask.get()); - HBITMAP oldXorMask = (HBITMAP)SelectObject(xorMaskDC, xorMask.get()); - - SetBkColor(workingDC, RGB(0,0,0)); - BitBlt(andMaskDC, 0, 0, cursor.bmWidth, cursor.bmHeight, workingDC, 0, 0, SRCCOPY); - - SetBkColor(xorMaskDC, RGB(255, 255, 255)); - SetTextColor(xorMaskDC, RGB(255, 255, 255)); - BitBlt(xorMaskDC, 0, 0, cursor.bmWidth, cursor.bmHeight, andMaskDC, 0, 0, SRCCOPY); - BitBlt(xorMaskDC, 0, 0, cursor.bmWidth, cursor.bmHeight, workingDC, 0,0, SRCAND); - - SelectObject(workingDC, oldCursor); - SelectObject(andMaskDC, oldAndMask); - SelectObject(xorMaskDC, oldXorMask); - - ICONINFO icon = {0}; - icon.fIcon = FALSE; - icon.xHotspot = hotspot.x(); - icon.yHotspot = hotspot.y(); - icon.hbmMask = andMask.get(); - icon.hbmColor = xorMask.get(); - m_impl = SharedCursor::create(CreateIconIndirect(&icon)); - - DeleteDC(xorMaskDC); - DeleteDC(andMaskDC); - } - DeleteDC(workingDC); - ReleaseDC(0, dc); -} - -Cursor::~Cursor() -{ -} - -Cursor& Cursor::operator=(const Cursor& other) -{ - m_impl = other.m_impl; - return *this; -} - -Cursor::Cursor(PlatformCursor c) - : m_impl(c) -{ -} - -static Cursor loadCursorByName(char* name, int x, int y) -{ - IntPoint hotSpot(x, y); - Cursor c; - RefPtr<Image> cursorImage(Image::loadPlatformResource(name)); - if (cursorImage && !cursorImage->isNull()) - c = Cursor(cursorImage.get(), hotSpot); - else - c = pointerCursor(); - return c; -} - -static PassRefPtr<SharedCursor> loadSharedCursor(HINSTANCE hInstance, LPCTSTR lpCursorName) -{ - return SharedCursor::create(LoadCursor(hInstance, lpCursorName)); -} - -const Cursor& pointerCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_ARROW); - return c; -} - -const Cursor& crossCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_CROSS); - return c; -} - -const Cursor& handCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_HAND); - return c; -} - -const Cursor& iBeamCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_IBEAM); - return c; -} - -const Cursor& waitCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_WAIT); - return c; -} - -const Cursor& helpCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_HELP); - return c; -} - -const Cursor& eastResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZEWE); - return c; -} - -const Cursor& northResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZENS); - return c; -} - -const Cursor& northEastResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZENESW); - return c; -} - -const Cursor& northWestResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZENWSE); - return c; -} - -const Cursor& southResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZENS); - return c; -} - -const Cursor& southEastResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZENWSE); - return c; -} - -const Cursor& southWestResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZENESW); - return c; -} - -const Cursor& westResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZEWE); - return c; -} - -const Cursor& northSouthResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZENS); - return c; -} - -const Cursor& eastWestResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZEWE); - return c; -} - -const Cursor& northEastSouthWestResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZENESW); - return c; -} - -const Cursor& northWestSouthEastResizeCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZENWSE); - return c; -} - -const Cursor& columnResizeCursor() -{ - // FIXME: Windows does not have a standard column resize cursor <rdar://problem/5018591> - static Cursor c = loadSharedCursor(0, IDC_SIZEWE); - return c; -} - -const Cursor& rowResizeCursor() -{ - // FIXME: Windows does not have a standard row resize cursor <rdar://problem/5018591> - static Cursor c = loadSharedCursor(0, IDC_SIZENS); - return c; -} - -const Cursor& middlePanningCursor() -{ - static const Cursor c = loadCursorByName("panIcon", 7, 7); - return c; -} - -const Cursor& eastPanningCursor() -{ - static const Cursor c = loadCursorByName("panEastCursor", 7, 7); - return c; -} - -const Cursor& northPanningCursor() -{ - static const Cursor c = loadCursorByName("panNorthCursor", 7, 7); - return c; -} - -const Cursor& northEastPanningCursor() -{ - static const Cursor c = loadCursorByName("panNorthEastCursor", 7, 7); - return c; -} - -const Cursor& northWestPanningCursor() -{ - static const Cursor c = loadCursorByName("panNorthWestCursor", 7, 7); - return c; -} - -const Cursor& southPanningCursor() -{ - static const Cursor c = loadCursorByName("panSouthCursor", 7, 7); - return c; -} - -const Cursor& southEastPanningCursor() -{ - static const Cursor c = loadCursorByName("panSouthEastCursor", 7, 7); - return c; -} - -const Cursor& southWestPanningCursor() -{ - static const Cursor c = loadCursorByName("panSouthWestCursor", 7, 7); - return c; -} - -const Cursor& westPanningCursor() -{ - static const Cursor c = loadCursorByName("panWestCursor", 7, 7); - return c; -} - -const Cursor& moveCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_SIZEALL); - return c; -} - -const Cursor& verticalTextCursor() -{ - static const Cursor c = loadCursorByName("verticalTextCursor", 7, 7); - return c; -} - -const Cursor& cellCursor() -{ - return pointerCursor(); -} - -const Cursor& contextMenuCursor() -{ - return pointerCursor(); -} - -const Cursor& aliasCursor() -{ - return pointerCursor(); -} - -const Cursor& progressCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_APPSTARTING); - return c; -} - -const Cursor& noDropCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_NO); - return c; -} - -const Cursor& copyCursor() -{ - return pointerCursor(); -} - -const Cursor& noneCursor() -{ - return pointerCursor(); -} - -const Cursor& notAllowedCursor() -{ - static Cursor c = loadSharedCursor(0, IDC_NO); - return c; -} - -const Cursor& zoomInCursor() -{ - static const Cursor c = loadCursorByName("zoomInCursor", 7, 7); - return c; -} - -const Cursor& zoomOutCursor() -{ - static const Cursor c = loadCursorByName("zoomOutCursor", 7, 7); - return c; -} - -const Cursor& grabCursor() -{ - return pointerCursor(); -} - -const Cursor& grabbingCursor() -{ - return pointerCursor(); -} - -} diff --git a/WebCore/platform/win/DragDataWin.cpp b/WebCore/platform/win/DragDataWin.cpp deleted file mode 100644 index 30487b8..0000000 --- a/WebCore/platform/win/DragDataWin.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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 - * 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 "DragData.h" - -#include "ClipboardWin.h" -#include "ClipboardUtilitiesWin.h" -#include "ClipboardAccessPolicy.h" -#include "DocumentFragment.h" -#include "PlatformString.h" -#include "Markup.h" -#include "TextEncoding.h" -#include <objidl.h> -#include <shlwapi.h> -#include <wininet.h> - -namespace WebCore { - -PassRefPtr<Clipboard> DragData::createClipboard(ClipboardAccessPolicy policy) const -{ - return ClipboardWin::create(true, m_platformDragData, policy); -} - -bool DragData::containsURL() const -{ - return SUCCEEDED(m_platformDragData->QueryGetData(urlWFormat())) - || SUCCEEDED(m_platformDragData->QueryGetData(urlFormat())) - || SUCCEEDED(m_platformDragData->QueryGetData(filenameWFormat())) - || SUCCEEDED(m_platformDragData->QueryGetData(filenameFormat())); -} - -String DragData::asURL(String* title) const -{ - bool success; - return getURL(m_platformDragData, success, title); -} - -bool DragData::containsFiles() const -{ - return SUCCEEDED(m_platformDragData->QueryGetData(cfHDropFormat())); -} - -void DragData::asFilenames(Vector<String>& result) const -{ - WCHAR filename[MAX_PATH]; - - STGMEDIUM medium; - if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium))) - return; - - HDROP hdrop = (HDROP)GlobalLock(medium.hGlobal); - - if (!hdrop) - return; - - const unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0); - for (unsigned i = 0; i < numFiles; i++) { - if (!DragQueryFileW(hdrop, 0, filename, ARRAYSIZE(filename))) - continue; - result.append((UChar*)filename); - } - - // Free up memory from drag - DragFinish(hdrop); - - GlobalUnlock(medium.hGlobal); -} - -bool DragData::containsPlainText() const -{ - return SUCCEEDED(m_platformDragData->QueryGetData(plainTextWFormat())) - || SUCCEEDED(m_platformDragData->QueryGetData(plainTextFormat())); -} - -String DragData::asPlainText() const -{ - bool success; - return getPlainText(m_platformDragData, success); -} - -bool DragData::containsColor() const -{ - return false; -} - -bool DragData::canSmartReplace() const -{ - return SUCCEEDED(m_platformDragData->QueryGetData(smartPasteFormat())); -} - -bool DragData::containsCompatibleContent() const -{ - return containsPlainText() || containsURL() - || containsHTML(m_platformDragData) - || containsFilenames(m_platformDragData) - || containsColor(); -} - -PassRefPtr<DocumentFragment> DragData::asFragment(Document* doc) const -{ - /* - * Order is richest format first. On OSX this is: - * * Web Archive - * * Filenames - * * HTML - * * RTF - * * TIFF - * * PICT - */ - - if (containsFilenames(m_platformDragData)) - if (PassRefPtr<DocumentFragment> fragment = fragmentFromFilenames(doc, m_platformDragData)) - return fragment; - - if (containsHTML(m_platformDragData)) - if (PassRefPtr<DocumentFragment> fragment = fragmentFromHTML(doc, m_platformDragData)) - return fragment; - - return 0; -} - -Color DragData::asColor() const -{ - return Color(); -} - -} - diff --git a/WebCore/platform/win/DragImageCGWin.cpp b/WebCore/platform/win/DragImageCGWin.cpp deleted file mode 100644 index 7788572..0000000 --- a/WebCore/platform/win/DragImageCGWin.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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 - * 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 "DragImage.h" - -#include "CachedImage.h" -#include "GraphicsContext.h" -#include "Image.h" -#include "RetainPtr.h" - -#include <CoreGraphics/CoreGraphics.h> - -#include <windows.h> - -namespace WebCore { - -HBITMAP allocImage(HDC dc, IntSize size, CGContextRef *targetRef) -{ - HBITMAP hbmp; - BITMAPINFO bmpInfo = {0}; - bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmpInfo.bmiHeader.biWidth = size.width(); - bmpInfo.bmiHeader.biHeight = size.height(); - bmpInfo.bmiHeader.biPlanes = 1; - bmpInfo.bmiHeader.biBitCount = 32; - bmpInfo.bmiHeader.biCompression = BI_RGB; - LPVOID bits; - hbmp = CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0); - - if (!targetRef) - return hbmp; - - CGColorSpaceRef deviceRGB = CGColorSpaceCreateDeviceRGB(); - CGContextRef bitmapContext = CGBitmapContextCreate(bits, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, 8, - bmpInfo.bmiHeader.biWidth * 4, deviceRGB, - kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst); - CGColorSpaceRelease(deviceRGB); - if (!bitmapContext) { - DeleteObject(hbmp); - return 0; - } - - *targetRef = bitmapContext; - return hbmp; -} - -static CGContextRef createCgContextFromBitmap(HBITMAP bitmap) -{ - BITMAP info; - GetObject(bitmap, sizeof(info), &info); - ASSERT(info.bmBitsPixel == 32); - - CGColorSpaceRef deviceRGB = CGColorSpaceCreateDeviceRGB(); - CGContextRef bitmapContext = CGBitmapContextCreate(info.bmBits, info.bmWidth, info.bmHeight, 8, - info.bmWidthBytes, deviceRGB, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst); - CGColorSpaceRelease(deviceRGB); - return bitmapContext; -} - -DragImageRef scaleDragImage(DragImageRef image, FloatSize scale) -{ - // FIXME: due to the way drag images are done on windows we need - // to preprocess the alpha channel <rdar://problem/5015946> - - if (!image) - return 0; - CGContextRef targetContext; - CGContextRef srcContext; - CGImageRef srcImage; - IntSize srcSize = dragImageSize(image); - IntSize dstSize(static_cast<int>(srcSize.width() * scale.width()), static_cast<int>(srcSize.height() * scale.height())); - HBITMAP hbmp = 0; - HDC dc = GetDC(0); - HDC dstDC = CreateCompatibleDC(dc); - if (!dstDC) - goto exit; - - hbmp = allocImage(dstDC, dstSize, &targetContext); - if (!hbmp) - goto exit; - - srcContext = createCgContextFromBitmap(image); - srcImage = CGBitmapContextCreateImage(srcContext); - CGRect rect; - rect.origin.x = 0; - rect.origin.y = 0; - rect.size = dstSize; - CGContextDrawImage(targetContext, rect, srcImage); - CGImageRelease(srcImage); - CGContextRelease(srcContext); - CGContextRelease(targetContext); - ::DeleteObject(image); - image = 0; - -exit: - if (!hbmp) - hbmp = image; - if (dstDC) - DeleteDC(dstDC); - ReleaseDC(0, dc); - return hbmp; -} - -DragImageRef createDragImageFromImage(Image* img) -{ - HBITMAP hbmp = 0; - HDC dc = GetDC(0); - HDC workingDC = CreateCompatibleDC(dc); - CGContextRef drawContext = 0; - if (!workingDC) - goto exit; - - hbmp = allocImage(workingDC, img->size(), &drawContext); - - if (!hbmp) - goto exit; - - if (!drawContext) { - ::DeleteObject(hbmp); - hbmp = 0; - } - - CGImageRef srcImage = img->getCGImageRef(); - CGRect rect; - rect.size = img->size(); - rect.origin.x = 0; - rect.origin.y = -rect.size.height; - static const CGFloat white [] = {1.0, 1.0, 1.0, 1.0}; - CGContextScaleCTM(drawContext, 1, -1); - CGContextSetFillColor(drawContext, white); - CGContextFillRect(drawContext, rect); - CGContextSetBlendMode(drawContext, kCGBlendModeNormal); - CGContextDrawImage(drawContext, rect, srcImage); - CGContextRelease(drawContext); - -exit: - if (workingDC) - DeleteDC(workingDC); - ReleaseDC(0, dc); - return hbmp; -} - -} diff --git a/WebCore/platform/win/DragImageCairoWin.cpp b/WebCore/platform/win/DragImageCairoWin.cpp deleted file mode 100644 index 5fff64f..0000000 --- a/WebCore/platform/win/DragImageCairoWin.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 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 "DragImage.h" - -#include "CachedImage.h" -#include "GraphicsContext.h" -#include "Image.h" -#include "NotImplemented.h" -#include "RetainPtr.h" - -#include <windows.h> - -namespace WebCore { - -DragImageRef scaleDragImage(DragImageRef image, FloatSize scale) -{ - notImplemented(); - - return image; -} - -DragImageRef createDragImageFromImage(Image* img) -{ - notImplemented(); - - return 0; -} - -} diff --git a/WebCore/platform/win/DragImageWin.cpp b/WebCore/platform/win/DragImageWin.cpp deleted file mode 100644 index 46146b3..0000000 --- a/WebCore/platform/win/DragImageWin.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 - * 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 "DragImage.h" - -#include "CachedImage.h" -#include "GraphicsContext.h" -#include "Image.h" -#include "RetainPtr.h" - -#include <windows.h> - -namespace WebCore { - -IntSize dragImageSize(DragImageRef image) -{ - if (!image) - return IntSize(); - BITMAP b; - GetObject(image, sizeof(BITMAP), &b); - return IntSize(b.bmWidth, b.bmHeight); -} - -void deleteDragImage(DragImageRef image) -{ - if (image) - ::DeleteObject(image); -} - -DragImageRef dissolveDragImageToFraction(DragImageRef image, float) -{ - //We don't do this on windows as the dragimage is blended by the OS - return image; -} - -DragImageRef createDragImageIconForCachedImage(CachedImage*) -{ - //FIXME: Provide icon for image type <rdar://problem/5015949> - return 0; -} - -} diff --git a/WebCore/platform/win/EditorWin.cpp b/WebCore/platform/win/EditorWin.cpp deleted file mode 100644 index 813eb78..0000000 --- a/WebCore/platform/win/EditorWin.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2006, 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 - * 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 "Editor.h" -#include "EditorClient.h" - -#include "ClipboardWin.h" -#include "Document.h" -#include "Element.h" -#include "htmlediting.h" -#include "NotImplemented.h" -#include "TextIterator.h" -#include "visible_units.h" - -#include <windows.h> - -namespace WebCore { - -PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy) -{ - COMPtr<IDataObject> clipboardData; - if (!SUCCEEDED(OleGetClipboard(&clipboardData))) - clipboardData = 0; - - return ClipboardWin::create(false, clipboardData.get(), policy); -} - -} // namespace WebCore diff --git a/WebCore/platform/win/EventLoopWin.cpp b/WebCore/platform/win/EventLoopWin.cpp deleted file mode 100644 index aae107d..0000000 --- a/WebCore/platform/win/EventLoopWin.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - */ - -#include "config.h" -#include "EventLoop.h" - -namespace WebCore { - -void EventLoop::cycle() -{ - MSG msg; - if (!GetMessage(&msg, 0, 0, 0)) { - m_ended = true; - return; - } - - TranslateMessage(&msg); - DispatchMessage(&msg); -} - -} // namespace WebCore diff --git a/WebCore/platform/win/FileChooserWin.cpp b/WebCore/platform/win/FileChooserWin.cpp deleted file mode 100644 index 7d07b5d..0000000 --- a/WebCore/platform/win/FileChooserWin.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2006, 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 - * 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 "FileChooser.h" - -#include "LocalizedStrings.h" -#include "StringTruncator.h" -#include <shlwapi.h> -#include <tchar.h> -#include <windows.h> - -namespace WebCore { - -String FileChooser::basenameForWidth(const Font& font, int width) const -{ - if (width <= 0) - return String(); - - String string; - if (m_filenames.isEmpty()) - string = fileButtonNoFileSelectedLabel(); - else if (m_filenames.size() == 1) { - String tmpFilename = m_filenames[0]; - LPTSTR basename = PathFindFileName(tmpFilename.charactersWithNullTermination()); - string = String(basename); - } else - return StringTruncator::rightTruncate(String::number(m_filenames.size()) + " files", width, font, false); - - return StringTruncator::centerTruncate(string, width, font, false); -} - -} // namespace WebCore diff --git a/WebCore/platform/win/FileSystemWin.cpp b/WebCore/platform/win/FileSystemWin.cpp deleted file mode 100644 index 5671462..0000000 --- a/WebCore/platform/win/FileSystemWin.cpp +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (C) 2007, 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 - * 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 "FileSystem.h" - -#include "CString.h" -#include "NotImplemented.h" -#include "PlatformString.h" - -#include <windows.h> -#include <winbase.h> -#include <shlobj.h> -#include <shlwapi.h> - -namespace WebCore { - -static bool statFile(String path, struct _stat64& st) -{ - ASSERT_ARG(path, !path.isNull()); - return !_wstat64(path.charactersWithNullTermination(), &st) && (st.st_mode & _S_IFMT) == _S_IFREG; -} - -bool getFileSize(const String& path, long long& result) -{ - struct _stat64 sb; - if (!statFile(path, sb)) - return false; - result = sb.st_size; - return true; -} - -bool getFileModificationTime(const String& path, time_t& result) -{ - struct _stat64 st; - if (!statFile(path, st)) - return false; - result = st.st_mtime; - return true; -} - -bool fileExists(const String& path) -{ - struct _stat64 st; - return statFile(path, st); -} - -bool deleteFile(const String& path) -{ - String filename = path; - return !!DeleteFileW(filename.charactersWithNullTermination()); -} - -bool deleteEmptyDirectory(const String& path) -{ - String filename = path; - return !!RemoveDirectoryW(filename.charactersWithNullTermination()); -} - -String pathByAppendingComponent(const String& path, const String& component) -{ - Vector<UChar> buffer(MAX_PATH); - - if (path.length() + 1 > buffer.size()) - return String(); - - memcpy(buffer.data(), path.characters(), path.length() * sizeof(UChar)); - buffer[path.length()] = '\0'; - - String componentCopy = component; - if (!PathAppendW(buffer.data(), componentCopy.charactersWithNullTermination())) - return String(); - - buffer.resize(wcslen(buffer.data())); - - return String::adopt(buffer); -} - -CString fileSystemRepresentation(const String&) -{ - return ""; -} - -bool makeAllDirectories(const String& path) -{ - String fullPath = path; - if (SHCreateDirectoryEx(0, fullPath.charactersWithNullTermination(), 0) != ERROR_SUCCESS) { - DWORD error = GetLastError(); - if (error != ERROR_FILE_EXISTS && error != ERROR_ALREADY_EXISTS) { - LOG_ERROR("Failed to create path %s", path.ascii().data()); - return false; - } - } - return true; -} - -String homeDirectoryPath() -{ - notImplemented(); - return ""; -} - -String pathGetFileName(const String& path) -{ - return String(::PathFindFileName(String(path).charactersWithNullTermination())); -} - -String directoryName(const String& path) -{ - notImplemented(); - return String(); -} - -static String bundleName() -{ - static bool initialized; - static String name = "WebKit"; - - if (!initialized) { - initialized = true; - - if (CFBundleRef bundle = CFBundleGetMainBundle()) - if (CFTypeRef bundleExecutable = CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleExecutableKey)) - if (CFGetTypeID(bundleExecutable) == CFStringGetTypeID()) - name = reinterpret_cast<CFStringRef>(bundleExecutable); - } - - return name; -} - -static String storageDirectory(DWORD pathIdentifier) -{ - Vector<UChar> buffer(MAX_PATH); - if (FAILED(SHGetFolderPathW(0, pathIdentifier | CSIDL_FLAG_CREATE, 0, 0, buffer.data()))) - return String(); - buffer.resize(wcslen(buffer.data())); - String directory = String::adopt(buffer); - - static const String companyNameDirectory = "Apple Computer\\"; - directory = pathByAppendingComponent(directory, companyNameDirectory + bundleName()); - if (!makeAllDirectories(directory)) - return String(); - - return directory; -} - -static String cachedStorageDirectory(DWORD pathIdentifier) -{ - static HashMap<DWORD, String> directories; - - HashMap<DWORD, String>::iterator it = directories.find(pathIdentifier); - if (it != directories.end()) - return it->second; - - String directory = storageDirectory(pathIdentifier); - directories.add(pathIdentifier, directory); - - return directory; -} - -CString openTemporaryFile(const char*, PlatformFileHandle& handle) -{ - handle = INVALID_HANDLE_VALUE; - - char tempPath[MAX_PATH]; - int tempPathLength = ::GetTempPathA(_countof(tempPath), tempPath); - if (tempPathLength <= 0 || tempPathLength > _countof(tempPath)) - return 0; - - HCRYPTPROV hCryptProv = 0; - if (!CryptAcquireContext(&hCryptProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) - return 0; - - char proposedPath[MAX_PATH]; - while (1) { - char tempFile[] = "XXXXXXXX.tmp"; // Use 8.3 style name (more characters aren't helpful due to 8.3 short file names) - const int randomPartLength = 8; - if (!CryptGenRandom(hCryptProv, randomPartLength, reinterpret_cast<BYTE*>(tempFile))) - break; - - // Limit to valid filesystem characters, also excluding others that could be problematic, like punctuation. - // don't include both upper and lowercase since Windows file systems are typically not case sensitive. - const char validChars[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - for (int i = 0; i < randomPartLength; ++i) - tempFile[i] = validChars[tempFile[i] % (sizeof(validChars) - 1)]; - - ASSERT(strlen(tempFile) == sizeof(tempFile) - 1); - - if (!PathCombineA(proposedPath, tempPath, tempFile)) - break; - - // use CREATE_NEW to avoid overwriting an existing file with the same name - handle = CreateFileA(proposedPath, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); - if (!isHandleValid(handle) && GetLastError() == ERROR_ALREADY_EXISTS) - continue; - - break; - } - - CryptReleaseContext(hCryptProv, 0); - - if (!isHandleValid(handle)) - return 0; - - return proposedPath; -} - -void closeFile(PlatformFileHandle& handle) -{ - if (isHandleValid(handle)) { - ::CloseHandle(handle); - handle = invalidPlatformFileHandle; - } -} - -int writeToFile(PlatformFileHandle handle, const char* data, int length) -{ - if (!isHandleValid(handle)) - return -1; - - DWORD bytesWritten; - bool success = WriteFile(handle, data, length, &bytesWritten, 0); - - if (!success) - return -1; - return static_cast<int>(bytesWritten); -} - -bool unloadModule(PlatformModule module) -{ - return ::FreeLibrary(module); -} - -String localUserSpecificStorageDirectory() -{ - return cachedStorageDirectory(CSIDL_LOCAL_APPDATA); -} - -String roamingUserSpecificStorageDirectory() -{ - return cachedStorageDirectory(CSIDL_APPDATA); -} - -bool safeCreateFile(const String& path, CFDataRef data) -{ - // Create a temporary file. - WCHAR tempDirPath[MAX_PATH]; - if (!GetTempPathW(ARRAYSIZE(tempDirPath), tempDirPath)) - return false; - - WCHAR tempPath[MAX_PATH]; - if (!GetTempFileNameW(tempDirPath, L"WEBKIT", 0, tempPath)) - return false; - - HANDLE tempFileHandle = CreateFileW(tempPath, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (tempFileHandle == INVALID_HANDLE_VALUE) - return false; - - // Write the data to this temp file. - DWORD written; - if (!WriteFile(tempFileHandle, CFDataGetBytePtr(data), static_cast<DWORD>(CFDataGetLength(data)), &written, 0)) - return false; - - CloseHandle(tempFileHandle); - - // Copy the temp file to the destination file. - String destination = path; - if (!MoveFileExW(tempPath, destination.charactersWithNullTermination(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED)) - return false; - - return true; -} - -Vector<String> listDirectory(const String& path, const String& filter) -{ - Vector<String> entries; - notImplemented(); - return entries; -} - -} // namespace WebCore diff --git a/WebCore/platform/win/GDIObjectCounter.cpp b/WebCore/platform/win/GDIObjectCounter.cpp deleted file mode 100644 index 3cc5bcb..0000000 --- a/WebCore/platform/win/GDIObjectCounter.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2007 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" - -#ifndef NDEBUG - -#include "GDIObjectCounter.h" - -#include "CString.h" -#include "Logging.h" - -#include <windows.h> - -namespace WebCore { - -GDIObjectCounter::GDIObjectCounter(const String& identifier) -{ - init(identifier); -} - -GDIObjectCounter::GDIObjectCounter(const String& className, void* instance) -{ - init(String::format("%s (%p)", className.latin1().data(), instance)); -} - -void GDIObjectCounter::init(const String& identifier) -{ - m_identifier = identifier; - m_startCount = currentGDIObjectsInUse(); - m_endCount = 0; -} - -GDIObjectCounter::~GDIObjectCounter() -{ - m_endCount = currentGDIObjectsInUse(); - int leaked = m_endCount - m_startCount; - if (leaked != 0) - LOG(PlatformLeaks, "%s: leaked %d GDI object%s!", m_identifier.latin1().data(), leaked, leaked == 1 ? "" : "s"); -} - -unsigned GDIObjectCounter::currentGDIObjectsInUse() -{ - return ::GetGuiResources(::GetCurrentProcess(), GR_GDIOBJECTS); -} - -} // namespace WebCore - -#endif // !defined(NDEBUG) diff --git a/WebCore/platform/win/GDIObjectCounter.h b/WebCore/platform/win/GDIObjectCounter.h deleted file mode 100644 index 9b9bd12..0000000 --- a/WebCore/platform/win/GDIObjectCounter.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2007 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. - */ - -#ifndef GDIObjectCounter_h -#define GDIObjectCounter_h - -#ifdef NDEBUG -#define LOCAL_GDI_COUNTER(num, identifier) ((void)0) -#else -#define LOCAL_GDI_COUNTER(num, identifier) GDIObjectCounter counter##num(identifier) -#endif - -#ifndef NDEBUG - -#include "PlatformString.h" - -namespace WebCore { - - class GDIObjectCounter { - public: - GDIObjectCounter(const String& identifier); - GDIObjectCounter(const String& className, void* instance); - ~GDIObjectCounter(); - - static unsigned currentGDIObjectsInUse(); - - private: - void init(const String& identifier); - String m_identifier; - unsigned m_startCount; - unsigned m_endCount; - }; - -} // namespace WebCore - -#endif // !defined(NDEBUG) - -#endif // !defined(GDIObjectCounter_h) diff --git a/WebCore/platform/win/KeyEventWin.cpp b/WebCore/platform/win/KeyEventWin.cpp deleted file mode 100644 index 99dfe44..0000000 --- a/WebCore/platform/win/KeyEventWin.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "PlatformKeyboardEvent.h" - -#include <windows.h> -#include <wtf/ASCIICType.h> - -using namespace WTF; - -namespace WebCore { - -static const unsigned short HIGH_BIT_MASK_SHORT = 0x8000; - -// FIXME: This is incomplete. We could change this to mirror -// more like what Firefox does, and generate these switch statements -// at build time. -static String keyIdentifierForWindowsKeyCode(unsigned short keyCode) -{ - switch (keyCode) { - case VK_MENU: - return "Alt"; - case VK_CONTROL: - return "Control"; - case VK_SHIFT: - return "Shift"; - case VK_CAPITAL: - return "CapsLock"; - case VK_LWIN: - case VK_RWIN: - return "Win"; - case VK_CLEAR: - return "Clear"; - case VK_DOWN: - return "Down"; - // "End" - case VK_END: - return "End"; - // "Enter" - case VK_RETURN: - return "Enter"; - case VK_EXECUTE: - return "Execute"; - case VK_F1: - return "F1"; - case VK_F2: - return "F2"; - case VK_F3: - return "F3"; - case VK_F4: - return "F4"; - case VK_F5: - return "F5"; - case VK_F6: - return "F6"; - case VK_F7: - return "F7"; - case VK_F8: - return "F8"; - case VK_F9: - return "F9"; - case VK_F10: - return "F11"; - case VK_F12: - return "F12"; - case VK_F13: - return "F13"; - case VK_F14: - return "F14"; - case VK_F15: - return "F15"; - case VK_F16: - return "F16"; - case VK_F17: - return "F17"; - case VK_F18: - return "F18"; - case VK_F19: - return "F19"; - case VK_F20: - return "F20"; - case VK_F21: - return "F21"; - case VK_F22: - return "F22"; - case VK_F23: - return "F23"; - case VK_F24: - return "F24"; - case VK_HELP: - return "Help"; - case VK_HOME: - return "Home"; - case VK_INSERT: - return "Insert"; - case VK_LEFT: - return "Left"; - case VK_NEXT: - return "PageDown"; - case VK_PRIOR: - return "PageUp"; - case VK_PAUSE: - return "Pause"; - case VK_SNAPSHOT: - return "PrintScreen"; - case VK_RIGHT: - return "Right"; - case VK_SCROLL: - return "Scroll"; - case VK_SELECT: - return "Select"; - case VK_UP: - return "Up"; - // Standard says that DEL becomes U+007F. - case VK_DELETE: - return "U+007F"; - default: - return String::format("U+%04X", toASCIIUpper(keyCode)); - } -} - -static bool isKeypadEvent(WPARAM code, LPARAM keyData, PlatformKeyboardEvent::Type type) -{ - if (type != PlatformKeyboardEvent::RawKeyDown && type != PlatformKeyboardEvent::KeyUp) - return false; - - switch (code) { - case VK_NUMLOCK: - case VK_NUMPAD0: - case VK_NUMPAD1: - case VK_NUMPAD2: - case VK_NUMPAD3: - case VK_NUMPAD4: - case VK_NUMPAD5: - case VK_NUMPAD6: - case VK_NUMPAD7: - case VK_NUMPAD8: - case VK_NUMPAD9: - case VK_MULTIPLY: - case VK_ADD: - case VK_SEPARATOR: - case VK_SUBTRACT: - case VK_DECIMAL: - case VK_DIVIDE: - return true; - case VK_RETURN: - return HIWORD(keyData) & KF_EXTENDED; - case VK_INSERT: - case VK_DELETE: - case VK_PRIOR: - case VK_NEXT: - case VK_END: - case VK_HOME: - case VK_LEFT: - case VK_UP: - case VK_RIGHT: - case VK_DOWN: - return !(HIWORD(keyData) & KF_EXTENDED); - default: - return false; - } -} - -static inline String singleCharacterString(UChar c) { return String(&c, 1); } - -PlatformKeyboardEvent::PlatformKeyboardEvent(HWND, WPARAM code, LPARAM keyData, Type type, bool systemKey) - : m_type(type) - , m_text((type == Char) ? singleCharacterString(code) : String()) - , m_unmodifiedText((type == Char) ? singleCharacterString(code) : String()) - , m_keyIdentifier((type == Char) ? String() : keyIdentifierForWindowsKeyCode(code)) - , m_autoRepeat(HIWORD(keyData) & KF_REPEAT) - , m_windowsVirtualKeyCode((type == RawKeyDown || type == KeyUp) ? code : 0) - , m_nativeVirtualKeyCode(m_windowsVirtualKeyCode) - , m_isKeypad(isKeypadEvent(code, keyData, type)) - , m_shiftKey(GetKeyState(VK_SHIFT) & HIGH_BIT_MASK_SHORT) - , m_ctrlKey(GetKeyState(VK_CONTROL) & HIGH_BIT_MASK_SHORT) - , m_altKey(GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT) - , m_metaKey(false) - , m_isSystemKey(systemKey) -{ -} - -void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type, bool) -{ - // No KeyDown events on Windows to disambiguate. - ASSERT_NOT_REACHED(); -} - -bool PlatformKeyboardEvent::currentCapsLockState() -{ - return GetKeyState(VK_CAPITAL) & 1; -} - -} diff --git a/WebCore/platform/win/Language.cpp b/WebCore/platform/win/Language.cpp deleted file mode 100644 index 787c5a3..0000000 --- a/WebCore/platform/win/Language.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2007 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 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 "Language.h" - -#include "CString.h" -#include "PlatformString.h" - -namespace WebCore { - -static String localeInfo(LCTYPE localeType, const String& fallback) -{ - LANGID langID = GetUserDefaultUILanguage(); - int localeChars = GetLocaleInfo(langID, localeType, 0, 0); - if (!localeChars) - return fallback; - Vector<WCHAR> localeNameBuf(localeChars); - localeChars = GetLocaleInfo(langID, localeType, localeNameBuf.data(), localeChars); - if (!localeChars) - return fallback; - String localeName = String::adopt(localeNameBuf); - if (localeName.isEmpty()) - return fallback; - - return localeName; -} - -String defaultLanguage() -{ - static String computedDefaultLanguage; - if (!computedDefaultLanguage.isEmpty()) - return computedDefaultLanguage; - - String languageName = localeInfo(LOCALE_SISO639LANGNAME, "en"); - String countryName = localeInfo(LOCALE_SISO3166CTRYNAME, String()); - - if (countryName.isEmpty()) - computedDefaultLanguage = languageName; - else - computedDefaultLanguage = String::format("%s-%s", languageName.latin1().data(), countryName.latin1().data()); - - return computedDefaultLanguage; -} - -} diff --git a/WebCore/platform/win/MIMETypeRegistryWin.cpp b/WebCore/platform/win/MIMETypeRegistryWin.cpp deleted file mode 100644 index 06c6f36..0000000 --- a/WebCore/platform/win/MIMETypeRegistryWin.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "MIMETypeRegistry.h" - -#include <shlwapi.h> -#include <wtf/HashMap.h> - -namespace WebCore -{ - -String getMIMETypeForUTI(const String & uti) -{ - String mimeType; - // FIXME: This is an ugly hack: public.type -> image/type mimetype - if (int dotLocation = uti.reverseFind('.')) { - mimeType = String("image/")+uti.substring(dotLocation + 1); - } - return mimeType; -} - -static String mimeTypeForExtension(const String& extension) -{ - String ext = "." + extension; - WCHAR contentTypeStr[256]; - DWORD contentTypeStrLen = sizeof(contentTypeStr); - DWORD keyType; - - HRESULT result = SHGetValue(HKEY_CLASSES_ROOT, ext.charactersWithNullTermination(), L"Content Type", &keyType, (LPVOID)contentTypeStr, &contentTypeStrLen); - - if (result == ERROR_SUCCESS && keyType == REG_SZ) - return String(contentTypeStr, contentTypeStrLen / sizeof(contentTypeStr[0]) - 1); - - return String(); -} - -String MIMETypeRegistry::getPreferredExtensionForMIMEType(const String& type) -{ - String mimeType; - - int semiColonPos = type.find(';'); - if (semiColonPos < 0) - mimeType = type; - else - mimeType = type.substring(0, semiColonPos); - - String path = "MIME\\Database\\Content Type\\" + type; - WCHAR extStr[MAX_PATH]; - DWORD extStrLen = sizeof(extStr); - DWORD keyType; - - HRESULT result = SHGetValueW(HKEY_CLASSES_ROOT, path.charactersWithNullTermination(), L"Extension", &keyType, (LPVOID)extStr, &extStrLen); - - if (result == ERROR_SUCCESS && keyType == REG_SZ) - return String(extStr + 1, extStrLen / sizeof(extStr[0]) - 2); - - return String(); -} - -String MIMETypeRegistry::getMIMETypeForExtension(const String &ext) -{ - if (ext.isEmpty()) - return String(); - - static HashMap<String, String> mimetypeMap; - if (mimetypeMap.isEmpty()) { - //fill with initial values - mimetypeMap.add("txt", "text/plain"); - mimetypeMap.add("pdf", "application/pdf"); - mimetypeMap.add("ps", "application/postscript"); - mimetypeMap.add("html", "text/html"); - mimetypeMap.add("htm", "text/html"); - mimetypeMap.add("xml", "text/xml"); - mimetypeMap.add("xsl", "text/xsl"); - mimetypeMap.add("js", "application/x-javascript"); - mimetypeMap.add("xhtml", "application/xhtml+xml"); - mimetypeMap.add("rss", "application/rss+xml"); - mimetypeMap.add("webarchive", "application/x-webarchive"); - mimetypeMap.add("svg", "image/svg+xml"); - mimetypeMap.add("svgz", "image/svg+xml"); - mimetypeMap.add("jpg", "image/jpeg"); - mimetypeMap.add("jpeg", "image/jpeg"); - mimetypeMap.add("png", "image/png"); - mimetypeMap.add("tif", "image/tiff"); - mimetypeMap.add("tiff", "image/tiff"); - mimetypeMap.add("ico", "image/ico"); - mimetypeMap.add("cur", "image/ico"); - mimetypeMap.add("bmp", "image/bmp"); - } - String result = mimetypeMap.get(ext); - if (result.isEmpty()) { - result = mimeTypeForExtension(ext); - if (!result.isEmpty()) - mimetypeMap.add(ext, result); - } - return result; -} - -} diff --git a/WebCore/platform/win/PasteboardWin.cpp b/WebCore/platform/win/PasteboardWin.cpp deleted file mode 100644 index 506cc7b..0000000 --- a/WebCore/platform/win/PasteboardWin.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "Pasteboard.h" - -#include "CString.h" -#include "ClipboardUtilitiesWin.h" -#include "Document.h" -#include "DocumentFragment.h" -#include "Element.h" -#include "Frame.h" -#include "HitTestResult.h" -#include "Image.h" -#include "KURL.h" -#include "NotImplemented.h" -#include "Page.h" -#include "Range.h" -#include "RenderImage.h" -#include "TextEncoding.h" -#include "markup.h" - -namespace WebCore { - -static UINT HTMLClipboardFormat = 0; -static UINT BookmarkClipboardFormat = 0; -static UINT WebSmartPasteFormat = 0; - -static LRESULT CALLBACK PasteboardOwnerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - LRESULT lresult = 0; - LONG_PTR longPtr = GetWindowLongPtr(hWnd, 0); - - switch(message) { - case WM_RENDERFORMAT: - // This message comes when SetClipboardData was sent a null data handle - // and now it's come time to put the data on the clipboard. - break; - case WM_RENDERALLFORMATS: - // This message comes when SetClipboardData was sent a null data handle - // and now this application is about to quit, so it must put data on - // the clipboard before it exits. - break; - case WM_DRAWCLIPBOARD: - break; - case WM_DESTROY: - break; - case WM_CHANGECBCHAIN: - break; - default: - lresult = DefWindowProc(hWnd, message, wParam, lParam); - break; - } - return lresult; -} - -Pasteboard* Pasteboard::generalPasteboard() -{ - static Pasteboard* pasteboard = new Pasteboard; - return pasteboard; -} - -Pasteboard::Pasteboard() -{ - // make a dummy HWND to be the Windows clipboard's owner - WNDCLASSEX wcex = {0}; - wcex.cbSize = sizeof(WNDCLASSEX); - wcex.lpfnWndProc = PasteboardOwnerWndProc; - wcex.hInstance = Page::instanceHandle(); - wcex.lpszClassName = L"PasteboardOwnerWindowClass"; - ::RegisterClassEx(&wcex); - - m_owner = ::CreateWindow(L"PasteboardOwnerWindowClass", L"PasteboardOwnerWindow", 0, 0, 0, 0, 0, - HWND_MESSAGE, 0, 0, 0); - - HTMLClipboardFormat = ::RegisterClipboardFormat(L"HTML Format"); - BookmarkClipboardFormat = ::RegisterClipboardFormat(L"UniformResourceLocatorW"); - WebSmartPasteFormat = ::RegisterClipboardFormat(L"WebKit Smart Paste Format"); -} - -void Pasteboard::clear() -{ - if (::OpenClipboard(m_owner)) { - ::EmptyClipboard(); - ::CloseClipboard(); - } -} - -void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame) -{ - clear(); - - // Put CF_HTML format on the pasteboard - if (::OpenClipboard(m_owner)) { - ExceptionCode ec = 0; - Vector<char> data; - markupToCF_HTML(createMarkup(selectedRange, 0, AnnotateForInterchange), - selectedRange->startContainer(ec)->document()->url().string(), data); - HGLOBAL cbData = createGlobalData(data); - if (!::SetClipboardData(HTMLClipboardFormat, cbData)) - ::GlobalFree(cbData); - ::CloseClipboard(); - } - - // Put plain string on the pasteboard. CF_UNICODETEXT covers CF_TEXT as well - String str = frame->selectedText(); - replaceNewlinesWithWindowsStyleNewlines(str); - replaceNBSPWithSpace(str); - if (::OpenClipboard(m_owner)) { - HGLOBAL cbData = createGlobalData(str); - if (!::SetClipboardData(CF_UNICODETEXT, cbData)) - ::GlobalFree(cbData); - ::CloseClipboard(); - } - - // enable smart-replacing later on by putting dummy data on the pasteboard - if (canSmartCopyOrDelete) { - if (::OpenClipboard(m_owner)) { - ::SetClipboardData(WebSmartPasteFormat, NULL); - ::CloseClipboard(); - } - - } -} - -void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) -{ - ASSERT(!url.isEmpty()); - - clear(); - - String title(titleStr); - if (title.isEmpty()) { - title = url.lastPathComponent(); - if (title.isEmpty()) - title = url.host(); - } - - // write to clipboard in format com.apple.safari.bookmarkdata to be able to paste into the bookmarks view with appropriate title - if (::OpenClipboard(m_owner)) { - HGLOBAL cbData = createGlobalData(url, title); - if (!::SetClipboardData(BookmarkClipboardFormat, cbData)) - ::GlobalFree(cbData); - ::CloseClipboard(); - } - - // write to clipboard in format CF_HTML to be able to paste into contenteditable areas as a link - if (::OpenClipboard(m_owner)) { - Vector<char> data; - markupToCF_HTML(urlToMarkup(url, title), "", data); - HGLOBAL cbData = createGlobalData(data); - if (!::SetClipboardData(HTMLClipboardFormat, cbData)) - ::GlobalFree(cbData); - ::CloseClipboard(); - } - - // bare-bones CF_UNICODETEXT support - if (::OpenClipboard(m_owner)) { - HGLOBAL cbData = createGlobalData(url.string()); - if (!::SetClipboardData(CF_UNICODETEXT, cbData)) - ::GlobalFree(cbData); - ::CloseClipboard(); - } -} - -void Pasteboard::writeImage(Node* node, const KURL&, const String&) -{ - ASSERT(node && node->renderer() && node->renderer()->isImage()); - RenderImage* renderer = static_cast<RenderImage*>(node->renderer()); - CachedImage* cachedImage = static_cast<CachedImage*>(renderer->cachedImage()); - ASSERT(cachedImage); - Image* image = cachedImage->image(); - ASSERT(image); - - clear(); - - HDC dc = GetDC(0); - HDC compatibleDC = CreateCompatibleDC(0); - HDC sourceDC = CreateCompatibleDC(0); - HBITMAP resultBitmap = CreateCompatibleBitmap(dc, image->width(), image->height()); - HBITMAP oldBitmap = (HBITMAP)SelectObject(compatibleDC, resultBitmap); - - BITMAPINFO bmInfo = {0}; - bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmInfo.bmiHeader.biWidth = image->width(); - bmInfo.bmiHeader.biHeight = image->height(); - bmInfo.bmiHeader.biPlanes = 1; - bmInfo.bmiHeader.biBitCount = 32; - bmInfo.bmiHeader.biCompression = BI_RGB; - HBITMAP coreBitmap = CreateDIBSection(dc, &bmInfo, DIB_RGB_COLORS, 0, 0, 0); - HBITMAP oldSource = (HBITMAP)SelectObject(sourceDC, coreBitmap); - image->getHBITMAP(coreBitmap); - - BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA}; - AlphaBlend(compatibleDC, 0, 0, image->width(), image->height(), - sourceDC, 0, 0, image->width(), image->height(), bf); - - SelectObject(compatibleDC, oldBitmap); - SelectObject(sourceDC, oldSource); - - DeleteObject(oldBitmap); - DeleteObject(oldSource); - DeleteObject(coreBitmap); - ReleaseDC(0, dc); - DeleteDC(compatibleDC); - DeleteDC(sourceDC); - - if (::OpenClipboard(m_owner)) { - ::SetClipboardData(CF_BITMAP, resultBitmap); - ::CloseClipboard(); - } -} - -bool Pasteboard::canSmartReplace() -{ - return ::IsClipboardFormatAvailable(WebSmartPasteFormat); -} - -String Pasteboard::plainText(Frame* frame) -{ - if (::IsClipboardFormatAvailable(CF_UNICODETEXT) && ::OpenClipboard(m_owner)) { - HANDLE cbData = ::GetClipboardData(CF_UNICODETEXT); - if (cbData) { - UChar* buffer = (UChar*)::GlobalLock(cbData); - String fromClipboard(buffer); - ::GlobalUnlock(cbData); - ::CloseClipboard(); - return fromClipboard; - } else - ::CloseClipboard(); - } - - if (::IsClipboardFormatAvailable(CF_TEXT) && ::OpenClipboard(m_owner)) { - HANDLE cbData = ::GetClipboardData(CF_TEXT); - if (cbData) { - char* buffer = (char*)::GlobalLock(cbData); - String fromClipboard(buffer); - ::GlobalUnlock(cbData); - ::CloseClipboard(); - return fromClipboard; - } else - ::CloseClipboard(); - } - - return String(); -} - -PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText) -{ - chosePlainText = false; - - if (::IsClipboardFormatAvailable(HTMLClipboardFormat) && ::OpenClipboard(m_owner)) { - // get data off of clipboard - HANDLE cbData = ::GetClipboardData(HTMLClipboardFormat); - if (cbData) { - SIZE_T dataSize = ::GlobalSize(cbData); - String cf_html(UTF8Encoding().decode((char*)::GlobalLock(cbData), dataSize)); - ::GlobalUnlock(cbData); - ::CloseClipboard(); - - PassRefPtr<DocumentFragment> fragment = fragmentFromCF_HTML(frame->document(), cf_html); - if (fragment) - return fragment; - } else - ::CloseClipboard(); - } - - if (allowPlainText && ::IsClipboardFormatAvailable(CF_UNICODETEXT)) { - chosePlainText = true; - if (::OpenClipboard(m_owner)) { - HANDLE cbData = ::GetClipboardData(CF_UNICODETEXT); - if (cbData) { - UChar* buffer = (UChar*)GlobalLock(cbData); - String str(buffer); - ::GlobalUnlock( cbData ); - ::CloseClipboard(); - RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), str); - if (fragment) - return fragment.release(); - } else - ::CloseClipboard(); - } - } - - if (allowPlainText && ::IsClipboardFormatAvailable(CF_TEXT)) { - chosePlainText = true; - if (::OpenClipboard(m_owner)) { - HANDLE cbData = ::GetClipboardData(CF_TEXT); - if (cbData) { - char* buffer = (char*)GlobalLock(cbData); - String str(buffer); - ::GlobalUnlock( cbData ); - ::CloseClipboard(); - RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), str); - if (fragment) - return fragment.release(); - } else - ::CloseClipboard(); - } - } - - return 0; -} - -} // namespace WebCore diff --git a/WebCore/platform/win/PlatformMouseEventWin.cpp b/WebCore/platform/win/PlatformMouseEventWin.cpp deleted file mode 100644 index 7110b39..0000000 --- a/WebCore/platform/win/PlatformMouseEventWin.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "PlatformMouseEvent.h" - -#include <wtf/Assertions.h> -#include <windows.h> -#include <windowsx.h> - -namespace WebCore { - -#define HIGH_BIT_MASK_SHORT 0x8000 - -static IntPoint positionForEvent(HWND hWnd, LPARAM lParam) -{ - POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; - return point; -} - -static IntPoint globalPositionForEvent(HWND hWnd, LPARAM lParam) -{ - POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; - ClientToScreen(hWnd, &point); - return point; -} - -static MouseEventType messageToEventType(UINT message) -{ - switch (message) { - case WM_LBUTTONDBLCLK: - case WM_RBUTTONDBLCLK: - case WM_MBUTTONDBLCLK: - //MSDN docs say double click is sent on mouse down - case WM_LBUTTONDOWN: - case WM_RBUTTONDOWN: - case WM_MBUTTONDOWN: - return MouseEventPressed; - - case WM_LBUTTONUP: - case WM_RBUTTONUP: - case WM_MBUTTONUP: - return MouseEventReleased; - - case WM_MOUSELEAVE: - case WM_MOUSEMOVE: - return MouseEventMoved; - - default: - ASSERT_NOT_REACHED(); - //Move is relatively harmless - return MouseEventMoved; - } -} -PlatformMouseEvent::PlatformMouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool activatedWebView) - : m_position(positionForEvent(hWnd, lParam)) - , m_globalPosition(globalPositionForEvent(hWnd, lParam)) - , m_clickCount(0) - , m_shiftKey(wParam & MK_SHIFT) - , m_ctrlKey(wParam & MK_CONTROL) - , m_altKey(GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT) - , m_metaKey(m_altKey) // FIXME: We'll have to test other browsers - , m_activatedWebView(activatedWebView) - , m_eventType(messageToEventType(message)) - , m_modifierFlags(wParam) -{ - m_timestamp = ::GetTickCount()*0.001; // GetTickCount returns milliseconds - - switch (message) { - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_LBUTTONDBLCLK: - m_button = LeftButton; - break; - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - case WM_RBUTTONDBLCLK: - m_button = RightButton; - break; - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_MBUTTONDBLCLK: - m_button = MiddleButton; - break; - case WM_MOUSEMOVE: - case WM_MOUSELEAVE: - if (wParam & MK_LBUTTON) - m_button = LeftButton; - else if (wParam & MK_MBUTTON) - m_button = MiddleButton; - else if (wParam & MK_RBUTTON) - m_button = RightButton; - else - m_button = NoButton; - break; - default: - ASSERT_NOT_REACHED(); - } -} - -} // namespace WebCore diff --git a/WebCore/platform/win/PlatformScreenWin.cpp b/WebCore/platform/win/PlatformScreenWin.cpp deleted file mode 100644 index 56c8139..0000000 --- a/WebCore/platform/win/PlatformScreenWin.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "PlatformScreen.h" - -#include "IntRect.h" -#include "FloatRect.h" -#include "Frame.h" -#include "FrameView.h" -#include "Page.h" -#include <windows.h> - -namespace WebCore { - -// Returns info for the default monitor if widget is NULL -static MONITORINFOEX monitorInfoForWidget(Widget* widget) -{ - HWND window = widget ? widget->root()->hostWindow()->platformWindow() : 0; - HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY); - - MONITORINFOEX monitorInfo; - monitorInfo.cbSize = sizeof(MONITORINFOEX); - GetMonitorInfo(monitor, &monitorInfo); - return monitorInfo; -} - -static DEVMODE deviceInfoForWidget(Widget* widget) -{ - MONITORINFOEX monitorInfo = monitorInfoForWidget(widget); - - DEVMODE deviceInfo; - deviceInfo.dmSize = sizeof(DEVMODE); - deviceInfo.dmDriverExtra = 0; - EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &deviceInfo); - - return deviceInfo; -} - -int screenDepth(Widget* widget) -{ - DEVMODE deviceInfo = deviceInfoForWidget(widget); - return deviceInfo.dmBitsPerPel; -} - -int screenDepthPerComponent(Widget* widget) -{ - // FIXME: Assumes RGB -- not sure if this is right. - DEVMODE deviceInfo = deviceInfoForWidget(widget); - return deviceInfo.dmBitsPerPel / 3; -} - -bool screenIsMonochrome(Widget* widget) -{ - DEVMODE deviceInfo = deviceInfoForWidget(widget); - return deviceInfo.dmColor == DMCOLOR_MONOCHROME; -} - -FloatRect screenRect(Widget* widget) -{ - MONITORINFOEX monitorInfo = monitorInfoForWidget(widget); - return monitorInfo.rcMonitor; -} - -FloatRect screenAvailableRect(Widget* widget) -{ - MONITORINFOEX monitorInfo = monitorInfoForWidget(widget); - return monitorInfo.rcWork; -} - -} // namespace WebCore diff --git a/WebCore/platform/win/PlatformScrollBar.h b/WebCore/platform/win/PlatformScrollBar.h deleted file mode 100644 index c84616a..0000000 --- a/WebCore/platform/win/PlatformScrollBar.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006, 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 - * 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 "Scrollbar.h" -#include "Timer.h" -#include <wtf/PassRefPtr.h> - -typedef struct HDC__* HDC; - -namespace WebCore { - -class PlatformScrollbar : public Scrollbar { -public: - static PassRefPtr<PlatformScrollbar> create(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size) - { - return adoptRef(new PlatformScrollbar(client, orientation, size)); - } - - PlatformScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0); -}; - -} - -#endif // PlatformScrollbar_h - diff --git a/WebCore/platform/win/PlatformScrollBarWin.cpp b/WebCore/platform/win/PlatformScrollBarWin.cpp deleted file mode 100644 index aa5333b..0000000 --- a/WebCore/platform/win/PlatformScrollBarWin.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. - * Copyright (C) 2008 Brent Fulgham - * - * 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 "FrameView.h" -#include "ScrollbarClient.h" -#include "ScrollbarTheme.h" - -namespace WebCore { - -PlatformScrollbar::PlatformScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size, - ScrollbarTheme* theme) - : Scrollbar(client, orientation, size, theme) -{ -} - -} - diff --git a/WebCore/platform/win/PopupMenuWin.cpp b/WebCore/platform/win/PopupMenuWin.cpp deleted file mode 100644 index 64b8a59..0000000 --- a/WebCore/platform/win/PopupMenuWin.cpp +++ /dev/null @@ -1,834 +0,0 @@ -/* - * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. - * - * 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 "PopupMenu.h" - -#include "Document.h" -#include "FloatRect.h" -#include "FontSelector.h" -#include "Frame.h" -#include "FrameView.h" -#include "GraphicsContext.h" -#include "HTMLNames.h" -#include "Page.h" -#include "PlatformMouseEvent.h" -#include "PlatformScreen.h" -#include "RenderTheme.h" -#include "RenderView.h" -#include "Scrollbar.h" -#include "ScrollbarTheme.h" -#include "SimpleFontData.h" -#include <tchar.h> -#include <windows.h> - -using std::min; - -namespace WebCore { - -using namespace HTMLNames; - -// Default Window animation duration in milliseconds -static const int defaultAnimationDuration = 200; -// Maximum height of a popup window -static const int maxPopupHeight = 320; - -static const int popupWindowAlphaPercent = 95; - -const int optionSpacingMiddle = 1; -const int popupWindowBorderWidth = 1; - -static LPCTSTR kPopupWindowClassName = _T("PopupWindowClass"); -static ATOM registerPopup(); -static LRESULT CALLBACK PopupWndProc(HWND, UINT, WPARAM, LPARAM); - -// FIXME: Remove this as soon as practical. -static inline bool isASCIIPrintable(unsigned c) -{ - return c >= 0x20 && c <= 0x7E; -} - -PopupMenu::PopupMenu(PopupMenuClient* client) - : m_popupClient(client) - , m_scrollbar(0) - , m_popup(0) - , m_DC(0) - , m_bmp(0) - , m_wasClicked(false) - , m_itemHeight(0) - , m_scrollOffset(0) - , m_wheelDelta(0) - , m_focusedIndex(0) - , m_scrollbarCapturingMouse(false) -{ -} - -PopupMenu::~PopupMenu() -{ - if (m_bmp) - ::DeleteObject(m_bmp); - if (m_DC) - ::DeleteObject(m_DC); - if (m_popup) - ::DestroyWindow(m_popup); -} - -void PopupMenu::show(const IntRect& r, FrameView* v, int index) -{ - calculatePositionAndSize(r, v); - if (clientRect().isEmpty()) - return; - - if (!m_popup) { - registerPopup(); - - DWORD exStyle = WS_EX_LAYERED | WS_EX_LTRREADING; - - // Even though we already know our size and location at this point, we pass (0,0,0,0) as our size/location here. - // We need to wait until after the call to ::SetWindowLongPtr to set our size so that in our WM_SIZE handler we can get access to the PopupMenu object - m_popup = ::CreateWindowEx(exStyle, kPopupWindowClassName, _T("PopupMenu"), - WS_POPUP | WS_BORDER, - 0, 0, 0, 0, - v->hostWindow()->platformWindow(), 0, 0, 0); - - if (!m_popup) - return; - - ::SetWindowLongPtr(m_popup, 0, (LONG_PTR)this); - ::SetLayeredWindowAttributes(m_popup, 0, (255 * popupWindowAlphaPercent) / 100, LWA_ALPHA); - } - - if (!m_scrollbar) - if (visibleItems() < client()->listSize()) { - // We need a scroll bar - m_scrollbar = client()->createScrollbar(this, VerticalScrollbar, SmallScrollbar); - } - - ::SetWindowPos(m_popup, HWND_TOP, m_windowRect.x(), m_windowRect.y(), m_windowRect.width(), m_windowRect.height(), 0); - - // Determine whether we should animate our popups - // Note: Must use 'BOOL' and 'FALSE' instead of 'bool' and 'false' to avoid stack corruption with SystemParametersInfo - BOOL shouldAnimate = FALSE; -#ifdef CAN_ANIMATE_TRANSPARENT_WINDOWS_SMOOTHLY - ::SystemParametersInfo(SPI_GETCOMBOBOXANIMATION, 0, &shouldAnimate, 0); -#endif - - if (shouldAnimate) { - RECT viewRect = {0}; - ::GetWindowRect(v->hostWindow()->platformWindow(), &viewRect); - - if (!::IsRectEmpty(&viewRect)) { - // Popups should slide into view away from the <select> box - // NOTE: This may have to change for Vista - DWORD slideDirection = (m_windowRect.y() < viewRect.top + v->contentsToWindow(r.location()).y()) ? AW_VER_NEGATIVE : AW_VER_POSITIVE; - - ::AnimateWindow(m_popup, defaultAnimationDuration, AW_SLIDE | slideDirection | AW_ACTIVATE); - } - } else - ::ShowWindow(m_popup, SW_SHOWNORMAL); - ::SetCapture(m_popup); - - if (client()) { - int index = client()->selectedIndex(); - if (index >= 0) - setFocusedIndex(index); - } -} - -void PopupMenu::hide() -{ - ::ShowWindow(m_popup, SW_HIDE); -} - -const int endOfLinePadding = 2; -void PopupMenu::calculatePositionAndSize(const IntRect& r, FrameView* v) -{ - // r is in absolute document coordinates, but we want to be in screen coordinates - - // First, move to WebView coordinates - IntRect rScreenCoords(v->contentsToWindow(r.location()), r.size()); - - // Then, translate to screen coordinates - POINT location(rScreenCoords.location()); - if (!::ClientToScreen(v->hostWindow()->platformWindow(), &location)) - return; - - rScreenCoords.setLocation(location); - - // First, determine the popup's height - int itemCount = client()->listSize(); - m_itemHeight = client()->menuStyle().font().height() + optionSpacingMiddle; - int naturalHeight = m_itemHeight * itemCount; - int popupHeight = min(maxPopupHeight, naturalHeight); - // The popup should show an integral number of items (i.e. no partial items should be visible) - popupHeight -= popupHeight % m_itemHeight; - - // Next determine its width - int popupWidth = 0; - for (int i = 0; i < itemCount; ++i) { - String text = client()->itemText(i); - if (text.isEmpty()) - continue; - - Font itemFont = client()->menuStyle().font(); - if (client()->itemIsLabel(i)) { - FontDescription d = itemFont.fontDescription(); - d.setWeight(d.bolderWeight()); - itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing()); - itemFont.update(m_popupClient->fontSelector()); - } - - popupWidth = max(popupWidth, itemFont.width(TextRun(text.characters(), text.length()))); - } - - if (naturalHeight > maxPopupHeight) - // We need room for a scrollbar - popupWidth += ScrollbarTheme::nativeTheme()->scrollbarThickness(SmallScrollbar); - - // Add padding to align the popup text with the <select> text - // Note: We can't add paddingRight() because that value includes the width - // of the dropdown button, so we must use our own endOfLinePadding constant. - popupWidth += max(0, endOfLinePadding - client()->clientInsetRight()) + max(0, client()->clientPaddingLeft() - client()->clientInsetLeft()); - - // Leave room for the border - popupWidth += 2 * popupWindowBorderWidth; - popupHeight += 2 * popupWindowBorderWidth; - - // The popup should be at least as wide as the control on the page - popupWidth = max(rScreenCoords.width() - client()->clientInsetLeft() - client()->clientInsetRight(), popupWidth); - - // Always left-align items in the popup. This matches popup menus on the mac. - int popupX = rScreenCoords.x() + client()->clientInsetLeft(); - - IntRect popupRect(popupX, rScreenCoords.bottom(), popupWidth, popupHeight); - - // The popup needs to stay within the bounds of the screen and not overlap any toolbars - FloatRect screen = screenAvailableRect(v); - - // Check that we don't go off the screen vertically - if (popupRect.bottom() > screen.height()) { - // The popup will go off the screen, so try placing it above the client - if (rScreenCoords.y() - popupRect.height() < 0) { - // The popup won't fit above, either, so place it whereever's bigger and resize it to fit - if ((rScreenCoords.y() + rScreenCoords.height() / 2) < (screen.height() / 2)) { - // Below is bigger - popupRect.setHeight(screen.height() - popupRect.y()); - } else { - // Above is bigger - popupRect.setY(0); - popupRect.setHeight(rScreenCoords.y()); - } - } else { - // The popup fits above, so reposition it - popupRect.setY(rScreenCoords.y() - popupRect.height()); - } - } - - // Check that we don't go off the screen horizontally - if (popupRect.x() < screen.x()) { - popupRect.setWidth(popupRect.width() - (screen.x() - popupRect.x())); - popupRect.setX(screen.x()); - } - m_windowRect = popupRect; - return; -} - -bool PopupMenu::setFocusedIndex(int i, bool hotTracking) -{ - if (i < 0 || i >= client()->listSize() || i == focusedIndex()) - return false; - - if (!client()->itemIsEnabled(i)) - return false; - - invalidateItem(focusedIndex()); - invalidateItem(i); - - m_focusedIndex = i; - - if (!hotTracking) - client()->setTextFromItem(i); - - if (!scrollToRevealSelection()) - ::UpdateWindow(m_popup); - - return true; -} - -int PopupMenu::visibleItems() const -{ - return clientRect().height() / m_itemHeight; -} - -int PopupMenu::listIndexAtPoint(const IntPoint& point) const -{ - return m_scrollOffset + point.y() / m_itemHeight; -} - -int PopupMenu::focusedIndex() const -{ - return m_focusedIndex; -} - -void PopupMenu::focusFirst() -{ - if (!client()) - return; - - int size = client()->listSize(); - - for (int i = 0; i < size; ++i) - if (client()->itemIsEnabled(i)) { - setFocusedIndex(i); - break; - } -} - -void PopupMenu::focusLast() -{ - if (!client()) - return; - - int size = client()->listSize(); - - for (int i = size - 1; i > 0; --i) - if (client()->itemIsEnabled(i)) { - setFocusedIndex(i); - break; - } -} - -bool PopupMenu::down(unsigned lines) -{ - if (!client()) - return false; - - int size = client()->listSize(); - - int lastSelectableIndex, selectedListIndex; - lastSelectableIndex = selectedListIndex = focusedIndex(); - for (int i = selectedListIndex + 1; i >= 0 && i < size; ++i) - if (client()->itemIsEnabled(i)) { - lastSelectableIndex = i; - if (i >= selectedListIndex + (int)lines) - break; - } - - return setFocusedIndex(lastSelectableIndex); -} - -bool PopupMenu::up(unsigned lines) -{ - if (!client()) - return false; - - int size = client()->listSize(); - - int lastSelectableIndex, selectedListIndex; - lastSelectableIndex = selectedListIndex = focusedIndex(); - for (int i = selectedListIndex - 1; i >= 0 && i < size; --i) - if (client()->itemIsEnabled(i)) { - lastSelectableIndex = i; - if (i <= selectedListIndex - (int)lines) - break; - } - - return setFocusedIndex(lastSelectableIndex); -} - -void PopupMenu::invalidateItem(int index) -{ - if (!m_popup) - return; - - IntRect damageRect(clientRect()); - damageRect.setY(m_itemHeight * (index - m_scrollOffset)); - damageRect.setHeight(m_itemHeight); - if (m_scrollbar) - damageRect.setWidth(damageRect.width() - m_scrollbar->frameRect().width()); - - RECT r = damageRect; - ::InvalidateRect(m_popup, &r, TRUE); -} - -IntRect PopupMenu::clientRect() const -{ - IntRect clientRect = m_windowRect; - clientRect.inflate(-popupWindowBorderWidth); - clientRect.setLocation(IntPoint(0, 0)); - return clientRect; -} - -void PopupMenu::incrementWheelDelta(int delta) -{ - m_wheelDelta += delta; -} - -void PopupMenu::reduceWheelDelta(int delta) -{ - ASSERT(delta >= 0); - ASSERT(delta <= abs(m_wheelDelta)); - - if (m_wheelDelta > 0) - m_wheelDelta -= delta; - else if (m_wheelDelta < 0) - m_wheelDelta += delta; - else - return; -} - -bool PopupMenu::scrollToRevealSelection() -{ - if (!m_scrollbar) - return false; - - int index = focusedIndex(); - - if (index < m_scrollOffset) { - m_scrollbar->setValue(index); - return true; - } - - if (index >= m_scrollOffset + visibleItems()) { - m_scrollbar->setValue(index - visibleItems() + 1); - return true; - } - - return false; -} - -void PopupMenu::updateFromElement() -{ - if (!m_popup) - return; - - m_focusedIndex = client()->selectedIndex(); - - ::InvalidateRect(m_popup, 0, TRUE); - if (!scrollToRevealSelection()) - ::UpdateWindow(m_popup); -} - -bool PopupMenu::itemWritingDirectionIsNatural() -{ - return true; -} - -const int separatorPadding = 4; -const int separatorHeight = 1; -void PopupMenu::paint(const IntRect& damageRect, HDC hdc) -{ - if (!m_popup) - return; - - if (!m_DC) { - m_DC = ::CreateCompatibleDC(::GetDC(m_popup)); - if (!m_DC) - return; - } - - if (m_bmp) { - bool keepBitmap = false; - BITMAP bitmap; - if (GetObject(m_bmp, sizeof(bitmap), &bitmap)) - keepBitmap = bitmap.bmWidth == clientRect().width() - && bitmap.bmHeight == clientRect().height(); - if (!keepBitmap) { - DeleteObject(m_bmp); - m_bmp = 0; - } - } - if (!m_bmp) { - BITMAPINFO bitmapInfo; - bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bitmapInfo.bmiHeader.biWidth = clientRect().width(); - bitmapInfo.bmiHeader.biHeight = -clientRect().height(); - bitmapInfo.bmiHeader.biPlanes = 1; - bitmapInfo.bmiHeader.biBitCount = 32; - bitmapInfo.bmiHeader.biCompression = BI_RGB; - bitmapInfo.bmiHeader.biSizeImage = 0; - bitmapInfo.bmiHeader.biXPelsPerMeter = 0; - bitmapInfo.bmiHeader.biYPelsPerMeter = 0; - bitmapInfo.bmiHeader.biClrUsed = 0; - bitmapInfo.bmiHeader.biClrImportant = 0; - - void* pixels = 0; - m_bmp = ::CreateDIBSection(m_DC, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0); - if (!m_bmp) - return; - - ::SelectObject(m_DC, m_bmp); - } - - GraphicsContext context(m_DC); - - int itemCount = client()->listSize(); - - // listRect is the damageRect translated into the coordinates of the entire menu list (which is itemCount * m_itemHeight pixels tall) - IntRect listRect = damageRect; - listRect.move(IntSize(0, m_scrollOffset * m_itemHeight)); - - for (int y = listRect.y(); y < listRect.bottom(); y += m_itemHeight) { - int index = y / m_itemHeight; - - Color optionBackgroundColor, optionTextColor; - PopupMenuStyle itemStyle = client()->itemStyle(index); - if (index == focusedIndex()) { - optionBackgroundColor = theme()->activeListBoxSelectionBackgroundColor(); - optionTextColor = theme()->activeListBoxSelectionForegroundColor(); - } else { - optionBackgroundColor = itemStyle.backgroundColor(); - optionTextColor = itemStyle.foregroundColor(); - } - - // itemRect is in client coordinates - IntRect itemRect(0, (index - m_scrollOffset) * m_itemHeight, damageRect.width(), m_itemHeight); - - // Draw the background for this menu item - if (itemStyle.isVisible()) - context.fillRect(itemRect, optionBackgroundColor); - - if (client()->itemIsSeparator(index)) { - IntRect separatorRect(itemRect.x() + separatorPadding, itemRect.y() + (itemRect.height() - separatorHeight) / 2, itemRect.width() - 2 * separatorPadding, separatorHeight); - context.fillRect(separatorRect, optionTextColor); - continue; - } - - String itemText = client()->itemText(index); - - unsigned length = itemText.length(); - const UChar* string = itemText.characters(); - TextRun textRun(string, length, false, 0, 0, itemText.defaultWritingDirection() == WTF::Unicode::RightToLeft); - - context.setFillColor(optionTextColor); - - Font itemFont = client()->menuStyle().font(); - if (client()->itemIsLabel(index)) { - FontDescription d = itemFont.fontDescription(); - d.setWeight(d.bolderWeight()); - itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing()); - itemFont.update(m_popupClient->fontSelector()); - } - context.setFont(itemFont); - - // Draw the item text - if (itemStyle.isVisible()) { - int textX = max(0, client()->clientPaddingLeft() - client()->clientInsetLeft()); - int textY = itemRect.y() + itemFont.ascent() + (itemRect.height() - itemFont.height()) / 2; - context.drawBidiText(textRun, IntPoint(textX, textY)); - } - } - - if (m_scrollbar) - m_scrollbar->paint(&context, damageRect); - - if (!hdc) - hdc = ::GetDC(m_popup); - - ::BitBlt(hdc, damageRect.x(), damageRect.y(), damageRect.width(), damageRect.height(), m_DC, damageRect.x(), damageRect.y(), SRCCOPY); -} - -void PopupMenu::valueChanged(Scrollbar* scrollBar) -{ - ASSERT(m_scrollbar); - - if (!m_popup) - return; - - int offset = scrollBar->value(); - - if (m_scrollOffset == offset) - return; - - int scrolledLines = m_scrollOffset - offset; - m_scrollOffset = offset; - - UINT flags = SW_INVALIDATE; - -#ifdef CAN_SET_SMOOTH_SCROLLING_DURATION - BOOL shouldSmoothScroll = FALSE; - ::SystemParametersInfo(SPI_GETLISTBOXSMOOTHSCROLLING, 0, &shouldSmoothScroll, 0); - if (shouldSmoothScroll) - flags |= MAKEWORD(SW_SMOOTHSCROLL, smoothScrollAnimationDuration); -#endif - - IntRect listRect = clientRect(); - if (m_scrollbar) - listRect.setWidth(listRect.width() - m_scrollbar->frameRect().width()); - RECT r = listRect; - ::ScrollWindowEx(m_popup, 0, scrolledLines * m_itemHeight, &r, 0, 0, 0, flags); - if (m_scrollbar) { - r = m_scrollbar->frameRect(); - ::InvalidateRect(m_popup, &r, TRUE); - } - ::UpdateWindow(m_popup); -} - -void PopupMenu::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect) -{ - IntRect scrollRect = rect; - scrollRect.move(scrollbar->x(), scrollbar->y()); - RECT r = scrollRect; - ::InvalidateRect(m_popup, &r, false); -} - -static ATOM registerPopup() -{ - static bool haveRegisteredWindowClass = false; - - if (haveRegisteredWindowClass) - return true; - - WNDCLASSEX wcex; - - wcex.cbSize = sizeof(WNDCLASSEX); - - wcex.style = 0; - wcex.lpfnWndProc = PopupWndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = sizeof(PopupMenu*); // For the PopupMenu pointer - wcex.hInstance = Page::instanceHandle(); - wcex.hIcon = 0; - wcex.hCursor = LoadCursor(0, IDC_ARROW); - wcex.hbrBackground = 0; - wcex.lpszMenuName = 0; - wcex.lpszClassName = kPopupWindowClassName; - wcex.hIconSm = 0; - - haveRegisteredWindowClass = true; - - return ::RegisterClassEx(&wcex); -} - -const int smoothScrollAnimationDuration = 5000; -static LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - LRESULT lResult = 0; - LONG_PTR longPtr = GetWindowLongPtr(hWnd, 0); - PopupMenu* popup = reinterpret_cast<PopupMenu*>(longPtr); - - switch (message) { - case WM_SIZE: - if (popup && popup->scrollbar()) { - IntSize size(LOWORD(lParam), HIWORD(lParam)); - popup->scrollbar()->setFrameRect(IntRect(size.width() - popup->scrollbar()->width(), 0, popup->scrollbar()->width(), size.height())); - - int visibleItems = popup->visibleItems(); - popup->scrollbar()->setEnabled(visibleItems < popup->client()->listSize()); - popup->scrollbar()->setSteps(1, max(1, visibleItems - 1)); - popup->scrollbar()->setProportion(visibleItems, popup->client()->listSize()); - } - break; - case WM_ACTIVATE: - if (popup && popup->client() && wParam == WA_INACTIVE) - popup->client()->hidePopup(); - break; - case WM_KILLFOCUS: - if (popup && popup->client() && (HWND)wParam != popup->popupHandle()) - // Focus is going elsewhere, so hide - popup->client()->hidePopup(); - break; - case WM_KEYDOWN: - if (popup && popup->client()) { - lResult = 0; - switch (LOWORD(wParam)) { - case VK_DOWN: - case VK_RIGHT: - popup->down(); - break; - case VK_UP: - case VK_LEFT: - popup->up(); - break; - case VK_HOME: - popup->focusFirst(); - break; - case VK_END: - popup->focusLast(); - break; - case VK_PRIOR: - if (popup->focusedIndex() != popup->scrollOffset()) { - // Set the selection to the first visible item - int firstVisibleItem = popup->scrollOffset(); - popup->up(popup->focusedIndex() - firstVisibleItem); - } else - // The first visible item is selected, so move the selection back one page - popup->up(popup->visibleItems()); - break; - case VK_NEXT: - if (popup) { - int lastVisibleItem = popup->scrollOffset() + popup->visibleItems() - 1; - if (popup->focusedIndex() != lastVisibleItem) { - // Set the selection to the last visible item - popup->down(lastVisibleItem - popup->focusedIndex()); - } else - // The last visible item is selected, so move the selection forward one page - popup->down(popup->visibleItems()); - } - break; - case VK_TAB: - ::SendMessage(popup->client()->hostWindow()->platformWindow(), message, wParam, lParam); - popup->client()->hidePopup(); - break; - default: - if (isASCIIPrintable(wParam)) - // Send the keydown to the WebView so it can be used for type-to-select. - ::PostMessage(popup->client()->hostWindow()->platformWindow(), message, wParam, lParam); - else - lResult = 1; - break; - } - } - break; - case WM_CHAR: - if (popup && popup->client()) { - lResult = 0; - int index; - switch (wParam) { - case 0x0D: // Enter/Return - popup->client()->hidePopup(); - index = popup->focusedIndex(); - ASSERT(index >= 0); - popup->client()->valueChanged(index); - break; - case 0x1B: // Escape - popup->client()->hidePopup(); - break; - case 0x09: // TAB - case 0x08: // Backspace - case 0x0A: // Linefeed - default: // Character - lResult = 1; - break; - } - } - break; - case WM_MOUSEMOVE: - if (popup) { - IntPoint mousePoint(MAKEPOINTS(lParam)); - if (popup->scrollbar()) { - IntRect scrollBarRect = popup->scrollbar()->frameRect(); - if (popup->scrollbarCapturingMouse() || scrollBarRect.contains(mousePoint)) { - // Put the point into coordinates relative to the scroll bar - mousePoint.move(-scrollBarRect.x(), -scrollBarRect.y()); - PlatformMouseEvent event(hWnd, message, wParam, MAKELPARAM(mousePoint.x(), mousePoint.y())); - popup->scrollbar()->mouseMoved(event); - break; - } - } - - BOOL shouldHotTrack = FALSE; - ::SystemParametersInfo(SPI_GETHOTTRACKING, 0, &shouldHotTrack, 0); - - RECT bounds; - GetClientRect(popup->popupHandle(), &bounds); - if ((shouldHotTrack || wParam & MK_LBUTTON) && ::PtInRect(&bounds, mousePoint)) - popup->setFocusedIndex(popup->listIndexAtPoint(mousePoint), true); - - // Release capture if the left button isn't down, and the mousePoint is outside the popup window. - // This way, the WebView will get future mouse events in the rest of the window. - if (!(wParam & MK_LBUTTON) && !::PtInRect(&bounds, mousePoint)) { - ::ReleaseCapture(); - break; - } - } - break; - case WM_LBUTTONDOWN: - if (popup) { - ::SetCapture(popup->popupHandle()); - IntPoint mousePoint(MAKEPOINTS(lParam)); - if (popup->scrollbar()) { - IntRect scrollBarRect = popup->scrollbar()->frameRect(); - if (scrollBarRect.contains(mousePoint)) { - // Put the point into coordinates relative to the scroll bar - mousePoint.move(-scrollBarRect.x(), -scrollBarRect.y()); - PlatformMouseEvent event(hWnd, message, wParam, MAKELPARAM(mousePoint.x(), mousePoint.y())); - popup->scrollbar()->mouseDown(event); - popup->setScrollbarCapturingMouse(true); - break; - } - } - - popup->setFocusedIndex(popup->listIndexAtPoint(mousePoint), true); - } - break; - case WM_LBUTTONUP: - if (popup) { - IntPoint mousePoint(MAKEPOINTS(lParam)); - if (popup->scrollbar()) { - ::ReleaseCapture(); - IntRect scrollBarRect = popup->scrollbar()->frameRect(); - if (popup->scrollbarCapturingMouse() || scrollBarRect.contains(mousePoint)) { - popup->setScrollbarCapturingMouse(false); - // Put the point into coordinates relative to the scroll bar - mousePoint.move(-scrollBarRect.x(), -scrollBarRect.y()); - PlatformMouseEvent event(hWnd, message, wParam, MAKELPARAM(mousePoint.x(), mousePoint.y())); - popup->scrollbar()->mouseUp(); - // FIXME: This is a hack to work around Scrollbar not invalidating correctly when it doesn't have a parent widget - RECT r = scrollBarRect; - ::InvalidateRect(popup->popupHandle(), &r, TRUE); - break; - } - } - // Only release capture and hide the popup if the mouse is inside the popup window. - RECT bounds; - GetClientRect(popup->popupHandle(), &bounds); - if (popup->client() && ::PtInRect(&bounds, mousePoint)) { - ::ReleaseCapture(); - popup->client()->hidePopup(); - int index = popup->focusedIndex(); - if (index >= 0) - popup->client()->valueChanged(index); - } - } - break; - case WM_MOUSEWHEEL: - if (popup && popup->scrollbar()) { - int i = 0; - for (popup->incrementWheelDelta(GET_WHEEL_DELTA_WPARAM(wParam)); abs(popup->wheelDelta()) >= WHEEL_DELTA; popup->reduceWheelDelta(WHEEL_DELTA)) - if (popup->wheelDelta() > 0) - ++i; - else - --i; - - popup->scrollbar()->scroll(i > 0 ? ScrollUp : ScrollDown, ScrollByLine, abs(i)); - } - break; - case WM_PAINT: - if (popup) { - PAINTSTRUCT paintInfo; - ::BeginPaint(popup->popupHandle(), &paintInfo); - popup->paint(paintInfo.rcPaint, paintInfo.hdc); - ::EndPaint(popup->popupHandle(), &paintInfo); - lResult = 0; - } - break; - case WM_PRINTCLIENT: - if (popup) - popup->paint(popup->clientRect(), (HDC)wParam); - break; - default: - lResult = DefWindowProc(hWnd, message, wParam, lParam); - } - - return lResult; -} - -} diff --git a/WebCore/platform/win/ScrollbarThemeSafari.cpp b/WebCore/platform/win/ScrollbarThemeSafari.cpp deleted file mode 100644 index 06a6533..0000000 --- a/WebCore/platform/win/ScrollbarThemeSafari.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * 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. - */ - -#include "config.h" -#include "ScrollbarThemeSafari.h" - -#if USE(SAFARI_THEME) - -#include "GraphicsContext.h" -#include "IntRect.h" -#include "Page.h" -#include "PlatformMouseEvent.h" -#include "Scrollbar.h" -#include "ScrollbarClient.h" -#include "ScrollbarThemeWin.h" -#include "Settings.h" -#include "SoftLinking.h" - -#include <CoreGraphics/CoreGraphics.h> - -// If you have an empty placeholder SafariThemeConstants.h, then include SafariTheme.h -// This is a workaround until a version of WebKitSupportLibrary is released with an updated SafariThemeConstants.h -#include <SafariTheme/SafariThemeConstants.h> -#ifndef SafariThemeConstants_h -#include <SafariTheme/SafariTheme.h> -#endif - -// FIXME: There are repainting problems due to Aqua scroll bar buttons' visual overflow. - -using namespace std; - -namespace WebCore { - -using namespace SafariTheme; - -ScrollbarTheme* ScrollbarTheme::nativeTheme() -{ - static ScrollbarThemeSafari safariTheme; - static ScrollbarThemeWin windowsTheme; - if (Settings::shouldPaintNativeControls()) - return &windowsTheme; - return &safariTheme; -} - -// FIXME: Get these numbers from CoreUI. -static int cScrollbarThickness[] = { 15, 11 }; -static int cRealButtonLength[] = { 28, 21 }; -static int cButtonInset[] = { 14, 11 }; -static int cButtonHitInset[] = { 3, 2 }; -// cRealButtonLength - cButtonInset -static int cButtonLength[] = { 14, 10 }; -static int cThumbMinLength[] = { 26, 20 }; - -#if !defined(NDEBUG) && defined(USE_DEBUG_SAFARI_THEME) -SOFT_LINK_DEBUG_LIBRARY(SafariTheme) -#else -SOFT_LINK_LIBRARY(SafariTheme) -#endif - -SOFT_LINK(SafariTheme, paintThemePart, void, __stdcall, - (ThemePart part, CGContextRef context, const CGRect& rect, NSControlSize size, ThemeControlState state), - (part, context, rect, size, state)) - -static ScrollbarControlState scrollbarControlStateFromThemeState(ThemeControlState state) -{ - ScrollbarControlState s = 0; - if (state & ActiveState) - s |= ActiveScrollbarState; - if (state & EnabledState) - s |= EnabledScrollbarState; - if (state & PressedState) - s |= PressedScrollbarState; - return s; -} - -ScrollbarThemeSafari::~ScrollbarThemeSafari() -{ -} - -int ScrollbarThemeSafari::scrollbarThickness(ScrollbarControlSize controlSize) -{ - return cScrollbarThickness[controlSize]; -} - -bool ScrollbarThemeSafari::hasButtons(Scrollbar* scrollbar) -{ - return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScrollbar ? - scrollbar->width() : - scrollbar->height()) >= 2 * (cRealButtonLength[scrollbar->controlSize()] - cButtonHitInset[scrollbar->controlSize()]); -} - -bool ScrollbarThemeSafari::hasThumb(Scrollbar* scrollbar) -{ - return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScrollbar ? - scrollbar->width() : - scrollbar->height()) >= 2 * cButtonInset[scrollbar->controlSize()] + cThumbMinLength[scrollbar->controlSize()] + 1; -} - -static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation orientation, ScrollbarControlSize controlSize, bool start) -{ - IntRect paintRect(buttonRect); - if (orientation == HorizontalScrollbar) { - paintRect.setWidth(cRealButtonLength[controlSize]); - if (!start) - paintRect.setX(buttonRect.x() - (cRealButtonLength[controlSize] - buttonRect.width())); - } else { - paintRect.setHeight(cRealButtonLength[controlSize]); - if (!start) - paintRect.setY(buttonRect.y() - (cRealButtonLength[controlSize] - buttonRect.height())); - } - - return paintRect; -} - -IntRect ScrollbarThemeSafari::backButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool painting) -{ - IntRect result; - - // Windows just has single arrows. - if (part == BackButtonEndPart) - return result; - - int thickness = scrollbarThickness(scrollbar->controlSize()); - if (scrollbar->orientation() == HorizontalScrollbar) - result = IntRect(scrollbar->x(), scrollbar->y(), cButtonLength[scrollbar->controlSize()], thickness); - else - result = IntRect(scrollbar->x(), scrollbar->y(), thickness, cButtonLength[scrollbar->controlSize()]); - if (painting) - return buttonRepaintRect(result, scrollbar->orientation(), scrollbar->controlSize(), true); - return result; -} - -IntRect ScrollbarThemeSafari::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool painting) -{ - IntRect result; - - // Windows just has single arrows. - if (part == ForwardButtonStartPart) - return result; - - int thickness = scrollbarThickness(scrollbar->controlSize()); - if (scrollbar->orientation() == HorizontalScrollbar) - result = IntRect(scrollbar->x() + scrollbar->width() - cButtonLength[scrollbar->controlSize()], scrollbar->y(), cButtonLength[scrollbar->controlSize()], thickness); - else - result = IntRect(scrollbar->x(), scrollbar->y() + scrollbar->height() - cButtonLength[scrollbar->controlSize()], thickness, cButtonLength[scrollbar->controlSize()]); - if (painting) - return buttonRepaintRect(result, scrollbar->orientation(), scrollbar->controlSize(), false); - return result; -} - -static IntRect trackRepaintRect(const IntRect& trackRect, ScrollbarOrientation orientation, ScrollbarControlSize controlSize) -{ - IntRect paintRect(trackRect); - if (orientation == HorizontalScrollbar) - paintRect.inflateX(cButtonLength[controlSize]); - else - paintRect.inflateY(cButtonLength[controlSize]); - - return paintRect; -} - -IntRect ScrollbarThemeSafari::trackRect(Scrollbar* scrollbar, bool painting) -{ - if (painting || !hasButtons(scrollbar)) - return scrollbar->frameRect(); - - IntRect result; - int thickness = scrollbarThickness(scrollbar->controlSize()); - if (scrollbar->orientation() == HorizontalScrollbar) - return IntRect(scrollbar->x() + cButtonLength[scrollbar->controlSize()], scrollbar->y(), scrollbar->width() - 2 * cButtonLength[scrollbar->controlSize()], thickness); - return IntRect(scrollbar->x(), scrollbar->y() + cButtonLength[scrollbar->controlSize()], thickness, scrollbar->height() - 2 * cButtonLength[scrollbar->controlSize()]); -} - -int ScrollbarThemeSafari::minimumThumbLength(Scrollbar* scrollbar) -{ - return cThumbMinLength[scrollbar->controlSize()]; -} - -bool ScrollbarThemeSafari::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt) -{ - return evt.shiftKey() && evt.button() == LeftButton; -} - -void ScrollbarThemeSafari::paintTrackBackground(GraphicsContext* graphicsContext, Scrollbar* scrollbar, const IntRect& trackRect) -{ - if (!SafariThemeLibrary()) - return; - NSControlSize size = scrollbar->controlSize() == SmallScrollbar ? NSSmallControlSize : NSRegularControlSize; - ThemeControlState state = 0; - if (scrollbar->client()->isActive()) - state |= ActiveState; - if (hasButtons(scrollbar)) - state |= EnabledState; - paintThemePart(scrollbar->orientation() == VerticalScrollbar ? VScrollTrackPart : HScrollTrackPart, graphicsContext->platformContext(), trackRect, size, state); -} - -void ScrollbarThemeSafari::paintButton(GraphicsContext* graphicsContext, Scrollbar* scrollbar, const IntRect& buttonRect, ScrollbarPart part) -{ - if (!SafariThemeLibrary()) - return; - NSControlSize size = scrollbar->controlSize() == SmallScrollbar ? NSSmallControlSize : NSRegularControlSize; - ThemeControlState state = 0; - if (scrollbar->client()->isActive()) - state |= ActiveState; - if (hasButtons(scrollbar)) - state |= EnabledState; - if (scrollbar->pressedPart() == part) - state |= PressedState; - if (part == BackButtonStartPart) - paintThemePart(scrollbar->orientation() == VerticalScrollbar ? ScrollUpArrowPart : ScrollLeftArrowPart, graphicsContext->platformContext(), - buttonRect, size, state); - else if (part == ForwardButtonEndPart) - paintThemePart(scrollbar->orientation() == VerticalScrollbar ? ScrollDownArrowPart : ScrollRightArrowPart, graphicsContext->platformContext(), - buttonRect, size, state); -} - -void ScrollbarThemeSafari::paintThumb(GraphicsContext* graphicsContext, Scrollbar* scrollbar, const IntRect& thumbRect) -{ - if (!SafariThemeLibrary()) - return; - NSControlSize size = scrollbar->controlSize() == SmallScrollbar ? NSSmallControlSize : NSRegularControlSize; - ThemeControlState state = 0; - if (scrollbar->client()->isActive()) - state |= ActiveState; - if (hasThumb(scrollbar)) - state |= EnabledState; - if (scrollbar->pressedPart() == ThumbPart) - state |= PressedState; - paintThemePart(scrollbar->orientation() == VerticalScrollbar ? VScrollThumbPart : HScrollThumbPart, graphicsContext->platformContext(), - thumbRect, size, state); -} - -} - -#endif diff --git a/WebCore/platform/win/ScrollbarThemeSafari.h b/WebCore/platform/win/ScrollbarThemeSafari.h deleted file mode 100644 index f039379..0000000 --- a/WebCore/platform/win/ScrollbarThemeSafari.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 ScrollbarThemeSafari_h -#define ScrollbarThemeSafari_h - -#if USE(SAFARI_THEME) - -#include "ScrollbarThemeComposite.h" - -namespace WebCore { - -class ScrollbarThemeSafari : public ScrollbarThemeComposite { -public: - virtual ~ScrollbarThemeSafari(); - - virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar); - - virtual bool supportsControlTints() const { return true; } - -protected: - virtual bool hasButtons(Scrollbar*); - virtual bool hasThumb(Scrollbar*); - - virtual IntRect backButtonRect(Scrollbar*, ScrollbarPart, bool painting = false); - virtual IntRect forwardButtonRect(Scrollbar*, ScrollbarPart, bool painting = false); - virtual IntRect trackRect(Scrollbar*, bool painting = false); - - virtual int minimumThumbLength(Scrollbar*); - - virtual bool shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent&); - - virtual void paintTrackBackground(GraphicsContext*, Scrollbar*, const IntRect&); - virtual void paintButton(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart); - virtual void paintThumb(GraphicsContext*, Scrollbar*, const IntRect&); -}; - -} -#endif - -#endif diff --git a/WebCore/platform/win/ScrollbarThemeWin.cpp b/WebCore/platform/win/ScrollbarThemeWin.cpp deleted file mode 100644 index e13d893..0000000 --- a/WebCore/platform/win/ScrollbarThemeWin.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/* - * 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. - */ - -#include "config.h" -#include "ScrollbarThemeWin.h" - -#include "GraphicsContext.h" -#include "PlatformMouseEvent.h" -#include "Scrollbar.h" -#include "SoftLinking.h" - -// Generic state constants -#define TS_NORMAL 1 -#define TS_HOVER 2 -#define TS_ACTIVE 3 -#define TS_DISABLED 4 - -#define SP_BUTTON 1 -#define SP_THUMBHOR 2 -#define SP_THUMBVERT 3 -#define SP_TRACKSTARTHOR 4 -#define SP_TRACKENDHOR 5 -#define SP_TRACKSTARTVERT 6 -#define SP_TRACKENDVERT 7 -#define SP_GRIPPERHOR 8 -#define SP_GRIPPERVERT 9 - -#define TS_UP_BUTTON 0 -#define TS_DOWN_BUTTON 4 -#define TS_LEFT_BUTTON 8 -#define TS_RIGHT_BUTTON 12 -#define TS_UP_BUTTON_HOVER 17 -#define TS_DOWN_BUTTON_HOVER 18 -#define TS_LEFT_BUTTON_HOVER 19 -#define TS_RIGHT_BUTTON_HOVER 20 - -using namespace std; - -namespace WebCore { - -static HANDLE scrollbarTheme; -static bool haveTheme; -static bool runningVista; - -// FIXME: Refactor the soft-linking code so that it can be shared with RenderThemeWin -SOFT_LINK_LIBRARY(uxtheme) -SOFT_LINK(uxtheme, OpenThemeData, HANDLE, WINAPI, (HWND hwnd, LPCWSTR pszClassList), (hwnd, pszClassList)) -SOFT_LINK(uxtheme, CloseThemeData, HRESULT, WINAPI, (HANDLE hTheme), (hTheme)) -SOFT_LINK(uxtheme, DrawThemeBackground, HRESULT, WINAPI, (HANDLE hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pRect, const RECT* pClipRect), (hTheme, hdc, iPartId, iStateId, pRect, pClipRect)) -SOFT_LINK(uxtheme, IsThemeActive, BOOL, WINAPI, (), ()) -SOFT_LINK(uxtheme, IsThemeBackgroundPartiallyTransparent, BOOL, WINAPI, (HANDLE hTheme, int iPartId, int iStateId), (hTheme, iPartId, iStateId)) - -static bool isRunningOnVistaOrLater() -{ - static bool os = false; - static bool initialized = false; - if (!initialized) { - OSVERSIONINFOEX vi = {sizeof(vi), 0}; - GetVersionEx((OSVERSIONINFO*)&vi); - - // NOTE: This does not work under a debugger - Vista shims Visual Studio, - // making it believe it is xpsp2, which is inherited by debugged applications - os = vi.dwMajorVersion >= 6; - initialized = true; - } - return os; -} - -static void checkAndInitScrollbarTheme() -{ - if (uxthemeLibrary() && !scrollbarTheme) - scrollbarTheme = OpenThemeData(0, L"Scrollbar"); - haveTheme = scrollbarTheme && IsThemeActive(); -} - -#if !USE(SAFARI_THEME) -ScrollbarTheme* ScrollbarTheme::nativeTheme() -{ - static ScrollbarThemeWin winTheme; - return &winTheme; -} -#endif - -ScrollbarThemeWin::ScrollbarThemeWin() -{ - static bool initialized; - if (!initialized) { - initialized = true; - checkAndInitScrollbarTheme(); - runningVista = isRunningOnVistaOrLater(); - } -} - -ScrollbarThemeWin::~ScrollbarThemeWin() -{ -} - -int ScrollbarThemeWin::scrollbarThickness(ScrollbarControlSize) -{ - static int thickness; - if (!thickness) - thickness = ::GetSystemMetrics(SM_CXVSCROLL); - return thickness; -} - -void ScrollbarThemeWin::themeChanged() -{ - if (haveTheme) - CloseThemeData(scrollbarTheme); -} - -bool ScrollbarThemeWin::invalidateOnMouseEnterExit() -{ - return runningVista; -} - -bool ScrollbarThemeWin::hasThumb(Scrollbar* scrollbar) -{ - return thumbLength(scrollbar) > 0; -} - -IntRect ScrollbarThemeWin::backButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool) -{ - // Windows just has single arrows. - if (part == BackButtonEndPart) - return IntRect(); - - // Our desired rect is essentially 17x17. - - // Our actual rect will shrink to half the available space when - // we have < 34 pixels left. This allows the scrollbar - // to scale down and function even at tiny sizes. - int thickness = scrollbarThickness(); - if (scrollbar->orientation() == HorizontalScrollbar) - return IntRect(scrollbar->x(), scrollbar->y(), - scrollbar->width() < 2 * thickness ? scrollbar->width() / 2 : thickness, thickness); - return IntRect(scrollbar->x(), scrollbar->y(), - thickness, scrollbar->height() < 2 * thickness ? scrollbar->height() / 2 : thickness); -} - -IntRect ScrollbarThemeWin::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool) -{ - // Windows just has single arrows. - if (part == ForwardButtonStartPart) - return IntRect(); - - // Our desired rect is essentially 17x17. - - // Our actual rect will shrink to half the available space when - // we have < 34 pixels left. This allows the scrollbar - // to scale down and function even at tiny sizes. - int thickness = scrollbarThickness(); - if (scrollbar->orientation() == HorizontalScrollbar) { - int w = scrollbar->width() < 2 * thickness ? scrollbar->width() / 2 : thickness; - return IntRect(scrollbar->x() + scrollbar->width() - w, scrollbar->y(), w, thickness); - } - - int h = scrollbar->height() < 2 * thickness ? scrollbar->height() / 2 : thickness; - return IntRect(scrollbar->x(), scrollbar->y() + scrollbar->height() - h, thickness, h); -} - -IntRect ScrollbarThemeWin::trackRect(Scrollbar* scrollbar, bool) -{ - int thickness = scrollbarThickness(); - if (scrollbar->orientation() == HorizontalScrollbar) { - if (scrollbar->width() < 2 * thickness) - return IntRect(); - return IntRect(scrollbar->x() + thickness, scrollbar->y(), scrollbar->width() - 2 * thickness, thickness); - } - if (scrollbar->height() < 2 * thickness) - return IntRect(); - return IntRect(scrollbar->x(), scrollbar->y() + thickness, thickness, scrollbar->height() - 2 * thickness); -} - -void ScrollbarThemeWin::paintTrackBackground(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect) -{ - // Just assume a forward track part. We only paint the track as a single piece when there is no thumb. - if (!hasThumb(scrollbar)) - paintTrackPiece(context, scrollbar, rect, ForwardTrackPart); -} - -void ScrollbarThemeWin::paintTrackPiece(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType) -{ - checkAndInitScrollbarTheme(); - - bool start = partType == BackTrackPart; - int part; - if (scrollbar->orientation() == HorizontalScrollbar) - part = start ? SP_TRACKSTARTHOR : SP_TRACKENDHOR; - else - part = start ? SP_TRACKSTARTVERT : SP_TRACKENDVERT; - - int state; - if (!scrollbar->enabled()) - state = TS_DISABLED; - else if ((scrollbar->hoveredPart() == BackTrackPart && start) || - (scrollbar->hoveredPart() == ForwardTrackPart && !start)) - state = (scrollbar->pressedPart() == scrollbar->hoveredPart() ? TS_ACTIVE : TS_HOVER); - else - state = TS_NORMAL; - - bool alphaBlend = false; - if (scrollbarTheme) - alphaBlend = IsThemeBackgroundPartiallyTransparent(scrollbarTheme, part, state); - HDC hdc = context->getWindowsContext(rect, alphaBlend); - RECT themeRect(rect); - if (scrollbarTheme) - DrawThemeBackground(scrollbarTheme, hdc, part, state, &themeRect, 0); - else { - DWORD color3DFace = ::GetSysColor(COLOR_3DFACE); - DWORD colorScrollbar = ::GetSysColor(COLOR_SCROLLBAR); - DWORD colorWindow = ::GetSysColor(COLOR_WINDOW); - if ((color3DFace != colorScrollbar) && (colorWindow != colorScrollbar)) - ::FillRect(hdc, &themeRect, HBRUSH(COLOR_SCROLLBAR+1)); - else { - static WORD patternBits[8] = { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }; - HBITMAP patternBitmap = ::CreateBitmap(8, 8, 1, 1, patternBits); - HBRUSH brush = ::CreatePatternBrush(patternBitmap); - SaveDC(hdc); - ::SetTextColor(hdc, ::GetSysColor(COLOR_3DHILIGHT)); - ::SetBkColor(hdc, ::GetSysColor(COLOR_3DFACE)); - ::SetBrushOrgEx(hdc, rect.x(), rect.y(), NULL); - ::SelectObject(hdc, brush); - ::FillRect(hdc, &themeRect, brush); - ::RestoreDC(hdc, -1); - ::DeleteObject(brush); - ::DeleteObject(patternBitmap); - } - } - context->releaseWindowsContext(hdc, rect, alphaBlend); -} - -void ScrollbarThemeWin::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part) -{ - checkAndInitScrollbarTheme(); - - bool start = (part == BackButtonStartPart); - int xpState = 0; - int classicState = 0; - if (scrollbar->orientation() == HorizontalScrollbar) - xpState = start ? TS_LEFT_BUTTON : TS_RIGHT_BUTTON; - else - xpState = start ? TS_UP_BUTTON : TS_DOWN_BUTTON; - classicState = xpState / 4; - - if (!scrollbar->enabled()) { - xpState += TS_DISABLED; - classicState |= DFCS_INACTIVE; - } else if ((scrollbar->hoveredPart() == BackButtonStartPart && start) || - (scrollbar->hoveredPart() == ForwardButtonEndPart && !start)) { - if (scrollbar->pressedPart() == scrollbar->hoveredPart()) { - xpState += TS_ACTIVE; - classicState |= DFCS_PUSHED | DFCS_FLAT; - } else - xpState += TS_HOVER; - } else { - if (scrollbar->hoveredPart() == NoPart || !runningVista) - xpState += TS_NORMAL; - else { - if (scrollbar->orientation() == HorizontalScrollbar) - xpState = start ? TS_LEFT_BUTTON_HOVER : TS_RIGHT_BUTTON_HOVER; - else - xpState = start ? TS_UP_BUTTON_HOVER : TS_DOWN_BUTTON_HOVER; - } - } - - bool alphaBlend = false; - if (scrollbarTheme) - alphaBlend = IsThemeBackgroundPartiallyTransparent(scrollbarTheme, SP_BUTTON, xpState); - HDC hdc = context->getWindowsContext(rect, alphaBlend); - - RECT themeRect(rect); - if (scrollbarTheme) - DrawThemeBackground(scrollbarTheme, hdc, SP_BUTTON, xpState, &themeRect, 0); - else - ::DrawFrameControl(hdc, &themeRect, DFC_SCROLL, classicState); - context->releaseWindowsContext(hdc, rect, alphaBlend); -} - -static IntRect gripperRect(int thickness, const IntRect& thumbRect) -{ - // Center in the thumb. - int gripperThickness = thickness / 2; - return IntRect(thumbRect.x() + (thumbRect.width() - gripperThickness) / 2, - thumbRect.y() + (thumbRect.height() - gripperThickness) / 2, - gripperThickness, gripperThickness); -} - -static void paintGripper(Scrollbar* scrollbar, HDC hdc, const IntRect& rect) -{ - if (!scrollbarTheme) - return; // Classic look has no gripper. - - int state; - if (!scrollbar->enabled()) - state = TS_DISABLED; - else if (scrollbar->pressedPart() == ThumbPart) - state = TS_ACTIVE; // Thumb always stays active once pressed. - else if (scrollbar->hoveredPart() == ThumbPart) - state = TS_HOVER; - else - state = TS_NORMAL; - - RECT themeRect(rect); - DrawThemeBackground(scrollbarTheme, hdc, scrollbar->orientation() == HorizontalScrollbar ? SP_GRIPPERHOR : SP_GRIPPERVERT, state, &themeRect, 0); -} - -void ScrollbarThemeWin::paintThumb(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect) -{ - checkAndInitScrollbarTheme(); - - int state; - if (!scrollbar->enabled()) - state = TS_DISABLED; - else if (scrollbar->pressedPart() == ThumbPart) - state = TS_ACTIVE; // Thumb always stays active once pressed. - else if (scrollbar->hoveredPart() == ThumbPart) - state = TS_HOVER; - else - state = TS_NORMAL; - - bool alphaBlend = false; - if (scrollbarTheme) - alphaBlend = IsThemeBackgroundPartiallyTransparent(scrollbarTheme, scrollbar->orientation() == HorizontalScrollbar ? SP_THUMBHOR : SP_THUMBVERT, state); - HDC hdc = context->getWindowsContext(rect, alphaBlend); - RECT themeRect(rect); - if (scrollbarTheme) { - DrawThemeBackground(scrollbarTheme, hdc, scrollbar->orientation() == HorizontalScrollbar ? SP_THUMBHOR : SP_THUMBVERT, state, &themeRect, 0); - paintGripper(scrollbar, hdc, gripperRect(scrollbarThickness(), rect)); - } else - ::DrawEdge(hdc, &themeRect, EDGE_RAISED, BF_RECT | BF_MIDDLE); - context->releaseWindowsContext(hdc, rect, alphaBlend); -} - -bool ScrollbarThemeWin::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt) -{ - return evt.shiftKey() && evt.button() == LeftButton; -} - -} - diff --git a/WebCore/platform/win/ScrollbarThemeWin.h b/WebCore/platform/win/ScrollbarThemeWin.h deleted file mode 100644 index 92e2523..0000000 --- a/WebCore/platform/win/ScrollbarThemeWin.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 ScrollbarThemeWin_h -#define ScrollbarThemeWin_h - -#include "ScrollbarThemeComposite.h" - -namespace WebCore { - -class ScrollbarThemeWin : public ScrollbarThemeComposite { -public: - ScrollbarThemeWin(); - virtual ~ScrollbarThemeWin(); - - virtual int scrollbarThickness(ScrollbarControlSize = RegularScrollbar); - - virtual void themeChanged(); - - virtual bool invalidateOnMouseEnterExit(); - -protected: - virtual bool hasButtons(Scrollbar*) { return true; } - virtual bool hasThumb(Scrollbar*); - - virtual IntRect backButtonRect(Scrollbar*, ScrollbarPart, bool painting = false); - virtual IntRect forwardButtonRect(Scrollbar*, ScrollbarPart, bool painting = false); - virtual IntRect trackRect(Scrollbar*, bool painting = false); - - virtual bool shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent&); - - virtual void paintTrackBackground(GraphicsContext*, Scrollbar*, const IntRect&); - virtual void paintTrackPiece(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart); - virtual void paintButton(GraphicsContext*, Scrollbar*, const IntRect&, ScrollbarPart); - virtual void paintThumb(GraphicsContext*, Scrollbar*, const IntRect&); -}; - -} -#endif diff --git a/WebCore/platform/win/SearchPopupMenuWin.cpp b/WebCore/platform/win/SearchPopupMenuWin.cpp deleted file mode 100644 index f2709bb..0000000 --- a/WebCore/platform/win/SearchPopupMenuWin.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2006, 2007 Apple Inc. - * - * 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 "SearchPopupMenu.h" - -#include "AtomicString.h" -#include <wtf/RetainPtr.h> - -namespace WebCore { - -SearchPopupMenu::SearchPopupMenu(PopupMenuClient* client) - : PopupMenu(client) -{ -} - -bool SearchPopupMenu::enabled() -{ - return true; -} - -static RetainPtr<CFStringRef> autosaveKey(const String& name) -{ - String key = "com.apple.WebKit.searchField:" + name; - return RetainPtr<CFStringRef>(AdoptCF, key.createCFString()); -} - -void SearchPopupMenu::saveRecentSearches(const AtomicString& name, const Vector<String>& searchItems) -{ - if (name.isEmpty()) - return; - - RetainPtr<CFMutableArrayRef> items; - - size_t size = searchItems.size(); - if (size) { - items.adoptCF(CFArrayCreateMutable(0, size, &kCFTypeArrayCallBacks)); - for (size_t i = 0; i < size; ++i) { - RetainPtr<CFStringRef> item(AdoptCF, searchItems[i].createCFString()); - CFArrayAppendValue(items.get(), item.get()); - } - } - - CFPreferencesSetAppValue(autosaveKey(name).get(), items.get(), kCFPreferencesCurrentApplication); - CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication); -} - -void SearchPopupMenu::loadRecentSearches(const AtomicString& name, Vector<String>& searchItems) -{ - if (name.isEmpty()) - return; - - searchItems.clear(); - RetainPtr<CFArrayRef> items(AdoptCF, reinterpret_cast<CFArrayRef>(CFPreferencesCopyAppValue(autosaveKey(name).get(), kCFPreferencesCurrentApplication))); - - if (!items || CFGetTypeID(items.get()) != CFArrayGetTypeID()) - return; - - size_t size = CFArrayGetCount(items.get()); - for (size_t i = 0; i < size; ++i) { - CFStringRef item = (CFStringRef)CFArrayGetValueAtIndex(items.get(), i); - if (CFGetTypeID(item) == CFStringGetTypeID()) - searchItems.append(item); - } -} - -} diff --git a/WebCore/platform/win/SharedBufferWin.cpp b/WebCore/platform/win/SharedBufferWin.cpp deleted file mode 100644 index ce93402..0000000 --- a/WebCore/platform/win/SharedBufferWin.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2007 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 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" - -namespace WebCore { - -PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& filePath) -{ - if (filePath.isEmpty()) - return 0; - - String nullifiedPath = filePath; - FILE* fileDescriptor = 0; - if (_wfopen_s(&fileDescriptor, nullifiedPath.charactersWithNullTermination(), TEXT("r+b")) || !fileDescriptor) { - LOG_ERROR("Failed to open file %s to create shared buffer", filePath.ascii().data()); - return 0; - } - - RefPtr<SharedBuffer> result; - - // Stat the file to get its size - struct _stat64 fileStat; - if (_fstat64(_fileno(fileDescriptor), &fileStat)) - goto exit; - - result = SharedBuffer::create(); - result->m_buffer.resize(fileStat.st_size); - if (result->m_buffer.size() != fileStat.st_size) { - result = 0; - goto exit; - } - - if (fread(result->m_buffer.data(), 1, fileStat.st_size, fileDescriptor) != fileStat.st_size) - LOG_ERROR("Failed to fully read contents of file %s - errno(%i)", filePath.ascii().data(), errno); - -exit: - fclose(fileDescriptor); - return result.release(); -} - -}; // namespace WebCore diff --git a/WebCore/platform/win/SharedTimerWin.cpp b/WebCore/platform/win/SharedTimerWin.cpp deleted file mode 100644 index b611659..0000000 --- a/WebCore/platform/win/SharedTimerWin.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (C) 2006 Apple Computer, 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 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 "SharedTimer.h" - -#include "Page.h" -#include "SystemTime.h" -#include "Widget.h" -#include <wtf/Assertions.h> - -// Note: wx headers set defines that affect the configuration of windows.h -// so we must include the wx header first to get unicode versions of functions, -// etc. -#if PLATFORM(WX) -#include <wx/wx.h> -#endif - -#include <windows.h> -#include <mmsystem.h> - -// These aren't in winuser.h with the MSVS 2003 Platform SDK, -// so use default values in that case. -#ifndef USER_TIMER_MINIMUM -#define USER_TIMER_MINIMUM 0x0000000A -#endif - -#ifndef USER_TIMER_MAXIMUM -#define USER_TIMER_MAXIMUM 0x7FFFFFFF -#endif - -#ifndef QS_RAWINPUT -#define QS_RAWINPUT 0x0400 -#endif - -#if PLATFORM(WIN) -#include "PluginView.h" -#endif - -namespace WebCore { - -static UINT timerID; -static void (*sharedTimerFiredFunction)(); - -static HWND timerWindowHandle = 0; -static UINT timerFiredMessage = 0; -static HANDLE timerQueue; -static HANDLE timer; -static Mutex timerMutex; -static bool highResTimerActive; -static bool processingCustomTimerMessage = false; -static LONG pendingTimers; - -const LPCWSTR kTimerWindowClassName = L"TimerWindowClass"; -const int timerResolution = 1; // To improve timer resolution, we call timeBeginPeriod/timeEndPeriod with this value to increase timer resolution to 1ms. -const int highResolutionThresholdMsec = 16; // Only activate high-res timer for sub-16ms timers (Windows can fire timers at 16ms intervals without changing the system resolution). -const int stopHighResTimerInMsec = 300; // Stop high-res timer after 0.3 seconds to lessen power consumption (we don't use a smaller time since oscillating between high and low resolution breaks timer accuracy on XP). - -enum { - sharedTimerID = 1000, - endHighResTimerID = 1001, -}; - -LRESULT CALLBACK TimerWindowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ -#if PLATFORM(WIN) - // Windows Media Player has a modal message loop that will deliver messages - // to us at inappropriate times and we will crash if we handle them when - // they are delivered. We repost all messages so that we will get to handle - // them once the modal loop exits. - if (PluginView::isCallingPlugin()) { - PostMessage(hWnd, message, wParam, lParam); - return 0; - } -#endif - - if (message == timerFiredMessage) { - InterlockedExchange(&pendingTimers, 0); - processingCustomTimerMessage = true; - sharedTimerFiredFunction(); - processingCustomTimerMessage = false; - } else if (message == WM_TIMER) { - if (wParam == sharedTimerID) { - KillTimer(timerWindowHandle, sharedTimerID); - sharedTimerFiredFunction(); - } else if (wParam == endHighResTimerID) { - KillTimer(timerWindowHandle, endHighResTimerID); - highResTimerActive = false; - timeEndPeriod(timerResolution); - } - } else - return DefWindowProc(hWnd, message, wParam, lParam); - - return 0; -} - -static void initializeOffScreenTimerWindow() -{ - if (timerWindowHandle) - return; - - WNDCLASSEX wcex; - memset(&wcex, 0, sizeof(WNDCLASSEX)); - wcex.cbSize = sizeof(WNDCLASSEX); - wcex.lpfnWndProc = TimerWindowWndProc; - wcex.hInstance = Page::instanceHandle(); - wcex.lpszClassName = kTimerWindowClassName; - RegisterClassEx(&wcex); - - timerWindowHandle = CreateWindow(kTimerWindowClassName, 0, 0, - CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, HWND_MESSAGE, 0, Page::instanceHandle(), 0); - timerFiredMessage = RegisterWindowMessage(L"com.apple.WebKit.TimerFired"); -} - -void setSharedTimerFiredFunction(void (*f)()) -{ - sharedTimerFiredFunction = f; -} - -static void clearTimer() -{ - MutexLocker locker(timerMutex); - if (timerQueue && timer) - DeleteTimerQueueTimer(timerQueue, timer, 0); - timer = 0; -} - -static void NTAPI queueTimerProc(PVOID, BOOLEAN) -{ - clearTimer(); - if (InterlockedIncrement(&pendingTimers) == 1) - PostMessage(timerWindowHandle, timerFiredMessage, 0, 0); -} - -void setSharedTimerFireTime(double fireTime) -{ - ASSERT(sharedTimerFiredFunction); - - double interval = fireTime - currentTime(); - unsigned intervalInMS; - if (interval < 0) - intervalInMS = 0; - else { - interval *= 1000; - if (interval > USER_TIMER_MAXIMUM) - intervalInMS = USER_TIMER_MAXIMUM; - else - intervalInMS = (unsigned)interval; - } - - if (interval < highResolutionThresholdMsec) { - if (!highResTimerActive) { - highResTimerActive = true; - timeBeginPeriod(timerResolution); - } - SetTimer(timerWindowHandle, endHighResTimerID, stopHighResTimerInMsec, 0); - } - - initializeOffScreenTimerWindow(); - bool timerSet = false; - DWORD queueStatus = LOWORD(GetQueueStatus(QS_PAINT | QS_MOUSEBUTTON | QS_KEY | QS_RAWINPUT)); - - // Win32 has a tri-level queue with application messages > user input > WM_PAINT/WM_TIMER. - - // If the queue doesn't contains input events, we use a higher priorty timer event posting mechanism. - if (!(queueStatus & (QS_MOUSEBUTTON | QS_KEY | QS_RAWINPUT))) { - if (intervalInMS < USER_TIMER_MINIMUM && !processingCustomTimerMessage && !(queueStatus & QS_PAINT)) { - // Call PostMessage immediately if the timer is already expired, unless a paint is pending. - // (we prioritize paints over timers) - if (InterlockedIncrement(&pendingTimers) == 1) - PostMessage(timerWindowHandle, timerFiredMessage, 0, 0); - timerSet = true; - } else { - // Otherwise, delay the PostMessage via a CreateTimerQueueTimer - if (!timerQueue) - timerQueue = CreateTimerQueue(); - MutexLocker locker(timerMutex); - if (timer) - timerSet = ChangeTimerQueueTimer(timerQueue, timer, intervalInMS, 0); - else - timerSet = CreateTimerQueueTimer(&timer, timerQueue, queueTimerProc, 0, intervalInMS, 0, WT_EXECUTEINTIMERTHREAD | WT_EXECUTEONLYONCE); - } - } - - if (timerSet) { - if (timerID) { - KillTimer(timerWindowHandle, timerID); - timerID = 0; - } - } else - timerID = SetTimer(timerWindowHandle, sharedTimerID, intervalInMS, 0); -} - -void stopSharedTimer() -{ - clearTimer(); - if (timerID) { - KillTimer(timerWindowHandle, timerID); - timerID = 0; - } -} - -} diff --git a/WebCore/platform/win/SoftLinking.h b/WebCore/platform/win/SoftLinking.h deleted file mode 100644 index 761cb7a..0000000 --- a/WebCore/platform/win/SoftLinking.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2007 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. - */ - -#ifndef SoftLinking_h -#define SoftLinking_h - -#include <windows.h> -#include <wtf/Assertions.h> - -#define SOFT_LINK_LIBRARY_HELPER(lib, suffix) \ - static HMODULE lib##Library() \ - { \ - static HMODULE library = LoadLibraryW(L###lib suffix); \ - ASSERT(library); \ - return library; \ - } - -#define SOFT_LINK_LIBRARY(lib) SOFT_LINK_LIBRARY_HELPER(lib, L".dll") -#define SOFT_LINK_DEBUG_LIBRARY(lib) SOFT_LINK_LIBRARY_HELPER(lib, L"_debug.dll") - -#define SOFT_LINK(library, functionName, resultType, callingConvention, parameterDeclarations, parameterNames) \ - static resultType callingConvention init##functionName parameterDeclarations; \ - static resultType (callingConvention*softLink##functionName) parameterDeclarations = init##functionName; \ - \ - static resultType callingConvention init##functionName parameterDeclarations \ - { \ - softLink##functionName = (resultType (callingConvention*) parameterDeclarations) GetProcAddress(library##Library(), #functionName); \ - ASSERT(softLink##functionName); \ - return softLink##functionName parameterNames; \ - }\ - \ - inline resultType functionName parameterDeclarations \ - {\ - return softLink##functionName parameterNames; \ - } - -#endif // SoftLinking_h diff --git a/WebCore/platform/win/SoundWin.cpp b/WebCore/platform/win/SoundWin.cpp deleted file mode 100644 index 443e7d9..0000000 --- a/WebCore/platform/win/SoundWin.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "Sound.h" - -#include <Windows.h> - -namespace WebCore { - -void systemBeep() { MessageBeep(static_cast<UINT>(-1)); } - -} // namespace WebCore - diff --git a/WebCore/platform/win/SystemTimeWin.cpp b/WebCore/platform/win/SystemTimeWin.cpp deleted file mode 100644 index 473e8de..0000000 --- a/WebCore/platform/win/SystemTimeWin.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "SystemTime.h" - -#include <DateMath.h> -#include <windows.h> - -#if COMPILER(MINGW) -#include <float.h> -#define FLOAT_MAX FLT_MAX -#endif - -namespace WebCore { - -double currentTime() -{ - // Call through to our high-resolution JSC time code, since calls like GetSystemTimeAsFileTime and ftime are only accurate within 15ms. - // This resolution can be improved with timeBeginPeriod/timeEndPeriod on Vista, but these calls don't - // improve the resolution of date/time getters (GetSystemTimeAsFileTime, ftime, etc.) on XP. - return JSC::getCurrentUTCTimeWithMicroseconds() * 0.001; -} - -float userIdleTime() -{ - LASTINPUTINFO lastInputInfo = {0}; - lastInputInfo.cbSize = sizeof(LASTINPUTINFO); - if (::GetLastInputInfo(&lastInputInfo)) - return (GetTickCount() - lastInputInfo.dwTime) * 0.001; // ::GetTickCount returns ms of uptime valid for up to 49.7 days. - return FLT_MAX; // return an arbitrarily high userIdleTime so that releasing pages from the page cache isn't postponed. -} - -} diff --git a/WebCore/platform/win/TemporaryLinkStubs.cpp b/WebCore/platform/win/TemporaryLinkStubs.cpp deleted file mode 100644 index 80c8df0..0000000 --- a/WebCore/platform/win/TemporaryLinkStubs.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "NotImplemented.h" -#include "SSLKeyGenerator.h" - -namespace WebCore { - -// <keygen> -String signedPublicKeyAndChallengeString(unsigned, const String&, const KURL&) { notImplemented(); return String(); } -void getSupportedKeySizes(Vector<String>&) { notImplemented(); } - -} // namespace WebCore diff --git a/WebCore/platform/win/WCDataObject.cpp b/WebCore/platform/win/WCDataObject.cpp deleted file mode 100644 index 5201bfa..0000000 --- a/WebCore/platform/win/WCDataObject.cpp +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (C) 2007 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 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 "WCDataObject.h" - -#include "PlatformString.h" - -namespace WebCore { - -class WCEnumFormatEtc : public IEnumFORMATETC -{ -public: - WCEnumFormatEtc(const Vector<FORMATETC>& formats); - WCEnumFormatEtc(const Vector<FORMATETC*>& formats); - - //IUnknown members - STDMETHOD(QueryInterface)(REFIID, void**); - STDMETHOD_(ULONG, AddRef)(void); - STDMETHOD_(ULONG, Release)(void); - - //IEnumFORMATETC members - STDMETHOD(Next)(ULONG, LPFORMATETC, ULONG*); - STDMETHOD(Skip)(ULONG); - STDMETHOD(Reset)(void); - STDMETHOD(Clone)(IEnumFORMATETC**); - -private: - long m_ref; - Vector<FORMATETC> m_formats; - size_t m_current; -}; - - - -WCEnumFormatEtc::WCEnumFormatEtc(const Vector<FORMATETC>& formats) -: m_ref(1) -, m_current(0) -{ - for(size_t i = 0; i < formats.size(); ++i) - m_formats.append(formats[i]); -} - -WCEnumFormatEtc::WCEnumFormatEtc(const Vector<FORMATETC*>& formats) -: m_ref(1) -, m_current(0) -{ - for(size_t i = 0; i < formats.size(); ++i) - m_formats.append(*formats[i]); -} - -STDMETHODIMP WCEnumFormatEtc::QueryInterface(REFIID riid, void** ppvObject) -{ - *ppvObject = 0; - if (IsEqualIID(riid, IID_IUnknown) || - IsEqualIID(riid, IID_IEnumFORMATETC)) { - *ppvObject = this; - AddRef(); - return S_OK; - } - - return E_NOINTERFACE; -} - -STDMETHODIMP_(ULONG) WCEnumFormatEtc::AddRef(void) -{ - return InterlockedIncrement(&m_ref); -} - -STDMETHODIMP_(ULONG) WCEnumFormatEtc::Release(void) -{ - long c = InterlockedDecrement(&m_ref); - if (c == 0) - delete this; - return c; -} - -STDMETHODIMP WCEnumFormatEtc::Next(ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched) -{ - if(pceltFetched != 0) - *pceltFetched=0; - - ULONG cReturn = celt; - - if(celt <= 0 || lpFormatEtc == 0 || m_current >= m_formats.size()) - return S_FALSE; - - if(pceltFetched == 0 && celt != 1) // pceltFetched can be 0 only for 1 item request - return S_FALSE; - - while (m_current < m_formats.size() && cReturn > 0) { - *lpFormatEtc++ = m_formats[m_current++]; - --cReturn; - } - if (pceltFetched != 0) - *pceltFetched = celt - cReturn; - - return (cReturn == 0) ? S_OK : S_FALSE; -} - -STDMETHODIMP WCEnumFormatEtc::Skip(ULONG celt) -{ - if((m_current + int(celt)) >= m_formats.size()) - return S_FALSE; - m_current += celt; - return S_OK; -} - -STDMETHODIMP WCEnumFormatEtc::Reset(void) -{ - m_current = 0; - return S_OK; -} - -STDMETHODIMP WCEnumFormatEtc::Clone(IEnumFORMATETC** ppCloneEnumFormatEtc) -{ - if(!ppCloneEnumFormatEtc) - return E_POINTER; - - WCEnumFormatEtc *newEnum = new WCEnumFormatEtc(m_formats); - if(!newEnum) - return E_OUTOFMEMORY; - - newEnum->AddRef(); - newEnum->m_current = m_current; - *ppCloneEnumFormatEtc = newEnum; - return S_OK; -} - - - -////////////////////////////////////////////////////////////////////////// - -HRESULT WCDataObject::createInstance(WCDataObject** result) -{ - if (!result) - return E_POINTER; - *result = new WCDataObject(); - return S_OK; -} - -WCDataObject::WCDataObject() -: m_ref(1) -{ -} - -WCDataObject::~WCDataObject() -{ - for(size_t i = 0; i < m_medium.size(); ++i) { - ReleaseStgMedium(m_medium[i]); - delete m_medium[i]; - } - WTF::deleteAllValues(m_formats); -} - -STDMETHODIMP WCDataObject::QueryInterface(REFIID riid,void** ppvObject) -{ - *ppvObject = 0; - if (IID_IUnknown==riid || IID_IDataObject==riid) - *ppvObject=this; - if (*ppvObject) { - AddRef(); - return S_OK; - } - return E_NOINTERFACE; -} - -STDMETHODIMP_(ULONG) WCDataObject::AddRef( void) -{ - return InterlockedIncrement(&m_ref); -} - -STDMETHODIMP_(ULONG) WCDataObject::Release( void) -{ - long c = InterlockedDecrement(&m_ref); - if (c == 0) - delete this; - return c; -} - -STDMETHODIMP WCDataObject::GetData(FORMATETC* pformatetcIn, STGMEDIUM* pmedium) -{ - if(!pformatetcIn || !pmedium) - return E_POINTER; - pmedium->hGlobal = 0; - - for(size_t i=0; i < m_formats.size(); ++i) { - if(/*pformatetcIn->tymed & m_formats[i]->tymed &&*/ // tymed can be 0 (TYMED_NULL) - but it can have a medium that contains an pUnkForRelease - pformatetcIn->lindex == m_formats[i]->lindex && - pformatetcIn->dwAspect == m_formats[i]->dwAspect && - pformatetcIn->cfFormat == m_formats[i]->cfFormat) { - CopyMedium(pmedium, m_medium[i], m_formats[i]); - return S_OK; - } - } - return DV_E_FORMATETC; -} - -STDMETHODIMP WCDataObject::GetDataHere(FORMATETC*, STGMEDIUM*) -{ - return E_NOTIMPL; -} - -STDMETHODIMP WCDataObject::QueryGetData(FORMATETC* pformatetc) -{ - if(!pformatetc) - return E_POINTER; - - if (!(DVASPECT_CONTENT & pformatetc->dwAspect)) - return (DV_E_DVASPECT); - HRESULT hr = DV_E_TYMED; - for(size_t i = 0; i < m_formats.size(); ++i) { - if(pformatetc->tymed & m_formats[i]->tymed) { - if(pformatetc->cfFormat == m_formats[i]->cfFormat) - return S_OK; - else - hr = DV_E_CLIPFORMAT; - } - else - hr = DV_E_TYMED; - } - return hr; -} - -STDMETHODIMP WCDataObject::GetCanonicalFormatEtc(FORMATETC*, FORMATETC*) -{ - return DATA_S_SAMEFORMATETC; -} - -STDMETHODIMP WCDataObject::SetData(FORMATETC* pformatetc, STGMEDIUM* pmedium, BOOL fRelease) -{ - if(!pformatetc || !pmedium) - return E_POINTER; - - FORMATETC* fetc=new FORMATETC; - if (!fetc) - return E_OUTOFMEMORY; - - STGMEDIUM* pStgMed = new STGMEDIUM; - - if(!pStgMed) { - delete fetc; - return E_OUTOFMEMORY; - } - - ZeroMemory(fetc,sizeof(FORMATETC)); - ZeroMemory(pStgMed,sizeof(STGMEDIUM)); - - *fetc = *pformatetc; - m_formats.append(fetc); - - if(fRelease) - *pStgMed = *pmedium; - else - CopyMedium(pStgMed, pmedium, pformatetc); - m_medium.append(pStgMed); - - return S_OK; -} - -void WCDataObject::CopyMedium(STGMEDIUM* pMedDest, STGMEDIUM* pMedSrc, FORMATETC* pFmtSrc) -{ - switch(pMedSrc->tymed) - { - case TYMED_HGLOBAL: - pMedDest->hGlobal = (HGLOBAL)OleDuplicateData(pMedSrc->hGlobal,pFmtSrc->cfFormat, 0); - break; - case TYMED_GDI: - pMedDest->hBitmap = (HBITMAP)OleDuplicateData(pMedSrc->hBitmap,pFmtSrc->cfFormat, 0); - break; - case TYMED_MFPICT: - pMedDest->hMetaFilePict = (HMETAFILEPICT)OleDuplicateData(pMedSrc->hMetaFilePict,pFmtSrc->cfFormat, 0); - break; - case TYMED_ENHMF: - pMedDest->hEnhMetaFile = (HENHMETAFILE)OleDuplicateData(pMedSrc->hEnhMetaFile,pFmtSrc->cfFormat, 0); - break; - case TYMED_FILE: - pMedSrc->lpszFileName = (LPOLESTR)OleDuplicateData(pMedSrc->lpszFileName,pFmtSrc->cfFormat, 0); - break; - case TYMED_ISTREAM: - pMedDest->pstm = pMedSrc->pstm; - pMedSrc->pstm->AddRef(); - break; - case TYMED_ISTORAGE: - pMedDest->pstg = pMedSrc->pstg; - pMedSrc->pstg->AddRef(); - break; - default: - break; - } - pMedDest->tymed = pMedSrc->tymed; - pMedDest->pUnkForRelease = 0; - if(pMedSrc->pUnkForRelease != 0) { - pMedDest->pUnkForRelease = pMedSrc->pUnkForRelease; - pMedSrc->pUnkForRelease->AddRef(); - } -} -STDMETHODIMP WCDataObject::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc) -{ - if(!ppenumFormatEtc) - return E_POINTER; - - *ppenumFormatEtc=0; - switch (dwDirection) - { - case DATADIR_GET: - *ppenumFormatEtc= new WCEnumFormatEtc(m_formats); - if(!(*ppenumFormatEtc)) - return E_OUTOFMEMORY; - break; - - case DATADIR_SET: - default: - return E_NOTIMPL; - break; - } - - return S_OK; -} - -STDMETHODIMP WCDataObject::DAdvise(FORMATETC*, DWORD, IAdviseSink*,DWORD*) -{ - return OLE_E_ADVISENOTSUPPORTED; -} - -STDMETHODIMP WCDataObject::DUnadvise(DWORD) -{ - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE WCDataObject::EnumDAdvise(IEnumSTATDATA**) -{ - return OLE_E_ADVISENOTSUPPORTED; -} - -void WCDataObject::clearData(CLIPFORMAT format) -{ - size_t ptr = 0; - while (ptr < m_formats.size()) { - if (m_formats[ptr]->cfFormat == format) { - FORMATETC* current = m_formats[ptr]; - m_formats[ptr] = m_formats[m_formats.size() - 1]; - m_formats[m_formats.size() - 1] = 0; - m_formats.removeLast(); - delete current; - STGMEDIUM* medium = m_medium[ptr]; - m_medium[ptr] = m_medium[m_medium.size() - 1]; - m_medium[m_medium.size() - 1] = 0; - m_medium.removeLast(); - ReleaseStgMedium(medium); - delete medium; - continue; - } - ptr++; - } -} - - -} diff --git a/WebCore/platform/win/WCDataObject.h b/WebCore/platform/win/WCDataObject.h deleted file mode 100644 index bdfb013..0000000 --- a/WebCore/platform/win/WCDataObject.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2007 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 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 WCDataObject_h -#define WCDataObject_h - -#include <wtf/Vector.h> -#include <ShlObj.h> -#include <objidl.h> - -namespace WebCore { - -class String; - -class WCDataObject : public IDataObject { -public: - void CopyMedium(STGMEDIUM* pMedDest, STGMEDIUM* pMedSrc, FORMATETC* pFmtSrc); - - //IUnknown - virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); - virtual ULONG STDMETHODCALLTYPE AddRef(void); - virtual ULONG STDMETHODCALLTYPE Release(void); - - //IDataObject - virtual HRESULT STDMETHODCALLTYPE GetData(FORMATETC* pformatIn, STGMEDIUM* pmedium); - virtual HRESULT STDMETHODCALLTYPE GetDataHere(FORMATETC* pformat, STGMEDIUM* pmedium); - virtual HRESULT STDMETHODCALLTYPE QueryGetData(FORMATETC* pformat); - virtual HRESULT STDMETHODCALLTYPE GetCanonicalFormatEtc(FORMATETC* pformatectIn,FORMATETC* pformatOut); - virtual HRESULT STDMETHODCALLTYPE SetData(FORMATETC* pformat, STGMEDIUM*pmedium, BOOL release); - virtual HRESULT STDMETHODCALLTYPE EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC** ppenumFormatEtc); - virtual HRESULT STDMETHODCALLTYPE DAdvise(FORMATETC*, DWORD, IAdviseSink*, DWORD*); - virtual HRESULT STDMETHODCALLTYPE DUnadvise(DWORD); - virtual HRESULT STDMETHODCALLTYPE EnumDAdvise(IEnumSTATDATA**); - - void clearData(CLIPFORMAT); - - static HRESULT createInstance(WCDataObject**); -private: - WCDataObject(); - virtual ~WCDataObject(); - long m_ref; - Vector<FORMATETC*> m_formats; - Vector<STGMEDIUM*> m_medium; -}; - -} - -#endif //!WCDataObject_h diff --git a/WebCore/platform/win/WebCoreTextRenderer.cpp b/WebCore/platform/win/WebCoreTextRenderer.cpp deleted file mode 100644 index 75ce003..0000000 --- a/WebCore/platform/win/WebCoreTextRenderer.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2007 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 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 "WebCoreTextRenderer.h" - -#include "Font.h" -#include "FontDescription.h" -#include "GraphicsContext.h" -#include "StringTruncator.h" -#include <wtf/unicode/Unicode.h> - -namespace WebCore { - -static bool shouldUseFontSmoothing = true; - -static bool isOneLeftToRightRun(const TextRun& run) -{ - for (int i = 0; i < run.length(); i++) { - WTF::Unicode::Direction direction = WTF::Unicode::direction(run[i]); - if (direction == WTF::Unicode::RightToLeft || direction > WTF::Unicode::OtherNeutral) - return false; - } - return true; -} - -static void doDrawTextAtPoint(GraphicsContext& context, const String& text, const IntPoint& point, const Font& font, const Color& color, int underlinedIndex) -{ - TextRun run(text.characters(), text.length()); - - context.setFillColor(color); - if (isOneLeftToRightRun(run)) - font.drawText(&context, run, point); - else { - context.setFont(font); - context.drawBidiText(run, point); - } - - if (underlinedIndex >= 0) { - ASSERT(underlinedIndex < static_cast<int>(text.length())); - - int beforeWidth; - if (underlinedIndex > 0) { - TextRun beforeRun(text.characters(), underlinedIndex); - beforeWidth = font.width(beforeRun); - } else - beforeWidth = 0; - - TextRun underlinedRun(text.characters() + underlinedIndex, 1); - int underlinedWidth = font.width(underlinedRun); - - IntPoint underlinePoint(point); - underlinePoint.move(beforeWidth, 1); - - context.setStrokeColor(color); - context.drawLineForText(underlinePoint, underlinedWidth, false); - } -} - -void WebCoreDrawTextAtPoint(GraphicsContext& context, const String& text, const IntPoint& point, const Font& font, const Color& color, int underlinedIndex) -{ - context.save(); - - doDrawTextAtPoint(context, text, point, font, color, underlinedIndex); - - context.restore(); -} - -void WebCoreDrawDoubledTextAtPoint(GraphicsContext& context, const String& text, const IntPoint& point, const Font& font, const Color& topColor, const Color& bottomColor, int underlinedIndex) -{ - context.save(); - - IntPoint textPos = point; - - doDrawTextAtPoint(context, text, textPos, font, bottomColor, underlinedIndex); - textPos.move(0, -1); - doDrawTextAtPoint(context, text, textPos, font, topColor, underlinedIndex); - - context.restore(); -} - -float WebCoreTextFloatWidth(const String& text, const Font& font) -{ - return StringTruncator::width(text, font, false); -} - -void WebCoreSetShouldUseFontSmoothing(bool smooth) -{ - shouldUseFontSmoothing = smooth; -} - -bool WebCoreShouldUseFontSmoothing() -{ - return shouldUseFontSmoothing; -} - -void WebCoreSetAlwaysUsesComplexTextCodePath(bool complex) -{ - Font::setCodePath(complex ? Font::Complex : Font::Auto); -} - -bool WebCoreAlwaysUsesComplexTextCodePath() -{ - return Font::codePath() == Font::Complex; -} - -} // namespace WebCore diff --git a/WebCore/platform/win/WebCoreTextRenderer.h b/WebCore/platform/win/WebCoreTextRenderer.h deleted file mode 100644 index 7b72946..0000000 --- a/WebCore/platform/win/WebCoreTextRenderer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2007 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 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. - */ - -namespace WebCore { - - class Color; - class Font; - class GraphicsContext; - class IntPoint; - class String; - - void WebCoreDrawTextAtPoint(GraphicsContext&, const String&, const IntPoint&, const Font&, const Color&, int underlinedIndex = -1); - void WebCoreDrawDoubledTextAtPoint(GraphicsContext&, const String&, const IntPoint&, const Font&, const Color& topColor, const Color& bottomColor, int underlinedIndex = -1); - float WebCoreTextFloatWidth(const String&, const Font&); - - void WebCoreSetShouldUseFontSmoothing(bool); - bool WebCoreShouldUseFontSmoothing(); - - void WebCoreSetAlwaysUsesComplexTextCodePath(bool); - bool WebCoreAlwaysUsesComplexTextCodePath(); - -} // namespace WebCore diff --git a/WebCore/platform/win/WheelEventWin.cpp b/WebCore/platform/win/WheelEventWin.cpp deleted file mode 100644 index d272ba7..0000000 --- a/WebCore/platform/win/WheelEventWin.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "PlatformWheelEvent.h" - -#include <windows.h> -#include <windowsx.h> - -namespace WebCore { - -#define HIGH_BIT_MASK_SHORT 0x8000 -#define SPI_GETWHEELSCROLLCHARS 0x006C - -static IntPoint positionForEvent(HWND hWnd, LPARAM lParam) -{ - POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; - ScreenToClient(hWnd, &point); - return point; -} - -static IntPoint globalPositionForEvent(HWND hWnd, LPARAM lParam) -{ - POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; - return point; -} - -int PlatformWheelEvent::horizontalLineMultiplier() const -{ - static ULONG scrollChars; - if (!scrollChars && !SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &scrollChars, 0)) - scrollChars = cLineMultiplier; - return scrollChars; -} - -int PlatformWheelEvent::verticalLineMultiplier() const -{ - static ULONG scrollLines; - if (!scrollLines && !SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0)) - scrollLines = cLineMultiplier; - return scrollLines; -} - -PlatformWheelEvent::PlatformWheelEvent(HWND hWnd, WPARAM wParam, LPARAM lParam, bool isHorizontal) - : m_position(positionForEvent(hWnd, lParam)) - , m_globalPosition(globalPositionForEvent(hWnd, lParam)) - , m_isAccepted(false) - , m_shiftKey(wParam & MK_SHIFT) - , m_ctrlKey(wParam & MK_CONTROL) - , m_altKey(GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT) - , m_metaKey(m_altKey) // FIXME: We'll have to test other browsers -{ - static ULONG scrollLines, scrollChars; - float delta = GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA; - if (isHorizontal) { - // Windows sends a positive delta for scrolling right, while AppKit - // sends a negative delta. EventHandler expects the AppKit values, - // so we have to negate our horizontal delta to match. - m_deltaX = -delta * horizontalLineMultiplier(); - m_deltaY = 0; - m_granularity = ScrollByLineWheelEvent; - } else { - m_deltaX = 0; - m_deltaY = delta; - int verticalMultiplier = verticalLineMultiplier(); - // A multiplier of -1 is used to mean that vertical wheel scrolling should be done by page. - m_granularity = (verticalMultiplier == -1) ? ScrollByPageWheelEvent : ScrollByLineWheelEvent; - if (m_granularity == ScrollByLineWheelEvent) - m_deltaY *= verticalMultiplier; - } -} - -} diff --git a/WebCore/platform/win/WidgetWin.cpp b/WebCore/platform/win/WidgetWin.cpp deleted file mode 100644 index 93dbf42..0000000 --- a/WebCore/platform/win/WidgetWin.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2006, 2007 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 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 "Widget.h" - -#include "Cursor.h" -#include "Document.h" -#include "Element.h" -#include "GraphicsContext.h" -#include "FrameWin.h" -#include "IntRect.h" -#include "FrameView.h" -#include <winsock2.h> -#include <windows.h> - -namespace WebCore { - -Widget::Widget(PlatformWidget widget) -{ - init(widget); -} - -Widget::~Widget() -{ - ASSERT(!parent()); -} - -void Widget::show() -{ -} - -void Widget::hide() -{ -} - -HCURSOR lastSetCursor = 0; -bool ignoreNextSetCursor = false; - -void Widget::setCursor(const Cursor& cursor) -{ - // This is set by PluginViewWin so it can ignore set setCursor call made by - // EventHandler.cpp. - if (ignoreNextSetCursor) { - ignoreNextSetCursor = false; - return; - } - - if (HCURSOR c = cursor.impl()->nativeCursor()) { - lastSetCursor = c; - SetCursor(c); - } -} - -void Widget::paint(GraphicsContext*, const IntRect&) -{ -} - -void Widget::setFocus() -{ -} - -void Widget::setIsSelected(bool) -{ -} - -IntRect Widget::frameRect() const -{ - return m_frame; -} - -void Widget::setFrameRect(const IntRect& rect) -{ - m_frame = rect; -} - -} // namespace WebCore diff --git a/WebCore/platform/win/WindowMessageBroadcaster.cpp b/WebCore/platform/win/WindowMessageBroadcaster.cpp deleted file mode 100644 index 7088995..0000000 --- a/WebCore/platform/win/WindowMessageBroadcaster.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2007 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 "WindowMessageBroadcaster.h" - -#include "WindowMessageListener.h" - -namespace WebCore { - -typedef HashMap<HWND, WindowMessageBroadcaster*> InstanceMap; - -static InstanceMap& instancesMap() -{ - static InstanceMap instances; - return instances; -} - -void WindowMessageBroadcaster::addListener(HWND hwnd, WindowMessageListener* listener) -{ - WindowMessageBroadcaster* broadcaster = instancesMap().get(hwnd); - if (!broadcaster) { - broadcaster = new WindowMessageBroadcaster(hwnd); - instancesMap().add(hwnd, broadcaster); - } - - broadcaster->addListener(listener); -} - -void WindowMessageBroadcaster::removeListener(HWND hwnd, WindowMessageListener* listener) -{ - WindowMessageBroadcaster* broadcaster = instancesMap().get(hwnd); - if (!broadcaster) - return; - - broadcaster->removeListener(listener); -} - -WindowMessageBroadcaster::WindowMessageBroadcaster(HWND hwnd) - : m_subclassedWindow(hwnd) - , m_originalWndProc(0) -{ - ASSERT_ARG(hwnd, IsWindow(hwnd)); -} - -WindowMessageBroadcaster::~WindowMessageBroadcaster() -{ -} - -void WindowMessageBroadcaster::addListener(WindowMessageListener* listener) -{ - if (m_listeners.isEmpty()) { - ASSERT(!m_originalWndProc); -#pragma warning(disable: 4244 4312) - m_originalWndProc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(m_subclassedWindow, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(SubclassedWndProc))); - } - - m_listeners.add(listener); -} - -void WindowMessageBroadcaster::removeListener(WindowMessageListener* listener) -{ - ListenerSet::iterator found = m_listeners.find(listener); - if (found == m_listeners.end()) - return; - - m_listeners.remove(found); - - if (m_listeners.isEmpty()) - destroy(); -} - -void WindowMessageBroadcaster::destroy() -{ - m_listeners.clear(); - unsubclassWindow(); - instancesMap().remove(m_subclassedWindow); - delete this; -} - -void WindowMessageBroadcaster::unsubclassWindow() -{ - SetWindowLongPtr(m_subclassedWindow, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(m_originalWndProc)); - m_originalWndProc = 0; -} - -LRESULT CALLBACK WindowMessageBroadcaster::SubclassedWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - WindowMessageBroadcaster* broadcaster = instancesMap().get(hwnd); - ASSERT(broadcaster); - - ListenerSet::const_iterator end = broadcaster->listeners().end(); - for (ListenerSet::const_iterator it = broadcaster->listeners().begin(); it != end; ++it) - (*it)->windowReceivedMessage(hwnd, message, wParam, lParam); - - WNDPROC originalWndProc = broadcaster->originalWndProc(); - - // This will delete broadcaster. - if (message == WM_DESTROY) - broadcaster->destroy(); - - return CallWindowProc(originalWndProc, hwnd, message, wParam, lParam); -} - -} // namespace WebCore diff --git a/WebCore/platform/win/WindowMessageBroadcaster.h b/WebCore/platform/win/WindowMessageBroadcaster.h deleted file mode 100644 index 734f4b1..0000000 --- a/WebCore/platform/win/WindowMessageBroadcaster.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2007 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. - */ - -#ifndef WindowMessageBroadcaster_h -#define WindowMessageBroadcaster_h - -#include <wtf/HashMap.h> -#include <wtf/HashSet.h> -#include <wtf/Noncopyable.h> - -namespace WebCore { - - class WindowMessageListener; - - class WindowMessageBroadcaster : Noncopyable { - public: - static void addListener(HWND, WindowMessageListener*); - static void removeListener(HWND, WindowMessageListener*); - - private: - typedef HashSet<WindowMessageListener*> ListenerSet; - - static LRESULT CALLBACK SubclassedWndProc(HWND, UINT, WPARAM, LPARAM); - - WindowMessageBroadcaster(HWND); - ~WindowMessageBroadcaster(); - - void addListener(WindowMessageListener*); - void removeListener(WindowMessageListener*); - const ListenerSet& listeners() const { return m_listeners; } - - void destroy(); - void unsubclassWindow(); - - WNDPROC originalWndProc() const { return m_originalWndProc; } - - HWND m_subclassedWindow; - WNDPROC m_originalWndProc; - ListenerSet m_listeners; - }; - -} // namespace WebCore - -#endif // WindowMessageBroadcaster_h diff --git a/WebCore/platform/win/WindowMessageListener.h b/WebCore/platform/win/WindowMessageListener.h deleted file mode 100644 index b99cb35..0000000 --- a/WebCore/platform/win/WindowMessageListener.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2007 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. - */ - -#ifndef WindowMessageListener_h -#define WindowMessageListener_h - -typedef struct HWND__* HWND; -typedef long LPARAM; -typedef unsigned UINT; -typedef unsigned WPARAM; - -namespace WebCore { - - class WindowMessageListener { - public: - virtual void windowReceivedMessage(HWND, UINT message, WPARAM, LPARAM) = 0; - }; - -} // namespace WebCore - -#endif // WindowMessageListener_h |