Use wxCOMPtr throughout the wxWebViewIE Find code.
As well as making the code a bit neater this seems to fix some memory issues. See #15207. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74020 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -184,7 +184,7 @@ private:
|
|||||||
bool CanExecCommand(wxString command) const;
|
bool CanExecCommand(wxString command) const;
|
||||||
void ExecCommand(wxString command);
|
void ExecCommand(wxString command);
|
||||||
wxCOMPtr<IHTMLDocument2> GetDocument() const;
|
wxCOMPtr<IHTMLDocument2> GetDocument() const;
|
||||||
bool IsElementVisible(IHTMLElement* elm);
|
bool IsElementVisible(wxCOMPtr<IHTMLElement> elm);
|
||||||
//Find helper functions.
|
//Find helper functions.
|
||||||
void FindInternal(const wxString& text, int flags, int internal_flag);
|
void FindInternal(const wxString& text, int flags, int internal_flag);
|
||||||
long FindNext(int direction = 1);
|
long FindNext(int direction = 1);
|
||||||
|
@@ -940,19 +940,19 @@ wxCOMPtr<IHTMLDocument2> wxWebViewIE::GetDocument() const
|
|||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxWebViewIE::IsElementVisible(IHTMLElement* elm)
|
bool wxWebViewIE::IsElementVisible(wxCOMPtr<IHTMLElement> elm)
|
||||||
{
|
{
|
||||||
wxIHTMLCurrentStyle* style;
|
wxCOMPtr<IHTMLElement> elm1 = elm;
|
||||||
IHTMLElement *elm1 = elm;
|
|
||||||
wxIHTMLElement2 *elm2;
|
|
||||||
BSTR tmp_bstr;
|
BSTR tmp_bstr;
|
||||||
bool is_visible = true;
|
bool is_visible = true;
|
||||||
//This method is not perfect but it does discover most of the hidden elements.
|
//This method is not perfect but it does discover most of the hidden elements.
|
||||||
//so if a better solution is found, then please do improve.
|
//so if a better solution is found, then please do improve.
|
||||||
while(elm1)
|
while(elm1)
|
||||||
{
|
{
|
||||||
|
wxCOMPtr<wxIHTMLElement2> elm2;
|
||||||
if(SUCCEEDED(elm1->QueryInterface(wxIID_IHTMLElement2, (void**) &elm2)))
|
if(SUCCEEDED(elm1->QueryInterface(wxIID_IHTMLElement2, (void**) &elm2)))
|
||||||
{
|
{
|
||||||
|
wxCOMPtr<wxIHTMLCurrentStyle> style;
|
||||||
if(SUCCEEDED(elm2->get_currentStyle(&style)))
|
if(SUCCEEDED(elm2->get_currentStyle(&style)))
|
||||||
{
|
{
|
||||||
//Check if the object has the style display:none.
|
//Check if the object has the style display:none.
|
||||||
@@ -976,7 +976,6 @@ bool wxWebViewIE::IsElementVisible(IHTMLElement* elm)
|
|||||||
IHTMLElement* parent;
|
IHTMLElement* parent;
|
||||||
if(is_visible && SUCCEEDED(elm1->get_parentElement(&parent)))
|
if(is_visible && SUCCEEDED(elm1->get_parentElement(&parent)))
|
||||||
{
|
{
|
||||||
elm1->Release();
|
|
||||||
elm1 = parent;
|
elm1 = parent;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -990,17 +989,17 @@ bool wxWebViewIE::IsElementVisible(IHTMLElement* elm)
|
|||||||
|
|
||||||
void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_flag)
|
void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_flag)
|
||||||
{
|
{
|
||||||
wxIMarkupServices *pIMS;
|
|
||||||
wxIMarkupContainer *pIMC;
|
|
||||||
wxIMarkupPointer *ptrBegin, *ptrEnd;
|
|
||||||
IHTMLElement* elm;
|
|
||||||
long find_flag = 0;
|
long find_flag = 0;
|
||||||
IHTMLDocument2 *document = GetDocument();
|
wxCOMPtr<wxIMarkupServices> pIMS;
|
||||||
|
wxCOMPtr<IHTMLDocument2> document = GetDocument();
|
||||||
|
|
||||||
//This function does the acutal work.
|
//This function does the acutal work.
|
||||||
if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices, (void **)&pIMS)))
|
if(document && SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices, (void **)&pIMS)))
|
||||||
{
|
{
|
||||||
|
wxCOMPtr<wxIMarkupContainer> pIMC;
|
||||||
if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupContainer, (void **)&pIMC)))
|
if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupContainer, (void **)&pIMC)))
|
||||||
{
|
{
|
||||||
|
wxCOMPtr<wxIMarkupPointer> ptrBegin, ptrEnd;
|
||||||
BSTR attr_bstr = SysAllocString(L"style=\"background-color:#ffff00\"");
|
BSTR attr_bstr = SysAllocString(L"style=\"background-color:#ffff00\"");
|
||||||
BSTR text_bstr = SysAllocString(text.wc_str());
|
BSTR text_bstr = SysAllocString(text.wc_str());
|
||||||
pIMS->CreateMarkupPointer(&ptrBegin);
|
pIMS->CreateMarkupPointer(&ptrBegin);
|
||||||
@@ -1026,6 +1025,7 @@ void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_fla
|
|||||||
|
|
||||||
while(ptrBegin->FindText(text_bstr, find_flag, ptrEnd, NULL) == S_OK)
|
while(ptrBegin->FindText(text_bstr, find_flag, ptrEnd, NULL) == S_OK)
|
||||||
{
|
{
|
||||||
|
wxCOMPtr<IHTMLElement> elm;
|
||||||
if(ptrBegin->CurrentScope(&elm) == S_OK)
|
if(ptrBegin->CurrentScope(&elm) == S_OK)
|
||||||
{
|
{
|
||||||
if(IsElementVisible(elm))
|
if(IsElementVisible(elm))
|
||||||
@@ -1054,20 +1054,14 @@ void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_fla
|
|||||||
m_findPointers.push_back(wxFindPointers(cptrBegin,cptrEnd));
|
m_findPointers.push_back(wxFindPointers(cptrBegin,cptrEnd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elm->Release();
|
|
||||||
}
|
}
|
||||||
ptrBegin->MoveToPointer(ptrEnd);
|
ptrBegin->MoveToPointer(ptrEnd);
|
||||||
}
|
}
|
||||||
//Clean up.
|
//Clean up.
|
||||||
SysFreeString(text_bstr);
|
SysFreeString(text_bstr);
|
||||||
SysFreeString(attr_bstr);
|
SysFreeString(attr_bstr);
|
||||||
pIMC->Release();
|
|
||||||
ptrBegin->Release();
|
|
||||||
ptrEnd->Release();
|
|
||||||
}
|
}
|
||||||
pIMS->Release();
|
|
||||||
}
|
}
|
||||||
document->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long wxWebViewIE::FindNext(int direction)
|
long wxWebViewIE::FindNext(int direction)
|
||||||
@@ -1111,20 +1105,21 @@ long wxWebViewIE::FindNext(int direction)
|
|||||||
return wxNOT_FOUND;
|
return wxNOT_FOUND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//some variables to use later on.
|
|
||||||
IHTMLElement *body_element;
|
wxCOMPtr<IHTMLDocument2> document = GetDocument();
|
||||||
IHTMLBodyElement *body;
|
wxCOMPtr<IHTMLElement> body_element;
|
||||||
wxIHTMLTxtRange *range = NULL;
|
|
||||||
wxIMarkupServices *pIMS;
|
|
||||||
IHTMLDocument2 *document = GetDocument();
|
|
||||||
long ret = -1;
|
long ret = -1;
|
||||||
//Now try to create a range from the body.
|
//Now try to create a range from the body.
|
||||||
if(SUCCEEDED(document->get_body(&body_element)))
|
if(document && SUCCEEDED(document->get_body(&body_element)))
|
||||||
{
|
{
|
||||||
|
wxCOMPtr<IHTMLBodyElement> body;
|
||||||
if(SUCCEEDED(body_element->QueryInterface(IID_IHTMLBodyElement,(void**)&body)))
|
if(SUCCEEDED(body_element->QueryInterface(IID_IHTMLBodyElement,(void**)&body)))
|
||||||
{
|
{
|
||||||
|
wxCOMPtr<wxIHTMLTxtRange> range;
|
||||||
if(SUCCEEDED(body->createTextRange((IHTMLTxtRange**)(&range))))
|
if(SUCCEEDED(body->createTextRange((IHTMLTxtRange**)(&range))))
|
||||||
{
|
{
|
||||||
|
wxCOMPtr<wxIMarkupServices> pIMS;
|
||||||
//So far so good, now we try to position our find pointers.
|
//So far so good, now we try to position our find pointers.
|
||||||
if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices,(void **)&pIMS)))
|
if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices,(void **)&pIMS)))
|
||||||
{
|
{
|
||||||
@@ -1133,15 +1128,10 @@ long wxWebViewIE::FindNext(int direction)
|
|||||||
{
|
{
|
||||||
ret = m_findPosition;
|
ret = m_findPosition;
|
||||||
}
|
}
|
||||||
pIMS->Release();
|
|
||||||
}
|
}
|
||||||
range->Release();
|
|
||||||
}
|
}
|
||||||
body->Release();
|
|
||||||
}
|
}
|
||||||
body_element->Release();
|
|
||||||
}
|
}
|
||||||
document->Release();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user