2 * Copyright (C) 2006, 2007, 2008 Apple, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebKitDLL.h"
30 #include "CFDictionaryPropertyBag.h"
31 #include "DOMCoreClasses.h"
32 #include "IWebNotification.h"
33 #include "WebDatabaseManager.h"
34 #include "WebDocumentLoader.h"
35 #include "WebEditorClient.h"
36 #include "WebElementPropertyBag.h"
38 #include "WebBackForwardList.h"
39 #include "WebChromeClient.h"
40 #include "WebContextMenuClient.h"
41 #include "WebDragClient.h"
42 #include "WebIconDatabase.h"
43 #include "WebInspector.h"
44 #include "WebInspectorClient.h"
46 #include "WebKitStatisticsPrivate.h"
47 #include "WebKitSystemBits.h"
48 #include "WebMutableURLRequest.h"
49 #include "WebNotificationCenter.h"
50 #include "WebPreferences.h"
51 #include "WebScriptDebugServer.h"
52 #pragma warning( push, 0 )
53 #include <CoreGraphics/CGContext.h>
54 #include <WebCore/BString.h>
55 #include <WebCore/Cache.h>
56 #include <WebCore/ContextMenu.h>
57 #include <WebCore/ContextMenuController.h>
58 #include <WebCore/CString.h>
59 #include <WebCore/Cursor.h>
60 #include <WebCore/Document.h>
61 #include <WebCore/DragController.h>
62 #include <WebCore/DragData.h>
63 #include <WebCore/Editor.h>
64 #include <WebCore/EventHandler.h>
65 #include <WebCore/EventNames.h>
66 #include <WebCore/FileSystem.h>
67 #include <WebCore/FocusController.h>
68 #include <WebCore/FontData.h>
69 #include <WebCore/FrameLoader.h>
70 #include <WebCore/FrameTree.h>
71 #include <WebCore/FrameView.h>
72 #include <WebCore/FrameWin.h>
73 #include <WebCore/GDIObjectCounter.h>
74 #include <WebCore/GraphicsContext.h>
75 #include <WebCore/HistoryItem.h>
76 #include <WebCore/HitTestResult.h>
77 #include <WebCore/IntRect.h>
78 #include <WebCore/KeyboardEvent.h>
79 #include <WebCore/Language.h>
80 #include <WebCore/MIMETypeRegistry.h>
81 #include <WebCore/NotImplemented.h>
82 #include <WebCore/Page.h>
83 #include <WebCore/PageCache.h>
84 #include <WebCore/PlatformKeyboardEvent.h>
85 #include <WebCore/PlatformMouseEvent.h>
86 #include <WebCore/PlatformWheelEvent.h>
87 #include <WebCore/PluginDatabaseWin.h>
88 #include <WebCore/PlugInInfoStore.h>
89 #include <WebCore/PluginViewWin.h>
90 #include <WebCore/ProgressTracker.h>
91 #include <WebCore/ResourceHandle.h>
92 #include <WebCore/ResourceHandleClient.h>
93 #include <WebCore/SelectionController.h>
94 #include <WebCore/Settings.h>
95 #include <WebCore/TypingCommand.h>
97 #include <JavaScriptCore/collector.h>
98 #include <JavaScriptCore/value.h>
99 #include <CFNetwork/CFURLCachePriv.h>
100 #include <CFNetwork/CFURLProtocolPriv.h>
101 #include <CoreFoundation/CoreFoundation.h>
102 #include <WebKitSystemInterface/WebKitSystemInterface.h>
103 #include <wtf/HashSet.h>
106 #include <windowsx.h>
109 using namespace WebCore;
110 using namespace WebCore::EventNames;
115 class PreferencesChangedOrRemovedObserver : public IWebNotificationObserver {
117 static PreferencesChangedOrRemovedObserver* sharedInstance();
120 PreferencesChangedOrRemovedObserver() {}
121 ~PreferencesChangedOrRemovedObserver() {}
123 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**) { return E_FAIL; }
124 virtual ULONG STDMETHODCALLTYPE AddRef(void) { return 0; }
125 virtual ULONG STDMETHODCALLTYPE Release(void) { return 0; }
128 // IWebNotificationObserver
129 virtual HRESULT STDMETHODCALLTYPE onNotify(
130 /* [in] */ IWebNotification* notification);
133 HRESULT notifyPreferencesChanged(WebCacheModel);
134 HRESULT notifyPreferencesRemoved(WebCacheModel);
137 PreferencesChangedOrRemovedObserver* PreferencesChangedOrRemovedObserver::sharedInstance()
139 static PreferencesChangedOrRemovedObserver* shared = new PreferencesChangedOrRemovedObserver;
143 HRESULT PreferencesChangedOrRemovedObserver::onNotify(IWebNotification* notification)
147 COMPtr<IUnknown> unkPrefs;
148 hr = notification->getObject(&unkPrefs);
152 COMPtr<IWebPreferences> preferences(Query, unkPrefs);
154 return E_NOINTERFACE;
156 WebCacheModel cacheModel;
157 hr = preferences->cacheModel(&cacheModel);
162 hr = notification->name(&nameBSTR);
166 name.adoptBSTR(nameBSTR);
168 if (wcscmp(name, WebPreferences::webPreferencesChangedNotification()) == 0)
169 return notifyPreferencesChanged(cacheModel);
171 if (wcscmp(name, WebPreferences::webPreferencesRemovedNotification()) == 0)
172 return notifyPreferencesRemoved(cacheModel);
174 ASSERT_NOT_REACHED();
178 HRESULT PreferencesChangedOrRemovedObserver::notifyPreferencesChanged(WebCacheModel cacheModel)
182 if (WebView::didSetCacheModel() || cacheModel > WebView::cacheModel())
183 WebView::setCacheModel(cacheModel);
184 else if (cacheModel < WebView::cacheModel()) {
185 WebCacheModel sharedPreferencesCacheModel;
186 hr = WebPreferences::sharedStandardPreferences()->cacheModel(&sharedPreferencesCacheModel);
189 WebView::setCacheModel(max(sharedPreferencesCacheModel, WebView::maxCacheModelInAnyInstance()));
195 HRESULT PreferencesChangedOrRemovedObserver::notifyPreferencesRemoved(WebCacheModel cacheModel)
199 if (cacheModel == WebView::cacheModel()) {
200 WebCacheModel sharedPreferencesCacheModel;
201 hr = WebPreferences::sharedStandardPreferences()->cacheModel(&sharedPreferencesCacheModel);
204 WebView::setCacheModel(max(sharedPreferencesCacheModel, WebView::maxCacheModelInAnyInstance()));
211 const LPCWSTR kWebViewWindowClassName = L"WebViewWindowClass";
213 const int WM_XP_THEMECHANGED = 0x031A;
214 const int WM_VISTA_MOUSEHWHEEL = 0x020E;
216 static const int maxToolTipWidth = 250;
218 static ATOM registerWebView();
219 static LRESULT CALLBACK WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
221 static void initializeStaticObservers();
223 static HRESULT updateSharedSettingsFromPreferencesIfNeeded(IWebPreferences*);
225 HRESULT createMatchEnumerator(Vector<IntRect>* rects, IEnumTextMatches** matches);
227 static bool continuousSpellCheckingEnabled;
228 static bool grammarCheckingEnabled;
230 static bool s_didSetCacheModel;
231 static WebCacheModel s_cacheModel = WebCacheModelDocumentViewer;
233 // WebView ----------------------------------------------------------------
235 bool WebView::s_allowSiteSpecificHacks = false;
243 , m_hasCustomDropTarget(false)
244 , m_useBackForwardList(true)
245 , m_userAgentOverridden(false)
246 , m_textSizeMultiplier(1)
247 , m_mouseActivated(false)
249 , m_currentCharacterCode(0)
250 , m_isBeingDestroyed(false)
252 , m_hasSpellCheckerDocumentTag(false)
253 , m_smartInsertDeleteEnabled(false)
255 , m_inIMEComposition(0)
257 , m_closeWindowTimer(this, &WebView::closeWindowTimerFired)
259 KJS::Collector::registerAsMainThread();
261 m_backingStoreSize.cx = m_backingStoreSize.cy = 0;
263 CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, IID_IDropTargetHelper,(void**)&m_dropTargetHelper);
265 initializeStaticObservers();
267 WebPreferences* sharedPreferences = WebPreferences::sharedStandardPreferences();
269 if (SUCCEEDED(sharedPreferences->continuousSpellCheckingEnabled(&enabled)))
270 continuousSpellCheckingEnabled = !!enabled;
271 if (SUCCEEDED(sharedPreferences->grammarCheckingEnabled(&enabled)))
272 grammarCheckingEnabled = !!enabled;
280 deleteBackingStore();
282 // <rdar://4958382> m_viewWindow will be destroyed when m_hostWindow is destroyed, but if
283 // setHostWindow was never called we will leak our HWND. If we still have a valid HWND at
284 // this point, we should just destroy it ourselves.
285 if (::IsWindow(m_viewWindow))
286 ::DestroyWindow(m_viewWindow);
289 ASSERT(!m_preferences);
295 WebView* WebView::createInstance()
297 WebView* instance = new WebView();
302 void initializeStaticObservers()
304 static bool initialized;
309 IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();
310 notifyCenter->addObserver(PreferencesChangedOrRemovedObserver::sharedInstance(), WebPreferences::webPreferencesChangedNotification(), 0);
311 notifyCenter->addObserver(PreferencesChangedOrRemovedObserver::sharedInstance(), WebPreferences::webPreferencesRemovedNotification(), 0);
314 static HashSet<WebView*>& allWebViewsSet()
316 static HashSet<WebView*> allWebViewsSet;
317 return allWebViewsSet;
320 void WebView::addToAllWebViewsSet()
322 allWebViewsSet().add(this);
325 void WebView::removeFromAllWebViewsSet()
327 allWebViewsSet().remove(this);
330 void WebView::setCacheModel(WebCacheModel cacheModel)
332 if (s_didSetCacheModel && cacheModel == s_cacheModel)
335 RetainPtr<CFStringRef> cfurlCacheDirectory(AdoptCF, wkCopyFoundationCacheDirectory());
336 if (!cfurlCacheDirectory)
337 cfurlCacheDirectory.adoptCF(WebCore::localUserSpecificStorageDirectory().createCFString());
340 CFURLCacheRef cfurlSharedCache = CFURLCacheSharedURLCache();
342 // As a fudge factor, use 1000 instead of 1024, in case the reported byte
343 // count doesn't align exactly to a megabyte boundary.
344 unsigned long long memSize = WebMemorySize() / 1024 / 1000;
345 unsigned long long diskFreeSize = WebVolumeFreeSize(cfurlCacheDirectory.get()) / 1024 / 1000;
347 unsigned cacheTotalCapacity = 0;
348 unsigned cacheMinDeadCapacity = 0;
349 unsigned cacheMaxDeadCapacity = 0;
351 unsigned pageCacheCapacity = 0;
353 CFIndex cfurlCacheMemoryCapacity = 0;
354 CFIndex cfurlCacheDiskCapacity = 0;
356 switch (cacheModel) {
357 case WebCacheModelDocumentViewer: {
358 // Page cache capacity (in pages)
359 pageCacheCapacity = 0;
361 // Object cache capacities (in bytes)
363 cacheTotalCapacity = 256 * 1024 * 1024;
364 else if (memSize >= 3072)
365 cacheTotalCapacity = 192 * 1024 * 1024;
366 else if (memSize >= 2048)
367 cacheTotalCapacity = 128 * 1024 * 1024;
368 else if (memSize >= 1536)
369 cacheTotalCapacity = 86 * 1024 * 1024;
370 else if (memSize >= 1024)
371 cacheTotalCapacity = 64 * 1024 * 1024;
372 else if (memSize >= 512)
373 cacheTotalCapacity = 32 * 1024 * 1024;
374 else if (memSize >= 256)
375 cacheTotalCapacity = 16 * 1024 * 1024;
377 cacheMinDeadCapacity = 0;
378 cacheMaxDeadCapacity = 0;
380 // Foundation memory cache capacity (in bytes)
381 cfurlCacheMemoryCapacity = 0;
383 // Foundation disk cache capacity (in bytes)
384 cfurlCacheDiskCapacity = CFURLCacheDiskCapacity(cfurlSharedCache);
388 case WebCacheModelDocumentBrowser: {
389 // Page cache capacity (in pages)
391 pageCacheCapacity = 3;
392 else if (memSize >= 512)
393 pageCacheCapacity = 2;
394 else if (memSize >= 256)
395 pageCacheCapacity = 1;
397 pageCacheCapacity = 0;
399 // Object cache capacities (in bytes)
401 cacheTotalCapacity = 256 * 1024 * 1024;
402 else if (memSize >= 3072)
403 cacheTotalCapacity = 192 * 1024 * 1024;
404 else if (memSize >= 2048)
405 cacheTotalCapacity = 128 * 1024 * 1024;
406 else if (memSize >= 1536)
407 cacheTotalCapacity = 86 * 1024 * 1024;
408 else if (memSize >= 1024)
409 cacheTotalCapacity = 64 * 1024 * 1024;
410 else if (memSize >= 512)
411 cacheTotalCapacity = 32 * 1024 * 1024;
412 else if (memSize >= 256)
413 cacheTotalCapacity = 16 * 1024 * 1024;
415 cacheMinDeadCapacity = cacheTotalCapacity / 8;
416 cacheMaxDeadCapacity = cacheTotalCapacity / 4;
418 // Foundation memory cache capacity (in bytes)
420 cfurlCacheMemoryCapacity = 4 * 1024 * 1024;
421 else if (memSize >= 1024)
422 cfurlCacheMemoryCapacity = 2 * 1024 * 1024;
423 else if (memSize >= 512)
424 cfurlCacheMemoryCapacity = 1 * 1024 * 1024;
426 cfurlCacheMemoryCapacity = 512 * 1024;
428 // Foundation disk cache capacity (in bytes)
429 if (diskFreeSize >= 16384)
430 cfurlCacheDiskCapacity = 50 * 1024 * 1024;
431 else if (diskFreeSize >= 8192)
432 cfurlCacheDiskCapacity = 40 * 1024 * 1024;
433 else if (diskFreeSize >= 4096)
434 cfurlCacheDiskCapacity = 30 * 1024 * 1024;
436 cfurlCacheDiskCapacity = 20 * 1024 * 1024;
440 case WebCacheModelPrimaryWebBrowser: {
441 // Page cache capacity (in pages)
442 // (Research indicates that value / page drops substantially after 3 pages.)
444 pageCacheCapacity = 7;
446 pageCacheCapacity = 6;
447 else if (memSize >= 2048)
448 pageCacheCapacity = 5;
449 else if (memSize >= 1024)
450 pageCacheCapacity = 4;
451 else if (memSize >= 512)
452 pageCacheCapacity = 3;
453 else if (memSize >= 256)
454 pageCacheCapacity = 2;
456 pageCacheCapacity = 1;
458 // Object cache capacities (in bytes)
459 // (Testing indicates that value / MB depends heavily on content and
460 // browsing pattern. Even growth above 128MB can have substantial
461 // value / MB for some content / browsing patterns.)
463 cacheTotalCapacity = 512 * 1024 * 1024;
464 else if (memSize >= 3072)
465 cacheTotalCapacity = 384 * 1024 * 1024;
466 else if (memSize >= 2048)
467 cacheTotalCapacity = 256 * 1024 * 1024;
468 else if (memSize >= 1536)
469 cacheTotalCapacity = 172 * 1024 * 1024;
470 else if (memSize >= 1024)
471 cacheTotalCapacity = 128 * 1024 * 1024;
472 else if (memSize >= 512)
473 cacheTotalCapacity = 64 * 1024 * 1024;
474 else if (memSize >= 256)
475 cacheTotalCapacity = 32 * 1024 * 1024;
477 cacheMinDeadCapacity = cacheTotalCapacity / 4;
478 cacheMaxDeadCapacity = cacheTotalCapacity / 2;
480 // This code is here to avoid a PLT regression. We can remove it if we
481 // can prove that the overall system gain would justify the regression.
482 cacheMaxDeadCapacity = max(24u, cacheMaxDeadCapacity);
484 // Foundation memory cache capacity (in bytes)
485 // (These values are small because WebCore does most caching itself.)
487 cfurlCacheMemoryCapacity = 4 * 1024 * 1024;
488 else if (memSize >= 512)
489 cfurlCacheMemoryCapacity = 2 * 1024 * 1024;
490 else if (memSize >= 256)
491 cfurlCacheMemoryCapacity = 1 * 1024 * 1024;
493 cfurlCacheMemoryCapacity = 512 * 1024;
495 // Foundation disk cache capacity (in bytes)
496 if (diskFreeSize >= 16384)
497 cfurlCacheDiskCapacity = 175 * 1024 * 1024;
498 else if (diskFreeSize >= 8192)
499 cfurlCacheDiskCapacity = 150 * 1024 * 1024;
500 else if (diskFreeSize >= 4096)
501 cfurlCacheDiskCapacity = 125 * 1024 * 1024;
502 else if (diskFreeSize >= 2048)
503 cfurlCacheDiskCapacity = 100 * 1024 * 1024;
504 else if (diskFreeSize >= 1024)
505 cfurlCacheDiskCapacity = 75 * 1024 * 1024;
507 cfurlCacheDiskCapacity = 50 * 1024 * 1024;
512 ASSERT_NOT_REACHED();
515 // Don't shrink a big disk cache, since that would cause churn.
516 cfurlCacheDiskCapacity = max(cfurlCacheDiskCapacity, CFURLCacheDiskCapacity(cfurlSharedCache));
518 cache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
519 pageCache()->setCapacity(pageCacheCapacity);
521 CFURLCacheSetMemoryCapacity(cfurlSharedCache, cfurlCacheMemoryCapacity);
522 CFURLCacheSetDiskCapacity(cfurlSharedCache, cfurlCacheDiskCapacity);
524 s_didSetCacheModel = true;
525 s_cacheModel = cacheModel;
529 WebCacheModel WebView::cacheModel()
534 bool WebView::didSetCacheModel()
536 return s_didSetCacheModel;
539 WebCacheModel WebView::maxCacheModelInAnyInstance()
541 WebCacheModel cacheModel = WebCacheModelDocumentViewer;
543 HashSet<WebView*>::iterator end = allWebViewsSet().end();
544 for (HashSet<WebView*>::iterator it = allWebViewsSet().begin(); it != end; ++it) {
545 COMPtr<IWebPreferences> pref;
546 if (FAILED((*it)->preferences(&pref)))
548 WebCacheModel prefCacheModel = WebCacheModelDocumentViewer;
549 if (FAILED(pref->cacheModel(&prefCacheModel)))
552 cacheModel = max(cacheModel, prefCacheModel);
558 void WebView::close()
565 removeFromAllWebViewsSet();
567 Frame* frame = m_page->mainFrame();
569 frame->loader()->detachFromParent();
571 if (m_mouseOutTracker) {
572 m_mouseOutTracker->dwFlags = TME_CANCEL;
573 ::TrackMouseEvent(m_mouseOutTracker.get());
574 m_mouseOutTracker.set(0);
577 m_page->setGroupName(String());
580 setDownloadDelegate(0);
581 setEditingDelegate(0);
582 setFrameLoadDelegate(0);
583 setFrameLoadDelegatePrivate(0);
584 setPolicyDelegate(0);
585 setResourceLoadDelegate(0);
590 m_webInspector->webViewClosed();
595 registerForIconNotification(false);
596 IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();
597 notifyCenter->removeObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
600 if (SUCCEEDED(m_preferences->identifier(&identifier)))
601 WebPreferences::removeReferenceForIdentifier(identifier);
603 SysFreeString(identifier);
605 COMPtr<WebPreferences> preferences = m_preferences;
607 preferences->didRemoveFromWebView();
609 deleteBackingStore();
612 void WebView::deleteBackingStore()
614 m_backingStoreBitmap.clear();
615 m_backingStoreDirtyRegion.clear();
617 m_backingStoreSize.cx = m_backingStoreSize.cy = 0;
620 bool WebView::ensureBackingStore()
623 ::GetClientRect(m_viewWindow, &windowRect);
624 LONG width = windowRect.right - windowRect.left;
625 LONG height = windowRect.bottom - windowRect.top;
626 if (width > 0 && height > 0 && (width != m_backingStoreSize.cx || height != m_backingStoreSize.cy)) {
627 deleteBackingStore();
629 m_backingStoreSize.cx = width;
630 m_backingStoreSize.cy = height;
631 BITMAPINFO bitmapInfo;
632 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
633 bitmapInfo.bmiHeader.biWidth = width;
634 bitmapInfo.bmiHeader.biHeight = -height;
635 bitmapInfo.bmiHeader.biPlanes = 1;
636 bitmapInfo.bmiHeader.biBitCount = 32;
637 bitmapInfo.bmiHeader.biCompression = BI_RGB;
638 bitmapInfo.bmiHeader.biSizeImage = 0;
639 bitmapInfo.bmiHeader.biXPelsPerMeter = 0;
640 bitmapInfo.bmiHeader.biYPelsPerMeter = 0;
641 bitmapInfo.bmiHeader.biClrUsed = 0;
642 bitmapInfo.bmiHeader.biClrImportant = 0;
645 m_backingStoreBitmap.set(::CreateDIBSection(NULL, &bitmapInfo, DIB_RGB_COLORS, &pixels, NULL, 0));
652 void WebView::addToDirtyRegion(const IntRect& dirtyRect)
654 HRGN newRegion = ::CreateRectRgn(dirtyRect.x(), dirtyRect.y(),
655 dirtyRect.right(), dirtyRect.bottom());
656 addToDirtyRegion(newRegion);
659 void WebView::addToDirtyRegion(HRGN newRegion)
661 LOCAL_GDI_COUNTER(0, __FUNCTION__);
663 if (m_backingStoreDirtyRegion) {
664 HRGN combinedRegion = ::CreateRectRgn(0,0,0,0);
665 ::CombineRgn(combinedRegion, m_backingStoreDirtyRegion.get(), newRegion, RGN_OR);
666 ::DeleteObject(newRegion);
667 m_backingStoreDirtyRegion.set(combinedRegion);
669 m_backingStoreDirtyRegion.set(newRegion);
672 void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const IntRect& scrollViewRect, const IntRect& clipRect)
674 LOCAL_GDI_COUNTER(0, __FUNCTION__);
676 // If there's no backing store we don't need to update it
677 if (!m_backingStoreBitmap) {
678 if (m_uiDelegatePrivate)
679 m_uiDelegatePrivate->webViewScrolled(this);
684 // Make a region to hold the invalidated scroll area.
685 HRGN updateRegion = ::CreateRectRgn(0, 0, 0, 0);
687 // Collect our device context info and select the bitmap to scroll.
688 HDC windowDC = ::GetDC(m_viewWindow);
689 HDC bitmapDC = ::CreateCompatibleDC(windowDC);
690 ::SelectObject(bitmapDC, m_backingStoreBitmap.get());
692 // Scroll the bitmap.
693 RECT scrollRectWin(scrollViewRect);
694 RECT clipRectWin(clipRect);
695 ::ScrollDC(bitmapDC, dx, dy, &scrollRectWin, &clipRectWin, updateRegion, 0);
697 ::GetRgnBox(updateRegion, ®ionBox);
702 // Add the dirty region to the backing store's dirty region.
703 addToDirtyRegion(updateRegion);
705 if (m_uiDelegatePrivate)
706 m_uiDelegatePrivate->webViewScrolled(this);
708 // Update the backing store.
709 updateBackingStore(frameView, bitmapDC, false);
712 ::DeleteDC(bitmapDC);
713 ::ReleaseDC(m_viewWindow, windowDC);
717 // This emulates the Mac smarts for painting rects intelligently. This is very
718 // important for us, since we double buffer based off dirty rects.
719 static void getUpdateRects(HRGN region, const IntRect& dirtyRect, Vector<IntRect>& rects)
721 ASSERT_ARG(region, region);
723 const int cRectThreshold = 10;
724 const float cWastedSpaceThreshold = 0.75f;
728 DWORD regionDataSize = GetRegionData(region, sizeof(RGNDATA), NULL);
729 if (!regionDataSize) {
730 rects.append(dirtyRect);
734 Vector<unsigned char> buffer(regionDataSize);
735 RGNDATA* regionData = reinterpret_cast<RGNDATA*>(buffer.data());
736 GetRegionData(region, regionDataSize, regionData);
737 if (regionData->rdh.nCount > cRectThreshold) {
738 rects.append(dirtyRect);
742 double singlePixels = 0.0;
745 for (i = 0, rect = reinterpret_cast<RECT*>(regionData->Buffer); i < regionData->rdh.nCount; i++, rect++)
746 singlePixels += (rect->right - rect->left) * (rect->bottom - rect->top);
748 double unionPixels = dirtyRect.width() * dirtyRect.height();
749 double wastedSpace = 1.0 - (singlePixels / unionPixels);
750 if (wastedSpace <= cWastedSpaceThreshold) {
751 rects.append(dirtyRect);
755 for (i = 0, rect = reinterpret_cast<RECT*>(regionData->Buffer); i < regionData->rdh.nCount; i++, rect++)
759 void WebView::updateBackingStore(FrameView* frameView, HDC dc, bool backingStoreCompletelyDirty)
761 LOCAL_GDI_COUNTER(0, __FUNCTION__);
766 windowDC = ::GetDC(m_viewWindow);
767 bitmapDC = ::CreateCompatibleDC(windowDC);
768 ::SelectObject(bitmapDC, m_backingStoreBitmap.get());
771 if (m_backingStoreBitmap && (m_backingStoreDirtyRegion || backingStoreCompletelyDirty)) {
772 // Do a layout first so that everything we render to the backing store is always current.
773 if (Frame* coreFrame = core(m_mainFrame))
774 if (FrameView* view = coreFrame->view())
775 view->layoutIfNeededRecursive();
777 Vector<IntRect> paintRects;
778 if (!backingStoreCompletelyDirty) {
780 ::GetRgnBox(m_backingStoreDirtyRegion.get(), ®ionBox);
781 getUpdateRects(m_backingStoreDirtyRegion.get(), regionBox, paintRects);
784 ::GetClientRect(m_viewWindow, &clientRect);
785 paintRects.append(clientRect);
788 for (unsigned i = 0; i < paintRects.size(); ++i)
789 paintIntoBackingStore(frameView, bitmapDC, paintRects[i]);
791 if (m_uiDelegatePrivate) {
792 COMPtr<IWebUIDelegatePrivate2> uiDelegatePrivate2(Query, m_uiDelegatePrivate);
793 if (uiDelegatePrivate2)
794 uiDelegatePrivate2->webViewPainted(this);
797 m_backingStoreDirtyRegion.clear();
801 ::DeleteDC(bitmapDC);
802 ::ReleaseDC(m_viewWindow, windowDC);
808 void WebView::paint(HDC dc, LPARAM options)
810 LOCAL_GDI_COUNTER(0, __FUNCTION__);
812 Frame* coreFrame = core(m_mainFrame);
815 FrameView* frameView = coreFrame->view();
822 int regionType = NULLREGION;
825 region.set(CreateRectRgn(0,0,0,0));
826 regionType = GetUpdateRgn(m_viewWindow, region.get(), false);
827 hdc = BeginPaint(m_viewWindow, &ps);
828 rcPaint = ps.rcPaint;
831 ::GetClientRect(m_viewWindow, &rcPaint);
832 if (options & PRF_ERASEBKGND)
833 ::FillRect(hdc, &rcPaint, (HBRUSH)GetStockObject(WHITE_BRUSH));
836 HDC bitmapDC = ::CreateCompatibleDC(hdc);
837 bool backingStoreCompletelyDirty = ensureBackingStore();
838 ::SelectObject(bitmapDC, m_backingStoreBitmap.get());
840 // Update our backing store if needed.
841 updateBackingStore(frameView, bitmapDC, backingStoreCompletelyDirty);
843 // Now we blit the updated backing store
844 IntRect windowDirtyRect = rcPaint;
846 // Apply the same heuristic for this update region too.
847 Vector<IntRect> blitRects;
848 if (region && regionType == COMPLEXREGION)
849 getUpdateRects(region.get(), windowDirtyRect, blitRects);
851 blitRects.append(windowDirtyRect);
853 for (unsigned i = 0; i < blitRects.size(); ++i)
854 paintIntoWindow(bitmapDC, hdc, blitRects[i]);
856 ::DeleteDC(bitmapDC);
858 // Paint the gripper.
859 COMPtr<IWebUIDelegate> ui;
860 if (SUCCEEDED(uiDelegate(&ui))) {
861 COMPtr<IWebUIDelegatePrivate> uiPrivate;
862 if (SUCCEEDED(ui->QueryInterface(IID_IWebUIDelegatePrivate, (void**)&uiPrivate))) {
864 if (SUCCEEDED(uiPrivate->webViewResizerRect(this, &r))) {
865 LOCAL_GDI_COUNTER(2, __FUNCTION__" webViewDrawResizer delegate call");
866 uiPrivate->webViewDrawResizer(this, hdc, (frameView->resizerOverlapsContent() ? true : false), &r);
872 EndPaint(m_viewWindow, &ps);
877 void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const IntRect& dirtyRect)
879 LOCAL_GDI_COUNTER(0, __FUNCTION__);
881 RECT rect = dirtyRect;
883 #if FLASH_BACKING_STORE_REDRAW
884 HDC dc = ::GetDC(m_viewWindow);
885 OwnPtr<HBRUSH> yellowBrush = CreateSolidBrush(RGB(255, 255, 0));
886 FillRect(dc, &rect, yellowBrush.get());
889 paintIntoWindow(bitmapDC, dc, dirtyRect);
890 ::ReleaseDC(m_viewWindow, dc);
893 FillRect(bitmapDC, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
894 if (frameView && frameView->frame() && frameView->frame()->renderer()) {
895 GraphicsContext gc(bitmapDC);
898 frameView->paint(&gc, dirtyRect);
903 void WebView::paintIntoWindow(HDC bitmapDC, HDC windowDC, const IntRect& dirtyRect)
905 LOCAL_GDI_COUNTER(0, __FUNCTION__);
906 #if FLASH_WINDOW_REDRAW
907 OwnPtr<HBRUSH> greenBrush = CreateSolidBrush(RGB(0, 255, 0));
908 RECT rect = dirtyRect;
909 FillRect(windowDC, &rect, greenBrush.get());
914 // Blit the dirty rect from the backing store into the same position
915 // in the destination DC.
916 BitBlt(windowDC, dirtyRect.x(), dirtyRect.y(), dirtyRect.width(), dirtyRect.height(), bitmapDC,
917 dirtyRect.x(), dirtyRect.y(), SRCCOPY);
920 void WebView::frameRect(RECT* rect)
922 ::GetWindowRect(m_viewWindow, rect);
925 void WebView::closeWindowSoon()
927 m_closeWindowTimer.startOneShot(0);
931 void WebView::closeWindowTimerFired(WebCore::Timer<WebView>*)
937 void WebView::closeWindow()
939 if (m_hasSpellCheckerDocumentTag) {
940 if (m_editingDelegate)
941 m_editingDelegate->closeSpellDocument(this);
942 m_hasSpellCheckerDocumentTag = false;
945 COMPtr<IWebUIDelegate> ui;
946 if (SUCCEEDED(uiDelegate(&ui)))
947 ui->webViewClose(this);
950 bool WebView::canHandleRequest(const WebCore::ResourceRequest& request)
952 // On the mac there's an about url protocol implementation but CFNetwork doesn't have that.
953 if (equalIgnoringCase(String(request.url().protocol()), "about"))
956 if (CFURLProtocolCanHandleRequest(request.cfURLRequest()))
959 // FIXME: Mac WebKit calls _representationExistsForURLScheme here
963 Page* WebView::page()
968 bool WebView::handleContextMenuEvent(WPARAM wParam, LPARAM lParam)
970 static const int contextMenuMargin = 1;
972 // Translate the screen coordinates into window coordinates
973 POINT coords = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
974 if (coords.x == -1 || coords.y == -1) {
975 FrameView* view = m_page->mainFrame()->view();
979 int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT);
982 // The context menu event was generated from the keyboard, so show the context menu by the current selection.
983 Position start = m_page->mainFrame()->selectionController()->selection().start();
984 Position end = m_page->mainFrame()->selectionController()->selection().end();
986 if (!start.node() || !end.node())
987 location = IntPoint(rightAligned ? view->contentsWidth() - contextMenuMargin : contextMenuMargin, contextMenuMargin);
989 RenderObject* renderer = start.node()->renderer();
993 // Calculate the rect of the first line of the selection (cribbed from -[WebCoreFrameBridge firstRectForDOMRange:]).
994 int extraWidthToEndOfLine = 0;
995 IntRect startCaretRect = renderer->caretRect(start.offset(), DOWNSTREAM, &extraWidthToEndOfLine);
996 IntRect endCaretRect = renderer->caretRect(end.offset(), UPSTREAM);
999 if (startCaretRect.y() == endCaretRect.y())
1000 firstRect = IntRect(min(startCaretRect.x(), endCaretRect.x()), startCaretRect.y(), abs(endCaretRect.x() - startCaretRect.x()), max(startCaretRect.height(), endCaretRect.height()));
1002 firstRect = IntRect(startCaretRect.x(), startCaretRect.y(), startCaretRect.width() + extraWidthToEndOfLine, startCaretRect.height());
1004 location = IntPoint(rightAligned ? firstRect.right() : firstRect.x(), firstRect.bottom());
1007 location = view->contentsToWindow(location);
1008 // FIXME: The IntSize(0, -1) is a hack to get the hit-testing to result in the selected element.
1009 // Ideally we'd have the position of a context menu event be separate from its target node.
1010 coords = location + IntSize(0, -1);
1012 if (!::ScreenToClient(m_viewWindow, &coords))
1016 lParam = MAKELPARAM(coords.x, coords.y);
1018 // The contextMenuController() holds onto the last context menu that was popped up on the
1019 // page until a new one is created. We need to clear this menu before propagating the event
1020 // through the DOM so that we can detect if we create a new menu for this event, since we
1021 // won't create a new menu if the DOM swallows the event and the defaultEventHandler does
1023 m_page->contextMenuController()->clearContextMenu();
1025 HitTestResult result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(IntPoint(coords.x, coords.y), false);
1026 Frame* targetFrame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document()->frame() : m_page->focusController()->focusedOrMainFrame();
1028 targetFrame->view()->setCursor(pointerCursor());
1029 PlatformMouseEvent mouseEvent(m_viewWindow, WM_RBUTTONUP, wParam, lParam);
1030 bool handledEvent = targetFrame->eventHandler()->sendContextMenuEvent(mouseEvent);
1035 ContextMenu* coreMenu = m_page->contextMenuController()->contextMenu();
1039 Node* node = coreMenu->hitTestResult().innerNonSharedNode();
1043 Frame* frame = node->document()->frame();
1047 FrameView* view = frame->view();
1051 POINT point(view->contentsToWindow(coreMenu->hitTestResult().point()));
1053 // Translate the point to screen coordinates
1054 if (!::ClientToScreen(view->containingWindow(), &point))
1057 BOOL hasCustomMenus = false;
1059 m_uiDelegate->hasCustomMenuImplementation(&hasCustomMenus);
1062 m_uiDelegate->trackCustomPopupMenu((IWebView*)this, (OLE_HANDLE)(ULONG64)coreMenu->platformDescription(), &point);
1064 // Surprisingly, TPM_RIGHTBUTTON means that items are selectable with either the right OR left mouse button
1065 UINT flags = TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERPOSANIMATION | TPM_HORIZONTAL
1066 | TPM_LEFTALIGN | TPM_HORPOSANIMATION;
1067 ::TrackPopupMenuEx(coreMenu->platformDescription(), flags, point.x, point.y, view->containingWindow(), 0);
1073 bool WebView::onMeasureItem(WPARAM /*wParam*/, LPARAM lParam)
1078 BOOL hasCustomMenus = false;
1079 m_uiDelegate->hasCustomMenuImplementation(&hasCustomMenus);
1080 if (!hasCustomMenus)
1083 m_uiDelegate->measureCustomMenuItem((IWebView*)this, (void*)lParam);
1087 bool WebView::onDrawItem(WPARAM /*wParam*/, LPARAM lParam)
1092 BOOL hasCustomMenus = false;
1093 m_uiDelegate->hasCustomMenuImplementation(&hasCustomMenus);
1094 if (!hasCustomMenus)
1097 m_uiDelegate->drawCustomMenuItem((IWebView*)this, (void*)lParam);
1101 bool WebView::onInitMenuPopup(WPARAM wParam, LPARAM /*lParam*/)
1106 HMENU menu = (HMENU)wParam;
1110 BOOL hasCustomMenus = false;
1111 m_uiDelegate->hasCustomMenuImplementation(&hasCustomMenus);
1112 if (!hasCustomMenus)
1115 m_uiDelegate->addCustomMenuDrawingData((IWebView*)this, (OLE_HANDLE)(ULONG64)menu);
1119 bool WebView::onUninitMenuPopup(WPARAM wParam, LPARAM /*lParam*/)
1124 HMENU menu = (HMENU)wParam;
1128 BOOL hasCustomMenus = false;
1129 m_uiDelegate->hasCustomMenuImplementation(&hasCustomMenus);
1130 if (!hasCustomMenus)
1133 m_uiDelegate->cleanUpCustomMenuDrawingData((IWebView*)this, (OLE_HANDLE)(ULONG64)menu);
1137 void WebView::performContextMenuAction(WPARAM wParam, LPARAM lParam, bool byPosition)
1139 ContextMenu* menu = m_page->contextMenuController()->contextMenu();
1142 ContextMenuItem* item = byPosition ? menu->itemAtIndex((unsigned)wParam, (HMENU)lParam) : menu->itemWithAction((ContextMenuAction)wParam);
1145 m_page->contextMenuController()->contextMenuItemSelected(item);
1149 bool WebView::handleMouseEvent(UINT message, WPARAM wParam, LPARAM lParam)
1151 static LONG globalClickCount;
1152 static IntPoint globalPrevPoint;
1153 static MouseButton globalPrevButton;
1154 static LONG globalPrevMouseDownTime;
1156 // Create our event.
1157 // On WM_MOUSELEAVE we need to create a mouseout event, so we force the position
1158 // of the event to be at (MINSHORT, MINSHORT).
1159 LPARAM position = (message == WM_MOUSELEAVE) ? ((MINSHORT << 16) | MINSHORT) : lParam;
1160 PlatformMouseEvent mouseEvent(m_viewWindow, message, wParam, position, m_mouseActivated);
1162 bool insideThreshold = abs(globalPrevPoint.x() - mouseEvent.pos().x()) < ::GetSystemMetrics(SM_CXDOUBLECLK) &&
1163 abs(globalPrevPoint.y() - mouseEvent.pos().y()) < ::GetSystemMetrics(SM_CYDOUBLECLK);
1164 LONG messageTime = ::GetMessageTime();
1166 bool handled = false;
1167 if (message == WM_LBUTTONDOWN || message == WM_MBUTTONDOWN || message == WM_RBUTTONDOWN) {
1168 // FIXME: I'm not sure if this is the "right" way to do this
1169 // but without this call, we never become focused since we don't allow
1170 // the default handling of mouse events.
1171 SetFocus(m_viewWindow);
1173 // Always start capturing events when the mouse goes down in our HWND.
1174 ::SetCapture(m_viewWindow);
1176 if (((messageTime - globalPrevMouseDownTime) < (LONG)::GetDoubleClickTime()) &&
1178 mouseEvent.button() == globalPrevButton)
1181 // Reset the click count.
1182 globalClickCount = 1;
1183 globalPrevMouseDownTime = messageTime;
1184 globalPrevButton = mouseEvent.button();
1185 globalPrevPoint = mouseEvent.pos();
1187 mouseEvent.setClickCount(globalClickCount);
1188 handled = m_page->mainFrame()->eventHandler()->handleMousePressEvent(mouseEvent);
1189 } else if (message == WM_LBUTTONDBLCLK || message == WM_MBUTTONDBLCLK || message == WM_RBUTTONDBLCLK) {
1191 mouseEvent.setClickCount(globalClickCount);
1192 handled = m_page->mainFrame()->eventHandler()->handleMousePressEvent(mouseEvent);
1193 } else if (message == WM_LBUTTONUP || message == WM_MBUTTONUP || message == WM_RBUTTONUP) {
1194 // Record the global position and the button of the up.
1195 globalPrevButton = mouseEvent.button();
1196 globalPrevPoint = mouseEvent.pos();
1197 mouseEvent.setClickCount(globalClickCount);
1198 m_page->mainFrame()->eventHandler()->handleMouseReleaseEvent(mouseEvent);
1200 } else if (message == WM_MOUSELEAVE && m_mouseOutTracker) {
1201 // Once WM_MOUSELEAVE is fired windows clears this tracker
1202 // so there is no need to disable it ourselves.
1203 m_mouseOutTracker.set(0);
1204 m_page->mainFrame()->eventHandler()->mouseMoved(mouseEvent);
1206 } else if (message == WM_MOUSEMOVE) {
1207 if (!insideThreshold)
1208 globalClickCount = 0;
1209 mouseEvent.setClickCount(globalClickCount);
1210 handled = m_page->mainFrame()->eventHandler()->mouseMoved(mouseEvent);
1211 if (!m_mouseOutTracker) {
1212 m_mouseOutTracker.set(new TRACKMOUSEEVENT);
1213 m_mouseOutTracker->cbSize = sizeof(TRACKMOUSEEVENT);
1214 m_mouseOutTracker->dwFlags = TME_LEAVE;
1215 m_mouseOutTracker->hwndTrack = m_viewWindow;
1216 ::TrackMouseEvent(m_mouseOutTracker.get());
1219 setMouseActivated(false);
1223 bool WebView::mouseWheel(WPARAM wParam, LPARAM lParam, bool isHorizontal)
1225 // Ctrl+Mouse wheel doesn't ever go into WebCore. It is used to
1226 // zoom instead (Mac zooms the whole Desktop, but Windows browsers trigger their
1227 // own local zoom modes for Ctrl+wheel).
1228 if (wParam & MK_CONTROL) {
1229 short delta = short(HIWORD(wParam));
1237 PlatformWheelEvent wheelEvent(m_viewWindow, wParam, lParam, isHorizontal);
1238 Frame* coreFrame = core(m_mainFrame);
1242 return coreFrame->eventHandler()->handleWheelEvent(wheelEvent);
1245 bool WebView::execCommand(WPARAM wParam, LPARAM /*lParam*/)
1247 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1248 switch (LOWORD(wParam)) {
1250 return frame->editor()->command("SelectAll").execute();
1252 return frame->editor()->command("Undo").execute();
1254 return frame->editor()->command("Redo").execute();
1259 bool WebView::keyUp(WPARAM virtualKeyCode, LPARAM keyData, bool systemKeyDown)
1261 PlatformKeyboardEvent keyEvent(m_viewWindow, virtualKeyCode, keyData, PlatformKeyboardEvent::KeyUp, systemKeyDown);
1263 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1264 m_currentCharacterCode = 0;
1266 return frame->eventHandler()->keyEvent(keyEvent);
1269 static const unsigned CtrlKey = 1 << 0;
1270 static const unsigned AltKey = 1 << 1;
1271 static const unsigned ShiftKey = 1 << 2;
1274 struct KeyDownEntry {
1275 unsigned virtualKey;
1280 struct KeyPressEntry {
1286 static const KeyDownEntry keyDownEntries[] = {
1287 { VK_LEFT, 0, "MoveLeft" },
1288 { VK_LEFT, ShiftKey, "MoveLeftAndModifySelection" },
1289 { VK_LEFT, CtrlKey, "MoveWordLeft" },
1290 { VK_LEFT, CtrlKey | ShiftKey, "MoveWordLeftAndModifySelection" },
1291 { VK_RIGHT, 0, "MoveRight" },
1292 { VK_RIGHT, ShiftKey, "MoveRightAndModifySelection" },
1293 { VK_RIGHT, CtrlKey, "MoveWordRight" },
1294 { VK_RIGHT, CtrlKey | ShiftKey, "MoveWordRightAndModifySelection" },
1295 { VK_UP, 0, "MoveUp" },
1296 { VK_UP, ShiftKey, "MoveUpAndModifySelection" },
1297 { VK_PRIOR, ShiftKey, "MoveUpAndModifySelection" },
1298 { VK_DOWN, 0, "MoveDown" },
1299 { VK_DOWN, ShiftKey, "MoveDownAndModifySelection" },
1300 { VK_NEXT, ShiftKey, "MoveDownAndModifySelection" },
1301 { VK_PRIOR, 0, "MovePageUp" },
1302 { VK_NEXT, 0, "MovePageDown" },
1303 { VK_HOME, 0, "MoveToBeginningOfLine" },
1304 { VK_HOME, ShiftKey, "MoveToBeginningOfLineAndModifySelection" },
1305 { VK_HOME, CtrlKey, "MoveToBeginningOfDocument" },
1306 { VK_HOME, CtrlKey | ShiftKey, "MoveToBeginningOfDocumentAndModifySelection" },
1308 { VK_END, 0, "MoveToEndOfLine" },
1309 { VK_END, ShiftKey, "MoveToEndOfLineAndModifySelection" },
1310 { VK_END, CtrlKey, "MoveToEndOfDocument" },
1311 { VK_END, CtrlKey | ShiftKey, "MoveToEndOfDocumentAndModifySelection" },
1313 { VK_BACK, 0, "BackwardDelete" },
1314 { VK_BACK, ShiftKey, "BackwardDelete" },
1315 { VK_DELETE, 0, "ForwardDelete" },
1316 { VK_DELETE, ShiftKey, "ForwardDelete" },
1317 { VK_BACK, CtrlKey, "DeleteWordBackward" },
1318 { VK_DELETE, CtrlKey, "DeleteWordForward" },
1320 { 'B', CtrlKey, "ToggleBold" },
1321 { 'I', CtrlKey, "ToggleItalic" },
1323 { VK_ESCAPE, 0, "Cancel" },
1324 { VK_OEM_PERIOD, CtrlKey, "Cancel" },
1325 { VK_TAB, 0, "InsertTab" },
1326 { VK_TAB, ShiftKey, "InsertBacktab" },
1327 { VK_RETURN, 0, "InsertNewline" },
1328 { VK_RETURN, CtrlKey, "InsertNewline" },
1329 { VK_RETURN, AltKey, "InsertNewline" },
1330 { VK_RETURN, AltKey | ShiftKey, "InsertNewline" },
1332 { 'C', CtrlKey, "Copy" },
1333 { 'V', CtrlKey, "Paste" },
1334 { 'X', CtrlKey, "Cut" },
1335 { 'A', CtrlKey, "SelectAll" },
1336 { 'Z', CtrlKey, "Undo" },
1337 { 'Z', CtrlKey | ShiftKey, "Redo" },
1340 static const KeyPressEntry keyPressEntries[] = {
1341 { '\t', 0, "InsertTab" },
1342 { '\t', ShiftKey, "InsertBacktab" },
1343 { '\r', 0, "InsertNewline" },
1344 { '\r', CtrlKey, "InsertNewline" },
1345 { '\r', AltKey, "InsertNewline" },
1346 { '\r', AltKey | ShiftKey, "InsertNewline" },
1349 const char* WebView::interpretKeyEvent(const KeyboardEvent* evt)
1351 ASSERT(evt->type() == keydownEvent || evt->type() == keypressEvent);
1353 static HashMap<int, const char*>* keyDownCommandsMap = 0;
1354 static HashMap<int, const char*>* keyPressCommandsMap = 0;
1356 if (!keyDownCommandsMap) {
1357 keyDownCommandsMap = new HashMap<int, const char*>;
1358 keyPressCommandsMap = new HashMap<int, const char*>;
1360 for (unsigned i = 0; i < _countof(keyDownEntries); i++)
1361 keyDownCommandsMap->set(keyDownEntries[i].modifiers << 16 | keyDownEntries[i].virtualKey, keyDownEntries[i].name);
1363 for (unsigned i = 0; i < _countof(keyPressEntries); i++)
1364 keyPressCommandsMap->set(keyPressEntries[i].modifiers << 16 | keyPressEntries[i].charCode, keyPressEntries[i].name);
1367 unsigned modifiers = 0;
1368 if (evt->shiftKey())
1369 modifiers |= ShiftKey;
1371 modifiers |= AltKey;
1373 modifiers |= CtrlKey;
1375 return evt->type() == keydownEvent ?
1376 keyDownCommandsMap->get(modifiers << 16 | evt->keyCode()) :
1377 keyPressCommandsMap->get(modifiers << 16 | evt->charCode());
1380 bool WebView::handleEditingKeyboardEvent(KeyboardEvent* evt)
1382 Node* node = evt->target()->toNode();
1384 Frame* frame = node->document()->frame();
1387 const PlatformKeyboardEvent* keyEvent = evt->keyEvent();
1388 if (!keyEvent || keyEvent->isSystemKey()) // do not treat this as text input if it's a system key event
1391 Editor::Command command = frame->editor()->command(interpretKeyEvent(evt));
1393 if (keyEvent->type() == PlatformKeyboardEvent::RawKeyDown) {
1394 // WebKit doesn't have enough information about mode to decide how commands that just insert text if executed via Editor should be treated,
1395 // so we leave it upon WebCore to either handle them immediately (e.g. Tab that changes focus) or let a keypress event be generated
1396 // (e.g. Tab that inserts a Tab character, or Enter).
1397 return !command.isTextInsertion() && command.execute(evt);
1400 if (command.execute(evt))
1403 // Don't insert null or control characters as they can result in unexpected behaviour
1404 if (evt->charCode() < ' ')
1407 return frame->editor()->insertText(evt->keyEvent()->text(), evt);
1410 bool WebView::keyDown(WPARAM virtualKeyCode, LPARAM keyData, bool systemKeyDown)
1412 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1413 if (virtualKeyCode == VK_CAPITAL)
1414 frame->eventHandler()->capsLockStateMayHaveChanged();
1416 PlatformKeyboardEvent keyEvent(m_viewWindow, virtualKeyCode, keyData, PlatformKeyboardEvent::RawKeyDown, systemKeyDown);
1417 bool handled = frame->eventHandler()->keyEvent(keyEvent);
1419 // These events cannot be canceled, and we have no default handling for them.
1420 // FIXME: match IE list more closely, see <http://msdn2.microsoft.com/en-us/library/ms536938.aspx>.
1425 // FIXME: remove WM_UNICHAR, too
1427 // WM_SYSCHAR events should not be removed, because access keys are implemented in WebCore in WM_SYSCHAR handler.
1429 ::PeekMessage(&msg, m_viewWindow, WM_CHAR, WM_CHAR, PM_REMOVE);
1433 // We need to handle back/forward using either Backspace(+Shift) or Ctrl+Left/Right Arrow keys.
1434 if ((virtualKeyCode == VK_BACK && keyEvent.shiftKey()) || (virtualKeyCode == VK_RIGHT && keyEvent.ctrlKey()))
1435 m_page->goForward();
1436 else if (virtualKeyCode == VK_BACK || (virtualKeyCode == VK_LEFT && keyEvent.ctrlKey()))
1439 // Need to scroll the page if the arrow keys, pgup/dn, or home/end are hit.
1440 ScrollDirection direction;
1441 ScrollGranularity granularity;
1442 switch (virtualKeyCode) {
1444 granularity = ScrollByLine;
1445 direction = ScrollLeft;
1448 granularity = ScrollByLine;
1449 direction = ScrollRight;
1452 granularity = ScrollByLine;
1453 direction = ScrollUp;
1456 granularity = ScrollByLine;
1457 direction = ScrollDown;
1460 granularity = ScrollByDocument;
1461 direction = ScrollUp;
1464 granularity = ScrollByDocument;
1465 direction = ScrollDown;
1468 granularity = ScrollByPage;
1469 direction = ScrollUp;
1472 granularity = ScrollByPage;
1473 direction = ScrollDown;
1479 if (!frame->eventHandler()->scrollOverflow(direction, granularity)) {
1480 handled = frame->view()->scroll(direction, granularity);
1481 Frame* parent = frame->tree()->parent();
1482 while(!handled && parent) {
1483 handled = parent->view()->scroll(direction, granularity);
1484 parent = parent->tree()->parent();
1490 bool WebView::keyPress(WPARAM charCode, LPARAM keyData, bool systemKeyDown)
1492 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1494 PlatformKeyboardEvent keyEvent(m_viewWindow, charCode, keyData, PlatformKeyboardEvent::Char, systemKeyDown);
1495 // IE does not dispatch keypress event for WM_SYSCHAR.
1497 return frame->eventHandler()->handleAccessKey(keyEvent);
1498 if (frame->eventHandler()->keyEvent(keyEvent))
1501 // Need to scroll the page if space is hit.
1502 if (charCode == ' ') {
1503 ScrollDirection direction = keyEvent.shiftKey() ? ScrollUp : ScrollDown;
1504 if (!frame->eventHandler()->scrollOverflow(direction, ScrollByPage))
1505 frame->view()->scroll(direction, ScrollByPage);
1511 bool WebView::inResizer(LPARAM lParam)
1513 if (!m_uiDelegatePrivate)
1517 if (FAILED(m_uiDelegatePrivate->webViewResizerRect(this, &r)))
1521 pt.x = LOWORD(lParam);
1522 pt.y = HIWORD(lParam);
1523 return !!PtInRect(&r, pt);
1526 static bool registerWebViewWindowClass()
1528 static bool haveRegisteredWindowClass = false;
1529 if (haveRegisteredWindowClass)
1532 haveRegisteredWindowClass = true;
1536 wcex.cbSize = sizeof(WNDCLASSEX);
1538 wcex.style = CS_DBLCLKS;
1539 wcex.lpfnWndProc = WebViewWndProc;
1540 wcex.cbClsExtra = 0;
1541 wcex.cbWndExtra = 4; // 4 bytes for the IWebView pointer
1542 wcex.hInstance = gInstance;
1544 wcex.hCursor = ::LoadCursor(0, IDC_ARROW);
1545 wcex.hbrBackground = 0;
1546 wcex.lpszMenuName = 0;
1547 wcex.lpszClassName = kWebViewWindowClassName;
1550 return !!RegisterClassEx(&wcex);
1554 extern HCURSOR lastSetCursor;
1557 static LRESULT CALLBACK WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1559 LRESULT lResult = 0;
1560 LONG_PTR longPtr = GetWindowLongPtr(hWnd, 0);
1561 WebView* webView = reinterpret_cast<WebView*>(longPtr);
1562 WebFrame* mainFrameImpl = webView ? webView->topLevelFrame() : 0;
1563 if (!mainFrameImpl || webView->isBeingDestroyed())
1564 return DefWindowProc(hWnd, message, wParam, lParam);
1568 // Windows Media Player has a modal message loop that will deliver messages
1569 // to us at inappropriate times and we will crash if we handle them when
1570 // they are delivered. We repost paint messages so that we eventually get
1571 // a chance to paint once the modal loop has exited, but other messages
1572 // aren't safe to repost, so we just drop them.
1573 if (PluginViewWin::isCallingPlugin()) {
1574 if (message == WM_PAINT)
1575 PostMessage(hWnd, message, wParam, lParam);
1579 bool handled = true;
1583 COMPtr<IWebDataSource> dataSource;
1584 mainFrameImpl->dataSource(&dataSource);
1585 Frame* coreFrame = core(mainFrameImpl);
1586 if (!webView->isPainting() && (!dataSource || coreFrame && (coreFrame->view()->didFirstLayout() || !coreFrame->loader()->committedFirstRealDocumentLoad())))
1587 webView->paint(0, 0);
1589 ValidateRect(hWnd, 0);
1592 case WM_PRINTCLIENT:
1593 webView->paint((HDC)wParam, lParam);
1597 webView->setIsBeingDestroyed();
1598 webView->revokeDragDrop();
1601 if (webView->inResizer(lParam))
1602 SetCursor(LoadCursor(0, IDC_SIZENWSE));
1604 case WM_LBUTTONDOWN:
1605 case WM_MBUTTONDOWN:
1606 case WM_RBUTTONDOWN:
1607 case WM_LBUTTONDBLCLK:
1608 case WM_MBUTTONDBLCLK:
1609 case WM_RBUTTONDBLCLK:
1614 if (Frame* coreFrame = core(mainFrameImpl))
1615 if (coreFrame->view()->didFirstLayout())
1616 handled = webView->handleMouseEvent(message, wParam, lParam);
1619 case WM_VISTA_MOUSEHWHEEL:
1620 if (Frame* coreFrame = core(mainFrameImpl))
1621 if (coreFrame->view()->didFirstLayout())
1622 handled = webView->mouseWheel(wParam, lParam, (wParam & MK_SHIFT) || message == WM_VISTA_MOUSEHWHEEL);
1625 handled = webView->keyDown(wParam, lParam, true);
1628 handled = webView->keyDown(wParam, lParam);
1631 handled = webView->keyUp(wParam, lParam, true);
1634 handled = webView->keyUp(wParam, lParam);
1637 handled = webView->keyPress(wParam, lParam, true);
1640 handled = webView->keyPress(wParam, lParam);
1642 // FIXME: We need to check WM_UNICHAR to support supplementary characters (that don't fit in 16 bits).
1644 if (webView->isBeingDestroyed())
1645 // If someone has sent us this message while we're being destroyed, we should bail out so we don't crash.
1649 webView->deleteBackingStore();
1650 if (Frame* coreFrame = core(mainFrameImpl))
1651 coreFrame->view()->resize(LOWORD(lParam), HIWORD(lParam));
1655 lResult = DefWindowProc(hWnd, message, wParam, lParam);
1657 // The window is being hidden (e.g., because we switched tabs.
1658 // Null out our backing store.
1659 webView->deleteBackingStore();
1662 COMPtr<IWebUIDelegate> uiDelegate;
1663 COMPtr<IWebUIDelegatePrivate> uiDelegatePrivate;
1664 if (SUCCEEDED(webView->uiDelegate(&uiDelegate)) && uiDelegate &&
1665 SUCCEEDED(uiDelegate->QueryInterface(IID_IWebUIDelegatePrivate, (void**) &uiDelegatePrivate)) && uiDelegatePrivate)
1666 uiDelegatePrivate->webViewReceivedFocus(webView);
1667 // FIXME: Merge this logic with updateActiveState, and switch this over to use updateActiveState
1669 // It's ok to just always do setWindowHasFocus, since we won't fire the focus event on the DOM
1670 // window unless the value changes. It's also ok to do setIsActive inside focus,
1671 // because Windows has no concept of having to update control tints (e.g., graphite vs. aqua)
1672 // and therefore only needs to update the selection (which is limited to the focused frame).
1673 FocusController* focusController = webView->page()->focusController();
1674 if (Frame* frame = focusController->focusedFrame()) {
1675 frame->setIsActive(true);
1677 // If the previously focused window is a child of ours (for example a plugin), don't send any
1679 if (!IsChild(hWnd, reinterpret_cast<HWND>(wParam)))
1680 frame->setWindowHasFocus(true);
1682 focusController->setFocusedFrame(webView->page()->mainFrame());
1685 case WM_KILLFOCUS: {
1686 COMPtr<IWebUIDelegate> uiDelegate;
1687 COMPtr<IWebUIDelegatePrivate> uiDelegatePrivate;
1688 HWND newFocusWnd = reinterpret_cast<HWND>(wParam);
1689 if (SUCCEEDED(webView->uiDelegate(&uiDelegate)) && uiDelegate &&
1690 SUCCEEDED(uiDelegate->QueryInterface(IID_IWebUIDelegatePrivate, (void**) &uiDelegatePrivate)) && uiDelegatePrivate)
1691 uiDelegatePrivate->webViewLostFocus(webView, (OLE_HANDLE)(ULONG64)newFocusWnd);
1692 // FIXME: Merge this logic with updateActiveState, and switch this over to use updateActiveState
1694 // However here we have to be careful. If we are losing focus because of a deactivate,
1695 // then we need to remember our focused target for restoration later.
1696 // If we are losing focus to another part of our window, then we are no longer focused for real
1697 // and we need to clear out the focused target.
1698 FocusController* focusController = webView->page()->focusController();
1699 webView->resetIME(focusController->focusedOrMainFrame());
1700 if (GetAncestor(hWnd, GA_ROOT) != newFocusWnd) {
1701 if (Frame* frame = focusController->focusedOrMainFrame()) {
1702 frame->setIsActive(false);
1704 // If we're losing focus to a child of ours, don't send blur events.
1705 if (!IsChild(hWnd, newFocusWnd))
1706 frame->setWindowHasFocus(false);
1709 focusController->setFocusedFrame(0);
1722 webView->delete_(0);
1726 handled = webView->execCommand(wParam, lParam);
1727 else // If the high word of wParam is 0, the message is from a menu
1728 webView->performContextMenuAction(wParam, lParam, false);
1730 case WM_MENUCOMMAND:
1731 webView->performContextMenuAction(wParam, lParam, true);
1733 case WM_CONTEXTMENU:
1734 handled = webView->handleContextMenuEvent(wParam, lParam);
1736 case WM_INITMENUPOPUP:
1737 handled = webView->onInitMenuPopup(wParam, lParam);
1739 case WM_MEASUREITEM:
1740 handled = webView->onMeasureItem(wParam, lParam);
1743 handled = webView->onDrawItem(wParam, lParam);
1745 case WM_UNINITMENUPOPUP:
1746 handled = webView->onUninitMenuPopup(wParam, lParam);
1748 case WM_XP_THEMECHANGED:
1749 if (Frame* coreFrame = core(mainFrameImpl)) {
1750 webView->deleteBackingStore();
1751 coreFrame->view()->themeChanged();
1754 case WM_MOUSEACTIVATE:
1755 webView->setMouseActivated(true);
1757 case WM_GETDLGCODE: {
1758 COMPtr<IWebUIDelegate> uiDelegate;
1759 COMPtr<IWebUIDelegatePrivate> uiDelegatePrivate;
1760 LONG_PTR dlgCode = 0;
1763 LPMSG lpMsg = (LPMSG)lParam;
1764 if (lpMsg->message == WM_KEYDOWN)
1765 keyCode = (UINT) lpMsg->wParam;
1767 if (SUCCEEDED(webView->uiDelegate(&uiDelegate)) && uiDelegate &&
1768 SUCCEEDED(uiDelegate->QueryInterface(IID_IWebUIDelegatePrivate, (void**) &uiDelegatePrivate)) && uiDelegatePrivate &&
1769 SUCCEEDED(uiDelegatePrivate->webViewGetDlgCode(webView, keyCode, &dlgCode)))
1775 case WM_IME_STARTCOMPOSITION:
1776 handled = webView->onIMEStartComposition();
1778 case WM_IME_REQUEST:
1779 webView->onIMERequest(wParam, lParam, &lResult);
1781 case WM_IME_COMPOSITION:
1782 handled = webView->onIMEComposition(lParam);
1784 case WM_IME_ENDCOMPOSITION:
1785 handled = webView->onIMEEndComposition();
1788 handled = webView->onIMEChar(wParam, lParam);
1791 handled = webView->onIMENotify(wParam, lParam, &lResult);
1794 handled = webView->onIMESelect(wParam, lParam);
1796 case WM_IME_SETCONTEXT:
1797 handled = webView->onIMESetContext(wParam, lParam);
1800 if (lastSetCursor) {
1801 SetCursor(lastSetCursor);
1811 lResult = DefWindowProc(hWnd, message, wParam, lParam);
1813 // Let the client know whether we consider this message handled.
1814 return (message == WM_KEYDOWN || message == WM_SYSKEYDOWN) ? !handled : lResult;
1817 bool WebView::developerExtrasEnabled() const
1819 if (m_preferences->developerExtrasDisabledByOverride())
1824 return SUCCEEDED(m_preferences->developerExtrasEnabled(&enabled)) && enabled;
1830 static String osVersion()
1833 OSVERSIONINFO versionInfo = {0};
1834 versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
1835 GetVersionEx(&versionInfo);
1837 if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
1838 if (versionInfo.dwMajorVersion == 4) {
1839 if (versionInfo.dwMinorVersion == 0)
1840 osVersion = "Windows 95";
1841 else if (versionInfo.dwMinorVersion == 10)
1842 osVersion = "Windows 98";
1843 else if (versionInfo.dwMinorVersion == 90)
1844 osVersion = "Windows 98; Win 9x 4.90";
1846 } else if (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
1847 osVersion = String::format("Windows NT %d.%d", versionInfo.dwMajorVersion, versionInfo.dwMinorVersion);
1849 if (!osVersion.length())
1850 osVersion = String::format("Windows %d.%d", versionInfo.dwMajorVersion, versionInfo.dwMinorVersion);
1855 static String webKitVersion()
1857 String versionStr = "420+";
1860 struct LANGANDCODEPAGE {
1865 TCHAR path[MAX_PATH];
1866 GetModuleFileName(gInstance, path, ARRAYSIZE(path));
1868 DWORD versionSize = GetFileVersionInfoSize(path, &handle);
1871 data = malloc(versionSize);
1874 if (!GetFileVersionInfo(path, 0, versionSize, data))
1877 if (!VerQueryValue(data, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate))
1880 _stprintf_s(key, ARRAYSIZE(key), TEXT("\\StringFileInfo\\%04x%04x\\ProductVersion"), lpTranslate[0].wLanguage, lpTranslate[0].wCodePage);
1881 LPCTSTR productVersion;
1882 UINT productVersionLength;
1883 if (!VerQueryValue(data, (LPTSTR)(LPCTSTR)key, (void**)&productVersion, &productVersionLength))
1885 versionStr = String(productVersion, productVersionLength);
1893 const String& WebView::userAgentForKURL(const KURL&)
1895 if (m_userAgentOverridden)
1896 return m_userAgentCustom;
1898 if (!m_userAgentStandard.length())
1899 m_userAgentStandard = String::format("Mozilla/5.0 (Windows; U; %s; %s) AppleWebKit/%s (KHTML, like Gecko)%s%s", osVersion().latin1().data(), defaultLanguage().latin1().data(), webKitVersion().latin1().data(), (m_applicationName.length() ? " " : ""), m_applicationName.latin1().data());
1900 return m_userAgentStandard;
1903 // IUnknown -------------------------------------------------------------------
1905 HRESULT STDMETHODCALLTYPE WebView::QueryInterface(REFIID riid, void** ppvObject)
1908 if (IsEqualGUID(riid, CLSID_WebView))
1910 else if (IsEqualGUID(riid, IID_IUnknown))
1911 *ppvObject = static_cast<IWebView*>(this);
1912 else if (IsEqualGUID(riid, IID_IWebView))
1913 *ppvObject = static_cast<IWebView*>(this);
1914 else if (IsEqualGUID(riid, IID_IWebViewPrivate))
1915 *ppvObject = static_cast<IWebViewPrivate*>(this);
1916 else if (IsEqualGUID(riid, IID_IWebIBActions))
1917 *ppvObject = static_cast<IWebIBActions*>(this);
1918 else if (IsEqualGUID(riid, IID_IWebViewCSS))
1919 *ppvObject = static_cast<IWebViewCSS*>(this);
1920 else if (IsEqualGUID(riid, IID_IWebViewEditing))
1921 *ppvObject = static_cast<IWebViewEditing*>(this);
1922 else if (IsEqualGUID(riid, IID_IWebViewUndoableEditing))
1923 *ppvObject = static_cast<IWebViewUndoableEditing*>(this);
1924 else if (IsEqualGUID(riid, IID_IWebViewEditingActions))
1925 *ppvObject = static_cast<IWebViewEditingActions*>(this);
1926 else if (IsEqualGUID(riid, IID_IWebNotificationObserver))
1927 *ppvObject = static_cast<IWebNotificationObserver*>(this);
1928 else if (IsEqualGUID(riid, IID_IDropTarget))
1929 *ppvObject = static_cast<IDropTarget*>(this);
1931 return E_NOINTERFACE;
1937 ULONG STDMETHODCALLTYPE WebView::AddRef(void)
1939 return ++m_refCount;
1942 ULONG STDMETHODCALLTYPE WebView::Release(void)
1944 ULONG newRef = --m_refCount;
1951 // IWebView --------------------------------------------------------------------
1953 HRESULT STDMETHODCALLTYPE WebView::canShowMIMEType(
1954 /* [in] */ BSTR mimeType,
1955 /* [retval][out] */ BOOL* canShow)
1957 String mimeTypeStr(mimeType, SysStringLen(mimeType));
1962 *canShow = MIMETypeRegistry::isSupportedImageMIMEType(mimeTypeStr) ||
1963 MIMETypeRegistry::isSupportedNonImageMIMEType(mimeTypeStr) ||
1964 PlugInInfoStore::supportsMIMEType(mimeTypeStr);
1969 HRESULT STDMETHODCALLTYPE WebView::canShowMIMETypeAsHTML(
1970 /* [in] */ BSTR /*mimeType*/,
1971 /* [retval][out] */ BOOL* canShow)
1978 HRESULT STDMETHODCALLTYPE WebView::MIMETypesShownAsHTML(
1979 /* [retval][out] */ IEnumVARIANT** /*enumVariant*/)
1981 ASSERT_NOT_REACHED();
1985 HRESULT STDMETHODCALLTYPE WebView::setMIMETypesShownAsHTML(
1986 /* [size_is][in] */ BSTR* /*mimeTypes*/,
1987 /* [in] */ int /*cMimeTypes*/)
1989 ASSERT_NOT_REACHED();
1993 HRESULT STDMETHODCALLTYPE WebView::URLFromPasteboard(
1994 /* [in] */ IDataObject* /*pasteboard*/,
1995 /* [retval][out] */ BSTR* /*url*/)
1997 ASSERT_NOT_REACHED();
2001 HRESULT STDMETHODCALLTYPE WebView::URLTitleFromPasteboard(
2002 /* [in] */ IDataObject* /*pasteboard*/,
2003 /* [retval][out] */ BSTR* /*urlTitle*/)
2005 ASSERT_NOT_REACHED();
2009 HRESULT STDMETHODCALLTYPE WebView::initWithFrame(
2010 /* [in] */ RECT frame,
2011 /* [in] */ BSTR frameName,
2012 /* [in] */ BSTR groupName)
2019 registerWebViewWindowClass();
2021 if (!::IsWindow(m_hostWindow)) {
2022 ASSERT_NOT_REACHED();
2026 m_viewWindow = CreateWindowEx(0, kWebViewWindowClassName, 0, WS_CHILD | WS_CLIPCHILDREN,
2027 frame.left, frame.top, frame.right - frame.left, frame.bottom - frame.top, m_hostWindow, 0, gInstance, 0);
2028 ASSERT(::IsWindow(m_viewWindow));
2030 hr = registerDragDrop();
2034 WebPreferences* sharedPreferences = WebPreferences::sharedStandardPreferences();
2035 sharedPreferences->willAddToWebView();
2036 m_preferences = sharedPreferences;
2038 m_groupName = String(groupName, SysStringLen(groupName));
2040 WebKitSetWebDatabasesPathIfNecessary();
2042 m_page = new Page(new WebChromeClient(this), new WebContextMenuClient(this), new WebEditorClient(this), new WebDragClient(this), new WebInspectorClient(this));
2045 COMPtr<IWebUIDelegate2> uiDelegate2;
2046 if (SUCCEEDED(m_uiDelegate->QueryInterface(IID_IWebUIDelegate2, (void**)&uiDelegate2))) {
2048 if (SUCCEEDED(uiDelegate2->ftpDirectoryTemplatePath(this, &path))) {
2049 m_page->settings()->setFTPDirectoryTemplatePath(String(path, SysStringLen(path)));
2050 SysFreeString(path);
2055 WebFrame* webFrame = WebFrame::createInstance();
2056 webFrame->initWithWebFrameView(0 /*FIXME*/, this, m_page, 0);
2057 m_mainFrame = webFrame;
2058 webFrame->Release(); // The WebFrame is owned by the Frame, so release our reference to it.
2059 m_page->mainFrame()->view()->attachToWindow();
2060 m_page->mainFrame()->view()->resize(frame.right - frame.left, frame.bottom - frame.top);
2062 m_page->mainFrame()->tree()->setName(String(frameName, SysStringLen(frameName)));
2063 m_page->mainFrame()->init();
2064 m_page->setGroupName(m_groupName);
2066 addToAllWebViewsSet();
2068 #pragma warning(suppress: 4244)
2069 SetWindowLongPtr(m_viewWindow, 0, (LONG_PTR)this);
2070 ShowWindow(m_viewWindow, SW_SHOW);
2072 initializeToolTipWindow();
2074 IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();
2075 notifyCenter->addObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
2076 m_preferences->postPreferencesChangesNotification();
2078 setSmartInsertDeleteEnabled(TRUE);
2082 static bool initCommonControls()
2084 static bool haveInitialized = false;
2085 if (haveInitialized)
2088 INITCOMMONCONTROLSEX init;
2089 init.dwSize = sizeof(init);
2090 init.dwICC = ICC_TREEVIEW_CLASSES;
2091 haveInitialized = !!::InitCommonControlsEx(&init);
2092 return haveInitialized;
2095 void WebView::initializeToolTipWindow()
2097 if (!initCommonControls())
2100 m_toolTipHwnd = CreateWindowEx(0, TOOLTIPS_CLASS, 0, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
2101 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
2102 m_viewWindow, 0, 0, 0);
2106 TOOLINFO info = {0};
2107 info.cbSize = sizeof(info);
2108 info.uFlags = TTF_IDISHWND | TTF_SUBCLASS ;
2109 info.uId = reinterpret_cast<UINT_PTR>(m_viewWindow);
2111 ::SendMessage(m_toolTipHwnd, TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&info));
2112 ::SendMessage(m_toolTipHwnd, TTM_SETMAXTIPWIDTH, 0, maxToolTipWidth);
2114 ::SetWindowPos(m_toolTipHwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
2117 void WebView::setToolTip(const String& toolTip)
2122 if (toolTip == m_toolTip)
2125 m_toolTip = toolTip;
2127 if (!m_toolTip.isEmpty()) {
2128 TOOLINFO info = {0};
2129 info.cbSize = sizeof(info);
2130 info.uFlags = TTF_IDISHWND;
2131 info.uId = reinterpret_cast<UINT_PTR>(m_viewWindow);
2132 info.lpszText = const_cast<UChar*>(m_toolTip.charactersWithNullTermination());
2133 ::SendMessage(m_toolTipHwnd, TTM_UPDATETIPTEXT, 0, reinterpret_cast<LPARAM>(&info));
2136 ::SendMessage(m_toolTipHwnd, TTM_ACTIVATE, !m_toolTip.isEmpty(), 0);
2139 HRESULT WebView::notifyDidAddIcon(IWebNotification* notification)
2141 COMPtr<IPropertyBag> propertyBag;
2142 HRESULT hr = notification->userInfo(&propertyBag);
2148 COMPtr<CFDictionaryPropertyBag> dictionaryPropertyBag;
2149 hr = propertyBag->QueryInterface(&dictionaryPropertyBag);
2153 CFDictionaryRef dictionary = dictionaryPropertyBag->dictionary();
2157 CFTypeRef value = CFDictionaryGetValue(dictionary, WebIconDatabase::iconDatabaseNotificationUserInfoURLKey());
2160 if (CFGetTypeID(value) != CFStringGetTypeID())
2163 String mainFrameURL;
2165 mainFrameURL = m_mainFrame->url().string();
2167 if (!mainFrameURL.isEmpty() && mainFrameURL == String((CFStringRef)value))
2168 dispatchDidReceiveIconFromWebFrame(m_mainFrame);
2173 void WebView::registerForIconNotification(bool listen)
2175 IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
2177 nc->addObserver(this, WebIconDatabase::iconDatabaseDidAddIconNotification(), 0);
2179 nc->removeObserver(this, WebIconDatabase::iconDatabaseDidAddIconNotification(), 0);
2182 void WebView::dispatchDidReceiveIconFromWebFrame(WebFrame* frame)
2184 registerForIconNotification(false);
2186 if (m_frameLoadDelegate)
2187 // FIXME: <rdar://problem/5491010> - Pass in the right HBITMAP.
2188 m_frameLoadDelegate->didReceiveIcon(this, 0, frame);
2191 HRESULT STDMETHODCALLTYPE WebView::setUIDelegate(
2192 /* [in] */ IWebUIDelegate* d)
2196 if (m_uiDelegatePrivate)
2197 m_uiDelegatePrivate = 0;
2200 if (FAILED(d->QueryInterface(IID_IWebUIDelegatePrivate, (void**)&m_uiDelegatePrivate)))
2201 m_uiDelegatePrivate = 0;
2207 HRESULT STDMETHODCALLTYPE WebView::uiDelegate(
2208 /* [out][retval] */ IWebUIDelegate** d)
2213 return m_uiDelegate.copyRefTo(d);
2216 HRESULT STDMETHODCALLTYPE WebView::setResourceLoadDelegate(
2217 /* [in] */ IWebResourceLoadDelegate* d)
2219 m_resourceLoadDelegate = d;
2223 HRESULT STDMETHODCALLTYPE WebView::resourceLoadDelegate(
2224 /* [out][retval] */ IWebResourceLoadDelegate** d)
2226 if (!m_resourceLoadDelegate)
2229 return m_resourceLoadDelegate.copyRefTo(d);
2232 HRESULT STDMETHODCALLTYPE WebView::setDownloadDelegate(
2233 /* [in] */ IWebDownloadDelegate* d)
2235 m_downloadDelegate = d;
2239 HRESULT STDMETHODCALLTYPE WebView::downloadDelegate(
2240 /* [out][retval] */ IWebDownloadDelegate** d)
2242 if (!m_downloadDelegate)
2245 return m_downloadDelegate.copyRefTo(d);
2248 HRESULT STDMETHODCALLTYPE WebView::setFrameLoadDelegate(
2249 /* [in] */ IWebFrameLoadDelegate* d)
2251 m_frameLoadDelegate = d;
2255 HRESULT STDMETHODCALLTYPE WebView::frameLoadDelegate(
2256 /* [out][retval] */ IWebFrameLoadDelegate** d)
2258 if (!m_frameLoadDelegate)
2261 return m_frameLoadDelegate.copyRefTo(d);
2264 HRESULT STDMETHODCALLTYPE WebView::setPolicyDelegate(
2265 /* [in] */ IWebPolicyDelegate* d)
2267 m_policyDelegate = d;
2271 HRESULT STDMETHODCALLTYPE WebView::policyDelegate(
2272 /* [out][retval] */ IWebPolicyDelegate** d)
2274 if (!m_policyDelegate)
2276 return m_policyDelegate.copyRefTo(d);
2279 HRESULT STDMETHODCALLTYPE WebView::mainFrame(
2280 /* [out][retval] */ IWebFrame** frame)
2283 ASSERT_NOT_REACHED();
2287 *frame = m_mainFrame;
2291 m_mainFrame->AddRef();
2295 HRESULT STDMETHODCALLTYPE WebView::focusedFrame(
2296 /* [out][retval] */ IWebFrame** frame)
2299 ASSERT_NOT_REACHED();
2304 Frame* f = m_page->focusController()->focusedFrame();
2308 WebFrame* webFrame = kit(f);
2312 return webFrame->QueryInterface(IID_IWebFrame, (void**) frame);
2314 HRESULT STDMETHODCALLTYPE WebView::backForwardList(
2315 /* [out][retval] */ IWebBackForwardList** list)
2317 if (!m_useBackForwardList)
2320 *list = WebBackForwardList::createInstance(m_page->backForwardList());
2325 HRESULT STDMETHODCALLTYPE WebView::setMaintainsBackForwardList(
2326 /* [in] */ BOOL flag)
2328 m_useBackForwardList = !!flag;
2332 HRESULT STDMETHODCALLTYPE WebView::goBack(
2333 /* [retval][out] */ BOOL* succeeded)
2335 *succeeded = m_page->goBack();
2339 HRESULT STDMETHODCALLTYPE WebView::goForward(
2340 /* [retval][out] */ BOOL* succeeded)
2342 *succeeded = m_page->goForward();
2346 HRESULT STDMETHODCALLTYPE WebView::goToBackForwardItem(
2347 /* [in] */ IWebHistoryItem* item,
2348 /* [retval][out] */ BOOL* succeeded)
2352 COMPtr<WebHistoryItem> webHistoryItem;
2353 HRESULT hr = item->QueryInterface(&webHistoryItem);
2357 m_page->goToItem(webHistoryItem->historyItem(), FrameLoadTypeIndexedBackForward);
2363 HRESULT STDMETHODCALLTYPE WebView::setTextSizeMultiplier(
2364 /* [in] */ float multiplier)
2366 if (m_textSizeMultiplier != multiplier)
2367 m_textSizeMultiplier = multiplier;
2372 m_mainFrame->setTextSizeMultiplier(multiplier);
2376 HRESULT STDMETHODCALLTYPE WebView::textSizeMultiplier(
2377 /* [retval][out] */ float* multiplier)
2379 *multiplier = m_textSizeMultiplier;
2383 HRESULT STDMETHODCALLTYPE WebView::setApplicationNameForUserAgent(
2384 /* [in] */ BSTR applicationName)
2386 m_applicationName = String(applicationName, SysStringLen(applicationName));
2387 m_userAgentStandard = String();
2391 HRESULT STDMETHODCALLTYPE WebView::applicationNameForUserAgent(
2392 /* [retval][out] */ BSTR* applicationName)
2394 *applicationName = SysAllocStringLen(m_applicationName.characters(), m_applicationName.length());
2395 if (!*applicationName && m_applicationName.length())
2396 return E_OUTOFMEMORY;
2400 HRESULT STDMETHODCALLTYPE WebView::setCustomUserAgent(
2401 /* [in] */ BSTR userAgentString)
2403 m_userAgentOverridden = userAgentString;
2404 m_userAgentCustom = String(userAgentString, SysStringLen(userAgentString));
2408 HRESULT STDMETHODCALLTYPE WebView::customUserAgent(
2409 /* [retval][out] */ BSTR* userAgentString)
2411 *userAgentString = 0;
2412 if (!m_userAgentOverridden)
2414 *userAgentString = SysAllocStringLen(m_userAgentCustom.characters(), m_userAgentCustom.length());
2415 if (!*userAgentString && m_userAgentCustom.length())
2416 return E_OUTOFMEMORY;
2420 HRESULT STDMETHODCALLTYPE WebView::userAgentForURL(
2421 /* [in] */ BSTR url,
2422 /* [retval][out] */ BSTR* userAgent)
2424 DeprecatedString urlStr((DeprecatedChar*)url, SysStringLen(url));
2425 String userAgentString = this->userAgentForKURL(KURL(urlStr));
2426 *userAgent = SysAllocStringLen(userAgentString.characters(), userAgentString.length());
2427 if (!*userAgent && userAgentString.length())
2428 return E_OUTOFMEMORY;
2432 HRESULT STDMETHODCALLTYPE WebView::supportsTextEncoding(
2433 /* [retval][out] */ BOOL* supports)
2439 HRESULT STDMETHODCALLTYPE WebView::setCustomTextEncodingName(
2440 /* [in] */ BSTR encodingName)
2447 hr = customTextEncodingName(&oldEncoding);
2451 if (oldEncoding != encodingName && (!oldEncoding || !encodingName || _tcscmp(oldEncoding, encodingName))) {
2452 if (Frame* coreFrame = core(m_mainFrame))
2453 coreFrame->loader()->reloadAllowingStaleData(String(encodingName, SysStringLen(encodingName)));
2459 HRESULT STDMETHODCALLTYPE WebView::customTextEncodingName(
2460 /* [retval][out] */ BSTR* encodingName)
2463 COMPtr<IWebDataSource> dataSource;
2464 COMPtr<WebDataSource> dataSourceImpl;
2470 if (FAILED(m_mainFrame->provisionalDataSource(&dataSource)) || !dataSource) {
2471 hr = m_mainFrame->dataSource(&dataSource);
2472 if (FAILED(hr) || !dataSource)
2476 hr = dataSource->QueryInterface(IID_WebDataSource, (void**)&dataSourceImpl);
2480 BString str = dataSourceImpl->documentLoader()->overrideEncoding();
2485 *encodingName = SysAllocStringLen(m_overrideEncoding.characters(), m_overrideEncoding.length());
2487 if (!*encodingName && m_overrideEncoding.length())
2488 return E_OUTOFMEMORY;
2493 HRESULT STDMETHODCALLTYPE WebView::setMediaStyle(
2494 /* [in] */ BSTR /*media*/)
2496 ASSERT_NOT_REACHED();
2500 HRESULT STDMETHODCALLTYPE WebView::mediaStyle(
2501 /* [retval][out] */ BSTR* /*media*/)
2503 ASSERT_NOT_REACHED();
2507 HRESULT STDMETHODCALLTYPE WebView::stringByEvaluatingJavaScriptFromString(
2508 /* [in] */ BSTR script, // assumes input does not have "JavaScript" at the begining.
2509 /* [retval][out] */ BSTR* result)
2512 ASSERT_NOT_REACHED();
2518 Frame* coreFrame = core(m_mainFrame);
2522 KJS::JSValue* scriptExecutionResult = coreFrame->loader()->executeScript(WebCore::String(script), true);
2523 if(!scriptExecutionResult)
2525 else if (scriptExecutionResult->isString()) {
2527 *result = BString(String(scriptExecutionResult->getString()));
2533 HRESULT STDMETHODCALLTYPE WebView::windowScriptObject(
2534 /* [retval][out] */ IWebScriptObject** /*webScriptObject*/)
2536 ASSERT_NOT_REACHED();
2540 HRESULT STDMETHODCALLTYPE WebView::setPreferences(
2541 /* [in] */ IWebPreferences* prefs)
2544 prefs = WebPreferences::sharedStandardPreferences();
2546 if (m_preferences == prefs)
2549 COMPtr<WebPreferences> webPrefs(Query, prefs);
2551 return E_NOINTERFACE;
2552 webPrefs->willAddToWebView();
2554 COMPtr<WebPreferences> oldPrefs = m_preferences;
2556 IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
2557 nc->removeObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
2559 BSTR identifierBSTR = 0;
2560 HRESULT hr = oldPrefs->identifier(&identifierBSTR);
2561 oldPrefs->didRemoveFromWebView();
2562 oldPrefs = 0; // Make sure we release the reference, since WebPreferences::removeReferenceForIdentifier will check for last reference to WebPreferences
2563 if (SUCCEEDED(hr)) {
2565 identifier.adoptBSTR(identifierBSTR);
2566 WebPreferences::removeReferenceForIdentifier(identifier);
2569 m_preferences = webPrefs;
2571 nc->addObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
2573 m_preferences->postPreferencesChangesNotification();
2578 HRESULT STDMETHODCALLTYPE WebView::preferences(
2579 /* [retval][out] */ IWebPreferences** prefs)
2583 *prefs = m_preferences.get();
2585 m_preferences->AddRef();
2589 HRESULT STDMETHODCALLTYPE WebView::setPreferencesIdentifier(
2590 /* [in] */ BSTR /*anIdentifier*/)
2592 ASSERT_NOT_REACHED();
2596 HRESULT STDMETHODCALLTYPE WebView::preferencesIdentifier(
2597 /* [retval][out] */ BSTR* /*anIdentifier*/)
2599 ASSERT_NOT_REACHED();
2603 HRESULT STDMETHODCALLTYPE WebView::setHostWindow(
2604 /* [in] */ OLE_HANDLE oleWindow)
2606 HWND window = (HWND)(ULONG64)oleWindow;
2607 if (m_viewWindow && window)
2608 SetParent(m_viewWindow, window);
2610 m_hostWindow = window;
2615 HRESULT STDMETHODCALLTYPE WebView::hostWindow(
2616 /* [retval][out] */ OLE_HANDLE* window)
2618 *window = (OLE_HANDLE)(ULONG64)m_hostWindow;
2623 static Frame *incrementFrame(Frame *curr, bool forward, bool wrapFlag)
2626 ? curr->tree()->traverseNextWithWrap(wrapFlag)
2627 : curr->tree()->traversePreviousWithWrap(wrapFlag);
2630 HRESULT STDMETHODCALLTYPE WebView::searchFor(
2631 /* [in] */ BSTR str,
2632 /* [in] */ BOOL forward,
2633 /* [in] */ BOOL caseFlag,
2634 /* [in] */ BOOL wrapFlag,
2635 /* [retval][out] */ BOOL* found)
2638 return E_INVALIDARG;
2640 if (!m_page || !m_page->mainFrame())
2641 return E_UNEXPECTED;
2643 if (!str || !SysStringLen(str))
2644 return E_INVALIDARG;
2646 String search(str, SysStringLen(str));
2649 WebCore::Frame* frame = m_page->focusController()->focusedOrMainFrame();
2650 WebCore::Frame* startFrame = frame;
2652 *found = frame->findString(search, !!forward, !!caseFlag, false, true);
2654 if (frame != startFrame)
2655 startFrame->selectionController()->clear();
2656 m_page->focusController()->setFocusedFrame(frame);
2659 frame = incrementFrame(frame, !!forward, !!wrapFlag);
2660 } while (frame && frame != startFrame);
2662 // Search contents of startFrame, on the other side of the selection that we did earlier.
2663 // We cheat a bit and just research with wrap on
2664 if (wrapFlag && !startFrame->selectionController()->isNone()) {
2665 *found = startFrame->findString(search, !!forward, !!caseFlag, true, true);
2666 m_page->focusController()->setFocusedFrame(frame);
2672 HRESULT STDMETHODCALLTYPE WebView::updateActiveState()
2674 Frame* frame = m_page->mainFrame();
2676 HWND window = ::GetAncestor(m_viewWindow, GA_ROOT);
2677 HWND activeWindow = ::GetActiveWindow();
2678 bool windowIsKey = window == activeWindow;
2679 activeWindow = ::GetAncestor(activeWindow, GA_ROOTOWNER);
2681 bool windowOrSheetIsKey = windowIsKey || (window == activeWindow);
2683 frame->setIsActive(windowIsKey);
2685 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
2686 frame->setWindowHasFocus(frame == focusedFrame && windowOrSheetIsKey);
2691 HRESULT STDMETHODCALLTYPE WebView::markAllMatchesForText(
2692 BSTR str, BOOL caseSensitive, BOOL highlight, UINT limit, UINT* matches)
2695 return E_INVALIDARG;
2697 if (!m_page || !m_page->mainFrame())
2698 return E_UNEXPECTED;
2700 if (!str || !SysStringLen(str))
2701 return E_INVALIDARG;
2703 String search(str, SysStringLen(str));
2706 WebCore::Frame* frame = m_page->mainFrame();
2708 frame->setMarkedTextMatchesAreHighlighted(!!highlight);
2709 *matches += frame->markAllMatchesForText(search, !!caseSensitive, (limit == 0)? 0 : (limit - *matches));
2710 frame = incrementFrame(frame, true, false);
2717 HRESULT STDMETHODCALLTYPE WebView::unmarkAllTextMatches()
2719 if (!m_page || !m_page->mainFrame())
2720 return E_UNEXPECTED;
2722 WebCore::Frame* frame = m_page->mainFrame();
2724 if (Document* document = frame->document())
2725 document->removeMarkers(DocumentMarker::TextMatch);
2726 frame = incrementFrame(frame, true, false);
2733 HRESULT STDMETHODCALLTYPE WebView::rectsForTextMatches(
2734 IEnumTextMatches** pmatches)
2736 Vector<IntRect> allRects;
2737 WebCore::Frame* frame = m_page->mainFrame();
2739 if (Document* document = frame->document()) {
2740 IntRect visibleRect = enclosingIntRect(frame->view()->visibleContentRect());
2741 Vector<IntRect> frameRects = document->renderedRectsForMarkers(DocumentMarker::TextMatch);
2742 IntPoint frameOffset(-frame->view()->scrollOffset().width(), -frame->view()->scrollOffset().height());
2743 frameOffset = frame->view()->convertToContainingWindow(frameOffset);
2745 Vector<IntRect>::iterator end = frameRects.end();
2746 for (Vector<IntRect>::iterator it = frameRects.begin(); it < end; it++) {
2747 it->intersect(visibleRect);
2748 it->move(frameOffset.x(), frameOffset.y());
2749 allRects.append(*it);
2752 frame = incrementFrame(frame, true, false);
2755 return createMatchEnumerator(&allRects, pmatches);
2758 HRESULT STDMETHODCALLTYPE WebView::generateSelectionImage(BOOL forceWhiteText, OLE_HANDLE* hBitmap)
2762 WebCore::Frame* frame = m_page->focusController()->focusedOrMainFrame();
2765 HBITMAP bitmap = imageFromSelection(frame, forceWhiteText ? TRUE : FALSE);
2766 *hBitmap = (OLE_HANDLE)(ULONG64)bitmap;
2772 HRESULT STDMETHODCALLTYPE WebView::selectionRect(RECT* rc)
2774 WebCore::Frame* frame = m_page->focusController()->focusedOrMainFrame();
2777 IntRect ir = enclosingIntRect(frame->selectionRect());
2778 ir = frame->view()->convertToContainingWindow(ir);
2779 ir.move(-frame->view()->scrollOffset().width(), -frame->view()->scrollOffset().height());
2782 rc->bottom = rc->top + ir.height();
2783 rc->right = rc->left + ir.width();
2789 HRESULT STDMETHODCALLTYPE WebView::registerViewClass(
2790 /* [in] */ IWebDocumentView* /*view*/,
2791 /* [in] */ IWebDocumentRepresentation* /*representation*/,
2792 /* [in] */ BSTR /*forMIMEType*/)
2794 ASSERT_NOT_REACHED();
2798 HRESULT STDMETHODCALLTYPE WebView::setGroupName(
2799 /* [in] */ BSTR groupName)
2801 m_groupName = String(groupName, SysStringLen(groupName));
2805 HRESULT STDMETHODCALLTYPE WebView::groupName(
2806 /* [retval][out] */ BSTR* groupName)
2808 *groupName = SysAllocStringLen(m_groupName.characters(), m_groupName.length());
2809 if (!*groupName && m_groupName.length())
2810 return E_OUTOFMEMORY;
2814 HRESULT STDMETHODCALLTYPE WebView::estimatedProgress(
2815 /* [retval][out] */ double* estimatedProgress)
2817 *estimatedProgress = m_page->progress()->estimatedProgress();
2821 HRESULT STDMETHODCALLTYPE WebView::isLoading(
2822 /* [retval][out] */ BOOL* isLoading)
2824 COMPtr<IWebDataSource> dataSource;
2825 COMPtr<IWebDataSource> provisionalDataSource;
2832 if (SUCCEEDED(m_mainFrame->dataSource(&dataSource)))
2833 dataSource->isLoading(isLoading);
2838 if (SUCCEEDED(m_mainFrame->provisionalDataSource(&provisionalDataSource)))
2839 provisionalDataSource->isLoading(isLoading);
2843 HRESULT STDMETHODCALLTYPE WebView::elementAtPoint(
2844 /* [in] */ LPPOINT point,
2845 /* [retval][out] */ IPropertyBag** elementDictionary)
2847 if (!elementDictionary) {
2848 ASSERT_NOT_REACHED();
2852 *elementDictionary = 0;
2854 Frame* frame = core(m_mainFrame);
2858 IntPoint webCorePoint = IntPoint(point->x, point->y);
2859 HitTestResult result = HitTestResult(webCorePoint);
2860 if (frame->renderer())
2861 result = frame->eventHandler()->hitTestResultAtPoint(webCorePoint, false);
2862 *elementDictionary = WebElementPropertyBag::createInstance(result);
2866 HRESULT STDMETHODCALLTYPE WebView::pasteboardTypesForSelection(
2867 /* [retval][out] */ IEnumVARIANT** /*enumVariant*/)
2869 ASSERT_NOT_REACHED();
2873 HRESULT STDMETHODCALLTYPE WebView::writeSelectionWithPasteboardTypes(
2874 /* [size_is][in] */ BSTR* /*types*/,
2875 /* [in] */ int /*cTypes*/,
2876 /* [in] */ IDataObject* /*pasteboard*/)
2878 ASSERT_NOT_REACHED();
2882 HRESULT STDMETHODCALLTYPE WebView::pasteboardTypesForElement(
2883 /* [in] */ IPropertyBag* /*elementDictionary*/,
2884 /* [retval][out] */ IEnumVARIANT** /*enumVariant*/)
2886 ASSERT_NOT_REACHED();
2890 HRESULT STDMETHODCALLTYPE WebView::writeElement(
2891 /* [in] */ IPropertyBag* /*elementDictionary*/,
2892 /* [size_is][in] */ BSTR* /*withPasteboardTypes*/,
2893 /* [in] */ int /*cWithPasteboardTypes*/,
2894 /* [in] */ IDataObject* /*pasteboard*/)
2896 ASSERT_NOT_REACHED();
2900 HRESULT STDMETHODCALLTYPE WebView::selectedText(
2901 /* [out, retval] */ BSTR* text)
2904 ASSERT_NOT_REACHED();
2910 Frame* focusedFrame = (m_page && m_page->focusController()) ? m_page->focusController()->focusedOrMainFrame() : 0;
2914 String frameSelectedText = focusedFrame->selectedText();
2915 *text = SysAllocStringLen(frameSelectedText.characters(), frameSelectedText.length());
2916 if (!*text && frameSelectedText.length())
2917 return E_OUTOFMEMORY;
2921 HRESULT STDMETHODCALLTYPE WebView::centerSelectionInVisibleArea(
2922 /* [in] */ IUnknown* /* sender */)
2924 Frame* coreFrame = core(m_mainFrame);
2928 coreFrame->revealSelection(RenderLayer::gAlignCenterAlways);
2933 HRESULT STDMETHODCALLTYPE WebView::moveDragCaretToPoint(
2934 /* [in] */ LPPOINT /*point*/)
2936 ASSERT_NOT_REACHED();
2940 HRESULT STDMETHODCALLTYPE WebView::removeDragCaret( void)
2942 ASSERT_NOT_REACHED();
2946 HRESULT STDMETHODCALLTYPE WebView::setDrawsBackground(
2947 /* [in] */ BOOL /*drawsBackground*/)
2949 ASSERT_NOT_REACHED();
2953 HRESULT STDMETHODCALLTYPE WebView::drawsBackground(
2954 /* [retval][out] */ BOOL* /*drawsBackground*/)
2956 ASSERT_NOT_REACHED();
2960 HRESULT STDMETHODCALLTYPE WebView::setMainFrameURL(
2961 /* [in] */ BSTR /*urlString*/)
2963 ASSERT_NOT_REACHED();
2967 HRESULT STDMETHODCALLTYPE WebView::mainFrameURL(
2968 /* [retval][out] */ BSTR* /*urlString*/)
2970 ASSERT_NOT_REACHED();
2974 HRESULT STDMETHODCALLTYPE WebView::mainFrameDocument(
2975 /* [retval][out] */ IDOMDocument** document)
2981 return m_mainFrame->DOMDocument(document);
2984 HRESULT STDMETHODCALLTYPE WebView::mainFrameTitle(
2985 /* [retval][out] */ BSTR* /*title*/)
2987 ASSERT_NOT_REACHED();
2991 HRESULT STDMETHODCALLTYPE WebView::mainFrameIcon(
2992 /* [retval][out] */ OLE_HANDLE* /*hBitmap*/)
2994 ASSERT_NOT_REACHED();
2998 HRESULT STDMETHODCALLTYPE WebView::registerURLSchemeAsLocal(
2999 /* [in] */ BSTR scheme)
3004 FrameLoader::registerURLSchemeAsLocal(String(scheme, ::SysStringLen(scheme)));
3009 // IWebIBActions ---------------------------------------------------------------
3011 HRESULT STDMETHODCALLTYPE WebView::takeStringURLFrom(
3012 /* [in] */ IUnknown* /*sender*/)
3014 ASSERT_NOT_REACHED();
3018 HRESULT STDMETHODCALLTYPE WebView::stopLoading(
3019 /* [in] */ IUnknown* /*sender*/)
3024 return m_mainFrame->stopLoading();
3027 HRESULT STDMETHODCALLTYPE WebView::reload(
3028 /* [in] */ IUnknown* /*sender*/)
3033 return m_mainFrame->reload();
3036 HRESULT STDMETHODCALLTYPE WebView::canGoBack(
3037 /* [in] */ IUnknown* /*sender*/,
3038 /* [retval][out] */ BOOL* result)
3040 *result = !!m_page->backForwardList()->backItem();
3044 HRESULT STDMETHODCALLTYPE WebView::goBack(
3045 /* [in] */ IUnknown* /*sender*/)
3047 ASSERT_NOT_REACHED();
3051 HRESULT STDMETHODCALLTYPE WebView::canGoForward(
3052 /* [in] */ IUnknown* /*sender*/,
3053 /* [retval][out] */ BOOL* result)
3055 *result = !!m_page->backForwardList()->forwardItem();
3059 HRESULT STDMETHODCALLTYPE WebView::goForward(
3060 /* [in] */ IUnknown* /*sender*/)
3062 ASSERT_NOT_REACHED();
3066 #define MinimumTextSizeMultiplier 0.5f
3067 #define MaximumTextSizeMultiplier 3.0f
3068 #define TextSizeMultiplierRatio 1.2f
3070 HRESULT STDMETHODCALLTYPE WebView::canMakeTextLarger(
3071 /* [in] */ IUnknown* /*sender*/,
3072 /* [retval][out] */ BOOL* result)
3074 bool canGrowMore = m_textSizeMultiplier*TextSizeMultiplierRatio < MaximumTextSizeMultiplier;
3075 *result = canGrowMore ? TRUE : FALSE;
3079 HRESULT STDMETHODCALLTYPE WebView::makeTextLarger(
3080 /* [in] */ IUnknown* /*sender*/)
3082 float newScale = m_textSizeMultiplier*TextSizeMultiplierRatio;
3083 bool canGrowMore = newScale < MaximumTextSizeMultiplier;
3086 return setTextSizeMultiplier(newScale);
3090 HRESULT STDMETHODCALLTYPE WebView::canMakeTextSmaller(
3091 /* [in] */ IUnknown* /*sender*/,
3092 /* [retval][out] */ BOOL* result)
3094 bool canShrinkMore = m_textSizeMultiplier/TextSizeMultiplierRatio > MinimumTextSizeMultiplier;
3095 *result = canShrinkMore ? TRUE : FALSE;
3099 HRESULT STDMETHODCALLTYPE WebView::makeTextSmaller(
3100 /* [in] */ IUnknown* /*sender*/)
3102 float newScale = m_textSizeMultiplier/TextSizeMultiplierRatio;
3103 bool canShrinkMore = newScale > MinimumTextSizeMultiplier;
3106 return setTextSizeMultiplier(newScale);
3109 HRESULT STDMETHODCALLTYPE WebView::canMakeTextStandardSize(
3110 /* [in] */ IUnknown* /*sender*/,
3111 /* [retval][out] */ BOOL* result)
3113 bool notAlreadyStandard = m_textSizeMultiplier != 1.0f;
3114 *result = notAlreadyStandard ? TRUE : FALSE;
3118 HRESULT STDMETHODCALLTYPE WebView::makeTextStandardSize(
3119 /* [in] */ IUnknown* /*sender*/)
3121 bool notAlreadyStandard = m_textSizeMultiplier != 1.0f;
3122 if (notAlreadyStandard)
3123 return setTextSizeMultiplier(1.0f);
3127 HRESULT STDMETHODCALLTYPE WebView::toggleContinuousSpellChecking(
3128 /* [in] */ IUnknown* /*sender*/)
3132 if (FAILED(hr = isContinuousSpellCheckingEnabled(&enabled)))
3134 return setContinuousSpellCheckingEnabled(enabled ? FALSE : TRUE);
3137 HRESULT STDMETHODCALLTYPE WebView::toggleSmartInsertDelete(
3138 /* [in] */ IUnknown* /*sender*/)
3140 BOOL enabled = FALSE;
3141 HRESULT hr = smartInsertDeleteEnabled(&enabled);
3145 return setSmartInsertDeleteEnabled(enabled ? FALSE : TRUE);
3148 HRESULT STDMETHODCALLTYPE WebView::toggleGrammarChecking(
3149 /* [in] */ IUnknown* /*sender*/)
3152 HRESULT hr = isGrammarCheckingEnabled(&enabled);
3156 return setGrammarCheckingEnabled(enabled ? FALSE : TRUE);
3159 // IWebViewCSS -----------------------------------------------------------------
3161 HRESULT STDMETHODCALLTYPE WebView::computedStyleForElement(
3162 /* [in] */ IDOMElement* /*element*/,
3163 /* [in] */ BSTR /*pseudoElement*/,
3164 /* [retval][out] */ IDOMCSSStyleDeclaration** /*style*/)
3166 ASSERT_NOT_REACHED();
3170 // IWebViewEditing -------------------------------------------------------------
3172 HRESULT STDMETHODCALLTYPE WebView::editableDOMRangeForPoint(
3173 /* [in] */ LPPOINT /*point*/,
3174 /* [retval][out] */ IDOMRange** /*range*/)
3176 ASSERT_NOT_REACHED();
3180 HRESULT STDMETHODCALLTYPE WebView::setSelectedDOMRange(
3181 /* [in] */ IDOMRange* /*range*/,
3182 /* [in] */ WebSelectionAffinity /*affinity*/)
3184 ASSERT_NOT_REACHED();
3188 HRESULT STDMETHODCALLTYPE WebView::selectedDOMRange(
3189 /* [retval][out] */ IDOMRange** /*range*/)
3191 ASSERT_NOT_REACHED();
3195 HRESULT STDMETHODCALLTYPE WebView::selectionAffinity(
3196 /* [retval][out][retval][out] */ WebSelectionAffinity* /*affinity*/)
3198 ASSERT_NOT_REACHED();
3202 HRESULT STDMETHODCALLTYPE WebView::setEditable(
3203 /* [in] */ BOOL /*flag*/)
3205 ASSERT_NOT_REACHED();
3209 HRESULT STDMETHODCALLTYPE WebView::isEditable(
3210 /* [retval][out] */ BOOL* /*isEditable*/)
3212 ASSERT_NOT_REACHED();
3216 HRESULT STDMETHODCALLTYPE WebView::setTypingStyle(
3217 /* [in] */ IDOMCSSStyleDeclaration* /*style*/)
3219 ASSERT_NOT_REACHED();
3223 HRESULT STDMETHODCALLTYPE WebView::typingStyle(
3224 /* [retval][out] */ IDOMCSSStyleDeclaration** /*style*/)
3226 ASSERT_NOT_REACHED();
3230 HRESULT STDMETHODCALLTYPE WebView::setSmartInsertDeleteEnabled(
3231 /* [in] */ BOOL flag)
3233 m_smartInsertDeleteEnabled = !!flag;
3237 HRESULT STDMETHODCALLTYPE WebView::smartInsertDeleteEnabled(
3238 /* [retval][out] */ BOOL* enabled)
3240 *enabled = m_smartInsertDeleteEnabled ? TRUE : FALSE;
3244 HRESULT STDMETHODCALLTYPE WebView::setContinuousSpellCheckingEnabled(
3245 /* [in] */ BOOL flag)
3247 if (continuousSpellCheckingEnabled != !!flag) {
3248 continuousSpellCheckingEnabled = !!flag;
3249 COMPtr<IWebPreferences> prefs;
3250 if (SUCCEEDED(preferences(&prefs)))
3251 prefs->setContinuousSpellCheckingEnabled(flag);
3254 BOOL spellCheckingEnabled;
3255 if (SUCCEEDED(isContinuousSpellCheckingEnabled(&spellCheckingEnabled)) && spellCheckingEnabled)
3256 preflightSpellChecker();
3258 m_mainFrame->unmarkAllMisspellings();
3263 HRESULT STDMETHODCALLTYPE WebView::isContinuousSpellCheckingEnabled(
3264 /* [retval][out] */ BOOL* enabled)
3266 *enabled = (continuousSpellCheckingEnabled && continuousCheckingAllowed()) ? TRUE : FALSE;
3270 HRESULT STDMETHODCALLTYPE WebView::spellCheckerDocumentTag(
3271 /* [retval][out] */ int* tag)
3273 // we just use this as a flag to indicate that we've spell checked the document
3274 // and need to close the spell checker out when the view closes.
3276 m_hasSpellCheckerDocumentTag = true;
3280 static COMPtr<IWebEditingDelegate> spellingDelegateForTimer;
3282 static void preflightSpellCheckerNow()
3284 spellingDelegateForTimer->preflightChosenSpellServer();
3285 spellingDelegateForTimer = 0;
3288 static void CALLBACK preflightSpellCheckerTimerCallback(HWND, UINT, UINT_PTR id, DWORD)
3291 preflightSpellCheckerNow();
3294 void WebView::preflightSpellChecker()
3296 // As AppKit does, we wish to delay tickling the shared spellchecker into existence on application launch.
3297 if (!m_editingDelegate)
3301 spellingDelegateForTimer = m_editingDelegate;
3302 if (SUCCEEDED(m_editingDelegate->sharedSpellCheckerExists(&exists)) && exists)
3303 preflightSpellCheckerNow();
3305 ::SetTimer(0, 0, 2000, preflightSpellCheckerTimerCallback);
3308 bool WebView::continuousCheckingAllowed()
3310 static bool allowContinuousSpellChecking = true;
3311 static bool readAllowContinuousSpellCheckingDefault = false;
3312 if (!readAllowContinuousSpellCheckingDefault) {
3313 COMPtr<IWebPreferences> prefs;
3314 if (SUCCEEDED(preferences(&prefs))) {
3316 prefs->allowContinuousSpellChecking(&allowed);
3317 allowContinuousSpellChecking = !!allowed;
3319 readAllowContinuousSpellCheckingDefault = true;
3321 return allowContinuousSpellChecking;
3324 HRESULT STDMETHODCALLTYPE WebView::undoManager(
3325 /* [retval][out] */ IWebUndoManager** /*manager*/)
3327 ASSERT_NOT_REACHED();
3331 HRESULT STDMETHODCALLTYPE WebView::setEditingDelegate(
3332 /* [in] */ IWebEditingDelegate* d)
3334 m_editingDelegate = d;
3338 HRESULT STDMETHODCALLTYPE WebView::editingDelegate(
3339 /* [retval][out] */ IWebEditingDelegate** d)
3342 ASSERT_NOT_REACHED();
3346 *d = m_editingDelegate.get();
3354 HRESULT STDMETHODCALLTYPE WebView::styleDeclarationWithText(
3355 /* [in] */ BSTR /*text*/,
3356 /* [retval][out] */ IDOMCSSStyleDeclaration** /*style*/)
3358 ASSERT_NOT_REACHED();
3362 HRESULT STDMETHODCALLTYPE WebView::hasSelectedRange(
3363 /* [retval][out] */ BOOL* hasSelectedRange)
3365 *hasSelectedRange = m_page->mainFrame()->selectionController()->isRange();
3369 HRESULT STDMETHODCALLTYPE WebView::cutEnabled(
3370 /* [retval][out] */ BOOL* enabled)
3372 Editor* editor = m_page->focusController()->focusedOrMainFrame()->editor();
3373 *enabled = editor->canCut() || editor->canDHTMLCut();
3377 HRESULT STDMETHODCALLTYPE WebView::copyEnabled(
3378 /* [retval][out] */ BOOL* enabled)
3380 Editor* editor = m_page->focusController()->focusedOrMainFrame()->editor();
3381 *enabled = editor->canCopy() || editor->canDHTMLCopy();
3385 HRESULT STDMETHODCALLTYPE WebView::pasteEnabled(
3386 /* [retval][out] */ BOOL* enabled)
3388 Editor* editor = m_page->focusController()->focusedOrMainFrame()->editor();
3389 *enabled = editor->canPaste() || editor->canDHTMLPaste();
3393 HRESULT STDMETHODCALLTYPE WebView::deleteEnabled(
3394 /* [retval][out] */ BOOL* enabled)
3396 *enabled = m_page->focusController()->focusedOrMainFrame()->editor()->canDelete();
3400 HRESULT STDMETHODCALLTYPE WebView::editingEnabled(
3401 /* [retval][out] */ BOOL* enabled)
3403 *enabled = m_page->focusController()->focusedOrMainFrame()->editor()->canEdit();
3407 HRESULT STDMETHODCALLTYPE WebView::isGrammarCheckingEnabled(
3408 /* [retval][out] */ BOOL* enabled)
3410 *enabled = grammarCheckingEnabled ? TRUE : FALSE;
3414 HRESULT STDMETHODCALLTYPE WebView::setGrammarCheckingEnabled(
3417 if (!m_editingDelegate) {
3418 LOG_ERROR("No NSSpellChecker");
3422 if (grammarCheckingEnabled == !!enabled)
3425 grammarCheckingEnabled = !!enabled;
3426 COMPtr<IWebPreferences> prefs;
3427 if (SUCCEEDED(preferences(&prefs)))
3428 prefs->setGrammarCheckingEnabled(enabled);
3430 m_editingDelegate->updateGrammar();
3432 // We call _preflightSpellChecker when turning continuous spell checking on, but we don't need to do that here
3433 // because grammar checking only occurs on code paths that already preflight spell checking appropriately.
3435 BOOL grammarEnabled;
3436 if (SUCCEEDED(isGrammarCheckingEnabled(&grammarEnabled)) && !grammarEnabled)
3437 m_mainFrame->unmarkAllBadGrammar();
3442 // IWebViewUndoableEditing -----------------------------------------------------
3444 HRESULT STDMETHODCALLTYPE WebView::replaceSelectionWithNode(
3445 /* [in] */ IDOMNode* /*node*/)
3447 ASSERT_NOT_REACHED();
3451 HRESULT STDMETHODCALLTYPE WebView::replaceSelectionWithText(
3452 /* [in] */ BSTR text)
3454 String textString(text, ::SysStringLen(text));
3455 Position start = m_page->mainFrame()->selectionController()->selection().start();
3456 m_page->focusController()->focusedOrMainFrame()->editor()->insertText(textString, 0);
3457 m_page->mainFrame()->selectionController()->setBase(start);
3461 HRESULT STDMETHODCALLTYPE WebView::replaceSelectionWithMarkupString(
3462 /* [in] */ BSTR /*markupString*/)
3464 ASSERT_NOT_REACHED();
3468 HRESULT STDMETHODCALLTYPE WebView::replaceSelectionWithArchive(
3469 /* [in] */ IWebArchive* /*archive*/)
3471 ASSERT_NOT_REACHED();
3475 HRESULT STDMETHODCALLTYPE WebView::deleteSelection( void)
3477 Editor* editor = m_page->focusController()->focusedOrMainFrame()->editor();
3478 editor->deleteSelectionWithSmartDelete(editor->canSmartCopyOrDelete());
3482 HRESULT STDMETHODCALLTYPE WebView::clearSelection( void)
3484 m_page->focusController()->focusedOrMainFrame()->selectionController()->clear();
3488 HRESULT STDMETHODCALLTYPE WebView::applyStyle(
3489 /* [in] */ IDOMCSSStyleDeclaration* /*style*/)
3491 ASSERT_NOT_REACHED();
3495 // IWebViewEditingActions ------------------------------------------------------
3497 HRESULT STDMETHODCALLTYPE WebView::copy(
3498 /* [in] */ IUnknown* /*sender*/)
3500 m_page->focusController()->focusedOrMainFrame()->editor()->command("Copy").execute();
3504 HRESULT STDMETHODCALLTYPE WebView::cut(
3505 /* [in] */ IUnknown* /*sender*/)
3507 m_page->focusController()->focusedOrMainFrame()->editor()->command("Cut").execute();
3511 HRESULT STDMETHODCALLTYPE WebView::paste(
3512 /* [in] */ IUnknown* /*sender*/)
3514 m_page->focusController()->focusedOrMainFrame()->editor()->command("Paste").execute();
3518 HRESULT STDMETHODCALLTYPE WebView::copyURL(
3519 /* [in] */ BSTR url)
3521 String temp(url, SysStringLen(url));
3522 m_page->focusController()->focusedOrMainFrame()->editor()->copyURL(KURL(temp.deprecatedString()), "");
3527 HRESULT STDMETHODCALLTYPE WebView::copyFont(
3528 /* [in] */ IUnknown* /*sender*/)
3530 ASSERT_NOT_REACHED();
3534 HRESULT STDMETHODCALLTYPE WebView::pasteFont(
3535 /* [in] */ IUnknown* /*sender*/)
3537 ASSERT_NOT_REACHED();
3541 HRESULT STDMETHODCALLTYPE WebView::delete_(
3542 /* [in] */ IUnknown* /*sender*/)
3544 m_page->focusController()->focusedOrMainFrame()->editor()->command("Delete").execute();
3548 HRESULT STDMETHODCALLTYPE WebView::pasteAsPlainText(
3549 /* [in] */ IUnknown* /*sender*/)
3551 ASSERT_NOT_REACHED();
3555 HRESULT STDMETHODCALLTYPE WebView::pasteAsRichText(
3556 /* [in] */ IUnknown* /*sender*/)
3558 ASSERT_NOT_REACHED();
3562 HRESULT STDMETHODCALLTYPE WebView::changeFont(
3563 /* [in] */ IUnknown* /*sender*/)
3565 ASSERT_NOT_REACHED();
3569 HRESULT STDMETHODCALLTYPE WebView::changeAttributes(
3570 /* [in] */ IUnknown* /*sender*/)
3572 ASSERT_NOT_REACHED();
3576 HRESULT STDMETHODCALLTYPE WebView::changeDocumentBackgroundColor(
3577 /* [in] */ IUnknown* /*sender*/)
3579 ASSERT_NOT_REACHED();
3583 HRESULT STDMETHODCALLTYPE WebView::changeColor(
3584 /* [in] */ IUnknown* /*sender*/)
3586 ASSERT_NOT_REACHED();
3590 HRESULT STDMETHODCALLTYPE WebView::alignCenter(
3591 /* [in] */ IUnknown* /*sender*/)
3593 ASSERT_NOT_REACHED();
3597 HRESULT STDMETHODCALLTYPE WebView::alignJustified(
3598 /* [in] */ IUnknown* /*sender*/)
3600 ASSERT_NOT_REACHED();
3604 HRESULT STDMETHODCALLTYPE WebView::alignLeft(
3605 /* [in] */ IUnknown* /*sender*/)
3607 ASSERT_NOT_REACHED();
3611 HRESULT STDMETHODCALLTYPE WebView::alignRight(
3612 /* [in] */ IUnknown* /*sender*/)
3614 ASSERT_NOT_REACHED();
3618 HRESULT STDMETHODCALLTYPE WebView::checkSpelling(
3619 /* [in] */ IUnknown* /*sender*/)
3621 if (!m_editingDelegate) {
3622 LOG_ERROR("No NSSpellChecker");
3626 core(m_mainFrame)->editor()->advanceToNextMisspelling();
3630 HRESULT STDMETHODCALLTYPE WebView::showGuessPanel(
3631 /* [in] */ IUnknown* /*sender*/)
3633 if (!m_editingDelegate) {
3634 LOG_ERROR("No NSSpellChecker");
3638 // Post-Tiger, this menu item is a show/hide toggle, to match AppKit. Leave Tiger behavior alone
3639 // to match rest of OS X.
3641 if (SUCCEEDED(m_editingDelegate->spellingUIIsShowing(&showing)) && showing) {
3642 m_editingDelegate->showSpellingUI(FALSE);
3645 core(m_mainFrame)->editor()->advanceToNextMisspelling(true);
3646 m_editingDelegate->showSpellingUI(TRUE);
3650 HRESULT STDMETHODCALLTYPE WebView::performFindPanelAction(
3651 /* [in] */ IUnknown* /*sender*/)
3653 ASSERT_NOT_REACHED();
3657 HRESULT STDMETHODCALLTYPE WebView::startSpeaking(
3658 /* [in] */ IUnknown* /*sender*/)
3660 ASSERT_NOT_REACHED();
3664 HRESULT STDMETHODCALLTYPE WebView::stopSpeaking(
3665 /* [in] */ IUnknown* /*sender*/)
3667 ASSERT_NOT_REACHED();
3671 // IWebNotificationObserver -----------------------------------------------------------------
3673 HRESULT STDMETHODCALLTYPE WebView::onNotify(
3674 /* [in] */ IWebNotification* notification)
3677 HRESULT hr = notification->name(&nameBSTR);
3682 name.adoptBSTR(nameBSTR);
3684 if (!wcscmp(name, WebIconDatabase::iconDatabaseDidAddIconNotification()))
3685 return notifyDidAddIcon(notification);
3687 if (!wcscmp(name, WebPreferences::webPreferencesChangedNotification()))
3688 return notifyPreferencesChanged(notification);
3693 HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification)
3697 COMPtr<IUnknown> unkPrefs;
3698 hr = notification->getObject(&unkPrefs);
3702 COMPtr<IWebPreferences> preferences(Query, unkPrefs);
3704 return E_NOINTERFACE;
3706 ASSERT(preferences == m_preferences);
3712 Settings* settings = m_page->settings();
3714 hr = preferences->cursiveFontFamily(&str);
3717 settings->setCursiveFontFamily(AtomicString(str, SysStringLen(str)));
3720 hr = preferences->defaultFixedFontSize(&size);
3723 settings->setDefaultFixedFontSize(size);
3725 hr = preferences->defaultFontSize(&size);
3728 settings->setDefaultFontSize(size);
3730 hr = preferences->defaultTextEncodingName(&str);
3733 settings->setDefaultTextEncodingName(String(str, SysStringLen(str)));
3736 hr = preferences->fantasyFontFamily(&str);