Overhaul IE zoom functions to support both text and optical zoom.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68264 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -112,19 +112,11 @@ public:
|
|||||||
bool IsOfflineMode();
|
bool IsOfflineMode();
|
||||||
void SetOfflineMode(bool offline);
|
void SetOfflineMode(bool offline);
|
||||||
|
|
||||||
/**
|
wxWebViewZoom GetIETextZoom();
|
||||||
* Get text zoom
|
void SetIETextZoom(wxWebViewZoom level);
|
||||||
* @return text zoom from 0 to 4
|
|
||||||
*/
|
|
||||||
int GetIETextZoom();
|
|
||||||
|
|
||||||
/**
|
wxWebViewZoom GetIEOpticalZoom();
|
||||||
* @param level 0 to 4
|
void SetIEOpticalZoom(wxWebViewZoom level);
|
||||||
*/
|
|
||||||
void SetIETextZoom(int level);
|
|
||||||
|
|
||||||
void SetIEOpticalZoom(float zoom);
|
|
||||||
float GetIEOpticalZoom();
|
|
||||||
|
|
||||||
void onActiveXEvent(wxActiveXEvent& evt);
|
void onActiveXEvent(wxActiveXEvent& evt);
|
||||||
void onEraseBg(wxEraseEvent&) {}
|
void onEraseBg(wxEraseEvent&) {}
|
||||||
@@ -139,6 +131,9 @@ private:
|
|||||||
bool m_canNavigateBack;
|
bool m_canNavigateBack;
|
||||||
bool m_canNavigateForward;
|
bool m_canNavigateForward;
|
||||||
|
|
||||||
|
//We store the current zoom type;
|
||||||
|
wxWebViewZoomType m_zoomType;
|
||||||
|
|
||||||
/** The "Busy" property of IWebBrowser2 does not always return busy when
|
/** The "Busy" property of IWebBrowser2 does not always return busy when
|
||||||
* we'd want it to; this variable may be set to true in cases where the
|
* we'd want it to; this variable may be set to true in cases where the
|
||||||
* Busy property is false but should be true.
|
* Busy property is false but should be true.
|
||||||
|
@@ -96,6 +96,7 @@ bool wxWebViewIE::Create(wxWindow* parent,
|
|||||||
m_historyLoadingFromList = false;
|
m_historyLoadingFromList = false;
|
||||||
m_historyEnabled = true;
|
m_historyEnabled = true;
|
||||||
m_historyPosition = -1;
|
m_historyPosition = -1;
|
||||||
|
m_zoomType = wxWEB_VIEW_ZOOM_TYPE_TEXT;
|
||||||
|
|
||||||
if (::CoCreateInstance(CLSID_WebBrowser, NULL,
|
if (::CoCreateInstance(CLSID_WebBrowser, NULL,
|
||||||
CLSCTX_INPROC_SERVER, // CLSCTX_INPROC,
|
CLSCTX_INPROC_SERVER, // CLSCTX_INPROC,
|
||||||
@@ -183,62 +184,32 @@ wxString wxWebViewIE::GetPageSource()
|
|||||||
return wxString(bstr);
|
return wxString(bstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME? retrieve OLECMDID_GETZOOMRANGE instead of hardcoding range 0-4
|
|
||||||
wxWebViewZoom wxWebViewIE::GetZoom()
|
wxWebViewZoom wxWebViewIE::GetZoom()
|
||||||
{
|
{
|
||||||
const int zoom = GetIETextZoom();
|
if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_LAYOUT)
|
||||||
|
return GetIEOpticalZoom();
|
||||||
switch (zoom)
|
else if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_TEXT)
|
||||||
{
|
return GetIETextZoom();
|
||||||
case 0:
|
else
|
||||||
return wxWEB_VIEW_ZOOM_TINY;
|
wxFAIL;
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
return wxWEB_VIEW_ZOOM_SMALL;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
return wxWEB_VIEW_ZOOM_MEDIUM;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
return wxWEB_VIEW_ZOOM_LARGE;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
return wxWEB_VIEW_ZOOM_LARGEST;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
wxASSERT(false);
|
|
||||||
return wxWEB_VIEW_ZOOM_MEDIUM;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWebViewIE::SetZoom(wxWebViewZoom zoom)
|
void wxWebViewIE::SetZoom(wxWebViewZoom zoom)
|
||||||
{
|
{
|
||||||
// I know I could cast from enum to int since wxWebViewZoom happens to
|
if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_LAYOUT)
|
||||||
// match with IE's zoom levels, but I don't like doing that, what if enum
|
SetIEOpticalZoom(zoom);
|
||||||
// values change...
|
else if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_TEXT)
|
||||||
switch (zoom)
|
SetIETextZoom(zoom);
|
||||||
{
|
else
|
||||||
case wxWEB_VIEW_ZOOM_TINY:
|
wxFAIL;
|
||||||
SetIETextZoom(0);
|
|
||||||
break;
|
|
||||||
case wxWEB_VIEW_ZOOM_SMALL:
|
|
||||||
SetIETextZoom(1);
|
|
||||||
break;
|
|
||||||
case wxWEB_VIEW_ZOOM_MEDIUM:
|
|
||||||
SetIETextZoom(2);
|
|
||||||
break;
|
|
||||||
case wxWEB_VIEW_ZOOM_LARGE:
|
|
||||||
SetIETextZoom(3);
|
|
||||||
break;
|
|
||||||
case wxWEB_VIEW_ZOOM_LARGEST:
|
|
||||||
SetIETextZoom(4);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
wxASSERT(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWebViewIE::SetIETextZoom(int level)
|
void wxWebViewIE::SetIETextZoom(wxWebViewZoom level)
|
||||||
{
|
{
|
||||||
|
//We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
|
||||||
|
//is 0 to 4 so the check is unnecessary, these match exactly with the
|
||||||
|
//enum values
|
||||||
VARIANT zoomVariant;
|
VARIANT zoomVariant;
|
||||||
VariantInit (&zoomVariant);
|
VariantInit (&zoomVariant);
|
||||||
V_VT(&zoomVariant) = VT_I4;
|
V_VT(&zoomVariant) = VT_I4;
|
||||||
@@ -247,79 +218,105 @@ void wxWebViewIE::SetIETextZoom(int level)
|
|||||||
HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM,
|
HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM,
|
||||||
OLECMDEXECOPT_DONTPROMPTUSER,
|
OLECMDEXECOPT_DONTPROMPTUSER,
|
||||||
&zoomVariant, NULL);
|
&zoomVariant, NULL);
|
||||||
wxASSERT (result == S_OK);
|
wxASSERT(result == S_OK);
|
||||||
|
|
||||||
VariantClear (&zoomVariant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxWebViewIE::GetIETextZoom()
|
wxWebViewZoom wxWebViewIE::GetIETextZoom()
|
||||||
{
|
{
|
||||||
VARIANT zoomVariant;
|
VARIANT zoomVariant;
|
||||||
VariantInit (&zoomVariant);
|
VariantInit (&zoomVariant);
|
||||||
V_VT(&zoomVariant) = VT_I4;
|
V_VT(&zoomVariant) = VT_I4;
|
||||||
V_I4(&zoomVariant) = 4;
|
|
||||||
|
|
||||||
HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM,
|
HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM,
|
||||||
OLECMDEXECOPT_DONTPROMPTUSER,
|
OLECMDEXECOPT_DONTPROMPTUSER,
|
||||||
NULL, &zoomVariant);
|
NULL, &zoomVariant);
|
||||||
wxASSERT (result == S_OK);
|
wxASSERT(result == S_OK);
|
||||||
|
|
||||||
int zoom = V_I4(&zoomVariant);
|
//We can safely cast here as we know that the range matches our enum
|
||||||
VariantClear (&zoomVariant);
|
return static_cast<wxWebViewZoom>(V_I4(&zoomVariant));
|
||||||
|
|
||||||
return zoom;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWebViewIE::SetIEOpticalZoom(float zoom)
|
void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level)
|
||||||
{
|
{
|
||||||
// TODO: add support for optical zoom (IE7+ only)
|
//We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
|
||||||
|
//is 10 to 1000 so the check is unnecessary
|
||||||
// TODO: get range from OLECMDID_OPTICAL_GETZOOMRANGE instead of hardcoding?
|
|
||||||
wxASSERT(zoom >= 10.0f);
|
|
||||||
wxASSERT(zoom <= 1000.0f);
|
|
||||||
|
|
||||||
VARIANT zoomVariant;
|
VARIANT zoomVariant;
|
||||||
VariantInit (&zoomVariant);
|
VariantInit (&zoomVariant);
|
||||||
V_VT(&zoomVariant) = VT_I4;
|
V_VT(&zoomVariant) = VT_I4;
|
||||||
V_I4(&zoomVariant) = (zoom * 100.0f);
|
|
||||||
|
//We make a somewhat arbitray map here, taken from values used by webkit
|
||||||
|
switch(level)
|
||||||
|
{
|
||||||
|
case wxWEB_VIEW_ZOOM_TINY:
|
||||||
|
V_I4(&zoomVariant) = 60;
|
||||||
|
break;
|
||||||
|
case wxWEB_VIEW_ZOOM_SMALL:
|
||||||
|
V_I4(&zoomVariant) = 80;
|
||||||
|
break;
|
||||||
|
case wxWEB_VIEW_ZOOM_MEDIUM:
|
||||||
|
V_I4(&zoomVariant) = 100;
|
||||||
|
break;
|
||||||
|
case wxWEB_VIEW_ZOOM_LARGE:
|
||||||
|
V_I4(&zoomVariant) = 130;
|
||||||
|
break;
|
||||||
|
case wxWEB_VIEW_ZOOM_LARGEST:
|
||||||
|
V_I4(&zoomVariant) = 160;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wxFAIL;
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM,
|
HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM,
|
||||||
OLECMDEXECOPT_DODEFAULT,
|
OLECMDEXECOPT_DODEFAULT,
|
||||||
&zoomVariant,
|
&zoomVariant,
|
||||||
NULL);
|
NULL);
|
||||||
wxASSERT (result == S_OK);
|
wxASSERT(result == S_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
float wxWebViewIE::GetIEOpticalZoom()
|
wxWebViewZoom wxWebViewIE::GetIEOpticalZoom()
|
||||||
{
|
{
|
||||||
// TODO: add support for optical zoom (IE7+ only)
|
|
||||||
|
|
||||||
VARIANT zoomVariant;
|
VARIANT zoomVariant;
|
||||||
VariantInit (&zoomVariant);
|
VariantInit (&zoomVariant);
|
||||||
V_VT(&zoomVariant) = VT_I4;
|
V_VT(&zoomVariant) = VT_I4;
|
||||||
V_I4(&zoomVariant) = -1;
|
|
||||||
|
|
||||||
HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM,
|
HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM,
|
||||||
OLECMDEXECOPT_DODEFAULT, NULL,
|
OLECMDEXECOPT_DODEFAULT, NULL,
|
||||||
&zoomVariant);
|
&zoomVariant);
|
||||||
wxASSERT (result == S_OK);
|
wxASSERT(result == S_OK);
|
||||||
|
|
||||||
const int zoom = V_I4(&zoomVariant);
|
const int zoom = V_I4(&zoomVariant);
|
||||||
VariantClear (&zoomVariant);
|
|
||||||
|
|
||||||
return zoom / 100.0f;
|
//We make a somewhat arbitray map here, taken from values used by webkit
|
||||||
|
if (zoom <= 65)
|
||||||
|
{
|
||||||
|
return wxWEB_VIEW_ZOOM_TINY;
|
||||||
|
}
|
||||||
|
else if (zoom > 65 && zoom <= 90)
|
||||||
|
{
|
||||||
|
return wxWEB_VIEW_ZOOM_SMALL;
|
||||||
|
}
|
||||||
|
else if (zoom > 90 && zoom <= 115)
|
||||||
|
{
|
||||||
|
return wxWEB_VIEW_ZOOM_MEDIUM;
|
||||||
|
}
|
||||||
|
else if (zoom > 115 && zoom <= 145)
|
||||||
|
{
|
||||||
|
return wxWEB_VIEW_ZOOM_LARGE;
|
||||||
|
}
|
||||||
|
else if (zoom > 145)
|
||||||
|
{
|
||||||
|
return wxWEB_VIEW_ZOOM_LARGEST;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWebViewIE::SetZoomType(wxWebViewZoomType)
|
void wxWebViewIE::SetZoomType(wxWebViewZoomType type)
|
||||||
{
|
{
|
||||||
// TODO: add support for optical zoom (IE7+ only)
|
m_zoomType = type;
|
||||||
wxASSERT(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWebViewZoomType wxWebViewIE::GetZoomType() const
|
wxWebViewZoomType wxWebViewIE::GetZoomType() const
|
||||||
{
|
{
|
||||||
// TODO: add support for optical zoom (IE7+ only)
|
return m_zoomType;
|
||||||
return wxWEB_VIEW_ZOOM_TYPE_TEXT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType) const
|
bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType) const
|
||||||
|
Reference in New Issue
Block a user