Chromium Code Reviews| 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. | 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. |
| 8 * All rights reserved. | 8 * All rights reserved. |
| 9 * (C) 2007 Eric Seidel (eric@webkit.org) | 9 * (C) 2007 Eric Seidel (eric@webkit.org) |
| 10 * | 10 * |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 24 * Boston, MA 02110-1301, USA. | 24 * Boston, MA 02110-1301, USA. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "core/dom/Element.h" | 27 #include "core/dom/Element.h" |
| 28 | 28 |
| 29 #include <memory> | 29 #include <memory> |
| 30 #include "bindings/core/v8/Dictionary.h" | 30 #include "bindings/core/v8/Dictionary.h" |
| 31 #include "bindings/core/v8/ExceptionMessages.h" | 31 #include "bindings/core/v8/ExceptionMessages.h" |
| 32 #include "bindings/core/v8/ExceptionState.h" | 32 #include "bindings/core/v8/ExceptionState.h" |
| 33 #include "bindings/core/v8/ScrollIntoViewOptionsOrBoolean.h" | |
| 33 #include "bindings/core/v8/V8DOMActivityLogger.h" | 34 #include "bindings/core/v8/V8DOMActivityLogger.h" |
| 34 #include "core/CSSValueKeywords.h" | 35 #include "core/CSSValueKeywords.h" |
| 35 #include "core/SVGNames.h" | 36 #include "core/SVGNames.h" |
| 36 #include "core/XMLNames.h" | 37 #include "core/XMLNames.h" |
| 37 #include "core/animation/AnimationTimeline.h" | 38 #include "core/animation/AnimationTimeline.h" |
| 38 #include "core/animation/CustomCompositorAnimations.h" | 39 #include "core/animation/CustomCompositorAnimations.h" |
| 39 #include "core/animation/css/CSSAnimations.h" | 40 #include "core/animation/css/CSSAnimations.h" |
| 40 #include "core/css/CSSIdentifierValue.h" | 41 #include "core/css/CSSIdentifierValue.h" |
| 41 #include "core/css/CSSPrimitiveValue.h" | 42 #include "core/css/CSSPrimitiveValue.h" |
| 42 #include "core/css/CSSStyleSheet.h" | 43 #include "core/css/CSSStyleSheet.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 #include "core/editing/EditingUtilities.h" | 88 #include "core/editing/EditingUtilities.h" |
| 88 #include "core/editing/FrameSelection.h" | 89 #include "core/editing/FrameSelection.h" |
| 89 #include "core/editing/iterators/TextIterator.h" | 90 #include "core/editing/iterators/TextIterator.h" |
| 90 #include "core/editing/serializers/Serialization.h" | 91 #include "core/editing/serializers/Serialization.h" |
| 91 #include "core/events/EventDispatcher.h" | 92 #include "core/events/EventDispatcher.h" |
| 92 #include "core/events/FocusEvent.h" | 93 #include "core/events/FocusEvent.h" |
| 93 #include "core/frame/FrameView.h" | 94 #include "core/frame/FrameView.h" |
| 94 #include "core/frame/HostsUsingFeatures.h" | 95 #include "core/frame/HostsUsingFeatures.h" |
| 95 #include "core/frame/LocalDOMWindow.h" | 96 #include "core/frame/LocalDOMWindow.h" |
| 96 #include "core/frame/LocalFrame.h" | 97 #include "core/frame/LocalFrame.h" |
| 98 #include "core/frame/ScrollIntoViewOptions.h" | |
| 97 #include "core/frame/ScrollToOptions.h" | 99 #include "core/frame/ScrollToOptions.h" |
| 98 #include "core/frame/Settings.h" | 100 #include "core/frame/Settings.h" |
| 99 #include "core/frame/UseCounter.h" | 101 #include "core/frame/UseCounter.h" |
| 100 #include "core/frame/VisualViewport.h" | 102 #include "core/frame/VisualViewport.h" |
| 101 #include "core/frame/csp/ContentSecurityPolicy.h" | 103 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 102 #include "core/html/ClassList.h" | 104 #include "core/html/ClassList.h" |
| 103 #include "core/html/HTMLCanvasElement.h" | 105 #include "core/html/HTMLCanvasElement.h" |
| 104 #include "core/html/HTMLCollection.h" | 106 #include "core/html/HTMLCollection.h" |
| 105 #include "core/html/HTMLDocument.h" | 107 #include "core/html/HTMLDocument.h" |
| 106 #include "core/html/HTMLElement.h" | 108 #include "core/html/HTMLElement.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 134 #include "core/svg/SVGElement.h" | 136 #include "core/svg/SVGElement.h" |
| 135 #include "core/svg/SVGTreeScopeResources.h" | 137 #include "core/svg/SVGTreeScopeResources.h" |
| 136 #include "platform/EventDispatchForbiddenScope.h" | 138 #include "platform/EventDispatchForbiddenScope.h" |
| 137 #include "platform/RuntimeEnabledFeatures.h" | 139 #include "platform/RuntimeEnabledFeatures.h" |
| 138 #include "platform/bindings/DOMDataStore.h" | 140 #include "platform/bindings/DOMDataStore.h" |
| 139 #include "platform/bindings/V8DOMWrapper.h" | 141 #include "platform/bindings/V8DOMWrapper.h" |
| 140 #include "platform/bindings/V8PerContextData.h" | 142 #include "platform/bindings/V8PerContextData.h" |
| 141 #include "platform/graphics/CompositorMutableProperties.h" | 143 #include "platform/graphics/CompositorMutableProperties.h" |
| 142 #include "platform/graphics/CompositorMutation.h" | 144 #include "platform/graphics/CompositorMutation.h" |
| 143 #include "platform/scroll/ScrollableArea.h" | 145 #include "platform/scroll/ScrollableArea.h" |
| 146 #include "platform/scroll/SmoothScrollSequencer.h" | |
| 144 #include "platform/wtf/BitVector.h" | 147 #include "platform/wtf/BitVector.h" |
| 145 #include "platform/wtf/HashFunctions.h" | 148 #include "platform/wtf/HashFunctions.h" |
| 146 #include "platform/wtf/text/CString.h" | 149 #include "platform/wtf/text/CString.h" |
| 147 #include "platform/wtf/text/StringBuilder.h" | 150 #include "platform/wtf/text/StringBuilder.h" |
| 148 #include "platform/wtf/text/TextPosition.h" | 151 #include "platform/wtf/text/TextPosition.h" |
| 149 | 152 |
| 150 namespace blink { | 153 namespace blink { |
| 151 | 154 |
| 152 namespace { | 155 namespace { |
| 153 | 156 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 } | 434 } |
| 432 | 435 |
| 433 const AtomicString& Element::nonce() const { | 436 const AtomicString& Element::nonce() const { |
| 434 return HasRareData() ? GetElementRareData()->GetNonce() : g_empty_atom; | 437 return HasRareData() ? GetElementRareData()->GetNonce() : g_empty_atom; |
| 435 } | 438 } |
| 436 | 439 |
| 437 void Element::setNonce(const AtomicString& nonce) { | 440 void Element::setNonce(const AtomicString& nonce) { |
| 438 EnsureElementRareData().SetNonce(nonce); | 441 EnsureElementRareData().SetNonce(nonce); |
| 439 } | 442 } |
| 440 | 443 |
| 444 void Element::scrollIntoView(ScrollIntoViewOptionsOrBoolean arg) { | |
| 445 ScrollIntoViewOptions options; | |
| 446 if (arg.isBoolean()) { | |
| 447 if (arg.getAsBoolean()) | |
| 448 options.setBlock("start"); | |
| 449 else | |
| 450 options.setBlock("end"); | |
| 451 options.setInlinePosition("nearest"); | |
| 452 } else if (arg.isScrollIntoViewOptions()) { | |
| 453 options = arg.getAsScrollIntoViewOptions(); | |
| 454 if (!RuntimeEnabledFeatures::cssomSmoothScrollEnabled() && | |
| 455 options.behavior() == "smooth") { | |
| 456 options.setBehavior("instant"); | |
| 457 } | |
| 458 } | |
| 459 scrollIntoViewWithOptions(options); | |
| 460 } | |
| 461 | |
| 441 void Element::scrollIntoView(bool align_to_top) { | 462 void Element::scrollIntoView(bool align_to_top) { |
| 463 ScrollIntoViewOptionsOrBoolean arg; | |
| 464 arg.setBoolean(align_to_top); | |
| 465 scrollIntoView(arg); | |
| 466 } | |
| 467 | |
| 468 static ScrollAlignment ToPhysicalAlignment(const ScrollIntoViewOptions& options, | |
| 469 ScrollOrientation axis, | |
| 470 ScrollOrientation writing_mode) { | |
|
bokan
2017/05/19 18:37:14
While it kind of makes sense here, writing mode is
sunyunjia
2017/05/19 22:30:41
Done.
| |
| 471 String alignment = | |
| 472 (axis == writing_mode) ? options.inlinePosition() : options.block(); | |
| 473 | |
| 474 if (alignment == "center") | |
| 475 return ScrollAlignment::kAlignCenterAlways; | |
| 476 if (alignment == "nearest") | |
| 477 return ScrollAlignment::kAlignToEdgeIfNeeded; | |
| 478 if (alignment == "start") { | |
| 479 return (axis == kHorizontalScroll) ? ScrollAlignment::kAlignLeftAlways | |
| 480 : ScrollAlignment::kAlignTopAlways; | |
| 481 } | |
| 482 if (alignment == "end") { | |
| 483 return (axis == kHorizontalScroll) ? ScrollAlignment::kAlignRightAlways | |
| 484 : ScrollAlignment::kAlignBottomAlways; | |
| 485 } | |
| 486 | |
| 487 // Default values | |
| 488 if (writing_mode == kHorizontalScroll) { | |
| 489 return (axis == kHorizontalScroll) ? ScrollAlignment::kAlignToEdgeIfNeeded | |
| 490 : ScrollAlignment::kAlignTopAlways; | |
| 491 } | |
| 492 return (axis == kHorizontalScroll) ? ScrollAlignment::kAlignLeftAlways | |
| 493 : ScrollAlignment::kAlignToEdgeIfNeeded; | |
| 494 } | |
| 495 | |
| 496 void Element::scrollIntoViewWithOptions(const ScrollIntoViewOptions& options) { | |
| 442 GetDocument().EnsurePaintLocationDataValidForNode(this); | 497 GetDocument().EnsurePaintLocationDataValidForNode(this); |
| 443 | 498 |
| 444 if (!GetLayoutObject()) | 499 if (!GetLayoutObject() || !GetDocument().GetPage()) |
| 445 return; | 500 return; |
| 446 | 501 |
| 447 bool make_visible_in_visual_viewport = | 502 bool make_visible_in_visual_viewport = |
| 448 !GetDocument().GetPage()->GetSettings().GetInertVisualViewport(); | 503 !GetDocument().GetPage()->GetSettings().GetInertVisualViewport(); |
| 449 | 504 |
| 505 ScrollBehavior behavior = (options.behavior() == "smooth") | |
| 506 ? kScrollBehaviorSmooth | |
| 507 : kScrollBehaviorAuto; | |
| 508 | |
| 509 ScrollOrientation orientation = GetComputedStyle()->IsHorizontalWritingMode() | |
| 510 ? kHorizontalScroll | |
| 511 : kVerticalScroll; | |
| 512 ScrollAlignment align_x = | |
| 513 ToPhysicalAlignment(options, kHorizontalScroll, orientation); | |
| 514 ScrollAlignment align_y = | |
| 515 ToPhysicalAlignment(options, kVerticalScroll, orientation); | |
| 516 | |
| 517 GetDocument().GetPage()->GetSmoothScrollSequencer()->AbortAnimations(); | |
| 450 LayoutRect bounds = BoundingBox(); | 518 LayoutRect bounds = BoundingBox(); |
| 451 // Align to the top / bottom and to the closest edge. | 519 GetLayoutObject()->ScrollRectToVisible( |
| 452 if (align_to_top) | 520 bounds, align_x, align_y, kProgrammaticScroll, |
| 453 GetLayoutObject()->ScrollRectToVisible( | 521 make_visible_in_visual_viewport, behavior); |
| 454 bounds, ScrollAlignment::kAlignToEdgeIfNeeded, | 522 |
| 455 ScrollAlignment::kAlignTopAlways, kProgrammaticScroll, | 523 GetDocument().GetPage()->GetSmoothScrollSequencer()->RunQueuedAnimations(); |
| 456 make_visible_in_visual_viewport); | |
| 457 else | |
| 458 GetLayoutObject()->ScrollRectToVisible( | |
| 459 bounds, ScrollAlignment::kAlignToEdgeIfNeeded, | |
| 460 ScrollAlignment::kAlignBottomAlways, kProgrammaticScroll, | |
| 461 make_visible_in_visual_viewport); | |
| 462 | 524 |
| 463 GetDocument().SetSequentialFocusNavigationStartingPoint(this); | 525 GetDocument().SetSequentialFocusNavigationStartingPoint(this); |
| 464 } | 526 } |
| 465 | 527 |
| 466 void Element::scrollIntoViewIfNeeded(bool center_if_needed) { | 528 void Element::scrollIntoViewIfNeeded(bool center_if_needed) { |
| 467 GetDocument().EnsurePaintLocationDataValidForNode(this); | 529 GetDocument().EnsurePaintLocationDataValidForNode(this); |
| 468 | 530 |
| 469 if (!GetLayoutObject()) | 531 if (!GetLayoutObject()) |
| 470 return; | 532 return; |
| 471 | 533 |
| (...skipping 3876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4348 } | 4410 } |
| 4349 | 4411 |
| 4350 DEFINE_TRACE_WRAPPERS(Element) { | 4412 DEFINE_TRACE_WRAPPERS(Element) { |
| 4351 if (HasRareData()) { | 4413 if (HasRareData()) { |
| 4352 visitor->TraceWrappers(GetElementRareData()); | 4414 visitor->TraceWrappers(GetElementRareData()); |
| 4353 } | 4415 } |
| 4354 ContainerNode::TraceWrappers(visitor); | 4416 ContainerNode::TraceWrappers(visitor); |
| 4355 } | 4417 } |
| 4356 | 4418 |
| 4357 } // namespace blink | 4419 } // namespace blink |
| OLD | NEW |