Title: [121866] trunk/Source/WebCore
Revision
121866
Author
[email protected]
Date
2012-07-04 10:43:12 -0700 (Wed, 04 Jul 2012)

Log Message

Text Autosizing: Add basic framework
https://bugs.webkit.org/show_bug.cgi?id=88655

This adds a highly simplified foundation that subsequent Text Autosizing patches
can build upon. I've refactored this code (since the earlier combined diff
uploaded to http://webkit.org/b/84186) to touch as few files as possible.

Patch by John Mellor <[email protected]> on 2012-07-04
Reviewed by Adam Barth.

No new tests. I plan to add a test framework as my next Text Autosizing patch.

* WebCore.gypi:
* dom/Document.cpp:
(WebCore::Document::Document):
* dom/Document.h:
(WebCore):
(Document):
(WebCore::Document::textAutosizer):
* page/FrameView.cpp:
(WebCore::FrameView::layout):
* rendering/TextAutosizer.cpp: Added.
(WebCore):
(WebCore::TextAutosizer::TextAutosizer):
(WebCore::TextAutosizer::~TextAutosizer):
(WebCore::TextAutosizer::create):
(WebCore::TextAutosizer::boostSubtree):
(WebCore::TextAutosizer::boostBlock):
(WebCore::TextAutosizer::boostText):
(WebCore::TextAutosizer::treatAsInline):
(WebCore::TextAutosizer::traverseNext):
(WebCore::TextAutosizer::cloneRenderStyleWithState):
* rendering/TextAutosizer.h: Added.
(WebCore):
(TextAutosizer):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (121865 => 121866)


--- trunk/Source/WebCore/ChangeLog	2012-07-04 17:39:26 UTC (rev 121865)
+++ trunk/Source/WebCore/ChangeLog	2012-07-04 17:43:12 UTC (rev 121866)
@@ -1,3 +1,40 @@
+2012-07-04  John Mellor  <[email protected]>
+
+        Text Autosizing: Add basic framework
+        https://bugs.webkit.org/show_bug.cgi?id=88655
+
+        This adds a highly simplified foundation that subsequent Text Autosizing patches
+        can build upon. I've refactored this code (since the earlier combined diff
+        uploaded to http://webkit.org/b/84186) to touch as few files as possible.
+
+        Reviewed by Adam Barth.
+
+        No new tests. I plan to add a test framework as my next Text Autosizing patch.
+
+        * WebCore.gypi:
+        * dom/Document.cpp:
+        (WebCore::Document::Document):
+        * dom/Document.h:
+        (WebCore):
+        (Document):
+        (WebCore::Document::textAutosizer):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::layout):
+        * rendering/TextAutosizer.cpp: Added.
+        (WebCore):
+        (WebCore::TextAutosizer::TextAutosizer):
+        (WebCore::TextAutosizer::~TextAutosizer):
+        (WebCore::TextAutosizer::create):
+        (WebCore::TextAutosizer::boostSubtree):
+        (WebCore::TextAutosizer::boostBlock):
+        (WebCore::TextAutosizer::boostText):
+        (WebCore::TextAutosizer::treatAsInline):
+        (WebCore::TextAutosizer::traverseNext):
+        (WebCore::TextAutosizer::cloneRenderStyleWithState):
+        * rendering/TextAutosizer.h: Added.
+        (WebCore):
+        (TextAutosizer):
+
 2012-07-04  Andrey Kosyakov  <[email protected]>
 
         Unreviewed, rolling out r121767.

Modified: trunk/Source/WebCore/WebCore.gypi (121865 => 121866)


--- trunk/Source/WebCore/WebCore.gypi	2012-07-04 17:39:26 UTC (rev 121865)
+++ trunk/Source/WebCore/WebCore.gypi	2012-07-04 17:43:12 UTC (rev 121866)
@@ -4630,6 +4630,8 @@
             'rendering/FixedTableLayout.h',
             'rendering/FlowThreadController.cpp',
             'rendering/FlowThreadController.h',
+            'rendering/TextAutosizer.cpp',
+            'rendering/TextAutosizer.h',
             'rendering/HitTestingTransformState.cpp',
             'rendering/HitTestingTransformState.h',
             'rendering/HitTestResult.cpp',

Modified: trunk/Source/WebCore/dom/Document.cpp (121865 => 121866)


--- trunk/Source/WebCore/dom/Document.cpp	2012-07-04 17:39:26 UTC (rev 121865)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-07-04 17:43:12 UTC (rev 121866)
@@ -216,6 +216,10 @@
 #include "Prerenderer.h"
 #endif
 
+#if ENABLE(TEXT_AUTOSIZING)
+#include "TextAutosizer.h"
+#endif
+
 using namespace std;
 using namespace WTF;
 using namespace Unicode;
@@ -516,6 +520,9 @@
 #if ENABLE(LINK_PRERENDER)
     m_prerenderer = Prerenderer::create(this);
 #endif
+#if ENABLE(TEXT_AUTOSIZING)
+    m_textAutosizer = TextAutosizer::create(this);
+#endif
     m_visuallyOrdered = false;
     m_bParsing = false;
     m_wellFormed = false;

Modified: trunk/Source/WebCore/dom/Document.h (121865 => 121866)


--- trunk/Source/WebCore/dom/Document.h	2012-07-04 17:39:26 UTC (rev 121865)
+++ trunk/Source/WebCore/dom/Document.h	2012-07-04 17:43:12 UTC (rev 121866)
@@ -173,6 +173,10 @@
 class Prerenderer;
 #endif
 
+#if ENABLE(TEXT_AUTOSIZING)
+class TextAutosizer;
+#endif
+
 typedef int ExceptionCode;
 
 enum PageshowEventPersistence {
@@ -1129,6 +1133,10 @@
     Prerenderer* prerenderer() { return m_prerenderer.get(); }
 #endif
 
+#if ENABLE(TEXT_AUTOSIZING)
+    TextAutosizer* textAutosizer() { return m_textAutosizer.get(); }
+#endif
+
     void adjustFloatQuadsForScrollAndAbsoluteZoomAndFrameScale(Vector<FloatQuad>&, RenderObject*);
     void adjustFloatRectForScrollAndAbsoluteZoomAndFrameScale(FloatRect&, RenderObject*);
 
@@ -1494,6 +1502,10 @@
     OwnPtr<Prerenderer> m_prerenderer;
 #endif
 
+#if ENABLE(TEXT_AUTOSIZING)
+    OwnPtr<TextAutosizer> m_textAutosizer;
+#endif
+
     bool m_scheduledTasksAreSuspended;
     
     bool m_visualUpdatesAllowed;

Modified: trunk/Source/WebCore/page/FrameView.cpp (121865 => 121866)


--- trunk/Source/WebCore/page/FrameView.cpp	2012-07-04 17:39:26 UTC (rev 121865)
+++ trunk/Source/WebCore/page/FrameView.cpp	2012-07-04 17:43:12 UTC (rev 121866)
@@ -87,6 +87,10 @@
 #include "TiledBackingStore.h"
 #endif
 
+#if ENABLE(TEXT_AUTOSIZING)
+#include "TextAutosizer.h"
+#endif
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -1111,6 +1115,11 @@
             beginDeferredRepaints();
             forceLayoutParentViewIfNeeded();
             root->layout();
+#if ENABLE(TEXT_AUTOSIZING)
+            bool boosted = document->textAutosizer()->boostSubtree(root);
+            if (boosted && root->needsLayout())
+                root->layout();
+#endif
             endDeferredRepaints();
             m_inLayout = false;
 

Added: trunk/Source/WebCore/rendering/TextAutosizer.cpp (0 => 121866)


--- trunk/Source/WebCore/rendering/TextAutosizer.cpp	                        (rev 0)
+++ trunk/Source/WebCore/rendering/TextAutosizer.cpp	2012-07-04 17:43:12 UTC (rev 121866)
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(TEXT_AUTOSIZING)
+
+#include "TextAutosizer.h"
+
+#include "Document.h"
+#include "InspectorInstrumentation.h"
+#include "RenderObject.h"
+#include "RenderText.h"
+#include "RenderView.h"
+#include "Settings.h"
+
+namespace WebCore {
+
+TextAutosizer::TextAutosizer(Document* document)
+    : m_document(document)
+{
+}
+
+TextAutosizer::~TextAutosizer()
+{
+}
+
+bool TextAutosizer::boostSubtree(RenderObject* layoutRoot)
+{
+    // FIXME: Text Autosizing should only be enabled when m_document->page()->mainFrame()->view()->useFixedLayout()
+    // is true, but for now it's useful to ignore this so that it can be tested on desktop.
+    if (!m_document->settings() || !m_document->settings()->textAutosizingEnabled() || layoutRoot->view()->printing() || !m_document->page())
+        return false;
+
+#ifdef HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP
+    IntSize windowSize(320, 480);
+#else
+    Frame* mainFrame = m_document->page()->mainFrame();
+    bool includeScrollbars = !InspectorInstrumentation::shouldApplyScreenWidthOverride(mainFrame);
+    IntSize windowSize = mainFrame->view()->visibleContentRect(includeScrollbars).size(); // FIXME: Check that this is always in logical (density-independent) pixels (see wkbug.com/87440).
+#endif
+
+    for (RenderObject* descendant = traverseNext(layoutRoot, layoutRoot); descendant; descendant = traverseNext(descendant, layoutRoot)) {
+        if (!treatAsInline(descendant))
+            boostBlock(toRenderBlock(descendant), windowSize);
+    }
+
+    return true;
+}
+
+void TextAutosizer::boostBlock(RenderBlock* block, LayoutSize windowSize)
+{
+    float windowLogicalWidth = block->isHorizontalWritingMode() ? windowSize.width() : windowSize.height();
+    float multiplier = block->logicalWidth() / windowLogicalWidth; // FIXME: This is overly simplistic.
+    if (multiplier < 1)
+        return;
+    for (RenderObject* descendant = traverseNext(block, block, treatAsInline); descendant; descendant = traverseNext(descendant, block, treatAsInline)) {
+        if (descendant->isText())
+            boostText(toRenderText(descendant), multiplier);
+    }
+}
+
+void TextAutosizer::boostText(RenderText* text, float multiplier)
+{
+    float specifiedSize = text->style()->fontDescription().specifiedSize();
+    float boostedSize = specifiedSize * multiplier; // FIXME: This is overly simplistic.
+
+    RefPtr<RenderStyle> style = RenderStyle::clone(text->style());
+    FontDescription fontDescription(style->fontDescription());
+    fontDescription.setComputedSize(boostedSize);
+    style->setFontDescription(fontDescription);
+    style->font().update(style->font().fontSelector());
+    text->setStyle(style.release());
+
+    // FIXME: Increase computed line height proportionately.
+    // FIXME: Boost list markers proportionately.
+}
+
+bool TextAutosizer::treatAsInline(const RenderObject* renderer)
+{
+    return !renderer->isRenderBlock() || renderer->isListItem() || renderer->isInlineBlockOrInlineTable();
+}
+
+RenderObject* TextAutosizer::traverseNext(RenderObject* current, const RenderObject* stayWithin, RenderObjectFilter filter)
+{
+    for (RenderObject* child = current->firstChild(); child; child = child->nextSibling()) {
+        if (!filter || filter(child)) {
+            ASSERT(!stayWithin || child->isDescendantOf(stayWithin));
+            return child;
+        }
+    }
+
+    for (RenderObject* ancestor = current; ancestor; ancestor = ancestor->parent()) {
+        if (ancestor == stayWithin)
+            return 0;
+        for (RenderObject* sibling = ancestor->nextSibling(); sibling; sibling = sibling->nextSibling()) {
+            if (!filter || filter(sibling)) {
+                ASSERT(!stayWithin || sibling->isDescendantOf(stayWithin));
+                return sibling;
+            }
+        }
+    }
+
+    return 0;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(TEXT_AUTOSIZING)

Added: trunk/Source/WebCore/rendering/TextAutosizer.h (0 => 121866)


--- trunk/Source/WebCore/rendering/TextAutosizer.h	                        (rev 0)
+++ trunk/Source/WebCore/rendering/TextAutosizer.h	2012-07-04 17:43:12 UTC (rev 121866)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TextAutosizer_h
+#define TextAutosizer_h
+
+#if ENABLE(TEXT_AUTOSIZING)
+
+#include "LayoutTypes.h"
+#include <wtf/Noncopyable.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+class Document;
+class RenderBlock;
+class RenderObject;
+class RenderStyle;
+class RenderText;
+
+class TextAutosizer {
+    WTF_MAKE_NONCOPYABLE(TextAutosizer);
+
+public:
+    static PassOwnPtr<TextAutosizer> create(Document* document) { return adoptPtr(new TextAutosizer(document)); }
+
+    virtual ~TextAutosizer();
+
+    bool boostSubtree(RenderObject* layoutRoot);
+
+private:
+    explicit TextAutosizer(Document*);
+
+    void boostBlock(RenderBlock*, LayoutSize windowSize);
+    void boostText(RenderText*, float multiplier);
+
+    typedef bool (*RenderObjectFilter)(const RenderObject*);
+    static bool treatAsInline(const RenderObject*);
+
+    RenderObject* traverseNext(RenderObject* current, const RenderObject* stayWithin, RenderObjectFilter = 0);
+
+    Document* m_document;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(TEXT_AUTOSIZING)
+
+#endif // TextAutosizer_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to