1/* 2 * Copyright (C) 2006, 2007, 2011, 2013 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE 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 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. 24 */ 25 26#ifndef WebFrame_H 27#define WebFrame_H 28 29#include "WebKit.h" 30#include "WebDataSource.h" 31 32#include "AccessibleDocument.h" 33 34#include <WebCore/AdjustViewSizeOrNot.h> 35#include <WebCore/FrameWin.h> 36#include <WebCore/GraphicsContext.h> 37#include <WebCore/URL.h> 38#include <WebCore/ResourceHandleClient.h> 39 40#include <WTF/RefPtr.h> 41#include <WTF/HashMap.h> 42#include <WTF/OwnPtr.h> 43#include <wtf/text/WTFString.h> 44 45namespace WebCore { 46 class AuthenticationChallenge; 47 class DocumentLoader; 48 class Element; 49 class FloatSize; 50 class Frame; 51 class GraphicsContext; 52 class HTMLFrameOwnerElement; 53 class IntRect; 54 class Page; 55 class ResourceError; 56 class SharedBuffer; 57} 58 59typedef const struct OpaqueJSContext* JSContextRef; 60typedef struct OpaqueJSValue* JSObjectRef; 61 62#if USE(CG) 63typedef struct CGContext PlatformGraphicsContext; 64#elif USE(CAIRO) 65namespace WebCore { 66class PlatformContextCairo; 67} 68typedef class WebCore::PlatformContextCairo PlatformGraphicsContext; 69#endif 70 71class WebFrame; 72class WebFramePolicyListener; 73class WebHistory; 74class WebView; 75 76interface IWebHistoryItemPrivate; 77 78WebFrame* kit(WebCore::Frame*); 79WebCore::Frame* core(WebFrame*); 80 81class DECLSPEC_UUID("{A3676398-4485-4a9d-87DC-CB5A40E6351D}") WebFrame : public IWebFrame, IWebFramePrivate, IWebDocumentText 82{ 83public: 84 static WebFrame* createInstance(); 85protected: 86 WebFrame(); 87 ~WebFrame(); 88 89public: 90 // IUnknown 91 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); 92 virtual ULONG STDMETHODCALLTYPE AddRef(void); 93 virtual ULONG STDMETHODCALLTYPE Release(void); 94 95 //IWebFrame 96 virtual HRESULT STDMETHODCALLTYPE name( 97 /* [retval][out] */ BSTR *frameName); 98 99 virtual HRESULT STDMETHODCALLTYPE webView( 100 /* [retval][out] */ IWebView **view); 101 102 virtual HRESULT STDMETHODCALLTYPE frameView( 103 /* [retval][out] */ IWebFrameView **view); 104 105 virtual HRESULT STDMETHODCALLTYPE DOMDocument( 106 /* [retval][out] */ IDOMDocument** document); 107 108 virtual HRESULT STDMETHODCALLTYPE DOMWindow(/* [retval][out] */ IDOMWindow**); 109 110 virtual HRESULT STDMETHODCALLTYPE frameElement( 111 /* [retval][out] */ IDOMHTMLElement **frameElement); 112 113 virtual HRESULT STDMETHODCALLTYPE loadRequest( 114 /* [in] */ IWebURLRequest *request); 115 116 virtual HRESULT STDMETHODCALLTYPE loadData( 117 /* [in] */ IStream *data, 118 /* [in] */ BSTR mimeType, 119 /* [in] */ BSTR textEncodingName, 120 /* [in] */ BSTR url); 121 122 virtual HRESULT STDMETHODCALLTYPE loadHTMLString( 123 /* [in] */ BSTR string, 124 /* [in] */ BSTR baseURL); 125 126 virtual HRESULT STDMETHODCALLTYPE loadAlternateHTMLString( 127 /* [in] */ BSTR str, 128 /* [in] */ BSTR baseURL, 129 /* [in] */ BSTR unreachableURL); 130 131 virtual HRESULT STDMETHODCALLTYPE loadArchive( 132 /* [in] */ IWebArchive *archive); 133 134 virtual HRESULT STDMETHODCALLTYPE dataSource( 135 /* [retval][out] */ IWebDataSource **source); 136 137 virtual HRESULT STDMETHODCALLTYPE provisionalDataSource( 138 /* [retval][out] */ IWebDataSource **source); 139 140 virtual HRESULT STDMETHODCALLTYPE stopLoading( void); 141 142 virtual HRESULT STDMETHODCALLTYPE reload( void); 143 144 virtual HRESULT STDMETHODCALLTYPE findFrameNamed( 145 /* [in] */ BSTR name, 146 /* [retval][out] */ IWebFrame **frame); 147 148 virtual HRESULT STDMETHODCALLTYPE parentFrame( 149 /* [retval][out] */ IWebFrame **frame); 150 151 virtual HRESULT STDMETHODCALLTYPE childFrames( 152 /* [retval][out] */ IEnumVARIANT **enumFrames); 153 154 virtual HRESULT STDMETHODCALLTYPE currentForm( 155 /* [retval][out] */ IDOMElement **formElement); 156 157 virtual /* [local] */ JSGlobalContextRef STDMETHODCALLTYPE globalContext(); 158 159 // IWebFramePrivate 160 virtual HRESULT STDMETHODCALLTYPE unused1() { return E_NOTIMPL; } 161 virtual HRESULT STDMETHODCALLTYPE renderTreeAsExternalRepresentation(BOOL forPrinting, BSTR *result); 162 163 virtual HRESULT STDMETHODCALLTYPE pageNumberForElementById( 164 /* [in] */ BSTR id, 165 /* [in] */ float pageWidthInPixels, 166 /* [in] */ float pageHeightInPixels, 167 /* [retval][out] */ int* result); 168 169 virtual HRESULT STDMETHODCALLTYPE numberOfPages( 170 /* [in] */ float pageWidthInPixels, 171 /* [in] */ float pageHeightInPixels, 172 /* [retval][out] */ int* result); 173 174 virtual HRESULT STDMETHODCALLTYPE scrollOffset( 175 /* [retval][out] */ SIZE* offset); 176 177 virtual HRESULT STDMETHODCALLTYPE layout(); 178 179 virtual HRESULT STDMETHODCALLTYPE firstLayoutDone( 180 /* [retval][out] */ BOOL* result); 181 182 virtual HRESULT STDMETHODCALLTYPE unused2() { return E_NOTIMPL; } 183 184 virtual HRESULT STDMETHODCALLTYPE pendingFrameUnloadEventCount( 185 /* [retval][out] */ UINT* result); 186 187 virtual HRESULT STDMETHODCALLTYPE unused3() { return E_NOTIMPL; } 188 189 virtual HRESULT STDMETHODCALLTYPE setInPrintingMode( 190 /* [in] */ BOOL value, 191 /* [in] */ HDC printDC); 192 193 virtual HRESULT STDMETHODCALLTYPE getPrintedPageCount( 194 /* [in] */ HDC printDC, 195 /* [retval][out] */ UINT *pageCount); 196 197 virtual HRESULT STDMETHODCALLTYPE spoolPages( 198 /* [in] */ HDC printDC, 199 /* [in] */ UINT startPage, 200 /* [in] */ UINT endPage, 201 /* [retval][out] */ void* ctx); 202 203 virtual HRESULT STDMETHODCALLTYPE isFrameSet( 204 /* [retval][out] */ BOOL* result); 205 206 virtual HRESULT STDMETHODCALLTYPE string( 207 /* [retval][out] */ BSTR* result); 208 209 virtual HRESULT STDMETHODCALLTYPE size( 210 /* [retval][out] */ SIZE *size); 211 212 virtual HRESULT STDMETHODCALLTYPE hasScrollBars( 213 /* [retval][out] */ BOOL *result); 214 215 virtual HRESULT STDMETHODCALLTYPE contentBounds( 216 /* [retval][out] */ RECT *result); 217 218 virtual HRESULT STDMETHODCALLTYPE frameBounds( 219 /* [retval][out] */ RECT *result); 220 221 virtual HRESULT STDMETHODCALLTYPE isDescendantOfFrame( 222 /* [in] */ IWebFrame *ancestor, 223 /* [retval][out] */ BOOL *result); 224 225 virtual HRESULT STDMETHODCALLTYPE setAllowsScrolling( 226 /* [in] */ BOOL flag); 227 228 virtual HRESULT STDMETHODCALLTYPE allowsScrolling( 229 /* [retval][out] */ BOOL *flag); 230 231 virtual HRESULT STDMETHODCALLTYPE setIsDisconnected( 232 /* [in] */ BOOL flag); 233 234 virtual HRESULT STDMETHODCALLTYPE setExcludeFromTextSearch( 235 /* [in] */ BOOL flag); 236 237 virtual HRESULT STDMETHODCALLTYPE reloadFromOrigin(); 238 239 virtual HRESULT STDMETHODCALLTYPE paintDocumentRectToContext(/* [in] */ RECT rect, /* [in] */ HDC deviceContext); 240 241 virtual HRESULT STDMETHODCALLTYPE paintScrollViewRectToContextAtPoint(/* [in] */ RECT rect, /* [in] */ POINT pt, /* [in] */ HDC deviceContext); 242 243 virtual HRESULT STDMETHODCALLTYPE elementDoesAutoComplete( 244 /* [in] */ IDOMElement* element, 245 /* [retval][out] */ BOOL* result); 246 247 virtual HRESULT STDMETHODCALLTYPE pauseAnimation(BSTR animationName, IDOMNode*, double secondsFromNow, BOOL* animationWasRunning); 248 virtual HRESULT STDMETHODCALLTYPE pauseTransition(BSTR propertyName, IDOMNode*, double secondsFromNow, BOOL* transitionWasRunning); 249 virtual HRESULT STDMETHODCALLTYPE numberOfActiveAnimations(UINT*); 250 virtual HRESULT STDMETHODCALLTYPE loadPlainTextString(BSTR string, BSTR url); 251 252 virtual HRESULT STDMETHODCALLTYPE isDisplayingStandaloneImage(BOOL*); 253 254 virtual HRESULT STDMETHODCALLTYPE allowsFollowingLink( 255 /* [in] */ BSTR url, 256 /* [retval][out] */ BOOL* result); 257 258 virtual HRESULT STDMETHODCALLTYPE stringByEvaluatingJavaScriptInScriptWorld(IWebScriptWorld*, JSObjectRef globalObjectRef, BSTR script, BSTR* evaluationResult); 259 virtual JSGlobalContextRef STDMETHODCALLTYPE globalContextForScriptWorld(IWebScriptWorld*); 260 261 virtual HRESULT STDMETHODCALLTYPE visibleContentRect(RECT*); 262 263 virtual HRESULT STDMETHODCALLTYPE layerTreeAsText(BSTR*); 264 265 virtual HRESULT STDMETHODCALLTYPE hasSpellingMarker( 266 /* [in] */ UINT from, 267 /* [in] */ UINT length, 268 /* [retval][out] */ BOOL *result); 269 270 virtual HRESULT STDMETHODCALLTYPE clearOpener(); 271 272 virtual HRESULT STDMETHODCALLTYPE setTextDirection(BSTR); 273 274 virtual HRESULT STDMETHODCALLTYPE unused4() { return E_NOTIMPL; } 275 276 virtual HRESULT STDMETHODCALLTYPE resumeAnimations(); 277 278 virtual HRESULT STDMETHODCALLTYPE suspendAnimations(); 279 280 // IWebDocumentText 281 virtual HRESULT STDMETHODCALLTYPE supportsTextEncoding( 282 /* [retval][out] */ BOOL* result); 283 284 virtual HRESULT STDMETHODCALLTYPE selectedString( 285 /* [retval][out] */ BSTR* result); 286 287 virtual HRESULT STDMETHODCALLTYPE selectAll(); 288 289 virtual HRESULT STDMETHODCALLTYPE deselectAll(); 290 291 // FrameLoaderClient 292 virtual void frameLoaderDestroyed(); 293 294 // WebFrame 295 PassRefPtr<WebCore::Frame> createSubframeWithOwnerElement(IWebView*, WebCore::Page*, WebCore::HTMLFrameOwnerElement*); 296 void initWithWebView(IWebView*, WebCore::Page*); 297 WebCore::Frame* impl(); 298 void invalidate(); 299 void unmarkAllMisspellings(); 300 void unmarkAllBadGrammar(); 301 302 void updateBackground(); 303 304 // WebFrame (matching WebCoreFrameBridge) 305 HRESULT inViewSourceMode(BOOL *flag); 306 HRESULT setInViewSourceMode(BOOL flag); 307 HRESULT elementWithName(BSTR name, IDOMElement* form, IDOMElement** element); 308 HRESULT formForElement(IDOMElement* element, IDOMElement** form); 309 HRESULT controlsInForm(IDOMElement* form, IDOMElement** controls, int* cControls); 310 HRESULT elementIsPassword(IDOMElement* element, bool* result); 311 HRESULT searchForLabelsBeforeElement(const BSTR* labels, unsigned cLabels, IDOMElement* beforeElement, unsigned* resultDistance, BOOL* resultIsInCellAbove, BSTR* result); 312 HRESULT matchLabelsAgainstElement(const BSTR* labels, int cLabels, IDOMElement* againstElement, BSTR* result); 313 HRESULT canProvideDocumentSource(bool* result); 314 315 WebCore::URL url() const; 316 317 WebView* webView() const; 318 void setWebView(WebView*); 319 320 COMPtr<IAccessible> accessible() const; 321 322protected: 323 void loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL); 324 void loadData(PassRefPtr<WebCore::SharedBuffer>, BSTR mimeType, BSTR textEncodingName, BSTR baseURL, BSTR failingURL); 325 const Vector<WebCore::IntRect>& computePageRects(HDC printDC); 326 void setPrinting(bool printing, const WebCore::FloatSize& pageSize, const WebCore::FloatSize& originalPageSize, float maximumShrinkRatio, WebCore::AdjustViewSizeOrNot); 327 void headerAndFooterHeights(float*, float*); 328 WebCore::IntRect printerMarginRect(HDC); 329 void spoolPage (PlatformGraphicsContext* pctx, WebCore::GraphicsContext* spoolCtx, HDC printDC, IWebUIDelegate*, float headerHeight, float footerHeight, UINT page, UINT pageCount); 330 void drawHeader(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, float headerHeight); 331 void drawFooter(PlatformGraphicsContext* pctx, IWebUIDelegate*, const WebCore::IntRect& pageRect, UINT page, UINT pageCount, float headerHeight, float footerHeight); 332 333protected: 334 ULONG m_refCount; 335 class WebFramePrivate; 336 WebFramePrivate* d; 337 bool m_quickRedirectComing; 338 WebCore::URL m_originalRequestURL; 339 bool m_inPrintingMode; 340 Vector<WebCore::IntRect> m_pageRects; 341 int m_pageHeight; // height of the page adjusted by margins 342 mutable COMPtr<AccessibleDocument> m_accessible; 343}; 344 345#endif 346