📄 webframe.cpp
字号:
}void WebFrame::loadHTMLString(BSTR string, BSTR baseURL, BSTR unreachableURL){ RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(reinterpret_cast<char*>(string), sizeof(UChar) * SysStringLen(string)); BString utf16Encoding(TEXT("utf-16"), 6); loadData(sharedBuffer.release(), 0, utf16Encoding, baseURL, unreachableURL);}HRESULT STDMETHODCALLTYPE WebFrame::loadHTMLString( /* [in] */ BSTR string, /* [in] */ BSTR baseURL){ loadHTMLString(string, baseURL, 0); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::loadAlternateHTMLString( /* [in] */ BSTR str, /* [in] */ BSTR baseURL, /* [in] */ BSTR unreachableURL){ loadHTMLString(str, baseURL, unreachableURL); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::loadArchive( /* [in] */ IWebArchive* /*archive*/){ ASSERT_NOT_REACHED(); return E_NOTIMPL;}static inline WebDataSource *getWebDataSource(DocumentLoader* loader){ return loader ? static_cast<WebDocumentLoader*>(loader)->dataSource() : 0;}HRESULT STDMETHODCALLTYPE WebFrame::dataSource( /* [retval][out] */ IWebDataSource** source){ if (!source) { ASSERT_NOT_REACHED(); return E_POINTER; } *source = 0; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->documentLoader()); *source = webDataSource; if (webDataSource) webDataSource->AddRef(); return *source ? S_OK : E_FAIL;}HRESULT STDMETHODCALLTYPE WebFrame::provisionalDataSource( /* [retval][out] */ IWebDataSource** source){ if (!source) { ASSERT_NOT_REACHED(); return E_POINTER; } *source = 0; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; WebDataSource* webDataSource = getWebDataSource(coreFrame->loader()->provisionalDocumentLoader()); *source = webDataSource; if (webDataSource) webDataSource->AddRef(); return *source ? S_OK : E_FAIL;}KURL WebFrame::url() const{ Frame* coreFrame = core(this); if (!coreFrame) return KURL(); return coreFrame->loader()->url();}HRESULT STDMETHODCALLTYPE WebFrame::stopLoading( void){ if (Frame* coreFrame = core(this)) coreFrame->loader()->stopAllLoaders(); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::reload( void){ Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; coreFrame->loader()->reload(); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::findFrameNamed( /* [in] */ BSTR name, /* [retval][out] */ IWebFrame** frame){ if (!frame) { ASSERT_NOT_REACHED(); return E_POINTER; } *frame = 0; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; Frame* foundFrame = coreFrame->tree()->find(AtomicString(name, SysStringLen(name))); if (!foundFrame) return S_OK; WebFrame* foundWebFrame = kit(foundFrame); if (!foundWebFrame) return E_FAIL; return foundWebFrame->QueryInterface(IID_IWebFrame, (void**)frame);}HRESULT STDMETHODCALLTYPE WebFrame::parentFrame( /* [retval][out] */ IWebFrame** frame){ HRESULT hr = S_OK; *frame = 0; if (Frame* coreFrame = core(this)) if (WebFrame* webFrame = kit(coreFrame->tree()->parent())) hr = webFrame->QueryInterface(IID_IWebFrame, (void**) frame); return hr;}class EnumChildFrames : public IEnumVARIANT{public: EnumChildFrames(Frame* f) : m_refCount(1), m_frame(f), m_curChild(f ? f->tree()->firstChild() : 0) { } virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) { *ppvObject = 0; if (IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IEnumVARIANT)) *ppvObject = this; else return E_NOINTERFACE; AddRef(); return S_OK; } virtual ULONG STDMETHODCALLTYPE AddRef(void) { return ++m_refCount; } virtual ULONG STDMETHODCALLTYPE Release(void) { ULONG newRef = --m_refCount; if (!newRef) delete(this); return newRef; } virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched) { if (pCeltFetched) *pCeltFetched = 0; if (!rgVar) return E_POINTER; VariantInit(rgVar); if (!celt || celt > 1) return S_FALSE; if (!m_frame || !m_curChild) return S_FALSE; WebFrame* webFrame = kit(m_curChild); IUnknown* unknown; HRESULT hr = webFrame->QueryInterface(IID_IUnknown, (void**)&unknown); if (FAILED(hr)) return hr; V_VT(rgVar) = VT_UNKNOWN; V_UNKNOWN(rgVar) = unknown; m_curChild = m_curChild->tree()->nextSibling(); if (pCeltFetched) *pCeltFetched = 1; return S_OK; } virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) { if (!m_frame) return S_FALSE; for (unsigned i = 0; i < celt && m_curChild; i++) m_curChild = m_curChild->tree()->nextSibling(); return m_curChild ? S_OK : S_FALSE; } virtual HRESULT STDMETHODCALLTYPE Reset(void) { if (!m_frame) return S_FALSE; m_curChild = m_frame->tree()->firstChild(); return S_OK; } virtual HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT**) { return E_NOTIMPL; }private: ULONG m_refCount; Frame* m_frame; Frame* m_curChild;};HRESULT STDMETHODCALLTYPE WebFrame::childFrames( /* [retval][out] */ IEnumVARIANT **enumFrames){ if (!enumFrames) return E_POINTER; *enumFrames = new EnumChildFrames(core(this)); return S_OK;}// IWebFramePrivate ------------------------------------------------------HRESULT STDMETHODCALLTYPE WebFrame::renderTreeAsExternalRepresentation( /* [retval][out] */ BSTR *result){ if (!result) return E_POINTER; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; *result = BString(externalRepresentation(coreFrame->contentRenderer())).release(); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::scrollOffset( /* [retval][out] */ SIZE* offset){ if (!offset) { ASSERT_NOT_REACHED(); return E_POINTER; } Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; FrameView* view = coreFrame->view(); if (!view) return E_FAIL; *offset = view->scrollOffset(); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::layout(){ Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; FrameView* view = coreFrame->view(); if (!view) return E_FAIL; view->layout(); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::firstLayoutDone( /* [retval][out] */ BOOL* result){ if (!result) { ASSERT_NOT_REACHED(); return E_POINTER; } *result = 0; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; *result = coreFrame->loader()->firstLayoutDone(); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::loadType( /* [retval][out] */ WebFrameLoadType* type){ if (!type) { ASSERT_NOT_REACHED(); return E_POINTER; } *type = (WebFrameLoadType)0; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; *type = (WebFrameLoadType)coreFrame->loader()->loadType(); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::pendingFrameUnloadEventCount( /* [retval][out] */ UINT* result){ if (!result) { ASSERT_NOT_REACHED(); return E_POINTER; } *result = 0; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; *result = coreFrame->eventHandler()->pendingFrameUnloadEventCount(); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::fetchApplicationIcon( /* [in] */ IWebIconFetcherDelegate *delegate, /* [retval][out] */ IWebIconFetcher **result){ if (!result) return E_POINTER; *result = 0; if (!delegate) return E_FAIL; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; *result = WebIconFetcher::fetchApplicationIcon(coreFrame, delegate); if (!*result) return E_FAIL; return S_OK;}// IWebDocumentText -----------------------------------------------------------HRESULT STDMETHODCALLTYPE WebFrame::supportsTextEncoding( /* [retval][out] */ BOOL* result){ *result = FALSE; return E_NOTIMPL;}HRESULT STDMETHODCALLTYPE WebFrame::selectedString( /* [retval][out] */ BSTR* result){ *result = 0; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; String text = coreFrame->displayStringModifiedByEncoding(coreFrame->selectedText()); *result = BString(text).release(); return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::selectAll(){ return E_NOTIMPL;}HRESULT STDMETHODCALLTYPE WebFrame::deselectAll(){ return E_NOTIMPL;}// WebFrame ---------------------------------------------------------------PassRefPtr<Frame> WebFrame::init(IWebView* webView, Page* page, HTMLFrameOwnerElement* ownerElement){ webView->QueryInterface(&d->webView); d->webView->Release(); // don't hold the extra ref HWND viewWindow; d->webView->viewWindow((OLE_HANDLE*)&viewWindow); this->AddRef(); // We release this ref in frameLoaderDestroyed() RefPtr<Frame> frame = Frame::create(page, ownerElement, this); d->frame = frame.get(); return frame.release();}Frame* WebFrame::impl(){ return d->frame;}void WebFrame::invalidate(){ Frame* coreFrame = core(this); ASSERT(coreFrame); if (Document* document = coreFrame->document()) document->recalcStyle(Node::Force);}void WebFrame::setTextSizeMultiplier(float multiplier){ Frame* coreFrame = core(this); ASSERT(coreFrame); coreFrame->setZoomFactor(multiplier, true);}HRESULT WebFrame::inViewSourceMode(BOOL* flag){ if (!flag) { ASSERT_NOT_REACHED(); return E_POINTER; } *flag = FALSE; Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; *flag = coreFrame->inViewSourceMode() ? TRUE : FALSE; return S_OK;}HRESULT WebFrame::setInViewSourceMode(BOOL flag){ Frame* coreFrame = core(this); if (!coreFrame) return E_FAIL; coreFrame->setInViewSourceMode(!!flag); return S_OK;}HRESULT WebFrame::elementWithName(BSTR name, IDOMElement* form, IDOMElement** element){ if (!form) return E_INVALIDARG; HTMLFormElement *formElement = formElementFromDOMElement(form); if (formElement) { Vector<HTMLFormControlElement*>& elements = formElement->formElements; AtomicString targetName((UChar*)name, SysStringLen(name)); for (unsigned int i = 0; i < elements.size(); i++) { HTMLFormControlElement *elt = elements[i]; // Skip option elements, other duds if (elt->name() == targetName) { *element = DOMElement::createInstance(elt); return S_OK; } } } return E_FAIL;}HRESULT WebFrame::formForElement(IDOMElement* element, IDOMElement** form){ if (!element) return E_INVALIDARG; HTMLInputElement *inputElement = inputElementFromDOMElement(element); if (!inputElement) return E_FAIL; HTMLFormElement *formElement = inputElement->form(); if (!formElement) return E_FAIL; *form = DOMElement::createInstance(formElement); return S_OK;}HRESULT WebFrame::elementDoesAutoComplete(IDOMElement *element, BOOL *result){ *result = false; if (!element) return E_INVALIDARG; HTMLInputElement *inputElement = inputElementFromDOMElement(element); if (!inputElement) *result = false; else *result = (inputElement->inputType() == HTMLInputElement::TEXT && inputElement->autoComplete()); return S_OK;}HRESULT WebFrame::pauseAnimation(BSTR animationName, IDOMNode* node, double secondsFromNow, BOOL* animationWasRunning){ if (!node || !animationWasRunning) return E_POINTER; *animationWasRunning = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -