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" | |
34 #include "bindings/core/v8/V8DOMActivityLogger.h" | 33 #include "bindings/core/v8/V8DOMActivityLogger.h" |
35 #include "core/CSSValueKeywords.h" | 34 #include "core/CSSValueKeywords.h" |
36 #include "core/SVGNames.h" | 35 #include "core/SVGNames.h" |
37 #include "core/XMLNames.h" | 36 #include "core/XMLNames.h" |
38 #include "core/animation/AnimationTimeline.h" | 37 #include "core/animation/AnimationTimeline.h" |
39 #include "core/animation/CustomCompositorAnimations.h" | 38 #include "core/animation/CustomCompositorAnimations.h" |
40 #include "core/animation/css/CSSAnimations.h" | 39 #include "core/animation/css/CSSAnimations.h" |
41 #include "core/css/CSSIdentifierValue.h" | 40 #include "core/css/CSSIdentifierValue.h" |
42 #include "core/css/CSSPrimitiveValue.h" | 41 #include "core/css/CSSPrimitiveValue.h" |
43 #include "core/css/CSSStyleSheet.h" | 42 #include "core/css/CSSStyleSheet.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 #include "core/editing/EditingUtilities.h" | 88 #include "core/editing/EditingUtilities.h" |
90 #include "core/editing/FrameSelection.h" | 89 #include "core/editing/FrameSelection.h" |
91 #include "core/editing/iterators/TextIterator.h" | 90 #include "core/editing/iterators/TextIterator.h" |
92 #include "core/editing/serializers/Serialization.h" | 91 #include "core/editing/serializers/Serialization.h" |
93 #include "core/events/EventDispatcher.h" | 92 #include "core/events/EventDispatcher.h" |
94 #include "core/events/FocusEvent.h" | 93 #include "core/events/FocusEvent.h" |
95 #include "core/frame/HostsUsingFeatures.h" | 94 #include "core/frame/HostsUsingFeatures.h" |
96 #include "core/frame/LocalDOMWindow.h" | 95 #include "core/frame/LocalDOMWindow.h" |
97 #include "core/frame/LocalFrame.h" | 96 #include "core/frame/LocalFrame.h" |
98 #include "core/frame/LocalFrameView.h" | 97 #include "core/frame/LocalFrameView.h" |
99 #include "core/frame/ScrollIntoViewOptions.h" | |
100 #include "core/frame/ScrollToOptions.h" | 98 #include "core/frame/ScrollToOptions.h" |
101 #include "core/frame/Settings.h" | 99 #include "core/frame/Settings.h" |
102 #include "core/frame/UseCounter.h" | 100 #include "core/frame/UseCounter.h" |
103 #include "core/frame/VisualViewport.h" | 101 #include "core/frame/VisualViewport.h" |
104 #include "core/frame/csp/ContentSecurityPolicy.h" | 102 #include "core/frame/csp/ContentSecurityPolicy.h" |
105 #include "core/html/HTMLCanvasElement.h" | 103 #include "core/html/HTMLCanvasElement.h" |
106 #include "core/html/HTMLCollection.h" | 104 #include "core/html/HTMLCollection.h" |
107 #include "core/html/HTMLDocument.h" | 105 #include "core/html/HTMLDocument.h" |
108 #include "core/html/HTMLElement.h" | 106 #include "core/html/HTMLElement.h" |
109 #include "core/html/HTMLFormControlsCollection.h" | 107 #include "core/html/HTMLFormControlsCollection.h" |
(...skipping 26 matching lines...) Expand all Loading... |
136 #include "core/svg/SVGElement.h" | 134 #include "core/svg/SVGElement.h" |
137 #include "core/svg/SVGTreeScopeResources.h" | 135 #include "core/svg/SVGTreeScopeResources.h" |
138 #include "platform/EventDispatchForbiddenScope.h" | 136 #include "platform/EventDispatchForbiddenScope.h" |
139 #include "platform/RuntimeEnabledFeatures.h" | 137 #include "platform/RuntimeEnabledFeatures.h" |
140 #include "platform/bindings/DOMDataStore.h" | 138 #include "platform/bindings/DOMDataStore.h" |
141 #include "platform/bindings/V8DOMWrapper.h" | 139 #include "platform/bindings/V8DOMWrapper.h" |
142 #include "platform/bindings/V8PerContextData.h" | 140 #include "platform/bindings/V8PerContextData.h" |
143 #include "platform/graphics/CompositorMutableProperties.h" | 141 #include "platform/graphics/CompositorMutableProperties.h" |
144 #include "platform/graphics/CompositorMutation.h" | 142 #include "platform/graphics/CompositorMutation.h" |
145 #include "platform/scroll/ScrollableArea.h" | 143 #include "platform/scroll/ScrollableArea.h" |
146 #include "platform/scroll/SmoothScrollSequencer.h" | |
147 #include "platform/wtf/BitVector.h" | 144 #include "platform/wtf/BitVector.h" |
148 #include "platform/wtf/HashFunctions.h" | 145 #include "platform/wtf/HashFunctions.h" |
149 #include "platform/wtf/text/CString.h" | 146 #include "platform/wtf/text/CString.h" |
150 #include "platform/wtf/text/StringBuilder.h" | 147 #include "platform/wtf/text/StringBuilder.h" |
151 #include "platform/wtf/text/TextPosition.h" | 148 #include "platform/wtf/text/TextPosition.h" |
152 | 149 |
153 namespace blink { | 150 namespace blink { |
154 | 151 |
155 namespace { | 152 namespace { |
156 | 153 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 431 } |
435 | 432 |
436 const AtomicString& Element::nonce() const { | 433 const AtomicString& Element::nonce() const { |
437 return HasRareData() ? GetElementRareData()->GetNonce() : g_empty_atom; | 434 return HasRareData() ? GetElementRareData()->GetNonce() : g_empty_atom; |
438 } | 435 } |
439 | 436 |
440 void Element::setNonce(const AtomicString& nonce) { | 437 void Element::setNonce(const AtomicString& nonce) { |
441 EnsureElementRareData().SetNonce(nonce); | 438 EnsureElementRareData().SetNonce(nonce); |
442 } | 439 } |
443 | 440 |
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 | |
462 void Element::scrollIntoView(bool align_to_top) { | 441 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 bool is_horizontal_writing_mode) { | |
471 String alignment = | |
472 ((axis == kHorizontalScroll && is_horizontal_writing_mode) || | |
473 (axis == kVerticalScroll && !is_horizontal_writing_mode)) | |
474 ? options.inlinePosition() | |
475 : options.block(); | |
476 | |
477 if (alignment == "center") | |
478 return ScrollAlignment::kAlignCenterAlways; | |
479 if (alignment == "nearest") | |
480 return ScrollAlignment::kAlignToEdgeIfNeeded; | |
481 if (alignment == "start") { | |
482 return (axis == kHorizontalScroll) ? ScrollAlignment::kAlignLeftAlways | |
483 : ScrollAlignment::kAlignTopAlways; | |
484 } | |
485 if (alignment == "end") { | |
486 return (axis == kHorizontalScroll) ? ScrollAlignment::kAlignRightAlways | |
487 : ScrollAlignment::kAlignBottomAlways; | |
488 } | |
489 | |
490 // Default values | |
491 if (is_horizontal_writing_mode) { | |
492 return (axis == kHorizontalScroll) ? ScrollAlignment::kAlignToEdgeIfNeeded | |
493 : ScrollAlignment::kAlignTopAlways; | |
494 } | |
495 return (axis == kHorizontalScroll) ? ScrollAlignment::kAlignLeftAlways | |
496 : ScrollAlignment::kAlignToEdgeIfNeeded; | |
497 } | |
498 | |
499 void Element::scrollIntoViewWithOptions(const ScrollIntoViewOptions& options) { | |
500 GetDocument().EnsurePaintLocationDataValidForNode(this); | 442 GetDocument().EnsurePaintLocationDataValidForNode(this); |
501 | 443 |
502 if (!GetLayoutObject() || !GetDocument().GetPage()) | 444 if (!GetLayoutObject()) |
503 return; | 445 return; |
504 | 446 |
505 bool make_visible_in_visual_viewport = | 447 bool make_visible_in_visual_viewport = |
506 !GetDocument().GetPage()->GetSettings().GetInertVisualViewport(); | 448 !GetDocument().GetPage()->GetSettings().GetInertVisualViewport(); |
507 | 449 |
508 ScrollBehavior behavior = (options.behavior() == "smooth") | |
509 ? kScrollBehaviorSmooth | |
510 : kScrollBehaviorAuto; | |
511 | |
512 bool is_horizontal_writing_mode = | |
513 GetComputedStyle()->IsHorizontalWritingMode(); | |
514 ScrollAlignment align_x = ToPhysicalAlignment(options, kHorizontalScroll, | |
515 is_horizontal_writing_mode); | |
516 ScrollAlignment align_y = | |
517 ToPhysicalAlignment(options, kVerticalScroll, is_horizontal_writing_mode); | |
518 | |
519 GetDocument().GetPage()->GetSmoothScrollSequencer()->AbortAnimations(); | |
520 LayoutRect bounds = BoundingBox(); | 450 LayoutRect bounds = BoundingBox(); |
521 GetLayoutObject()->ScrollRectToVisible( | 451 // Align to the top / bottom and to the closest edge. |
522 bounds, align_x, align_y, kProgrammaticScroll, | 452 if (align_to_top) |
523 make_visible_in_visual_viewport, behavior); | 453 GetLayoutObject()->ScrollRectToVisible( |
524 | 454 bounds, ScrollAlignment::kAlignToEdgeIfNeeded, |
525 GetDocument().GetPage()->GetSmoothScrollSequencer()->RunQueuedAnimations(); | 455 ScrollAlignment::kAlignTopAlways, kProgrammaticScroll, |
| 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); |
526 | 462 |
527 GetDocument().SetSequentialFocusNavigationStartingPoint(this); | 463 GetDocument().SetSequentialFocusNavigationStartingPoint(this); |
528 } | 464 } |
529 | 465 |
530 void Element::scrollIntoViewIfNeeded(bool center_if_needed) { | 466 void Element::scrollIntoViewIfNeeded(bool center_if_needed) { |
531 GetDocument().EnsurePaintLocationDataValidForNode(this); | 467 GetDocument().EnsurePaintLocationDataValidForNode(this); |
532 | 468 |
533 if (!GetLayoutObject()) | 469 if (!GetLayoutObject()) |
534 return; | 470 return; |
535 | 471 |
(...skipping 3881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4417 } | 4353 } |
4418 | 4354 |
4419 DEFINE_TRACE_WRAPPERS(Element) { | 4355 DEFINE_TRACE_WRAPPERS(Element) { |
4420 if (HasRareData()) { | 4356 if (HasRareData()) { |
4421 visitor->TraceWrappers(GetElementRareData()); | 4357 visitor->TraceWrappers(GetElementRareData()); |
4422 } | 4358 } |
4423 ContainerNode::TraceWrappers(visitor); | 4359 ContainerNode::TraceWrappers(visitor); |
4424 } | 4360 } |
4425 | 4361 |
4426 } // namespace blink | 4362 } // namespace blink |
OLD | NEW |