1 // Displays the page magnifier
2 function webdeveloper_displayPageMagnifier(element
)
4 var canvas
= document
.getElementById("webdeveloper-page-magnifier");
6 // If the canvas is not set or has no context
7 if(!canvas
|| !canvas
.getContext
)
9 window
.openDialog("chrome://webdeveloper/content/message/message.xul", "webdeveloper-message-dialog", "centerscreen,chrome,modal", document
.getElementById("webdeveloper-string-bundle").getString("webdeveloper_firefox15Required"));
14 var container
= document
.getElementById("webdeveloper-page-magnifier-container");
16 // If the element is set
19 checked
= element
.getAttribute("checked");
22 webdeveloper_configureElement(document
.getElementById("webdeveloper-page-magnifier-toolbar"), "hidden", !checked
);
24 // If displaying page validation
27 var browserBoxObject
= webdeveloper_getSelectedBrowser().boxObject
;
29 document
.getElementById("webdeveloper.magnification.level").value
= webdeveloper_getStringPreference("webdeveloper.magnification.level", true);
30 webdeveloper_updatePageMagnifier(0, 0);
32 container
.addEventListener("DOMMouseScroll", webdeveloper_scrollPageMagnifier
, false);
33 window
.addEventListener("mousemove", webdeveloper_movePageMagnifier
, false);
35 container
.style
.left
= (browserBoxObject
.x
+ 10) + "px";
36 container
.style
.top
= (browserBoxObject
.y
+ 10) + "px";
37 container
.hidden
= false;
41 // Try to remove the event listener
44 container
.removeEventListener("DOMMouseScroll", webdeveloper_scrollPageMagnifier
, false);
51 // Try to remove the event listener
54 window
.removeEventListener("mousemove", webdeveloper_movePageMagnifier
, false);
61 container
.hidden
= true;
64 webdeveloper_toggleAppliedStyle(element
, "webdeveloper-display-page-magnifier");
68 // Called when the page magnifier is moved
69 function webdeveloper_movePageMagnifier(event
)
71 var canvas
= document
.getElementById("webdeveloper-page-magnifier");
72 var eventTarget
= event
.target
;
74 // If the canvas and event target are set and the canvas is the event target
75 if(canvas
&& eventTarget
&& canvas
== eventTarget
)
77 var container
= document
.getElementById("webdeveloper-page-magnifier-container");
79 // If the container is set
82 var browserBoxObject
= webdeveloper_getSelectedBrowser().boxObject
;
83 var browserXPosition
= browserBoxObject
.x
;
84 var browserYPosition
= browserBoxObject
.y
;
85 var canvasHalfHeight
= canvas
.height
/ 2;
86 var canvasHalfWidth
= canvas
.width
/ 2;
87 var containerXPosition
= event
.clientX
- canvasHalfWidth
;
88 var containerYPosition
= event
.clientY
- canvasHalfHeight
;
89 var documentElement
= webdeveloper_getContentDocument().documentElement
;
90 var magnificationLevel
= parseFloat(webdeveloper_getStringPreference("webdeveloper.magnification.level", true));
91 var magnifierXPosition
= event
.clientX
- browserXPosition
- (canvasHalfWidth
/ magnificationLevel
) + documentElement
.scrollLeft
;
92 var magnifierYPosition
= event
.clientY
- browserYPosition
- (canvasHalfHeight
/ magnificationLevel
) + documentElement
.scrollTop
;
94 // If the container X position is less than the browser X position
95 if(containerXPosition
< browserXPosition
)
97 containerXPosition
= browserXPosition
;
100 // If the container Y position is less than the browser Y position
101 if(containerYPosition
< browserYPosition
)
103 containerYPosition
= browserYPosition
;
106 // If the magnifier X position is less than 0
107 if(magnifierXPosition
< 0)
109 magnifierXPosition
= 0;
112 // If the magnifier Y position is less than 0
113 if(magnifierYPosition
< 0)
115 magnifierYPosition
= 0;
118 container
.style
.left
= containerXPosition
+ "px";
119 container
.style
.top
= containerYPosition
+ "px";
121 webdeveloper_updatePageMagnifier(magnifierXPosition
, magnifierYPosition
);
126 // Called when the page magnifier is scrolled with the mouse wheel
127 function webdeveloper_scrollPageMagnifier(event
)
129 var eventDetail
= event
.detail
;
131 // If the event detail is set
134 var magnificationLevel
= parseFloat(webdeveloper_getStringPreference("webdeveloper.magnification.level", true));
136 // If the event detail is greater than zero (scroll down)
139 // If the magnification level is greater than one
140 if(magnificationLevel
> 1)
142 magnificationLevel
-= 1;
147 magnificationLevel
+= 1;
150 document
.getElementById("webdeveloper.magnification.level").value
= magnificationLevel
;
152 webdeveloper_setStringPreference("webdeveloper.magnification.level", magnificationLevel
);
153 webdeveloper_updatePageMagnifier(0, 0);
155 event
.preventDefault();
159 // Updates the magnification level
160 function webdeveloper_updateMagnificationLevel(element
)
162 var magnificationLevel
= element
.value
;
163 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
165 // If the magnification level is empty or not a number or less than zero
166 if(!magnificationLevel
|| parseFloat(magnificationLevel
) != magnificationLevel
|| magnificationLevel
<= 0)
168 webdeveloper_error(stringBundle
.getString("webdeveloper_invalidWidth"));
172 webdeveloper_setStringPreference("webdeveloper.magnification.level", magnificationLevel
);
173 webdeveloper_updatePageMagnifier(0, 0);
177 // Updates the page magnifier
178 function webdeveloper_updatePageMagnifier(xPosition
, yPosition
)
180 var canvas
= document
.getElementById("webdeveloper-page-magnifier");
182 // If the canvas was found
185 var context
= canvas
.getContext("2d");
186 var height
= canvas
.height
;
187 var magnificationLevel
= parseFloat(webdeveloper_getStringPreference("webdeveloper.magnification.level", true));
188 var width
= canvas
.width
;
191 context
.scale(magnificationLevel
, magnificationLevel
);
192 context
.drawWindow(webdeveloper_getContentWindow(), xPosition
, yPosition
, (xPosition
+ width
) / magnificationLevel
, (yPosition
+ height
) / magnificationLevel
, "rgb(255, 255, 255)");