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 "bindings/core/v8/DOMDataStore.h" | 29 #include "bindings/core/v8/DOMDataStore.h" |
| 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 "bindings/core/v8/V8DOMWrapper.h" | 35 #include "bindings/core/v8/V8DOMWrapper.h" |
| 35 #include "bindings/core/v8/V8PerContextData.h" | 36 #include "bindings/core/v8/V8PerContextData.h" |
| 36 #include "core/CSSValueKeywords.h" | 37 #include "core/CSSValueKeywords.h" |
| 37 #include "core/SVGNames.h" | 38 #include "core/SVGNames.h" |
| 38 #include "core/XMLNames.h" | 39 #include "core/XMLNames.h" |
| 39 #include "core/animation/AnimationTimeline.h" | 40 #include "core/animation/AnimationTimeline.h" |
| 40 #include "core/animation/CustomCompositorAnimations.h" | 41 #include "core/animation/CustomCompositorAnimations.h" |
| 41 #include "core/animation/css/CSSAnimations.h" | 42 #include "core/animation/css/CSSAnimations.h" |
| 42 #include "core/css/CSSIdentifierValue.h" | 43 #include "core/css/CSSIdentifierValue.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 #include "core/editing/FrameSelection.h" | 91 #include "core/editing/FrameSelection.h" |
| 91 #include "core/editing/iterators/TextIterator.h" | 92 #include "core/editing/iterators/TextIterator.h" |
| 92 #include "core/editing/serializers/Serialization.h" | 93 #include "core/editing/serializers/Serialization.h" |
| 93 #include "core/events/EventDispatcher.h" | 94 #include "core/events/EventDispatcher.h" |
| 94 #include "core/events/FocusEvent.h" | 95 #include "core/events/FocusEvent.h" |
| 95 #include "core/frame/FrameHost.h" | 96 #include "core/frame/FrameHost.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 14 matching lines...) Expand all Loading... | |
| 124 #include "core/loader/DocumentLoader.h" | 126 #include "core/loader/DocumentLoader.h" |
| 125 #include "core/page/ChromeClient.h" | 127 #include "core/page/ChromeClient.h" |
| 126 #include "core/page/FocusController.h" | 128 #include "core/page/FocusController.h" |
| 127 #include "core/page/Page.h" | 129 #include "core/page/Page.h" |
| 128 #include "core/page/PointerLockController.h" | 130 #include "core/page/PointerLockController.h" |
| 129 #include "core/page/SpatialNavigation.h" | 131 #include "core/page/SpatialNavigation.h" |
| 130 #include "core/page/scrolling/RootScrollerController.h" | 132 #include "core/page/scrolling/RootScrollerController.h" |
| 131 #include "core/page/scrolling/ScrollCustomizationCallbacks.h" | 133 #include "core/page/scrolling/ScrollCustomizationCallbacks.h" |
| 132 #include "core/page/scrolling/ScrollState.h" | 134 #include "core/page/scrolling/ScrollState.h" |
| 133 #include "core/page/scrolling/ScrollStateCallback.h" | 135 #include "core/page/scrolling/ScrollStateCallback.h" |
| 136 #include "core/page/scrolling/ScrollingCoordinator.h" | |
| 134 #include "core/page/scrolling/TopDocumentRootScrollerController.h" | 137 #include "core/page/scrolling/TopDocumentRootScrollerController.h" |
| 135 #include "core/paint/PaintLayer.h" | 138 #include "core/paint/PaintLayer.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" |
| 146 #include "platform/scroll/ProgrammaticScrollCoordinator.h" | |
| 143 #include "platform/scroll/ScrollableArea.h" | 147 #include "platform/scroll/ScrollableArea.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 #include <memory> | 153 #include <memory> |
| 150 | 154 |
| 151 namespace blink { | 155 namespace blink { |
| 152 | 156 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 synchronizeAttribute(name); | 425 synchronizeAttribute(name); |
| 422 if (const Attribute* attribute = elementData()->attributes().find(name)) | 426 if (const Attribute* attribute = elementData()->attributes().find(name)) |
| 423 return attribute->value(); | 427 return attribute->value(); |
| 424 return nullAtom; | 428 return nullAtom; |
| 425 } | 429 } |
| 426 | 430 |
| 427 bool Element::shouldIgnoreAttributeCase() const { | 431 bool Element::shouldIgnoreAttributeCase() const { |
| 428 return isHTMLElement() && document().isHTMLDocument(); | 432 return isHTMLElement() && document().isHTMLDocument(); |
| 429 } | 433 } |
| 430 | 434 |
| 431 void Element::scrollIntoView(bool alignToTop) { | 435 void Element::scrollIntoView(ExceptionState& exception) { |
| 436 ScrollIntoViewOptions options; | |
| 437 options.setBlock("start"); | |
|
bokan
2017/02/02 22:51:49
according to the spec we should also initialize th
sunyunjia
2017/02/10 23:25:20
Done.
| |
| 438 scrollIntoViewWithOptions(options); | |
| 439 } | |
| 440 | |
| 441 void Element::scrollIntoView(ScrollIntoViewOptionsOrBoolean arg, | |
| 442 ExceptionState& exception) { | |
| 443 ScrollIntoViewOptions options; | |
| 444 if (arg.isBoolean()) { | |
| 445 if (arg.getAsBoolean()) | |
| 446 options.setBlock("end"); | |
|
bokan
2017/02/02 22:51:49
Similarly, we need to set |inline| here too.
sunyunjia
2017/02/10 23:25:20
Done.
| |
| 447 else | |
| 448 options.setBlock("start"); | |
| 449 scrollIntoViewWithOptions(options); | |
| 450 } else if (arg.isScrollIntoViewOptions()) { | |
| 451 options = arg.getAsScrollIntoViewOptions(); | |
| 452 if (!RuntimeEnabledFeatures::cssomSmoothScrollEnabled() && | |
| 453 options.behavior() == "smooth") { | |
| 454 exception.throwTypeError( | |
| 455 "Smooth ScrollIntoView is an Experimental Web" | |
| 456 " Platform Feature, go to chrome://flags to enable it."); | |
| 457 return; | |
| 458 } | |
| 459 scrollIntoViewWithOptions(options); | |
|
bokan
2017/02/02 22:51:49
move this below the if statement, make the "else"
sunyunjia
2017/02/10 23:25:20
Done.
| |
| 460 } else { | |
| 461 exception.throwTypeError( | |
| 462 "ScrollIntoView only supports bool or" | |
| 463 " ScrollIntoViewOptions as argument."); | |
| 464 } | |
| 465 } | |
| 466 | |
| 467 void Element::scrollIntoViewWithOptions(const ScrollIntoViewOptions& options) { | |
| 432 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); | 468 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); |
| 433 | 469 |
| 434 if (!layoutObject()) | 470 if (!layoutObject()) |
| 435 return; | 471 return; |
| 436 | 472 |
| 437 bool makeVisibleInVisualViewport = | 473 bool makeVisibleInVisualViewport = |
| 438 !document().page()->settings().getInertVisualViewport(); | 474 !document().page()->settings().getInertVisualViewport(); |
| 439 | 475 |
| 476 ScrollBehavior behavior = ScrollBehaviorAuto; | |
| 477 if (options.behavior() == "smooth") { | |
| 478 behavior = ScrollBehaviorSmooth; | |
| 479 } | |
| 480 // Align to the top / bottom and to the closest edge. | |
| 481 ScrollAlignment alignment = ScrollAlignment::alignCenterAlways; | |
| 482 if (options.block() == "start") | |
| 483 alignment = ScrollAlignment::alignTopAlways; | |
| 484 if (options.block() == "end") | |
|
bokan
2017/02/02 22:51:49
use |else if|
sunyunjia
2017/02/10 23:25:20
Done.
| |
| 485 alignment = ScrollAlignment::alignBottomAlways; | |
| 486 if (options.block() == "nearest") | |
|
bokan
2017/02/02 22:51:49
should this be "center"? "nearest" from the spec a
sunyunjia
2017/02/10 23:25:20
Done.
| |
| 487 alignment = ScrollAlignment::alignCenterAlways; | |
| 488 | |
| 440 LayoutRect bounds = boundingBox(); | 489 LayoutRect bounds = boundingBox(); |
| 441 // Align to the top / bottom and to the closest edge. | 490 layoutObject()->scrollRectToVisible( |
| 442 if (alignToTop) | 491 bounds, ScrollAlignment::alignToEdgeIfNeeded, alignment, |
|
bokan
2017/02/02 22:51:49
How come we don't do anything for the inline direc
sunyunjia
2017/02/10 23:25:20
Done. I'm simply using x as inline direction and y
bokan
2017/02/21 21:33:00
For western languages that's right, x is inline an
| |
| 443 layoutObject()->scrollRectToVisible( | 492 ProgrammaticScroll, makeVisibleInVisualViewport, behavior); |
| 444 bounds, ScrollAlignment::alignToEdgeIfNeeded, | 493 |
| 445 ScrollAlignment::alignTopAlways, ProgrammaticScroll, | 494 document() |
| 446 makeVisibleInVisualViewport); | 495 .page() |
| 447 else | 496 ->scrollingCoordinator() |
| 448 layoutObject()->scrollRectToVisible( | 497 ->programmaticScrollCoordinator() |
| 449 bounds, ScrollAlignment::alignToEdgeIfNeeded, | 498 ->runQueuedAnimations(); |
| 450 ScrollAlignment::alignBottomAlways, ProgrammaticScroll, | |
| 451 makeVisibleInVisualViewport); | |
| 452 | 499 |
| 453 document().setSequentialFocusNavigationStartingPoint(this); | 500 document().setSequentialFocusNavigationStartingPoint(this); |
| 454 } | 501 } |
| 455 | 502 |
| 456 void Element::scrollIntoViewIfNeeded(bool centerIfNeeded) { | 503 void Element::scrollIntoViewIfNeeded(bool centerIfNeeded) { |
| 457 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); | 504 document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); |
| 458 | 505 |
| 459 if (!layoutObject()) | 506 if (!layoutObject()) |
| 460 return; | 507 return; |
| 461 | 508 |
| (...skipping 3666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4128 } | 4175 } |
| 4129 | 4176 |
| 4130 DEFINE_TRACE_WRAPPERS(Element) { | 4177 DEFINE_TRACE_WRAPPERS(Element) { |
| 4131 if (hasRareData()) { | 4178 if (hasRareData()) { |
| 4132 visitor->traceWrappers(elementRareData()); | 4179 visitor->traceWrappers(elementRareData()); |
| 4133 } | 4180 } |
| 4134 ContainerNode::traceWrappers(visitor); | 4181 ContainerNode::traceWrappers(visitor); |
| 4135 } | 4182 } |
| 4136 | 4183 |
| 4137 } // namespace blink | 4184 } // namespace blink |
| OLD | NEW |