Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: Source/core/html/HTMLBodyElement.cpp

Issue 782793002: Update Element API for CSSOM smooth scrolling to match the spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
26 26
27 #include "bindings/core/v8/ScriptEventListener.h" 27 #include "bindings/core/v8/ScriptEventListener.h"
28 #include "core/CSSValueKeywords.h" 28 #include "core/CSSValueKeywords.h"
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/css/CSSImageValue.h" 30 #include "core/css/CSSImageValue.h"
31 #include "core/css/StylePropertySet.h" 31 #include "core/css/StylePropertySet.h"
32 #include "core/css/parser/CSSParser.h" 32 #include "core/css/parser/CSSParser.h"
33 #include "core/dom/Attribute.h" 33 #include "core/dom/Attribute.h"
34 #include "core/frame/FrameView.h" 34 #include "core/frame/FrameView.h"
35 #include "core/frame/LocalFrame.h" 35 #include "core/frame/LocalFrame.h"
36 #include "core/frame/ScrollToOptions.h"
36 #include "core/frame/UseCounter.h" 37 #include "core/frame/UseCounter.h"
37 #include "core/html/HTMLFrameElementBase.h" 38 #include "core/html/HTMLFrameElementBase.h"
38 #include "core/html/parser/HTMLParserIdioms.h" 39 #include "core/html/parser/HTMLParserIdioms.h"
39 #include "core/rendering/RenderBox.h" 40 #include "core/rendering/RenderBox.h"
40 41
41 namespace blink { 42 namespace blink {
42 43
43 using namespace HTMLNames; 44 using namespace HTMLNames;
44 45
45 inline HTMLBodyElement::HTMLBodyElement(Document& document) 46 inline HTMLBodyElement::HTMLBodyElement(Document& document)
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 if (!document.inQuirksMode()) 259 if (!document.inQuirksMode())
259 return; 260 return;
260 } 261 }
261 262
262 LocalFrame* frame = document.frame(); 263 LocalFrame* frame = document.frame();
263 if (!frame) 264 if (!frame)
264 return; 265 return;
265 FrameView* view = frame->view(); 266 FrameView* view = frame->view();
266 if (!view) 267 if (!view)
267 return; 268 return;
268 view->setScrollPosition(DoublePoint(scrollLeft * frame->pageZoomFactor(), vi ew->scrollY())); 269 view->setScrollPosition(DoublePoint(scrollLeft * frame->pageZoomFactor(), vi ew->scrollY()), ScrollBehaviorAuto);
269 } 270 }
270 271
271 double HTMLBodyElement::scrollTop() 272 double HTMLBodyElement::scrollTop()
272 { 273 {
273 Document& document = this->document(); 274 Document& document = this->document();
274 document.updateLayoutIgnorePendingStylesheets(); 275 document.updateLayoutIgnorePendingStylesheets();
275 276
276 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { 277 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
277 RenderBox* render = renderBox(); 278 RenderBox* render = renderBox();
278 if (!render) 279 if (!render)
(...skipping 29 matching lines...) Expand all
308 if (!document.inQuirksMode()) 309 if (!document.inQuirksMode())
309 return; 310 return;
310 } 311 }
311 312
312 LocalFrame* frame = document.frame(); 313 LocalFrame* frame = document.frame();
313 if (!frame) 314 if (!frame)
314 return; 315 return;
315 FrameView* view = frame->view(); 316 FrameView* view = frame->view();
316 if (!view) 317 if (!view)
317 return; 318 return;
318 view->setScrollPosition(DoublePoint(view->scrollX(), scrollTop * frame->page ZoomFactor())); 319 view->setScrollPosition(DoublePoint(view->scrollX(), scrollTop * frame->page ZoomFactor()), ScrollBehaviorAuto);
319 } 320 }
320 321
321 int HTMLBodyElement::scrollHeight() 322 int HTMLBodyElement::scrollHeight()
322 { 323 {
323 // Update the document's layout. 324 // Update the document's layout.
324 Document& document = this->document(); 325 Document& document = this->document();
325 document.updateLayoutIgnorePendingStylesheets(); 326 document.updateLayoutIgnorePendingStylesheets();
326 FrameView* view = document.view(); 327 FrameView* view = document.view();
327 return view ? adjustForZoom(view->contentsHeight(), &document) : 0; 328 return view ? adjustForZoom(view->contentsHeight(), &document) : 0;
328 } 329 }
329 330
330 int HTMLBodyElement::scrollWidth() 331 int HTMLBodyElement::scrollWidth()
331 { 332 {
332 // Update the document's layout. 333 // Update the document's layout.
333 Document& document = this->document(); 334 Document& document = this->document();
334 document.updateLayoutIgnorePendingStylesheets(); 335 document.updateLayoutIgnorePendingStylesheets();
335 FrameView* view = document.view(); 336 FrameView* view = document.view();
336 return view ? adjustForZoom(view->contentsWidth(), &document) : 0; 337 return view ? adjustForZoom(view->contentsWidth(), &document) : 0;
337 } 338 }
338 339
340 void HTMLBodyElement::scrollBy(const ScrollToOptions& scrollToOptions)
Ian Vollick 2014/12/08 16:35:23 nit: The similarity of these methods and those in
ajuma 2014/12/08 18:34:13 Added helpers (scrollFrameBy, scrollFrameTo, scrol
341 {
342 Document& document = this->document();
343 document.updateLayoutIgnorePendingStylesheets();
344
345 double left = scrollToOptions.hasLeft() ? scrollToOptions.left() : 0.0;
346 double top = scrollToOptions.hasTop() ? scrollToOptions.top() : 0.0;
347 if (std::isnan(left) || std::isnan(top))
348 return;
349
350 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
351 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB ehavior);
352
353 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
354 RenderBox* render = renderBox();
355 if (!render)
356 return;
357 if (render->hasOverflowClip()) {
358 double currentScaledLeft = render->scrollLeft();
359 double currentScaledTop = render->scrollTop();
360 double newScaledLeft = left * render->style()->effectiveZoom() + cur rentScaledLeft;
361 double newScaledTop = top * render->style()->effectiveZoom() + curre ntScaledTop;
362 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instantly.
363 render->scrollToOffset(DoubleSize(newScaledLeft, newScaledTop));
364 return;
365 }
366 if (!document.inQuirksMode())
367 return;
368 }
369
370 LocalFrame* frame = document.frame();
371 if (!frame)
372 return;
373 FrameView* view = frame->view();
374 if (!view)
375 return;
376
377 double newScaledLeft = left * frame->pageZoomFactor() + view->scrollX();
378 double newScaledTop = top * frame->pageZoomFactor() + view->scrollY();
379 view->setScrollPosition(DoublePoint(newScaledLeft, newScaledTop), scrollBeha vior);
380 }
381
382 void HTMLBodyElement::scrollTo(const ScrollToOptions& scrollToOptions)
383 {
384 Document& document = this->document();
385 document.updateLayoutIgnorePendingStylesheets();
386
387 if ((scrollToOptions.hasLeft() && std::isnan(scrollToOptions.left()))
388 || (scrollToOptions.hasTop() && std::isnan(scrollToOptions.top())))
389 return;
390
391 ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
392 ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollB ehavior);
393
394 if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
395 RenderBox* render = renderBox();
396 if (!render)
397 return;
398 if (render->hasOverflowClip()) {
399 double scaledLeft = render->scrollLeft();
400 double scaledTop = render->scrollTop();
401 if (scrollToOptions.hasLeft())
402 scaledLeft = scrollToOptions.left() * render->style()->effective Zoom();
403 if (scrollToOptions.hasTop())
404 scaledTop = scrollToOptions.top() * render->style()->effectiveZo om();
405 // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instantly.
406 render->scrollToOffset(DoubleSize(scaledLeft, scaledTop));
407 return;
408 }
409 if (!document.inQuirksMode())
410 return;
411 }
412
413 LocalFrame* frame = document.frame();
414 if (!frame)
415 return;
416 FrameView* view = frame->view();
417 if (!view)
418 return;
419
420 double scaledLeft = view->scrollX();
421 double scaledTop = view->scrollY();
422 if (scrollToOptions.hasLeft())
423 scaledLeft = scrollToOptions.left() * frame->pageZoomFactor();
424 if (scrollToOptions.hasTop())
425 scaledTop = scrollToOptions.top() * frame->pageZoomFactor();
426 view->setScrollPosition(DoublePoint(scaledLeft, scaledTop), scrollBehavior);
427 }
428
339 } // namespace blink 429 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698