[haiku-webkit-commits] r283 - webkit/trunk/WebKit/haiku/API

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Thu, 04 Mar 2010 15:27:31 +0000

Author: stippi
Date: Thu Mar  4 15:27:31 2010
New Revision: 283
URL: http://mmlr.dyndns.org/changeset/283

Log:
* Added methods for setting the default fonts and font sizes.
 * Added explicit Apply() method.
 * Removed debug output from BWebSettings::_HandleSetPersistentStoragePath().
 * Enabled the PageCache for each page, when it has been enabled globally. Makes
   going back/forward instant, unless WebCore thinks a page cannot be cached,
   then it's as fast as before (loading from memory cached resources). It does
   for example work for static documents, but doesn't work for haiku-os.org,
   probably because there are "onload handlers" that would potentially break.

Modified:
   webkit/trunk/WebKit/haiku/API/WebSettings.cpp
   webkit/trunk/WebKit/haiku/API/WebSettings.h
   webkit/trunk/WebKit/haiku/API/WebSettingsPrivate.cpp
   webkit/trunk/WebKit/haiku/API/WebSettingsPrivate.h

Modified: webkit/trunk/WebKit/haiku/API/WebSettings.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebSettings.cpp       Thu Mar  4 15:23:15 
2010        (r282)
+++ webkit/trunk/WebKit/haiku/API/WebSettings.cpp       Thu Mar  4 15:27:31 
2010        (r283)
@@ -40,6 +40,7 @@
 #include <Directory.h>
 #include <Entry.h>
 #include <FindDirectory.h>
+#include <Font.h>
 #include <Path.h>
 #include <stdio.h>
 
@@ -52,7 +53,22 @@
        HANDLE_SET_OFFLINE_STORAGE_DEFAULT_QUOTA = 'hsoq',
        HANDLE_SET_OFFLINE_WEB_APPLICATION_CACHE_PATH = 'hsap',
        HANDLE_SET_OFFLINE_WEB_APPLICATION_CACHE_QUOTA = 'hsaq',
-       HANDLE_SET_LOCAL_STORAGE_PATH = 'hslp'
+       HANDLE_SET_LOCAL_STORAGE_PATH = 'hslp',
+       HANDLE_SET_FONT = 'hsfn',
+       HANDLE_SET_FONT_SIZE = 'hsfs',
+       HANDLE_APPLY = 'hapl'
+};
+
+enum {
+       SERIF_FONT = 0,
+       SANS_SERIF_FONT,
+       FIXED_FONT,
+       STANDARD_FONT,
+};
+
+enum {
+       STANDARD_FONT_SIZE = 0,
+       FIXED_FONT_SIZE,
 };
 
 BWebSettings::BWebSettings()
@@ -139,28 +155,90 @@
        _PostSetPath(this, HANDLE_SET_LOCAL_STORAGE_PATH, path);
 }
 
+void BWebSettings::SetSerifFont(const BFont& font)
+{
+    _PostFont(SERIF_FONT, font);
+}
+
+void BWebSettings::SetSansSerifFont(const BFont& font)
+{
+    _PostFont(SANS_SERIF_FONT, font);
+}
+
+void BWebSettings::SetFixedFont(const BFont& font)
+{
+    _PostFont(FIXED_FONT, font);
+}
+
+void BWebSettings::SetStandardFont(const BFont& font)
+{
+    _PostFont(STANDARD_FONT, font);
+}
+
+void BWebSettings::SetDefaultStandardFontSize(float size)
+{
+    _PostFontSize(STANDARD_FONT_SIZE, size);
+}
+
+void BWebSettings::SetDefaultFixedFontSize(float size)
+{
+    _PostFontSize(FIXED_FONT_SIZE, size);
+}
+
+void BWebSettings::Apply()
+{
+    Looper()->PostMessage(HANDLE_APPLY, this);
+}
+
 // #pragma mark - private
 
 void BWebSettings::_PostSetPath(BHandler* handler, uint32 what, const BString& 
path)
 {
        BMessage message(what);
        message.AddString("path", path.String());
-       if (find_thread(0) == handler->Looper()->Thread())
-           handler->MessageReceived(&message);
-       else
-           handler->Looper()->PostMessage(&message, handler);
+       _PostMessage(handler, &message);
 }
 
 void BWebSettings::_PostSetQuota(BHandler* handler, uint32 what, int64 
maximumSize)
 {
        BMessage message(what);
        message.AddInt64("quota", maximumSize);
+       _PostMessage(handler, &message);
+}
+
+void BWebSettings::_PostFont(uint32 which, const BFont& font)
+{
+       BMessage message(HANDLE_SET_FONT);
+       message.AddInt32("which", which);
+
+       font_family family;
+       font_style style;
+       font.GetFamilyAndStyle(&family, &style);
+       BString string(family);
+       string << ' ' << style;
+       message.AddString("font", string.String());
+
+       _PostMessage(this, &message);
+}
+
+void BWebSettings::_PostFontSize(uint32 which, float size)
+{
+       BMessage message(HANDLE_SET_FONT_SIZE);
+       message.AddInt32("which", which);
+       message.AddFloat("size", size);
+       _PostMessage(this, &message);
+}
+
+void BWebSettings::_PostMessage(BHandler* handler, BMessage* message)
+{
        if (find_thread(0) == handler->Looper()->Thread())
-           handler->MessageReceived(&message);
+           handler->MessageReceived(message);
        else
-           handler->Looper()->PostMessage(&message, handler);
+           handler->Looper()->PostMessage(message, handler);
 }
 
+// #pragma mark -
+
 void BWebSettings::MessageReceived(BMessage* message)
 {
        switch (message->what) {
@@ -213,6 +291,15 @@
                    _HandleSetLocalStoragePath(path);
                break;
        }
+       case HANDLE_SET_FONT:
+               _HandleSetFont(message);
+               break;
+       case HANDLE_SET_FONT_SIZE:
+               _HandleSetFontSize(message);
+               break;
+       case HANDLE_APPLY:
+               _HandleApply();
+               break;
        default:
                BHandler::MessageReceived(message);
        }
@@ -220,7 +307,6 @@
 
 void BWebSettings::_HandleSetPersistentStoragePath(const BString& path)
 {
-printf("BWebSettings::_HandleSetPersistentStoragePath(%s)\n", path.String());
     BPath storagePath;
 
     if (!path.Length())
@@ -323,3 +409,55 @@
     fData->apply();
 }
 
+void BWebSettings::_HandleSetFont(BMessage* message)
+{
+       int32 which;
+       if (message->FindInt32("which", &which) != B_OK)
+               return;
+       BString font;
+       if (message->FindString("font", &font) != B_OK)
+               return;
+       switch (which) {
+       case SERIF_FONT:
+        fData->serifFontFamily = font;
+        fData->serifFontFamilySet = true;
+        break;
+       case SANS_SERIF_FONT:
+        fData->sansSerifFontFamily = font;
+        fData->sansSerifFontFamilySet = true;
+        break;
+       case FIXED_FONT:
+        fData->fixedFontFamily = font;
+        fData->fixedFontFamilySet = true;
+        break;
+       case STANDARD_FONT:
+        fData->standardFontFamily = font;
+        fData->standardFontFamilySet = true;
+        break;
+       }
+}
+
+void BWebSettings::_HandleSetFontSize(BMessage* message)
+{
+       int32 which;
+       if (message->FindInt32("which", &which) != B_OK)
+               return;
+       float size;
+       if (message->FindFloat("size", &size) != B_OK)
+               return;
+       switch (which) {
+       case STANDARD_FONT_SIZE:
+        fData->defaultFontSize = size;
+        fData->defaultFontSizeSet = true;
+        break;
+       case FIXED_FONT_SIZE:
+        fData->defaultFixedFontSize = size;
+        fData->defaultFixedFontSizeSet = true;
+        break;
+       }
+}
+
+void BWebSettings::_HandleApply()
+{
+       fData->apply();
+}

Modified: webkit/trunk/WebKit/haiku/API/WebSettings.h
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebSettings.h Thu Mar  4 15:23:15 2010        
(r282)
+++ webkit/trunk/WebKit/haiku/API/WebSettings.h Thu Mar  4 15:27:31 2010        
(r283)
@@ -32,6 +32,7 @@
 
 
 class BBitmap;
+class BFont;
 class BMessenger;
 class BWebPage;
 
@@ -72,6 +73,16 @@
     
                        void                            
SetLocalStoragePath(const BString& path);
 
+                       void                            SetSerifFont(const 
BFont& font);
+                       void                            SetSansSerifFont(const 
BFont& font);
+                       void                            SetFixedFont(const 
BFont& font);
+                       void                            SetStandardFont(const 
BFont& font);
+
+                       void                            
SetDefaultStandardFontSize(float size);
+                       void                            
SetDefaultFixedFontSize(float size);
+
+                       void                            Apply();
+
 private:
                        friend class BWebPage;
                        friend class BPrivate::WebSettingsPrivate;
@@ -83,6 +94,9 @@
 private:
        static  void                            _PostSetPath(BHandler* handler, 
uint32 what, const BString& path);
        static  void                            _PostSetQuota(BHandler* 
handler, uint32 what, int64 maximumSize);
+                       void                            _PostFont(uint32 which, 
const BFont& font);
+                       void                            _PostFontSize(uint32 
which, float size);
+       static  void                            _PostMessage(BHandler* handler, 
BMessage* message);
 
        virtual void                            MessageReceived(BMessage* 
message);
 
@@ -95,6 +109,9 @@
                        void                            
_HandleSetWebApplicationCachePath(const BString& path);
                        void                            
_HandleSetWebApplicationCacheQuota(int64 maximumSize);
                        void                            
_HandleSetLocalStoragePath(const BString& path);
+                       void                            
_HandleSetFont(BMessage* message);
+                       void                            
_HandleSetFontSize(BMessage* message);
+                       void                            _HandleApply();
 private:
                        BPrivate::WebSettingsPrivate* fData;
 };

Modified: webkit/trunk/WebKit/haiku/API/WebSettingsPrivate.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebSettingsPrivate.cpp        Thu Mar  4 
15:23:15 2010        (r282)
+++ webkit/trunk/WebKit/haiku/API/WebSettingsPrivate.cpp        Thu Mar  4 
15:27:31 2010        (r283)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "WebSettingsPrivate.h"
 
+#include "PageCache.h"
 #include "PlatformString.h"
 #include "Settings.h"
 #include "WebSettings.h"
@@ -43,10 +44,26 @@
     , localStorageEnabled(false)
     , databasesEnabled(false)
     , offlineWebApplicationCacheEnabled(false)
+    , serifFontFamilySet(false)
+    , sansSerifFontFamilySet(false)
+    , fixedFontFamilySet(false)
+    , standardFontFamilySet(false)
+    , defaultFontSizeSet(false)
+    , defaultFixedFontSizeSet(false)
 {
        apply();
        if (settings)
            sAllSettings.AddItem(this);
+       else {
+               // Initialize some default settings
+               // TODO: Get these from the system settings.
+               serifFontFamily = "DejaVu Serif";
+               sansSerifFontFamily = "DejaVu Sans";
+               fixedFontFamily = "DejaVu Sans Mono";
+               standardFontFamily = serifFontFamily;
+               defaultFontSize = 14;
+               defaultFixedFontSize = 14;
+       }
 }
 
 WebSettingsPrivate::~WebSettingsPrivate()
@@ -59,9 +76,7 @@
 {
        if (settings) {
                WebSettingsPrivate* global = BWebSettings::Default()->fData;
-           // Default settings
-           // TODO: Get attributes from hash map and fall back to global 
settings if
-           // attributes are not set.
+           // Apply default values
            settings->setLoadsImagesAutomatically(true);
            settings->setMinimumFontSize(5);
            settings->setMinimumLogicalFontSize(5);
@@ -72,15 +87,39 @@
            settings->setEditingBehavior(WebCore::EditingMacBehavior);
            settings->setLocalStorageEnabled(global->localStorageEnabled);
            settings->setLocalStorageDatabasePath(global->localStoragePath);
-       
-           settings->setDefaultFixedFontSize(14);
-           settings->setDefaultFontSize(14);
-       
-           settings->setSerifFontFamily("DejaVu Serif");
-           settings->setSansSerifFontFamily("DejaVu Sans");
-           settings->setFixedFontFamily("DejaVu Sans Mono");
-           settings->setStandardFontFamily("DejaVu Serif");
            settings->setDefaultTextEncodingName("UTF-8");
+        settings->setUsesPageCache(WebCore::pageCache()->capacity());
+
+           // Apply local or global settings
+               if (defaultFontSizeSet)
+            settings->setDefaultFontSize(defaultFontSize);
+               else
+            settings->setDefaultFontSize(global->defaultFontSize);
+
+               if (defaultFixedFontSizeSet)
+            settings->setDefaultFixedFontSize(defaultFixedFontSize);
+               else
+            settings->setDefaultFixedFontSize(global->defaultFixedFontSize);
+
+               if (serifFontFamilySet)
+            settings->setSerifFontFamily(serifFontFamily.String());
+               else
+            settings->setSerifFontFamily(global->serifFontFamily.String());
+
+               if (sansSerifFontFamilySet)
+            settings->setSansSerifFontFamily(sansSerifFontFamily.String());
+               else
+            
settings->setSansSerifFontFamily(global->sansSerifFontFamily.String());
+
+               if (fixedFontFamilySet)
+            settings->setFixedFontFamily(fixedFontFamily.String());
+               else
+            settings->setFixedFontFamily(global->fixedFontFamily.String());
+
+               if (standardFontFamilySet)
+            settings->setStandardFontFamily(standardFontFamily.String());
+               else
+            
settings->setStandardFontFamily(global->standardFontFamily.String());
        } else {
            int32 count = sAllSettings.CountItems();
            for (int32 i = 0; i < count; i++) {

Modified: webkit/trunk/WebKit/haiku/API/WebSettingsPrivate.h
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebSettingsPrivate.h  Thu Mar  4 15:23:15 
2010        (r282)
+++ webkit/trunk/WebKit/haiku/API/WebSettingsPrivate.h  Thu Mar  4 15:27:31 
2010        (r283)
@@ -52,6 +52,20 @@
     bool databasesEnabled;
     bool offlineWebApplicationCacheEnabled;
 
+       BString serifFontFamily;
+       BString sansSerifFontFamily;
+       BString fixedFontFamily;
+       BString standardFontFamily;
+       float defaultFontSize;
+       float defaultFixedFontSize;
+
+       bool serifFontFamilySet : 1;
+       bool sansSerifFontFamilySet : 1;
+       bool fixedFontFamilySet : 1;
+       bool standardFontFamilySet : 1;
+       bool defaultFontSizeSet : 1;
+       bool defaultFixedFontSizeSet : 1;
+
 private:
        static BList sAllSettings;
 };

Other related posts:

  • » [haiku-webkit-commits] r283 - webkit/trunk/WebKit/haiku/API - webkit