[WK2] Add support for text document viewport configuration
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Feb 2014 23:03:03 +0000 (23:03 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Feb 2014 23:03:03 +0000 (23:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128359

Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-02-07
Reviewed by Simon Fraser.

Source/WebCore:

Define a set of ViewportParameters suitable for displaying text documents.
Add a documents class for text document to differentiate them from other type of documents.

* WebCore.exp.in:
* dom/Document.h:
(WebCore::Document::isTextDocument):
* html/TextDocument.cpp:
(WebCore::TextDocument::TextDocument):
* page/ViewportConfiguration.cpp:
(WebCore::ViewportConfiguration::ViewportConfiguration):
(WebCore::ViewportConfiguration::webpageParameters):
(WebCore::ViewportConfiguration::plainTextParameters):
* page/ViewportConfiguration.h:

Source/WebKit2:

When a text document is being loaded, use the plainText viewport parameters.

* UIProcess/API/ios/WKContentView.h:
* UIProcess/API/ios/WKContentView.mm:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::didCommitLoad):

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/dom/Document.h
Source/WebCore/html/TextDocument.cpp
Source/WebCore/page/ViewportConfiguration.cpp
Source/WebCore/page/ViewportConfiguration.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/ios/WKContentView.h
Source/WebKit2/UIProcess/API/ios/WKContentView.mm
Source/WebKit2/WebProcess/WebPage/WebPage.cpp

index 8520ed0..41b9cb7 100644 (file)
@@ -1,3 +1,24 @@
+2014-02-07  Benjamin Poulain  <bpoulain@apple.com>
+
+        [WK2] Add support for text document viewport configuration
+        https://bugs.webkit.org/show_bug.cgi?id=128359
+
+        Reviewed by Simon Fraser.
+
+        Define a set of ViewportParameters suitable for displaying text documents.
+        Add a documents class for text document to differentiate them from other type of documents.
+
+        * WebCore.exp.in:
+        * dom/Document.h:
+        (WebCore::Document::isTextDocument):
+        * html/TextDocument.cpp:
+        (WebCore::TextDocument::TextDocument):
+        * page/ViewportConfiguration.cpp:
+        (WebCore::ViewportConfiguration::ViewportConfiguration):
+        (WebCore::ViewportConfiguration::webpageParameters):
+        (WebCore::ViewportConfiguration::plainTextParameters):
+        * page/ViewportConfiguration.h:
+
 2014-02-07  Bem Jones-Bey  <bjonesbe@adobe.com>
 
         FloatingObject::unsafeClone should not copy m_originatingLine
index bfe2243..d4ffcdd 100644 (file)
@@ -849,6 +849,8 @@ __ZN7WebCore21SerializedScriptValueD1Ev
 __ZN7WebCore21URLByRemovingUserInfoEP5NSURL
 __ZN7WebCore21UserContentURLPattern5parseERKN3WTF6StringE
 __ZN7WebCore21ViewportConfiguration15setContentsSizeERKNS_7IntSizeE
+__ZN7WebCore21ViewportConfiguration17webpageParametersEv
+__ZN7WebCore21ViewportConfiguration19plainTextParametersEv
 __ZN7WebCore21ViewportConfiguration20setMinimumLayoutSizeERKNS_7IntSizeE
 __ZN7WebCore21ViewportConfiguration20setViewportArgumentsERKNS_17ViewportArgumentsE
 __ZN7WebCore21ViewportConfiguration23setDefaultConfigurationERKNS0_10ParametersE
index 90597af..403b277 100644 (file)
@@ -240,6 +240,7 @@ enum DocumentClass {
     PluginDocumentClass = 1 << 3,
     MediaDocumentClass = 1 << 4,
     SVGDocumentClass = 1 << 5,
+    TextDocumentClass = 1 << 6
 };
 
 typedef unsigned char DocumentClassFlags;
@@ -481,6 +482,7 @@ public:
     bool isSVGDocument() const { return m_documentClasses & SVGDocumentClass; }
     bool isPluginDocument() const { return m_documentClasses & PluginDocumentClass; }
     bool isMediaDocument() const { return m_documentClasses & MediaDocumentClass; }
+    bool isTextDocument() const { return m_documentClasses & TextDocumentClass; }
     bool hasSVGRootNode() const;
     virtual bool isFrameSet() const { return false; }
 
index 1fc166e..1e290b1 100644 (file)
@@ -30,7 +30,7 @@
 namespace WebCore {
 
 TextDocument::TextDocument(Frame* frame, const URL& url)
-    : HTMLDocument(frame, url)
+    : HTMLDocument(frame, url, TextDocumentClass)
 {
     setCompatibilityMode(QuirksMode);
     lockCompatibilityMode();
index 365904c..02f2781 100644 (file)
 #include <wtf/Assertions.h>
 #include <wtf/MathExtras.h>
 
+#if PLATFORM(IOS)
+#include "WebCoreSystemInterface.h"
+#endif
+
 namespace WebCore {
 
 #if !ASSERT_DISABLED
@@ -44,11 +48,7 @@ ViewportConfiguration::ViewportConfiguration()
 {
     // Setup a reasonable default configuration to avoid computing infinite scale/sizes.
     // Those are the original iPhone configuration.
-    m_defaultConfiguration.width = 980;
-    m_defaultConfiguration.widthIsSet = true;
-    m_defaultConfiguration.allowsUserScaling = true;
-    m_defaultConfiguration.minimumScale = 0.25;
-    m_defaultConfiguration.maximumScale = 5;
+    m_defaultConfiguration = ViewportConfiguration::webpageParameters();
     updateConfiguration();
 }
 
@@ -140,6 +140,35 @@ double ViewportConfiguration::minimumScale() const
     return minimumScale;
 }
 
+ViewportConfiguration::Parameters ViewportConfiguration::webpageParameters()
+{
+    Parameters parameters;
+    parameters.width = 980;
+    parameters.widthIsSet = true;
+    parameters.allowsUserScaling = true;
+    parameters.minimumScale = 0.25;
+    parameters.maximumScale = 5;
+    return parameters;
+}
+
+ViewportConfiguration::Parameters ViewportConfiguration::plainTextParameters()
+{
+    Parameters parameters;
+
+#if PLATFORM(IOS)
+    parameters.width = static_cast<int>(wkGetViewportScreenSize().width);
+#else
+    // FIXME: this needs to be unified with ViewportArguments on all ports.
+    parameters.width = 320;
+#endif
+
+    parameters.widthIsSet = true;
+    parameters.allowsUserScaling = true;
+    parameters.minimumScale = 0.25;
+    parameters.maximumScale = 5;
+    return parameters;
+}
+
 static inline bool viewportArgumentValueIsValid(float value)
 {
     return value > 0;
index 6ba52ff..a783b24 100644 (file)
@@ -82,6 +82,9 @@ public:
     double maximumScale() const { return m_configuration.maximumScale; }
     bool allowsUserScaling() const { return m_configuration.allowsUserScaling; }
 
+    static Parameters webpageParameters();
+    static Parameters plainTextParameters();
+
 private:
     void updateConfiguration();
     int layoutWidth() const;
index f9422a4..ad0ff47 100644 (file)
@@ -1,3 +1,17 @@
+2014-02-07  Benjamin Poulain  <bpoulain@apple.com>
+
+        [WK2] Add support for text document viewport configuration
+        https://bugs.webkit.org/show_bug.cgi?id=128359
+
+        Reviewed by Simon Fraser.
+
+        When a text document is being loaded, use the plainText viewport parameters.
+
+        * UIProcess/API/ios/WKContentView.h:
+        * UIProcess/API/ios/WKContentView.mm:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::didCommitLoad):
+
 2014-02-07  Gavin Barraclough  <barraclough@apple.com>
 
         Should report user input to PageThrottler
index cdc886e..2cd2a6b 100644 (file)
 @class WKContentView;
 @class WKWebViewConfiguration;
 
-typedef NS_ENUM(unsigned, WKContentType)
-{
-    Standard = 0,
-    PlainText,
-    Image
-};
-
 namespace WebKit {
 class RemoteLayerTreeTransaction;
 }
@@ -55,7 +48,6 @@ WK_API_CLASS
 @property (readonly, nonatomic) WKBrowsingContextController *browsingContextController;
 
 @property (nonatomic, assign) id <WKContentViewDelegate> delegate;
-@property (nonatomic, readonly) WKContentType contentType;
 
 @property (readonly) WKPageRef _pageRef;
 
index dfee8ac..fe1e8a7 100644 (file)
@@ -157,15 +157,6 @@ using namespace WebKit;
     return _browsingContextController.get();
 }
 
-- (WKContentType)contentType
-{
-    if (_page->mainFrame()->mimeType() == "text/plain")
-        return WKContentType::PlainText;
-    else if (_page->mainFrame()->isDisplayingStandaloneImageDocument())
-        return WKContentType::Image;
-    return WKContentType::Standard;
-}
-
 - (WKPageRef)_pageRef
 {
     return toAPI(_page.get());
index b0ea22b..b19b709 100644 (file)
@@ -3959,15 +3959,11 @@ void WebPage::didCommitLoad(WebFrame* frame)
 #if PLATFORM(IOS)
     m_userHasChangedPageScaleFactor = false;
 
-    // FIXME: Setup a real configuration.
-    ViewportConfiguration::Parameters defaultConfiguration;
-    defaultConfiguration.width = 980;
-    defaultConfiguration.widthIsSet = true;
-    defaultConfiguration.allowsUserScaling = true;
-    defaultConfiguration.minimumScale = 0.25;
-    defaultConfiguration.maximumScale = 5;
-
-    m_viewportConfiguration.setDefaultConfiguration(defaultConfiguration);
+    if (frame->coreFrame()->document()->isTextDocument())
+        m_viewportConfiguration.setDefaultConfiguration(ViewportConfiguration::plainTextParameters());
+    else
+        m_viewportConfiguration.setDefaultConfiguration(ViewportConfiguration::webpageParameters());
+
     m_viewportConfiguration.setViewportArguments(ViewportArguments());
     m_viewportConfiguration.setContentsSize(m_viewportConfiguration.minimumLayoutSize());
     viewportConfigurationChanged();