OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2000 Simon Hausmann (hausmann@kde.org) | 4 * (C) 2000 Simon Hausmann (hausmann@kde.org) |
5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
6 * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. | 6 * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return backgroundAttr; | 190 return backgroundAttr; |
191 } | 191 } |
192 | 192 |
193 bool HTMLBodyElement::supportsFocus() const | 193 bool HTMLBodyElement::supportsFocus() const |
194 { | 194 { |
195 // This override is needed because the inherited method bails if the parent
is editable. | 195 // This override is needed because the inherited method bails if the parent
is editable. |
196 // The <body> should be focusable even if <html> is editable. | 196 // The <body> should be focusable even if <html> is editable. |
197 return rendererIsEditable() || HTMLElement::supportsFocus(); | 197 return rendererIsEditable() || HTMLElement::supportsFocus(); |
198 } | 198 } |
199 | 199 |
200 static double adjustForZoom(int value, Document* document) | 200 static int adjustForZoom(int value, Document* document) |
201 { | 201 { |
202 LocalFrame* frame = document->frame(); | 202 LocalFrame* frame = document->frame(); |
203 float zoomFactor = frame->pageZoomFactor(); | 203 float zoomFactor = frame->pageZoomFactor(); |
204 if (zoomFactor == 1) | 204 if (zoomFactor == 1) |
205 return static_cast<double>(value); | 205 return value; |
206 return static_cast<double>(value) / zoomFactor; | 206 // Needed because of truncation (rather than rounding) when scaling up. |
| 207 if (zoomFactor > 1) |
| 208 value++; |
| 209 return static_cast<int>(value / zoomFactor); |
207 } | 210 } |
208 | 211 |
209 // Blink, Gecko and Presto's quirks mode implementations of overflow set to the | 212 // Blink, Gecko and Presto's quirks mode implementations of overflow set to the |
210 // body element differ from IE's: the formers can create a scrollable area for t
he | 213 // body element differ from IE's: the formers can create a scrollable area for t
he |
211 // body element that is not the same as the root elements's one. On IE's quirks
mode | 214 // body element that is not the same as the root elements's one. On IE's quirks
mode |
212 // though, as body is the root element, body's and the root element's scrollable
areas, | 215 // though, as body is the root element, body's and the root element's scrollable
areas, |
213 // if any, are the same. | 216 // if any, are the same. |
214 // In order words, a <body> will only have an overflow clip (that differs from | 217 // In order words, a <body> will only have an overflow clip (that differs from |
215 // documentElement's) if both html and body nodes have its overflow set to eith
er hidden, | 218 // documentElement's) if both html and body nodes have its overflow set to eith
er hidden, |
216 // auto or scroll. | 219 // auto or scroll. |
217 // That said, Blink's {set}scroll{Top,Left} behaviors match Gecko's: even if the
re is a non-overflown | 220 // That said, Blink's {set}scroll{Top,Left} behaviors match Gecko's: even if the
re is a non-overflown |
218 // scrollable area, scrolling should not get propagated to the viewport in neith
er strict | 221 // scrollable area, scrolling should not get propagated to the viewport in neith
er strict |
219 // or quirks modes. | 222 // or quirks modes. |
220 double HTMLBodyElement::scrollLeft() | 223 int HTMLBodyElement::scrollLeft() |
221 { | 224 { |
222 Document& document = this->document(); | 225 Document& document = this->document(); |
223 document.updateLayoutIgnorePendingStylesheets(); | 226 document.updateLayoutIgnorePendingStylesheets(); |
224 | 227 |
225 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { | 228 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |
226 RenderBox* render = renderBox(); | 229 RenderBox* render = renderBox(); |
227 if (!render) | 230 if (!render) |
228 return 0; | 231 return 0; |
229 if (render->hasOverflowClip()) | 232 if (render->hasOverflowClip()) |
230 return adjustForAbsoluteZoom(render->scrollLeft(), render); | 233 return adjustForAbsoluteZoom(render->scrollLeft(), render); |
231 if (!document.inQuirksMode()) | 234 if (!document.inQuirksMode()) |
232 return 0; | 235 return 0; |
233 } | 236 } |
234 | 237 |
235 FrameView* view = document.view(); | 238 FrameView* view = document.view(); |
236 return view ? adjustForZoom(view->scrollX(), &document) : 0; | 239 return view ? adjustForZoom(view->scrollX(), &document) : 0; |
237 } | 240 } |
238 | 241 |
239 void HTMLBodyElement::setScrollLeft(double scrollLeft) | 242 void HTMLBodyElement::setScrollLeft(int scrollLeft) |
240 { | 243 { |
241 Document& document = this->document(); | 244 Document& document = this->document(); |
242 document.updateLayoutIgnorePendingStylesheets(); | 245 document.updateLayoutIgnorePendingStylesheets(); |
243 | 246 |
244 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { | 247 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |
245 RenderBox* render = renderBox(); | 248 RenderBox* render = renderBox(); |
246 if (!render) | 249 if (!render) |
247 return; | 250 return; |
248 if (render->hasOverflowClip()) { | 251 if (render->hasOverflowClip()) { |
249 // FIXME: Investigate how are other browsers casting to int (roundin
g, ceiling, ...). | 252 // FIXME: Investigate how are other browsers casting to int (roundin
g, ceiling, ...). |
250 render->setScrollLeft(static_cast<int>(scrollLeft * render->style()-
>effectiveZoom())); | 253 render->setScrollLeft(static_cast<int>(scrollLeft * render->style()-
>effectiveZoom())); |
251 return; | 254 return; |
252 } | 255 } |
253 if (!document.inQuirksMode()) | 256 if (!document.inQuirksMode()) |
254 return; | 257 return; |
255 } | 258 } |
256 | 259 |
257 LocalFrame* frame = document.frame(); | 260 LocalFrame* frame = document.frame(); |
258 if (!frame) | 261 if (!frame) |
259 return; | 262 return; |
260 FrameView* view = frame->view(); | 263 FrameView* view = frame->view(); |
261 if (!view) | 264 if (!view) |
262 return; | 265 return; |
263 view->setScrollPosition(IntPoint(static_cast<int>(scrollLeft * frame->pageZo
omFactor()), view->scrollY())); | 266 view->setScrollPosition(IntPoint(static_cast<int>(scrollLeft * frame->pageZo
omFactor()), view->scrollY())); |
264 } | 267 } |
265 | 268 |
266 double HTMLBodyElement::scrollTop() | 269 int HTMLBodyElement::scrollTop() |
267 { | 270 { |
268 Document& document = this->document(); | 271 Document& document = this->document(); |
269 document.updateLayoutIgnorePendingStylesheets(); | 272 document.updateLayoutIgnorePendingStylesheets(); |
270 | 273 |
271 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { | 274 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |
272 RenderBox* render = renderBox(); | 275 RenderBox* render = renderBox(); |
273 if (!render) | 276 if (!render) |
274 return 0; | 277 return 0; |
275 if (render->hasOverflowClip()) | 278 if (render->hasOverflowClip()) |
276 return adjustForAbsoluteZoom(render->scrollTop(), render); | 279 return adjustForAbsoluteZoom(render->scrollTop(), render); |
277 if (!document.inQuirksMode()) | 280 if (!document.inQuirksMode()) |
278 return 0; | 281 return 0; |
279 } | 282 } |
280 | 283 |
281 FrameView* view = document.view(); | 284 FrameView* view = document.view(); |
282 return view ? adjustForZoom(view->scrollY(), &document) : 0; | 285 return view ? adjustForZoom(view->scrollY(), &document) : 0; |
283 } | 286 } |
284 | 287 |
285 void HTMLBodyElement::setScrollTop(double scrollTop) | 288 void HTMLBodyElement::setScrollTop(int scrollTop) |
286 { | 289 { |
287 Document& document = this->document(); | 290 Document& document = this->document(); |
288 document.updateLayoutIgnorePendingStylesheets(); | 291 document.updateLayoutIgnorePendingStylesheets(); |
289 | 292 |
290 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { | 293 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |
291 RenderBox* render = renderBox(); | 294 RenderBox* render = renderBox(); |
292 if (!render) | 295 if (!render) |
293 return; | 296 return; |
294 if (render->hasOverflowClip()) { | 297 if (render->hasOverflowClip()) { |
295 // FIXME: Investigate how are other browsers casting to int (roundin
g, ceiling, ...). | 298 // FIXME: Investigate how are other browsers casting to int (roundin
g, ceiling, ...). |
296 render->setScrollTop(static_cast<int>(scrollTop * render->style()->e
ffectiveZoom())); | 299 render->setScrollTop(static_cast<int>(scrollTop * render->style()->e
ffectiveZoom())); |
297 return; | 300 return; |
298 } | 301 } |
299 if (!document.inQuirksMode()) | 302 if (!document.inQuirksMode()) |
300 return; | 303 return; |
301 } | 304 } |
302 | 305 |
303 LocalFrame* frame = document.frame(); | 306 LocalFrame* frame = document.frame(); |
304 if (!frame) | 307 if (!frame) |
305 return; | 308 return; |
306 FrameView* view = frame->view(); | 309 FrameView* view = frame->view(); |
307 if (!view) | 310 if (!view) |
308 return; | 311 return; |
309 view->setScrollPosition(IntPoint(view->scrollX(), static_cast<int>(scrollTop
* frame->pageZoomFactor()))); | 312 view->setScrollPosition(IntPoint(view->scrollX(), static_cast<int>(scrollTop
* frame->pageZoomFactor()))); |
310 } | 313 } |
311 | 314 |
312 double HTMLBodyElement::scrollHeight() | 315 int HTMLBodyElement::scrollHeight() |
313 { | 316 { |
314 // Update the document's layout. | 317 // Update the document's layout. |
315 Document& document = this->document(); | 318 Document& document = this->document(); |
316 document.updateLayoutIgnorePendingStylesheets(); | 319 document.updateLayoutIgnorePendingStylesheets(); |
317 FrameView* view = document.view(); | 320 FrameView* view = document.view(); |
318 return view ? adjustForZoom(view->contentsHeight(), &document) : 0; | 321 return view ? adjustForZoom(view->contentsHeight(), &document) : 0; |
319 } | 322 } |
320 | 323 |
321 double HTMLBodyElement::scrollWidth() | 324 int HTMLBodyElement::scrollWidth() |
322 { | 325 { |
323 // Update the document's layout. | 326 // Update the document's layout. |
324 Document& document = this->document(); | 327 Document& document = this->document(); |
325 document.updateLayoutIgnorePendingStylesheets(); | 328 document.updateLayoutIgnorePendingStylesheets(); |
326 FrameView* view = document.view(); | 329 FrameView* view = document.view(); |
327 return view ? adjustForZoom(view->contentsWidth(), &document) : 0; | 330 return view ? adjustForZoom(view->contentsWidth(), &document) : 0; |
328 } | 331 } |
329 | 332 |
330 } // namespace WebCore | 333 } // namespace WebCore |
OLD | NEW |