Debian Codegraph @

closure-library/closure/goog/editor/browserfeature.js

raw
1 // Copyright 2005 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Trogedit constants for browser features and quirks that should
17 * be used by the rich text editor.
18 */
19
20 goog.provide('goog.editor.BrowserFeature');
21
22 goog.require('goog.editor.defines');
23 goog.require('goog.labs.userAgent.browser');
24 goog.require('goog.userAgent');
25 goog.require('goog.userAgent.product');
26 goog.require('goog.userAgent.product.isVersion');
27
28
29 /**
30 * Maps browser quirks to boolean values, detailing what the current
31 * browser supports.
32 * @const
33 */
34 goog.editor.BrowserFeature = {
35 // Whether this browser uses the IE TextRange object.
36 HAS_IE_RANGES: goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(9),
37
38 // Whether this browser uses the W3C standard Range object.
39 // Assumes IE higher versions will be compliance with W3C standard.
40 HAS_W3C_RANGES: goog.userAgent.GECKO || goog.userAgent.WEBKIT ||
41 goog.userAgent.OPERA || goog.userAgent.EDGE ||
42 (goog.userAgent.IE && goog.userAgent.isDocumentModeOrHigher(9)),
43
44 // Has the contentEditable attribute, which makes nodes editable.
45 //
46 // NOTE(nicksantos): FF3 has contentEditable, but there are 3 major reasons
47 // why we don't use it:
48 // 1) In FF3, we listen for key events on the document, and we'd have to
49 // filter them properly. See TR_Browser.USE_DOCUMENT_FOR_KEY_EVENTS.
50 // 2) In FF3, we listen for focus/blur events on the document, which
51 // simply doesn't make sense in contentEditable. focus/blur
52 // on contentEditable elements still has some quirks, which we're
53 // talking to Firefox-team about.
54 // 3) We currently use Mutation events in FF3 to detect changes,
55 // and these are dispatched on the document only.
56 // If we ever hope to support FF3/contentEditable, all 3 of these issues
57 // will need answers. Most just involve refactoring at our end.
58 HAS_CONTENT_EDITABLE: goog.userAgent.IE || goog.userAgent.WEBKIT ||
59 goog.userAgent.OPERA || goog.userAgent.EDGE ||
60 (goog.editor.defines.USE_CONTENTEDITABLE_IN_FIREFOX_3 &&
61 goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9')),
62
63 // Whether to use mutation event types to detect changes
64 // in the field contents.
65 USE_MUTATION_EVENTS: goog.userAgent.GECKO,
66
67 // Whether the browser has a functional DOMSubtreeModified event.
68 // TODO(user): Enable for all FF3 once we're confident this event fires
69 // reliably. Currently it's only enabled if using contentEditable in FF as
70 // we have no other choice in that case but to use this event.
71 HAS_DOM_SUBTREE_MODIFIED_EVENT: goog.userAgent.WEBKIT ||
72 (goog.editor.defines.USE_CONTENTEDITABLE_IN_FIREFOX_3 &&
73 goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9')),
74
75 // Whether nodes can be copied from one document to another
76 HAS_DOCUMENT_INDEPENDENT_NODES: goog.userAgent.GECKO,
77
78 // Whether the cursor goes before or inside the first block element on
79 // focus, e.g., <body><p>foo</p></body>. FF will put the cursor before the
80 // paragraph on focus, which is wrong.
81 PUTS_CURSOR_BEFORE_FIRST_BLOCK_ELEMENT_ON_FOCUS: goog.userAgent.GECKO,
82
83 // Whether the selection of one frame is cleared when another frame
84 // is focused.
85 CLEARS_SELECTION_WHEN_FOCUS_LEAVES:
86 goog.userAgent.IE || goog.userAgent.WEBKIT || goog.userAgent.OPERA,
87
88 // Whether "unselectable" is supported as an element style.
89 HAS_UNSELECTABLE_STYLE: goog.userAgent.GECKO || goog.userAgent.WEBKIT,
90
91 // Whether this browser's "FormatBlock" command does not suck.
92 FORMAT_BLOCK_WORKS_FOR_BLOCKQUOTES:
93 goog.userAgent.GECKO || goog.userAgent.WEBKIT || goog.userAgent.OPERA,
94
95 // Whether this browser's "FormatBlock" command may create multiple
96 // blockquotes.
97 CREATES_MULTIPLE_BLOCKQUOTES:
98 (goog.userAgent.WEBKIT && !goog.userAgent.isVersionOrHigher('534.16')) ||
99 goog.userAgent.OPERA,
100
101 // Whether this browser's "FormatBlock" command will wrap blockquotes
102 // inside of divs, instead of replacing divs with blockquotes.
103 WRAPS_BLOCKQUOTE_IN_DIVS: goog.userAgent.OPERA,
104
105 // Whether the readystatechange event is more reliable than load.
106 PREFERS_READY_STATE_CHANGE_EVENT: goog.userAgent.IE,
107
108 // Whether hitting the tab key will fire a keypress event.
109 // see http://www.quirksmode.org/js/keys.html
110 // TODO(user): This is fixed in IE8 and higher.
111 TAB_FIRES_KEYPRESS: !goog.userAgent.IE,
112
113 // Has a standards mode quirk where width=100% doesn't do the right thing,
114 // but width=99% does.
115 // TODO(user|user): This should be fixable by less hacky means
116 NEEDS_99_WIDTH_IN_STANDARDS_MODE: goog.userAgent.IE,
117
118 // Whether keyboard events only reliably fire on the document.
119 // On Gecko without contentEditable, keyboard events only fire reliably on the
120 // document element. With contentEditable, the field itself is focusable,
121 // which means that it will fire key events. This does not apply if
122 // application is using ContentEditableField or otherwise overriding Field
123 // not to use an iframe.
124 USE_DOCUMENT_FOR_KEY_EVENTS: goog.userAgent.GECKO &&
125 !goog.editor.defines.USE_CONTENTEDITABLE_IN_FIREFOX_3,
126
127 // Whether this browser shows non-standard attributes in innerHTML.
128 SHOWS_CUSTOM_ATTRS_IN_INNER_HTML: goog.userAgent.IE,
129
130 // Whether this browser shrinks empty nodes away to nothing.
131 // (If so, we need to insert some space characters into nodes that
132 // shouldn't be collapsed)
133 COLLAPSES_EMPTY_NODES:
134 goog.userAgent.GECKO || goog.userAgent.WEBKIT || goog.userAgent.OPERA,
135
136 // Whether we must convert <strong> and <em> tags to <b>, <i>.
137 CONVERT_TO_B_AND_I_TAGS: goog.userAgent.GECKO || goog.userAgent.OPERA,
138
139 // Whether this browser likes to tab through images in contentEditable mode,
140 // and we like to disable this feature.
141 TABS_THROUGH_IMAGES: goog.userAgent.IE,
142
143 // Whether this browser unescapes urls when you extract it from the href tag.
144 UNESCAPES_URLS_WITHOUT_ASKING:
145 goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('7.0'),
146
147 // Whether this browser supports execCommand("styleWithCSS") to toggle between
148 // inserting html tags or inline styling for things like bold, italic, etc.
149 HAS_STYLE_WITH_CSS:
150 goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.8') ||
151 goog.userAgent.WEBKIT || goog.userAgent.OPERA,
152
153 // Whether clicking on an editable link will take you to that site.
154 FOLLOWS_EDITABLE_LINKS: goog.userAgent.WEBKIT ||
155 goog.userAgent.IE && goog.userAgent.isVersionOrHigher('9'),
156
157 // Whether this browser has document.activeElement available.
158 HAS_ACTIVE_ELEMENT: goog.userAgent.IE || goog.userAgent.EDGE ||
159 goog.userAgent.OPERA ||
160 goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9'),
161
162 // Whether this browser supports the setCapture method on DOM elements.
163 HAS_SET_CAPTURE: goog.userAgent.IE,
164
165 // Whether this browser can't set background color when the selection
166 // is collapsed.
167 EATS_EMPTY_BACKGROUND_COLOR: goog.userAgent.GECKO ||
168 goog.userAgent.WEBKIT && !goog.userAgent.isVersionOrHigher('527'),
169
170 // Whether this browser supports the "focusin" or "DOMFocusIn" event
171 // consistently.
172 // NOTE(nicksantos): FF supports DOMFocusIn, but doesn't seem to do so
173 // consistently.
174 SUPPORTS_FOCUSIN: goog.userAgent.IE || goog.userAgent.OPERA,
175
176 // Whether clicking on an image will cause the selection to move to the image.
177 // Note: Gecko moves the selection, but it won't always go to the image.
178 // For example, if the image is wrapped in a div, and you click on the img,
179 // anchorNode = focusNode = div, anchorOffset = 0, focusOffset = 1, so this
180 // is another way of "selecting" the image, but there are too many special
181 // cases like this so we will do the work manually.
182 SELECTS_IMAGES_ON_CLICK: goog.userAgent.IE || goog.userAgent.OPERA,
183
184 // Whether this browser moves <style> tags into new <head> elements.
185 MOVES_STYLE_TO_HEAD: goog.userAgent.WEBKIT,
186
187 // Whether this browser collapses the selection in a contenteditable when the
188 // mouse is pressed in a non-editable portion of the same frame, even if
189 // Event.preventDefault is called. This field is deprecated and unused -- only
190 // old versions of Opera have this bug.
191 COLLAPSES_SELECTION_ONMOUSEDOWN: false,
192
193 // Whether the user can actually create a selection in this browser with the
194 // caret in the MIDDLE of the selection by double-clicking.
195 CARET_INSIDE_SELECTION: goog.userAgent.OPERA,
196
197 // Whether the browser focuses <body contenteditable> automatically when
198 // the user clicks on <html>. This field is deprecated and unused -- only old
199 // versions of Opera don't have this behavior.
200 FOCUSES_EDITABLE_BODY_ON_HTML_CLICK: true,
201
202 // Whether to use keydown for key listening (uses keypress otherwise). Taken
203 // from goog.events.KeyHandler.
204 USES_KEYDOWN: goog.userAgent.IE || goog.userAgent.EDGE ||
205 goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher('525'),
206
207 // Whether this browser converts spaces to non-breaking spaces when calling
208 // execCommand's RemoveFormat.
209 // See: https://bugs.webkit.org/show_bug.cgi?id=14062
210 ADDS_NBSPS_IN_REMOVE_FORMAT:
211 goog.userAgent.WEBKIT && !goog.userAgent.isVersionOrHigher('531'),
212
213 // Whether the browser will get stuck inside a link. That is, if your cursor
214 // is after a link and you type, does your text go inside the link tag.
215 // Bug: http://bugs.webkit.org/show_bug.cgi?id=17697
216 GETS_STUCK_IN_LINKS:
217 goog.userAgent.WEBKIT && !goog.userAgent.isVersionOrHigher('528'),
218
219 // Whether the browser corrupts empty text nodes in Node#normalize,
220 // removing them from the Document instead of merging them.
221 NORMALIZE_CORRUPTS_EMPTY_TEXT_NODES:
222 goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9') ||
223 goog.userAgent.IE || goog.userAgent.EDGE || goog.userAgent.OPERA ||
224 goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher('531'),
225
226 // Whether the browser corrupts all text nodes in Node#normalize,
227 // removing them from the Document instead of merging them.
228 NORMALIZE_CORRUPTS_ALL_TEXT_NODES: goog.userAgent.IE,
229
230 // Browsers where executing subscript then superscript (or vv) will cause both
231 // to be applied in a nested fashion instead of the first being overwritten by
232 // the second.
233 NESTS_SUBSCRIPT_SUPERSCRIPT: goog.userAgent.IE || goog.userAgent.EDGE ||
234 goog.userAgent.GECKO || goog.userAgent.OPERA,
235
236 // Whether this browser can place a cursor in an empty element natively.
237 CAN_SELECT_EMPTY_ELEMENT: !goog.userAgent.IE && !goog.userAgent.WEBKIT,
238
239 FORGETS_FORMATTING_WHEN_LISTIFYING: goog.userAgent.GECKO ||
240 goog.userAgent.WEBKIT && !goog.userAgent.isVersionOrHigher('526'),
241
242 LEAVES_P_WHEN_REMOVING_LISTS: goog.userAgent.IE || goog.userAgent.OPERA,
243
244 CAN_LISTIFY_BR: !goog.userAgent.IE && !goog.userAgent.OPERA,
245
246 // See bug 1286408. When somewhere inside your selection there is an element
247 // with a style attribute that sets the font size, if you change the font
248 // size, the browser creates a font tag, but the font size in the style attr
249 // overrides the font tag. Only webkit removes that font size from the style
250 // attr.
251 DOESNT_OVERRIDE_FONT_SIZE_IN_STYLE_ATTR:
252 !goog.userAgent.WEBKIT && !goog.userAgent.EDGE,
253
254 // Implements this spec about dragging files from the filesystem to the
255 // browser: http://www.whatwg/org/specs/web-apps/current-work/#dnd
256 SUPPORTS_HTML5_FILE_DRAGGING: (goog.userAgent.product.CHROME &&
257 goog.userAgent.product.isVersion('4')) ||
258 (goog.userAgent.product.SAFARI &&
259 goog.userAgent.isVersionOrHigher('533')) ||
260 (goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('2.0')) ||
261 (goog.userAgent.IE && goog.userAgent.isVersionOrHigher('10')) ||
262 // TODO(user): Remove when b/27923889 is fixed.
263 (goog.userAgent.OPERA &&
264 goog.labs.userAgent.browser.isVersionOrHigher('15')) ||
265 goog.userAgent.EDGE,
266
267 // Version of Opera that supports the opera-defaultBlock execCommand to change
268 // the default block inserted when [return] is pressed. Note that this only is
269 // used if the caret is not already in a block that can be repeated.
270 // TODO(user): Link to public documentation of this feature if Opera puts
271 // something up about it.
272 SUPPORTS_OPERA_DEFAULTBLOCK_COMMAND:
273 goog.userAgent.OPERA && goog.userAgent.isVersionOrHigher('11.10'),
274
275 SUPPORTS_FILE_PASTING:
276 goog.userAgent.product.CHROME && goog.userAgent.product.isVersion('12')
277 };