[webkit-dev] Changing minimum font size
steve at opencommunity.co.uk
Mon Aug 22 17:57:41 PDT 2005
I assumed from reading the documentation that the third line was
apparently needed because the second line merely sets a property and
doesn't fire off any notification and hence I saw no way that the
webview would be refreshed with the new preferences. Unfortunately my
assumption was wrong since looking at the WebKit source shows that if
the new preferences pointer is identical to the old one, it does
Based on that, my next approach was this:
if (![NSApp enableMinimumFontSize])
WebPreferences * webPrefs = [[WebPreferences alloc] init];
[webPrefs setMinimumFontSize:[NSApp minimumFontSize]];
to toggle setting the minimum font size on or off. This worked fine -
except that the webview text font increased to 16pt from the original
12pt and wouldn't budge thenafter. After some thought, I realised
that the HTML being rendered didn't include any explicit font size in
the stylesheet and thus it was picking up the default from the newly
allocated WebPreference. However the default font size in webPrefs
was different from that in defaultWebPrefs. I've no idea why but
adding the following lines:
after the alloc solved the problem. A better approach would appear to
copy the entire contents of defaultWebPrefs into webPrefs after the
alloc and before setting the minimum font size as that would ensure
fidelity between the preferences.
Thanks for the pointer, John!
On Aug 22, 2005, at 8:52am, John Sullivan wrote:
> On Aug 21, 2005, at 3:55 PM, Steve Palmer wrote:
>> I asked this on the cocoa-dev alias but got no response. Hopefully
>> this is a more appropriate list?
>> I'm trying to get my head around web preferences. Based on my
>> reading of the API documentation, this should work to change the
>> minimum font size used by a webview that already has text:
>> WebPreferences * webPrefs = [myWebView preferences];
>> [webPrefs setMinimumFontSize:12];
>> [myWebView setPreferences:webPrefs];
>> However the existing webview text isn't changed. Any suggestions
>> what I'm missing?
>> - Steve
> The third line above isn't necessary; there's no need to set the
> preferences back to the same WebPreferences* object.
> The other two lines seem correct. It's not clear why this wouldn't
> be working in your case. You should be able to debug this if you
> build WebKit from the open-source repository (see
> webkit.opendarwin.org). Here's what should happen:
> Setting the minimum font size runs this code:
> - (void)setMinimumFontSize:(int)size
> [self _setIntegerValue: size forKey:
> _setIntegerValue should store the new value, and call [self
> _postPreferencesChangesNotification]. Note that _setIntegerValue
> will do nothing if the new value matches the old (but that
> shouldn't be your case, since the initial value of minimumFontSize
> should be 0, which represents no minimum.
> _postPreferencesChangedNotification should send a
> WebView should observe the _postPreferencesChangedNotification and
> call [self _updateWebCoreSettingsFromPreferences: preferences].
> _updateWebCoreSettingsFromPreferences then calls [_private-
> >settings setMinimumFontSize:[preferences minimumFontSize]] to make
> the new value known to WebCore.
> -[WebCoreSettings setMinimumFontSize:] then stores the value and
> calls [self _updateAllViews], which schedules a redraw that should
> use the new settings.
> So one of these steps must be failing in your case for some reason.
> You should be able to figure out which one with a little debugging.
> I hope this helps,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the webkit-dev