Debian Codegraph @

closure-library/closure/goog/style/cursor.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 Functions to create special cursor styles, like "draggable"
17 * (open hand) or "dragging" (closed hand).
18 *
19 * @author [email protected] (Damian Gajda) Ported to closure.
20 */
21
22 goog.provide('goog.style.cursor');
23
24 goog.require('goog.userAgent');
25
26
27 /**
28 * The file name for the open-hand (draggable) cursor.
29 * @type {string}
30 */
31 goog.style.cursor.OPENHAND_FILE = 'openhand.cur';
32
33
34 /**
35 * The file name for the close-hand (dragging) cursor.
36 * @type {string}
37 */
38 goog.style.cursor.CLOSEDHAND_FILE = 'closedhand.cur';
39
40
41 /**
42 * Create the style for the draggable cursor based on browser and OS.
43 * The value can be extended to be '!important' if needed.
44 *
45 * @param {string} absoluteDotCurFilePath The absolute base path of
46 * 'openhand.cur' file to be used if the browser supports it.
47 * @param {boolean=} opt_obsolete Just for compiler backward compatibility.
48 * @return {string} The "draggable" mouse cursor style value.
49 */
50 goog.style.cursor.getDraggableCursorStyle = function(
51 absoluteDotCurFilePath, opt_obsolete) {
52 return goog.style.cursor.getCursorStyle_(
53 '-moz-grab', absoluteDotCurFilePath + goog.style.cursor.OPENHAND_FILE,
54 'default');
55 };
56
57
58 /**
59 * Create the style for the dragging cursor based on browser and OS.
60 * The value can be extended to be '!important' if needed.
61 *
62 * @param {string} absoluteDotCurFilePath The absolute base path of
63 * 'closedhand.cur' file to be used if the browser supports it.
64 * @param {boolean=} opt_obsolete Just for compiler backward compatibility.
65 * @return {string} The "dragging" mouse cursor style value.
66 */
67 goog.style.cursor.getDraggingCursorStyle = function(
68 absoluteDotCurFilePath, opt_obsolete) {
69 return goog.style.cursor.getCursorStyle_(
70 '-moz-grabbing',
71 absoluteDotCurFilePath + goog.style.cursor.CLOSEDHAND_FILE, 'move');
72 };
73
74
75 /**
76 * Create the style for the cursor based on browser and OS.
77 *
78 * @param {string} geckoNonWinBuiltInStyleValue The Gecko on non-Windows OS,
79 * built in cursor style.
80 * @param {string} absoluteDotCurFilePath The .cur file absolute file to be
81 * used if the browser supports it.
82 * @param {string} defaultStyle The default fallback cursor style.
83 * @return {string} The computed mouse cursor style value.
84 * @private
85 */
86 goog.style.cursor.getCursorStyle_ = function(
87 geckoNonWinBuiltInStyleValue, absoluteDotCurFilePath, defaultStyle) {
88 // Use built in cursors for Gecko on non Windows OS.
89 // We prefer our custom cursor, but Firefox Mac and Firefox Linux
90 // cannot do custom cursors. They do have a built-in hand, so use it:
91 if (goog.userAgent.GECKO && !goog.userAgent.WINDOWS) {
92 return geckoNonWinBuiltInStyleValue;
93 }
94
95 // Use the custom cursor file.
96 var cursorStyleValue = 'url("' + absoluteDotCurFilePath + '")';
97 // Change hot-spot for Safari.
98 if (goog.userAgent.WEBKIT) {
99 // Safari seems to ignore the hotspot specified in the .cur file (it uses
100 // 0,0 instead). This causes the cursor to jump as it transitions between
101 // openhand and pointer which is especially annoying when trying to hover
102 // over the route for draggable routes. We specify the hotspot here as 7,5
103 // in the css - unfortunately ie6 can't understand this and falls back to
104 // the builtin cursors so we just do this for safari (but ie DOES correctly
105 // use the hotspot specified in the file so this is ok). The appropriate
106 // coordinates were determined by looking at a hex dump and the format
107 // description from wikipedia.
108 cursorStyleValue += ' 7 5';
109 }
110 // Add default cursor fallback.
111 cursorStyleValue += ', ' + defaultStyle;
112 return cursorStyleValue;
113 };