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 13 matching lines...) Expand all Loading... | |
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/DOMDataStore.h" | 30 #include "bindings/core/v8/DOMDataStore.h" |
31 #include "bindings/core/v8/Dictionary.h" | 31 #include "bindings/core/v8/Dictionary.h" |
32 #include "bindings/core/v8/ExceptionMessages.h" | 32 #include "bindings/core/v8/ExceptionMessages.h" |
33 #include "bindings/core/v8/ExceptionState.h" | 33 #include "bindings/core/v8/ExceptionState.h" |
34 #include "bindings/core/v8/ScrollIntoViewOptionsOrBoolean.h" | |
34 #include "bindings/core/v8/V8DOMActivityLogger.h" | 35 #include "bindings/core/v8/V8DOMActivityLogger.h" |
35 #include "bindings/core/v8/V8DOMWrapper.h" | 36 #include "bindings/core/v8/V8DOMWrapper.h" |
36 #include "bindings/core/v8/V8PerContextData.h" | 37 #include "bindings/core/v8/V8PerContextData.h" |
37 #include "core/CSSValueKeywords.h" | 38 #include "core/CSSValueKeywords.h" |
38 #include "core/SVGNames.h" | 39 #include "core/SVGNames.h" |
39 #include "core/XMLNames.h" | 40 #include "core/XMLNames.h" |
40 #include "core/animation/AnimationTimeline.h" | 41 #include "core/animation/AnimationTimeline.h" |
41 #include "core/animation/CustomCompositorAnimations.h" | 42 #include "core/animation/CustomCompositorAnimations.h" |
42 #include "core/animation/css/CSSAnimations.h" | 43 #include "core/animation/css/CSSAnimations.h" |
43 #include "core/css/CSSIdentifierValue.h" | 44 #include "core/css/CSSIdentifierValue.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 #include "core/editing/EditingUtilities.h" | 91 #include "core/editing/EditingUtilities.h" |
91 #include "core/editing/FrameSelection.h" | 92 #include "core/editing/FrameSelection.h" |
92 #include "core/editing/iterators/TextIterator.h" | 93 #include "core/editing/iterators/TextIterator.h" |
93 #include "core/editing/serializers/Serialization.h" | 94 #include "core/editing/serializers/Serialization.h" |
94 #include "core/events/EventDispatcher.h" | 95 #include "core/events/EventDispatcher.h" |
95 #include "core/events/FocusEvent.h" | 96 #include "core/events/FocusEvent.h" |
96 #include "core/frame/FrameView.h" | 97 #include "core/frame/FrameView.h" |
97 #include "core/frame/HostsUsingFeatures.h" | 98 #include "core/frame/HostsUsingFeatures.h" |
98 #include "core/frame/LocalDOMWindow.h" | 99 #include "core/frame/LocalDOMWindow.h" |
99 #include "core/frame/LocalFrame.h" | 100 #include "core/frame/LocalFrame.h" |
101 #include "core/frame/ScrollIntoViewOptions.h" | |
100 #include "core/frame/ScrollToOptions.h" | 102 #include "core/frame/ScrollToOptions.h" |
101 #include "core/frame/Settings.h" | 103 #include "core/frame/Settings.h" |
102 #include "core/frame/UseCounter.h" | 104 #include "core/frame/UseCounter.h" |
103 #include "core/frame/VisualViewport.h" | 105 #include "core/frame/VisualViewport.h" |
104 #include "core/frame/csp/ContentSecurityPolicy.h" | 106 #include "core/frame/csp/ContentSecurityPolicy.h" |
105 #include "core/html/ClassList.h" | 107 #include "core/html/ClassList.h" |
106 #include "core/html/HTMLCanvasElement.h" | 108 #include "core/html/HTMLCanvasElement.h" |
107 #include "core/html/HTMLCollection.h" | 109 #include "core/html/HTMLCollection.h" |
108 #include "core/html/HTMLDocument.h" | 110 #include "core/html/HTMLDocument.h" |
109 #include "core/html/HTMLElement.h" | 111 #include "core/html/HTMLElement.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
123 #include "core/loader/DocumentLoader.h" | 125 #include "core/loader/DocumentLoader.h" |
124 #include "core/page/ChromeClient.h" | 126 #include "core/page/ChromeClient.h" |
125 #include "core/page/FocusController.h" | 127 #include "core/page/FocusController.h" |
126 #include "core/page/Page.h" | 128 #include "core/page/Page.h" |
127 #include "core/page/PointerLockController.h" | 129 #include "core/page/PointerLockController.h" |
128 #include "core/page/SpatialNavigation.h" | 130 #include "core/page/SpatialNavigation.h" |
129 #include "core/page/scrolling/RootScrollerController.h" | 131 #include "core/page/scrolling/RootScrollerController.h" |
130 #include "core/page/scrolling/ScrollCustomizationCallbacks.h" | 132 #include "core/page/scrolling/ScrollCustomizationCallbacks.h" |
131 #include "core/page/scrolling/ScrollState.h" | 133 #include "core/page/scrolling/ScrollState.h" |
132 #include "core/page/scrolling/ScrollStateCallback.h" | 134 #include "core/page/scrolling/ScrollStateCallback.h" |
135 #include "core/page/scrolling/ScrollingCoordinator.h" | |
bokan
2017/04/07 15:56:52
Unused, remove.
sunyunjia
2017/05/12 18:40:24
Done.
| |
133 #include "core/page/scrolling/TopDocumentRootScrollerController.h" | 136 #include "core/page/scrolling/TopDocumentRootScrollerController.h" |
134 #include "core/paint/PaintLayer.h" | 137 #include "core/paint/PaintLayer.h" |
135 #include "core/probe/CoreProbes.h" | 138 #include "core/probe/CoreProbes.h" |
136 #include "core/svg/SVGAElement.h" | 139 #include "core/svg/SVGAElement.h" |
137 #include "core/svg/SVGElement.h" | 140 #include "core/svg/SVGElement.h" |
138 #include "core/svg/SVGTreeScopeResources.h" | 141 #include "core/svg/SVGTreeScopeResources.h" |
139 #include "platform/EventDispatchForbiddenScope.h" | 142 #include "platform/EventDispatchForbiddenScope.h" |
140 #include "platform/RuntimeEnabledFeatures.h" | 143 #include "platform/RuntimeEnabledFeatures.h" |
141 #include "platform/graphics/CompositorMutableProperties.h" | 144 #include "platform/graphics/CompositorMutableProperties.h" |
142 #include "platform/graphics/CompositorMutation.h" | 145 #include "platform/graphics/CompositorMutation.h" |
143 #include "platform/scroll/ScrollableArea.h" | 146 #include "platform/scroll/ScrollableArea.h" |
147 #include "platform/scroll/SmoothScrollSequencer.h" | |
144 #include "wtf/BitVector.h" | 148 #include "wtf/BitVector.h" |
145 #include "wtf/HashFunctions.h" | 149 #include "wtf/HashFunctions.h" |
146 #include "wtf/text/CString.h" | 150 #include "wtf/text/CString.h" |
147 #include "wtf/text/StringBuilder.h" | 151 #include "wtf/text/StringBuilder.h" |
148 #include "wtf/text/TextPosition.h" | 152 #include "wtf/text/TextPosition.h" |
149 | 153 |
150 namespace blink { | 154 namespace blink { |
151 | 155 |
152 namespace { | 156 namespace { |
153 | 157 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 synchronizeAttribute(name); | 424 synchronizeAttribute(name); |
421 if (const Attribute* attribute = elementData()->attributes().find(name)) | 425 if (const Attribute* attribute = elementData()->attributes().find(name)) |
422 return attribute->value(); | 426 return attribute->value(); |
423 return nullAtom; | 427 return nullAtom; |
424 } | 428 } |
425 | 429 |
426 bool Element::shouldIgnoreAttributeCase() const { | 430 bool Element::shouldIgnoreAttributeCase() const { |
427 return isHTMLElement() && document().isHTMLDocument(); | 431 return isHTMLElement() && document().isHTMLDocument(); |
428 } | 432 } |
429 | 433 |
434 void Element::scrollIntoView(ScrollIntoViewOptionsOrBoolean arg) { | |
435 ScrollIntoViewOptions options; | |
436 if (arg.isBoolean()) { | |
437 if (arg.getAsBoolean()) | |
438 options.setBlock("start"); | |
439 else | |
440 options.setBlock("end"); | |
441 options.setInlinePosition("nearest"); | |
442 } else if (arg.isScrollIntoViewOptions()) { | |
443 options = arg.getAsScrollIntoViewOptions(); | |
444 if (!RuntimeEnabledFeatures::cssomSmoothScrollEnabled() && | |
445 options.behavior() == "smooth") { | |
446 options.setBehavior("instant"); | |
447 } | |
448 } | |
449 scrollIntoViewWithOptions(options); | |
450 } | |
451 | |
430 void Element::scrollIntoView(bool alignToTop) { | 452 void Element::scrollIntoView(bool alignToTop) { |
453 ScrollIntoViewOptions options; | |
454 if (alignToTop) | |
455 options.setBlock("start"); | |
456 else | |
457 options.setBlock("end"); | |
458 options.setInlinePosition("nearest"); | |
459 scrollIntoViewWithOptions(options); | |
460 } | |
461 | |
462 void Element::scrollIntoViewWithOptions(const ScrollIntoViewOptions& options) { | |
431 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); | 463 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); |
432 | 464 |
433 if (!layoutObject()) | 465 if (!layoutObject()) |
434 return; | 466 return; |
435 | 467 |
436 bool makeVisibleInVisualViewport = | 468 bool makeVisibleInVisualViewport = |
437 !document().page()->settings().getInertVisualViewport(); | 469 !document().page()->settings().getInertVisualViewport(); |
438 | 470 |
471 ScrollBehavior behavior = ScrollBehaviorAuto; | |
472 if (options.behavior() == "smooth") { | |
473 behavior = ScrollBehaviorSmooth; | |
474 } | |
475 // Block Alignment to the top / bottom and to the closest edge. | |
476 ScrollAlignment blockAlignment = ScrollAlignment::alignTopAlways; | |
477 if (options.block() == "center") | |
478 blockAlignment = ScrollAlignment::alignCenterAlways; | |
479 else if (options.block() == "end") | |
480 blockAlignment = ScrollAlignment::alignBottomAlways; | |
481 else if (options.block() == "nearest") | |
482 blockAlignment = ScrollAlignment::alignToEdgeIfNeeded; | |
483 | |
484 // Inline Alignment to the top / bottom and to the closest edge. | |
bokan
2017/04/07 15:56:52
Should this be left / right, rather than top / bot
sunyunjia
2017/05/12 18:40:24
Done.
| |
485 ScrollAlignment inlineAlignment = ScrollAlignment::alignToEdgeIfNeeded; | |
bokan
2017/04/07 15:56:52
For consistency with the above block, default to a
sunyunjia
2017/05/12 18:40:24
I set the default value according to the spec: htt
bokan
2017/05/15 17:15:27
Ah, thanks and sorry, I missed that that was speci
| |
486 if (options.inlinePosition() == "start") | |
487 inlineAlignment = ScrollAlignment::alignLeftAlways; | |
488 else if (options.inlinePosition() == "center") | |
489 inlineAlignment = ScrollAlignment::alignCenterAlways; | |
490 else if (options.inlinePosition() == "end") | |
491 inlineAlignment = ScrollAlignment::alignRightAlways; | |
492 | |
439 LayoutRect bounds = boundingBox(); | 493 LayoutRect bounds = boundingBox(); |
440 // Align to the top / bottom and to the closest edge. | 494 layoutObject()->scrollRectToVisible(bounds, inlineAlignment, blockAlignment, |
441 if (alignToTop) | 495 ProgrammaticScroll, |
442 layoutObject()->scrollRectToVisible( | 496 makeVisibleInVisualViewport, behavior); |
443 bounds, ScrollAlignment::alignToEdgeIfNeeded, | 497 |
444 ScrollAlignment::alignTopAlways, ProgrammaticScroll, | 498 if (document().page()) { |
bokan
2017/04/07 15:56:52
nit: remove braces
sunyunjia
2017/05/12 18:40:24
Done.
| |
445 makeVisibleInVisualViewport); | 499 document().page()->smoothScrollSequencer()->runQueuedAnimations(); |
446 else | 500 } |
447 layoutObject()->scrollRectToVisible( | |
448 bounds, ScrollAlignment::alignToEdgeIfNeeded, | |
449 ScrollAlignment::alignBottomAlways, ProgrammaticScroll, | |
450 makeVisibleInVisualViewport); | |
451 | 501 |
452 document().setSequentialFocusNavigationStartingPoint(this); | 502 document().setSequentialFocusNavigationStartingPoint(this); |
453 } | 503 } |
454 | 504 |
455 void Element::scrollIntoViewIfNeeded(bool centerIfNeeded) { | 505 void Element::scrollIntoViewIfNeeded(bool centerIfNeeded) { |
456 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); | 506 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); |
457 | 507 |
458 if (!layoutObject()) | 508 if (!layoutObject()) |
459 return; | 509 return; |
460 | 510 |
(...skipping 3828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4289 } | 4339 } |
4290 | 4340 |
4291 DEFINE_TRACE_WRAPPERS(Element) { | 4341 DEFINE_TRACE_WRAPPERS(Element) { |
4292 if (hasRareData()) { | 4342 if (hasRareData()) { |
4293 visitor->traceWrappers(elementRareData()); | 4343 visitor->traceWrappers(elementRareData()); |
4294 } | 4344 } |
4295 ContainerNode::traceWrappers(visitor); | 4345 ContainerNode::traceWrappers(visitor); |
4296 } | 4346 } |
4297 | 4347 |
4298 } // namespace blink | 4348 } // namespace blink |
OLD | NEW |