• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1.  Redistributions of source code must retain the above copyright
9 *     notice, this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright
11 *     notice, this list of conditions and the following disclaimer in the
12 *     documentation and/or other materials provided with the distribution.
13 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 *     its contributors may be used to endorse or promote products derived
15 *     from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#import <WebKit/WebViewFactory.h>
30
31#import <WebKit/WebFrameInternal.h>
32#import <WebKit/WebViewInternal.h>
33#import <WebKit/WebHTMLViewInternal.h>
34#import <WebKit/WebLocalizableStrings.h>
35#import <WebKit/WebNSUserDefaultsExtras.h>
36#import <WebKit/WebNSObjectExtras.h>
37#import <WebKit/WebNSViewExtras.h>
38#import <WebKit/WebPluginDatabase.h>
39#import <WebKitSystemInterface.h>
40#import <wtf/Assertions.h>
41
42@interface NSMenu (WebViewFactoryAdditions)
43- (NSMenuItem *)addItemWithTitle:(NSString *)title action:(SEL)action tag:(int)tag;
44@end
45
46@implementation NSMenu (WebViewFactoryAdditions)
47
48- (NSMenuItem *)addItemWithTitle:(NSString *)title action:(SEL)action tag:(int)tag
49{
50    NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:title action:action keyEquivalent:@""] autorelease];
51    [item setTag:tag];
52    [self addItem:item];
53    return item;
54}
55
56@end
57
58@implementation WebViewFactory
59
60+ (void)createSharedFactory
61{
62    if (![self sharedFactory]) {
63        [[[self alloc] init] release];
64    }
65    ASSERT([[self sharedFactory] isKindOfClass:self]);
66}
67
68- (NSArray *)pluginsInfo
69{
70    return [[WebPluginDatabase sharedDatabase] plugins];
71}
72
73- (void)refreshPlugins
74{
75    [[WebPluginDatabase sharedDatabase] refresh];
76}
77
78- (NSString *)inputElementAltText
79{
80    return UI_STRING_KEY("Submit", "Submit (input element)", "alt text for <input> elements with no alt, title, or value");
81}
82
83- (NSString *)resetButtonDefaultLabel
84{
85    return UI_STRING("Reset", "default label for Reset buttons in forms on web pages");
86}
87
88- (NSString *)searchableIndexIntroduction
89{
90    return UI_STRING("This is a searchable index. Enter search keywords: ",
91        "text that appears at the start of nearly-obsolete web pages in the form of a 'searchable index'");
92}
93
94- (NSString *)submitButtonDefaultLabel
95{
96    return UI_STRING("Submit", "default label for Submit buttons in forms on web pages");
97}
98
99- (NSString *)fileButtonChooseFileLabel
100{
101    return UI_STRING("Choose File", "title for file button used in HTML forms");
102}
103
104- (NSString *)fileButtonNoFileSelectedLabel
105{
106    return UI_STRING("no file selected", "text to display in file button used in HTML forms when no file is selected");
107}
108
109- (NSString *)copyImageUnknownFileLabel
110{
111    return UI_STRING("unknown", "Unknown filename");
112}
113
114- (NSString *)searchMenuNoRecentSearchesText
115{
116    return UI_STRING("No recent searches", "Label for only item in menu that appears when clicking on the search field image, when no searches have been performed");
117}
118
119- (NSString *)searchMenuRecentSearchesText
120{
121    return UI_STRING("Recent Searches", "label for first item in the menu that appears when clicking on the search field image, used as embedded menu title");
122}
123
124- (NSString *)searchMenuClearRecentSearchesText
125{
126    return UI_STRING("Clear Recent Searches", "menu item in Recent Searches menu that empties menu's contents");
127}
128
129- (NSString *)defaultLanguageCode
130{
131    return [NSUserDefaults _webkit_preferredLanguageCode];
132}
133
134- (NSString *)contextMenuItemTagOpenLinkInNewWindow
135{
136    return UI_STRING("Open Link in New Window", "Open in New Window context menu item");
137}
138
139- (NSString *)contextMenuItemTagDownloadLinkToDisk
140{
141    return UI_STRING("Download Linked File", "Download Linked File context menu item");
142}
143
144- (NSString *)contextMenuItemTagCopyLinkToClipboard
145{
146    return UI_STRING("Copy Link", "Copy Link context menu item");
147}
148
149- (NSString *)contextMenuItemTagOpenImageInNewWindow
150{
151    return UI_STRING("Open Image in New Window", "Open Image in New Window context menu item");
152}
153
154- (NSString *)contextMenuItemTagDownloadImageToDisk
155{
156    return UI_STRING("Download Image", "Download Image context menu item");
157}
158
159- (NSString *)contextMenuItemTagCopyImageToClipboard
160{
161    return UI_STRING("Copy Image", "Copy Image context menu item");
162}
163
164- (NSString *)contextMenuItemTagOpenFrameInNewWindow
165{
166    return UI_STRING("Open Frame in New Window", "Open Frame in New Window context menu item");
167}
168
169- (NSString *)contextMenuItemTagCopy
170{
171    return UI_STRING("Copy", "Copy context menu item");
172}
173
174- (NSString *)contextMenuItemTagGoBack
175{
176    return UI_STRING("Back", "Back context menu item");
177}
178
179- (NSString *)contextMenuItemTagGoForward
180{
181    return UI_STRING("Forward", "Forward context menu item");
182}
183
184- (NSString *)contextMenuItemTagStop
185{
186    return UI_STRING("Stop", "Stop context menu item");
187}
188
189- (NSString *)contextMenuItemTagReload
190{
191    return UI_STRING("Reload", "Reload context menu item");
192}
193
194- (NSString *)contextMenuItemTagCut
195{
196    return UI_STRING("Cut", "Cut context menu item");
197}
198
199- (NSString *)contextMenuItemTagPaste
200{
201    return UI_STRING("Paste", "Paste context menu item");
202}
203
204- (NSString *)contextMenuItemTagNoGuessesFound
205{
206    return UI_STRING("No Guesses Found", "No Guesses Found context menu item");
207}
208
209- (NSString *)contextMenuItemTagIgnoreSpelling
210{
211    return UI_STRING("Ignore Spelling", "Ignore Spelling context menu item");
212}
213
214- (NSString *)contextMenuItemTagLearnSpelling
215{
216    return UI_STRING("Learn Spelling", "Learn Spelling context menu item");
217}
218
219- (NSString *)contextMenuItemTagSearchInSpotlight
220{
221    return UI_STRING("Search in Spotlight", "Search in Spotlight context menu item");
222}
223
224- (NSString *)contextMenuItemTagSearchWeb
225{
226    return UI_STRING("Search in Google", "Search in Google context menu item");
227}
228
229- (NSString *)contextMenuItemTagLookUpInDictionary
230{
231    return UI_STRING("Look Up in Dictionary", "Look Up in Dictionary context menu item");
232}
233
234- (NSString *)contextMenuItemTagOpenLink
235{
236    return UI_STRING("Open Link", "Open Link context menu item");
237}
238
239- (NSString *)contextMenuItemTagIgnoreGrammar
240{
241    return UI_STRING("Ignore Grammar", "Ignore Grammar context menu item");
242}
243
244- (NSString *)contextMenuItemTagSpellingMenu
245{
246#ifndef BUILDING_ON_TIGER
247    return UI_STRING("Spelling and Grammar", "Spelling and Grammar context sub-menu item");
248#else
249    return UI_STRING("Spelling", "Spelling context sub-menu item");
250#endif
251}
252
253- (NSString *)contextMenuItemTagShowSpellingPanel:(bool)show
254{
255#ifndef BUILDING_ON_TIGER
256    if (show)
257        return UI_STRING("Show Spelling and Grammar", "menu item title");
258    return UI_STRING("Hide Spelling and Grammar", "menu item title");
259#else
260    return UI_STRING("Spelling...", "menu item title");
261#endif
262}
263
264- (NSString *)contextMenuItemTagCheckSpelling
265{
266#ifndef BUILDING_ON_TIGER
267    return UI_STRING("Check Document Now", "Check spelling context menu item");
268#else
269    return UI_STRING("Check Spelling", "Check spelling context menu item");
270#endif
271}
272
273- (NSString *)contextMenuItemTagCheckSpellingWhileTyping
274{
275#ifndef BUILDING_ON_TIGER
276    return UI_STRING("Check Spelling While Typing", "Check spelling while typing context menu item");
277#else
278    return UI_STRING("Check Spelling as You Type", "Check spelling while typing context menu item");
279#endif
280}
281
282- (NSString *)contextMenuItemTagCheckGrammarWithSpelling
283{
284    return UI_STRING("Check Grammar With Spelling", "Check grammar with spelling context menu item");
285}
286
287- (NSString *)contextMenuItemTagFontMenu
288{
289    return UI_STRING("Font", "Font context sub-menu item");
290}
291
292- (NSString *)contextMenuItemTagShowFonts
293{
294    return UI_STRING("Show Fonts", "Show fonts context menu item");
295}
296
297- (NSString *)contextMenuItemTagBold
298{
299    return UI_STRING("Bold", "Bold context menu item");
300}
301
302- (NSString *)contextMenuItemTagItalic
303{
304    return UI_STRING("Italic", "Italic context menu item");
305}
306
307- (NSString *)contextMenuItemTagUnderline
308{
309    return UI_STRING("Underline", "Underline context menu item");
310}
311
312- (NSString *)contextMenuItemTagOutline
313{
314    return UI_STRING("Outline", "Outline context menu item");
315}
316
317- (NSString *)contextMenuItemTagStyles
318{
319    return UI_STRING("Styles...", "Styles context menu item");
320}
321
322- (NSString *)contextMenuItemTagShowColors
323{
324    return UI_STRING("Show Colors", "Show colors context menu item");
325}
326
327- (NSString *)contextMenuItemTagSpeechMenu
328{
329    return UI_STRING("Speech", "Speech context sub-menu item");
330}
331
332- (NSString *)contextMenuItemTagStartSpeaking
333{
334    return UI_STRING("Start Speaking", "Start speaking context menu item");
335}
336
337- (NSString *)contextMenuItemTagStopSpeaking
338{
339    return UI_STRING("Stop Speaking", "Stop speaking context menu item");
340}
341
342- (NSString *)contextMenuItemTagWritingDirectionMenu
343{
344#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
345    return UI_STRING("Paragraph Direction", "Paragraph direction context sub-menu item");
346#else
347    return UI_STRING("Writing Direction", "Writing direction context sub-menu item");
348#endif
349}
350
351- (NSString *)contextMenuItemTagTextDirectionMenu
352{
353    return UI_STRING("Selection Direction", "Selection direction context sub-menu item");
354}
355
356- (NSString *)contextMenuItemTagDefaultDirection
357{
358    return UI_STRING("Default", "Default writing direction context menu item");
359}
360
361- (NSString *)contextMenuItemTagLeftToRight
362{
363    return UI_STRING("Left to Right", "Left to Right context menu item");
364}
365
366- (NSString *)contextMenuItemTagRightToLeft
367{
368    return UI_STRING("Right to Left", "Right to Left context menu item");
369}
370
371- (NSString *)contextMenuItemTagCorrectSpellingAutomatically
372{
373    return UI_STRING("Correct Spelling Automatically", "Correct Spelling Automatically context menu item");
374}
375
376- (NSString *)contextMenuItemTagSubstitutionsMenu
377{
378    return UI_STRING("Substitutions", "Substitutions context sub-menu item");
379}
380
381- (NSString *)contextMenuItemTagShowSubstitutions:(bool)show
382{
383    if (show)
384        return UI_STRING("Show Substitutions", "menu item title");
385    return UI_STRING("Hide Substitutions", "menu item title");
386}
387
388- (NSString *)contextMenuItemTagSmartCopyPaste
389{
390    return UI_STRING("Smart Copy/Paste", "Smart Copy/Paste context menu item");
391}
392
393- (NSString *)contextMenuItemTagSmartQuotes
394{
395    return UI_STRING("Smart Quotes", "Smart Quotes context menu item");
396}
397
398- (NSString *)contextMenuItemTagSmartDashes
399{
400    return UI_STRING("Smart Dashes", "Smart Dashes context menu item");
401}
402
403- (NSString *)contextMenuItemTagSmartLinks
404{
405    return UI_STRING("Smart Links", "Smart Links context menu item");
406}
407
408- (NSString *)contextMenuItemTagTextReplacement
409{
410    return UI_STRING("Text Replacement", "Text Replacement context menu item");
411}
412
413- (NSString *)contextMenuItemTagTransformationsMenu
414{
415    return UI_STRING("Transformations", "Transformations context sub-menu item");
416}
417
418- (NSString *)contextMenuItemTagMakeUpperCase
419{
420    return UI_STRING("Make Upper Case", "Make Upper Case context menu item");
421}
422
423- (NSString *)contextMenuItemTagMakeLowerCase
424{
425    return UI_STRING("Make Lower Case", "Make Lower Case context menu item");
426}
427
428- (NSString *)contextMenuItemTagCapitalize
429{
430    return UI_STRING("Capitalize", "Capitalize context menu item");
431}
432
433- (NSString *)contextMenuItemTagChangeBack:(NSString *)replacedString
434{
435    static NSString *formatString = nil;
436#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
437    static bool lookedUpString = false;
438    if (!lookedUpString) {
439        formatString = [[[NSBundle bundleForClass:[NSSpellChecker class]] localizedStringForKey:@"Change Back to \\U201C%@\\U201D" value:nil table:@"MenuCommands"] retain];
440        lookedUpString = true;
441    }
442#endif
443    return formatString ? [NSString stringWithFormat:formatString, replacedString] : replacedString;
444}
445
446- (NSString *)contextMenuItemTagInspectElement
447{
448    return UI_STRING("Inspect Element", "Inspect Element context menu item");
449}
450
451- (BOOL)objectIsTextMarker:(id)object
452{
453    return object != nil && CFGetTypeID(object) == WKGetAXTextMarkerTypeID();
454}
455
456- (BOOL)objectIsTextMarkerRange:(id)object
457{
458    return object != nil && CFGetTypeID(object) == WKGetAXTextMarkerRangeTypeID();
459}
460
461- (WebCoreTextMarker *)textMarkerWithBytes:(const void *)bytes length:(size_t)length
462{
463    return WebCFAutorelease(WKCreateAXTextMarker(bytes, length));
464}
465
466- (BOOL)getBytes:(void *)bytes fromTextMarker:(WebCoreTextMarker *)textMarker length:(size_t)length
467{
468    return WKGetBytesFromAXTextMarker(textMarker, bytes, length);
469}
470
471- (WebCoreTextMarkerRange *)textMarkerRangeWithStart:(WebCoreTextMarker *)start end:(WebCoreTextMarker *)end
472{
473    ASSERT(start != nil);
474    ASSERT(end != nil);
475    ASSERT(CFGetTypeID(start) == WKGetAXTextMarkerTypeID());
476    ASSERT(CFGetTypeID(end) == WKGetAXTextMarkerTypeID());
477    return WebCFAutorelease(WKCreateAXTextMarkerRange(start, end));
478}
479
480- (WebCoreTextMarker *)startOfTextMarkerRange:(WebCoreTextMarkerRange *)range
481{
482    ASSERT(range != nil);
483    ASSERT(CFGetTypeID(range) == WKGetAXTextMarkerRangeTypeID());
484    return WebCFAutorelease(WKCopyAXTextMarkerRangeStart(range));
485}
486
487- (WebCoreTextMarker *)endOfTextMarkerRange:(WebCoreTextMarkerRange *)range
488{
489    ASSERT(range != nil);
490    ASSERT(CFGetTypeID(range) == WKGetAXTextMarkerRangeTypeID());
491    return WebCFAutorelease(WKCopyAXTextMarkerRangeEnd(range));
492}
493
494- (void)accessibilityHandleFocusChanged
495{
496    WKAccessibilityHandleFocusChanged();
497}
498
499- (AXUIElementRef)AXUIElementForElement:(id)element
500{
501    return WKCreateAXUIElementRef(element);
502}
503
504- (CGRect)accessibilityConvertScreenRect:(CGRect)bounds
505{
506    NSArray *screens = [NSScreen screens];
507    if ([screens count]) {
508        CGFloat screenHeight = NSHeight([[screens objectAtIndex:0] frame]);
509        bounds.origin.y = (screenHeight - (bounds.origin.y + bounds.size.height));
510    } else
511        bounds = CGRectZero;
512
513    return bounds;
514}
515
516- (void)unregisterUniqueIdForUIElement:(id)element
517{
518    WKUnregisterUniqueIdForElement(element);
519}
520
521- (NSString *)AXWebAreaText
522{
523    return UI_STRING("HTML content", "accessibility role description for web area");
524}
525
526- (NSString *)AXLinkText
527{
528    return UI_STRING("link", "accessibility role description for link");
529}
530
531- (NSString *)AXListMarkerText
532{
533    return UI_STRING("list marker", "accessibility role description for list marker");
534}
535
536- (NSString *)AXImageMapText
537{
538    return UI_STRING("image map", "accessibility role description for image map");
539}
540
541- (NSString *)AXHeadingText
542{
543    return UI_STRING("heading", "accessibility role description for headings");
544}
545
546- (NSString *)AXDefinitionListTermText
547{
548    return UI_STRING("term", "term word of a definition");
549}
550
551- (NSString *)AXDefinitionListDefinitionText
552{
553    return UI_STRING("definition", "definition phrase");
554}
555
556- (NSString *)AXButtonActionVerb
557{
558    return UI_STRING("press", "Verb stating the action that will occur when a button is pressed, as used by accessibility");
559}
560
561- (NSString *)AXRadioButtonActionVerb
562{
563    return UI_STRING("select", "Verb stating the action that will occur when a radio button is clicked, as used by accessibility");
564}
565
566- (NSString *)AXTextFieldActionVerb
567{
568    return UI_STRING("activate", "Verb stating the action that will occur when a text field is selected, as used by accessibility");
569}
570
571- (NSString *)AXCheckedCheckBoxActionVerb
572{
573    return UI_STRING("uncheck", "Verb stating the action that will occur when a checked checkbox is clicked, as used by accessibility");
574}
575
576- (NSString *)AXUncheckedCheckBoxActionVerb
577{
578    return UI_STRING("check", "Verb stating the action that will occur when an unchecked checkbox is clicked, as used by accessibility");
579}
580
581- (NSString *)AXLinkActionVerb
582{
583    return UI_STRING("jump", "Verb stating the action that will occur when a link is clicked, as used by accessibility");
584}
585
586- (NSString *)multipleFileUploadTextForNumberOfFiles:(unsigned)numberOfFiles
587{
588    return [NSString stringWithFormat:UI_STRING("%d files", "Label to describe the number of files selected in a file upload control that allows multiple files"), numberOfFiles];
589}
590
591- (NSString *)unknownFileSizeText
592{
593    return UI_STRING("Unknown", "Unknown filesize FTP directory listing item");
594}
595
596- (NSString*)imageTitleForFilename:(NSString*)filename width:(int)width height:(int)height
597{
598    return [NSString stringWithFormat:UI_STRING("%@ %d×%d pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filename, width, height];
599}
600
601- (NSString*)mediaElementLoadingStateText
602{
603    return UI_STRING("Loading...", "Media controller status message when the media is loading");
604}
605
606- (NSString*)mediaElementLiveBroadcastStateText
607{
608    return UI_STRING("Live Broadcast", "Media controller status message when watching a live broadcast");
609}
610
611@end
612