Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit cab2635

Browse files
committedSep 21, 2012
Make the key enums as part of WebPage instance.
This way, we don't add anything into phantom object. http://code.google.com/p/phantomjs/issues/detail?id=492
·
2.1.11.7.0
1 parent e7c37d4 commit cab2635

File tree

5 files changed

+432
-35
lines changed

5 files changed

+432
-35
lines changed
 

‎src/modules/webpage.js

Lines changed: 422 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,428 @@ function decorateNewPage(opts, page) {
325325
// @see https://developer.mozilla.org/en/DOM/window.prompt
326326
definePageCallbackSetter(page, "onPrompt", "_getJsPromptCallback");
327327

328+
page.event = {};
329+
page.event.key = {
330+
'0': 48,
331+
'1': 49,
332+
'2': 50,
333+
'3': 51,
334+
'4': 52,
335+
'5': 53,
336+
'6': 54,
337+
'7': 55,
338+
'8': 56,
339+
'9': 57,
340+
'A': 65,
341+
'AE': 198,
342+
'Aacute': 193,
343+
'Acircumflex': 194,
344+
'AddFavorite': 16777408,
345+
'Adiaeresis': 196,
346+
'Agrave': 192,
347+
'Alt': 16777251,
348+
'AltGr': 16781571,
349+
'Ampersand': 38,
350+
'Any': 32,
351+
'Apostrophe': 39,
352+
'ApplicationLeft': 16777415,
353+
'ApplicationRight': 16777416,
354+
'Aring': 197,
355+
'AsciiCircum': 94,
356+
'AsciiTilde': 126,
357+
'Asterisk': 42,
358+
'At': 64,
359+
'Atilde': 195,
360+
'AudioCycleTrack': 16777478,
361+
'AudioForward': 16777474,
362+
'AudioRandomPlay': 16777476,
363+
'AudioRepeat': 16777475,
364+
'AudioRewind': 16777413,
365+
'Away': 16777464,
366+
'B': 66,
367+
'Back': 16777313,
368+
'BackForward': 16777414,
369+
'Backslash': 92,
370+
'Backspace': 16777219,
371+
'Backtab': 16777218,
372+
'Bar': 124,
373+
'BassBoost': 16777331,
374+
'BassDown': 16777333,
375+
'BassUp': 16777332,
376+
'Battery': 16777470,
377+
'Bluetooth': 16777471,
378+
'Book': 16777417,
379+
'BraceLeft': 123,
380+
'BraceRight': 125,
381+
'BracketLeft': 91,
382+
'BracketRight': 93,
383+
'BrightnessAdjust': 16777410,
384+
'C': 67,
385+
'CD': 16777418,
386+
'Calculator': 16777419,
387+
'Calendar': 16777444,
388+
'Call': 17825796,
389+
'Camera': 17825824,
390+
'CameraFocus': 17825825,
391+
'Cancel': 16908289,
392+
'CapsLock': 16777252,
393+
'Ccedilla': 199,
394+
'Clear': 16777227,
395+
'ClearGrab': 16777421,
396+
'Close': 16777422,
397+
'Codeinput': 16781623,
398+
'Colon': 58,
399+
'Comma': 44,
400+
'Community': 16777412,
401+
'Context1': 17825792,
402+
'Context2': 17825793,
403+
'Context3': 17825794,
404+
'Context4': 17825795,
405+
'ContrastAdjust': 16777485,
406+
'Control': 16777249,
407+
'Copy': 16777423,
408+
'Cut': 16777424,
409+
'D': 68,
410+
'DOS': 16777426,
411+
'Dead_Abovedot': 16781910,
412+
'Dead_Abovering': 16781912,
413+
'Dead_Acute': 16781905,
414+
'Dead_Belowdot': 16781920,
415+
'Dead_Breve': 16781909,
416+
'Dead_Caron': 16781914,
417+
'Dead_Cedilla': 16781915,
418+
'Dead_Circumflex': 16781906,
419+
'Dead_Diaeresis': 16781911,
420+
'Dead_Doubleacute': 16781913,
421+
'Dead_Grave': 16781904,
422+
'Dead_Hook': 16781921,
423+
'Dead_Horn': 16781922,
424+
'Dead_Iota': 16781917,
425+
'Dead_Macron': 16781908,
426+
'Dead_Ogonek': 16781916,
427+
'Dead_Semivoiced_Sound': 16781919,
428+
'Dead_Tilde': 16781907,
429+
'Dead_Voiced_Sound': 16781918,
430+
'Delete': 16777223,
431+
'Direction_L': 16777305,
432+
'Direction_R': 16777312,
433+
'Display': 16777425,
434+
'Documents': 16777427,
435+
'Dollar': 36,
436+
'Down': 16777237,
437+
'E': 69,
438+
'ETH': 208,
439+
'Eacute': 201,
440+
'Ecircumflex': 202,
441+
'Ediaeresis': 203,
442+
'Egrave': 200,
443+
'Eisu_Shift': 16781615,
444+
'Eisu_toggle': 16781616,
445+
'Eject': 16777401,
446+
'End': 16777233,
447+
'Enter': 16777221,
448+
'Equal': 61,
449+
'Escape': 16777216,
450+
'Excel': 16777428,
451+
'Exclam': 33,
452+
'Execute': 16908291,
453+
'Explorer': 16777429,
454+
'F': 70,
455+
'F1': 16777264,
456+
'F10': 16777273,
457+
'F11': 16777274,
458+
'F12': 16777275,
459+
'F13': 16777276,
460+
'F14': 16777277,
461+
'F15': 16777278,
462+
'F16': 16777279,
463+
'F17': 16777280,
464+
'F18': 16777281,
465+
'F19': 16777282,
466+
'F2': 16777265,
467+
'F20': 16777283,
468+
'F21': 16777284,
469+
'F22': 16777285,
470+
'F23': 16777286,
471+
'F24': 16777287,
472+
'F25': 16777288,
473+
'F26': 16777289,
474+
'F27': 16777290,
475+
'F28': 16777291,
476+
'F29': 16777292,
477+
'F3': 16777266,
478+
'F30': 16777293,
479+
'F31': 16777294,
480+
'F32': 16777295,
481+
'F33': 16777296,
482+
'F34': 16777297,
483+
'F35': 16777298,
484+
'F4': 16777267,
485+
'F5': 16777268,
486+
'F6': 16777269,
487+
'F7': 16777270,
488+
'F8': 16777271,
489+
'F9': 16777272,
490+
'Favorites': 16777361,
491+
'Finance': 16777411,
492+
'Flip': 17825798,
493+
'Forward': 16777314,
494+
'G': 71,
495+
'Game': 16777430,
496+
'Go': 16777431,
497+
'Greater': 62,
498+
'H': 72,
499+
'Hangul': 16781617,
500+
'Hangul_Banja': 16781625,
501+
'Hangul_End': 16781619,
502+
'Hangul_Hanja': 16781620,
503+
'Hangul_Jamo': 16781621,
504+
'Hangul_Jeonja': 16781624,
505+
'Hangul_PostHanja': 16781627,
506+
'Hangul_PreHanja': 16781626,
507+
'Hangul_Romaja': 16781622,
508+
'Hangul_Special': 16781631,
509+
'Hangul_Start': 16781618,
510+
'Hangup': 17825797,
511+
'Hankaku': 16781609,
512+
'Help': 16777304,
513+
'Henkan': 16781603,
514+
'Hibernate': 16777480,
515+
'Hiragana': 16781605,
516+
'Hiragana_Katakana': 16781607,
517+
'History': 16777407,
518+
'Home': 16777232,
519+
'HomePage': 16777360,
520+
'HotLinks': 16777409,
521+
'Hyper_L': 16777302,
522+
'Hyper_R': 16777303,
523+
'I': 73,
524+
'Iacute': 205,
525+
'Icircumflex': 206,
526+
'Idiaeresis': 207,
527+
'Igrave': 204,
528+
'Insert': 16777222,
529+
'J': 74,
530+
'K': 75,
531+
'Kana_Lock': 16781613,
532+
'Kana_Shift': 16781614,
533+
'Kanji': 16781601,
534+
'Katakana': 16781606,
535+
'KeyboardBrightnessDown': 16777398,
536+
'KeyboardBrightnessUp': 16777397,
537+
'KeyboardLightOnOff': 16777396,
538+
'L': 76,
539+
'LastNumberRedial': 17825801,
540+
'Launch0': 16777378,
541+
'Launch1': 16777379,
542+
'Launch2': 16777380,
543+
'Launch3': 16777381,
544+
'Launch4': 16777382,
545+
'Launch5': 16777383,
546+
'Launch6': 16777384,
547+
'Launch7': 16777385,
548+
'Launch8': 16777386,
549+
'Launch9': 16777387,
550+
'LaunchA': 16777388,
551+
'LaunchB': 16777389,
552+
'LaunchC': 16777390,
553+
'LaunchD': 16777391,
554+
'LaunchE': 16777392,
555+
'LaunchF': 16777393,
556+
'LaunchG': 16777486,
557+
'LaunchH': 16777487,
558+
'LaunchMail': 16777376,
559+
'LaunchMedia': 16777377,
560+
'Left': 16777234,
561+
'Less': 60,
562+
'LightBulb': 16777405,
563+
'LogOff': 16777433,
564+
'M': 77,
565+
'MailForward': 16777467,
566+
'Market': 16777434,
567+
'Massyo': 16781612,
568+
'MediaLast': 16842751,
569+
'MediaNext': 16777347,
570+
'MediaPause': 16777349,
571+
'MediaPlay': 16777344,
572+
'MediaPrevious': 16777346,
573+
'MediaRecord': 16777348,
574+
'MediaStop': 16777345,
575+
'MediaTogglePlayPause': 16777350,
576+
'Meeting': 16777435,
577+
'Memo': 16777404,
578+
'Menu': 16777301,
579+
'MenuKB': 16777436,
580+
'MenuPB': 16777437,
581+
'Messenger': 16777465,
582+
'Meta': 16777250,
583+
'Minus': 45,
584+
'Mode_switch': 16781694,
585+
'MonBrightnessDown': 16777395,
586+
'MonBrightnessUp': 16777394,
587+
'Muhenkan': 16781602,
588+
'Multi_key': 16781600,
589+
'MultipleCandidate': 16781629,
590+
'Music': 16777469,
591+
'MySites': 16777438,
592+
'N': 78,
593+
'News': 16777439,
594+
'No': 16842754,
595+
'Ntilde': 209,
596+
'NumLock': 16777253,
597+
'NumberSign': 35,
598+
'O': 79,
599+
'Oacute': 211,
600+
'Ocircumflex': 212,
601+
'Odiaeresis': 214,
602+
'OfficeHome': 16777440,
603+
'Ograve': 210,
604+
'Ooblique': 216,
605+
'OpenUrl': 16777364,
606+
'Option': 16777441,
607+
'Otilde': 213,
608+
'P': 80,
609+
'PageDown': 16777239,
610+
'PageUp': 16777238,
611+
'ParenLeft': 40,
612+
'ParenRight': 41,
613+
'Paste': 16777442,
614+
'Pause': 16777224,
615+
'Percent': 37,
616+
'Period': 46,
617+
'Phone': 16777443,
618+
'Pictures': 16777468,
619+
'Play': 16908293,
620+
'Plus': 43,
621+
'PowerDown': 16777483,
622+
'PowerOff': 16777399,
623+
'PreviousCandidate': 16781630,
624+
'Print': 16777225,
625+
'Printer': 16908290,
626+
'Q': 81,
627+
'Question': 63,
628+
'QuoteDbl': 34,
629+
'QuoteLeft': 96,
630+
'R': 82,
631+
'Refresh': 16777316,
632+
'Reload': 16777446,
633+
'Reply': 16777445,
634+
'Return': 16777220,
635+
'Right': 16777236,
636+
'Romaji': 16781604,
637+
'RotateWindows': 16777447,
638+
'RotationKB': 16777449,
639+
'RotationPB': 16777448,
640+
'S': 83,
641+
'Save': 16777450,
642+
'ScreenSaver': 16777402,
643+
'ScrollLock': 16777254,
644+
'Search': 16777362,
645+
'Select': 16842752,
646+
'Semicolon': 59,
647+
'Send': 16777451,
648+
'Shift': 16777248,
649+
'Shop': 16777406,
650+
'SingleCandidate': 16781628,
651+
'Slash': 47,
652+
'Sleep': 16908292,
653+
'Space': 32,
654+
'Spell': 16777452,
655+
'SplitScreen': 16777453,
656+
'Standby': 16777363,
657+
'Stop': 16777315,
658+
'Subtitle': 16777477,
659+
'Super_L': 16777299,
660+
'Super_R': 16777300,
661+
'Support': 16777454,
662+
'Suspend': 16777484,
663+
'SysReq': 16777226,
664+
'T': 84,
665+
'THORN': 222,
666+
'Tab': 16777217,
667+
'TaskPane': 16777455,
668+
'Terminal': 16777456,
669+
'Time': 16777479,
670+
'ToDoList': 16777420,
671+
'ToggleCallHangup': 17825799,
672+
'Tools': 16777457,
673+
'TopMenu': 16777482,
674+
'Touroku': 16781611,
675+
'Travel': 16777458,
676+
'TrebleDown': 16777335,
677+
'TrebleUp': 16777334,
678+
'U': 85,
679+
'UWB': 16777473,
680+
'Uacute': 218,
681+
'Ucircumflex': 219,
682+
'Udiaeresis': 220,
683+
'Ugrave': 217,
684+
'Underscore': 95,
685+
'Up': 16777235,
686+
'V': 86,
687+
'Video': 16777459,
688+
'View': 16777481,
689+
'VoiceDial': 17825800,
690+
'VolumeDown': 16777328,
691+
'VolumeMute': 16777329,
692+
'VolumeUp': 16777330,
693+
'W': 87,
694+
'WLAN': 16777472,
695+
'WWW': 16777403,
696+
'WakeUp': 16777400,
697+
'WebCam': 16777466,
698+
'Word': 16777460,
699+
'X': 88,
700+
'Xfer': 16777461,
701+
'Y': 89,
702+
'Yacute': 221,
703+
'Yes': 16842753,
704+
'Z': 90,
705+
'Zenkaku': 16781608,
706+
'Zenkaku_Hankaku': 16781610,
707+
'Zoom': 16908294,
708+
'ZoomIn': 16777462,
709+
'ZoomOut': 16777463,
710+
'acute': 180,
711+
'brokenbar': 166,
712+
'cedilla': 184,
713+
'cent': 162,
714+
'copyright': 169,
715+
'currency': 164,
716+
'degree': 176,
717+
'diaeresis': 168,
718+
'division': 247,
719+
'exclamdown': 161,
720+
'guillemotleft': 171,
721+
'guillemotright': 187,
722+
'hyphen': 173,
723+
'iTouch': 16777432,
724+
'macron': 175,
725+
'masculine': 186,
726+
'mu': 181,
727+
'multiply': 215,
728+
'nobreakspace': 160,
729+
'notsign': 172,
730+
'onehalf': 189,
731+
'onequarter': 188,
732+
'onesuperior': 185,
733+
'ordfeminine': 170,
734+
'paragraph': 182,
735+
'periodcentered': 183,
736+
'plusminus': 177,
737+
'questiondown': 191,
738+
'registered': 174,
739+
'section': 167,
740+
'ssharp': 223,
741+
'sterling': 163,
742+
'threequarters': 190,
743+
'threesuperior': 179,
744+
'twosuperior': 178,
745+
'unknown': 33554431,
746+
'ydiaeresis': 255,
747+
'yen': 165
748+
};
749+
328750
return page;
329751
}
330752

‎src/phantom.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#include <QDir>
3535
#include <QFileInfo>
3636
#include <QFile>
37-
// note: QMetaObject apparently does not define QMetaEnum...
38-
#include <qmetaobject.h>
3937
#include <QWebPage>
4038

4139
#include "consts.h"
@@ -65,16 +63,6 @@ Phantom::Phantom(QObject *parent)
6563
m_config.init(&args);
6664
// Apply debug configuration as early as possible
6765
Utils::printDebugMessages = m_config.printDebugMessages();
68-
69-
// initialize key map
70-
QMetaEnum keys = staticQtMetaObject.enumerator( staticQtMetaObject.indexOfEnumerator("Key") );
71-
for(int i = 0; i < keys.keyCount(); ++i) {
72-
QString name = keys.key(i);
73-
if (name.startsWith("Key_")) {
74-
name.remove(0, 4);
75-
}
76-
m_keyMap[name] = keys.value(i);
77-
}
7866
}
7967

8068
void Phantom::init()
@@ -259,11 +247,6 @@ bool Phantom::printDebugMessages() const
259247
return m_config.printDebugMessages();
260248
}
261249

262-
QVariantMap Phantom::keys() const
263-
{
264-
return m_keyMap;
265-
}
266-
267250
bool Phantom::areCookiesEnabled() const
268251
{
269252
return CookieJar::instance()->isEnabled();
@@ -440,7 +423,6 @@ void Phantom::initCompletions()
440423
addCompletion("outputEncoding");
441424
addCompletion("scriptName");
442425
addCompletion("version");
443-
addCompletion("keys");
444426
addCompletion("cookiesEnabled");
445427
addCompletion("cookies");
446428
// functions

‎src/phantom.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class Phantom: public REPLCompletable
5454
Q_PROPERTY(QString scriptName READ scriptName)
5555
Q_PROPERTY(QVariantMap version READ version)
5656
Q_PROPERTY(QObject *page READ page)
57-
Q_PROPERTY(QVariantMap keys READ keys)
5857
Q_PROPERTY(bool cookiesEnabled READ areCookiesEnabled WRITE setCookiesEnabled)
5958
Q_PROPERTY(QVariantList cookies READ cookies WRITE setCookies)
6059

@@ -97,8 +96,6 @@ class Phantom: public REPLCompletable
9796

9897
bool printDebugMessages() const;
9998

100-
QVariantMap keys() const;
101-
10299
bool areCookiesEnabled() const;
103100
void setCookiesEnabled(const bool value);
104101

@@ -188,7 +185,6 @@ private slots:
188185
QList<QPointer<WebPage> > m_pages;
189186
QList<QPointer<WebServer> > m_servers;
190187
Config m_config;
191-
QVariantMap m_keyMap;
192188

193189
friend class CustomPage;
194190
};

‎test/phantom-spec.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ describe("phantom global object", function() {
6767
expect(typeof phantom.exit).toEqual("function");
6868
});
6969

70-
it("should have 'keys' property", function() {
71-
expect(phantom.hasOwnProperty('keys')).toBeTruthy();
72-
});
73-
7470
it("should have 'cookiesEnabled' property, and should be 'true' by default", function() {
7571
expect(phantom.hasOwnProperty('cookiesEnabled')).toBeTruthy();
7672
expect(phantom.cookiesEnabled).toBeTruthy();

‎test/webpage-spec.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ describe("WebPage object", function() {
142142
expect(page.zoomFactor).toEqual(1.0);
143143
});
144144

145+
expectHasProperty(page, 'event');
145146
expectHasProperty(page, 'cookies');
146147

147148
checkViewportSize(page, {height:300,width:400});
@@ -181,7 +182,7 @@ describe("WebPage object", function() {
181182
window.loggedEvent.keydown = event;
182183
}, false);
183184
});
184-
page.sendEvent('keydown', phantom.keys.A);
185+
page.sendEvent('keydown', page.event.key.A);
185186
});
186187

187188
waits(50);
@@ -190,7 +191,7 @@ describe("WebPage object", function() {
190191
var event = page.evaluate(function() {
191192
return window.loggedEvent.keydown;
192193
});
193-
expect(event.which).toEqual(phantom.keys.A);
194+
expect(event.which).toEqual(page.event.key.A);
194195
});
195196
});
196197

@@ -202,7 +203,7 @@ describe("WebPage object", function() {
202203
window.loggedEvent.keyup = event;
203204
}, false);
204205
});
205-
page.sendEvent('keyup', phantom.keys.A);
206+
page.sendEvent('keyup', page.event.key.A);
206207
});
207208

208209
waits(50);
@@ -211,7 +212,7 @@ describe("WebPage object", function() {
211212
var event = page.evaluate(function() {
212213
return window.loggedEvent.keyup;
213214
});
214-
expect(event.which).toEqual(phantom.keys.A);
215+
expect(event.which).toEqual(page.event.key.A);
215216
});
216217
});
217218

@@ -223,7 +224,7 @@ describe("WebPage object", function() {
223224
window.loggedEvent.keypress = event;
224225
}, false);
225226
});
226-
page.sendEvent('keypress', phantom.keys.A);
227+
page.sendEvent('keypress', page.event.key.A);
227228
});
228229

229230
waits(50);
@@ -232,7 +233,7 @@ describe("WebPage object", function() {
232233
var event = page.evaluate(function() {
233234
return window.loggedEvent.keypress;
234235
});
235-
expect(event.which).toEqual(phantom.keys.A);
236+
expect(event.which).toEqual(page.event.key.A);
236237
});
237238
});
238239

@@ -247,11 +248,11 @@ describe("WebPage object", function() {
247248
return document.querySelector('input').value;
248249
});
249250
};
250-
page.sendEvent('keypress', phantom.keys.A);
251+
page.sendEvent('keypress', page.event.key.A);
251252
expect(getText()).toEqual("A");
252-
page.sendEvent('keypress', phantom.keys.B);
253+
page.sendEvent('keypress', page.event.key.B);
253254
expect(getText()).toEqual("AB");
254-
page.sendEvent('keypress', phantom.keys.Backspace);
255+
page.sendEvent('keypress', page.event.key.Backspace);
255256
expect(getText()).toEqual("A");
256257
});
257258
});

0 commit comments

Comments
 (0)
This repository has been archived.