summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/win
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-05-06 11:45:16 +0100
committerSteve Block <steveblock@google.com>2011-05-12 13:44:10 +0100
commitcad810f21b803229eb11403f9209855525a25d57 (patch)
tree29a6fd0279be608e0fe9ffe9841f722f0f4e4269 /Source/WebCore/platform/win
parent121b0cf4517156d0ac5111caf9830c51b69bae8f (diff)
downloadexternal_webkit-cad810f21b803229eb11403f9209855525a25d57.zip
external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.gz
external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.bz2
Merge WebKit at r75315: Initial merge by git.
Change-Id: I570314b346ce101c935ed22a626b48c2af266b84
Diffstat (limited to 'Source/WebCore/platform/win')
-rw-r--r--Source/WebCore/platform/win/BString.cpp201
-rw-r--r--Source/WebCore/platform/win/BString.h82
-rw-r--r--Source/WebCore/platform/win/BitmapInfo.cpp64
-rw-r--r--Source/WebCore/platform/win/BitmapInfo.h64
-rw-r--r--Source/WebCore/platform/win/COMPtr.h242
-rw-r--r--Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp497
-rw-r--r--Source/WebCore/platform/win/ClipboardUtilitiesWin.h71
-rw-r--r--Source/WebCore/platform/win/ClipboardWin.cpp810
-rw-r--r--Source/WebCore/platform/win/ClipboardWin.h93
-rw-r--r--Source/WebCore/platform/win/ContextMenuItemWin.cpp105
-rw-r--r--Source/WebCore/platform/win/ContextMenuWin.cpp141
-rw-r--r--Source/WebCore/platform/win/CursorWin.cpp294
-rw-r--r--Source/WebCore/platform/win/DragDataWin.cpp145
-rw-r--r--Source/WebCore/platform/win/DragImageCGWin.cpp162
-rw-r--r--Source/WebCore/platform/win/DragImageCairoWin.cpp191
-rw-r--r--Source/WebCore/platform/win/DragImageWin.cpp83
-rw-r--r--Source/WebCore/platform/win/EditorWin.cpp53
-rw-r--r--Source/WebCore/platform/win/EventLoopWin.cpp45
-rw-r--r--Source/WebCore/platform/win/FileChooserWin.cpp55
-rw-r--r--Source/WebCore/platform/win/FileSystemWin.cpp307
-rw-r--r--Source/WebCore/platform/win/GDIObjectCounter.cpp74
-rw-r--r--Source/WebCore/platform/win/GDIObjectCounter.h63
-rw-r--r--Source/WebCore/platform/win/KeyEventWin.cpp225
-rw-r--r--Source/WebCore/platform/win/LanguageWin.cpp68
-rw-r--r--Source/WebCore/platform/win/LoggingWin.cpp100
-rw-r--r--Source/WebCore/platform/win/MIMETypeRegistryWin.cpp111
-rw-r--r--Source/WebCore/platform/win/PasteboardWin.cpp340
-rw-r--r--Source/WebCore/platform/win/PlatformMouseEventWin.cpp128
-rw-r--r--Source/WebCore/platform/win/PlatformScreenWin.cpp108
-rw-r--r--Source/WebCore/platform/win/PopupMenuWin.cpp1017
-rw-r--r--Source/WebCore/platform/win/PopupMenuWin.h125
-rw-r--r--Source/WebCore/platform/win/ScrollbarThemeSafari.cpp257
-rw-r--r--Source/WebCore/platform/win/ScrollbarThemeSafari.h63
-rw-r--r--Source/WebCore/platform/win/ScrollbarThemeWin.cpp379
-rw-r--r--Source/WebCore/platform/win/ScrollbarThemeWin.h62
-rw-r--r--Source/WebCore/platform/win/SearchPopupMenuWin.cpp102
-rw-r--r--Source/WebCore/platform/win/SearchPopupMenuWin.h44
-rw-r--r--Source/WebCore/platform/win/SharedBufferWin.cpp71
-rw-r--r--Source/WebCore/platform/win/SharedTimerWin.cpp224
-rw-r--r--Source/WebCore/platform/win/SoftLinking.h82
-rw-r--r--Source/WebCore/platform/win/SoundWin.cpp36
-rw-r--r--Source/WebCore/platform/win/SystemInfo.cpp56
-rw-r--r--Source/WebCore/platform/win/SystemInfo.h35
-rw-r--r--Source/WebCore/platform/win/SystemTimeWin.cpp49
-rw-r--r--Source/WebCore/platform/win/TemporaryLinkStubs.cpp36
-rw-r--r--Source/WebCore/platform/win/WCDataObject.cpp384
-rw-r--r--Source/WebCore/platform/win/WCDataObject.h69
-rw-r--r--Source/WebCore/platform/win/WebCoreInstanceHandle.cpp33
-rw-r--r--Source/WebCore/platform/win/WebCoreInstanceHandle.h41
-rw-r--r--Source/WebCore/platform/win/WebCoreTextRenderer.cpp126
-rw-r--r--Source/WebCore/platform/win/WebCoreTextRenderer.h45
-rw-r--r--Source/WebCore/platform/win/WheelEventWin.cpp136
-rw-r--r--Source/WebCore/platform/win/WidgetWin.cpp101
-rw-r--r--Source/WebCore/platform/win/WindowMessageBroadcaster.cpp130
-rw-r--r--Source/WebCore/platform/win/WindowMessageBroadcaster.h69
-rw-r--r--Source/WebCore/platform/win/WindowMessageListener.h46
56 files changed, 8740 insertions, 0 deletions
diff --git a/Source/WebCore/platform/win/BString.cpp b/Source/WebCore/platform/win/BString.cpp
new file mode 100644
index 0000000..4d6d11e
--- /dev/null
+++ b/Source/WebCore/platform/win/BString.cpp
@@ -0,0 +1,201 @@
+/*
+ * 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 "KURL.h"
+#include "PlatformString.h"
+#include <wtf/text/AtomicString.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.characters(), s.length());
+}
+
+#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/Source/WebCore/platform/win/BString.h b/Source/WebCore/platform/win/BString.h
new file mode 100644
index 0000000..bdbf189
--- /dev/null
+++ b/Source/WebCore/platform/win/BString.h
@@ -0,0 +1,82 @@
+/*
+ * 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
+
+#include <wtf/Forward.h>
+
+#if PLATFORM(CF)
+typedef const struct __CFString * CFStringRef;
+#endif
+
+typedef wchar_t* BSTR;
+
+namespace JSC {
+ class UString;
+}
+
+namespace WebCore {
+
+ class KURL;
+
+ 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/Source/WebCore/platform/win/BitmapInfo.cpp b/Source/WebCore/platform/win/BitmapInfo.cpp
new file mode 100644
index 0000000..610a27e
--- /dev/null
+++ b/Source/WebCore/platform/win/BitmapInfo.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2009 Brent Fulgham
+ * Copyright (C) 2007-2009 Torch Mobile, Inc. All Rights Reserved.
+ * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
+ *
+ * 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 "BitmapInfo.h"
+
+#include <wtf/Assertions.h>
+
+namespace WebCore {
+
+BitmapInfo bitmapInfoForSize(int width, int height, BitmapInfo::BitCount bitCount)
+{
+ BitmapInfo bitmapInfo;
+ bitmapInfo.bmiHeader.biWidth = width;
+ bitmapInfo.bmiHeader.biHeight = height;
+ bitmapInfo.bmiHeader.biPlanes = 1;
+ bitmapInfo.bmiHeader.biBitCount = bitCount;
+ bitmapInfo.bmiHeader.biCompression = BI_RGB;
+
+ return bitmapInfo;
+}
+
+BitmapInfo::BitmapInfo()
+{
+ memset(&bmiHeader, 0, sizeof(bmiHeader));
+ bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+}
+
+BitmapInfo BitmapInfo::create(const IntSize& size, BitCount bitCount)
+{
+ return bitmapInfoForSize(size.width(), size.height(), bitCount);
+}
+
+BitmapInfo BitmapInfo::createBottomUp(const IntSize& size, BitCount bitCount)
+{
+ return bitmapInfoForSize(size.width(), -size.height(), bitCount);
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/BitmapInfo.h b/Source/WebCore/platform/win/BitmapInfo.h
new file mode 100644
index 0000000..caf1b31
--- /dev/null
+++ b/Source/WebCore/platform/win/BitmapInfo.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2009 Brent Fulgham
+ * Copyright (C) 2007-2009 Torch Mobile, Inc. All Rights Reserved.
+ * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
+ *
+ * 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 BitmapInfo_h
+#define BitmapInfo_h
+
+#include "IntSize.h"
+#include <windows.h>
+
+namespace WebCore {
+
+struct BitmapInfo : public BITMAPINFO {
+ enum BitCount {
+ BitCount1 = 1,
+ BitCount4 = 4,
+ BitCount8 = 8,
+ BitCount16 = 16,
+ BitCount24 = 24,
+ BitCount32 = 32
+ };
+
+ BitmapInfo();
+ static BitmapInfo create(const IntSize&, BitCount bitCount = BitCount32);
+ static BitmapInfo createBottomUp(const IntSize&, BitCount bitCount = BitCount32);
+
+ bool is16bit() const { return bmiHeader.biBitCount == 16; }
+ bool is32bit() const { return bmiHeader.biBitCount == 32; }
+ unsigned width() const { return abs(bmiHeader.biWidth); }
+ unsigned height() const { return abs(bmiHeader.biHeight); }
+ IntSize size() const { return IntSize(width(), height()); }
+ unsigned bytesPerLine() const { return (width() * bmiHeader.biBitCount + 7) / 8; }
+ unsigned paddedBytesPerLine() const { return (bytesPerLine() + 3) & ~0x3; }
+ unsigned paddedWidth() const { return paddedBytesPerLine() * 8 / bmiHeader.biBitCount; }
+ unsigned numPixels() const { return paddedWidth() * height(); }
+};
+
+} // namespace WebCore
+
+#endif // BitmapInfo_h
diff --git a/Source/WebCore/platform/win/COMPtr.h b/Source/WebCore/platform/win/COMPtr.h
new file mode 100644
index 0000000..95b53af
--- /dev/null
+++ b/Source/WebCore/platform/win/COMPtr.h
@@ -0,0 +1,242 @@
+/*
+ * Copyright (C) 2007, 2010 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
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+
+#include <unknwn.h>
+#include <wtf/Assertions.h>
+#include <wtf/HashTraits.h>
+
+#if !OS(WINCE)
+#include <guiddef.h>
+#endif
+
+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; }
+
+ void clear();
+ T* leakRef();
+
+ 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*);
+
+ // FIXME: Remove releaseRef once we change all callers to call leakRef instead.
+ T* releaseRef() { return leakRef(); }
+
+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 void COMPtr<T>::clear()
+{
+ if (T* ptr = m_ptr) {
+ m_ptr = 0;
+ ptr->Release();
+ }
+}
+
+template<typename T> inline T* COMPtr<T>::leakRef()
+{
+ T* ptr = m_ptr;
+ m_ptr = 0;
+ return 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) { new (&slot) COMPtr<P>(HashTableDeletedValue); }
+ static bool isDeletedValue(const COMPtr<P>& value) { return value.isHashTableDeletedValue(); }
+ };
+
+ 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/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp b/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp
new file mode 100644
index 0000000..eb1e659
--- /dev/null
+++ b/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp
@@ -0,0 +1,497 @@
+/*
+ * 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 "DocumentFragment.h"
+#include "KURL.h"
+#include "PlatformString.h"
+#include "TextEncoding.h"
+#include "markup.h"
+#include <shlwapi.h>
+#include <wininet.h> // for INTERNET_MAX_URL_LENGTH
+#include <wtf/StringExtras.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/StringConcatenate.h>
+
+#if PLATFORM(CF)
+#include <CoreFoundation/CoreFoundation.h>
+#include <wtf/RetainPtr.h>
+#endif
+
+namespace WebCore {
+
+#if PLATFORM(CF)
+FORMATETC* cfHDropFormat()
+{
+ static FORMATETC urlFormat = {CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
+ return &urlFormat;
+}
+
+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 = CFURLGetString(cfURL.get());
+
+ // Work around <rdar://problem/6708300>, where CFURLCreateWithFileSystemPath makes URLs with "localhost".
+ if (url.startsWith("file://localhost/"))
+ url.remove(7, 9);
+
+ return true;
+}
+#endif
+
+static bool getWebLocData(IDataObject* dataObject, String& url, String* title)
+{
+ bool succeeded = false;
+#if PLATFORM(CF)
+ WCHAR filename[MAX_PATH];
+ WCHAR urlBuffer[INTERNET_MAX_URL_LENGTH];
+
+ STGMEDIUM medium;
+ if (FAILED(dataObject->GetData(cfHDropFormat(), &medium)))
+ return false;
+
+ HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal));
+
+ if (!hdrop)
+ return false;
+
+ if (!DragQueryFileW(hdrop, 0, filename, WTF_ARRAY_LENGTH(filename)))
+ goto exit;
+
+ if (_wcsicmp(PathFindExtensionW(filename), L".url"))
+ goto exit;
+
+ if (!GetPrivateProfileStringW(L"InternetShortcut", L"url", 0, urlBuffer, WTF_ARRAY_LENGTH(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);
+#endif
+ 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 = static_cast<PWSTR>(GlobalLock(cbData));
+ _snwprintf(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 String getFullCFHTML(IDataObject* data, bool& success)
+{
+ STGMEDIUM store;
+ if (SUCCEEDED(data->GetData(htmlFormat(), &store))) {
+ // MS HTML Format parsing
+ char* data = static_cast<char*>(GlobalLock(store.hGlobal));
+ SIZE_T dataSize = ::GlobalSize(store.hGlobal);
+ String cfhtml(UTF8Encoding().decode(data, dataSize));
+ GlobalUnlock(store.hGlobal);
+ ReleaseStgMedium(&store);
+ success = true;
+ return cfhtml;
+ }
+ success = false;
+ return String();
+}
+
+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());
+}
+
+// Find the markup between "<!--StartFragment -->" and "<!--EndFragment -->", accounting for browser quirks.
+static String extractMarkupFromCFHTML(const String& cfhtml)
+{
+ unsigned markupStart = cfhtml.find("<html", 0, false);
+ unsigned tagStart = cfhtml.find("startfragment", markupStart, false);
+ unsigned fragmentStart = cfhtml.find('>', tagStart) + 1;
+ unsigned tagEnd = cfhtml.find("endfragment", fragmentStart, false);
+ unsigned fragmentEnd = cfhtml.reverseFind('<', tagEnd);
+ return cfhtml.substring(fragmentStart, fragmentEnd - fragmentStart).stripWhiteSpace();
+}
+
+// Documentation for the CF_HTML format is available at http://msdn.microsoft.com/workshop/networking/clipboard/htmlclipboard.asp
+void markupToCFHTML(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);
+
+ unsigned headerBufferLength = startHTMLOffset + 1; // + 1 for '\0' terminator.
+ char* headerBuffer = (char*)malloc(headerBufferLength);
+ snprintf(headerBuffer, headerBufferLength, header, startHTMLOffset, endHTMLOffset, startFragmentOffset, endFragmentOffset);
+ append(result, CString(headerBuffer));
+ free(headerBuffer);
+ 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
+}
+
+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;
+}
+
+String getURL(IDataObject* dataObject, DragData::FilenameConversionPolicy filenamePolicy, bool& success, String* title)
+{
+ STGMEDIUM store;
+ String url;
+ success = false;
+ if (getWebLocData(dataObject, url, title))
+ success = true;
+ else if (SUCCEEDED(dataObject->GetData(urlWFormat(), &store))) {
+ // URL using Unicode
+ UChar* data = static_cast<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 = static_cast<char*>(GlobalLock(store.hGlobal));
+ url = extractURL(String(data), title);
+ GlobalUnlock(store.hGlobal);
+ ReleaseStgMedium(&store);
+ success = true;
+ }
+#if PLATFORM(CF)
+ else if (filenamePolicy == DragData::ConvertFilenames) {
+ if (SUCCEEDED(dataObject->GetData(filenameWFormat(), &store))) {
+ // file using unicode
+ wchar_t* data = static_cast<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 = static_cast<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);
+ }
+ }
+#endif
+ return url;
+}
+
+String getPlainText(IDataObject* dataObject, bool& success)
+{
+ STGMEDIUM store;
+ String text;
+ success = false;
+ if (SUCCEEDED(dataObject->GetData(plainTextWFormat(), &store))) {
+ // Unicode text
+ UChar* data = static_cast<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 = static_cast<char*>(GlobalLock(store.hGlobal));
+ text = String(data);
+ GlobalUnlock(store.hGlobal);
+ ReleaseStgMedium(&store);
+ success = true;
+ } else {
+ // FIXME: Originally, we called getURL() here because dragging and dropping files doesn't
+ // populate the drag with text data. Per https://bugs.webkit.org/show_bug.cgi?id=38826, this
+ // is undesirable, so maybe this line can be removed.
+ text = getURL(dataObject, DragData::DoNotConvertFilenames, success);
+ success = true;
+ }
+ return text;
+}
+
+String getTextHTML(IDataObject* data, bool& success)
+{
+ STGMEDIUM store;
+ String html;
+ success = false;
+ if (SUCCEEDED(data->GetData(texthtmlFormat(), &store))) {
+ UChar* data = static_cast<UChar*>(GlobalLock(store.hGlobal));
+ html = String(data);
+ GlobalUnlock(store.hGlobal);
+ ReleaseStgMedium(&store);
+ success = true;
+ }
+ return html;
+}
+
+String getCFHTML(IDataObject* data, bool& success)
+{
+ String cfhtml = getFullCFHTML(data, success);
+ if (success)
+ return extractMarkupFromCFHTML(cfhtml);
+ return String();
+}
+
+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> fragmentFromCFHTML(Document* doc, const String& cfhtml)
+{
+ // obtain baseURL if present
+ String srcURLStr("sourceURL:");
+ String srcURL;
+ unsigned lineStart = cfhtml.find(srcURLStr, 0, false);
+ if (lineStart != -1) {
+ unsigned srcEnd = cfhtml.find("\n", lineStart, false);
+ unsigned srcStart = lineStart+srcURLStr.length();
+ String rawSrcURL = cfhtml.substring(srcStart, srcEnd-srcStart);
+ replaceNBSPWithSpace(rawSrcURL);
+ srcURL = rawSrcURL.stripWhiteSpace();
+ }
+
+ String markup = extractMarkupFromCFHTML(cfhtml);
+ return createFragmentFromMarkup(doc, markup, srcURL, FragmentScriptingNotAllowed);
+}
+
+PassRefPtr<DocumentFragment> fragmentFromHTML(Document* doc, IDataObject* data)
+{
+ if (!doc || !data)
+ return 0;
+
+ bool success = false;
+ String cfhtml = getFullCFHTML(data, success);
+ if (success) {
+ if (PassRefPtr<DocumentFragment> fragment = fragmentFromCFHTML(doc, cfhtml))
+ return fragment;
+ }
+
+ String html = getTextHTML(data, success);
+ String srcURL;
+ if (success)
+ return createFragmentFromMarkup(doc, html, srcURL, FragmentScriptingNotAllowed);
+
+ return 0;
+}
+
+bool containsHTML(IDataObject* data)
+{
+ return SUCCEEDED(data->QueryGetData(texthtmlFormat())) || SUCCEEDED(data->QueryGetData(htmlFormat()));
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/ClipboardUtilitiesWin.h b/Source/WebCore/platform/win/ClipboardUtilitiesWin.h
new file mode 100644
index 0000000..1a29e7e
--- /dev/null
+++ b/Source/WebCore/platform/win/ClipboardUtilitiesWin.h
@@ -0,0 +1,71 @@
+/*
+ * 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>
+#include <wtf/Forward.h>
+
+namespace WebCore {
+
+class Document;
+class KURL;
+
+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 markupToCFHTML(const String& markup, const String& srcURL, Vector<char>& result);
+
+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> fragmentFromCFHTML(Document*, const String& cfhtml);
+
+String getURL(IDataObject*, DragData::FilenameConversionPolicy, bool& success, String* title = 0);
+String getPlainText(IDataObject*, bool& success);
+String getTextHTML(IDataObject*, bool& success);
+String getCFHTML(IDataObject*, bool& success);
+
+} // namespace WebCore
+
+#endif // ClipboardUtilitiesWin_h
diff --git a/Source/WebCore/platform/win/ClipboardWin.cpp b/Source/WebCore/platform/win/ClipboardWin.cpp
new file mode 100644
index 0000000..58cfe44
--- /dev/null
+++ b/Source/WebCore/platform/win/ClipboardWin.cpp
@@ -0,0 +1,810 @@
+/*
+ * 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 "CachedImage.h"
+#include "ClipboardUtilitiesWin.h"
+#include "Document.h"
+#include "DragData.h"
+#include "Editor.h"
+#include "Element.h"
+#include "EventHandler.h"
+#include "FileList.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "FrameView.h"
+#include "HTMLNames.h"
+#include "HTMLParserIdioms.h"
+#include "Image.h"
+#include "MIMETypeRegistry.h"
+#include "NotImplemented.h"
+#include "Page.h"
+#include "Pasteboard.h"
+#include "PlatformMouseEvent.h"
+#include "PlatformString.h"
+#include "Range.h"
+#include "RenderImage.h"
+#include "ResourceResponse.h"
+#include "SharedBuffer.h"
+#include "WCDataObject.h"
+#include "markup.h"
+#include <shlwapi.h>
+#include <wininet.h>
+#include <wtf/RefPtr.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/StringConcatenate.h>
+#include <wtf/text/StringHash.h>
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+// 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, ClipboardDataTypeTextHTML };
+
+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;
+ if (qType == "text/html")
+ return ClipboardDataTypeTextHTML;
+
+ 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;
+}
+
+#if !OS(WINCE)
+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] || type & (GCT_LFNCHAR | GCT_SHORTCHAR))
+ psz[writeTo++] = psz[readFrom];
+
+ readFrom++;
+ }
+ psz[writeTo] = 0;
+}
+#endif
+
+static String filesystemPathFromUrlOrTitle(const String& url, const String& title, TCHAR* extension, bool isLink)
+{
+#if OS(WINCE)
+ notImplemented();
+ return String();
+#else
+ static const size_t fsPathMaxLengthExcludingNullTerminator = MAX_PATH - 1;
+ bool usedURL = false;
+ WCHAR fsPathBuffer[MAX_PATH];
+ fsPathBuffer[0] = 0;
+ int extensionLen = extension ? lstrlen(extension) : 0;
+ int fsPathMaxLengthExcludingExtension = fsPathMaxLengthExcludingNullTerminator - extensionLen;
+
+ if (!title.isEmpty()) {
+ size_t len = min<size_t>(title.length(), fsPathMaxLengthExcludingExtension);
+ CopyMemory(fsPathBuffer, title.characters(), len * sizeof(UChar));
+ fsPathBuffer[len] = 0;
+ pathRemoveBadFSCharacters(fsPathBuffer, len);
+ }
+
+ if (!lstrlen(fsPathBuffer)) {
+ KURL kurl(ParsedURLString, url);
+ usedURL = true;
+ // The filename for any content based drag or file url 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.
+ DWORD len = fsPathMaxLengthExcludingExtension;
+ String lastComponent = kurl.lastPathComponent();
+ if (kurl.isLocalFile() || (!isLink && !lastComponent.isEmpty())) {
+ len = min<DWORD>(fsPathMaxLengthExcludingExtension, lastComponent.length());
+ CopyMemory(fsPathBuffer, lastComponent.characters(), len * sizeof(UChar));
+ } else {
+ len = min<DWORD>(fsPathMaxLengthExcludingExtension, url.length());
+ CopyMemory(fsPathBuffer, url.characters(), len * sizeof(UChar));
+ }
+ fsPathBuffer[len] = 0;
+ pathRemoveBadFSCharacters(fsPathBuffer, len);
+ }
+
+ if (!extension)
+ return String(static_cast<UChar*>(fsPathBuffer));
+
+ if (!isLink && usedURL) {
+ PathRenameExtension(fsPathBuffer, extension);
+ return String(static_cast<UChar*>(fsPathBuffer));
+ }
+
+ String result(static_cast<UChar*>(fsPathBuffer));
+ result += String(static_cast<UChar*>(extension));
+ return result;
+#endif
+}
+
+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 {
+#if OS(WINCE)
+ notImplemented();
+ return 0;
+#else
+ WCHAR tempPath[MAX_PATH];
+ WCHAR extension[MAX_PATH];
+ if (!::GetTempPath(WTF_ARRAY_LENGTH(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;
+#endif
+ }
+
+ 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 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();
+
+ const String& preferredTitle = title.isEmpty() ? image->response().suggestedFilename() : title;
+ String extension = image->image()->filenameExtension();
+ if (extension.isEmpty()) {
+ // Do not continue processing in the rare and unusual case where a decoded image is not able
+ // to provide a filename extension. Something tricky (like a bait-n-switch) is going on
+ return 0;
+ }
+ extension.insert(".", 0);
+ fsPath = filesystemPathFromUrlOrTitle(url, preferredTitle, (TCHAR*)extension.charactersWithNullTermination(), false);
+
+ if (fsPath.length() <= 0) {
+ GlobalUnlock(memObj);
+ GlobalFree(memObj);
+ return 0;
+ }
+
+ int maxSize = min(fsPath.length(), WTF_ARRAY_LENGTH(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;
+
+#if PLATFORM(CF)
+ // HDROP
+ if (hDropContent) {
+ medium.hGlobal = hDropContent;
+ hr = dataObject->SetData(cfHDropFormat(), &medium, TRUE);
+ }
+#endif
+
+exit:
+ if (FAILED(hr)) {
+ if (fileDescriptor)
+ GlobalFree(fileDescriptor);
+ if (fileContent)
+ GlobalFree(fileContent);
+ if (hDropContent)
+ GlobalFree(hDropContent);
+ }
+ return hr;
+}
+
+PassRefPtr<Clipboard> Clipboard::create(ClipboardAccessPolicy policy, DragData* dragData, Frame* frame)
+{
+ return ClipboardWin::create(DragAndDrop, dragData->platformData(), policy, frame);
+}
+
+ClipboardWin::ClipboardWin(ClipboardType clipboardType, IDataObject* dataObject, ClipboardAccessPolicy policy, Frame* frame)
+ : Clipboard(policy, clipboardType)
+ , m_dataObject(dataObject)
+ , m_writableDataObject(0)
+ , m_frame(frame)
+{
+}
+
+ClipboardWin::ClipboardWin(ClipboardType clipboardType, WCDataObject* dataObject, ClipboardAccessPolicy policy, Frame* frame)
+ : Clipboard(policy, clipboardType)
+ , m_dataObject(dataObject)
+ , m_writableDataObject(dataObject)
+ , m_frame(frame)
+{
+}
+
+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;
+ markupToCFHTML(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(isForDragAndDrop());
+ 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(isForDragAndDrop());
+ 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);
+ if (dataType == ClipboardDataTypeURL)
+ return getURL(m_dataObject.get(), DragData::DoNotConvertFilenames, success);
+ else if (dataType == ClipboardDataTypeTextHTML) {
+ String data = getTextHTML(m_dataObject.get(), success);
+ if (success)
+ return data;
+ return getCFHTML(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(isForDragAndDrop());
+ if (policy() != ClipboardWritable || !m_writableDataObject)
+ return false;
+
+ ClipboardDataType winType = clipboardTypeFromMIMEType(type);
+
+ if (winType == ClipboardDataTypeURL)
+ return WebCore::writeURL(m_writableDataObject.get(), KURL(ParsedURLString, 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, const 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(DATADIR_GET, &itr)))
+ return results;
+
+ if (!itr)
+ return results;
+
+ FORMATETC data;
+
+ // IEnumFORMATETC::Next returns S_FALSE if there are no more items.
+ while (itr->Next(1, &data, 0) == S_OK)
+ addMimeTypesForFormat(results, data);
+
+ return results;
+}
+
+PassRefPtr<FileList> ClipboardWin::files() const
+{
+#if OS(WINCE)
+ notImplemented();
+ return 0;
+#else
+ RefPtr<FileList> files = FileList::create();
+ if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
+ return files.release();
+
+ if (!m_dataObject)
+ return files.release();
+
+ STGMEDIUM medium;
+ if (FAILED(m_dataObject->GetData(cfHDropFormat(), &medium)))
+ return files.release();
+
+ HDROP hdrop = reinterpret_cast<HDROP>(GlobalLock(medium.hGlobal));
+ if (!hdrop)
+ return files.release();
+
+ WCHAR filename[MAX_PATH];
+ UINT fileCount = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0);
+ for (UINT i = 0; i < fileCount; i++) {
+ if (!DragQueryFileW(hdrop, i, filename, WTF_ARRAY_LENGTH(filename)))
+ continue;
+ files->append(File::create(reinterpret_cast<UChar*>(filename)));
+ }
+
+ GlobalUnlock(medium.hGlobal);
+ ReleaseStgMedium(&medium);
+ return files.release();
+#endif
+}
+
+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;
+ if (m_dragImage) {
+ result = createDragImageFromImage(m_dragImage->image());
+ loc = m_dragLoc;
+ } else if (m_dragImageElement) {
+ Node* node = m_dragImageElement.get();
+ result = node->document()->frame()->nodeImage(node);
+ 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 = toRenderImage(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(stripLeadingAndTrailingHTMLSpaces(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;
+ markupToCFHTML(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);
+
+ String url = kurl.string();
+ ASSERT(url.containsOnlyASCII()); // KURL::string() is URL encoded.
+
+ String fsPath = filesystemPathFromUrlOrTitle(url, titleStr, L".URL", true);
+ CString content = makeString("[InternetShortcut]\r\nURL=", url, "\r\n").ascii();
+
+ if (fsPath.length() <= 0)
+ return;
+
+ HGLOBAL urlFileDescriptor = GlobalAlloc(GPTR, sizeof(FILEGROUPDESCRIPTOR));
+ if (!urlFileDescriptor)
+ return;
+
+ HGLOBAL urlFileContent = GlobalAlloc(GPTR, content.length());
+ if (!urlFileContent) {
+ GlobalFree(urlFileDescriptor);
+ return;
+ }
+
+ FILEGROUPDESCRIPTOR* fgd = static_cast<FILEGROUPDESCRIPTOR*>(GlobalLock(urlFileDescriptor));
+ ZeroMemory(fgd, sizeof(FILEGROUPDESCRIPTOR));
+ fgd->cItems = 1;
+ fgd->fgd[0].dwFlags = FD_FILESIZE;
+ fgd->fgd[0].nFileSizeLow = content.length();
+
+ unsigned maxSize = min(fsPath.length(), WTF_ARRAY_LENGTH(fgd->fgd[0].cFileName));
+ CopyMemory(fgd->fgd[0].cFileName, fsPath.characters(), maxSize * sizeof(UChar));
+ GlobalUnlock(urlFileDescriptor);
+
+ char* fileContents = static_cast<char*>(GlobalLock(urlFileContent));
+ CopyMemory(fileContents, content.data(), content.length());
+ GlobalUnlock(urlFileContent);
+
+ 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;
+ markupToCFHTML(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->editor()->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);
+}
+
+void ClipboardWin::writePlainText(const String& text)
+{
+ if (!m_writableDataObject)
+ return;
+
+ STGMEDIUM medium = {0};
+ medium.tymed = TYMED_HGLOBAL;
+ ExceptionCode ec = 0;
+
+ String str = text;
+ replaceNewlinesWithWindowsStyleNewlines(str);
+ replaceNBSPWithSpace(str);
+ medium.hGlobal = createGlobalData(str);
+ if (medium.hGlobal && FAILED(m_writableDataObject->SetData(plainTextWFormat(), &medium, TRUE)))
+ ::GlobalFree(medium.hGlobal);
+
+ medium.hGlobal = 0;
+}
+
+bool ClipboardWin::hasData()
+{
+ if (!m_dataObject)
+ return false;
+
+ COMPtr<IEnumFORMATETC> itr;
+ if (FAILED(m_dataObject->EnumFormatEtc(DATADIR_GET, &itr)))
+ return false;
+
+ if (!itr)
+ return false;
+
+ FORMATETC data;
+
+ // IEnumFORMATETC::Next returns S_FALSE if there are no more items.
+ if (itr->Next(1, &data, 0) == S_OK) {
+ // There is at least one item in the IDataObject
+ return true;
+ }
+
+ return false;
+}
+
+void ClipboardWin::setExternalDataObject(IDataObject *dataObject)
+{
+ ASSERT(isForDragAndDrop());
+
+ m_writableDataObject = 0;
+ m_dataObject = dataObject;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/ClipboardWin.h b/Source/WebCore/platform/win/ClipboardWin.h
new file mode 100644
index 0000000..ce64b85
--- /dev/null
+++ b/Source/WebCore/platform/win/ClipboardWin.h
@@ -0,0 +1,93 @@
+/*
+ * 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 "COMPtr.h"
+#include "CachedResourceClient.h"
+#include "Clipboard.h"
+
+struct IDataObject;
+
+namespace WebCore {
+
+class CachedImage;
+class Frame;
+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(ClipboardType clipboardType, IDataObject* dataObject, ClipboardAccessPolicy policy, Frame* frame)
+ {
+ return adoptRef(new ClipboardWin(clipboardType, dataObject, policy, frame));
+ }
+ static PassRefPtr<ClipboardWin> create(ClipboardType clipboardType, WCDataObject* dataObject, ClipboardAccessPolicy policy, Frame* frame)
+ {
+ return adoptRef(new ClipboardWin(clipboardType, dataObject, policy, frame));
+ }
+ ~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
+ virtual HashSet<String> types() const;
+ virtual PassRefPtr<FileList> files() 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 void writePlainText(const String&);
+
+ virtual bool hasData();
+
+ COMPtr<IDataObject> dataObject() { return m_dataObject; }
+
+ void setExternalDataObject(IDataObject *dataObject);
+
+private:
+ ClipboardWin(ClipboardType, IDataObject*, ClipboardAccessPolicy, Frame*);
+ ClipboardWin(ClipboardType, WCDataObject*, ClipboardAccessPolicy, Frame*);
+
+ 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/Source/WebCore/platform/win/ContextMenuItemWin.cpp b/Source/WebCore/platform/win/ContextMenuItemWin.cpp
new file mode 100644
index 0000000..a19fb9b
--- /dev/null
+++ b/Source/WebCore/platform/win/ContextMenuItemWin.cpp
@@ -0,0 +1,105 @@
+/*
+ * 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"
+
+#if OS(WINCE)
+#ifndef MFS_DISABLED
+#define MFS_DISABLED MF_GRAYED
+#endif
+#ifndef MIIM_FTYPE
+#define MIIM_FTYPE MIIM_TYPE
+#endif
+#ifndef MIIM_STRING
+#define MIIM_STRING 0
+#endif
+#endif
+
+namespace WebCore {
+
+ContextMenuItem::ContextMenuItem(const MENUITEMINFO& info)
+{
+ if (info.fMask & MIIM_FTYPE)
+ m_type = info.fType == MFT_SEPARATOR ? SeparatorType : ActionType;
+ else
+ m_type = SeparatorType;
+
+ if (m_type == ActionType && info.fMask & MIIM_STRING)
+ m_title = String(info.dwTypeData, info.cch);
+
+ if ((info.fMask & MIIM_SUBMENU) && info.hSubMenu) {
+ m_type = SubmenuType;
+ ContextMenu::getContextMenuItems(info.hSubMenu, m_subMenuItems);
+ }
+
+ if (info.fMask & MIIM_ID)
+ m_action = static_cast<ContextMenuAction>(info.wID);
+ else
+ m_action = ContextMenuItemTagNoAction;
+
+ if (info.fMask & MIIM_STATE) {
+ m_checked = info.fState & MFS_CHECKED;
+ m_enabled = !(info.fState & MFS_DISABLED);
+ } else {
+ m_checked = false;
+ m_enabled = false;
+ }
+}
+
+// ContextMenuItem::nativeMenuItem doesn't set the info.dwTypeData. This is
+// done to make the lifetime handling of the returned MENUITEMINFO easier on
+// callers. Callers can set dwTypeData themselves (and make their own decisions
+// about its lifetime) if they need it.
+MENUITEMINFO ContextMenuItem::nativeMenuItem() const
+{
+ MENUITEMINFO info = {0};
+ info.cbSize = sizeof(MENUITEMINFO);
+
+ if (m_type == SeparatorType) {
+ info.fMask = MIIM_FTYPE;
+ info.fType = MFT_SEPARATOR;
+ return info;
+ }
+
+ info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE;
+ info.fType = MFT_STRING;
+
+ info.wID = m_action;
+
+ if (m_type == SubmenuType) {
+ info.fMask |= MIIM_SUBMENU;
+ info.hSubMenu = ContextMenu::createNativeMenuFromItems(m_subMenuItems);
+ }
+
+ info.fState |= m_enabled ? MFS_ENABLED : MFS_DISABLED;
+ info.fState |= m_checked ? MFS_CHECKED : MFS_UNCHECKED;
+
+ return info;
+}
+
+}
diff --git a/Source/WebCore/platform/win/ContextMenuWin.cpp b/Source/WebCore/platform/win/ContextMenuWin.cpp
new file mode 100644
index 0000000..ed1b895
--- /dev/null
+++ b/Source/WebCore/platform/win/ContextMenuWin.cpp
@@ -0,0 +1,141 @@
+/*
+ * 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 "Document.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "Node.h"
+#include "NotImplemented.h"
+#include <tchar.h>
+#include <windows.h>
+#include <wtf/Vector.h>
+#include <wtf/text/CString.h>
+
+#ifndef MIIM_FTYPE
+#define MIIM_FTYPE MIIM_TYPE
+#endif
+#ifndef MIIM_STRING
+#define MIIM_STRING MIIM_TYPE
+#endif
+
+namespace WebCore {
+
+ContextMenu::ContextMenu(HMENU menu)
+{
+ getContextMenuItems(menu, m_items);
+}
+
+void ContextMenu::getContextMenuItems(HMENU menu, Vector<ContextMenuItem>& items)
+{
+#if OS(WINCE)
+ notImplemented();
+#else
+ int count = ::GetMenuItemCount(menu);
+ if (count <= 0)
+ return;
+
+ for (int i = 0; i < count; ++i) {
+ MENUITEMINFO info = {0};
+ info.cbSize = sizeof(MENUITEMINFO);
+ info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE | MIIM_SUBMENU;
+
+ if (!::GetMenuItemInfo(menu, i, TRUE, &info))
+ continue;
+
+ if (info.fType == MFT_SEPARATOR) {
+ items.append(ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
+ continue;
+ }
+
+ int menuStringLength = info.cch + 1;
+ OwnArrayPtr<WCHAR> menuString(new WCHAR[menuStringLength]);
+ info.dwTypeData = menuString.get();
+ info.cch = menuStringLength;
+
+ if (::GetMenuItemInfo(menu, i, TRUE, &info))
+ items.append(ContextMenuItem(info));
+ }
+#endif
+}
+
+HMENU ContextMenu::createNativeMenuFromItems(const Vector<ContextMenuItem>& items)
+{
+ HMENU menu = ::CreatePopupMenu();
+
+ for (size_t i = 0; i < items.size(); ++i) {
+ const ContextMenuItem& item = items[i];
+
+ MENUITEMINFO menuItem = item.nativeMenuItem();
+
+#if OS(WINCE)
+ UINT flags = MF_BYPOSITION;
+ UINT newItem = 0;
+ LPCWSTR title = 0;
+
+ if (item.type() == SeparatorType)
+ flags |= MF_SEPARATOR;
+ else {
+ flags |= MF_STRING;
+ flags |= item.checked() ? MF_CHECKED : MF_UNCHECKED;
+ flags |= item.enabled() ? MF_ENABLED : MF_GRAYED;
+
+ title = menuItem.dwTypeData;
+ menuItem.dwTypeData = 0;
+
+ if (menuItem.hSubMenu) {
+ flags |= MF_POPUP;
+ newItem = reinterpret_cast<UINT>(menuItem.hSubMenu);
+ menuItem.hSubMenu = 0;
+ } else
+ newItem = menuItem.wID;
+ }
+
+ ::InsertMenuW(menu, i, flags, newItem, title);
+#else
+ // ContextMenuItem::nativeMenuItem doesn't set the title of the MENUITEMINFO to make the
+ // lifetime handling easier for callers.
+ String itemTitle = item.title();
+ if (item.type() != SeparatorType) {
+ menuItem.fMask |= MIIM_STRING;
+ menuItem.cch = itemTitle.length();
+ menuItem.dwTypeData = const_cast<LPWSTR>(itemTitle.charactersWithNullTermination());
+ }
+
+ ::InsertMenuItem(menu, i, TRUE, &menuItem);
+#endif
+ }
+
+ return menu;
+}
+
+HMENU ContextMenu::nativeMenu() const
+{
+ return createNativeMenuFromItems(m_items);
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/CursorWin.cpp b/Source/WebCore/platform/win/CursorWin.cpp
new file mode 100644
index 0000000..2dd1452
--- /dev/null
+++ b/Source/WebCore/platform/win/CursorWin.cpp
@@ -0,0 +1,294 @@
+/*
+ * 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 "BitmapInfo.h"
+#include "Image.h"
+#include "IntPoint.h"
+
+#include <wtf/OwnPtr.h>
+
+#include <windows.h>
+
+#define ALPHA_CURSORS
+
+namespace WebCore {
+
+static inline bool supportsAlphaCursors()
+{
+ OSVERSIONINFO osinfo = {0};
+ osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&osinfo);
+ return osinfo.dwMajorVersion > 5 || (osinfo.dwMajorVersion == 5 && osinfo.dwMinorVersion > 0);
+}
+
+static PassRefPtr<SharedCursor> createSharedCursor(Image* img, const IntPoint& hotSpot)
+{
+ RefPtr<SharedCursor> impl;
+
+ IntPoint effectiveHotSpot = determineHotSpot(img, hotSpot);
+ static bool doAlpha = supportsAlphaCursors();
+ BitmapInfo cursorImage = BitmapInfo::create(IntSize(img->width(), img->height()));
+
+ 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 = effectiveHotSpot.x();
+ ii.yHotspot = effectiveHotSpot.y();
+ ii.hbmMask = hMask.get();
+ ii.hbmColor = hCursor.get();
+
+ 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 = effectiveHotSpot.x();
+ icon.yHotspot = effectiveHotSpot.y();
+ icon.hbmMask = andMask.get();
+ icon.hbmColor = xorMask.get();
+ impl = SharedCursor::create(CreateIconIndirect(&icon));
+
+ DeleteDC(xorMaskDC);
+ DeleteDC(andMaskDC);
+ }
+ DeleteDC(workingDC);
+ ReleaseDC(0, dc);
+
+ return impl.release();
+}
+
+static PassRefPtr<SharedCursor> loadSharedCursor(HINSTANCE hInstance, LPCTSTR lpCursorName)
+{
+ return SharedCursor::create(::LoadCursor(hInstance, lpCursorName));
+}
+
+static PassRefPtr<SharedCursor> loadCursorByName(char* name, int x, int y)
+{
+ IntPoint hotSpot(x, y);
+ RefPtr<Image> cursorImage(Image::loadPlatformResource(name));
+ if (cursorImage && !cursorImage->isNull())
+ return createSharedCursor(cursorImage.get(), hotSpot);
+ return loadSharedCursor(0, IDC_ARROW);
+}
+
+void Cursor::ensurePlatformCursor() const
+{
+ if (m_platformCursor)
+ return;
+
+ switch (m_type) {
+ case Cursor::Pointer:
+ case Cursor::Cell:
+ case Cursor::ContextMenu:
+ case Cursor::Alias:
+ case Cursor::Copy:
+ case Cursor::None:
+ case Cursor::Grab:
+ case Cursor::Grabbing:
+ m_platformCursor = loadSharedCursor(0, IDC_ARROW);
+ break;
+ case Cursor::Cross:
+ m_platformCursor = loadSharedCursor(0, IDC_CROSS);
+ break;
+ case Cursor::Hand:
+ m_platformCursor = loadSharedCursor(0, IDC_HAND);
+ break;
+ case Cursor::IBeam:
+ m_platformCursor = loadSharedCursor(0, IDC_IBEAM);
+ break;
+ case Cursor::Wait:
+ m_platformCursor = loadSharedCursor(0, IDC_WAIT);
+ break;
+ case Cursor::Help:
+ m_platformCursor = loadSharedCursor(0, IDC_HELP);
+ break;
+ case Cursor::Move:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZEALL);
+ break;
+ case Cursor::MiddlePanning:
+ m_platformCursor = loadCursorByName("panIcon", 8, 8);
+ break;
+ case Cursor::EastResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZEWE);
+ break;
+ case Cursor::EastPanning:
+ m_platformCursor = loadCursorByName("panEastCursor", 7, 7);
+ break;
+ case Cursor::NorthResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENS);
+ break;
+ case Cursor::NorthPanning:
+ m_platformCursor = loadCursorByName("panNorthCursor", 7, 7);
+ break;
+ case Cursor::NorthEastResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENESW);
+ break;
+ case Cursor::NorthEastPanning:
+ m_platformCursor = loadCursorByName("panNorthEastCursor", 7, 7);
+ break;
+ case Cursor::NorthWestResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENWSE);
+ break;
+ case Cursor::NorthWestPanning:
+ m_platformCursor = loadCursorByName("panNorthWestCursor", 7, 7);
+ break;
+ case Cursor::SouthResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENS);
+ break;
+ case Cursor::SouthPanning:
+ m_platformCursor = loadCursorByName("panSouthCursor", 7, 7);
+ break;
+ case Cursor::SouthEastResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENWSE);
+ break;
+ case Cursor::SouthEastPanning:
+ m_platformCursor = loadCursorByName("panSouthEastCursor", 7, 7);
+ break;
+ case Cursor::SouthWestResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENESW);
+ break;
+ case Cursor::SouthWestPanning:
+ m_platformCursor = loadCursorByName("panSouthWestCursor", 7, 7);
+ break;
+ case Cursor::WestResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZEWE);
+ break;
+ case Cursor::NorthSouthResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENS);
+ break;
+ case Cursor::EastWestResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZEWE);
+ break;
+ case Cursor::WestPanning:
+ m_platformCursor = loadCursorByName("panWestCursor", 7, 7);
+ break;
+ case Cursor::NorthEastSouthWestResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENESW);
+ break;
+ case Cursor::NorthWestSouthEastResize:
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENWSE);
+ break;
+ case Cursor::ColumnResize:
+ // FIXME: Windows does not have a standard column resize cursor <rdar://problem/5018591>
+ m_platformCursor = loadSharedCursor(0, IDC_SIZEWE);
+ break;
+ case Cursor::RowResize:
+ // FIXME: Windows does not have a standard row resize cursor <rdar://problem/5018591>
+ m_platformCursor = loadSharedCursor(0, IDC_SIZENS);
+ break;
+ case Cursor::VerticalText:
+ m_platformCursor = loadCursorByName("verticalTextCursor", 7, 7);
+ break;
+ case Cursor::Progress:
+ m_platformCursor = loadSharedCursor(0, IDC_APPSTARTING);
+ break;
+ case Cursor::NoDrop:
+ break;
+ case Cursor::NotAllowed:
+ m_platformCursor = loadSharedCursor(0, IDC_NO);
+ break;
+ case Cursor::ZoomIn:
+ m_platformCursor = loadCursorByName("zoomInCursor", 7, 7);
+ break;
+ case Cursor::ZoomOut:
+ m_platformCursor = loadCursorByName("zoomOutCursor", 7, 7);
+ break;
+ case Cursor::Custom:
+ m_platformCursor = createSharedCursor(m_image.get(), m_hotSpot);
+ break;
+ }
+}
+
+SharedCursor::~SharedCursor()
+{
+ DestroyIcon(m_nativeCursor);
+}
+
+Cursor::Cursor(const Cursor& other)
+ : m_type(other.m_type)
+ , m_image(other.m_image)
+ , m_hotSpot(other.m_hotSpot)
+ , m_platformCursor(other.m_platformCursor)
+{
+}
+
+Cursor& Cursor::operator=(const Cursor& other)
+{
+ m_type = other.m_type;
+ m_image = other.m_image;
+ m_hotSpot = other.m_hotSpot;
+ m_platformCursor = other.m_platformCursor;
+ return *this;
+}
+
+Cursor::~Cursor()
+{
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/DragDataWin.cpp b/Source/WebCore/platform/win/DragDataWin.cpp
new file mode 100644
index 0000000..56345e2
--- /dev/null
+++ b/Source/WebCore/platform/win/DragDataWin.cpp
@@ -0,0 +1,145 @@
+/*
+ * 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 "ClipboardUtilitiesWin.h"
+#include "DocumentFragment.h"
+#include "PlatformString.h"
+#include "Markup.h"
+#include "TextEncoding.h"
+#include <objidl.h>
+#include <shlwapi.h>
+#include <wininet.h>
+
+namespace WebCore {
+
+bool DragData::containsURL(FilenameConversionPolicy filenamePolicy) const
+{
+ return SUCCEEDED(m_platformDragData->QueryGetData(urlWFormat()))
+ || SUCCEEDED(m_platformDragData->QueryGetData(urlFormat()))
+ || (filenamePolicy == ConvertFilenames
+ && (SUCCEEDED(m_platformDragData->QueryGetData(filenameWFormat()))
+ || SUCCEEDED(m_platformDragData->QueryGetData(filenameFormat()))));
+}
+
+String DragData::asURL(FilenameConversionPolicy filenamePolicy, String* title) const
+{
+ bool success;
+ return getURL(m_platformDragData, filenamePolicy, 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, WTF_ARRAY_LENGTH(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/Source/WebCore/platform/win/DragImageCGWin.cpp b/Source/WebCore/platform/win/DragImageCGWin.cpp
new file mode 100644
index 0000000..bc45e22
--- /dev/null
+++ b/Source/WebCore/platform/win/DragImageCGWin.cpp
@@ -0,0 +1,162 @@
+/*
+ * 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 "BitmapInfo.h"
+#include "CachedImage.h"
+#include "GraphicsContextCG.h"
+#include "Image.h"
+#include "RetainPtr.h"
+
+#include <CoreGraphics/CoreGraphics.h>
+
+#include <windows.h>
+
+namespace WebCore {
+
+void deallocContext(CGContextRef target)
+{
+ CGContextRelease(target);
+}
+
+HBITMAP allocImage(HDC dc, IntSize size, CGContextRef *targetRef)
+{
+ BitmapInfo bmpInfo = BitmapInfo::create(size);
+
+ LPVOID bits;
+ HBITMAP hbmp = CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0);
+
+ if (!targetRef)
+ return hbmp;
+
+ CGContextRef bitmapContext = CGBitmapContextCreate(bits, bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, 8,
+ bmpInfo.bmiHeader.biWidth * 4, deviceRGBColorSpaceRef(),
+ kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);
+ 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);
+
+ CGContextRef bitmapContext = CGBitmapContextCreate(info.bmBits, info.bmWidth, info.bmHeight, 8,
+ info.bmWidthBytes, deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);
+ 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/Source/WebCore/platform/win/DragImageCairoWin.cpp b/Source/WebCore/platform/win/DragImageCairoWin.cpp
new file mode 100644
index 0000000..e356575
--- /dev/null
+++ b/Source/WebCore/platform/win/DragImageCairoWin.cpp
@@ -0,0 +1,191 @@
+/*
+ * 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 "BitmapInfo.h"
+#include "CachedImage.h"
+#include "GraphicsContext.h"
+#include "Image.h"
+#include "RetainPtr.h"
+
+#include <cairo-win32.h>
+#include "GraphicsContextPlatformPrivateCairo.h"
+
+#include <windows.h>
+
+extern "C" {
+typedef struct _cairo* CairoContextRef;
+}
+
+namespace WebCore {
+
+void deallocContext(CairoContextRef target)
+{
+ cairo_destroy(target);
+}
+
+HBITMAP allocImage(HDC dc, IntSize size, CairoContextRef* targetRef)
+{
+ BitmapInfo bmpInfo = BitmapInfo::create(size);
+
+ LPVOID bits;
+ HBITMAP hbmp = CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0);
+
+ // At this point, we have a Cairo surface that points to a Windows DIB. The DIB interprets
+ // with the opposite meaning of positive Y axis, so everything we draw into this cairo
+ // context is going to be upside down.
+ if (!targetRef)
+ return hbmp;
+
+ cairo_surface_t* bitmapContext = cairo_image_surface_create_for_data((unsigned char*)bits,
+ CAIRO_FORMAT_ARGB32,
+ bmpInfo.bmiHeader.biWidth,
+ bmpInfo.bmiHeader.biHeight,
+ bmpInfo.bmiHeader.biWidth * 4);
+
+ if (!bitmapContext) {
+ DeleteObject(hbmp);
+ return 0;
+ }
+
+ *targetRef = cairo_create (bitmapContext);
+ cairo_surface_destroy (bitmapContext);
+
+ // At this point, we have a Cairo surface that points to a Windows DIB. The DIB interprets
+ // with the opposite meaning of positive Y axis, so everything we draw into this cairo
+ // context is going to be upside down.
+ //
+ // So, we must invert the CTM for the context so that drawing commands will be flipped
+ // before they get written to the internal buffer.
+ cairo_matrix_t matrix;
+ cairo_matrix_init(&matrix, 1.0, 0.0, 0.0, -1.0, 0.0, size.height());
+ cairo_set_matrix(*targetRef, &matrix);
+
+ return hbmp;
+}
+
+static cairo_surface_t* createCairoContextFromBitmap(HBITMAP bitmap)
+{
+ BITMAP info;
+ GetObject(bitmap, sizeof(info), &info);
+ ASSERT(info.bmBitsPixel == 32);
+
+ // At this point, we have a Cairo surface that points to a Windows BITMAP. The BITMAP
+ // has the opposite meaning of positive Y axis, so everything we draw into this cairo
+ // context is going to be upside down.
+ return cairo_image_surface_create_for_data((unsigned char*)info.bmBits,
+ CAIRO_FORMAT_ARGB32,
+ info.bmWidth,
+ info.bmHeight,
+ info.bmWidthBytes);
+}
+
+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;
+
+ 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;
+
+ CairoContextRef targetContext;
+ hbmp = allocImage(dstDC, dstSize, &targetContext);
+ if (!hbmp)
+ goto exit;
+
+ cairo_surface_t* srcImage = createCairoContextFromBitmap(image);
+
+ // Scale the target surface to the new image size, and flip it
+ // so that when we set the srcImage as the surface it will draw
+ // right-side-up.
+ cairo_translate(targetContext, 0, dstSize.height());
+ cairo_scale(targetContext, scale.width(), -scale.height());
+ cairo_set_source_surface (targetContext, srcImage, 0.0, 0.0);
+
+ // Now we can paint and get the correct result
+ cairo_paint(targetContext);
+
+ cairo_surface_destroy (srcImage);
+ cairo_destroy(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);
+ if (!workingDC)
+ goto exit;
+
+ CairoContextRef drawContext = 0;
+ hbmp = allocImage(workingDC, img->size(), &drawContext);
+ if (!hbmp)
+ goto exit;
+
+ if (!drawContext) {
+ ::DeleteObject(hbmp);
+ hbmp = 0;
+ }
+
+ cairo_set_source_rgb (drawContext, 1.0, 0.0, 1.0);
+ cairo_fill_preserve (drawContext);
+
+ cairo_surface_t* srcImage = img->nativeImageForCurrentFrame();
+
+ // Draw the image.
+ cairo_set_source_surface(drawContext, srcImage, 0.0, 0.0);
+ cairo_paint(drawContext);
+
+ cairo_destroy (drawContext);
+
+exit:
+ if (workingDC)
+ DeleteDC(workingDC);
+ ReleaseDC(0, dc);
+ return hbmp;
+}
+
+}
diff --git a/Source/WebCore/platform/win/DragImageWin.cpp b/Source/WebCore/platform/win/DragImageWin.cpp
new file mode 100644
index 0000000..135e9d0
--- /dev/null
+++ b/Source/WebCore/platform/win/DragImageWin.cpp
@@ -0,0 +1,83 @@
+/*
+ * 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* image)
+{
+ if (!image)
+ return 0;
+
+ String filename = image->response().suggestedFilename();
+
+ SHFILEINFO shfi = {0};
+ if (FAILED(SHGetFileInfo(static_cast<LPCWSTR>(filename.charactersWithNullTermination()), FILE_ATTRIBUTE_NORMAL,
+ &shfi, sizeof(shfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES)))
+ return 0;
+
+ ICONINFO iconInfo;
+ if (!GetIconInfo(shfi.hIcon, &iconInfo)) {
+ DestroyIcon(shfi.hIcon);
+ return 0;
+ }
+
+ DestroyIcon(shfi.hIcon);
+ DeleteObject(iconInfo.hbmMask);
+
+ return iconInfo.hbmColor;
+}
+
+}
diff --git a/Source/WebCore/platform/win/EditorWin.cpp b/Source/WebCore/platform/win/EditorWin.cpp
new file mode 100644
index 0000000..f9505b3
--- /dev/null
+++ b/Source/WebCore/platform/win/EditorWin.cpp
@@ -0,0 +1,53 @@
+/*
+ * 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 "Frame.h"
+#include "htmlediting.h"
+#include "TextIterator.h"
+#include "visible_units.h"
+
+#include <windows.h>
+
+namespace WebCore {
+
+PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy, Frame* frame)
+{
+ COMPtr<IDataObject> clipboardData;
+#if !OS(WINCE)
+ if (!SUCCEEDED(OleGetClipboard(&clipboardData)))
+ clipboardData = 0;
+#endif
+
+ return ClipboardWin::create(Clipboard::CopyAndPaste, clipboardData.get(), policy, frame);
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/EventLoopWin.cpp b/Source/WebCore/platform/win/EventLoopWin.cpp
new file mode 100644
index 0000000..ece320f
--- /dev/null
+++ b/Source/WebCore/platform/win/EventLoopWin.cpp
@@ -0,0 +1,45 @@
+/*
+ * 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"
+
+#include <windows.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/Source/WebCore/platform/win/FileChooserWin.cpp b/Source/WebCore/platform/win/FileChooserWin.cpp
new file mode 100644
index 0000000..7d07b5d
--- /dev/null
+++ b/Source/WebCore/platform/win/FileChooserWin.cpp
@@ -0,0 +1,55 @@
+/*
+ * 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/Source/WebCore/platform/win/FileSystemWin.cpp b/Source/WebCore/platform/win/FileSystemWin.cpp
new file mode 100644
index 0000000..5ee3b8e
--- /dev/null
+++ b/Source/WebCore/platform/win/FileSystemWin.cpp
@@ -0,0 +1,307 @@
+/*
+ * 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 "NotImplemented.h"
+#include "PlatformString.h"
+#include <wtf/HashMap.h>
+#include <wtf/text/CString.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)
+{
+ return path.left(path.length() - pathGetFileName(path).length());
+}
+
+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(WTF_ARRAY_LENGTH(tempPath), tempPath);
+ if (tempPathLength <= 0 || tempPathLength > WTF_ARRAY_LENGTH(tempPath))
+ return CString();
+
+ HCRYPTPROV hCryptProv = 0;
+ if (!CryptAcquireContext(&hCryptProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
+ return CString();
+
+ 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 CString();
+
+ 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(WTF_ARRAY_LENGTH(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/Source/WebCore/platform/win/GDIObjectCounter.cpp b/Source/WebCore/platform/win/GDIObjectCounter.cpp
new file mode 100644
index 0000000..9a5adc7
--- /dev/null
+++ b/Source/WebCore/platform/win/GDIObjectCounter.cpp
@@ -0,0 +1,74 @@
+/*
+ * 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 "Logging.h"
+#include <wtf/text/CString.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/Source/WebCore/platform/win/GDIObjectCounter.h b/Source/WebCore/platform/win/GDIObjectCounter.h
new file mode 100644
index 0000000..9b9bd12
--- /dev/null
+++ b/Source/WebCore/platform/win/GDIObjectCounter.h
@@ -0,0 +1,63 @@
+/*
+ * 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/Source/WebCore/platform/win/KeyEventWin.cpp b/Source/WebCore/platform/win/KeyEventWin.cpp
new file mode 100644
index 0000000..43fb0a4
--- /dev/null
+++ b/Source/WebCore/platform/win/KeyEventWin.cpp
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2006, 2007, 2010 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;
+}
+
+void PlatformKeyboardEvent::getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey)
+{
+ shiftKey = GetKeyState(VK_SHIFT) & HIGH_BIT_MASK_SHORT;
+ ctrlKey = GetKeyState(VK_CONTROL) & HIGH_BIT_MASK_SHORT;
+ altKey = GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT;
+ metaKey = false;
+}
+
+}
diff --git a/Source/WebCore/platform/win/LanguageWin.cpp b/Source/WebCore/platform/win/LanguageWin.cpp
new file mode 100644
index 0000000..cafda5d
--- /dev/null
+++ b/Source/WebCore/platform/win/LanguageWin.cpp
@@ -0,0 +1,68 @@
+/*
+ * 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 <wtf/text/StringConcatenate.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;
+ UChar* localeNameBuf;
+ String localeName = String::createUninitialized(localeChars, localeNameBuf);
+ localeChars = GetLocaleInfo(langID, localeType, localeNameBuf, localeChars);
+ if (!localeChars)
+ return fallback;
+ if (localeName.isEmpty())
+ return fallback;
+
+ localeName.truncate(localeName.length() - 1);
+ return localeName;
+}
+
+String platformDefaultLanguage()
+{
+ 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 = makeString(languageName, '-', countryName);
+
+ return computedDefaultLanguage;
+}
+
+}
diff --git a/Source/WebCore/platform/win/LoggingWin.cpp b/Source/WebCore/platform/win/LoggingWin.cpp
new file mode 100644
index 0000000..fe237e5
--- /dev/null
+++ b/Source/WebCore/platform/win/LoggingWin.cpp
@@ -0,0 +1,100 @@
+/*
+ * 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 "Logging.h"
+
+#include "PlatformString.h"
+#include <wtf/OwnArrayPtr.h>
+
+namespace WebCore {
+
+static inline void initializeWithUserDefault(WTFLogChannel& channel)
+{
+ DWORD length = GetEnvironmentVariableA(channel.defaultName, 0, 0);
+ if (!length)
+ return;
+
+ OwnArrayPtr<char> buffer(new char[length]);
+
+ if (!GetEnvironmentVariableA(channel.defaultName, buffer.get(), length))
+ return;
+
+ String variableValue(buffer.get());
+
+ static const String& hexadecimalPrefix = *new String("0x");
+ if (variableValue.length() < 3 || !variableValue.startsWith(hexadecimalPrefix, false)) {
+ LOG_ERROR("Unable to parse hex value for %s (%s), logging is off", channel.defaultName, buffer.get());
+ return;
+ }
+
+ String unprefixedValue = variableValue.substring(2);
+
+ // Now parse the unprefixed string as a hexadecimal number.
+ bool parsedSuccessfully = false;
+ unsigned logLevel = unprefixedValue.toUIntStrict(&parsedSuccessfully, 16);
+
+ if (!parsedSuccessfully) {
+ LOG_ERROR("Unable to parse hex value for %s (%s), logging is off", channel.defaultName, buffer.get());
+ return;
+ }
+
+ if ((logLevel & channel.mask) == channel.mask)
+ channel.state = WTFLogChannelOn;
+ else
+ channel.state = WTFLogChannelOff;
+}
+
+void InitializeLoggingChannelsIfNecessary()
+{
+ static bool haveInitializedLoggingChannels = false;
+ if (haveInitializedLoggingChannels)
+ return;
+ haveInitializedLoggingChannels = true;
+
+ initializeWithUserDefault(LogNotYetImplemented);
+ initializeWithUserDefault(LogFrames);
+ initializeWithUserDefault(LogLoading);
+ initializeWithUserDefault(LogPopupBlocking);
+ initializeWithUserDefault(LogEvents);
+ initializeWithUserDefault(LogEditing);
+ initializeWithUserDefault(LogLiveConnect);
+ initializeWithUserDefault(LogIconDatabase);
+ initializeWithUserDefault(LogSQLDatabase);
+ initializeWithUserDefault(LogSpellingAndGrammar);
+ initializeWithUserDefault(LogBackForward);
+ initializeWithUserDefault(LogHistory);
+ initializeWithUserDefault(LogPageCache);
+ initializeWithUserDefault(LogPlatformLeaks);
+ initializeWithUserDefault(LogNetwork);
+ initializeWithUserDefault(LogFTP);
+ initializeWithUserDefault(LogThreading);
+ initializeWithUserDefault(LogStorageAPI);
+ initializeWithUserDefault(LogMedia);
+ initializeWithUserDefault(LogPlugins);
+ initializeWithUserDefault(LogArchives);
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp b/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp
new file mode 100644
index 0000000..980742a
--- /dev/null
+++ b/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp
@@ -0,0 +1,111 @@
+/*
+ * 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
+{
+
+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 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");
+ mimetypeMap.add("wml", "text/vnd.wap.wml");
+ mimetypeMap.add("wmlc", "application/vnd.wap.wmlc");
+ }
+ String result = mimetypeMap.get(ext);
+ if (result.isEmpty()) {
+ result = mimeTypeForExtension(ext);
+ if (!result.isEmpty())
+ mimetypeMap.add(ext, result);
+ }
+ return result;
+}
+
+bool MIMETypeRegistry::isApplicationPluginMIMEType(const String&)
+{
+ return false;
+}
+
+}
diff --git a/Source/WebCore/platform/win/PasteboardWin.cpp b/Source/WebCore/platform/win/PasteboardWin.cpp
new file mode 100644
index 0000000..4b20adb
--- /dev/null
+++ b/Source/WebCore/platform/win/PasteboardWin.cpp
@@ -0,0 +1,340 @@
+/*
+ * 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 "BitmapInfo.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 "Page.h"
+#include "Range.h"
+#include "RenderImage.h"
+#include "TextEncoding.h"
+#include "WebCoreInstanceHandle.h"
+#include "markup.h"
+#include <wtf/text/CString.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;
+
+ 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_DESTROY:
+ break;
+#if !OS(WINCE)
+ case WM_DRAWCLIPBOARD:
+ break;
+ case WM_CHANGECBCHAIN:
+ break;
+#endif
+ default:
+ lresult = DefWindowProc(hWnd, message, wParam, lParam);
+ break;
+ }
+ return lresult;
+}
+
+Pasteboard* Pasteboard::generalPasteboard()
+{
+ static Pasteboard* pasteboard = new Pasteboard;
+ return pasteboard;
+}
+
+Pasteboard::Pasteboard()
+{
+ HWND hWndParent = 0;
+#if !OS(WINCE)
+ hWndParent = HWND_MESSAGE;
+#endif
+
+ WNDCLASS wc;
+ memset(&wc, 0, sizeof(WNDCLASS));
+ wc.lpfnWndProc = PasteboardOwnerWndProc;
+ wc.hInstance = WebCore::instanceHandle();
+ wc.lpszClassName = L"PasteboardOwnerWindowClass";
+ RegisterClass(&wc);
+
+ m_owner = ::CreateWindow(L"PasteboardOwnerWindowClass", L"PasteboardOwnerWindow", 0, 0, 0, 0, 0,
+ hWndParent, 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;
+ markupToCFHTML(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->editor()->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, 0);
+ ::CloseClipboard();
+ }
+
+ }
+}
+
+void Pasteboard::writePlainText(const String& text)
+{
+ clear();
+
+ // Put plain string on the pasteboard. CF_UNICODETEXT covers CF_TEXT as well
+ String str = text;
+ replaceNewlinesWithWindowsStyleNewlines(str);
+ if (::OpenClipboard(m_owner)) {
+ HGLOBAL cbData = createGlobalData(str);
+ if (!::SetClipboardData(CF_UNICODETEXT, cbData))
+ ::GlobalFree(cbData);
+ ::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;
+ markupToCFHTML(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 = toRenderImage(node->renderer());
+ CachedImage* cachedImage = renderer->cachedImage();
+ if (!cachedImage || cachedImage->errorOccurred())
+ return;
+ Image* image = cachedImage->image();
+ ASSERT(image);
+
+ clear();
+
+ HDC dc = GetDC(0);
+ HDC compatibleDC = CreateCompatibleDC(0);
+ HDC sourceDC = CreateCompatibleDC(0);
+ OwnPtr<HBITMAP> resultBitmap(CreateCompatibleBitmap(dc, image->width(), image->height()));
+ HGDIOBJ oldBitmap = SelectObject(compatibleDC, resultBitmap.get());
+
+ BitmapInfo bmInfo = BitmapInfo::create(image->size());
+
+ HBITMAP coreBitmap = CreateDIBSection(dc, &bmInfo, DIB_RGB_COLORS, 0, 0, 0);
+ HGDIOBJ oldSource = SelectObject(sourceDC, coreBitmap);
+ image->getHBITMAP(coreBitmap);
+
+ BitBlt(compatibleDC, 0, 0, image->width(), image->height(), sourceDC, 0, 0, SRCCOPY);
+
+ SelectObject(sourceDC, oldSource);
+ DeleteObject(coreBitmap);
+
+ SelectObject(compatibleDC, oldBitmap);
+ DeleteDC(sourceDC);
+ DeleteDC(compatibleDC);
+ ReleaseDC(0, dc);
+
+ if (::OpenClipboard(m_owner)) {
+ ::SetClipboardData(CF_BITMAP, resultBitmap.leakPtr());
+ ::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 = static_cast<UChar*>(GlobalLock(cbData));
+ String fromClipboard(buffer);
+ GlobalUnlock(cbData);
+ ::CloseClipboard();
+ return fromClipboard;
+ }
+ ::CloseClipboard();
+ }
+
+ if (::IsClipboardFormatAvailable(CF_TEXT) && ::OpenClipboard(m_owner)) {
+ HANDLE cbData = ::GetClipboardData(CF_TEXT);
+ if (cbData) {
+ char* buffer = static_cast<char*>(GlobalLock(cbData));
+ String fromClipboard(buffer);
+ GlobalUnlock(cbData);
+ ::CloseClipboard();
+ return fromClipboard;
+ }
+ ::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 cfhtml(UTF8Encoding().decode(static_cast<char*>(GlobalLock(cbData)), dataSize));
+ GlobalUnlock(cbData);
+ ::CloseClipboard();
+
+ PassRefPtr<DocumentFragment> fragment = fragmentFromCFHTML(frame->document(), cfhtml);
+ 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 = static_cast<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 = static_cast<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/Source/WebCore/platform/win/PlatformMouseEventWin.cpp b/Source/WebCore/platform/win/PlatformMouseEventWin.cpp
new file mode 100644
index 0000000..a1cf5aa
--- /dev/null
+++ b/Source/WebCore/platform/win/PlatformMouseEventWin.cpp
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2008 Torch Mobile Inc.
+ *
+ * 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 "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;
+
+#if !OS(WINCE)
+ case WM_MOUSELEAVE:
+#endif
+ 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 didActivateWebView)
+ : 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_didActivateWebView(didActivateWebView)
+ , 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:
+#if !OS(WINCE)
+ case WM_MOUSELEAVE:
+#endif
+ 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/Source/WebCore/platform/win/PlatformScreenWin.cpp b/Source/WebCore/platform/win/PlatformScreenWin.cpp
new file mode 100644
index 0000000..21fa10d
--- /dev/null
+++ b/Source/WebCore/platform/win/PlatformScreenWin.cpp
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2009 Torch Mobile, Inc.
+ *
+ * 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 "HostWindow.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()->platformPageClient() : 0;
+ HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY);
+
+ MONITORINFOEX monitorInfo;
+ monitorInfo.cbSize = sizeof(MONITORINFOEX);
+ GetMonitorInfo(monitor, &monitorInfo);
+ return monitorInfo;
+}
+
+static DEVMODE deviceInfoForWidget(Widget* widget)
+{
+ DEVMODE deviceInfo;
+ deviceInfo.dmSize = sizeof(DEVMODE);
+ deviceInfo.dmDriverExtra = 0;
+#if OS(WINCE)
+ if (!EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &deviceInfo))
+ deviceInfo.dmBitsPerPel = 16;
+#else
+ MONITORINFOEX monitorInfo = monitorInfoForWidget(widget);
+ EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &deviceInfo);
+#endif
+
+ return deviceInfo;
+}
+
+int screenDepth(Widget* widget)
+{
+ DEVMODE deviceInfo = deviceInfoForWidget(widget);
+ if (deviceInfo.dmBitsPerPel == 32) {
+ // Some video drivers return 32, but this function is supposed to ignore the alpha
+ // component. See <http://webkit.org/b/42972>.
+ return 24;
+ }
+ return deviceInfo.dmBitsPerPel;
+}
+
+int screenDepthPerComponent(Widget* widget)
+{
+ // FIXME: Assumes RGB -- not sure if this is right.
+ return screenDepth(widget) / 3;
+}
+
+bool screenIsMonochrome(Widget* widget)
+{
+#if OS(WINCE)
+ // EnumDisplaySettings doesn't set dmColor in DEVMODE.
+ return false;
+#else
+ DEVMODE deviceInfo = deviceInfoForWidget(widget);
+ return deviceInfo.dmColor == DMCOLOR_MONOCHROME;
+#endif
+}
+
+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/Source/WebCore/platform/win/PopupMenuWin.cpp b/Source/WebCore/platform/win/PopupMenuWin.cpp
new file mode 100644
index 0000000..e86aef9
--- /dev/null
+++ b/Source/WebCore/platform/win/PopupMenuWin.cpp
@@ -0,0 +1,1017 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2009 Torch Mobile Inc.
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "PopupMenuWin.h"
+
+#include "BitmapInfo.h"
+#include "Document.h"
+#include "FloatRect.h"
+#include "FontSelector.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "GraphicsContext.h"
+#include "HTMLNames.h"
+#include "HostWindow.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 "WebCoreInstanceHandle.h"
+#include <tchar.h>
+#include <windows.h>
+#include <windowsx.h>
+#if OS(WINCE)
+#include <ResDefCE.h>
+#define MAKEPOINTS(l) (*((POINTS FAR *)&(l)))
+#endif
+
+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;
+
+const int optionSpacingMiddle = 1;
+const int popupWindowBorderWidth = 1;
+
+static LPCTSTR kPopupWindowClassName = _T("PopupWindowClass");
+
+// This is used from within our custom message pump when we want to send a
+// message to the web view and not have our message stolen and sent to
+// the popup window.
+static const UINT WM_HOST_WINDOW_FIRST = WM_USER;
+static const UINT WM_HOST_WINDOW_CHAR = WM_USER + WM_CHAR;
+static const UINT WM_HOST_WINDOW_MOUSEMOVE = WM_USER + WM_MOUSEMOVE;
+
+// FIXME: Remove this as soon as practical.
+static inline bool isASCIIPrintable(unsigned c)
+{
+ return c >= 0x20 && c <= 0x7E;
+}
+
+static void translatePoint(LPARAM& lParam, HWND from, HWND to)
+{
+ POINT pt;
+ pt.x = (short)GET_X_LPARAM(lParam);
+ pt.y = (short)GET_Y_LPARAM(lParam);
+ ::MapWindowPoints(from, to, &pt, 1);
+ lParam = MAKELPARAM(pt.x, pt.y);
+}
+
+PopupMenuWin::PopupMenuWin(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)
+ , m_showPopup(false)
+{
+}
+
+PopupMenuWin::~PopupMenuWin()
+{
+ if (m_bmp)
+ ::DeleteObject(m_bmp);
+ if (m_DC)
+ ::DeleteDC(m_DC);
+ if (m_popup)
+ ::DestroyWindow(m_popup);
+ if (m_scrollbar)
+ m_scrollbar->setParent(0);
+}
+
+void PopupMenuWin::disconnectClient()
+{
+ m_popupClient = 0;
+}
+
+LPCTSTR PopupMenuWin::popupClassName()
+{
+ return kPopupWindowClassName;
+}
+
+void PopupMenuWin::show(const IntRect& r, FrameView* view, int index)
+{
+ calculatePositionAndSize(r, view);
+ if (clientRect().isEmpty())
+ return;
+
+ HWND hostWindow = view->hostWindow()->platformPageClient();
+
+ if (!m_scrollbar && visibleItems() < client()->listSize()) {
+ // We need a scroll bar
+ m_scrollbar = client()->createScrollbar(this, VerticalScrollbar, SmallScrollbar);
+ m_scrollbar->styleChanged();
+ }
+
+ if (!m_popup) {
+ registerClass();
+
+ DWORD exStyle = WS_EX_LTRREADING;
+
+ m_popup = ::CreateWindowEx(exStyle, kPopupWindowClassName, _T("PopupMenu"),
+ WS_POPUP | WS_BORDER,
+ m_windowRect.x(), m_windowRect.y(), m_windowRect.width(), m_windowRect.height(),
+ hostWindow, 0, WebCore::instanceHandle(), this);
+
+ if (!m_popup)
+ return;
+ } else {
+ // We need to reposition the popup window.
+ ::MoveWindow(m_popup, m_windowRect.x(), m_windowRect.y(), m_windowRect.width(), m_windowRect.height(), false);
+ }
+
+ // 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;
+#if !OS(WINCE)
+ ::SystemParametersInfo(SPI_GETCOMBOBOXANIMATION, 0, &shouldAnimate, 0);
+
+ if (shouldAnimate) {
+ RECT viewRect = {0};
+ ::GetWindowRect(hostWindow, &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 + view->contentsToWindow(r.location()).y()) ? AW_VER_NEGATIVE : AW_VER_POSITIVE;
+
+ ::AnimateWindow(m_popup, defaultAnimationDuration, AW_SLIDE | slideDirection);
+ }
+ } else
+#endif
+ ::ShowWindow(m_popup, SW_SHOWNOACTIVATE);
+
+ if (client()) {
+ int index = client()->selectedIndex();
+ if (index >= 0)
+ setFocusedIndex(index);
+ }
+
+ m_showPopup = true;
+
+ // Protect the popup menu in case its owner is destroyed while we're running the message pump.
+ RefPtr<PopupMenu> protect(this);
+
+ ::SetCapture(hostWindow);
+
+ MSG msg;
+ HWND activeWindow;
+
+ while (::GetMessage(&msg, 0, 0, 0)) {
+ switch (msg.message) {
+ case WM_HOST_WINDOW_MOUSEMOVE:
+ case WM_HOST_WINDOW_CHAR:
+ if (msg.hwnd == m_popup) {
+ // This message should be sent to the host window.
+ msg.hwnd = hostWindow;
+ msg.message -= WM_HOST_WINDOW_FIRST;
+ }
+ break;
+
+ // Steal mouse messages.
+#if !OS(WINCE)
+ case WM_NCMOUSEMOVE:
+ case WM_NCLBUTTONDOWN:
+ case WM_NCLBUTTONUP:
+ case WM_NCLBUTTONDBLCLK:
+ case WM_NCRBUTTONDOWN:
+ case WM_NCRBUTTONUP:
+ case WM_NCRBUTTONDBLCLK:
+ case WM_NCMBUTTONDOWN:
+ case WM_NCMBUTTONUP:
+ case WM_NCMBUTTONDBLCLK:
+#endif
+ case WM_MOUSEWHEEL:
+ msg.hwnd = m_popup;
+ break;
+
+ // These mouse messages use client coordinates so we need to convert them.
+ case WM_MOUSEMOVE:
+ case WM_LBUTTONDOWN:
+ case WM_LBUTTONUP:
+ case WM_LBUTTONDBLCLK:
+ case WM_RBUTTONDOWN:
+ case WM_RBUTTONUP:
+ case WM_RBUTTONDBLCLK:
+ case WM_MBUTTONDOWN:
+ case WM_MBUTTONUP:
+ case WM_MBUTTONDBLCLK: {
+ // Translate the coordinate.
+ translatePoint(msg.lParam, msg.hwnd, m_popup);
+
+ msg.hwnd = m_popup;
+ break;
+ }
+
+ // Steal all keyboard messages.
+ case WM_KEYDOWN:
+ case WM_KEYUP:
+ case WM_CHAR:
+ case WM_DEADCHAR:
+ case WM_SYSKEYUP:
+ case WM_SYSCHAR:
+ case WM_SYSDEADCHAR:
+ msg.hwnd = m_popup;
+ break;
+ }
+
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
+
+ if (!m_popupClient)
+ break;
+
+ if (!m_showPopup)
+ break;
+ activeWindow = ::GetActiveWindow();
+ if (activeWindow != hostWindow && !::IsChild(activeWindow, hostWindow))
+ break;
+ if (::GetCapture() != hostWindow)
+ break;
+ }
+
+ if (::GetCapture() == hostWindow)
+ ::ReleaseCapture();
+
+ // We're done, hide the popup if necessary.
+ hide();
+}
+
+void PopupMenuWin::hide()
+{
+ if (!m_showPopup)
+ return;
+
+ m_showPopup = false;
+
+ ::ShowWindow(m_popup, SW_HIDE);
+
+ if (client())
+ client()->popupDidHide();
+
+ // Post a WM_NULL message to wake up the message pump if necessary.
+ ::PostMessage(m_popup, WM_NULL, 0, 0);
+}
+
+void PopupMenuWin::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()->platformPageClient(), &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
+ popupWidth += max(0, client()->clientPaddingRight() - 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 PopupMenuWin::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 PopupMenuWin::visibleItems() const
+{
+ return clientRect().height() / m_itemHeight;
+}
+
+int PopupMenuWin::listIndexAtPoint(const IntPoint& point) const
+{
+ return m_scrollOffset + point.y() / m_itemHeight;
+}
+
+int PopupMenuWin::focusedIndex() const
+{
+ return m_focusedIndex;
+}
+
+void PopupMenuWin::focusFirst()
+{
+ if (!client())
+ return;
+
+ int size = client()->listSize();
+
+ for (int i = 0; i < size; ++i)
+ if (client()->itemIsEnabled(i)) {
+ setFocusedIndex(i);
+ break;
+ }
+}
+
+void PopupMenuWin::focusLast()
+{
+ if (!client())
+ return;
+
+ int size = client()->listSize();
+
+ for (int i = size - 1; i > 0; --i)
+ if (client()->itemIsEnabled(i)) {
+ setFocusedIndex(i);
+ break;
+ }
+}
+
+bool PopupMenuWin::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 PopupMenuWin::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 PopupMenuWin::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 PopupMenuWin::clientRect() const
+{
+ IntRect clientRect = m_windowRect;
+ clientRect.inflate(-popupWindowBorderWidth);
+ clientRect.setLocation(IntPoint(0, 0));
+ return clientRect;
+}
+
+void PopupMenuWin::incrementWheelDelta(int delta)
+{
+ m_wheelDelta += delta;
+}
+
+void PopupMenuWin::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 PopupMenuWin::scrollToRevealSelection()
+{
+ if (!m_scrollbar)
+ return false;
+
+ int index = focusedIndex();
+
+ if (index < m_scrollOffset) {
+ m_scrollbar->setValue(index, Scrollbar::NotFromScrollAnimator);
+ return true;
+ }
+
+ if (index >= m_scrollOffset + visibleItems()) {
+ m_scrollbar->setValue(index - visibleItems() + 1, Scrollbar::NotFromScrollAnimator);
+ return true;
+ }
+
+ return false;
+}
+
+void PopupMenuWin::updateFromElement()
+{
+ if (!m_popup)
+ return;
+
+ m_focusedIndex = client()->selectedIndex();
+
+ ::InvalidateRect(m_popup, 0, TRUE);
+ if (!scrollToRevealSelection())
+ ::UpdateWindow(m_popup);
+}
+
+const int separatorPadding = 4;
+const int separatorHeight = 1;
+void PopupMenuWin::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) {
+#if OS(WINCE)
+ BitmapInfo bitmapInfo = BitmapInfo::createBottomUp(clientRect().size(), BitmapInfo::BitCount16);
+#else
+ BitmapInfo bitmapInfo = BitmapInfo::createBottomUp(clientRect().size());
+#endif
+ 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 = RenderTheme::defaultTheme()->activeListBoxSelectionBackgroundColor();
+ optionTextColor = RenderTheme::defaultTheme()->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, ColorSpaceDeviceRGB);
+
+ if (client()->itemIsSeparator(index)) {
+ IntRect separatorRect(itemRect.x() + separatorPadding, itemRect.y() + (itemRect.height() - separatorHeight) / 2, itemRect.width() - 2 * separatorPadding, separatorHeight);
+ context.fillRect(separatorRect, optionTextColor, ColorSpaceDeviceRGB);
+ 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, ColorSpaceDeviceRGB);
+
+ 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());
+ }
+
+ // Draw the item text
+ if (itemStyle.isVisible()) {
+ int textX = max(0, client()->clientPaddingLeft() - client()->clientInsetLeft());
+ if (RenderTheme::defaultTheme()->popupOptionSupportsTextIndent() && itemStyle.textDirection() == LTR)
+ textX += itemStyle.textIndent().calcMinValue(itemRect.width());
+ int textY = itemRect.y() + itemFont.ascent() + (itemRect.height() - itemFont.height()) / 2;
+ context.drawBidiText(itemFont, textRun, IntPoint(textX, textY));
+ }
+ }
+
+ if (m_scrollbar)
+ m_scrollbar->paint(&context, damageRect);
+
+ HDC localDC = hdc ? hdc : ::GetDC(m_popup);
+
+ ::BitBlt(localDC, damageRect.x(), damageRect.y(), damageRect.width(), damageRect.height(), m_DC, damageRect.x(), damageRect.y(), SRCCOPY);
+
+ if (!hdc)
+ ::ReleaseDC(m_popup, localDC);
+}
+
+int PopupMenuWin::scrollSize(ScrollbarOrientation orientation) const
+{
+ return ((orientation == VerticalScrollbar) && m_scrollbar) ? (m_scrollbar->totalSize() - m_scrollbar->visibleSize()) : 0;
+}
+
+void PopupMenuWin::setScrollOffsetFromAnimation(const IntPoint& offset)
+{
+ if (m_scrollbar)
+ m_scrollbar->setValue(offset.y(), Scrollbar::FromScrollAnimator);
+}
+
+void PopupMenuWin::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 PopupMenuWin::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect)
+{
+ IntRect scrollRect = rect;
+ scrollRect.move(scrollbar->x(), scrollbar->y());
+ RECT r = scrollRect;
+ ::InvalidateRect(m_popup, &r, false);
+}
+
+void PopupMenuWin::registerClass()
+{
+ static bool haveRegisteredWindowClass = false;
+
+ if (haveRegisteredWindowClass)
+ return;
+
+#if OS(WINCE)
+ WNDCLASS wcex;
+#else
+ WNDCLASSEX wcex;
+ wcex.cbSize = sizeof(WNDCLASSEX);
+ wcex.hIconSm = 0;
+ wcex.style = CS_DROPSHADOW;
+#endif
+
+ wcex.lpfnWndProc = PopupMenuWndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = sizeof(PopupMenu*); // For the PopupMenu pointer
+ wcex.hInstance = WebCore::instanceHandle();
+ wcex.hIcon = 0;
+ wcex.hCursor = LoadCursor(0, IDC_ARROW);
+ wcex.hbrBackground = 0;
+ wcex.lpszMenuName = 0;
+ wcex.lpszClassName = kPopupWindowClassName;
+
+ haveRegisteredWindowClass = true;
+
+#if OS(WINCE)
+ RegisterClass(&wcex);
+#else
+ RegisterClassEx(&wcex);
+#endif
+}
+
+
+LRESULT CALLBACK PopupMenuWin::PopupMenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+#if OS(WINCE)
+ LONG longPtr = GetWindowLong(hWnd, 0);
+#else
+ LONG_PTR longPtr = GetWindowLongPtr(hWnd, 0);
+#endif
+
+ if (PopupMenuWin* popup = reinterpret_cast<PopupMenuWin*>(longPtr))
+ return popup->wndProc(hWnd, message, wParam, lParam);
+
+ if (message == WM_CREATE) {
+ LPCREATESTRUCT createStruct = reinterpret_cast<LPCREATESTRUCT>(lParam);
+
+ // Associate the PopupMenu with the window.
+#if OS(WINCE)
+ ::SetWindowLong(hWnd, 0, (LONG)createStruct->lpCreateParams);
+#else
+ ::SetWindowLongPtr(hWnd, 0, (LONG_PTR)createStruct->lpCreateParams);
+#endif
+ return 0;
+ }
+
+ return ::DefWindowProc(hWnd, message, wParam, lParam);
+}
+
+const int smoothScrollAnimationDuration = 5000;
+
+LRESULT PopupMenuWin::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ LRESULT lResult = 0;
+
+ switch (message) {
+#if !OS(WINCE)
+ case WM_MOUSEACTIVATE:
+ return MA_NOACTIVATE;
+#endif
+ case WM_SIZE: {
+ if (!scrollbar())
+ break;
+
+ IntSize size(LOWORD(lParam), HIWORD(lParam));
+ scrollbar()->setFrameRect(IntRect(size.width() - scrollbar()->width(), 0, scrollbar()->width(), size.height()));
+
+ int visibleItems = this->visibleItems();
+ scrollbar()->setEnabled(visibleItems < client()->listSize());
+ scrollbar()->setSteps(1, max(1, visibleItems - 1));
+ scrollbar()->setProportion(visibleItems, client()->listSize());
+
+ break;
+ }
+ case WM_KEYDOWN:
+ if (!client())
+ break;
+
+ lResult = 0;
+ switch (LOWORD(wParam)) {
+ case VK_DOWN:
+ case VK_RIGHT:
+ down();
+ break;
+ case VK_UP:
+ case VK_LEFT:
+ up();
+ break;
+ case VK_HOME:
+ focusFirst();
+ break;
+ case VK_END:
+ focusLast();
+ break;
+ case VK_PRIOR:
+ if (focusedIndex() != scrollOffset()) {
+ // Set the selection to the first visible item
+ int firstVisibleItem = scrollOffset();
+ up(focusedIndex() - firstVisibleItem);
+ } else {
+ // The first visible item is selected, so move the selection back one page
+ up(visibleItems());
+ }
+ break;
+ case VK_NEXT: {
+ int lastVisibleItem = scrollOffset() + visibleItems() - 1;
+ if (focusedIndex() != lastVisibleItem) {
+ // Set the selection to the last visible item
+ down(lastVisibleItem - focusedIndex());
+ } else {
+ // The last visible item is selected, so move the selection forward one page
+ down(visibleItems());
+ }
+ break;
+ }
+ case VK_TAB:
+ ::SendMessage(client()->hostWindow()->platformPageClient(), message, wParam, lParam);
+ hide();
+ break;
+ case VK_ESCAPE:
+ hide();
+ break;
+ default:
+ if (isASCIIPrintable(wParam))
+ // Send the keydown to the WebView so it can be used for type-to-select.
+ // Since we know that the virtual key is ASCII printable, it's OK to convert this to
+ // a WM_CHAR message. (We don't want to call TranslateMessage because that will post a
+ // WM_CHAR message that will be stolen and redirected to the popup HWND.
+ ::PostMessage(m_popup, WM_HOST_WINDOW_CHAR, wParam, lParam);
+ else
+ lResult = 1;
+ break;
+ }
+ break;
+ case WM_CHAR: {
+ if (!client())
+ break;
+
+ lResult = 0;
+ int index;
+ switch (wParam) {
+ case 0x0D: // Enter/Return
+ hide();
+ index = focusedIndex();
+ ASSERT(index >= 0);
+ client()->valueChanged(index);
+ break;
+ case 0x1B: // Escape
+ hide();
+ break;
+ case 0x09: // TAB
+ case 0x08: // Backspace
+ case 0x0A: // Linefeed
+ default: // Character
+ lResult = 1;
+ break;
+ }
+ break;
+ }
+ case WM_MOUSEMOVE: {
+ IntPoint mousePoint(MAKEPOINTS(lParam));
+ if (scrollbar()) {
+ IntRect scrollBarRect = scrollbar()->frameRect();
+ if (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()));
+ scrollbar()->mouseMoved(event);
+ break;
+ }
+ }
+
+ BOOL shouldHotTrack = FALSE;
+#if !OS(WINCE)
+ ::SystemParametersInfo(SPI_GETHOTTRACKING, 0, &shouldHotTrack, 0);
+#endif
+
+ RECT bounds;
+ GetClientRect(popupHandle(), &bounds);
+ if (!::PtInRect(&bounds, mousePoint) && !(wParam & MK_LBUTTON) && client()) {
+ // When the mouse is not inside the popup menu and the left button isn't down, just
+ // repost the message to the web view.
+
+ // Translate the coordinate.
+ translatePoint(lParam, m_popup, client()->hostWindow()->platformPageClient());
+
+ ::PostMessage(m_popup, WM_HOST_WINDOW_MOUSEMOVE, wParam, lParam);
+ break;
+ }
+
+ if ((shouldHotTrack || wParam & MK_LBUTTON) && ::PtInRect(&bounds, mousePoint))
+ setFocusedIndex(listIndexAtPoint(mousePoint), true);
+
+ break;
+ }
+ case WM_LBUTTONDOWN: {
+ IntPoint mousePoint(MAKEPOINTS(lParam));
+ if (scrollbar()) {
+ IntRect scrollBarRect = 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()));
+ scrollbar()->mouseDown(event);
+ setScrollbarCapturingMouse(true);
+ break;
+ }
+ }
+
+ // If the mouse is inside the window, update the focused index. Otherwise,
+ // hide the popup.
+ RECT bounds;
+ GetClientRect(m_popup, &bounds);
+ if (::PtInRect(&bounds, mousePoint))
+ setFocusedIndex(listIndexAtPoint(mousePoint), true);
+ else
+ hide();
+ break;
+ }
+ case WM_LBUTTONUP: {
+ IntPoint mousePoint(MAKEPOINTS(lParam));
+ if (scrollbar()) {
+ IntRect scrollBarRect = scrollbar()->frameRect();
+ if (scrollbarCapturingMouse() || scrollBarRect.contains(mousePoint)) {
+ 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()));
+ 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(popupHandle(), &r, TRUE);
+ break;
+ }
+ }
+ // Only hide the popup if the mouse is inside the popup window.
+ RECT bounds;
+ GetClientRect(popupHandle(), &bounds);
+ if (client() && ::PtInRect(&bounds, mousePoint)) {
+ hide();
+ int index = focusedIndex();
+ if (index >= 0)
+ client()->valueChanged(index);
+ }
+ break;
+ }
+
+ case WM_MOUSEWHEEL: {
+ if (!scrollbar())
+ break;
+
+ int i = 0;
+ for (incrementWheelDelta(GET_WHEEL_DELTA_WPARAM(wParam)); abs(wheelDelta()) >= WHEEL_DELTA; reduceWheelDelta(WHEEL_DELTA)) {
+ if (wheelDelta() > 0)
+ ++i;
+ else
+ --i;
+ }
+ scrollbar()->scroll(i > 0 ? ScrollUp : ScrollDown, ScrollByLine, abs(i));
+ break;
+ }
+
+ case WM_PAINT: {
+ PAINTSTRUCT paintInfo;
+ ::BeginPaint(popupHandle(), &paintInfo);
+ paint(paintInfo.rcPaint, paintInfo.hdc);
+ ::EndPaint(popupHandle(), &paintInfo);
+ lResult = 0;
+ break;
+ }
+#if !OS(WINCE)
+ case WM_PRINTCLIENT:
+ paint(clientRect(), (HDC)wParam);
+ break;
+#endif
+ default:
+ lResult = DefWindowProc(hWnd, message, wParam, lParam);
+ }
+
+ return lResult;
+}
+
+}
diff --git a/Source/WebCore/platform/win/PopupMenuWin.h b/Source/WebCore/platform/win/PopupMenuWin.h
new file mode 100644
index 0000000..bfec7aa
--- /dev/null
+++ b/Source/WebCore/platform/win/PopupMenuWin.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef PopupMenuWin_h
+#define PopupMenuWin_h
+
+#include "IntRect.h"
+#include "PopupMenu.h"
+#include "PopupMenuClient.h"
+#include "Scrollbar.h"
+#include "ScrollbarClient.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+typedef struct HWND__* HWND;
+typedef struct HDC__* HDC;
+typedef struct HBITMAP__* HBITMAP;
+
+namespace WebCore {
+
+class FrameView;
+class Scrollbar;
+
+class PopupMenuWin : public PopupMenu, private ScrollbarClient {
+public:
+ PopupMenuWin(PopupMenuClient*);
+ ~PopupMenuWin();
+
+ virtual void show(const IntRect&, FrameView*, int index);
+ virtual void hide();
+ virtual void updateFromElement();
+ virtual void disconnectClient();
+
+ static LPCTSTR popupClassName();
+
+private:
+ PopupMenuClient* client() const { return m_popupClient; }
+
+ Scrollbar* scrollbar() const { return m_scrollbar.get(); }
+
+ bool up(unsigned lines = 1);
+ bool down(unsigned lines = 1);
+
+ int itemHeight() const { return m_itemHeight; }
+ const IntRect& windowRect() const { return m_windowRect; }
+ IntRect clientRect() const;
+
+ int visibleItems() const;
+
+ int listIndexAtPoint(const IntPoint&) const;
+
+ bool setFocusedIndex(int index, bool hotTracking = false);
+ int focusedIndex() const;
+ void focusFirst();
+ void focusLast();
+
+ void paint(const IntRect& damageRect, HDC = 0);
+
+ HWND popupHandle() const { return m_popup; }
+
+ void setWasClicked(bool b = true) { m_wasClicked = b; }
+ bool wasClicked() const { return m_wasClicked; }
+
+ void setScrollOffset(int offset) { m_scrollOffset = offset; }
+ int scrollOffset() const { return m_scrollOffset; }
+
+ bool scrollToRevealSelection();
+
+ void incrementWheelDelta(int delta);
+ void reduceWheelDelta(int delta);
+ int wheelDelta() const { return m_wheelDelta; }
+
+ bool scrollbarCapturingMouse() const { return m_scrollbarCapturingMouse; }
+ void setScrollbarCapturingMouse(bool b) { m_scrollbarCapturingMouse = b; }
+
+ // ScrollBarClient
+ virtual int scrollSize(ScrollbarOrientation orientation) const;
+ virtual void setScrollOffsetFromAnimation(const IntPoint&);
+ virtual void valueChanged(Scrollbar*);
+ virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
+ virtual bool isActive() const { return true; }
+ virtual bool scrollbarCornerPresent() const { return false; }
+
+ void calculatePositionAndSize(const IntRect&, FrameView*);
+ void invalidateItem(int index);
+
+ static LRESULT CALLBACK PopupMenuWndProc(HWND, UINT, WPARAM, LPARAM);
+ LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+ static void registerClass();
+
+ PopupMenuClient* m_popupClient;
+ RefPtr<Scrollbar> m_scrollbar;
+ HWND m_popup;
+ HDC m_DC;
+ HBITMAP m_bmp;
+ bool m_wasClicked;
+ IntRect m_windowRect;
+ int m_itemHeight;
+ int m_scrollOffset;
+ int m_wheelDelta;
+ int m_focusedIndex;
+ bool m_scrollbarCapturingMouse;
+ bool m_showPopup;
+};
+
+}
+
+#endif // PopupMenuWin_h
diff --git a/Source/WebCore/platform/win/ScrollbarThemeSafari.cpp b/Source/WebCore/platform/win/ScrollbarThemeSafari.cpp
new file mode 100644
index 0000000..4e979f2
--- /dev/null
+++ b/Source/WebCore/platform/win/ScrollbarThemeSafari.cpp
@@ -0,0 +1,257 @@
+/*
+ * 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 };
+
+#ifdef DEBUG_ALL
+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/Source/WebCore/platform/win/ScrollbarThemeSafari.h b/Source/WebCore/platform/win/ScrollbarThemeSafari.h
new file mode 100644
index 0000000..f039379
--- /dev/null
+++ b/Source/WebCore/platform/win/ScrollbarThemeSafari.h
@@ -0,0 +1,63 @@
+/*
+ * 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/Source/WebCore/platform/win/ScrollbarThemeWin.cpp b/Source/WebCore/platform/win/ScrollbarThemeWin.cpp
new file mode 100644
index 0000000..ff3aaa4
--- /dev/null
+++ b/Source/WebCore/platform/win/ScrollbarThemeWin.cpp
@@ -0,0 +1,379 @@
+/*
+ * 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 "LocalWindowsContext.h"
+#include "PlatformMouseEvent.h"
+#include "Scrollbar.h"
+#include "SoftLinking.h"
+#include "SystemInfo.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 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))
+
+// Constants used to figure the drag rect outside which we should snap the
+// scrollbar thumb back to its origin. These calculations are based on
+// observing the behavior of the MSVC8 main window scrollbar + some
+// guessing/extrapolation.
+static const int kOffEndMultiplier = 3;
+static const int kOffSideMultiplier = 8;
+
+static void checkAndInitScrollbarTheme()
+{
+ if (uxthemeLibrary() && !scrollbarTheme && IsThemeActive())
+ scrollbarTheme = OpenThemeData(0, L"Scrollbar");
+}
+
+#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 (!scrollbarTheme)
+ return;
+
+ CloseThemeData(scrollbarTheme);
+ scrollbarTheme = 0;
+}
+
+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);
+}
+
+bool ScrollbarThemeWin::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt)
+{
+ return evt.shiftKey() && evt.button() == LeftButton;
+}
+
+bool ScrollbarThemeWin::shouldSnapBackToDragOrigin(Scrollbar* scrollbar, const PlatformMouseEvent& evt)
+{
+ // Find the rect within which we shouldn't snap, by expanding the track rect
+ // in both dimensions.
+ IntRect rect = trackRect(scrollbar);
+ const bool horz = scrollbar->orientation() == HorizontalScrollbar;
+ const int thickness = scrollbarThickness(scrollbar->controlSize());
+ rect.inflateX((horz ? kOffEndMultiplier : kOffSideMultiplier) * thickness);
+ rect.inflateY((horz ? kOffSideMultiplier : kOffEndMultiplier) * thickness);
+
+ // Convert the event to local coordinates.
+ IntPoint mousePosition = scrollbar->convertFromContainingWindow(evt.pos());
+ mousePosition.move(scrollbar->x(), scrollbar->y());
+
+ // We should snap iff the event is outside our calculated rect.
+ return !rect.contains(mousePosition);
+}
+
+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);
+
+ LocalWindowsContext windowsContext(context, rect, alphaBlend);
+ RECT themeRect(rect);
+
+ if (scrollbarTheme)
+ DrawThemeBackground(scrollbarTheme, windowsContext.hdc(), part, state, &themeRect, 0);
+ else {
+ DWORD color3DFace = ::GetSysColor(COLOR_3DFACE);
+ DWORD colorScrollbar = ::GetSysColor(COLOR_SCROLLBAR);
+ DWORD colorWindow = ::GetSysColor(COLOR_WINDOW);
+ HDC hdc = windowsContext.hdc();
+ 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);
+ }
+ }
+}
+
+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;
+#if !OS(WINCE)
+ classicState |= DFCS_FLAT;
+#endif
+ } 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);
+
+ LocalWindowsContext windowsContext(context, rect, alphaBlend);
+ RECT themeRect(rect);
+ if (scrollbarTheme)
+ DrawThemeBackground(scrollbarTheme, windowsContext.hdc(), SP_BUTTON, xpState, &themeRect, 0);
+ else
+ ::DrawFrameControl(windowsContext.hdc(), &themeRect, DFC_SCROLL, classicState);
+}
+
+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);
+}
+
+}
+
diff --git a/Source/WebCore/platform/win/ScrollbarThemeWin.h b/Source/WebCore/platform/win/ScrollbarThemeWin.h
new file mode 100644
index 0000000..cd2f176
--- /dev/null
+++ b/Source/WebCore/platform/win/ScrollbarThemeWin.h
@@ -0,0 +1,62 @@
+/*
+ * 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 bool shouldSnapBackToDragOrigin(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/Source/WebCore/platform/win/SearchPopupMenuWin.cpp b/Source/WebCore/platform/win/SearchPopupMenuWin.cpp
new file mode 100644
index 0000000..7ae800b
--- /dev/null
+++ b/Source/WebCore/platform/win/SearchPopupMenuWin.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc.
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "SearchPopupMenuWin.h"
+
+#include <wtf/text/AtomicString.h>
+
+#if PLATFORM(CF)
+#include <wtf/RetainPtr.h>
+#endif
+
+namespace WebCore {
+
+SearchPopupMenuWin::SearchPopupMenuWin(PopupMenuClient* client)
+ : m_popup(adoptRef(new PopupMenuWin(client)))
+{
+}
+
+PopupMenu* SearchPopupMenuWin::popupMenu()
+{
+ return m_popup.get();
+}
+
+bool SearchPopupMenuWin::enabled()
+{
+#if PLATFORM(CF)
+ return true;
+#else
+ return false;
+#endif
+}
+
+#if PLATFORM(CF)
+static RetainPtr<CFStringRef> autosaveKey(const String& name)
+{
+ String key = "com.apple.WebKit.searchField:" + name;
+ return RetainPtr<CFStringRef>(AdoptCF, key.createCFString());
+}
+#endif
+
+void SearchPopupMenuWin::saveRecentSearches(const AtomicString& name, const Vector<String>& searchItems)
+{
+ if (name.isEmpty())
+ return;
+
+#if PLATFORM(CF)
+ 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);
+#endif
+}
+
+void SearchPopupMenuWin::loadRecentSearches(const AtomicString& name, Vector<String>& searchItems)
+{
+ if (name.isEmpty())
+ return;
+
+#if PLATFORM(CF)
+ 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);
+ }
+#endif
+}
+
+}
diff --git a/Source/WebCore/platform/win/SearchPopupMenuWin.h b/Source/WebCore/platform/win/SearchPopupMenuWin.h
new file mode 100644
index 0000000..299a133
--- /dev/null
+++ b/Source/WebCore/platform/win/SearchPopupMenuWin.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef SearchPopupMenuWin_h
+#define SearchPopupMenuWin_h
+
+#include "PopupMenuWin.h"
+#include "SearchPopupMenu.h"
+
+namespace WebCore {
+
+class SearchPopupMenuWin : public SearchPopupMenu {
+public:
+ SearchPopupMenuWin(PopupMenuClient*);
+
+ virtual PopupMenu* popupMenu();
+ virtual void saveRecentSearches(const AtomicString& name, const Vector<String>& searchItems);
+ virtual void loadRecentSearches(const AtomicString& name, Vector<String>& searchItems);
+ virtual bool enabled();
+
+private:
+ RefPtr<PopupMenuWin> m_popup;
+};
+
+}
+
+#endif // SearchPopupMenuWin_h
diff --git a/Source/WebCore/platform/win/SharedBufferWin.cpp b/Source/WebCore/platform/win/SharedBufferWin.cpp
new file mode 100644
index 0000000..59a5a76
--- /dev/null
+++ b/Source/WebCore/platform/win/SharedBufferWin.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
+ *
+ * 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"
+#include <wtf/text/CString.h>
+
+// INVALID_FILE_SIZE is not defined on WinCE.
+#ifndef INVALID_FILE_SIZE
+#define INVALID_FILE_SIZE 0xffffffff
+#endif
+
+namespace WebCore {
+
+PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& filePath)
+{
+ if (filePath.isEmpty())
+ return 0;
+
+ String nullifiedPath = filePath;
+ HANDLE fileHandle = CreateFileW(nullifiedPath.charactersWithNullTermination(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+ if (fileHandle == INVALID_HANDLE_VALUE) {
+ LOG_ERROR("Failed to open file %s to create shared buffer, GetLastError() = %u", filePath.ascii().data(), GetLastError());
+ return 0;
+ }
+
+ RefPtr<SharedBuffer> result;
+ DWORD bytesToRead = GetFileSize(fileHandle, 0);
+ DWORD lastError = GetLastError();
+
+ if (bytesToRead != INVALID_FILE_SIZE || lastError == NO_ERROR) {
+ Vector<char> buffer(bytesToRead);
+ DWORD bytesRead;
+ if (ReadFile(fileHandle, buffer.data(), bytesToRead, &bytesRead, 0) && bytesToRead == bytesRead)
+ result = SharedBuffer::adoptVector(buffer);
+ else
+ LOG_ERROR("Failed to fully read contents of file %s, GetLastError() = %u", filePath.ascii().data(), GetLastError());
+ } else
+ LOG_ERROR("Failed to get filesize of file %s, GetLastError() = %u", filePath.ascii().data(), lastError);
+
+ CloseHandle(fileHandle);
+ return result.release();
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/SharedTimerWin.cpp b/Source/WebCore/platform/win/SharedTimerWin.cpp
new file mode 100644
index 0000000..b7367aa
--- /dev/null
+++ b/Source/WebCore/platform/win/SharedTimerWin.cpp
@@ -0,0 +1,224 @@
+/*
+ * 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 "Settings.h"
+#include "WebCoreInstanceHandle.h"
+#include "Widget.h"
+#include <wtf/Assertions.h>
+#include <wtf/CurrentTime.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>
+
+#if PLATFORM(WIN)
+#include "PluginView.h"
+#endif
+
+// 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
+
+namespace WebCore {
+
+static UINT timerID;
+static void (*sharedTimerFiredFunction)();
+
+static HWND timerWindowHandle = 0;
+static UINT timerFiredMessage = 0;
+static HANDLE timerQueue;
+static HANDLE timer;
+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 = WebCore::instanceHandle();
+ wcex.lpszClassName = kTimerWindowClassName;
+ RegisterClassEx(&wcex);
+
+ timerWindowHandle = CreateWindow(kTimerWindowClassName, 0, 0,
+ CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, HWND_MESSAGE, 0, WebCore::instanceHandle(), 0);
+ timerFiredMessage = RegisterWindowMessage(L"com.apple.WebKit.TimerFired");
+}
+
+void setSharedTimerFiredFunction(void (*f)())
+{
+ sharedTimerFiredFunction = f;
+}
+
+static void NTAPI queueTimerProc(PVOID, BOOLEAN)
+{
+ 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;
+ }
+
+ initializeOffScreenTimerWindow();
+ bool timerSet = false;
+
+ if (Settings::shouldUseHighResolutionTimers()) {
+ if (interval < highResolutionThresholdMsec) {
+ if (!highResTimerActive) {
+ highResTimerActive = true;
+ timeBeginPeriod(timerResolution);
+ }
+ SetTimer(timerWindowHandle, endHighResTimerID, stopHighResTimerInMsec, 0);
+ }
+
+ 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();
+ if (timer)
+ DeleteTimerQueueTimer(timerQueue, timer, 0);
+ 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);
+ timer = 0;
+ }
+}
+
+void stopSharedTimer()
+{
+ if (timerQueue && timer) {
+ DeleteTimerQueueTimer(timerQueue, timer, 0);
+ timer = 0;
+ }
+
+ if (timerID) {
+ KillTimer(timerWindowHandle, timerID);
+ timerID = 0;
+ }
+}
+
+}
diff --git a/Source/WebCore/platform/win/SoftLinking.h b/Source/WebCore/platform/win/SoftLinking.h
new file mode 100644
index 0000000..b67cc81
--- /dev/null
+++ b/Source/WebCore/platform/win/SoftLinking.h
@@ -0,0 +1,82 @@
+/*
+ * 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); \
+ return library; \
+ }
+
+#if OS(WINCE)
+#define SOFT_LINK_GETPROCADDRESS GetProcAddressA
+#else
+#define SOFT_LINK_GETPROCADDRESS GetProcAddress
+#endif
+
+#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 = reinterpret_cast<resultType (callingConvention*) parameterDeclarations>(SOFT_LINK_GETPROCADDRESS(library##Library(), #functionName)); \
+ ASSERT(softLink##functionName); \
+ return softLink##functionName parameterNames; \
+ }\
+ \
+ inline resultType functionName parameterDeclarations \
+ {\
+ return softLink##functionName parameterNames; \
+ }
+
+#define SOFT_LINK_OPTIONAL(library, functionName, resultType, callingConvention, parameterDeclarations) \
+ typedef resultType (callingConvention *functionName##PtrType) parameterDeclarations; \
+ static functionName##PtrType functionName##Ptr() \
+ { \
+ static functionName##PtrType ptr; \
+ static bool initialized; \
+ \
+ if (initialized) \
+ return ptr; \
+ initialized = true; \
+ \
+ ptr = reinterpret_cast<functionName##PtrType>(SOFT_LINK_GETPROCADDRESS(library##Library(), #functionName)); \
+ return ptr; \
+ }\
+
+#endif // SoftLinking_h
diff --git a/Source/WebCore/platform/win/SoundWin.cpp b/Source/WebCore/platform/win/SoundWin.cpp
new file mode 100644
index 0000000..443e7d9
--- /dev/null
+++ b/Source/WebCore/platform/win/SoundWin.cpp
@@ -0,0 +1,36 @@
+/*
+ * 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/Source/WebCore/platform/win/SystemInfo.cpp b/Source/WebCore/platform/win/SystemInfo.cpp
new file mode 100644
index 0000000..f2fe62b
--- /dev/null
+++ b/Source/WebCore/platform/win/SystemInfo.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2009 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 "SystemInfo.h"
+
+#include <windows.h>
+
+namespace WebCore {
+
+bool isRunningOnVistaOrLater()
+{
+#if OS(WINCE)
+ return false;
+#else
+ static bool isVistaOrLater;
+ static bool initialized;
+
+ if (initialized)
+ return isVistaOrLater;
+
+ initialized = true;
+
+ OSVERSIONINFOEX vi = {0};
+ vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+ GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&vi));
+
+ isVistaOrLater = vi.dwMajorVersion >= 6;
+
+ return isVistaOrLater;
+#endif
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/SystemInfo.h b/Source/WebCore/platform/win/SystemInfo.h
new file mode 100644
index 0000000..9f2c2a0
--- /dev/null
+++ b/Source/WebCore/platform/win/SystemInfo.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2009 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 SystemInfo_h
+#define SystemInfo_h
+
+namespace WebCore {
+
+bool isRunningOnVistaOrLater();
+
+} // namespace WebCore
+
+#endif // SystemInfo_h
diff --git a/Source/WebCore/platform/win/SystemTimeWin.cpp b/Source/WebCore/platform/win/SystemTimeWin.cpp
new file mode 100644
index 0000000..451262d
--- /dev/null
+++ b/Source/WebCore/platform/win/SystemTimeWin.cpp
@@ -0,0 +1,49 @@
+/*
+ * 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 <windows.h>
+
+#if COMPILER(MINGW) || (PLATFORM(QT) && COMPILER(MSVC))
+#include <float.h>
+#define FLOAT_MAX FLT_MAX
+#endif
+
+namespace WebCore {
+
+float userIdleTime()
+{
+#if !OS(WINCE)
+ LASTINPUTINFO lastInputInfo;
+ 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.
+#endif
+ return FLT_MAX; // return an arbitrarily high userIdleTime so that releasing pages from the page cache isn't postponed.
+}
+
+}
diff --git a/Source/WebCore/platform/win/TemporaryLinkStubs.cpp b/Source/WebCore/platform/win/TemporaryLinkStubs.cpp
new file mode 100644
index 0000000..d82f21c
--- /dev/null
+++ b/Source/WebCore/platform/win/TemporaryLinkStubs.cpp
@@ -0,0 +1,36 @@
+/*
+ * 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/Source/WebCore/platform/win/WCDataObject.cpp b/Source/WebCore/platform/win/WCDataObject.cpp
new file mode 100644
index 0000000..6b4c859
--- /dev/null
+++ b/Source/WebCore/platform/win/WCDataObject.cpp
@@ -0,0 +1,384 @@
+/*
+ * 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 (IsEqualIID(riid, IID_IUnknown) ||
+ IsEqualIID(riid, IID_IDataObject)) {
+ *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)
+ {
+#if !OS(WINCE)
+ 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;
+#endif
+ 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/Source/WebCore/platform/win/WCDataObject.h b/Source/WebCore/platform/win/WCDataObject.h
new file mode 100644
index 0000000..133115d
--- /dev/null
+++ b/Source/WebCore/platform/win/WCDataObject.h
@@ -0,0 +1,69 @@
+/*
+ * 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/Forward.h>
+#include <wtf/Vector.h>
+#include <ShlObj.h>
+#include <objidl.h>
+
+namespace WebCore {
+
+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/Source/WebCore/platform/win/WebCoreInstanceHandle.cpp b/Source/WebCore/platform/win/WebCoreInstanceHandle.cpp
new file mode 100644
index 0000000..dd21b2d
--- /dev/null
+++ b/Source/WebCore/platform/win/WebCoreInstanceHandle.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2010 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. 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 INC. 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 "WebCoreInstanceHandle.h"
+
+namespace WebCore {
+
+HINSTANCE s_instanceHandle;
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/WebCoreInstanceHandle.h b/Source/WebCore/platform/win/WebCoreInstanceHandle.h
new file mode 100644
index 0000000..9b6ce66
--- /dev/null
+++ b/Source/WebCore/platform/win/WebCoreInstanceHandle.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 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. 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 INC. 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 WebCoreInstanceHandle_h
+#define WebCoreInstanceHandle_h
+
+typedef struct HINSTANCE__* HINSTANCE;
+
+namespace WebCore {
+
+// The global DLL or application instance used for all windows.
+extern HINSTANCE s_instanceHandle;
+
+inline void setInstanceHandle(HINSTANCE instanceHandle) { s_instanceHandle = instanceHandle; }
+inline HINSTANCE instanceHandle() { return s_instanceHandle; }
+
+}
+
+#endif // WebCoreInstanceHandle_h
diff --git a/Source/WebCore/platform/win/WebCoreTextRenderer.cpp b/Source/WebCore/platform/win/WebCoreTextRenderer.cpp
new file mode 100644
index 0000000..a32fa4f
--- /dev/null
+++ b/Source/WebCore/platform/win/WebCoreTextRenderer.cpp
@@ -0,0 +1,126 @@
+/*
+ * 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, ColorSpaceDeviceRGB);
+ if (isOneLeftToRightRun(run))
+ font.drawText(&context, run, point);
+ else
+ context.drawBidiText(font, 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, ColorSpaceDeviceRGB);
+ 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/Source/WebCore/platform/win/WebCoreTextRenderer.h b/Source/WebCore/platform/win/WebCoreTextRenderer.h
new file mode 100644
index 0000000..7efc1f3
--- /dev/null
+++ b/Source/WebCore/platform/win/WebCoreTextRenderer.h
@@ -0,0 +1,45 @@
+/*
+ * 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 <wtf/Forward.h>
+
+namespace WebCore {
+
+ class Color;
+ class Font;
+ class GraphicsContext;
+ class IntPoint;
+
+ 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/Source/WebCore/platform/win/WheelEventWin.cpp b/Source/WebCore/platform/win/WheelEventWin.cpp
new file mode 100644
index 0000000..3fb8118
--- /dev/null
+++ b/Source/WebCore/platform/win/WheelEventWin.cpp
@@ -0,0 +1,136 @@
+/*
+ * 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 "PlatformWheelEvent.h"
+
+#include "FloatPoint.h"
+#include "FloatSize.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;
+}
+
+static int horizontalScrollChars()
+{
+ static ULONG scrollChars;
+ if (!scrollChars && !SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &scrollChars, 0))
+ scrollChars = 1;
+ return scrollChars;
+}
+
+static int verticalScrollLines()
+{
+ static ULONG scrollLines;
+ if (!scrollLines && !SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0))
+ scrollLines = 3;
+ return scrollLines;
+}
+
+PlatformWheelEvent::PlatformWheelEvent(HWND hWnd, const FloatSize& delta, const FloatPoint& location)
+ : m_isAccepted(false)
+ , m_shiftKey(false)
+ , m_ctrlKey(false)
+ , m_altKey(false)
+ , m_metaKey(false)
+{
+ m_deltaX = delta.width();
+ m_deltaY = delta.height();
+
+ m_wheelTicksX = m_deltaX;
+ m_wheelTicksY = m_deltaY;
+
+ // Global Position is just x, y location of event
+ POINT point = {location.x(), location.y()};
+ m_globalPosition = point;
+
+ // Position needs to be translated to our client
+ ScreenToClient(hWnd, &point);
+ m_position = point;
+}
+
+PlatformWheelEvent::PlatformWheelEvent(HWND hWnd, WPARAM wParam, LPARAM lParam, bool isMouseHWheel)
+ : 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
+{
+ // How many pixels should we scroll per line? Gecko uses the height of the
+ // current line, which means scroll distance changes as you go through the
+ // page or go to different pages. IE 7 is ~50 px/line, although the value
+ // seems to vary slightly by page and zoom level. Since IE 7 has a
+ // smoothing algorithm on scrolling, it can get away with slightly larger
+ // scroll values without feeling jerky. Here we use 100 px per three lines
+ // (the default scroll amount on Windows is three lines per wheel tick).
+ static const float cScrollbarPixelsPerLine = 100.0f / 3.0f;
+ float delta = GET_WHEEL_DELTA_WPARAM(wParam) / static_cast<float>(WHEEL_DELTA);
+ if (isMouseHWheel) {
+ // Windows is <-- -/+ -->, WebKit wants <-- +/- -->, so we negate
+ // |delta| after saving the original value on the wheel tick member.
+ m_wheelTicksX = delta;
+ m_wheelTicksY = 0;
+ delta = -delta;
+ } else {
+ // Even though we use shift + vertical wheel to scroll horizontally in
+ // WebKit, we still note it as a vertical scroll on the wheel tick
+ // member, so that the DOM event we later construct will match the real
+ // hardware event better.
+ m_wheelTicksX = 0;
+ m_wheelTicksY = delta;
+ }
+ if (isMouseHWheel || m_shiftKey) {
+ m_deltaX = delta * static_cast<float>(horizontalScrollChars()) * cScrollbarPixelsPerLine;
+ m_deltaY = 0;
+ m_granularity = ScrollByPixelWheelEvent;
+ } else {
+ m_deltaX = 0;
+ m_deltaY = delta;
+ int verticalMultiplier = verticalScrollLines();
+ m_granularity = (verticalMultiplier == WHEEL_PAGESCROLL) ? ScrollByPageWheelEvent : ScrollByPixelWheelEvent;
+ if (m_granularity == ScrollByPixelWheelEvent)
+ m_deltaY *= static_cast<float>(verticalMultiplier) * cScrollbarPixelsPerLine;
+ }
+}
+
+}
diff --git a/Source/WebCore/platform/win/WidgetWin.cpp b/Source/WebCore/platform/win/WidgetWin.cpp
new file mode 100644
index 0000000..416260b
--- /dev/null
+++ b/Source/WebCore/platform/win/WidgetWin.cpp
@@ -0,0 +1,101 @@
+/*
+ * 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 "Chrome.h"
+#include "Cursor.h"
+#include "Document.h"
+#include "Element.h"
+#include "FrameView.h"
+#include "FrameWin.h"
+#include "GraphicsContext.h"
+#include "IntRect.h"
+#include "Page.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()
+{
+}
+
+bool ignoreNextSetCursor = false;
+
+void Widget::setCursor(const Cursor& cursor)
+{
+ // This is set by PluginViewWin so it can ignore the setCursor call made by
+ // EventHandler.cpp.
+ if (ignoreNextSetCursor) {
+ ignoreNextSetCursor = false;
+ return;
+ }
+
+ ScrollView* view = root();
+ if (!view)
+ return;
+ view->hostWindow()->setCursor(cursor);
+}
+
+void Widget::paint(GraphicsContext*, const IntRect&)
+{
+}
+
+void Widget::setFocus(bool focused)
+{
+}
+
+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/Source/WebCore/platform/win/WindowMessageBroadcaster.cpp b/Source/WebCore/platform/win/WindowMessageBroadcaster.cpp
new file mode 100644
index 0000000..7088995
--- /dev/null
+++ b/Source/WebCore/platform/win/WindowMessageBroadcaster.cpp
@@ -0,0 +1,130 @@
+/*
+ * 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/Source/WebCore/platform/win/WindowMessageBroadcaster.h b/Source/WebCore/platform/win/WindowMessageBroadcaster.h
new file mode 100644
index 0000000..e7856e7
--- /dev/null
+++ b/Source/WebCore/platform/win/WindowMessageBroadcaster.h
@@ -0,0 +1,69 @@
+/*
+ * 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 : public 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/Source/WebCore/platform/win/WindowMessageListener.h b/Source/WebCore/platform/win/WindowMessageListener.h
new file mode 100644
index 0000000..b99cb35
--- /dev/null
+++ b/Source/WebCore/platform/win/WindowMessageListener.h
@@ -0,0 +1,46 @@
+/*
+ * 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