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();
|
||||
void SetOfflineMode(bool offline);
|
||||
|
||||
/**
|
||||
* Get text zoom
|
||||
* @return text zoom from 0 to 4
|
||||
*/
|
||||
int GetIETextZoom();
|
||||
wxWebViewZoom GetIETextZoom();
|
||||
void SetIETextZoom(wxWebViewZoom level);
|
||||
|
||||
/**
|
||||
* @param level 0 to 4
|
||||
*/
|
||||
void SetIETextZoom(int level);
|
||||
|
||||
void SetIEOpticalZoom(float zoom);
|
||||
float GetIEOpticalZoom();
|
||||
wxWebViewZoom GetIEOpticalZoom();
|
||||
void SetIEOpticalZoom(wxWebViewZoom level);
|
||||
|
||||
void onActiveXEvent(wxActiveXEvent& evt);
|
||||
void onEraseBg(wxEraseEvent&) {}
|
||||
@@ -139,6 +131,9 @@ private:
|
||||
bool m_canNavigateBack;
|
||||
bool m_canNavigateForward;
|
||||
|
||||
//We store the current zoom type;
|
||||
wxWebViewZoomType m_zoomType;
|
||||
|
||||
/** 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
|
||||
* Busy property is false but should be true.
|
||||
|
@@ -96,6 +96,7 @@ bool wxWebViewIE::Create(wxWindow* parent,
|
||||
m_historyLoadingFromList = false;
|
||||
m_historyEnabled = true;
|
||||
m_historyPosition = -1;
|
||||
m_zoomType = wxWEB_VIEW_ZOOM_TYPE_TEXT;
|
||||
|
||||
if (::CoCreateInstance(CLSID_WebBrowser, NULL,
|
||||
CLSCTX_INPROC_SERVER, // CLSCTX_INPROC,
|
||||
@@ -183,62 +184,32 @@ wxString wxWebViewIE::GetPageSource()
|
||||
return wxString(bstr);
|
||||
}
|
||||
|
||||
// FIXME? retrieve OLECMDID_GETZOOMRANGE instead of hardcoding range 0-4
|
||||
wxWebViewZoom wxWebViewIE::GetZoom()
|
||||
{
|
||||
const int zoom = GetIETextZoom();
|
||||
if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_LAYOUT)
|
||||
return GetIEOpticalZoom();
|
||||
else if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_TEXT)
|
||||
return GetIETextZoom();
|
||||
else
|
||||
wxFAIL;
|
||||
|
||||
switch (zoom)
|
||||
{
|
||||
case 0:
|
||||
return wxWEB_VIEW_ZOOM_TINY;
|
||||
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)
|
||||
{
|
||||
// I know I could cast from enum to int since wxWebViewZoom happens to
|
||||
// match with IE's zoom levels, but I don't like doing that, what if enum
|
||||
// values change...
|
||||
switch (zoom)
|
||||
{
|
||||
case wxWEB_VIEW_ZOOM_TINY:
|
||||
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);
|
||||
}
|
||||
if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_LAYOUT)
|
||||
SetIEOpticalZoom(zoom);
|
||||
else if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_TEXT)
|
||||
SetIETextZoom(zoom);
|
||||
else
|
||||
wxFAIL;
|
||||
}
|
||||
|
||||
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;
|
||||
VariantInit (&zoomVariant);
|
||||
V_VT(&zoomVariant) = VT_I4;
|
||||
@@ -248,40 +219,52 @@ void wxWebViewIE::SetIETextZoom(int level)
|
||||
OLECMDEXECOPT_DONTPROMPTUSER,
|
||||
&zoomVariant, NULL);
|
||||
wxASSERT(result == S_OK);
|
||||
|
||||
VariantClear (&zoomVariant);
|
||||
}
|
||||
|
||||
int wxWebViewIE::GetIETextZoom()
|
||||
wxWebViewZoom wxWebViewIE::GetIETextZoom()
|
||||
{
|
||||
VARIANT zoomVariant;
|
||||
VariantInit (&zoomVariant);
|
||||
V_VT(&zoomVariant) = VT_I4;
|
||||
V_I4(&zoomVariant) = 4;
|
||||
|
||||
HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM,
|
||||
OLECMDEXECOPT_DONTPROMPTUSER,
|
||||
NULL, &zoomVariant);
|
||||
wxASSERT(result == S_OK);
|
||||
|
||||
int zoom = V_I4(&zoomVariant);
|
||||
VariantClear (&zoomVariant);
|
||||
|
||||
return zoom;
|
||||
//We can safely cast here as we know that the range matches our enum
|
||||
return static_cast<wxWebViewZoom>(V_I4(&zoomVariant));
|
||||
}
|
||||
|
||||
void wxWebViewIE::SetIEOpticalZoom(float zoom)
|
||||
void wxWebViewIE::SetIEOpticalZoom(wxWebViewZoom level)
|
||||
{
|
||||
// TODO: add support for optical zoom (IE7+ only)
|
||||
|
||||
// TODO: get range from OLECMDID_OPTICAL_GETZOOMRANGE instead of hardcoding?
|
||||
wxASSERT(zoom >= 10.0f);
|
||||
wxASSERT(zoom <= 1000.0f);
|
||||
|
||||
//We do not use OLECMDID_OPTICAL_GETZOOMRANGE as the docs say the range
|
||||
//is 10 to 1000 so the check is unnecessary
|
||||
VARIANT zoomVariant;
|
||||
VariantInit (&zoomVariant);
|
||||
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,
|
||||
OLECMDEXECOPT_DODEFAULT,
|
||||
@@ -290,14 +273,11 @@ void wxWebViewIE::SetIEOpticalZoom(float zoom)
|
||||
wxASSERT(result == S_OK);
|
||||
}
|
||||
|
||||
float wxWebViewIE::GetIEOpticalZoom()
|
||||
wxWebViewZoom wxWebViewIE::GetIEOpticalZoom()
|
||||
{
|
||||
// TODO: add support for optical zoom (IE7+ only)
|
||||
|
||||
VARIANT zoomVariant;
|
||||
VariantInit (&zoomVariant);
|
||||
V_VT(&zoomVariant) = VT_I4;
|
||||
V_I4(&zoomVariant) = -1;
|
||||
|
||||
HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM,
|
||||
OLECMDEXECOPT_DODEFAULT, NULL,
|
||||
@@ -305,21 +285,38 @@ float wxWebViewIE::GetIEOpticalZoom()
|
||||
wxASSERT(result == S_OK);
|
||||
|
||||
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)
|
||||
wxASSERT(false);
|
||||
m_zoomType = type;
|
||||
}
|
||||
|
||||
wxWebViewZoomType wxWebViewIE::GetZoomType() const
|
||||
{
|
||||
// TODO: add support for optical zoom (IE7+ only)
|
||||
return wxWEB_VIEW_ZOOM_TYPE_TEXT;
|
||||
return m_zoomType;
|
||||
}
|
||||
|
||||
bool wxWebViewIE::CanSetZoomType(wxWebViewZoomType) const
|
||||
|
Reference in New Issue
Block a user