From c5f417cb50ebe47dfcecd5998cf7abc2505c514c Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Thu, 14 Jul 2011 09:58:33 +0000 Subject: [PATCH] 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 --- include/wx/msw/webview_ie.h | 19 ++--- src/msw/webview_ie.cpp | 155 ++++++++++++++++++------------------ 2 files changed, 83 insertions(+), 91 deletions(-) diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index 416b54047c..efc13b61ed 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -112,19 +112,11 @@ public: bool IsOfflineMode(); void SetOfflineMode(bool offline); - /** - * Get text zoom - * @return text zoom from 0 to 4 - */ - int GetIETextZoom(); - - /** - * @param level 0 to 4 - */ - void SetIETextZoom(int level); + wxWebViewZoom GetIETextZoom(); + void SetIETextZoom(wxWebViewZoom 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. diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 83accbe58b..fd68dccafe 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -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(); - - 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; - } + if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_LAYOUT) + return GetIEOpticalZoom(); + else if(m_zoomType == wxWEB_VIEW_ZOOM_TYPE_TEXT) + return GetIETextZoom(); + else + wxFAIL; + } + 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; @@ -247,79 +218,105 @@ void wxWebViewIE::SetIETextZoom(int level) HRESULT result = m_webBrowser->ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, &zoomVariant, NULL); - wxASSERT (result == S_OK); - - VariantClear (&zoomVariant); + wxASSERT(result == S_OK); } -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); + wxASSERT(result == S_OK); - return zoom; + //We can safely cast here as we know that the range matches our enum + return static_cast(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, &zoomVariant, 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; VariantInit (&zoomVariant); V_VT(&zoomVariant) = VT_I4; - V_I4(&zoomVariant) = -1; HRESULT result = m_webBrowser->ExecWB((OLECMDID)OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DODEFAULT, NULL, &zoomVariant); - wxASSERT (result == S_OK); + 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 -- 2.45.2