| 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) 2001 Peter Kelly (pmk@post.com) | 4 * (C) 2001 Peter Kelly (pmk@post.com) |
| 5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 6 * (C) 2007 David Smith (catfish.man@gmail.com) | 6 * (C) 2007 David Smith (catfish.man@gmail.com) |
| 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. | 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. |
| 8 * (C) 2007 Eric Seidel (eric@webkit.org) | 8 * (C) 2007 Eric Seidel (eric@webkit.org) |
| 9 * | 9 * |
| 10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 if (!renderer()) | 298 if (!renderer()) |
| 299 return; | 299 return; |
| 300 | 300 |
| 301 LayoutRect bounds = boundingBox(); | 301 LayoutRect bounds = boundingBox(); |
| 302 if (centerIfNeeded) | 302 if (centerIfNeeded) |
| 303 renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignCenterIfNe
eded, ScrollAlignment::alignCenterIfNeeded); | 303 renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignCenterIfNe
eded, ScrollAlignment::alignCenterIfNeeded); |
| 304 else | 304 else |
| 305 renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNe
eded, ScrollAlignment::alignToEdgeIfNeeded); | 305 renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNe
eded, ScrollAlignment::alignToEdgeIfNeeded); |
| 306 } | 306 } |
| 307 | 307 |
| 308 static float localZoomForRenderer(RenderObject& renderer) | |
| 309 { | |
| 310 // FIXME: This does the wrong thing if two opposing zooms are in effect and
canceled each | |
| 311 // other out, but the alternative is that we'd have to crawl up the whole re
nder tree every | |
| 312 // time (or store an additional bit in the RenderStyle to indicate that a zo
om was specified). | |
| 313 float zoomFactor = 1; | |
| 314 if (renderer.style()->effectiveZoom() != 1) { | |
| 315 // Need to find the nearest enclosing RenderObject that set up | |
| 316 // a differing zoom, and then we divide our result by it to eliminate th
e zoom. | |
| 317 RenderObject* prev = &renderer; | |
| 318 for (RenderObject* curr = prev->parent(); curr; curr = curr->parent()) { | |
| 319 if (curr->style()->effectiveZoom() != prev->style()->effectiveZoom()
) { | |
| 320 zoomFactor = prev->style()->zoom(); | |
| 321 break; | |
| 322 } | |
| 323 prev = curr; | |
| 324 } | |
| 325 if (prev->isRenderView()) | |
| 326 zoomFactor = prev->style()->zoom(); | |
| 327 } | |
| 328 return zoomFactor; | |
| 329 } | |
| 330 | |
| 331 static double adjustForLocalZoom(LayoutUnit value, RenderObject& renderer) | |
| 332 { | |
| 333 float zoomFactor = localZoomForRenderer(renderer); | |
| 334 if (zoomFactor == 1) | |
| 335 return value.toDouble(); | |
| 336 return value.toDouble() / zoomFactor; | |
| 337 } | |
| 338 | |
| 339 int Element::offsetLeft() | 308 int Element::offsetLeft() |
| 340 { | 309 { |
| 341 document().updateLayoutIgnorePendingStylesheets(); | 310 document().updateLayoutIgnorePendingStylesheets(); |
| 342 if (RenderBoxModelObject* renderer = renderBoxModelObject()) | 311 if (RenderBoxModelObject* renderer = renderBoxModelObject()) |
| 343 return lroundf(adjustForLocalZoom(renderer->offsetLeft(), *renderer)); | 312 return renderer->offsetLeft(); |
| 344 return 0; | 313 return 0; |
| 345 } | 314 } |
| 346 | 315 |
| 347 int Element::offsetTop() | 316 int Element::offsetTop() |
| 348 { | 317 { |
| 349 document().updateLayoutIgnorePendingStylesheets(); | 318 document().updateLayoutIgnorePendingStylesheets(); |
| 350 if (RenderBoxModelObject* renderer = renderBoxModelObject()) | 319 if (RenderBoxModelObject* renderer = renderBoxModelObject()) |
| 351 return lroundf(adjustForLocalZoom(renderer->pixelSnappedOffsetTop(), *re
nderer)); | 320 return renderer->pixelSnappedOffsetTop(); |
| 352 return 0; | 321 return 0; |
| 353 } | 322 } |
| 354 | 323 |
| 355 int Element::offsetWidth() | 324 int Element::offsetWidth() |
| 356 { | 325 { |
| 357 document().updateLayoutIgnorePendingStylesheets(); | 326 document().updateLayoutIgnorePendingStylesheets(); |
| 358 if (RenderBoxModelObject* renderer = renderBoxModelObject()) | 327 if (RenderBoxModelObject* renderer = renderBoxModelObject()) |
| 359 return renderer->pixelSnappedOffsetWidth(); | 328 return renderer->pixelSnappedOffsetWidth(); |
| 360 return 0; | 329 return 0; |
| 361 } | 330 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 416 |
| 448 return 0; | 417 return 0; |
| 449 } | 418 } |
| 450 | 419 |
| 451 void Element::setScrollLeft(int newLeft) | 420 void Element::setScrollLeft(int newLeft) |
| 452 { | 421 { |
| 453 document().updateLayoutIgnorePendingStylesheets(); | 422 document().updateLayoutIgnorePendingStylesheets(); |
| 454 | 423 |
| 455 if (document().documentElement() != this) { | 424 if (document().documentElement() != this) { |
| 456 if (RenderBox* rend = renderBox()) | 425 if (RenderBox* rend = renderBox()) |
| 457 rend->setScrollLeft(LayoutUnit::fromFloatRound(newLeft * rend->style
()->effectiveZoom())); | 426 rend->setScrollLeft(newLeft); |
| 458 } | 427 } |
| 459 } | 428 } |
| 460 | 429 |
| 461 void Element::setScrollLeft(const Dictionary& scrollOptionsHorizontal, Exception
State& exceptionState) | 430 void Element::setScrollLeft(const Dictionary& scrollOptionsHorizontal, Exception
State& exceptionState) |
| 462 { | 431 { |
| 463 String scrollBehaviorString; | 432 String scrollBehaviorString; |
| 464 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; | 433 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; |
| 465 if (DictionaryHelper::get(scrollOptionsHorizontal, "behavior", scrollBehavio
rString)) { | 434 if (DictionaryHelper::get(scrollOptionsHorizontal, "behavior", scrollBehavio
rString)) { |
| 466 if (!ScrollableArea::scrollBehaviorFromString(scrollBehaviorString, scro
llBehavior)) { | 435 if (!ScrollableArea::scrollBehaviorFromString(scrollBehaviorString, scro
llBehavior)) { |
| 467 exceptionState.throwTypeError("The ScrollBehavior provided is invali
d."); | 436 exceptionState.throwTypeError("The ScrollBehavior provided is invali
d."); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 478 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instant
ly. | 447 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instant
ly. |
| 479 setScrollLeft(position); | 448 setScrollLeft(position); |
| 480 } | 449 } |
| 481 | 450 |
| 482 void Element::setScrollTop(int newTop) | 451 void Element::setScrollTop(int newTop) |
| 483 { | 452 { |
| 484 document().updateLayoutIgnorePendingStylesheets(); | 453 document().updateLayoutIgnorePendingStylesheets(); |
| 485 | 454 |
| 486 if (document().documentElement() != this) { | 455 if (document().documentElement() != this) { |
| 487 if (RenderBox* rend = renderBox()) | 456 if (RenderBox* rend = renderBox()) |
| 488 rend->setScrollTop(LayoutUnit::fromFloatRound(newTop * rend->style()
->effectiveZoom())); | 457 rend->setScrollTop(newTop); |
| 489 } | 458 } |
| 490 } | 459 } |
| 491 | 460 |
| 492 void Element::setScrollTop(const Dictionary& scrollOptionsVertical, ExceptionSta
te& exceptionState) | 461 void Element::setScrollTop(const Dictionary& scrollOptionsVertical, ExceptionSta
te& exceptionState) |
| 493 { | 462 { |
| 494 String scrollBehaviorString; | 463 String scrollBehaviorString; |
| 495 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; | 464 ScrollBehavior scrollBehavior = ScrollBehaviorAuto; |
| 496 if (DictionaryHelper::get(scrollOptionsVertical, "behavior", scrollBehaviorS
tring)) { | 465 if (DictionaryHelper::get(scrollOptionsVertical, "behavior", scrollBehaviorS
tring)) { |
| 497 if (!ScrollableArea::scrollBehaviorFromString(scrollBehaviorString, scro
llBehavior)) { | 466 if (!ScrollableArea::scrollBehaviorFromString(scrollBehaviorString, scro
llBehavior)) { |
| 498 exceptionState.throwTypeError("The ScrollBehavior provided is invali
d."); | 467 exceptionState.throwTypeError("The ScrollBehavior provided is invali
d."); |
| (...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1838 return false; | 1807 return false; |
| 1839 // Turn off style sharing for elements that can gain layers for reasons outs
ide of the style system. | 1808 // Turn off style sharing for elements that can gain layers for reasons outs
ide of the style system. |
| 1840 // See comments in RenderObject::setStyle(). | 1809 // See comments in RenderObject::setStyle(). |
| 1841 // FIXME: Why does gaining a layer from outside the style system require dis
abling sharing? | 1810 // FIXME: Why does gaining a layer from outside the style system require dis
abling sharing? |
| 1842 if (isHTMLCanvasElement(*this)) | 1811 if (isHTMLCanvasElement(*this)) |
| 1843 return false; | 1812 return false; |
| 1844 return true; | 1813 return true; |
| 1845 } | 1814 } |
| 1846 | 1815 |
| 1847 } // namespace blink | 1816 } // namespace blink |
| OLD | NEW |