Commit a147b791 authored by hyatt@apple.com's avatar hyatt@apple.com

Add full page zoom API for Windows WebKit.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ab0d8cee
2008-03-20 Dave Hyatt <hyatt@apple.com>
Add full page zoom API for Windows WebKit.
Reviewed by aroben
* Interfaces/IWebView.idl:
* WebView.cpp:
(WebView::WebView):
(WebView::setTextSizeMultiplier):
(WebView::setPageSizeMultiplier):
(WebView::setZoomMultiplier):
(WebView::textSizeMultiplier):
(WebView::pageSizeMultiplier):
(WebView::zoomMultiplier):
(WebView::canMakeTextLarger):
(WebView::canZoomPageIn):
(WebView::canZoomIn):
(WebView::makeTextLarger):
(WebView::zoomPageIn):
(WebView::zoomIn):
(WebView::canMakeTextSmaller):
(WebView::canZoomPageOut):
(WebView::canZoomOut):
(WebView::makeTextSmaller):
(WebView::zoomPageOut):
(WebView::zoomOut):
(WebView::canMakeTextStandardSize):
(WebView::canResetPageZoom):
(WebView::canResetZoom):
(WebView::makeTextStandardSize):
(WebView::resetPageZoom):
(WebView::resetZoom):
* WebView.h:
2008-03-20 John Sullivan <sullivan@apple.com>
* English.lproj/Localizable.strings:
......
......@@ -815,6 +815,51 @@ interface IWebIBActions : IUnknown
- (void)toggleGrammarChecking:(id)sender
*/
HRESULT toggleGrammarChecking([in] IUnknown* sender);
/*!
@method setPageSizeMultiplier:
@abstract Set a zoom factor for all views managed by this webView.
@param multiplier A fractional percentage value, 1.0 is 100%.
- (void)setPageSizeMultiplier:(float)multiplier;
*/
HRESULT setPageSizeMultiplier([in] float multiplier);
/*!
@method pageSizeMultiplier
@result The page size multipler.
- (float)pageSizeMultiplier;
*/
HRESULT pageSizeMultiplier([out, retval] float* multiplier);
/*
- (BOOL)canZoomPageIn;
*/
HRESULT canZoomPageIn([in] IUnknown* sender, [out, retval] BOOL* result);
/*
- (IBAction)zoomPageIn:(id)sender;
*/
HRESULT zoomPageIn([in] IUnknown* sender);
/*
- (BOOL)canZoomPageOut;
*/
HRESULT canZoomPageOut([in] IUnknown* sender, [out, retval] BOOL* result);
/*
- (IBAction)zoomPageOut:(id)sender;
*/
HRESULT zoomPageOut([in] IUnknown* sender);
/*
- (BOOL)canResetPageZoom;
*/
HRESULT canResetPageZoom([in] IUnknown* sender, [out, retval] BOOL* result);
/*
- (IBAction)resetPageZoom:(id)sender;
*/
HRESULT resetPageZoom([in] IUnknown* sender);
}
/*
......
......@@ -251,7 +251,8 @@ WebView::WebView()
, m_hasCustomDropTarget(false)
, m_useBackForwardList(true)
, m_userAgentOverridden(false)
, m_textSizeMultiplier(1)
, m_zoomMultiplier(1.0f)
, m_zoomMultiplierIsTextOnly(true)
, m_mouseActivated(false)
, m_dragData(0)
, m_currentCharacterCode(0)
......@@ -2383,23 +2384,50 @@ HRESULT STDMETHODCALLTYPE WebView::goToBackForwardItem(
HRESULT STDMETHODCALLTYPE WebView::setTextSizeMultiplier(
/* [in] */ float multiplier)
{
if (m_textSizeMultiplier != multiplier)
m_textSizeMultiplier = multiplier;
if (!m_mainFrame)
return E_FAIL;
setZoomMultiplier(multiplier, true);
return S_OK;
}
m_mainFrame->setTextSizeMultiplier(multiplier);
HRESULT STDMETHODCALLTYPE WebView::setPageSizeMultiplier(
/* [in] */ float multiplier)
{
if (!m_mainFrame)
return E_FAIL;
setZoomMultiplier(multiplier, false);
return S_OK;
}
void WebView::setZoomMultiplier(float multiplier, bool isTextOnly)
{
m_zoomMultiplier = multiplier;
m_zoomMultiplierIsTextOnly = isTextOnly;
if (Frame* coreFrame = core(m_mainFrame))
coreFrame->setZoomFactor(multiplier, isTextOnly);
}
HRESULT STDMETHODCALLTYPE WebView::textSizeMultiplier(
/* [retval][out] */ float* multiplier)
{
*multiplier = m_textSizeMultiplier;
*multiplier = zoomMultiplier(true);
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebView::pageSizeMultiplier(
/* [retval][out] */ float* multiplier)
{
*multiplier = zoomMultiplier(false);
return S_OK;
}
float WebView::zoomMultiplier(bool isTextOnly)
{
if (isTextOnly != m_zoomMultiplierIsTextOnly)
return 1.0f;
return m_zoomMultiplier;
}
HRESULT STDMETHODCALLTYPE WebView::setApplicationNameForUserAgent(
/* [in] */ BSTR applicationName)
{
......@@ -3070,64 +3098,137 @@ HRESULT STDMETHODCALLTYPE WebView::goForward(
return E_NOTIMPL;
}
#define MinimumTextSizeMultiplier 0.5f
#define MaximumTextSizeMultiplier 3.0f
#define TextSizeMultiplierRatio 1.2f
// FIXME: This code should move into WebCore so it can be shared by all the WebKits.
#define MinimumZoomMultiplier 0.5f
#define MaximumZoomMultiplier 3.0f
#define ZoomMultiplierRatio 1.2f
HRESULT STDMETHODCALLTYPE WebView::canMakeTextLarger(
/* [in] */ IUnknown* /*sender*/,
/* [retval][out] */ BOOL* result)
{
bool canGrowMore = m_textSizeMultiplier*TextSizeMultiplierRatio < MaximumTextSizeMultiplier;
bool canGrowMore = canZoomIn(true);
*result = canGrowMore ? TRUE : FALSE;
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebView::canZoomPageIn(
/* [in] */ IUnknown* /*sender*/,
/* [retval][out] */ BOOL* result)
{
bool canGrowMore = canZoomIn(false);
*result = canGrowMore ? TRUE : FALSE;
return S_OK;
}
bool WebView::canZoomIn(bool isTextOnly)
{
return zoomMultiplier(isTextOnly) * ZoomMultiplierRatio < MaximumZoomMultiplier;
}
HRESULT STDMETHODCALLTYPE WebView::makeTextLarger(
/* [in] */ IUnknown* /*sender*/)
{
float newScale = m_textSizeMultiplier*TextSizeMultiplierRatio;
bool canGrowMore = newScale < MaximumTextSizeMultiplier;
if (!canGrowMore)
return E_FAIL;
return setTextSizeMultiplier(newScale);
return canZoomIn(true);
}
HRESULT STDMETHODCALLTYPE WebView::zoomPageIn(
/* [in] */ IUnknown* /*sender*/)
{
return canZoomIn(false);
}
HRESULT WebView::zoomIn(bool isTextOnly)
{
if (!canZoomIn(isTextOnly))
return E_FAIL;
setZoomMultiplier(zoomMultiplier(isTextOnly) * ZoomMultiplierRatio, isTextOnly);
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebView::canMakeTextSmaller(
/* [in] */ IUnknown* /*sender*/,
/* [retval][out] */ BOOL* result)
{
bool canShrinkMore = m_textSizeMultiplier/TextSizeMultiplierRatio > MinimumTextSizeMultiplier;
bool canShrinkMore = canZoomOut(true);
*result = canShrinkMore ? TRUE : FALSE;
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebView::canZoomPageOut(
/* [in] */ IUnknown* /*sender*/,
/* [retval][out] */ BOOL* result)
{
bool canShrinkMore = canZoomOut(false);
*result = canShrinkMore ? TRUE : FALSE;
return S_OK;
}
bool WebView::canZoomOut(bool isTextOnly)
{
return zoomMultiplier(isTextOnly) / ZoomMultiplierRatio > MinimumZoomMultiplier;
}
HRESULT STDMETHODCALLTYPE WebView::makeTextSmaller(
/* [in] */ IUnknown* /*sender*/)
{
float newScale = m_textSizeMultiplier/TextSizeMultiplierRatio;
bool canShrinkMore = newScale > MinimumTextSizeMultiplier;
if (!canShrinkMore)
return zoomOut(true);
}
HRESULT STDMETHODCALLTYPE WebView::zoomPageOut(
/* [in] */ IUnknown* /*sender*/)
{
return zoomOut(false);
}
HRESULT WebView::zoomOut(bool isTextOnly)
{
if (!canZoomOut(isTextOnly))
return E_FAIL;
return setTextSizeMultiplier(newScale);
setZoomMultiplier(zoomMultiplier(isTextOnly) / ZoomMultiplierRatio, isTextOnly);
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebView::canMakeTextStandardSize(
/* [in] */ IUnknown* /*sender*/,
/* [retval][out] */ BOOL* result)
{
bool notAlreadyStandard = m_textSizeMultiplier != 1.0f;
bool notAlreadyStandard = canResetZoom(true);
*result = notAlreadyStandard ? TRUE : FALSE;
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebView::canResetPageZoom(
/* [in] */ IUnknown* /*sender*/,
/* [retval][out] */ BOOL* result)
{
bool notAlreadyStandard = canResetZoom(false);
*result = notAlreadyStandard ? TRUE : FALSE;
return S_OK;
}
bool WebView::canResetZoom(bool isTextOnly)
{
return zoomMultiplier(isTextOnly) != 1.0f;
}
HRESULT STDMETHODCALLTYPE WebView::makeTextStandardSize(
/* [in] */ IUnknown* /*sender*/)
{
bool notAlreadyStandard = m_textSizeMultiplier != 1.0f;
if (notAlreadyStandard)
return setTextSizeMultiplier(1.0f);
return resetZoom(true);
}
HRESULT STDMETHODCALLTYPE WebView::resetPageZoom(
/* [in] */ IUnknown* /*sender*/)
{
return resetZoom(false);
}
HRESULT WebView::resetZoom(bool isTextOnly)
{
if (!canResetZoom(isTextOnly))
return E_FAIL;
setZoomMultiplier(1.0f, isTextOnly);
return S_OK;
}
......
......@@ -437,6 +437,33 @@ public:
virtual HRESULT STDMETHODCALLTYPE setGrammarCheckingEnabled(
BOOL enabled);
virtual HRESULT STDMETHODCALLTYPE setPageSizeMultiplier(
/* [in] */ float multiplier);
virtual HRESULT STDMETHODCALLTYPE pageSizeMultiplier(
/* [retval][out] */ float *multiplier);
virtual HRESULT STDMETHODCALLTYPE canZoomPageIn(
/* [in] */ IUnknown *sender,
/* [retval][out] */ BOOL *result);
virtual HRESULT STDMETHODCALLTYPE zoomPageIn(
/* [in] */ IUnknown *sender);
virtual HRESULT STDMETHODCALLTYPE canZoomPageOut(
/* [in] */ IUnknown *sender,
/* [retval][out] */ BOOL *result);
virtual HRESULT STDMETHODCALLTYPE zoomPageOut(
/* [in] */ IUnknown *sender);
virtual HRESULT STDMETHODCALLTYPE canResetPageZoom(
/* [in] */ IUnknown *sender,
/* [retval][out] */ BOOL *result);
virtual HRESULT STDMETHODCALLTYPE resetPageZoom(
/* [in] */ IUnknown *sender);
// IWebViewUndoableEditing
virtual HRESULT STDMETHODCALLTYPE replaceSelectionWithNode(
......@@ -715,6 +742,16 @@ public:
void updateActiveState();
private:
void setZoomMultiplier(float multiplier, bool isTextOnly);
float zoomMultiplier(bool isTextOnly);
bool canZoomIn(bool isTextOnly);
HRESULT zoomIn(bool isTextOnly);
bool canZoomOut(bool isTextOnly);
HRESULT zoomOut(bool isTextOnly);
bool canResetZoom(bool isTextOnly);
HRESULT resetZoom(bool isTextOnly);
protected:
HIMC getIMMContext();
void releaseIMMContext(HIMC);
......@@ -762,7 +799,8 @@ protected:
bool m_useBackForwardList;
WebCore::String m_userAgentCustom;
WebCore::String m_userAgentStandard;
float m_textSizeMultiplier;
float m_zoomMultiplier;
bool m_zoomMultiplierIsTextOnly;
WebCore::String m_overrideEncoding;
WebCore::String m_applicationName;
bool m_mouseActivated;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment