Merge mozilla-central to b2g-inbound

This commit is contained in:
Carsten "Tomcat" Book 2014-06-02 15:28:19 +02:00
commit fe8c4744c1
48 changed files with 2064 additions and 1105 deletions

View File

@ -1467,7 +1467,7 @@ pref("browser.newtabpage.rows", 3);
// number of columns of newtab grid
pref("browser.newtabpage.columns", 3);
pref("browser.newtabpage.directorySource", "chrome://global/content/directoryLinks.json");
pref("browser.newtabpage.directory.source", "chrome://global/content/directoryLinks.json");
// Enable the DOM fullscreen API.
pref("full-screen-api.enabled", true);

View File

@ -217,6 +217,7 @@ let gPage = {
}
}
DirectoryLinksProvider.reportShownCount(directoryCount);
// Record how many directory sites were shown, but place counts over the
// default 9 in the same bucket
for (let type of Object.keys(directoryCount)) {

View File

@ -56,7 +56,7 @@ const EXPECTED_REFLOWS = [
];
const PREF_PRELOAD = "browser.newtab.preload";
const PREF_NEWTAB_DIRECTORYSOURCE = "browser.newtabpage.directorySource";
const PREF_NEWTAB_DIRECTORYSOURCE = "browser.newtabpage.directory.source";
/*
* This test ensures that there are no unexpected
@ -64,26 +64,51 @@ const PREF_NEWTAB_DIRECTORYSOURCE = "browser.newtabpage.directorySource";
*/
function test() {
waitForExplicitFinish();
let DirectoryLinksProvider = Cu.import("resource://gre/modules/DirectoryLinksProvider.jsm", {}).DirectoryLinksProvider;
let NewTabUtils = Cu.import("resource://gre/modules/NewTabUtils.jsm", {}).NewTabUtils;
let Promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
// resolves promise when directory links are downloaded and written to disk
function watchLinksChangeOnce() {
let deferred = Promise.defer();
let observer = {
onManyLinksChanged: () => {
DirectoryLinksProvider.removeObserver(observer);
NewTabUtils.links.populateCache(() => {
NewTabUtils.allPages.update();
deferred.resolve();
}, true);
}
};
observer.onDownloadFail = observer.onManyLinksChanged;
DirectoryLinksProvider.addObserver(observer);
return deferred.promise;
};
Services.prefs.setBoolPref(PREF_PRELOAD, false);
Services.prefs.setCharPref(PREF_NEWTAB_DIRECTORYSOURCE, "data:application/json,{}");
registerCleanupFunction(() => {
Services.prefs.clearUserPref(PREF_PRELOAD);
Services.prefs.clearUserPref(PREF_NEWTAB_DIRECTORYSOURCE);
return watchLinksChangeOnce();
});
// Add a reflow observer and open a new tab.
docShell.addWeakReflowObserver(observer);
BrowserOpenTab();
// run tests when directory source change completes
watchLinksChangeOnce().then(() => {
// Add a reflow observer and open a new tab.
docShell.addWeakReflowObserver(observer);
BrowserOpenTab();
// Wait until the tabopen animation has finished.
waitForTransitionEnd(function () {
// Remove reflow observer and clean up.
docShell.removeWeakReflowObserver(observer);
gBrowser.removeCurrentTab();
finish();
// Wait until the tabopen animation has finished.
waitForTransitionEnd(function () {
// Remove reflow observer and clean up.
docShell.removeWeakReflowObserver(observer);
gBrowser.removeCurrentTab();
finish();
});
});
Services.prefs.setBoolPref(PREF_PRELOAD, false);
// set directory source to empty links
Services.prefs.setCharPref(PREF_NEWTAB_DIRECTORYSOURCE, "data:application/json,{}");
}
let observer = {

View File

@ -2,20 +2,19 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
const PREF_NEWTAB_ENABLED = "browser.newtabpage.enabled";
const PREF_NEWTAB_DIRECTORYSOURCE = "browser.newtabpage.directorySource";
const PREF_NEWTAB_DIRECTORYSOURCE = "browser.newtabpage.directory.source";
Services.prefs.setBoolPref(PREF_NEWTAB_ENABLED, true);
// start with no directory links by default
Services.prefs.setCharPref(PREF_NEWTAB_DIRECTORYSOURCE, "data:application/json,{}");
let tmp = {};
Cu.import("resource://gre/modules/Promise.jsm", tmp);
Cu.import("resource://gre/modules/NewTabUtils.jsm", tmp);
Cu.import("resource://gre/modules/DirectoryLinksProvider.jsm", tmp);
Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader)
.loadSubScript("chrome://browser/content/sanitize.js", tmp);
Cu.import("resource://gre/modules/Timer.jsm", tmp);
let {Promise, NewTabUtils, Sanitizer, clearTimeout} = tmp;
let {Promise, NewTabUtils, Sanitizer, clearTimeout, DirectoryLinksProvider} = tmp;
let uri = Services.io.newURI("about:newtab", null, null);
let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
@ -60,22 +59,45 @@ registerCleanupFunction(function () {
if (oldInnerHeight)
gBrowser.contentWindow.innerHeight = oldInnerHeight;
Services.prefs.clearUserPref(PREF_NEWTAB_ENABLED);
Services.prefs.clearUserPref(PREF_NEWTAB_DIRECTORYSOURCE);
// Stop any update timers to prevent unexpected updates in later tests
let timer = NewTabUtils.allPages._scheduleUpdateTimeout;
if (timer) {
clearTimeout(timer);
delete NewTabUtils.allPages._scheduleUpdateTimeout;
}
Services.prefs.clearUserPref(PREF_NEWTAB_ENABLED);
Services.prefs.clearUserPref(PREF_NEWTAB_DIRECTORYSOURCE);
return watchLinksChangeOnce();
});
/**
* Resolves promise when directory links are downloaded and written to disk
*/
function watchLinksChangeOnce() {
let deferred = Promise.defer();
let observer = {
onManyLinksChanged: () => {
DirectoryLinksProvider.removeObserver(observer);
deferred.resolve();
}
};
observer.onDownloadFail = observer.onManyLinksChanged;
DirectoryLinksProvider.addObserver(observer);
return deferred.promise;
};
/**
* Provide the default test function to start our test runner.
*/
function test() {
TestRunner.run();
waitForExplicitFinish();
// start TestRunner.run() after directory links is downloaded and written to disk
watchLinksChangeOnce().then(() => {
TestRunner.run();
});
Services.prefs.setCharPref(PREF_NEWTAB_DIRECTORYSOURCE, "data:application/json,{}");
}
/**
@ -86,8 +108,6 @@ let TestRunner = {
* Starts the test runner.
*/
run: function () {
waitForExplicitFinish();
this._iter = runTests();
this.next();
},

View File

@ -2032,8 +2032,9 @@ GK_ATOM(x_symbol, "x-symbol")
GK_ATOM(az, "az")
GK_ATOM(ba, "ba")
GK_ATOM(crh, "crh")
GK_ATOM(nl, "nl")
GK_ATOM(el, "el")
GK_ATOM(ga_ie, "ga-ie")
GK_ATOM(nl, "nl")
// Names for editor transactions
GK_ATOM(TypingTxnName, "Typing")

File diff suppressed because it is too large Load Diff

View File

@ -268,6 +268,7 @@ GLContextEGL::~GLContextEGL()
#endif
sEGLLibrary.fDestroyContext(EGL_DISPLAY(), mContext);
sEGLLibrary.UnsetCachedCurrentContext();
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION < 17
if (!mIsOffscreen) {
@ -381,7 +382,18 @@ GLContextEGL::MakeCurrentImpl(bool aForce) {
// Assume that EGL has the same problem as WGL does,
// where MakeCurrent with an already-current context is
// still expensive.
if (aForce || sEGLLibrary.fGetCurrentContext() != mContext) {
bool hasDifferentContext = false;
if (sEGLLibrary.CachedCurrentContext() != mContext) {
// even if the cached context doesn't match the current one
// might still
if (sEGLLibrary.fGetCurrentContext() != mContext) {
hasDifferentContext = true;
} else {
sEGLLibrary.SetCachedCurrentContext(mContext);
}
}
if (aForce || hasDifferentContext) {
EGLSurface surface = mSurfaceOverride != EGL_NO_SURFACE
? mSurfaceOverride
: mSurface;
@ -402,7 +414,11 @@ GLContextEGL::MakeCurrentImpl(bool aForce) {
printf_stderr("EGL Error: 0x%04x\n", eglError);
#endif
}
} else {
sEGLLibrary.SetCachedCurrentContext(mContext);
}
} else {
MOZ_ASSERT(sEGLLibrary.CachedCurrentContextMatches());
}
return succeeded;

View File

@ -6,6 +6,7 @@
#include "gfxCrashReporterUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/Assertions.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsPrintfCString.h"
@ -20,6 +21,9 @@ namespace mozilla {
namespace gl {
GLLibraryEGL sEGLLibrary;
#ifdef MOZ_B2G
ThreadLocal<EGLContext> GLLibraryEGL::sCurrentContext;
#endif
// should match the order of EGLExtensions, and be null-terminated.
static const char *sEGLExtensionNames[] = {
@ -104,6 +108,11 @@ GLLibraryEGL::EnsureInitialized()
mozilla::ScopedGfxFeatureReporter reporter("EGL");
#ifdef MOZ_B2G
if (!sCurrentContext.init())
MOZ_CRASH("Tls init failed");
#endif
#ifdef XP_WIN
#ifdef MOZ_WEBGL
if (!mEGLLibrary) {

View File

@ -10,7 +10,7 @@
#endif
#include "GLLibraryLoader.h"
#include "mozilla/ThreadLocal.h"
#include "nsIFile.h"
#include <bitset>
@ -529,6 +529,33 @@ public:
static void AfterGLCall(const char* glFunction);
#endif
#ifdef MOZ_B2G
EGLContext CachedCurrentContext() {
return sCurrentContext.get();
}
void UnsetCachedCurrentContext() {
sCurrentContext.set(nullptr);
}
void SetCachedCurrentContext(EGLContext aCtx) {
sCurrentContext.set(aCtx);
}
bool CachedCurrentContextMatches() {
return sCurrentContext.get() == fGetCurrentContext();
}
private:
static ThreadLocal<EGLContext> sCurrentContext;
public:
#else
EGLContext CachedCurrentContext() {
return nullptr;
}
void UnsetCachedCurrentContext() {}
void SetCachedCurrentContext(EGLContext aCtx) { }
bool CachedCurrentContextMatches() { return true; }
#endif
private:
bool mInitialized;
PRLibrary* mEGLLibrary;

View File

@ -69,12 +69,12 @@ AddRegion(nsIntRegion& aDest, const nsIntRegion& aSource)
aDest.SimplifyOutward(20);
}
static nsIntRegion
TransformRegion(const nsIntRegion& aRegion, const gfx3DMatrix& aTransform)
TransformRegion(nsIntRegion& aRegion, const gfx3DMatrix& aTransform)
{
nsIntRegion result;
AddTransformedRegion(result, aRegion, aTransform);
return result;
aRegion.Transform(aTransform);
return aRegion;
}
/**

View File

@ -6,7 +6,8 @@
#include "nsRegion.h"
#include "nsPrintfCString.h"
#include "nsTArray.h"
#include "gfx3DMatrix.h"
#include "gfxUtils.h"
bool nsRegion::Contains(const nsRegion& aRgn) const
{
@ -445,6 +446,44 @@ nsRegion& nsRegion::ScaleInverseRoundOut (float aXScale, float aYScale)
return *this;
}
static nsIntRect
TransformRect(const nsIntRect& aRect, const gfx3DMatrix& aTransform)
{
if (aRect.IsEmpty()) {
return nsIntRect();
}
gfxRect rect(aRect.x, aRect.y, aRect.width, aRect.height);
rect = aTransform.TransformBounds(rect);
rect.RoundOut();
nsIntRect intRect;
if (!gfxUtils::GfxRectToIntRect(rect, &intRect)) {
return nsIntRect();
}
return intRect;
}
nsRegion& nsRegion::Transform (const gfx3DMatrix &aTransform)
{
int n;
pixman_box32_t *boxes = pixman_region32_rectangles(&mImpl, &n);
for (int i=0; i<n; i++) {
nsRect rect = BoxToRect(boxes[i]);
boxes[i] = RectToBox(nsIntRegion::ToRect(TransformRect(nsIntRegion::FromRect(rect), aTransform)));
}
pixman_region32_t region;
// This will union all of the rectangles and runs in about O(n lg(n))
pixman_region32_init_rects(&region, boxes, n);
pixman_region32_fini(&mImpl);
mImpl = region;
return *this;
}
nsRegion nsRegion::ConvertAppUnitsRoundOut (int32_t aFromAPP, int32_t aToAPP) const
{
if (aFromAPP == aToAPP) {

View File

@ -19,6 +19,7 @@
#include "xpcom-config.h" // for CPP_THROW_NEW
class nsIntRegion;
class gfx3DMatrix;
#include "pixman.h"
@ -221,6 +222,7 @@ public:
nsRegion ConvertAppUnitsRoundIn (int32_t aFromAPP, int32_t aToAPP) const;
nsRegion& ScaleRoundOut(float aXScale, float aYScale);
nsRegion& ScaleInverseRoundOut(float aXScale, float aYScale);
nsRegion& Transform (const gfx3DMatrix &aTransform);
nsIntRegion ScaleToOutsidePixels (float aXScale, float aYScale, nscoord aAppUnitsPerPixel) const;
nsIntRegion ScaleToInsidePixels (float aXScale, float aYScale, nscoord aAppUnitsPerPixel) const;
nsIntRegion ScaleToNearestPixels (float aXScale, float aYScale, nscoord aAppUnitsPerPixel) const;
@ -536,6 +538,12 @@ public:
return *this;
}
nsIntRegion& Transform (const gfx3DMatrix &aTransform)
{
mImpl.Transform(aTransform);
return *this;
}
/**
* Make sure the region has at most aMaxRects by adding area to it
* if necessary. The simplified region will be a superset of the

View File

@ -176,8 +176,8 @@ gfxAndroidPlatform::GetCommonFallbackFonts(const uint32_t aCh,
static const char kMotoyaLMaru[] = "MotoyaLMaru";
if (IS_IN_BMP(aCh)) {
// try language-specific "Droid Sans *" fonts for certain blocks,
// as most devices probably have these
// try language-specific "Droid Sans *" and "Noto Sans *" fonts for
// certain blocks, as most devices probably have these
uint8_t block = (aCh >> 8) & 0xff;
switch (block) {
case 0x05:
@ -188,12 +188,15 @@ gfxAndroidPlatform::GetCommonFallbackFonts(const uint32_t aCh,
aFontList.AppendElement("Droid Sans Arabic");
break;
case 0x09:
aFontList.AppendElement("Noto Sans Devanagari");
aFontList.AppendElement("Droid Sans Devanagari");
break;
case 0x0b:
aFontList.AppendElement("Noto Sans Tamil");
aFontList.AppendElement("Droid Sans Tamil");
break;
case 0x0e:
aFontList.AppendElement("Noto Sans Thai");
aFontList.AppendElement("Droid Sans Thai");
break;
case 0x10: case 0x2d:

View File

@ -7,9 +7,7 @@
#include "mozilla/MemoryReporting.h"
#include "gfxHarfBuzzShaper.h"
#include <algorithm>
#include "gfxGraphiteShaper.h"
#include "gfxDWriteFontList.h"
#include "gfxContext.h"
#include <dwrite.h>
@ -106,14 +104,6 @@ gfxDWriteFont::gfxDWriteFont(gfxFontEntry *aFontEntry,
}
ComputeMetrics(anAAOption);
if (FontCanSupportGraphite()) {
mGraphiteShaper = new gfxGraphiteShaper(this);
}
if (FontCanSupportHarfBuzz()) {
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
}
}
gfxDWriteFont::~gfxDWriteFont()
@ -134,32 +124,6 @@ gfxDWriteFont::CopyWithAntialiasOption(AntialiasOption anAAOption)
&mStyle, mNeedsBold, anAAOption);
}
bool
gfxDWriteFont::ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping)
{
bool ok = false;
if (mGraphiteShaper && gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText);
}
if (!ok && mHarfBuzzShaper) {
ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText);
}
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
return ok;
}
const gfxFont::Metrics&
gfxDWriteFont::GetMetrics()
{

View File

@ -71,14 +71,6 @@ public:
virtual cairo_scaled_font_t *GetCairoScaledFont();
protected:
virtual bool ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping = false);
bool GetFakeMetricsForArialBlack(DWRITE_FONT_METRICS *aFontMetrics);
void ComputeMetrics(AntialiasOption anAAOption);

View File

@ -24,8 +24,6 @@
#include "gfxFT2Utils.h"
#include "gfxFT2FontList.h"
#include <locale.h>
#include "gfxHarfBuzzShaper.h"
#include "gfxGraphiteShaper.h"
#include "nsGkAtoms.h"
#include "nsTArray.h"
#include "nsUnicodeRange.h"
@ -44,42 +42,20 @@
*/
bool
gfxFT2Font::ShapeText(gfxContext *aContext,
gfxFT2Font::ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping)
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText)
{
bool ok = false;
if (FontCanSupportGraphite()) {
if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
if (!mGraphiteShaper) {
mGraphiteShaper = new gfxGraphiteShaper(this);
}
ok = mGraphiteShaper->ShapeText(aContext, aText,
aOffset, aLength,
aScript, aShapedText);
}
}
if (!ok) {
if (!mHarfBuzzShaper) {
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
}
ok = mHarfBuzzShaper->ShapeText(aContext, aText,
aOffset, aLength,
aScript, aShapedText);
}
if (!ok) {
if (!gfxFont::ShapeText(aContext, aText, aOffset, aLength, aScript,
aShapedText)) {
// harfbuzz must have failed(?!), just render raw glyphs
AddRange(aText, aOffset, aLength, aShapedText);
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
}
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
return true;
}

View File

@ -77,8 +77,7 @@ protected:
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping);
gfxShapedText *aShapedText);
void FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd);

View File

@ -23,6 +23,7 @@
#include "gfxTypes.h"
#include "gfxContext.h"
#include "gfxFontMissingGlyphs.h"
#include "gfxGraphiteShaper.h"
#include "gfxHarfBuzzShaper.h"
#include "gfxUserFontSet.h"
#include "gfxPlatformFontList.h"
@ -44,6 +45,8 @@
#include "gfxMathTable.h"
#include "gfx2DGlue.h"
#include "GreekCasing.h"
#if defined(XP_MACOSX)
#include "nsCocoaFeatures.h"
#endif
@ -3942,8 +3945,7 @@ gfxFont::ShapeText(gfxContext *aContext,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping)
gfxShapedText *aShapedText)
{
nsDependentCSubstring ascii((const char*)aText, aLength);
nsAutoString utf16;
@ -3952,7 +3954,7 @@ gfxFont::ShapeText(gfxContext *aContext,
return false;
}
return ShapeText(aContext, utf16.BeginReading(), aOffset, aLength,
aScript, aShapedText, aPreferPlatformShaping);
aScript, aShapedText);
}
bool
@ -3961,30 +3963,29 @@ gfxFont::ShapeText(gfxContext *aContext,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping)
gfxShapedText *aShapedText)
{
bool ok = false;
if (mGraphiteShaper && gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText);
if (FontCanSupportGraphite()) {
if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
if (!mGraphiteShaper) {
mGraphiteShaper = new gfxGraphiteShaper(this);
}
ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText);
}
}
if (!ok && mHarfBuzzShaper && !aPreferPlatformShaping) {
if (!ok) {
if (!mHarfBuzzShaper) {
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
}
ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText);
}
if (!ok) {
if (!mPlatformShaper) {
CreatePlatformShaper();
}
if (mPlatformShaper) {
ok = mPlatformShaper->ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText);
}
}
NS_WARN_IF_FALSE(ok, "shaper failed, expect scrambled or missing text");
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
@ -5709,8 +5710,8 @@ gfxFont::InitFakeSmallCapsRun(gfxContext *aContext,
// capitals where the accent is to be removed (bug 307039).
// These are handled by using the full-size font with the
// uppercasing transform.
GreekCasing::State state;
ch2 = GreekCasing::UpperCase(ch, state);
mozilla::GreekCasing::State state;
ch2 = mozilla::GreekCasing::UpperCase(ch, state);
if (ch != ch2) {
chCase = kSpecialUpper;
}

View File

@ -1470,12 +1470,12 @@ public:
// Shape a piece of text and store the resulting glyph data into
// aShapedText. Parameters aOffset/aLength indicate the range of
// aShapedText to be updated; aLength is also the length of aText.
virtual bool ShapeText(gfxContext *aContext,
virtual bool ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText) = 0;
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText) = 0;
gfxFont *GetFont() const { return mFont; }
@ -1976,8 +1976,7 @@ protected:
uint32_t aOffset, // dest offset in gfxShapedText
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText, // where to store the result
bool aPreferPlatformShaping = false);
gfxShapedText *aShapedText); // where to store the result
// Call the appropriate shaper to generate glyphs for aText and store
// them into aShapedText.
@ -1986,8 +1985,7 @@ protected:
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping = false);
gfxShapedText *aShapedText);
// Helper to adjust for synthetic bold and set character-type flags
// in the shaped text; implementations of ShapeText should call this
@ -2146,19 +2144,14 @@ protected:
// measurement by mathml code
nsAutoPtr<gfxFont> mNonAAFont;
// we may switch between these shapers on the fly, based on the script
// of the text run being shaped
nsAutoPtr<gfxFontShaper> mPlatformShaper;
// we create either or both of these shapers when needed, depending
// whether the font has graphite tables, and whether graphite shaping
// is actually enabled
nsAutoPtr<gfxFontShaper> mHarfBuzzShaper;
nsAutoPtr<gfxFontShaper> mGraphiteShaper;
mozilla::RefPtr<mozilla::gfx::ScaledFont> mAzureScaledFont;
// Create a default platform text shaper for this font.
// (TODO: This should become pure virtual once all font backends have
// been updated.)
virtual void CreatePlatformShaper() { }
// Helper for subclasses that want to initialize standard metrics from the
// tables of sfnt (TrueType/OpenType) fonts.
// This will use mFUnitsConvFactor if it is already set, else compute it

View File

@ -8,9 +8,7 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/WindowsVersion.h"
#include "gfxHarfBuzzShaper.h"
#include <algorithm>
#include "gfxGraphiteShaper.h"
#include "gfxWindowsPlatform.h"
#include "gfxContext.h"
#include "mozilla/Preferences.h"
@ -51,10 +49,6 @@ gfxGDIFont::gfxGDIFont(GDIFontEntry *aFontEntry,
mSpaceGlyph(0),
mNeedsBold(aNeedsBold)
{
if (FontCanSupportGraphite()) {
mGraphiteShaper = new gfxGraphiteShaper(this);
}
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
}
gfxGDIFont::~gfxGDIFont()
@ -79,13 +73,12 @@ gfxGDIFont::CopyWithAntialiasOption(AntialiasOption anAAOption)
}
bool
gfxGDIFont::ShapeText(gfxContext *aContext,
gfxGDIFont::ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping)
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText)
{
if (!mMetrics) {
Initialize();
@ -104,7 +97,7 @@ gfxGDIFont::ShapeText(gfxContext *aContext,
}
return gfxFont::ShapeText(aContext, aText, aOffset, aLength, aScript,
aShapedText, aPreferPlatformShaping);
aShapedText);
}
const gfxFont::Metrics&

View File

@ -71,13 +71,12 @@ public:
protected:
/* override to ensure the cairo font is set up properly */
virtual bool ShapeText(gfxContext *aContext,
virtual bool ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping);
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText);
void Initialize(); // creates metrics and Cairo fonts

View File

@ -8,9 +8,7 @@
#include "mozilla/MemoryReporting.h"
#include "gfxCoreTextShaper.h"
#include "gfxHarfBuzzShaper.h"
#include <algorithm>
#include "gfxGraphiteShaper.h"
#include "gfxPlatformMac.h"
#include "gfxContext.h"
#include "gfxFontUtils.h"
@ -106,13 +104,6 @@ gfxMacFont::gfxMacFont(MacOSFontEntry *aFontEntry, const gfxFontStyle *aFontStyl
NS_WARNING(warnBuf);
#endif
}
if (FontCanSupportGraphite()) {
mGraphiteShaper = new gfxGraphiteShaper(this);
}
if (FontCanSupportHarfBuzz()) {
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
}
}
gfxMacFont::~gfxMacFont()
@ -126,29 +117,31 @@ gfxMacFont::~gfxMacFont()
}
bool
gfxMacFont::ShapeText(gfxContext *aContext,
gfxMacFont::ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping)
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText)
{
if (!mIsValid) {
NS_WARNING("invalid font! expect incorrect text rendering");
return false;
}
bool requiresAAT =
static_cast<MacOSFontEntry*>(GetFontEntry())->RequiresAATLayout();
return gfxFont::ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText, requiresAAT);
}
if (static_cast<MacOSFontEntry*>(GetFontEntry())->RequiresAATLayout()) {
if (!mCoreTextShaper) {
mCoreTextShaper = new gfxCoreTextShaper(this);
}
if (mCoreTextShaper->ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText)) {
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
return true;
}
}
void
gfxMacFont::CreatePlatformShaper()
{
mPlatformShaper = new gfxCoreTextShaper(this);
return gfxFont::ShapeText(aContext, aText, aOffset, aLength, aScript,
aShapedText);
}
bool

View File

@ -51,16 +51,13 @@ public:
virtual FontType GetType() const { return FONT_TYPE_MAC; }
protected:
virtual void CreatePlatformShaper();
// override to prefer CoreText shaping with fonts that depend on AAT
virtual bool ShapeText(gfxContext *aContext,
virtual bool ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping = false);
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText);
void InitMetrics();
void InitMetricsFromPlatform();
@ -76,6 +73,8 @@ protected:
cairo_font_face_t *mFontFace;
nsAutoPtr<gfxFontShaper> mCoreTextShaper;
Metrics mMetrics;
uint32_t mSpaceGlyph;
};

View File

@ -20,8 +20,6 @@
#include "gfxFT2Utils.h"
#include "harfbuzz/hb.h"
#include "harfbuzz/hb-ot.h"
#include "gfxHarfBuzzShaper.h"
#include "gfxGraphiteShaper.h"
#include "nsUnicodeProperties.h"
#include "nsUnicodeScriptCodes.h"
#include "gfxFontconfigUtils.h"
@ -663,14 +661,6 @@ public:
protected:
virtual already_AddRefed<gfxFont> GetSmallCapsFont();
virtual bool ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping);
private:
gfxFcFont(cairo_scaled_font_t *aCairoFont, gfxFcFontEntry *aFontEntry,
const gfxFontStyle *aFontStyle);
@ -1632,42 +1622,6 @@ gfxFcFont::GetSmallCapsFont()
return font.forget();
}
bool
gfxFcFont::ShapeText(gfxContext *aContext,
const char16_t *aText,
uint32_t aOffset,
uint32_t aLength,
int32_t aScript,
gfxShapedText *aShapedText,
bool aPreferPlatformShaping)
{
bool ok = false;
if (FontCanSupportGraphite()) {
if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
if (!mGraphiteShaper) {
mGraphiteShaper = new gfxGraphiteShaper(this);
}
ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText);
}
}
if (!ok) {
if (!mHarfBuzzShaper) {
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
}
ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength,
aScript, aShapedText);
}
NS_WARN_IF_FALSE(ok, "shaper failed, expect scrambled or missing text");
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
return ok;
}
/* static */ void
gfxPangoFontGroup::Shutdown()
{

View File

@ -724,6 +724,9 @@ gfxUtils::TransformRectToRect(const gfxRect& aFrom, const IntPoint& aToTopLeft,
return m;
}
/* This function is sort of shitty. We truncate doubles
* to ints then convert those ints back to doubles to make sure that
* they equal the doubles that we got in. */
bool
gfxUtils::GfxRectToIntRect(const gfxRect& aIn, nsIntRect* aOut)
{

View File

@ -0,0 +1,268 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GreekCasing.h"
#include "nsUnicharUtils.h"
// Custom uppercase mapping for Greek; see bug 307039 for details
#define GREEK_LOWER_ALPHA 0x03B1
#define GREEK_LOWER_ALPHA_TONOS 0x03AC
#define GREEK_LOWER_ALPHA_OXIA 0x1F71
#define GREEK_LOWER_EPSILON 0x03B5
#define GREEK_LOWER_EPSILON_TONOS 0x03AD
#define GREEK_LOWER_EPSILON_OXIA 0x1F73
#define GREEK_LOWER_ETA 0x03B7
#define GREEK_LOWER_ETA_TONOS 0x03AE
#define GREEK_LOWER_ETA_OXIA 0x1F75
#define GREEK_LOWER_IOTA 0x03B9
#define GREEK_LOWER_IOTA_TONOS 0x03AF
#define GREEK_LOWER_IOTA_OXIA 0x1F77
#define GREEK_LOWER_IOTA_DIALYTIKA 0x03CA
#define GREEK_LOWER_IOTA_DIALYTIKA_TONOS 0x0390
#define GREEK_LOWER_IOTA_DIALYTIKA_OXIA 0x1FD3
#define GREEK_LOWER_OMICRON 0x03BF
#define GREEK_LOWER_OMICRON_TONOS 0x03CC
#define GREEK_LOWER_OMICRON_OXIA 0x1F79
#define GREEK_LOWER_UPSILON 0x03C5
#define GREEK_LOWER_UPSILON_TONOS 0x03CD
#define GREEK_LOWER_UPSILON_OXIA 0x1F7B
#define GREEK_LOWER_UPSILON_DIALYTIKA 0x03CB
#define GREEK_LOWER_UPSILON_DIALYTIKA_TONOS 0x03B0
#define GREEK_LOWER_UPSILON_DIALYTIKA_OXIA 0x1FE3
#define GREEK_LOWER_OMEGA 0x03C9
#define GREEK_LOWER_OMEGA_TONOS 0x03CE
#define GREEK_LOWER_OMEGA_OXIA 0x1F7D
#define GREEK_UPPER_ALPHA 0x0391
#define GREEK_UPPER_EPSILON 0x0395
#define GREEK_UPPER_ETA 0x0397
#define GREEK_UPPER_IOTA 0x0399
#define GREEK_UPPER_IOTA_DIALYTIKA 0x03AA
#define GREEK_UPPER_OMICRON 0x039F
#define GREEK_UPPER_UPSILON 0x03A5
#define GREEK_UPPER_UPSILON_DIALYTIKA 0x03AB
#define GREEK_UPPER_OMEGA 0x03A9
#define GREEK_UPPER_ALPHA_TONOS 0x0386
#define GREEK_UPPER_ALPHA_OXIA 0x1FBB
#define GREEK_UPPER_EPSILON_TONOS 0x0388
#define GREEK_UPPER_EPSILON_OXIA 0x1FC9
#define GREEK_UPPER_ETA_TONOS 0x0389
#define GREEK_UPPER_ETA_OXIA 0x1FCB
#define GREEK_UPPER_IOTA_TONOS 0x038A
#define GREEK_UPPER_IOTA_OXIA 0x1FDB
#define GREEK_UPPER_OMICRON_TONOS 0x038C
#define GREEK_UPPER_OMICRON_OXIA 0x1FF9
#define GREEK_UPPER_UPSILON_TONOS 0x038E
#define GREEK_UPPER_UPSILON_OXIA 0x1FEB
#define GREEK_UPPER_OMEGA_TONOS 0x038F
#define GREEK_UPPER_OMEGA_OXIA 0x1FFB
#define COMBINING_ACUTE_ACCENT 0x0301
#define COMBINING_DIAERESIS 0x0308
#define COMBINING_ACUTE_TONE_MARK 0x0341
#define COMBINING_GREEK_DIALYTIKA_TONOS 0x0344
namespace mozilla {
uint32_t
GreekCasing::UpperCase(uint32_t aCh, GreekCasing::State& aState)
{
switch (aCh) {
case GREEK_UPPER_ALPHA:
case GREEK_LOWER_ALPHA:
aState = kAlpha;
return GREEK_UPPER_ALPHA;
case GREEK_UPPER_EPSILON:
case GREEK_LOWER_EPSILON:
aState = kEpsilon;
return GREEK_UPPER_EPSILON;
case GREEK_UPPER_ETA:
case GREEK_LOWER_ETA:
aState = kEta;
return GREEK_UPPER_ETA;
case GREEK_UPPER_IOTA:
aState = kIota;
return GREEK_UPPER_IOTA;
case GREEK_UPPER_OMICRON:
case GREEK_LOWER_OMICRON:
aState = kOmicron;
return GREEK_UPPER_OMICRON;
case GREEK_UPPER_UPSILON:
switch (aState) {
case kOmicron:
aState = kOmicronUpsilon;
break;
default:
aState = kUpsilon;
break;
}
return GREEK_UPPER_UPSILON;
case GREEK_UPPER_OMEGA:
case GREEK_LOWER_OMEGA:
aState = kOmega;
return GREEK_UPPER_OMEGA;
// iota and upsilon may be the second vowel of a diphthong
case GREEK_LOWER_IOTA:
switch (aState) {
case kAlphaAcc:
case kEpsilonAcc:
case kOmicronAcc:
case kUpsilonAcc:
aState = kStart;
return GREEK_UPPER_IOTA_DIALYTIKA;
default:
break;
}
aState = kIota;
return GREEK_UPPER_IOTA;
case GREEK_LOWER_UPSILON:
switch (aState) {
case kAlphaAcc:
case kEpsilonAcc:
case kEtaAcc:
case kOmicronAcc:
aState = kStart;
return GREEK_UPPER_UPSILON_DIALYTIKA;
case kOmicron:
aState = kOmicronUpsilon;
break;
default:
aState = kUpsilon;
break;
}
return GREEK_UPPER_UPSILON;
case GREEK_UPPER_IOTA_DIALYTIKA:
case GREEK_LOWER_IOTA_DIALYTIKA:
case GREEK_UPPER_UPSILON_DIALYTIKA:
case GREEK_LOWER_UPSILON_DIALYTIKA:
case COMBINING_DIAERESIS:
aState = kDiaeresis;
return ToUpperCase(aCh);
// remove accent if it follows a vowel or diaeresis,
// and set appropriate state for diphthong detection
case COMBINING_ACUTE_ACCENT:
case COMBINING_ACUTE_TONE_MARK:
switch (aState) {
case kAlpha:
aState = kAlphaAcc;
return uint32_t(-1); // omit this char from result string
case kEpsilon:
aState = kEpsilonAcc;
return uint32_t(-1);
case kEta:
aState = kEtaAcc;
return uint32_t(-1);
case kIota:
aState = kIotaAcc;
return uint32_t(-1);
case kOmicron:
aState = kOmicronAcc;
return uint32_t(-1);
case kUpsilon:
aState = kUpsilonAcc;
return uint32_t(-1);
case kOmicronUpsilon:
aState = kStart; // this completed a diphthong
return uint32_t(-1);
case kOmega:
aState = kOmegaAcc;
return uint32_t(-1);
case kDiaeresis:
aState = kStart;
return uint32_t(-1);
default:
break;
}
break;
// combinations with dieresis+accent just strip the accent,
// and reset to start state (don't form diphthong with following vowel)
case GREEK_LOWER_IOTA_DIALYTIKA_TONOS:
case GREEK_LOWER_IOTA_DIALYTIKA_OXIA:
aState = kStart;
return GREEK_UPPER_IOTA_DIALYTIKA;
case GREEK_LOWER_UPSILON_DIALYTIKA_TONOS:
case GREEK_LOWER_UPSILON_DIALYTIKA_OXIA:
aState = kStart;
return GREEK_UPPER_UPSILON_DIALYTIKA;
case COMBINING_GREEK_DIALYTIKA_TONOS:
aState = kStart;
return COMBINING_DIAERESIS;
// strip accents from vowels, and note the vowel seen so that we can detect
// diphthongs where diaeresis needs to be added
case GREEK_LOWER_ALPHA_TONOS:
case GREEK_LOWER_ALPHA_OXIA:
case GREEK_UPPER_ALPHA_TONOS:
case GREEK_UPPER_ALPHA_OXIA:
aState = kAlphaAcc;
return GREEK_UPPER_ALPHA;
case GREEK_LOWER_EPSILON_TONOS:
case GREEK_LOWER_EPSILON_OXIA:
case GREEK_UPPER_EPSILON_TONOS:
case GREEK_UPPER_EPSILON_OXIA:
aState = kEpsilonAcc;
return GREEK_UPPER_EPSILON;
case GREEK_LOWER_ETA_TONOS:
case GREEK_LOWER_ETA_OXIA:
case GREEK_UPPER_ETA_TONOS:
case GREEK_UPPER_ETA_OXIA:
aState = kEtaAcc;
return GREEK_UPPER_ETA;
case GREEK_LOWER_IOTA_TONOS:
case GREEK_LOWER_IOTA_OXIA:
case GREEK_UPPER_IOTA_TONOS:
case GREEK_UPPER_IOTA_OXIA:
aState = kIotaAcc;
return GREEK_UPPER_IOTA;
case GREEK_LOWER_OMICRON_TONOS:
case GREEK_LOWER_OMICRON_OXIA:
case GREEK_UPPER_OMICRON_TONOS:
case GREEK_UPPER_OMICRON_OXIA:
aState = kOmicronAcc;
return GREEK_UPPER_OMICRON;
case GREEK_LOWER_UPSILON_TONOS:
case GREEK_LOWER_UPSILON_OXIA:
case GREEK_UPPER_UPSILON_TONOS:
case GREEK_UPPER_UPSILON_OXIA:
switch (aState) {
case kOmicron:
aState = kStart; // this completed a diphthong
break;
default:
aState = kUpsilonAcc;
break;
}
return GREEK_UPPER_UPSILON;
case GREEK_LOWER_OMEGA_TONOS:
case GREEK_LOWER_OMEGA_OXIA:
case GREEK_UPPER_OMEGA_TONOS:
case GREEK_UPPER_OMEGA_OXIA:
aState = kOmegaAcc;
return GREEK_UPPER_OMEGA;
}
// all other characters just reset the state, and use standard mappings
aState = kStart;
return ToUpperCase(aCh);
}
} // namespace mozilla

View File

@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef GreekCasing_h_
#define GreekCasing_h_
#include <stdint.h>
namespace mozilla {
class GreekCasing {
// When doing an Uppercase transform in Greek, we need to keep track of the
// current state while iterating through the string, to recognize and process
// diphthongs correctly. For clarity, we define a state for each vowel and
// each vowel with accent, although a few of these do not actually need any
// special treatment and could be folded into kStart.
private:
enum GreekStates {
kStart,
kAlpha,
kEpsilon,
kEta,
kIota,
kOmicron,
kUpsilon,
kOmega,
kAlphaAcc,
kEpsilonAcc,
kEtaAcc,
kIotaAcc,
kOmicronAcc,
kUpsilonAcc,
kOmegaAcc,
kOmicronUpsilon,
kDiaeresis
};
public:
class State {
public:
State()
: mState(kStart)
{
}
State(const GreekStates& aState)
: mState(aState)
{
}
void Reset()
{
mState = kStart;
}
operator GreekStates() const
{
return mState;
}
private:
GreekStates mState;
};
static uint32_t UpperCase(uint32_t aCh, State& aState);
};
} // namespace mozilla
#endif

View File

@ -0,0 +1,246 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/******************************************************************************
This file provides a finite state machine to support Irish Gaelic uppercasing
rules.
The caller will need to iterate through a string, passing a State variable
along with the current character to each UpperCase call and checking the flags
that are returned:
If aMarkPos is true, caller must remember the current index in the string as
a possible target for a future action.
If aAction is non-zero, then one or more characters from the marked index are
to be modified:
1 lowercase the marked letter
2 lowercase the marked letter and its successor
3 lowercase the marked letter, and delete its successor
### Rules from https://bugzilla.mozilla.org/show_bug.cgi?id=1014639,
### comments 1 and 4:
v = [a,á,e,é,i,í,o,ó,u,ú]
V = [A,Á,E,É,I,Í,O,Ó,U,Ú]
bhf -> bhF
bhF -> bhF
bp -> bP
bP -> bP
dt -> dT
dT -> dT
gc -> gC
gC -> gC
h{V} -> h{V}
mb -> mB
mB -> mB
n-{v} -> n{V}
n{V} -> n{V}
nd -> nD
nD -> nD
ng -> nG
nG -> nG
t-{v} -> t{V}
t{V} -> t{V}
ts{v} -> tS{V}
tS{v} -> tS{V}
tS{V} -> tS{V}
tsl -> tSL
tSl -> tSL
tSL -> tSL
tsn -> tSN
tSn -> tSN
tSN -> tSN
tsr -> tSR
tSr -> tSR
tSR -> tSR
### Create table of states and actions for each input class.
Start (non-word) state is #; generic in-word state is _, once we know there's
no special action to do in this word.
# _ b bh d g h m n n- t t- ts
input\state
b b' _ _ _ _ _ _ 1 _ _ _ _ _
B _ _ _ _ _ _ _ 1 _ _ _ _ _
c _ _ _ _ _ 1 _ _ _ _ _ _ _
C _ _ _ _ _ 1 _ _ _ _ _ _ _
d d' _ _ _ _ _ _ _ 1 _ _ _ _
D _ _ _ _ _ _ _ _ 1 _ _ _ _
f _ _ _ 2 _ _ _ _ _ _ _ _ _
F _ _ _ 2 _ _ _ _ _ _ _ _ _
g g' _ _ _ _ _ _ _ 1 _ _ _ _
G _ _ _ _ _ _ _ _ 1 _ _ _ _
h h' _ bh _ _ _ _ _ _ _ _ _ _
l _ _ _ _ _ _ _ _ _ _ _ _ 1
L _ _ _ _ _ _ _ _ _ _ _ _ 1
m m' _ _ _ _ _ _ _ _ _ _ _ _
n n' _ _ _ _ _ _ _ _ _ _ _ 1
N _ _ _ _ _ _ _ _ _ _ _ _ 1
p _ _ 1 _ _ _ _ _ _ _ _ _ _
P _ _ 1 _ _ _ _ _ _ _ _ _ _
r _ _ _ _ _ _ _ _ _ _ _ _ 1
R _ _ _ _ _ _ _ _ _ _ _ _ 1
s _ _ _ _ _ _ _ _ _ _ ts _ _
S _ _ _ _ _ _ _ _ _ _ ts _ _
t t' _ _ _ 1 _ _ _ _ _ _ _ _
T _ _ _ _ 1 _ _ _ _ _ _ _ _
vowel _ _ _ _ _ _ _ _ _ 1d _ 1d 1
Vowel _ _ _ _ _ _ 1 _ 1 _ 1 _ 1
hyph _ _ _ _ _ _ _ _ n- _ t- _ _
letter _ _ _ _ _ _ _ _ _ _ _ _ _
other # # # # # # # # # # # # #
Actions:
1 lowercase one letter at start of word
2 lowercase two letters at start of word
1d lowercase one letter at start of word, and delete next
(and then go to state _, nothing further to do in this word)
else just go to the given state; suffix ' indicates mark start-of-word.
### Consolidate identical states and classes:
0 1 2 3 4 5 6 7 8 9 A B
# _ b bh d g h m n [nt]- t ts
input\state
b b' _ _ _ _ _ _ 1 _ _ _ _
B _ _ _ _ _ _ _ 1 _ _ _ _
[cC] _ _ _ _ _ 1 _ _ _ _ _ _
d d' _ _ _ _ _ _ _ 1 _ _ _
[DG] _ _ _ _ _ _ _ _ 1 _ _ _
[fF] _ _ _ 2 _ _ _ _ _ _ _ _
g g' _ _ _ _ _ _ _ 1 _ _ _
h h' _ bh _ _ _ _ _ _ _ _ _
[lLNrR] _ _ _ _ _ _ _ _ _ _ _ 1
m m' _ _ _ _ _ _ _ _ _ _ _
n n' _ _ _ _ _ _ _ _ _ _ 1
[pP] _ _ 1 _ _ _ _ _ _ _ _ _
[sS] _ _ _ _ _ _ _ _ _ _ ts _
t t' _ _ _ 1 _ _ _ _ _ _ _
T _ _ _ _ 1 _ _ _ _ _ _ _
vowel _ _ _ _ _ _ _ _ _ 1d _ 1
Vowel _ _ _ _ _ _ 1 _ 1 _ 1 1
hyph _ _ _ _ _ _ _ _ [nt-] _ [nt-] _
letter _ _ _ _ _ _ _ _ _ _ _ _
other # # # # # # # # # # # #
So we have 20 input classes, and 12 states.
State table array will contain bytes that encode action and new state:
0x80 - bit flag: mark start-of-word position
0x40 - currently unused
0x30 - action mask: 4 values
0x00 - do nothing
0x10 - lowercase one letter
0x20 - lowercase two letters
0x30 - lowercase one, delete one
0x0F - next-state mask
******************************************************************************/
#include "IrishCasing.h"
#include "nsUnicodeProperties.h"
#include "nsUnicharUtils.h"
namespace mozilla {
const uint8_t
IrishCasing::sUppercaseStateTable[kNumClasses][kNumStates] = {
// # _ b bh d g h m n [nt]- t ts
{ 0x82, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11, 0x01, 0x01, 0x01, 0x01 }, // b
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11, 0x01, 0x01, 0x01, 0x01 }, // B
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, // [cC]
{ 0x84, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11, 0x01, 0x01, 0x01 }, // d
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11, 0x01, 0x01, 0x01 }, // [DG]
{ 0x01, 0x01, 0x01, 0x21, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, // [fF]
{ 0x85, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11, 0x01, 0x01, 0x01 }, // g
{ 0x86, 0x01, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, // h
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11 }, // [lLNrR]
{ 0x87, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, // m
{ 0x88, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11 }, // n
{ 0x01, 0x01, 0x11, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, // [pP]
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0B, 0x01 }, // [sS]
{ 0x8A, 0x01, 0x01, 0x01, 0x11, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, // t
{ 0x01, 0x01, 0x01, 0x01, 0x11, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, // T
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x31, 0x01, 0x11 }, // vowel
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x11 }, // Vowel
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x09, 0x01, 0x09, 0x01 }, // hyph
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }, // letter
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } // other
};
#define HYPHEN 0x2010
#define NO_BREAK_HYPHEN 0x2011
#define a_ACUTE 0x00e1
#define e_ACUTE 0x00e9
#define i_ACUTE 0x00ed
#define o_ACUTE 0x00f3
#define u_ACUTE 0x00fa
#define A_ACUTE 0x00c1
#define E_ACUTE 0x00c9
#define I_ACUTE 0x00cd
#define O_ACUTE 0x00d3
#define U_ACUTE 0x00da
const uint8_t IrishCasing::sLcClasses[26] = {
kClass_vowel, kClass_b, kClass_cC, kClass_d, kClass_vowel,
kClass_fF, kClass_g, kClass_h, kClass_vowel, kClass_letter,
kClass_letter, kClass_lLNrR, kClass_m, kClass_n, kClass_vowel,
kClass_pP, kClass_letter, kClass_lLNrR, kClass_sS, kClass_t,
kClass_vowel, kClass_letter, kClass_letter, kClass_letter, kClass_letter,
kClass_letter
};
const uint8_t IrishCasing::sUcClasses[26] = {
kClass_Vowel, kClass_B, kClass_cC, kClass_DG, kClass_Vowel,
kClass_fF, kClass_DG, kClass_letter, kClass_Vowel, kClass_letter,
kClass_letter, kClass_lLNrR, kClass_letter, kClass_lLNrR, kClass_Vowel,
kClass_pP, kClass_letter, kClass_lLNrR, kClass_sS, kClass_T,
kClass_Vowel, kClass_letter, kClass_letter, kClass_letter, kClass_letter,
kClass_letter
};
uint32_t
IrishCasing::UpperCase(uint32_t aCh, State& aState,
bool& aMarkPos, uint8_t& aAction)
{
using mozilla::unicode::GetGenCategory;
uint8_t cls;
if (aCh >= 'a' && aCh <= 'z') {
cls = sLcClasses[aCh - 'a'];
} else if (aCh >= 'A' && aCh <= 'Z') {
cls = sUcClasses[aCh - 'A'];
} else if (GetGenCategory(aCh) == nsIUGenCategory::kLetter) {
if (aCh == a_ACUTE || aCh == e_ACUTE || aCh == i_ACUTE ||
aCh == o_ACUTE || aCh == u_ACUTE) {
cls = kClass_vowel;
} else if (aCh == A_ACUTE || aCh == E_ACUTE || aCh == I_ACUTE ||
aCh == O_ACUTE || aCh == U_ACUTE) {
cls = kClass_Vowel;
} else {
cls = kClass_letter;
}
} else if (aCh == '-' || aCh == HYPHEN || aCh == NO_BREAK_HYPHEN) {
cls = kClass_hyph;
} else {
cls = kClass_other;
}
uint8_t stateEntry = sUppercaseStateTable[cls][aState];
aMarkPos = !!(stateEntry & kMarkPositionFlag);
aAction = (stateEntry & kActionMask) >> kActionShift;
aState = (stateEntry & kNextStateMask);
return ToUpperCase(aCh);
}
} // namespace mozilla

View File

@ -0,0 +1,108 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef IrishCasing_h_
#define IrishCasing_h_
#include <stdint.h>
namespace mozilla {
class IrishCasing {
private:
enum IrishStates {
kState_Start,
kState_InWord,
kState_b,
kState_bh,
kState_d,
kState_g,
kState_h,
kState_m,
kState_n,
kState_nt_,
kState_t,
kState_ts,
kNumStates
};
enum IrishClasses {
kClass_b,
kClass_B,
kClass_cC,
kClass_d,
kClass_DG,
kClass_fF,
kClass_g,
kClass_h,
kClass_lLNrR,
kClass_m,
kClass_n,
kClass_pP,
kClass_sS,
kClass_t,
kClass_T,
kClass_vowel,
kClass_Vowel,
kClass_hyph,
kClass_letter,
kClass_other,
kNumClasses
};
public:
class State {
friend class IrishCasing;
public:
State()
: mState(kState_Start)
{
}
State(const IrishStates& aState)
: mState(aState)
{
}
void Reset()
{
mState = kState_Start;
}
operator IrishStates() const
{
return mState;
}
private:
State(uint8_t aState)
: mState(IrishStates(aState))
{
}
uint8_t GetClass(uint32_t aCh);
IrishStates mState;
};
enum {
kMarkPositionFlag = 0x80,
kActionMask = 0x30,
kActionShift = 4,
kNextStateMask = 0x0f
};
static const uint8_t sUppercaseStateTable[kNumClasses][kNumStates];
static const uint8_t sLcClasses[26];
static const uint8_t sUcClasses[26];
static uint32_t UpperCase(uint32_t aCh, State& aState,
bool& aMarkPos, uint8_t& aAction);
};
} // namespace mozilla
#endif

View File

@ -7,7 +7,9 @@
DIRS += ['internal']
EXPORTS += [
'GreekCasing.h',
'ICUUtils.h',
'IrishCasing.h',
'nsBidiUtils.h',
'nsSpecialCasingData.h',
'nsUnicharUtils.h',

View File

@ -214,263 +214,6 @@ ToTitleCase(uint32_t aChar)
return mozilla::unicode::GetTitlecaseForLower(aChar);
}
// Custom uppercase mapping for Greek; see bug 307039 for details
#define GREEK_LOWER_ALPHA 0x03B1
#define GREEK_LOWER_ALPHA_TONOS 0x03AC
#define GREEK_LOWER_ALPHA_OXIA 0x1F71
#define GREEK_LOWER_EPSILON 0x03B5
#define GREEK_LOWER_EPSILON_TONOS 0x03AD
#define GREEK_LOWER_EPSILON_OXIA 0x1F73
#define GREEK_LOWER_ETA 0x03B7
#define GREEK_LOWER_ETA_TONOS 0x03AE
#define GREEK_LOWER_ETA_OXIA 0x1F75
#define GREEK_LOWER_IOTA 0x03B9
#define GREEK_LOWER_IOTA_TONOS 0x03AF
#define GREEK_LOWER_IOTA_OXIA 0x1F77
#define GREEK_LOWER_IOTA_DIALYTIKA 0x03CA
#define GREEK_LOWER_IOTA_DIALYTIKA_TONOS 0x0390
#define GREEK_LOWER_IOTA_DIALYTIKA_OXIA 0x1FD3
#define GREEK_LOWER_OMICRON 0x03BF
#define GREEK_LOWER_OMICRON_TONOS 0x03CC
#define GREEK_LOWER_OMICRON_OXIA 0x1F79
#define GREEK_LOWER_UPSILON 0x03C5
#define GREEK_LOWER_UPSILON_TONOS 0x03CD
#define GREEK_LOWER_UPSILON_OXIA 0x1F7B
#define GREEK_LOWER_UPSILON_DIALYTIKA 0x03CB
#define GREEK_LOWER_UPSILON_DIALYTIKA_TONOS 0x03B0
#define GREEK_LOWER_UPSILON_DIALYTIKA_OXIA 0x1FE3
#define GREEK_LOWER_OMEGA 0x03C9
#define GREEK_LOWER_OMEGA_TONOS 0x03CE
#define GREEK_LOWER_OMEGA_OXIA 0x1F7D
#define GREEK_UPPER_ALPHA 0x0391
#define GREEK_UPPER_EPSILON 0x0395
#define GREEK_UPPER_ETA 0x0397
#define GREEK_UPPER_IOTA 0x0399
#define GREEK_UPPER_IOTA_DIALYTIKA 0x03AA
#define GREEK_UPPER_OMICRON 0x039F
#define GREEK_UPPER_UPSILON 0x03A5
#define GREEK_UPPER_UPSILON_DIALYTIKA 0x03AB
#define GREEK_UPPER_OMEGA 0x03A9
#define GREEK_UPPER_ALPHA_TONOS 0x0386
#define GREEK_UPPER_ALPHA_OXIA 0x1FBB
#define GREEK_UPPER_EPSILON_TONOS 0x0388
#define GREEK_UPPER_EPSILON_OXIA 0x1FC9
#define GREEK_UPPER_ETA_TONOS 0x0389
#define GREEK_UPPER_ETA_OXIA 0x1FCB
#define GREEK_UPPER_IOTA_TONOS 0x038A
#define GREEK_UPPER_IOTA_OXIA 0x1FDB
#define GREEK_UPPER_OMICRON_TONOS 0x038C
#define GREEK_UPPER_OMICRON_OXIA 0x1FF9
#define GREEK_UPPER_UPSILON_TONOS 0x038E
#define GREEK_UPPER_UPSILON_OXIA 0x1FEB
#define GREEK_UPPER_OMEGA_TONOS 0x038F
#define GREEK_UPPER_OMEGA_OXIA 0x1FFB
#define COMBINING_ACUTE_ACCENT 0x0301
#define COMBINING_DIAERESIS 0x0308
#define COMBINING_ACUTE_TONE_MARK 0x0341
#define COMBINING_GREEK_DIALYTIKA_TONOS 0x0344
uint32_t
GreekCasing::UpperCase(uint32_t aCh, GreekCasing::State& aState)
{
switch (aCh) {
case GREEK_UPPER_ALPHA:
case GREEK_LOWER_ALPHA:
aState = kAlpha;
return GREEK_UPPER_ALPHA;
case GREEK_UPPER_EPSILON:
case GREEK_LOWER_EPSILON:
aState = kEpsilon;
return GREEK_UPPER_EPSILON;
case GREEK_UPPER_ETA:
case GREEK_LOWER_ETA:
aState = kEta;
return GREEK_UPPER_ETA;
case GREEK_UPPER_IOTA:
aState = kIota;
return GREEK_UPPER_IOTA;
case GREEK_UPPER_OMICRON:
case GREEK_LOWER_OMICRON:
aState = kOmicron;
return GREEK_UPPER_OMICRON;
case GREEK_UPPER_UPSILON:
switch (aState) {
case kOmicron:
aState = kOmicronUpsilon;
break;
default:
aState = kUpsilon;
break;
}
return GREEK_UPPER_UPSILON;
case GREEK_UPPER_OMEGA:
case GREEK_LOWER_OMEGA:
aState = kOmega;
return GREEK_UPPER_OMEGA;
// iota and upsilon may be the second vowel of a diphthong
case GREEK_LOWER_IOTA:
switch (aState) {
case kAlphaAcc:
case kEpsilonAcc:
case kOmicronAcc:
case kUpsilonAcc:
aState = kStart;
return GREEK_UPPER_IOTA_DIALYTIKA;
default:
break;
}
aState = kIota;
return GREEK_UPPER_IOTA;
case GREEK_LOWER_UPSILON:
switch (aState) {
case kAlphaAcc:
case kEpsilonAcc:
case kEtaAcc:
case kOmicronAcc:
aState = kStart;
return GREEK_UPPER_UPSILON_DIALYTIKA;
case kOmicron:
aState = kOmicronUpsilon;
break;
default:
aState = kUpsilon;
break;
}
return GREEK_UPPER_UPSILON;
case GREEK_UPPER_IOTA_DIALYTIKA:
case GREEK_LOWER_IOTA_DIALYTIKA:
case GREEK_UPPER_UPSILON_DIALYTIKA:
case GREEK_LOWER_UPSILON_DIALYTIKA:
case COMBINING_DIAERESIS:
aState = kDiaeresis;
return ToUpperCase(aCh);
// remove accent if it follows a vowel or diaeresis,
// and set appropriate state for diphthong detection
case COMBINING_ACUTE_ACCENT:
case COMBINING_ACUTE_TONE_MARK:
switch (aState) {
case kAlpha:
aState = kAlphaAcc;
return uint32_t(-1); // omit this char from result string
case kEpsilon:
aState = kEpsilonAcc;
return uint32_t(-1);
case kEta:
aState = kEtaAcc;
return uint32_t(-1);
case kIota:
aState = kIotaAcc;
return uint32_t(-1);
case kOmicron:
aState = kOmicronAcc;
return uint32_t(-1);
case kUpsilon:
aState = kUpsilonAcc;
return uint32_t(-1);
case kOmicronUpsilon:
aState = kStart; // this completed a diphthong
return uint32_t(-1);
case kOmega:
aState = kOmegaAcc;
return uint32_t(-1);
case kDiaeresis:
aState = kStart;
return uint32_t(-1);
default:
break;
}
break;
// combinations with dieresis+accent just strip the accent,
// and reset to start state (don't form diphthong with following vowel)
case GREEK_LOWER_IOTA_DIALYTIKA_TONOS:
case GREEK_LOWER_IOTA_DIALYTIKA_OXIA:
aState = kStart;
return GREEK_UPPER_IOTA_DIALYTIKA;
case GREEK_LOWER_UPSILON_DIALYTIKA_TONOS:
case GREEK_LOWER_UPSILON_DIALYTIKA_OXIA:
aState = kStart;
return GREEK_UPPER_UPSILON_DIALYTIKA;
case COMBINING_GREEK_DIALYTIKA_TONOS:
aState = kStart;
return COMBINING_DIAERESIS;
// strip accents from vowels, and note the vowel seen so that we can detect
// diphthongs where diaeresis needs to be added
case GREEK_LOWER_ALPHA_TONOS:
case GREEK_LOWER_ALPHA_OXIA:
case GREEK_UPPER_ALPHA_TONOS:
case GREEK_UPPER_ALPHA_OXIA:
aState = kAlphaAcc;
return GREEK_UPPER_ALPHA;
case GREEK_LOWER_EPSILON_TONOS:
case GREEK_LOWER_EPSILON_OXIA:
case GREEK_UPPER_EPSILON_TONOS:
case GREEK_UPPER_EPSILON_OXIA:
aState = kEpsilonAcc;
return GREEK_UPPER_EPSILON;
case GREEK_LOWER_ETA_TONOS:
case GREEK_LOWER_ETA_OXIA:
case GREEK_UPPER_ETA_TONOS:
case GREEK_UPPER_ETA_OXIA:
aState = kEtaAcc;
return GREEK_UPPER_ETA;
case GREEK_LOWER_IOTA_TONOS:
case GREEK_LOWER_IOTA_OXIA:
case GREEK_UPPER_IOTA_TONOS:
case GREEK_UPPER_IOTA_OXIA:
aState = kIotaAcc;
return GREEK_UPPER_IOTA;
case GREEK_LOWER_OMICRON_TONOS:
case GREEK_LOWER_OMICRON_OXIA:
case GREEK_UPPER_OMICRON_TONOS:
case GREEK_UPPER_OMICRON_OXIA:
aState = kOmicronAcc;
return GREEK_UPPER_OMICRON;
case GREEK_LOWER_UPSILON_TONOS:
case GREEK_LOWER_UPSILON_OXIA:
case GREEK_UPPER_UPSILON_TONOS:
case GREEK_UPPER_UPSILON_OXIA:
switch (aState) {
case kOmicron:
aState = kStart; // this completed a diphthong
break;
default:
aState = kUpsilonAcc;
break;
}
return GREEK_UPPER_UPSILON;
case GREEK_LOWER_OMEGA_TONOS:
case GREEK_LOWER_OMEGA_OXIA:
case GREEK_UPPER_OMEGA_TONOS:
case GREEK_UPPER_OMEGA_OXIA:
aState = kOmegaAcc;
return GREEK_UPPER_OMEGA;
}
// all other characters just reset the state, and use standard mappings
aState = kStart;
return ToUpperCase(aCh);
}
int32_t
CaseInsensitiveCompare(const char16_t *a,
const char16_t *b,

View File

@ -37,63 +37,6 @@ inline bool IsLowerCase(uint32_t c) {
return ToUpperCase(c) != c;
}
class GreekCasing {
// When doing an Uppercase transform in Greek, we need to keep track of the
// current state while iterating through the string, to recognize and process
// diphthongs correctly. For clarity, we define a state for each vowel and
// each vowel with accent, although a few of these do not actually need any
// special treatment and could be folded into kStart.
private:
enum GreekStates {
kStart,
kAlpha,
kEpsilon,
kEta,
kIota,
kOmicron,
kUpsilon,
kOmega,
kAlphaAcc,
kEpsilonAcc,
kEtaAcc,
kIotaAcc,
kOmicronAcc,
kUpsilonAcc,
kOmegaAcc,
kOmicronUpsilon,
kDiaeresis
};
public:
class State {
public:
State()
: mState(kStart)
{
}
State(const GreekStates& aState)
: mState(aState)
{
}
void Reset()
{
mState = kStart;
}
operator GreekStates() const
{
return mState;
}
private:
GreekStates mState;
};
static uint32_t UpperCase(uint32_t aCh, State& aState);
};
#ifdef MOZILLA_INTERNAL_API
class nsCaseInsensitiveStringComparator : public nsStringComparator

View File

@ -4,7 +4,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
intl_unicharutil_util_lcppsrcs = []
intl_unicharutil_util_lcppsrcs = [
'GreekCasing.cpp',
]
if CONFIG['ENABLE_INTL_API']:
intl_unicharutil_util_lcppsrcs += [
@ -12,6 +14,7 @@ if CONFIG['ENABLE_INTL_API']:
]
intl_unicharutil_util_lcppsrcs += [
'IrishCasing.cpp',
'nsBidiUtils.cpp',
'nsSpecialCasingData.cpp',
'nsUnicharUtils.cpp',

View File

@ -17,6 +17,8 @@
#include "nsTextFrameUtils.h"
#include "nsIPersistentProperties2.h"
#include "nsNetUtil.h"
#include "GreekCasing.h"
#include "IrishCasing.h"
// Unicode characters needing special casing treatment in tr/az languages
#define LATIN_CAPITAL_LETTER_I_WITH_DOT_ABOVE 0x0130
@ -224,9 +226,10 @@ GetParametersForInner(nsTransformedTextRun* aTextRun, uint32_t* aFlags,
// same setting here, if the behavior is shared by other languages.
enum LanguageSpecificCasingBehavior {
eLSCB_None, // default non-lang-specific behavior
eLSCB_Turkish, // preserve dotted/dotless-i distinction in uppercase
eLSCB_Dutch, // treat "ij" digraph as a unit for capitalization
eLSCB_Greek // strip accent when uppercasing Greek vowels
eLSCB_Greek, // strip accent when uppercasing Greek vowels
eLSCB_Irish, // keep prefix letters as lowercase when uppercasing Irish
eLSCB_Turkish // preserve dotted/dotless-i distinction in uppercase
};
static LanguageSpecificCasingBehavior
@ -245,6 +248,9 @@ GetCasingFor(const nsIAtom* aLang)
if (aLang == nsGkAtoms::el) {
return eLSCB_Greek;
}
if (aLang == nsGkAtoms::ga_ie) {
return eLSCB_Irish;
}
return eLSCB_None;
}
@ -277,7 +283,9 @@ nsCaseTransformTextRunFactory::TransformString(
const nsIAtom* lang = aLanguage;
LanguageSpecificCasingBehavior languageSpecificCasing = GetCasingFor(lang);
GreekCasing::State greekState;
mozilla::GreekCasing::State greekState;
mozilla::IrishCasing::State irishState;
uint32_t irishMark = uint32_t(-1); // location of possible prefix letter(s)
for (uint32_t i = 0; i < length; ++i) {
uint32_t ch = str[i];
@ -292,11 +300,14 @@ nsCaseTransformTextRunFactory::TransformString(
lang = styleContext->StyleFont()->mLanguage;
languageSpecificCasing = GetCasingFor(lang);
greekState.Reset();
irishState.Reset();
irishMark = uint32_t(-1);
}
}
int extraChars = 0;
const mozilla::unicode::MultiCharMapping *mcm;
bool inhibitBreakBefore = false; // have we just deleted preceding hyphen?
if (NS_IS_HIGH_SURROGATE(ch) && i < length - 1 &&
NS_IS_LOW_SURROGATE(str[i + 1])) {
@ -396,10 +407,63 @@ nsCaseTransformTextRunFactory::TransformString(
}
if (languageSpecificCasing == eLSCB_Greek) {
ch = GreekCasing::UpperCase(ch, greekState);
ch = mozilla::GreekCasing::UpperCase(ch, greekState);
break;
}
if (languageSpecificCasing == eLSCB_Irish) {
bool mark;
uint8_t action;
ch = mozilla::IrishCasing::UpperCase(ch, irishState, mark, action);
if (mark) {
irishMark = aConvertedString.Length();
break;
} else if (action) {
nsString& str = aConvertedString; // shorthand
switch (action) {
case 1:
// lowercase a single prefix letter
NS_ASSERTION(str.Length() > 0 && irishMark < str.Length(),
"bad irishMark!");
str.SetCharAt(ToLowerCase(str[irishMark]), irishMark);
irishMark = uint32_t(-1);
break;
case 2:
// lowercase two prefix letters (immediately before current pos)
NS_ASSERTION(str.Length() >= 2 && irishMark == str.Length() - 2,
"bad irishMark!");
str.SetCharAt(ToLowerCase(str[irishMark]), irishMark);
str.SetCharAt(ToLowerCase(str[irishMark + 1]), irishMark + 1);
irishMark = uint32_t(-1);
break;
case 3:
// lowercase one prefix letter, and delete following hyphen
// (which must be the immediately-preceding char)
NS_ASSERTION(str.Length() >= 2 && irishMark == str.Length() - 2,
"bad irishMark!");
str.Replace(irishMark, 2, ToLowerCase(str[irishMark]));
aDeletedCharsArray[irishMark + 1] = true;
// Remove the trailing entries (corresponding to the deleted hyphen)
// from the auxiliary arrays.
aCharsToMergeArray.SetLength(aCharsToMergeArray.Length() - 1);
if (aTextRun) {
aStyleArray->SetLength(aStyleArray->Length() - 1);
aCanBreakBeforeArray->SetLength(aCanBreakBeforeArray->Length() - 1);
inhibitBreakBefore = true;
}
mergeNeeded = true;
irishMark = uint32_t(-1);
break;
}
// ch has been set to the uppercase for current char;
// No need to check for SpecialUpper here as none of the characters
// that could trigger an Irish casing action have special mappings.
break;
}
// If we didn't have any special action to perform, fall through
// to check for special uppercase (ß)
}
mcm = mozilla::unicode::SpecialUpper(ch);
if (mcm) {
int j = 0;
@ -467,7 +531,8 @@ nsCaseTransformTextRunFactory::TransformString(
aCharsToMergeArray.AppendElement(false);
if (aTextRun) {
aStyleArray->AppendElement(styleContext);
aCanBreakBeforeArray->AppendElement(aTextRun->CanBreakLineBefore(i));
aCanBreakBeforeArray->AppendElement(inhibitBreakBefore ? false :
aTextRun->CanBreakLineBefore(i));
}
if (IS_IN_BMP(ch)) {

View File

@ -0,0 +1,120 @@
<!DOCTYPE html>
<html lang="ga-IE">
<head>
<meta charset="utf-8">
<title>Test for Irish uppercasing</title>
<style>
body {
font: 16px/20px monospace;
text-transform: none;
}
</style>
</head>
<body>
ORD NA bhFOCAL
/ COSÁN NA bhFILÍ
/ ÁR bPOBAL
/ NÓRA NA bPORTACH
/ I dTOSACH BÁIRE
/ AN GHAEILGE I dTUAISCEART NA hÉIREANN
/ AS AN gCEANTAR SIN
/ I gCONTAE NA MÍ AGUS I gCONAMARA
/ DÉ hAOINE
/ OIRTHEAR NA hÁISE
/ PARLAIMINT NA hEORPA
/ POBLACHT NA hÉIREANN
/ EALAÍN NA hIODÁILE
/ NA hÍOSÁNAIGH
/ ACADAMH NA hOLLSCOLAÍOCHTA
/ TÍR NA hÓIGE
/ TOGHCHÁN NA hUACHTARÁNACHTA
/ NA hÚDARÁIS CHÁNACH
/ I mBUN MO MHACHNAMH
/ I mBÉAL FEIRSTE AGUS I mBAILE ÁTHA CLIATH
/ ÁR nACMHAINNÍ UISCE
/ EOLAÍOCHT NA nÁBHAR
/ LUCHT NA nEALAÍON
/ CEOL NA nÉAN
/ ORD NA nIMEACHTAÍ
/ LUCHT ADHARTHA NA nÍOMHÁNNA
/ GNÉITHE DÁR nOIDHREACHT
/ CULTÚR NA nÓG
/ OCHT nUAIRE SA LÁ
/ FORMHÓR NA nÚDARÁS
/ ÁR nATHAIR
/ CLÁR NA nÁBHAR
/ LOCH nEATHACH
/ CUMANN NA nÉIREANNACH AONTAITHE
/ GRÉASÁN NA nIONTAS
/ NÓIBHÍSEACHT NA nÍOSÁNACH
/ I gCEANTAR NA nOILEÁN
/ TÍR NA nÓG
/ BAILE NA nULTACH
/ GORT NA nÚLL
/ CEOL NA nDAOINE
/ I nDÚN NA nGALL
/ TÁIM I nGRÁ LEAT
/ LABHAIR SÉ I nGAEILGE!
/ CÉN tAM É?
/ TÁ AN tÁDH ORM INNIU!
/ DEN OBAIR AN tEOLAS
/ AN tÉILEAMH A ÍOC
/ AN tINNEALL CUARDAIGH IS FEARR
/ AN tÍOCHTAR A CHUR IN UACHTAR
/ TABHAIR AN tORDÚ SEO DÓ!
/ TÁ AN tÓR BUÍ AIGE.
/ AN tUISCE BEATHA AR AN TÁBLA.
/ AN tÚRSCÉAL IS DEIREANAÍ
/ AN tACHT OIDEACHAIS
/ AN tÁIVÉ MÁIRIA
/ AN tEARRACH ARABACH
/ AN tÉIRÍ AMACH
/ AN tIMEALL
/ AN tÍOSÁNACH PEADAR CANISIUS
/ AN tOILEÁNACH
/ AN tÓR MUIRE
/ AN tUASAL ÉAMON Ó CUÍV
/ AN tÚDARÁS UM BÓITHRE NÁISIÚNTA
/ AR AON tSLÍ
/ BÉAL ÁTHA AN tSLÉIBHE
/ AMACH ÓN tSNÁTHAID
/ BANRÍON AN tSNEACHTA
/ AR AN tSRÁID
/ CAINT AN tSRÁIDBHAILE
/ CORA CRUA AN tSAOIL
/ BHOLADH AN tSÁILE
/ UAIR SA tSEACHTAIN
/ DEIREADH AN tSÉASÚIR
/ FEAR AN tSIOPA
/ AN tSÍOCHÁIN A CHOIMEÁD
/ AN tSOCHAÍ FAISNÉISE
/ GAOTH AN tSÓLÁIS
/ IS BEAG AN tSUIM IAD
/ INFHEICTHE AG AN tSÚIL
/ CNOC AN tSAMHRAIDH
/ CIONN tSÁILE
/ AN tSEIRBHÍS PHOIBLÍ
/ BAILE AN tSÉIPÉIL
/ AN tSIRIA
/ AN tSÍN
/ OIFIG AN tSOLÁTHAIR
/ POLL AN tSÓMAIS
/ EOLAIRE AN tSUÍMH
/ CASADH AN tSÚGÁIN
/ SCRÍOBHFAIDH
/ PREABPHAS
/ ÚSÁIDTEAR
/ SNAGCHEOL
/ STÁITSE IMBOLC
/ IN-ATHNUAITE AGATSA
/ TEANGA DHOMHANDA
/ RÉALTSRUTH
/ NA HATAÍ
/ NA HATAÍ
/ ÁR NATHAIR
/ ÁR NATHAIR
/ T-LÉINE
/ TORC ALLTA
/ TSK TSK TSK A CHARA
</body>
</html>

View File

@ -0,0 +1,120 @@
<!DOCTYPE html>
<html lang="ga-IE">
<head>
<meta charset="utf-8">
<title>Test for Irish uppercasing</title>
<style>
body {
font: 16px/20px monospace;
text-transform: uppercase;
}
</style>
</head>
<body>
ord na bhfocal
/ Cosán na bhFilí
/ ár bpobal
/ Nóra na bPortach
/ i dtosach báire
/ An Ghaeilge i dTuaisceart na hÉireann
/ as an gceantar sin
/ I gContae na Mí agus i gConamara
/ Dé hAoine
/ Oirthear na hÁise
/ Parlaimint na hEorpa
/ Poblacht na hÉireann
/ Ealaín na hIodáile
/ na hÍosánaigh
/ Acadamh na hOllscolaíochta
/ Tír na hÓige
/ toghchán na hUachtaránachta
/ na hÚdaráis Chánach
/ I mbun mo mhachnamh
/ I mBéal Feirste agus i mBaile Átha Cliath
/ ár n-acmhainní uisce
/ eolaíocht na n-ábhar
/ lucht na n-ealaíon
/ ceol na n-éan
/ ord na n-imeachtaí
/ lucht adhartha na n-íomhánna
/ gnéithe dár n-oidhreacht
/ cultúr na n-óg
/ ocht n-uaire sa lá
/ formhór na n-údarás
/ Ár nAthair
/ Clár na nÁbhar
/ Loch nEathach
/ Cumann na nÉireannach Aontaithe
/ Gréasán na nIontas
/ nóibhíseacht na nÍosánach
/ i gCeantar na nOileán
/ Tír na nÓg
/ Baile na nUltach
/ Gort na nÚll
/ ceol na ndaoine
/ i nDún na nGall
/ táim i ngrá leat
/ labhair sé i nGaeilge!
/ cén t-am é?
/ tá an t-ádh orm inniu!
/ Den obair an t-eolas
/ An t-éileamh a íoc
/ an t-inneall cuardaigh is fearr
/ an t-íochtar a chur in uachtar
/ Tabhair an t-ordú seo dó!
/ Tá an t-ór buí aige.
/ an t-uisce beatha ar an tábla.
/ an t-úrscéal is deireanaí
/ An tAcht Oideachais
/ an tÁivé Máiria
/ An tEarrach Arabach
/ An tÉirí Amach
/ An tImeall
/ An tÍosánach Peadar Canisius
/ An tOileánach
/ An tÓr Muire
/ an tUasal Éamon Ó Cuív
/ An tÚdarás um Bóithre Náisiúnta
/ ar aon tslí
/ Béal Átha an tSléibhe
/ Amach ón tsnáthaid
/ Banríon an tSneachta
/ ar an tsráid
/ Caint an tSráidbhaile
/ cora crua an tsaoil
/ bholadh an tsáile
/ uair sa tseachtain
/ deireadh an tséasúir
/ fear an tsiopa
/ an tsíocháin a choimeád
/ an tsochaí faisnéise
/ gaoth an tsóláis
/ Is beag an tsuim iad
/ infheicthe ag an tsúil
/ Cnoc an tSamhraidh
/ Cionn tSáile
/ an tSeirbhís Phoiblí
/ Baile an tSéipéil
/ An tSiria
/ An tSín
/ Oifig an tSoláthair
/ Poll an tSómais
/ Eolaire an tSuímh
/ Casadh an tSúgáin
/ scríobhfaidh
/ preabphas
/ úsáidtear
/ snagcheol
/ Stáitse Imbolc
/ in-athnuaite agatsa
/ Teanga Dhomhanda
/ Réaltsruth
/ na hataí
/ Na Hataí
/ ár nathair
/ Ár Nathair
/ t-léine
/ torc allta
/ tsk tsk tsk a chara
</body>
</html>

View File

@ -28,6 +28,7 @@ HTTP(..) != small-caps-turkish-1.html small-caps-turkish-1-notref.html
== greek-uppercase-1.html greek-uppercase-1-ref.html
== greek-uppercase-2.html greek-uppercase-2-ref.html
HTTP(..) == greek-small-caps-1.html greek-small-caps-1-ref.html
== irish-uppercase-1.html irish-uppercase-1-ref.html
== fullwidth-1.html fullwidth-1-ref.html
== fullwidth-2.html fullwidth-2-ref.html
== fullwidth-all.html fullwidth-all-ref.html

View File

@ -133,16 +133,13 @@ VcmSIPCCBinding::VcmSIPCCBinding ()
class VcmIceOpaque : public NrIceOpaque {
public:
VcmIceOpaque(cc_streamid_t stream_id,
cc_call_handle_t call_handle,
VcmIceOpaque(cc_call_handle_t call_handle,
uint16_t level) :
stream_id_(stream_id),
call_handle_(call_handle),
level_(level) {}
virtual ~VcmIceOpaque() {}
cc_streamid_t stream_id_;
cc_call_handle_t call_handle_;
uint16_t level_;
};
@ -172,8 +169,8 @@ void VcmSIPCCBinding::CandidateReady(NrIceMediaStream* stream,
MOZ_ASSERT(opaque);
VcmIceOpaque *vcm_opaque = static_cast<VcmIceOpaque *>(opaque);
CSFLogDebug(logTag, "Candidate ready on call %u, level %u",
vcm_opaque->call_handle_, vcm_opaque->level_);
CSFLogDebug(logTag, "Candidate ready on call %u, level %u: %s",
vcm_opaque->call_handle_, vcm_opaque->level_, candidate.c_str());
char *candidate_tmp = (char *)malloc(candidate.size() + 1);
if (!candidate_tmp)
@ -595,11 +592,15 @@ static short vcmRxAllocICE_s(TemporaryRef<NrIceCtx> ctx_in,
*candidatesp = nullptr;
*candidate_ctp = 0;
// Set the opaque so we can correlate events.
stream->SetOpaque(new VcmIceOpaque(stream_id, call_handle, level));
// This can be called multiple times; don't connect to the signal more than
// once (see bug 1018473 for an explanation).
if (!stream->opaque()) {
// Set the opaque so we can correlate events.
stream->SetOpaque(new VcmIceOpaque(call_handle, level));
// Attach ourself to the candidate signal.
VcmSIPCCBinding::connectCandidateSignal(stream);
// Attach ourself to the candidate signal.
VcmSIPCCBinding::connectCandidateSignal(stream);
}
std::vector<std::string> candidates = stream->GetCandidates();
CSFLogDebug( logTag, "%s: Got %lu candidates", __FUNCTION__, (unsigned long) candidates.size());

View File

@ -477,6 +477,12 @@ TestObserver::OnIceCandidate(uint16_t level,
{
std::cout << name << ": onIceCandidate [" << level << "/"
<< mid << "] " << candidate << std::endl;
// Check for duplicates.
for (auto it = candidates.begin(); it != candidates.end(); ++it) {
EXPECT_NE(*it, candidate) << "Duplicate candidate";
}
candidates.push_back(candidate);
return NS_OK;
}

View File

@ -3144,7 +3144,7 @@ pref("font.name.monospace.ko", "Fira Mono OT");
pref("font.name.serif.th", "Charis SIL Compact");
pref("font.name.sans-serif.th", "Fira Sans OT");
pref("font.name.monospace.th", "Fira Mono OT");
pref("font.name-list.sans-serif.th", "Fira Sans OT, Droid Sans Thai");
pref("font.name-list.sans-serif.th", "Fira Sans OT, Noto Sans Thai, Droid Sans Thai");
pref("font.name.serif.tr", "Charis SIL Compact");
pref("font.name.sans-serif.tr", "Fira Sans OT");

View File

@ -10,6 +10,7 @@ skip-if = e10s # Bug ?????? - intermittent crash of child process reported when
[browser_bug982298.js]
[browser_default_image_filename.js]
skip-if = e10s # Bug 933103 - mochitest's EventUtils.synthesizeMouse functions not e10s friendly
[browser_f7_caret_browsing.js]
[browser_findbar.js]
skip-if = e10s # Disabled for e10s: Bug ?????? - seems to be a timing issue with RemoteFinder.jsm messages coming later than the tests expect.
[browser_input_file_tooltips.js]

View File

@ -0,0 +1,242 @@
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
let gTab = null;
let gListener = null;
const kURL = "data:text/html;charset=utf-8,Caret browsing is fun.<input id='in'>";
const kPrefShortcutEnabled = "accessibility.browsewithcaret_shortcut.enabled";
const kPrefWarnOnEnable = "accessibility.warn_on_browsewithcaret";
const kPrefCaretBrowsingOn = "accessibility.browsewithcaret";
let oldPrefs = {};
for (let pref of [kPrefShortcutEnabled, kPrefWarnOnEnable, kPrefCaretBrowsingOn]) {
oldPrefs[pref] = Services.prefs.getBoolPref(pref);
}
Services.prefs.setBoolPref(kPrefShortcutEnabled, true);
Services.prefs.setBoolPref(kPrefWarnOnEnable, true);
Services.prefs.setBoolPref(kPrefCaretBrowsingOn, false);
registerCleanupFunction(function() {
if (gTab)
gBrowser.removeTab(gTab);
if (gListener)
Services.wm.removeListener(gListener);
for (let pref of [kPrefShortcutEnabled, kPrefWarnOnEnable, kPrefCaretBrowsingOn]) {
Services.prefs.setBoolPref(pref, oldPrefs[pref]);
}
});
function promiseWaitForFocusEvent(el) {
let deferred = Promise.defer();
el.addEventListener("focus", function listener() {
el.removeEventListener("focus", listener, false);
deferred.resolve();
}, false);
return deferred.promise;
}
function promiseTestPageLoad() {
let deferred = Promise.defer();
info("Waiting for test page to load.");
gTab = gBrowser.selectedTab = gBrowser.addTab(kURL);
let browser = gBrowser.selectedBrowser;
browser.addEventListener("load", function listener() {
if (browser.currentURI.spec == "about:blank")
return;
info("Page loaded: " + browser.currentURI.spec);
browser.removeEventListener("load", listener, true);
deferred.resolve();
}, true);
return deferred.promise;
}
function promiseCaretPromptOpened() {
let deferred = Promise.defer();
if (gListener) {
console.trace();
ok(false, "Should not be waiting for another prompt right now.");
return false;
}
info("Waiting for caret prompt to open");
gListener = {
onOpenWindow: function(win) {
let window = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
window.addEventListener("load", function listener() {
window.removeEventListener("load", listener);
if (window.location.href == "chrome://global/content/commonDialog.xul") {
info("Caret prompt opened, removing listener and focusing");
Services.wm.removeListener(gListener);
gListener = null;
deferred.resolve(window);
}
});
},
onCloseWindow: function() {},
};
Services.wm.addListener(gListener);
return deferred.promise;
}
function hitF7(async = true) {
let f7 = () => EventUtils.sendKey("F7", window.content);
// Need to not stop execution inside this task:
if (async) {
executeSoon(f7);
} else {
f7();
}
}
function syncToggleCaretNoDialog(expected) {
let openedDialog = false;
promiseCaretPromptOpened().then(function(win) {
openedDialog = true;
win.close(); // This will eventually return focus here and allow the test to continue...
});
// Cause the dialog to appear sync, if it still does.
hitF7(false);
if (gListener) {
Services.wm.removeListener(gListener);
gListener = null;
}
let expectedStr = expected ? "on." : "off.";
ok(!openedDialog, "Shouldn't open a dialog to turn caret browsing " + expectedStr);
let prefVal = Services.prefs.getBoolPref(kPrefCaretBrowsingOn);
is(prefVal, expected, "Caret browsing should now be " + expectedStr);
}
add_task(function* checkTogglingCaretBrowsing() {
yield promiseTestPageLoad();
let textEl = window.content.document.getElementById("in");
textEl.focus();
let promiseGotKey = promiseCaretPromptOpened();
hitF7();
let prompt = yield promiseGotKey;
let doc = prompt.document;
is(doc.documentElement.defaultButton, "cancel", "'No' button should be the default");
ok(!doc.getElementById("checkbox").checked, "Checkbox shouldn't be checked by default.");
let promiseInputFocused = promiseWaitForFocusEvent(textEl);
doc.documentElement.cancelDialog();
yield promiseInputFocused;
ok(!Services.prefs.getBoolPref(kPrefCaretBrowsingOn), "Caret browsing should still be off after cancelling the dialog.");
promiseGotKey = promiseCaretPromptOpened();
hitF7();
prompt = yield promiseGotKey;
doc = prompt.document;
is(doc.documentElement.defaultButton, "cancel", "'No' button should be the default");
ok(!doc.getElementById("checkbox").checked, "Checkbox shouldn't be checked by default.");
promiseInputFocused = promiseWaitForFocusEvent(textEl);
doc.documentElement.acceptDialog();
yield promiseInputFocused;
ok(Services.prefs.getBoolPref(kPrefCaretBrowsingOn), "Caret browsing should be on after accepting the dialog.");
syncToggleCaretNoDialog(false);
promiseGotKey = promiseCaretPromptOpened();
hitF7();
prompt = yield promiseGotKey;
doc = prompt.document;
is(doc.documentElement.defaultButton, "cancel", "'No' button should be the default");
ok(!doc.getElementById("checkbox").checked, "Checkbox shouldn't be checked by default.");
promiseInputFocused = promiseWaitForFocusEvent(textEl);
doc.documentElement.cancelDialog();
yield promiseInputFocused;
ok(!Services.prefs.getBoolPref(kPrefCaretBrowsingOn), "Caret browsing should still be off after cancelling the dialog.");
Services.prefs.setBoolPref(kPrefShortcutEnabled, true);
Services.prefs.setBoolPref(kPrefWarnOnEnable, true);
Services.prefs.setBoolPref(kPrefCaretBrowsingOn, false);
gBrowser.removeTab(gTab);
gTab = null;
});
add_task(function* toggleCheckboxNoCaretBrowsing() {
yield promiseTestPageLoad();
let textEl = window.content.document.getElementById("in");
textEl.focus();
let promiseGotKey = promiseCaretPromptOpened();
hitF7();
let prompt = yield promiseGotKey;
let doc = prompt.document;
is(doc.documentElement.defaultButton, "cancel", "'No' button should be the default");
let checkbox = doc.getElementById("checkbox");
ok(!checkbox.checked, "Checkbox shouldn't be checked by default.");
// Check the box:
checkbox.click();
let promiseInputFocused = promiseWaitForFocusEvent(textEl);
// Say no:
doc.documentElement.getButton("cancel").click();
yield promiseInputFocused;
ok(!Services.prefs.getBoolPref(kPrefCaretBrowsingOn), "Caret browsing should still be off.");
ok(!Services.prefs.getBoolPref(kPrefShortcutEnabled), "Shortcut should now be disabled.");
syncToggleCaretNoDialog(false);
ok(!Services.prefs.getBoolPref(kPrefShortcutEnabled), "Shortcut should still be disabled.");
Services.prefs.setBoolPref(kPrefShortcutEnabled, true);
Services.prefs.setBoolPref(kPrefWarnOnEnable, true);
Services.prefs.setBoolPref(kPrefCaretBrowsingOn, false);
gBrowser.removeTab(gTab);
gTab = null;
});
add_task(function* toggleCheckboxNoCaretBrowsing() {
yield promiseTestPageLoad();
let textEl = window.content.document.getElementById("in");
textEl.focus();
let promiseGotKey = promiseCaretPromptOpened();
hitF7();
let prompt = yield promiseGotKey;
let doc = prompt.document;
is(doc.documentElement.defaultButton, "cancel", "'No' button should be the default");
let checkbox = doc.getElementById("checkbox");
ok(!checkbox.checked, "Checkbox shouldn't be checked by default.");
// Check the box:
checkbox.click();
let promiseInputFocused = promiseWaitForFocusEvent(textEl);
// Say yes:
doc.documentElement.acceptDialog();
yield promiseInputFocused;
ok(Services.prefs.getBoolPref(kPrefCaretBrowsingOn), "Caret browsing should now be on.");
ok(Services.prefs.getBoolPref(kPrefShortcutEnabled), "Shortcut should still be enabled.");
ok(!Services.prefs.getBoolPref(kPrefWarnOnEnable), "Should no longer warn when enabling.");
syncToggleCaretNoDialog(false);
syncToggleCaretNoDialog(true);
syncToggleCaretNoDialog(false);
Services.prefs.setBoolPref(kPrefShortcutEnabled, true);
Services.prefs.setBoolPref(kPrefWarnOnEnable, true);
Services.prefs.setBoolPref(kPrefCaretBrowsingOn, false);
gBrowser.removeTab(gTab);
gTab = null;
});

View File

@ -1100,7 +1100,11 @@
if (event.defaultPrevented || !event.isTrusted)
return;
var isEnabled = this.mPrefs.getBoolPref("accessibility.browsewithcaret_shortcut.enabled");
const kPrefShortcutEnabled = "accessibility.browsewithcaret_shortcut.enabled";
const kPrefWarnOnEnable = "accessibility.warn_on_browsewithcaret";
const kPrefCaretBrowsingOn = "accessibility.browsewithcaret";
var isEnabled = this.mPrefs.getBoolPref(kPrefShortcutEnabled);
if (!isEnabled)
return;
@ -1109,12 +1113,12 @@
var warn = true;
try {
warn = this.mPrefs.getBoolPref("accessibility.warn_on_browsewithcaret");
warn = this.mPrefs.getBoolPref(kPrefWarnOnEnable);
} catch (ex) {
}
try {
browseWithCaretOn = this.mPrefs.getBoolPref("accessibility.browsewithcaret");
browseWithCaretOn = this.mPrefs.getBoolPref(kPrefCaretBrowsingOn);
} catch (ex) {
}
if (warn && !browseWithCaretOn) {
@ -1125,14 +1129,22 @@
var buttonPressed = promptService.confirmEx(window,
this.mStrBundle.GetStringFromName('browsewithcaret.checkWindowTitle'),
this.mStrBundle.GetStringFromName('browsewithcaret.checkLabel'),
promptService.STD_YES_NO_BUTTONS,
// Make "No" the default:
promptService.STD_YES_NO_BUTTONS | promptService.BUTTON_POS_1_DEFAULT,
null, null, null, this.mStrBundle.GetStringFromName('browsewithcaret.checkMsg'),
checkValue);
if (buttonPressed != 0)
if (buttonPressed != 0) {
if (checkValue.value) {
try {
this.mPrefs.setBoolPref(kPrefShortcutEnabled, false);
} catch (ex) {
}
}
return;
}
if (checkValue.value) {
try {
this.mPrefs.setBoolPref("accessibility.warn_on_browsewithcaret", false);
this.mPrefs.setBoolPref(kPrefWarnOnEnable, false);
}
catch (ex) {
}
@ -1141,7 +1153,7 @@
// Toggle the pref
try {
this.mPrefs.setBoolPref("accessibility.browsewithcaret",!browseWithCaretOn);
this.mPrefs.setBoolPref(kPrefCaretBrowsingOn, !browseWithCaretOn);
} catch (ex) {
}
]]>

View File

@ -14,6 +14,7 @@ const XMLHttpRequest =
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
@ -21,6 +22,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm")
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyGetter(this, "gTextDecoder", () => {
return new TextDecoder();
});
// The filename where directory links are stored locally
const DIRECTORY_LINKS_FILE = "directoryLinks.json";
@ -32,7 +36,7 @@ const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
const PREF_SELECTED_LOCALE = "general.useragent.locale";
// The preference that tells where to obtain directory links
const PREF_DIRECTORY_SOURCE = "browser.newtabpage.directorySource";
const PREF_DIRECTORY_SOURCE = "browser.newtabpage.directory.source";
// The frecency of a directory link
const DIRECTORY_FRECENCY = 1000;
@ -52,7 +56,13 @@ let DirectoryLinksProvider = {
__linksURL: null,
_observers: [],
_observers: new Set(),
// links download deferred, resolved upon download completion
_downloadDeferred: null,
// download default interval is 24 hours in milliseconds
_downloadIntervalMS: 86400000,
get _observedPrefs() Object.freeze({
linksURL: PREF_DIRECTORY_SOURCE,
@ -111,8 +121,9 @@ let DirectoryLinksProvider = {
if (aData == this._observedPrefs["linksURL"]) {
delete this.__linksURL;
}
this._callObservers("onManyLinksChanged");
}
// force directory download on changes to any of the observed prefs
this._fetchAndCacheLinksIfNecessary(true);
},
_addPrefsObserver: function DirectoryLinksProvider_addObserver() {
@ -129,38 +140,6 @@ let DirectoryLinksProvider = {
}
},
/**
* Fetches the current set of directory links.
* @param aCallback a callback that is provided a set of links.
*/
_fetchLinks: function DirectoryLinksProvider_fetchLinks(aCallback) {
try {
NetUtil.asyncFetch(this._linksURL, (aInputStream, aResult, aRequest) => {
let output;
if (Components.isSuccessCode(aResult)) {
try {
let json = NetUtil.readInputStreamToString(aInputStream,
aInputStream.available(),
{charset: "UTF-8"});
let locale = this.locale;
output = JSON.parse(json)[locale];
}
catch (e) {
Cu.reportError(e);
}
}
else {
Cu.reportError(new Error("the fetch of " + this._linksURL + "was unsuccessful"));
}
aCallback(output || []);
});
}
catch (e) {
Cu.reportError(e);
aCallback([]);
}
},
_fetchAndCacheLinks: function DirectoryLinksProvider_fetchAndCacheLinks(uri) {
let deferred = Promise.defer();
let xmlHttp = new XMLHttpRequest();
@ -172,11 +151,9 @@ let DirectoryLinksProvider = {
if (this.status && this.status != 200) {
json = "{}";
}
let directoryLinksFilePath = OS.Path.join(OS.Constants.Path.localProfileDir, DIRECTORY_LINKS_FILE);
OS.File.writeAtomic(directoryLinksFilePath, json, {tmpPath: directoryLinksFilePath + ".tmp"})
OS.File.writeAtomic(self._directoryFilePath, json, {tmpPath: self._directoryFilePath + ".tmp"})
.then(() => {
deferred.resolve();
self._callObservers("onManyLinksChanged");
},
() => {
deferred.reject("Error writing uri data in profD.");
@ -197,12 +174,93 @@ let DirectoryLinksProvider = {
return deferred.promise;
},
/**
* Downloads directory links if needed
* @return promise resolved immediately if no download needed, or upon completion
*/
_fetchAndCacheLinksIfNecessary: function DirectoryLinksProvider_fetchAndCacheLinksIfNecessary(forceDownload=false) {
if (this._downloadDeferred) {
// fetching links already - just return the promise
return this._downloadDeferred.promise;
}
if (forceDownload || this._needsDownload) {
this._downloadDeferred = Promise.defer();
this._fetchAndCacheLinks(this._linksURL).then(() => {
// the new file was successfully downloaded and cached, so update a timestamp
this._lastDownloadMS = Date.now();
this._downloadDeferred.resolve();
this._downloadDeferred = null;
this._callObservers("onManyLinksChanged")
},
error => {
this._downloadDeferred.resolve();
this._downloadDeferred = null;
this._callObservers("onDownloadFail");
});
return this._downloadDeferred.promise;
}
// download is not needed
return Promise.resolve();
},
/**
* @return true if download is needed, false otherwise
*/
get _needsDownload () {
// fail if last download occured less then 24 hours ago
if ((Date.now() - this._lastDownloadMS) > this._downloadIntervalMS) {
return true;
}
return false;
},
/**
* Reads directory links file and parses its content
* @return a promise resolved to valid list of links or [] if read or parse fails
*/
_readDirectoryLinksFile: function DirectoryLinksProvider_readDirectoryLinksFile() {
return OS.File.read(this._directoryFilePath).then(binaryData => {
let output;
try {
let locale = this.locale;
let json = gTextDecoder.decode(binaryData);
output = JSON.parse(json)[locale];
}
catch (e) {
Cu.reportError(e);
}
return output || [];
},
error => {
Cu.reportError(error);
return [];
});
},
/**
* Submits counts of shown directory links for each type and
* triggers directory download if sponsored link was shown
*
* @param object keyed on types containing counts
* @return download promise
*/
reportShownCount: function DirectoryLinksProvider_reportShownCount(directoryCount) {
if (directoryCount.sponsored > 0
|| directoryCount.affiliate > 0
|| directoryCount.organic > 0) {
return this._fetchAndCacheLinksIfNecessary();
}
return Promise.resolve();
},
/**
* Gets the current set of directory links.
* @param aCallback The function that the array of links is passed to.
*/
getLinks: function DirectoryLinksProvider_getLinks(aCallback) {
this._fetchLinks(rawLinks => {
this._readDirectoryLinksFile().then(rawLinks => {
// all directory links have a frecency of DIRECTORY_FRECENCY
aCallback(rawLinks.map((link, position) => {
link.frecency = DIRECTORY_FRECENCY;
@ -214,6 +272,19 @@ let DirectoryLinksProvider = {
init: function DirectoryLinksProvider_init() {
this._addPrefsObserver();
// setup directory file path and last download timestamp
this._directoryFilePath = OS.Path.join(OS.Constants.Path.localProfileDir, DIRECTORY_LINKS_FILE);
this._lastDownloadMS = 0;
return Task.spawn(function() {
// get the last modified time of the links file if it exists
let doesFileExists = yield OS.File.exists(this._directoryFilePath);
if (doesFileExists) {
let fileInfo = yield OS.File.stat(this._directoryFilePath);
this._lastDownloadMS = Date.parse(fileInfo.lastModificationDate);
}
// fetch directory on startup without force
yield this._fetchAndCacheLinksIfNecessary();
}.bind(this));
},
/**
@ -226,7 +297,11 @@ let DirectoryLinksProvider = {
},
addObserver: function DirectoryLinksProvider_addObserver(aObserver) {
this._observers.push(aObserver);
this._observers.add(aObserver);
},
removeObserver: function DirectoryLinksProvider_removeObserver(aObserver) {
this._observers.delete(aObserver);
},
_callObservers: function DirectoryLinksProvider__callObservers(aMethodName, aArg) {
@ -242,8 +317,6 @@ let DirectoryLinksProvider = {
},
_removeObservers: function() {
while (this._observers.length) {
this._observers.pop();
}
this._observers.clear();
}
};

View File

@ -14,7 +14,9 @@ Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource://gre/modules/Http.jsm");
Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/osfile.jsm")
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
@ -29,6 +31,10 @@ const kTestURL = 'data:application/json,' + JSON.stringify(kURLData);
const kLocalePref = DirectoryLinksProvider._observedPrefs.prefSelectedLocale;
const kSourceUrlPref = DirectoryLinksProvider._observedPrefs.linksURL;
// app/profile/firefox.js are not avaialble in xpcshell: hence, preset them
Services.prefs.setCharPref(kLocalePref, "en-US");
Services.prefs.setCharPref(kSourceUrlPref, kTestURL);
// httpd settings
var server;
const kDefaultServerPort = 9000;
@ -103,19 +109,44 @@ function cleanJsonFile(jsonFile = DIRECTORY_LINKS_FILE) {
return OS.File.remove(directoryLinksFilePath);
}
// All tests that call setupDirectoryLinksProvider() must also call cleanDirectoryLinksProvider().
function setupDirectoryLinksProvider(options = {}) {
let linksURL = options.linksURL || kTestURL;
DirectoryLinksProvider.init();
Services.prefs.setCharPref(kLocalePref, options.locale || "en-US");
Services.prefs.setCharPref(kSourceUrlPref, linksURL);
do_check_eq(DirectoryLinksProvider._linksURL, linksURL);
function LinksChangeObserver() {
this.deferred = Promise.defer();
this.onManyLinksChanged = () => this.deferred.resolve();
this.onDownloadFail = this.onManyLinksChanged;
}
function cleanDirectoryLinksProvider() {
DirectoryLinksProvider.reset();
Services.prefs.clearUserPref(kLocalePref);
Services.prefs.clearUserPref(kSourceUrlPref);
function promiseDirectoryDownloadOnPrefChange(pref, newValue) {
let oldValue = Services.prefs.getCharPref(pref);
if (oldValue != newValue) {
// if the preference value is already equal to newValue
// the pref service will not call our observer and we
// deadlock. Hence only setup observer if values differ
let observer = new LinksChangeObserver();
DirectoryLinksProvider.addObserver(observer);
Services.prefs.setCharPref(pref, newValue);
return observer.deferred.promise;
}
return Promise.resolve();
}
function promiseSetupDirectoryLinksProvider(options = {}) {
return Task.spawn(function() {
let linksURL = options.linksURL || kTestURL;
yield DirectoryLinksProvider.init();
yield promiseDirectoryDownloadOnPrefChange(kLocalePref, options.locale || "en-US");
yield promiseDirectoryDownloadOnPrefChange(kSourceUrlPref, linksURL);
do_check_eq(DirectoryLinksProvider._linksURL, linksURL);
DirectoryLinksProvider._lastDownloadMS = options.lastDownloadMS || 0;
});
}
function promiseCleanDirectoryLinksProvider() {
return Task.spawn(function() {
yield promiseDirectoryDownloadOnPrefChange(kLocalePref, "en-US");
yield promiseDirectoryDownloadOnPrefChange(kSourceUrlPref, kTestURL);
DirectoryLinksProvider._lastDownloadMS = 0;
DirectoryLinksProvider.reset();
});
}
function run_test() {
@ -130,10 +161,14 @@ function run_test() {
// Teardown.
do_register_cleanup(function() {
server.stop(function() { });
DirectoryLinksProvider.reset();
Services.prefs.clearUserPref(kLocalePref);
Services.prefs.clearUserPref(kSourceUrlPref);
});
}
add_task(function test_fetchAndCacheLinks_local() {
yield DirectoryLinksProvider.init();
yield cleanJsonFile();
// Trigger cache of data or chrome uri files in profD
yield DirectoryLinksProvider._fetchAndCacheLinks(kTestURL);
@ -142,6 +177,7 @@ add_task(function test_fetchAndCacheLinks_local() {
});
add_task(function test_fetchAndCacheLinks_remote() {
yield DirectoryLinksProvider.init();
yield cleanJsonFile();
// this must trigger directory links json download and save it to cache file
yield DirectoryLinksProvider._fetchAndCacheLinks(kExampleURL);
@ -150,6 +186,7 @@ add_task(function test_fetchAndCacheLinks_remote() {
});
add_task(function test_fetchAndCacheLinks_malformedURI() {
yield DirectoryLinksProvider.init();
yield cleanJsonFile();
let someJunk = "some junk";
try {
@ -165,6 +202,7 @@ add_task(function test_fetchAndCacheLinks_malformedURI() {
});
add_task(function test_fetchAndCacheLinks_unknownHost() {
yield DirectoryLinksProvider.init();
yield cleanJsonFile();
let nonExistentServer = "http://nosuchhost";
try {
@ -180,6 +218,7 @@ add_task(function test_fetchAndCacheLinks_unknownHost() {
});
add_task(function test_fetchAndCacheLinks_non200Status() {
yield DirectoryLinksProvider.init();
yield cleanJsonFile();
yield DirectoryLinksProvider._fetchAndCacheLinks(kFailURL);
let data = yield readJsonFile();
@ -187,24 +226,19 @@ add_task(function test_fetchAndCacheLinks_non200Status() {
});
// To test onManyLinksChanged observer, trigger a fetch
add_task(function test_linkObservers() {
let deferred = Promise.defer();
let testObserver = {
onManyLinksChanged: function() {
deferred.resolve();
}
}
add_task(function test_DirectoryLinksProvider__linkObservers() {
yield DirectoryLinksProvider.init();
DirectoryLinksProvider.init();
let testObserver = new LinksChangeObserver();
DirectoryLinksProvider.addObserver(testObserver);
do_check_eq(DirectoryLinksProvider._observers.length, 1);
DirectoryLinksProvider._fetchAndCacheLinks(kTestURL);
do_check_eq(DirectoryLinksProvider._observers.size, 1);
DirectoryLinksProvider._fetchAndCacheLinksIfNecessary(true);
yield deferred.promise;
yield testObserver.deferred.promise;
DirectoryLinksProvider._removeObservers();
do_check_eq(DirectoryLinksProvider._observers.length, 0);
do_check_eq(DirectoryLinksProvider._observers.size, 0);
cleanDirectoryLinksProvider();
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_linksURL_locale() {
@ -217,7 +251,7 @@ add_task(function test_linksURL_locale() {
};
let dataURI = 'data:application/json,' + JSON.stringify(data);
setupDirectoryLinksProvider({linksURL: dataURI});
yield promiseSetupDirectoryLinksProvider({linksURL: dataURI});
let links;
let expected_data;
@ -227,7 +261,7 @@ add_task(function test_linksURL_locale() {
expected_data = [{url: "http://example.com", title: "US", frecency: DIRECTORY_FRECENCY, lastVisitDate: 1}];
isIdentical(links, expected_data);
Services.prefs.setCharPref('general.useragent.locale', 'zh-CN');
yield promiseDirectoryDownloadOnPrefChange("general.useragent.locale", "zh-CN");
links = yield fetchData();
do_check_eq(links.length, 2)
@ -237,11 +271,11 @@ add_task(function test_linksURL_locale() {
];
isIdentical(links, expected_data);
cleanDirectoryLinksProvider();
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_prefObserver_url() {
setupDirectoryLinksProvider({linksURL: kTestURL});
add_task(function test_DirectoryLinksProvider__prefObserver_url() {
yield promiseSetupDirectoryLinksProvider({linksURL: kTestURL});
let links = yield fetchData();
do_check_eq(links.length, 1);
@ -252,18 +286,146 @@ add_task(function test_prefObserver_url() {
// 1. _linksURL is properly set after the pref change
// 2. invalid source url is correctly handled
let exampleUrl = 'http://nosuchhost/bad';
Services.prefs.setCharPref(kSourceUrlPref, exampleUrl);
yield promiseDirectoryDownloadOnPrefChange(kSourceUrlPref, exampleUrl);
do_check_eq(DirectoryLinksProvider._linksURL, exampleUrl);
// since the download fail, the directory file must remain the same
let newLinks = yield fetchData();
isIdentical(newLinks, expectedData);
// now remove the file, and re-download
yield cleanJsonFile();
yield promiseDirectoryDownloadOnPrefChange(kSourceUrlPref, exampleUrl + " ");
// we now should see empty links
newLinks = yield fetchData();
isIdentical(newLinks, []);
cleanDirectoryLinksProvider();
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_getLinks_noLocaleData() {
setupDirectoryLinksProvider({locale: 'zh-CN'});
add_task(function test_DirectoryLinksProvider_getLinks_noLocaleData() {
yield promiseSetupDirectoryLinksProvider({locale: 'zh-CN'});
let links = yield fetchData();
do_check_eq(links.length, 0);
cleanDirectoryLinksProvider();
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_DirectoryLinksProvider_needsDownload() {
// test timestamping
DirectoryLinksProvider._lastDownloadMS = 0;
do_check_true(DirectoryLinksProvider._needsDownload);
DirectoryLinksProvider._lastDownloadMS = Date.now();
do_check_false(DirectoryLinksProvider._needsDownload);
DirectoryLinksProvider._lastDownloadMS = Date.now() - (60*60*24 + 1)*1000;
do_check_true(DirectoryLinksProvider._needsDownload);
DirectoryLinksProvider._lastDownloadMS = 0;
});
add_task(function test_DirectoryLinksProvider_fetchAndCacheLinksIfNecessary() {
yield DirectoryLinksProvider.init();
yield cleanJsonFile();
// explicitly change source url to cause the download during setup
yield promiseSetupDirectoryLinksProvider({linksURL: kTestURL+" "});
yield DirectoryLinksProvider._fetchAndCacheLinksIfNecessary();
// inspect lastDownloadMS timestamp which should be 5 seconds less then now()
let lastDownloadMS = DirectoryLinksProvider._lastDownloadMS;
do_check_true((Date.now() - lastDownloadMS) < 5000);
// we should have fetched a new file during setup
let data = yield readJsonFile();
isIdentical(data, kURLData);
// attempt to download again - the timestamp should not change
yield DirectoryLinksProvider._fetchAndCacheLinksIfNecessary();
do_check_eq(DirectoryLinksProvider._lastDownloadMS, lastDownloadMS);
// clean the file and force the download
yield cleanJsonFile();
yield DirectoryLinksProvider._fetchAndCacheLinksIfNecessary(true);
data = yield readJsonFile();
isIdentical(data, kURLData);
// make sure that failed download does not corrupt the file, nor changes lastDownloadMS
lastDownloadMS = DirectoryLinksProvider._lastDownloadMS;
yield promiseDirectoryDownloadOnPrefChange(kSourceUrlPref, "http://");
yield DirectoryLinksProvider._fetchAndCacheLinksIfNecessary(true);
data = yield readJsonFile();
isIdentical(data, kURLData);
do_check_eq(DirectoryLinksProvider._lastDownloadMS, lastDownloadMS);
// _fetchAndCacheLinksIfNecessary must return same promise if download is in progress
let downloadPromise = DirectoryLinksProvider._fetchAndCacheLinksIfNecessary(true);
let anotherPromise = DirectoryLinksProvider._fetchAndCacheLinksIfNecessary(true);
do_check_true(downloadPromise === anotherPromise);
yield downloadPromise;
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_DirectoryLinksProvider_fetchDirectoryOnPrefChange() {
yield DirectoryLinksProvider.init();
let testObserver = new LinksChangeObserver();
DirectoryLinksProvider.addObserver(testObserver);
yield cleanJsonFile();
// ensure that provider does not think it needs to download
do_check_false(DirectoryLinksProvider._needsDownload);
// change the source URL, which should force directory download
yield promiseDirectoryDownloadOnPrefChange(kSourceUrlPref, kExampleURL);
// then wait for testObserver to fire and test that json is downloaded
yield testObserver.deferred.promise;
let data = yield readJsonFile();
isIdentical(data, kHttpHandlerData[kExamplePath]);
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_DirectoryLinksProvider_fetchDirectoryOnShowCount() {
yield promiseSetupDirectoryLinksProvider();
// set lastdownload to 0 to make DirectoryLinksProvider want to download
DirectoryLinksProvider._lastDownloadMS = 0;
do_check_true(DirectoryLinksProvider._needsDownload);
// Tell DirectoryLinksProvider that newtab has no room for sponsored links
let directoryCount = {sponsored: 0};
yield DirectoryLinksProvider.reportShownCount(directoryCount);
// the provider must skip download, hence that lastdownload is still 0
do_check_eq(DirectoryLinksProvider._lastDownloadMS, 0);
// make room for sponsored links and repeat, download should happen
directoryCount.sponsored = 1;
yield DirectoryLinksProvider.reportShownCount(directoryCount);
do_check_true(DirectoryLinksProvider._lastDownloadMS != 0);
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_DirectoryLinksProvider_fetchDirectoryOnInit() {
// ensure preferences are set to defaults
yield promiseSetupDirectoryLinksProvider();
// now clean to provider, so we can init it again
yield promiseCleanDirectoryLinksProvider();
yield cleanJsonFile();
yield DirectoryLinksProvider.init();
let data = yield readJsonFile();
isIdentical(data, kURLData);
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_DirectoryLinksProvider_getLinksFromCorruptedFile() {
yield promiseSetupDirectoryLinksProvider();
// write bogus json to a file and attempt to fetch from it
let directoryLinksFilePath = OS.Path.join(OS.Constants.Path.profileDir, DIRECTORY_LINKS_FILE);
yield OS.File.writeAtomic(directoryLinksFilePath, '{"en-US":');
let data = yield fetchData();
isIdentical(data, []);
yield promiseCleanDirectoryLinksProvider();
});

View File

@ -694,36 +694,31 @@ CODE_MAP_X11(Pause, 0x007F)
CODE_MAP_ANDROID(Pause, 0x0077)
// Media keys
// NOTE: Following media keys which cause scancode 0xE000 on Windows should be
// mapped with virtual keycode.
// See KeyboardLayout::ConvertScanCodeToCodeNameIndex() for the detail.
// CODE_MAP_WIN(BrowserBack, 0xE000) // VK_BROWSER_BACK
CODE_MAP_WIN(BrowserBack, 0xE06A)
CODE_MAP_X11(BrowserBack, 0x00A6)
CODE_MAP_ANDROID(BrowserBack, 0x009E)
// CODE_MAP_WIN(BrowserFavorites, 0xE000) // VK_BROWSER_FAVORITES
CODE_MAP_WIN(BrowserFavorites, 0xE066)
CODE_MAP_X11(BrowserFavorites, 0x00A4)
CODE_MAP_ANDROID(BrowserFavorites, 0x009C)
// CODE_MAP_WIN(BrowserForward, 0xE000) // VK_BROWSER_FORWARD
CODE_MAP_WIN(BrowserForward, 0xE069)
CODE_MAP_X11(BrowserForward, 0x00A7)
CODE_MAP_ANDROID(BrowserForward, 0x009F)
// CODE_MAP_WIN(BrowserHome, 0xE000) // VK_BROWSER_HOME
CODE_MAP_WIN(BrowserHome, 0xE032)
CODE_MAP_X11(BrowserHome, 0x00B4)
// CODE_MAP_ANDROID(BrowserHome) // not available? works as Home key.
// CODE_MAP_WIN(BrowserRefresh, 0xE000) // VK_BROWSER_REFRESH
CODE_MAP_WIN(BrowserRefresh, 0xE067)
CODE_MAP_X11(BrowserRefresh, 0x00B5)
CODE_MAP_ANDROID(BrowserRefresh, 0x00AD)
// CODE_MAP_WIN(BrowserSearch, 0xE000) // VK_BROWSER_SEARCH
CODE_MAP_WIN(BrowserSearch, 0xE065)
CODE_MAP_X11(BrowserSearch, 0x00E1)
CODE_MAP_ANDROID(BrowserSearch, 0x00D9)
// CODE_MAP_WIN(BrowserStop, 0xE000) // VK_BROWSER_STOP
CODE_MAP_WIN(BrowserStop, 0xE068)
CODE_MAP_X11(BrowserStop, 0x0088)
CODE_MAP_ANDROID(BrowserStop, 0x0080)
@ -732,35 +727,35 @@ CODE_MAP_ANDROID(BrowserStop, 0x0080)
CODE_MAP_X11(Eject, 0x00A9)
CODE_MAP_ANDROID(Eject, 0x00A1)
// CODE_MAP_WIN(LaunchApp1, 0xE000) // VK_LAUNCH_APP1
CODE_MAP_WIN(LaunchApp1, 0xE06B)
CODE_MAP_X11(LaunchApp1, 0x0098)
CODE_MAP_ANDROID(LaunchApp1, 0x0090)
// CODE_MAP_WIN(LaunchApp2, 0xE000) // VK_LAUNCH_APP2
CODE_MAP_WIN(LaunchApp2, 0xE021)
CODE_MAP_X11(LaunchApp2, 0x0094)
// CODE_MAP_ANDROID(LaunchApp2) // not available?
// CODE_MAP_WIN(LaunchMail, 0xE000) // VK_LAUNCH_MAIL
CODE_MAP_WIN(LaunchMail, 0xE06C)
CODE_MAP_X11(LaunchMail, 0x00A3)
// CODE_MAP_ANDROID(LaunchMail) // not available?
// CODE_MAP_WIN(MediaPlayPause, 0xE000) // VK_MEDIA_PLAY_PAUSE
CODE_MAP_WIN(MediaPlayPause, 0xE022)
CODE_MAP_X11(MediaPlayPause, 0x00AC)
CODE_MAP_ANDROID(MediaPlayPause, 0x00A4)
// CODE_MAP_WIN(MediaSelect, 0xE000) // VK_LAUNCH_MEDIA_SELECT
CODE_MAP_WIN(MediaSelect, 0xE06D)
CODE_MAP_X11(MediaSelect, 0x00B3)
// CODE_MAP_ANDROID(MediaSelect) // not available?
// CODE_MAP_WIN(MediaStop, 0xE000) // VK_MEDIA_STOP
CODE_MAP_WIN(MediaStop, 0xE024)
CODE_MAP_X11(MediaStop, 0x00AE)
CODE_MAP_ANDROID(MediaStop, 0x00A6)
// CODE_MAP_WIN(MediaTrackNext, 0xE000) // VK_MEDIA_NEXT_TRACK
CODE_MAP_WIN(MediaTrackNext, 0xE019)
CODE_MAP_X11(MediaTrackNext, 0x00AB)
CODE_MAP_ANDROID(MediaTrackNext, 0x00A3)
// CODE_MAP_WIN(MediaTrackPrevious, 0xE000) // VK_MEDIA_PREV_TRACK
CODE_MAP_WIN(MediaTrackPrevious, 0xE010)
CODE_MAP_X11(MediaTrackPrevious, 0x00AD)
CODE_MAP_ANDROID(MediaTrackPrevious, 0x00A5)
@ -773,17 +768,17 @@ CODE_MAP_ANDROID(Power, 0x0074)
// CODE_MAP_X11(Sleep) // not available?
CODE_MAP_ANDROID(Sleep, 0x008E)
// CODE_MAP_WIN(VolumeDown, 0xE000) // VK_VOLUME_DOWN
CODE_MAP_WIN(VolumeDown, 0xE02E)
CODE_MAP_MAC(VolumeDown, kVK_VolumeDown) // not available?
CODE_MAP_X11(VolumeDown, 0x007A)
CODE_MAP_ANDROID(VolumeDown, 0x0072)
// CODE_MAP_WIN(VolumeMute, 0xE000) // VK_VOLUME_MUTE
CODE_MAP_WIN(VolumeMute, 0xE020)
CODE_MAP_MAC(VolumeMute, kVK_Mute) // not available?
CODE_MAP_X11(VolumeMute, 0x0079)
CODE_MAP_ANDROID(VolumeMute, 0x0071)
// CODE_MAP_WIN(VolumeUp, 0xE000) // VK_VOLUME_UP
CODE_MAP_WIN(VolumeUp, 0xE030)
CODE_MAP_MAC(VolumeUp, kVK_VolumeUp) // not available?
CODE_MAP_X11(VolumeUp, 0x007B)
CODE_MAP_ANDROID(VolumeUp, 0x0073) // side of body, not on keyboard

View File

@ -40,6 +40,11 @@
#include <winable.h>
#endif
// In WinUser.h, MAPVK_VK_TO_VSC_EX is defined only when WINVER >= 0x0600
#ifndef MAPVK_VK_TO_VSC_EX
#define MAPVK_VK_TO_VSC_EX (4)
#endif
namespace mozilla {
namespace widget {
@ -584,15 +589,25 @@ NativeKey::NativeKey(nsWindowBase* aWidget,
mKeyboardLayout = keyboardLayout->GetLayout();
mScanCode = WinUtils::GetScanCode(mMsg.lParam);
mIsExtended = WinUtils::IsExtendedScanCode(mMsg.lParam);
// On WinXP and WinServer2003, we cannot compute the virtual keycode for
// extended keys due to the API limitation.
bool canComputeVirtualKeyCodeFromScanCode =
(!mIsExtended || IsVistaOrLater());
switch (mMsg.message) {
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP: {
// If the key message is sent from other application like a11y tools, the
// scancode value might not be set proper value. Then, probably the value
// is 0.
// NOTE: If the virtual keycode can be caused by both non-extended key
// and extended key, the API returns the non-extended key's
// scancode. E.g., VK_LEFT causes "4" key on numpad.
if (!mScanCode) {
uint16_t scanCodeEx = ComputeScanCodeExFromVirtualKeyCode(mMsg.wParam);
if (scanCodeEx) {
mScanCode = static_cast<uint8_t>(scanCodeEx & 0xFF);
uint8_t extended = static_cast<uint8_t>((scanCodeEx & 0xFF00) >> 8);
mIsExtended = (extended == 0xE0) || (extended == 0xE1);
}
}
// First, resolve the IME converted virtual keycode to its original
// keycode.
if (mMsg.wParam == VK_PROCESSKEY) {
@ -648,7 +663,7 @@ NativeKey::NativeKey(nsWindowBase* aWidget,
break;
}
if (!canComputeVirtualKeyCodeFromScanCode) {
if (!CanComputeVirtualKeyCodeFromScanCode()) {
// The right control key and the right alt key are extended keys.
// Therefore, we never get VK_RCONTRL and VK_RMENU for the result of
// MapVirtualKeyEx() on WinXP or WinServer2003.
@ -679,11 +694,9 @@ NativeKey::NativeKey(nsWindowBase* aWidget,
// Otherwise, compute the virtual keycode with MapVirtualKeyEx().
mVirtualKeyCode = ComputeVirtualKeyCodeFromScanCodeEx();
// The result might be unexpected value due to the scan code is
// wrong. For example, any key messages can be generated by
// SendMessage() or PostMessage() from applications. So, it's possible
// failure. Then, let's respect the extended flag even if it might be
// set intentionally.
// Following code shouldn't be used now because we compute scancode value
// if we detect that the sender doesn't set proper scancode.
// However, the detection might fail. Therefore, let's keep using this.
switch (mOriginalVirtualKeyCode) {
case VK_CONTROL:
if (mVirtualKeyCode != VK_LCONTROL &&
@ -711,9 +724,13 @@ NativeKey::NativeKey(nsWindowBase* aWidget,
case WM_CHAR:
case WM_UNICHAR:
case WM_SYSCHAR:
// NOTE: If other applications like a11y tools sends WM_*CHAR without
// scancode, we cannot compute virtual keycode. I.e., with such
// applications, we cannot generate proper KeyboardEvent.code value.
// We cannot compute the virtual key code from WM_CHAR message on WinXP
// if it's caused by an extended key.
if (!canComputeVirtualKeyCodeFromScanCode) {
if (!CanComputeVirtualKeyCodeFromScanCode()) {
break;
}
mVirtualKeyCode = mOriginalVirtualKeyCode =
@ -732,11 +749,9 @@ NativeKey::NativeKey(nsWindowBase* aWidget,
keyboardLayout->ConvertNativeKeyCodeToDOMKeyCode(mOriginalVirtualKeyCode);
mKeyNameIndex =
keyboardLayout->ConvertNativeKeyCodeToKeyNameIndex(mOriginalVirtualKeyCode);
// Even on WinXP or WinServer 2003, we should use extended flag for computing
// the DOM code value since it's really our internal code.
mCodeNameIndex =
KeyboardLayout::ConvertScanCodeToCodeNameIndex(
mIsExtended ? (0xE000 | mScanCode) : mScanCode, mOriginalVirtualKeyCode);
GetScanCodeWithExtendedFlag());
keyboardLayout->InitNativeKey(*this, mModKeyState);
@ -875,6 +890,18 @@ NativeKey::GetKeyLocation() const
}
}
bool
NativeKey::CanComputeVirtualKeyCodeFromScanCode() const
{
// Vista or later supports ScanCodeEx.
if (IsVistaOrLater()) {
return true;
}
// Otherwise, MapVirtualKeyEx() can compute virtual keycode only with
// non-extended key.
return !mIsExtended;
}
uint8_t
NativeKey::ComputeVirtualKeyCodeFromScanCode() const
{
@ -885,14 +912,24 @@ NativeKey::ComputeVirtualKeyCodeFromScanCode() const
uint8_t
NativeKey::ComputeVirtualKeyCodeFromScanCodeEx() const
{
// NOTE: WinXP doesn't support mapping scan code to virtual keycode of
// extended keys.
NS_ENSURE_TRUE(!mIsExtended || IsVistaOrLater(), 0);
if (NS_WARN_IF(!CanComputeVirtualKeyCodeFromScanCode())) {
return 0;
}
return static_cast<uint8_t>(
::MapVirtualKeyEx(GetScanCodeWithExtendedFlag(), MAPVK_VSC_TO_VK_EX,
mKeyboardLayout));
}
uint16_t
NativeKey::ComputeScanCodeExFromVirtualKeyCode(UINT aVirtualKeyCode) const
{
return static_cast<uint16_t>(
::MapVirtualKeyEx(aVirtualKeyCode,
IsVistaOrLater() ? MAPVK_VK_TO_VSC_EX :
MAPVK_VK_TO_VSC,
mKeyboardLayout));
}
char16_t
NativeKey::ComputeUnicharFromScanCode() const
{
@ -2629,8 +2666,7 @@ KeyboardLayout::ConvertNativeKeyCodeToKeyNameIndex(uint8_t aVirtualKey) const
// static
CodeNameIndex
KeyboardLayout::ConvertScanCodeToCodeNameIndex(UINT aScanCode,
UINT aVirtualKeyCode)
KeyboardLayout::ConvertScanCodeToCodeNameIndex(UINT aScanCode)
{
switch (aScanCode) {
@ -2641,49 +2677,6 @@ KeyboardLayout::ConvertScanCodeToCodeNameIndex(UINT aScanCode,
#undef NS_NATIVE_KEY_TO_DOM_CODE_NAME_INDEX
// Some special keys cuases 0xE000 of scan code. Then, we should compute
// the code value with virtual keycode.
case 0xE000:
switch (aVirtualKeyCode) {
case VK_BROWSER_BACK:
return CODE_NAME_INDEX_BrowserBack;
case VK_BROWSER_FAVORITES:
return CODE_NAME_INDEX_BrowserFavorites;
case VK_BROWSER_FORWARD:
return CODE_NAME_INDEX_BrowserForward;
case VK_BROWSER_HOME:
return CODE_NAME_INDEX_BrowserHome;
case VK_BROWSER_REFRESH:
return CODE_NAME_INDEX_BrowserRefresh;
case VK_BROWSER_SEARCH:
return CODE_NAME_INDEX_BrowserSearch;
case VK_BROWSER_STOP:
return CODE_NAME_INDEX_BrowserStop;
case VK_LAUNCH_APP1: // my computer
return CODE_NAME_INDEX_LaunchApp1;
case VK_LAUNCH_APP2: // calculator
return CODE_NAME_INDEX_LaunchApp2;
case VK_LAUNCH_MAIL:
return CODE_NAME_INDEX_LaunchMail;
case VK_LAUNCH_MEDIA_SELECT:
return CODE_NAME_INDEX_MediaSelect;
case VK_MEDIA_PLAY_PAUSE:
return CODE_NAME_INDEX_MediaPlayPause;
case VK_MEDIA_STOP:
return CODE_NAME_INDEX_MediaStop;
case VK_MEDIA_NEXT_TRACK:
return CODE_NAME_INDEX_MediaTrackNext;
case VK_MEDIA_PREV_TRACK:
return CODE_NAME_INDEX_MediaTrackPrevious;
case VK_VOLUME_MUTE:
return CODE_NAME_INDEX_VolumeMute;
case VK_VOLUME_DOWN:
return CODE_NAME_INDEX_VolumeDown;
case VK_VOLUME_UP:
return CODE_NAME_INDEX_VolumeUp;
default:
return CODE_NAME_INDEX_UNKNOWN;
}
default:
return CODE_NAME_INDEX_UNKNOWN;
}

View File

@ -382,6 +382,11 @@ private:
*/
bool GetFollowingCharMessage(MSG& aCharMsg) const;
/**
* Whether the key event can compute virtual keycode from the scancode value.
*/
bool CanComputeVirtualKeyCodeFromScanCode() const;
/**
* Wraps MapVirtualKeyEx() with MAPVK_VSC_TO_VK.
*/
@ -392,6 +397,11 @@ private:
*/
uint8_t ComputeVirtualKeyCodeFromScanCodeEx() const;
/**
* Wraps MapVirtualKeyEx() with MAPVK_VK_TO_VSC_EX or MAPVK_VK_TO_VSC.
*/
uint16_t ComputeScanCodeExFromVirtualKeyCode(UINT aVirtualKeyCode) const;
/**
* Wraps MapVirtualKeyEx() with MAPVK_VSC_TO_VK and MAPVK_VK_TO_CHAR.
*/
@ -565,13 +575,8 @@ public:
* ConvertScanCodeToCodeNameIndex() returns CodeNameIndex value for
* the given scan code. aScanCode can be over 0xE000 since this method
* doesn't use Windows API.
*
* NOTE: Some special keys always generate 0xE000 for the scan code but
* the virtual keycode indicates the key. In such case, this method
* computes CodeNameIndex from aVirtualKeyCode.
*/
static CodeNameIndex ConvertScanCodeToCodeNameIndex(UINT aScanCode,
UINT aVirtualKeyCode);
static CodeNameIndex ConvertScanCodeToCodeNameIndex(UINT aScanCode);
HKL GetLayout() const
{