[Text Autosizing] Provide an API for influencing the font scale factor
authorpeter@chromium.org <peter@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Aug 2012 22:12:23 +0000 (22:12 +0000)
committerpeter@chromium.org <peter@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Aug 2012 22:12:23 +0000 (22:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=92882

Reviewed by Adam Barth.

Source/WebCore:

Add the font scale factor to settings, and provide an API in
window.internal.settings to change it from layout tests.

The font scale factor applied to Text Autosizing influences the sizing
of text, and will influence the scaling of boosted blocks once the
implementation progresses. For Android, it will be set to the font size
chosen in the user's system-wide preferences.

Test: fast/text-autosizing/font-scale-factor.html

* page/Settings.cpp:
(WebCore::Settings::Settings):
(WebCore):
(WebCore::Settings::setTextAutosizingFontScaleFactor):
* page/Settings.h:
(Settings):
(WebCore::Settings::textAutosizingFontScaleFactor):
* rendering/TextAutosizer.cpp:
(WebCore::TextAutosizer::processBlock):
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::Backup::Backup):
(WebCore::InternalSettings::Backup::restoreTo):
(WebCore::InternalSettings::setTextAutosizingFontScaleFactor):
(WebCore):
* testing/InternalSettings.h:
(Backup):
(InternalSettings):
* testing/InternalSettings.idl:

Source/WebKit/chromium:

Add an API to change Text Autosizing's font scale factor.

The font scale factor applied to Text Autosizing influences the sizing
of text, and will influence the scaling of boosted blocks once the
implementation progresses. For Android, it will be set to the font size
chosen in the user's system-wide preferences.

* public/WebSettings.h:
* src/WebSettingsImpl.cpp:
(WebKit::WebSettingsImpl::setTextAutosizingFontScaleFactor):
(WebKit):
* src/WebSettingsImpl.h:
(WebSettingsImpl):

LayoutTests:

Add a basic test. More usable tests should be added later, as it's
really hard to test this accurately in this phase of the implementation,
and Text Autosizing is still subject to various bugs.

The font scale factor applied to Text Autosizing influences the sizing
of text, and will influence the scaling of boosted blocks once the
implementation progresses. For Android, it will be set to the font size
chosen in the user's system-wide preferences.

* fast/text-autosizing/font-scale-factor-expected.html: Added.
* fast/text-autosizing/font-scale-factor.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@124372 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text-autosizing/font-scale-factor-expected.html [new file with mode: 0644]
LayoutTests/fast/text-autosizing/font-scale-factor.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/Settings.cpp
Source/WebCore/page/Settings.h
Source/WebCore/rendering/TextAutosizer.cpp
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/InternalSettings.idl
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebSettings.h
Source/WebKit/chromium/src/WebSettingsImpl.cpp
Source/WebKit/chromium/src/WebSettingsImpl.h

index d78c91b..04589e6 100644 (file)
@@ -1,3 +1,22 @@
+2012-08-01  Peter Beverloo  <peter@chromium.org>
+
+        [Text Autosizing] Provide an API for influencing the font scale factor
+        https://bugs.webkit.org/show_bug.cgi?id=92882
+
+        Reviewed by Adam Barth.
+
+        Add a basic test. More usable tests should be added later, as it's
+        really hard to test this accurately in this phase of the implementation,
+        and Text Autosizing is still subject to various bugs.
+
+        The font scale factor applied to Text Autosizing influences the sizing
+        of text, and will influence the scaling of boosted blocks once the
+        implementation progresses. For Android, it will be set to the font size
+        chosen in the user's system-wide preferences.
+
+        * fast/text-autosizing/font-scale-factor-expected.html: Added.
+        * fast/text-autosizing/font-scale-factor.html: Added.
+
 2012-08-01  Mike West  <mkwst@chromium.org>
 
         CSP should correctly block plugin resources rendered in PluginDocuments.
diff --git a/LayoutTests/fast/text-autosizing/font-scale-factor-expected.html b/LayoutTests/fast/text-autosizing/font-scale-factor-expected.html
new file mode 100644 (file)
index 0000000..a804ed1
--- /dev/null
@@ -0,0 +1,15 @@
+<html>
+  <head>
+    <meta name="viewport" content="width=800" />
+    <style>
+      body {
+        width: 800px;
+        margin: 0px;
+      }
+    </style>
+  </head>
+  <body>
+    <!-- FIXME: The line-height and margin-top shouldn't need to be changed here. The margins are a bug. See http://wkbug.com/91660. -->
+    <p style="font-size: 5rem; line-height: 0.30; margin: 2.20rem 0 1rem 0">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
+  </body>
+</html>
diff --git a/LayoutTests/fast/text-autosizing/font-scale-factor.html b/LayoutTests/fast/text-autosizing/font-scale-factor.html
new file mode 100644 (file)
index 0000000..2975d1f
--- /dev/null
@@ -0,0 +1,24 @@
+<html>
+  <head>
+    <meta name="viewport" content="width=800" />
+    <style>
+      body {
+        width: 800px;
+        margin: 0px;
+      }
+    </style>
+    <script>
+      if (window.internals) {
+        window.internals.settings.setTextAutosizingEnabled(true);
+        window.internals.settings.setTextAutosizingWindowSizeOverride(320, 480);
+        window.internals.settings.setTextAutosizingFontScaleFactor(2);
+      } else {
+        console.warn("Please use DumpRenderTree to run this test.");
+      }
+    </script>
+  </head>
+  <body>
+    <!-- FIXME: The line-height and margin-top shouldn't need to be changed here. See http://wkbug.com/91660. -->
+    <p style="line-height: 1.5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sapien sapien, tempus id egestas a, consectetur et felis. Ut pharetra mi eget lectus laoreet rutrum. Mauris tellus odio, egestas vitae sodales in, vehicula eget ante. Pellentesque id egestas arcu. Quisque tellus quam, rhoncus ac elementum vel, volutpat vel felis. Aliquam ut leo dolor, eget egestas tellus. Nunc ut velit gravida nisl fringilla rutrum eget at arcu. Vivamus et pretium mauris.</p>
+  </body>
+</html>
index 4b3ef43..055a842 100644 (file)
@@ -1,3 +1,39 @@
+2012-08-01  Peter Beverloo  <peter@chromium.org>
+
+        [Text Autosizing] Provide an API for influencing the font scale factor
+        https://bugs.webkit.org/show_bug.cgi?id=92882
+
+        Reviewed by Adam Barth.
+
+        Add the font scale factor to settings, and provide an API in
+        window.internal.settings to change it from layout tests.
+
+        The font scale factor applied to Text Autosizing influences the sizing
+        of text, and will influence the scaling of boosted blocks once the
+        implementation progresses. For Android, it will be set to the font size
+        chosen in the user's system-wide preferences.
+
+        Test: fast/text-autosizing/font-scale-factor.html
+
+        * page/Settings.cpp:
+        (WebCore::Settings::Settings):
+        (WebCore):
+        (WebCore::Settings::setTextAutosizingFontScaleFactor):
+        * page/Settings.h:
+        (Settings):
+        (WebCore::Settings::textAutosizingFontScaleFactor):
+        * rendering/TextAutosizer.cpp:
+        (WebCore::TextAutosizer::processBlock):
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::Backup::Backup):
+        (WebCore::InternalSettings::Backup::restoreTo):
+        (WebCore::InternalSettings::setTextAutosizingFontScaleFactor):
+        (WebCore):
+        * testing/InternalSettings.h:
+        (Backup):
+        (InternalSettings):
+        * testing/InternalSettings.idl:
+
 2012-08-01  Mike West  <mkwst@chromium.org>
 
         CSP should correctly block plugin resources rendered in PluginDocuments.
index dd55501..48e1f0e 100644 (file)
@@ -139,6 +139,7 @@ Settings::Settings(Page* page)
     , m_editingBehaviorType(editingBehaviorTypeForPlatform())
     , m_maximumHTMLParserDOMTreeDepth(defaultMaximumHTMLParserDOMTreeDepth)
 #if ENABLE(TEXT_AUTOSIZING)
+    , m_textAutosizingFontScaleFactor(1)
 #if HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP
     , m_textAutosizingWindowSizeOverride(320, 480)
     , m_textAutosizingEnabled(true)
@@ -429,6 +430,13 @@ void Settings::setTextAutosizingWindowSizeOverride(const IntSize& textAutosizing
     m_textAutosizingWindowSizeOverride = textAutosizingWindowSizeOverride;
     m_page->setNeedsRecalcStyleInAllFrames();
 }
+
+void Settings::setTextAutosizingFontScaleFactor(float fontScaleFactor)
+{
+    m_textAutosizingFontScaleFactor = fontScaleFactor;
+    m_page->setNeedsRecalcStyleInAllFrames();
+}
+
 #endif
 
 void Settings::setLoadsImagesAutomatically(bool loadsImagesAutomatically)
index 83f64ec..e6ddb68 100644 (file)
@@ -111,6 +111,9 @@ namespace WebCore {
         void setTextAutosizingEnabled(bool);
         bool textAutosizingEnabled() const { return m_textAutosizingEnabled; }
 
+        void setTextAutosizingFontScaleFactor(float);
+        float textAutosizingFontScaleFactor() const { return m_textAutosizingFontScaleFactor; }
+
         // Only set by Layout Tests, and only used if textAutosizingEnabled() returns true.
         void setTextAutosizingWindowSizeOverride(const IntSize&);
         const IntSize& textAutosizingWindowSizeOverride() const { return m_textAutosizingWindowSizeOverride; }
@@ -644,6 +647,7 @@ namespace WebCore {
         unsigned m_editingBehaviorType;
         unsigned m_maximumHTMLParserDOMTreeDepth;
 #if ENABLE(TEXT_AUTOSIZING)
+        float m_textAutosizingFontScaleFactor;
         IntSize m_textAutosizingWindowSizeOverride;
         bool m_textAutosizingEnabled : 1;
 #endif
index 0824aa3..82399c7 100644 (file)
@@ -68,6 +68,8 @@ void TextAutosizer::processBlock(RenderBlock* block, const IntSize& windowSize)
 {
     int windowLogicalWidth = block->isHorizontalWritingMode() ? windowSize.width() : windowSize.height();
     float multiplier = static_cast<float>(block->logicalWidth()) / windowLogicalWidth; // FIXME: This is overly simplistic.
+    multiplier *= m_document->settings()->textAutosizingFontScaleFactor();
+
     if (multiplier < 1)
         return;
     for (RenderObject* descendant = traverseNext(block, block, treatAsInline); descendant; descendant = traverseNext(descendant, block, treatAsInline)) {
index d359a02..aabe150 100755 (executable)
@@ -91,6 +91,7 @@ InternalSettings::Backup::Backup(Page* page, Settings* settings)
 #if ENABLE(TEXT_AUTOSIZING)
     , m_originalTextAutosizingEnabled(settings->textAutosizingEnabled())
     , m_originalTextAutosizingWindowSizeOverride(settings->textAutosizingWindowSizeOverride())
+    , m_originalTextAutosizingFontScaleFactor(settings->textAutosizingFontScaleFactor())
 #endif
 #if ENABLE(DIALOG_ELEMENT)
     , m_originalDialogElementEnabled(RuntimeEnabledFeatures::dialogElementEnabled())
@@ -121,6 +122,7 @@ void InternalSettings::Backup::restoreTo(Page* page, Settings* settings)
 #if ENABLE(TEXT_AUTOSIZING)
     settings->setTextAutosizingEnabled(m_originalTextAutosizingEnabled);
     settings->setTextAutosizingWindowSizeOverride(m_originalTextAutosizingWindowSizeOverride);
+    settings->setTextAutosizingFontScaleFactor(m_originalTextAutosizingFontScaleFactor);
 #endif
 #if ENABLE(DIALOG_ELEMENT)
     RuntimeEnabledFeatures::setDialogElementEnabled(m_originalDialogElementEnabled);
@@ -380,6 +382,17 @@ void InternalSettings::setTextAutosizingWindowSizeOverride(int width, int height
 #endif
 }
 
+void InternalSettings::setTextAutosizingFontScaleFactor(float fontScaleFactor, ExceptionCode& ec)
+{
+#if ENABLE(TEXT_AUTOSIZING)
+    InternalSettingsGuardForSettings();
+    settings()->setTextAutosizingFontScaleFactor(fontScaleFactor);
+#else
+    UNUSED_PARAM(fontScaleFactor);
+    UNUSED_PARAM(ec);
+#endif
+}
+
 void InternalSettings::setEnableScrollAnimator(bool enabled, ExceptionCode& ec)
 {
 #if ENABLE(SMOOTH_SCROLLING)
index bb25c58..9f40ef1 100755 (executable)
@@ -73,6 +73,7 @@ public:
 #if ENABLE(TEXT_AUTOSIZING)
         bool m_originalTextAutosizingEnabled;
         IntSize m_originalTextAutosizingWindowSizeOverride;
+        float m_originalTextAutosizingFontScaleFactor;
 #endif
 #if ENABLE(DIALOG_ELEMENT)
         bool m_originalDialogElementEnabled;
@@ -115,6 +116,7 @@ public:
     void setPictographFontFamily(const String& family, const String& script, ExceptionCode&);
     void setTextAutosizingEnabled(bool enabled, ExceptionCode&);
     void setTextAutosizingWindowSizeOverride(int width, int height, ExceptionCode&);
+    void setTextAutosizingFontScaleFactor(float fontScaleFactor, ExceptionCode&);
     void setEnableScrollAnimator(bool enabled, ExceptionCode&);
     bool scrollAnimatorEnabled(ExceptionCode&);
     void setCSSExclusionsEnabled(bool enabled, ExceptionCode&);
index 6c04bc6..45b1404 100755 (executable)
@@ -54,6 +54,7 @@ module window {
         void setPictographFontFamily(in DOMString family, in DOMString script) raises(DOMException);
         void setTextAutosizingEnabled(in boolean enabled) raises(DOMException);
         void setTextAutosizingWindowSizeOverride(in long width, in long height) raises(DOMException);
+        void setTextAutosizingFontScaleFactor(in float fontScaleFactor) raises(DOMException);
         void setEnableScrollAnimator(in boolean enabled) raises(DOMException);
         boolean scrollAnimatorEnabled() raises(DOMException);
         void setCSSExclusionsEnabled(in boolean enabled) raises(DOMException);
index eb3d868..8b847c7 100644 (file)
@@ -1,3 +1,24 @@
+2012-08-01  Peter Beverloo  <peter@chromium.org>
+
+        [Text Autosizing] Provide an API for influencing the font scale factor
+        https://bugs.webkit.org/show_bug.cgi?id=92882
+
+        Reviewed by Adam Barth.
+
+        Add an API to change Text Autosizing's font scale factor.
+
+        The font scale factor applied to Text Autosizing influences the sizing
+        of text, and will influence the scaling of boosted blocks once the
+        implementation progresses. For Android, it will be set to the font size
+        chosen in the user's system-wide preferences.
+
+        * public/WebSettings.h:
+        * src/WebSettingsImpl.cpp:
+        (WebKit::WebSettingsImpl::setTextAutosizingFontScaleFactor):
+        (WebKit):
+        * src/WebSettingsImpl.h:
+        (WebSettingsImpl):
+
 2012-08-01  Dirk Pranke  <dpranke@chromium.org>
 
         Roll chromium DEPS to 149416.
index 16fdc15..b763c48 100644 (file)
@@ -145,6 +145,7 @@ public:
     virtual void setSyncXHRInDocumentsEnabled(bool) = 0;
     virtual void setTextAreasAreResizable(bool) = 0;
     virtual void setTextAutosizingEnabled(bool) = 0;
+    virtual void setTextAutosizingFontScaleFactor(float) = 0;
     virtual void setTextDirectionSubmenuInclusionBehaviorNeverIncluded() = 0;
     virtual void setUnifiedTextCheckerEnabled(bool) = 0;
     virtual void setUserStyleSheetLocation(const WebURL&) = 0;
index 9fc608f..80a3a13 100644 (file)
@@ -149,6 +149,15 @@ void WebSettingsImpl::setTextAutosizingEnabled(bool enabled)
 #endif
 }
 
+void WebSettingsImpl::setTextAutosizingFontScaleFactor(float fontScaleFactor)
+{
+#if ENABLE(TEXT_AUTOSIZING)
+    m_settings->setTextAutosizingFontScaleFactor(fontScaleFactor);
+#else
+    UNUSED_PARAM(fontScaleFactor);
+#endif
+}
+
 void WebSettingsImpl::setDefaultTextEncodingName(const WebString& encoding)
 {
     m_settings->setDefaultTextEncodingName((String)encoding);
index 656529d..8f3305a 100644 (file)
@@ -140,6 +140,7 @@ public:
     virtual void setSyncXHRInDocumentsEnabled(bool);
     virtual void setTextAreasAreResizable(bool);
     virtual void setTextAutosizingEnabled(bool);
+    virtual void setTextAutosizingFontScaleFactor(float);
     virtual void setTextDirectionSubmenuInclusionBehaviorNeverIncluded();
     virtual void setUnifiedTextCheckerEnabled(bool);
     virtual void setUserStyleSheetLocation(const WebURL&);