Changeset 68869 in webkit


Ignore:
Timestamp:
Oct 1, 2010 12:32:27 AM (14 years ago)
Author:
jam@chromium.org
Message:

2010-09-29 John Abd-El-Malek <jam@chromium.org>

Reviewed by NOBODY (OOPS!).

[chromium] Changes to consolidate plugin zoom
https://bugs.webkit.org/show_bug.cgi?id=46550

  • public/WebPlugin.h: (WebKit::WebPlugin::setZoomLevel):
  • public/WebPluginContainer.h:
  • public/WebView.h:
  • public/WebViewClient.h: (WebKit::WebViewClient::zoomLimitsChanged): (WebKit::WebViewClient::zoomLevelChanged):
  • src/FrameLoaderClientImpl.cpp: (WebKit::FrameLoaderClientImpl::createPlugin):
  • src/WebPluginContainerImpl.cpp: (WebKit::WebPluginContainerImpl::loadFrameRequest): (WebKit::WebPluginContainerImpl::zoomChanged): (WebKit::WebPluginContainerImpl::zoomLimitsChanged):
  • src/WebPluginContainerImpl.h:
  • src/WebViewImpl.cpp: (WebKit::WebViewImpl::WebViewImpl): (WebKit::WebViewImpl::zoomLevel): (WebKit::WebViewImpl::setZoomLevel): (WebKit::WebViewImpl::zoomLimitsChanged): (WebKit::WebViewImpl::fullFramePluginZoomLevelChanged): (WebKit::WebView::zoomLevelToZoomFactor): (WebKit::WebView::zoomFactorToZoomLevel):
  • src/WebViewImpl.h:
Location:
trunk/WebKit/chromium
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r68865 r68869  
     12010-09-29  John Abd-El-Malek  <jam@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        [chromium] Changes to consolidate plugin zoom
     6        https://bugs.webkit.org/show_bug.cgi?id=46550
     7
     8        * public/WebPlugin.h:
     9        (WebKit::WebPlugin::setZoomLevel):
     10        * public/WebPluginContainer.h:
     11        * public/WebView.h:
     12        * public/WebViewClient.h:
     13        (WebKit::WebViewClient::zoomLimitsChanged):
     14        (WebKit::WebViewClient::zoomLevelChanged):
     15        * src/FrameLoaderClientImpl.cpp:
     16        (WebKit::FrameLoaderClientImpl::createPlugin):
     17        * src/WebPluginContainerImpl.cpp:
     18        (WebKit::WebPluginContainerImpl::loadFrameRequest):
     19        (WebKit::WebPluginContainerImpl::zoomChanged):
     20        (WebKit::WebPluginContainerImpl::zoomLimitsChanged):
     21        * src/WebPluginContainerImpl.h:
     22        * src/WebViewImpl.cpp:
     23        (WebKit::WebViewImpl::WebViewImpl):
     24        (WebKit::WebViewImpl::zoomLevel):
     25        (WebKit::WebViewImpl::setZoomLevel):
     26        (WebKit::WebViewImpl::zoomLimitsChanged):
     27        (WebKit::WebViewImpl::fullFramePluginZoomLevelChanged):
     28        (WebKit::WebView::zoomLevelToZoomFactor):
     29        (WebKit::WebView::zoomFactorToZoomLevel):
     30        * src/WebViewImpl.h:
     31
    1322010-09-30  MORITA Hajime  <morrita@google.com>
    233
  • trunk/WebKit/chromium/public/WebPlugin.h

    r63330 r68869  
    100100
    101101    // Used for zooming of full page plugins.
    102     virtual void setZoomFactor(float scale, bool textOnly) { }
     102    virtual void setZoomLevel(double level, bool textOnly) { }
    103103
    104104    // Find interface.
  • trunk/WebKit/chromium/public/WebPluginContainer.h

    r61942 r68869  
    7979        const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData) = 0;
    8080
     81    // Notifies that the zoom level has changed.
     82    virtual void zoomLevelChanged(double zoomLevel) = 0;
     83
    8184    virtual WebPlugin* plugin() = 0;
    8285    virtual void setPlugin(WebPlugin*) = 0;
  • trunk/WebKit/chromium/public/WebView.h

    r68367 r68869  
    3737#include "WebWidget.h"
    3838
     39// FIXME(jam): take this out after Chrome is updated
     40#define ZOOM_LEVEL_IS_DOUBLE
     41
    3942namespace WebKit {
    4043
     
    5558class WebView : public WebWidget {
    5659public:
     60    WEBKIT_API static const double textSizeMultiplierRatio;
     61    WEBKIT_API static const double minTextSizeMultiplier;
     62    WEBKIT_API static const double maxTextSizeMultiplier;
     63
    5764    // Controls the time that user scripts injected into the document run.
    5865    enum UserScriptInjectAt {
     
    162169
    163170    // Returns the current zoom level.  0 is "original size", and each increment
    164     // above or below represents zooming 20% larger or smaller to limits of 300%
    165     // and 50% of original size, respectively.
    166     virtual int zoomLevel() = 0;
     171    // above or below represents zooming 20% larger or smaller to default limits
     172    // of 300% and 50% of original size, respectively.  Only plugins use
     173    // non whole-numbers, since they might choose to have specific zoom level so
     174    // that fixed-width content is fit-to-page-width, for example.
     175    virtual double zoomLevel() = 0;
    167176
    168177    // Changes the zoom level to the specified level, clamping at the limits
     
    174183    // at one time.  Changing the mode while the page is zoomed will have odd
    175184    // effects.
    176     virtual int setZoomLevel(bool textOnly, int zoomLevel) = 0;
     185    virtual double setZoomLevel(bool textOnly, double zoomLevel) = 0;
     186
     187    // Updates the zoom limits for this view.
     188    virtual void zoomLimitsChanged(double minimumZoomLevel,
     189                                   double maximumZoomLevel) = 0;
     190
     191    // Helper functions to convert between zoom level and zoom factor.  zoom
     192    // factor is zoom percent / 100, so 300% = 3.0.
     193    WEBKIT_API static double zoomLevelToZoomFactor(double zoomLevel);
     194    WEBKIT_API static double zoomFactorToZoomLevel(double factor);
    177195
    178196
  • trunk/WebKit/chromium/public/WebViewClient.h

    r68240 r68869  
    349349    virtual WebDeviceOrientationClient* deviceOrientationClient() { return 0; }
    350350
     351
     352    // Zoom ----------------------------------------------------------------
     353
     354    // Informs the browser that the zoom levels for this frame have changed from
     355    // the default values.
     356    virtual void zoomLimitsChanged(double minimumLevel, double maximumLevel) { }
     357
     358    // Informs the browser that the zoom level has changed as a result of an
     359    // action that wasn't initiated by the client.
     360    virtual void zoomLevelChanged() { }
     361
    351362protected:
    352363    ~WebViewClient() { }
  • trunk/WebKit/chromium/src/FrameLoaderClientImpl.cpp

    r68576 r68869  
    14121412        return 0;
    14131413
    1414     bool zoomTextOnly = m_webFrame->viewImpl()->zoomTextOnly();
    1415     float zoomFactor = zoomTextOnly ? m_webFrame->frame()->textZoomFactor() : m_webFrame->frame()->pageZoomFactor();
    1416     if (zoomFactor != 1) {
    1417         // There's a saved zoom level, so tell the plugin about it since
    1418         // WebViewImpl::setZoomLevel was called before the plugin was created.
    1419         webPlugin->setZoomFactor(zoomFactor, zoomTextOnly);
    1420     }
    1421 
    14221414    // The element might have been removed during plugin initialization!
    14231415    if (!element->renderer())
  • trunk/WebKit/chromium/src/WebPluginContainerImpl.cpp

    r68656 r68869  
    4949#include "WebURLRequest.h"
    5050#include "WebVector.h"
     51#include "WebViewImpl.h"
    5152#include "WrappedResourceResponse.h"
    5253
     
    349350}
    350351
     352void WebPluginContainerImpl::zoomLevelChanged(double zoomLevel)
     353{
     354    WebViewImpl* view = WebViewImpl::fromPage(m_element->document()->frame()->page());
     355    view->fullFramePluginZoomLevelChanged(zoomLevel);
     356}
     357
    351358void WebPluginContainerImpl::didReceiveResponse(const ResourceResponse& response)
    352359{
  • trunk/WebKit/chromium/src/WebPluginContainerImpl.h

    r62743 r68869  
    8484    virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed);
    8585    virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData);
     86    virtual void zoomLevelChanged(double zoomLevel);
    8687
    8788    // This cannot be null.
  • trunk/WebKit/chromium/src/WebViewImpl.cpp

    r68865 r68869  
    147147// text zoom to half and 3x the original text size.  These three values match
    148148// those in Apple's port in WebKit/WebKit/WebView/WebView.mm
    149 static const double textSizeMultiplierRatio = 1.2;
    150 static const double minTextSizeMultiplier = 0.5;
    151 static const double maxTextSizeMultiplier = 3.0;
     149const double WebView::textSizeMultiplierRatio = 1.2;
     150const double WebView::minTextSizeMultiplier = 0.5;
     151const double WebView::maxTextSizeMultiplier = 3.0;
     152
    152153
    153154// The group name identifies a namespace of pages.  Page group is used on OSX
     
    254255#endif
    255256    , m_zoomLevel(0)
    256     , m_zoomTextOnly(false)
     257    , m_minimumZoomLevel(zoomFactorToZoomLevel(minTextSizeMultiplier))
     258    , m_maximumZoomLevel(zoomFactorToZoomLevel(maxTextSizeMultiplier))
    257259    , m_contextMenuAllowed(false)
    258260    , m_doingDragAndDrop(false)
     
    15281530}
    15291531
    1530 int WebViewImpl::zoomLevel()
     1532double WebViewImpl::zoomLevel()
    15311533{
    15321534    return m_zoomLevel;
    15331535}
    15341536
    1535 int WebViewImpl::setZoomLevel(bool textOnly, int zoomLevel)
    1536 {
    1537     float zoomFactor = static_cast<float>(
    1538         std::max(std::min(std::pow(textSizeMultiplierRatio, zoomLevel),
    1539                           maxTextSizeMultiplier),
    1540                  minTextSizeMultiplier));
     1537double WebViewImpl::setZoomLevel(bool textOnly, double zoomLevel)
     1538{
     1539    if (zoomLevel < m_minimumZoomLevel)
     1540        m_zoomLevel = m_minimumZoomLevel;
     1541    else if (zoomLevel > m_maximumZoomLevel)
     1542        m_zoomLevel = m_maximumZoomLevel;
     1543    else
     1544        m_zoomLevel = zoomLevel;
     1545
    15411546    Frame* frame = mainFrameImpl()->frame();
    1542 
    1543     float oldZoomFactor = m_zoomTextOnly ? frame->textZoomFactor() : frame->pageZoomFactor();
    1544 
    1545     if (textOnly)
    1546         frame->setPageAndTextZoomFactors(1, zoomFactor);
    1547     else
    1548         frame->setPageAndTextZoomFactors(zoomFactor, 1);
    1549 
    1550     if (oldZoomFactor != zoomFactor || textOnly != m_zoomTextOnly) {
    1551         WebPluginContainerImpl* pluginContainer = WebFrameImpl::pluginContainerFromFrame(frame);
    1552         if (pluginContainer)
    1553             pluginContainer->plugin()->setZoomFactor(zoomFactor, textOnly);
    1554     }
    1555 
    1556     m_zoomLevel = zoomLevel;
    1557     m_zoomTextOnly = textOnly;
    1558 
     1547    WebPluginContainerImpl* pluginContainer = WebFrameImpl::pluginContainerFromFrame(frame);
     1548    if (pluginContainer)
     1549        pluginContainer->plugin()->setZoomLevel(m_zoomLevel, textOnly);
     1550    else {
     1551        double zoomFactor = zoomLevelToZoomFactor(m_zoomLevel);
     1552        if (textOnly)
     1553            frame->setPageAndTextZoomFactors(1, zoomFactor);
     1554        else
     1555            frame->setPageAndTextZoomFactors(zoomFactor, 1);
     1556    }
    15591557    return m_zoomLevel;
     1558}
     1559
     1560void WebViewImpl::zoomLimitsChanged(double minimumZoomLevel,
     1561                                    double maximumZoomLevel)
     1562{
     1563    m_minimumZoomLevel = minimumZoomLevel;
     1564    m_maximumZoomLevel = maximumZoomLevel;
     1565    m_client->zoomLimitsChanged(m_minimumZoomLevel, m_maximumZoomLevel);
     1566}
     1567
     1568void WebViewImpl::fullFramePluginZoomLevelChanged(double zoomLevel)
     1569{
     1570    if (zoomLevel == m_zoomLevel)
     1571        return;
     1572
     1573    m_zoomLevel = std::max(std::min(zoomLevel, m_maximumZoomLevel), m_minimumZoomLevel);
     1574    m_client->zoomLevelChanged();
     1575}
     1576
     1577double WebView::zoomLevelToZoomFactor(double zoomLevel)
     1578{
     1579    return std::pow(textSizeMultiplierRatio, zoomLevel);
     1580}
     1581
     1582double WebView::zoomFactorToZoomLevel(double factor)
     1583{
     1584    // Since factor = 1.2^level, level = log(factor) / log(1.2)
     1585    return log(factor) / log(textSizeMultiplierRatio);
    15601586}
    15611587
  • trunk/WebKit/chromium/src/WebViewImpl.h

    r68865 r68869  
    133133    virtual void setInitialFocus(bool reverse);
    134134    virtual void clearFocusedNode();
    135     virtual int zoomLevel();
    136     virtual int setZoomLevel(bool textOnly, int zoomLevel);
     135    virtual double zoomLevel();
     136    virtual double setZoomLevel(bool textOnly, double zoomLevel);
     137    virtual void zoomLimitsChanged(double minimumZoomLevel,
     138                                   double maximumZoomLevel);
    137139    virtual void performMediaPlayerAction(
    138140        const WebMediaPlayerAction& action,
     
    343345    WebCore::PopupContainer* selectPopup() const { return m_selectPopup.get(); }
    344346
    345     bool zoomTextOnly() const { return m_zoomTextOnly; }
    346 
    347347    // Returns true if the event leads to scrolling.
    348348    static bool mapKeyCodeForScroll(int keyCode,
    349349                                   WebCore::ScrollDirection* scrollDirection,
    350350                                   WebCore::ScrollGranularity* scrollGranularity);
     351
     352    // Called by a full frame plugin inside this view to inform it that its
     353    // zoom level has been updated.  The plugin should only call this function
     354    // if the zoom change was triggered by the browser, it's only needed in case
     355    // a plugin can update its own zoom, say because of its own UI.
     356    void fullFramePluginZoomLevelChanged(double zoomLevel);
    351357
    352358private:
     
    441447    // Keeps track of the current zoom level. 0 means no zoom, positive numbers
    442448    // mean zoom in, negative numbers mean zoom out.
    443     int m_zoomLevel;
    444 
    445     bool m_zoomTextOnly;
     449    double m_zoomLevel;
     450
     451    double m_minimumZoomLevel;
     452
     453    double m_maximumZoomLevel;
    446454
    447455    bool m_contextMenuAllowed;
Note: See TracChangeset for help on using the changeset viewer.