Chromium Code Reviews| Index: third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp |
| diff --git a/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp b/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp |
| index 821c591037a4101779d04fa968fa7bf95eff4df7..2dd1de41bdb943475f39318dec12398e1b712a1a 100644 |
| --- a/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp |
| +++ b/third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp |
| @@ -1213,51 +1213,52 @@ IntSize PaintLayerScrollableArea::ScrollbarOffset( |
| return IntSize(); |
| } |
| -static inline const LayoutObject& ScrollbarStyleSource( |
| - const LayoutObject& layout_object) { |
| - if (Node* node = layout_object.GetNode()) { |
| - if (layout_object.IsLayoutView()) { |
| - Document& doc = node->GetDocument(); |
| - if (Settings* settings = doc.GetSettings()) { |
| - if (!settings->GetAllowCustomScrollbarInMainFrame() && |
| - layout_object.GetFrame() && layout_object.GetFrame()->IsMainFrame()) |
| - return layout_object; |
| - } |
| - |
| - // Try the <body> element first as a scrollbar source. |
| - Element* body = doc.body(); |
| - if (body && body->GetLayoutObject() && |
| - body->GetLayoutObject()->Style()->HasPseudoStyle(kPseudoIdScrollbar)) |
| - return *body->GetLayoutObject(); |
| - |
| - // If the <body> didn't have a custom style, then the root element might. |
| - Element* doc_element = doc.documentElement(); |
| - if (doc_element && doc_element->GetLayoutObject() && |
| - doc_element->GetLayoutObject()->Style()->HasPseudoStyle( |
| - kPseudoIdScrollbar)) |
| - return *doc_element->GetLayoutObject(); |
| +LayoutObject* PaintLayerScrollableArea::LayoutObjectForScrollbars() const { |
| + LayoutObject* layout_object = GetLayoutBox(); |
| + Node* node = layout_object->GetNode(); |
| + |
| + if (!node) |
| + return layout_object; |
|
bokan
2017/06/27 17:48:52
Lets return nullptr in this case.
|
| + |
| + if (layout_object->IsLayoutView()) { |
| + Document& doc = node->GetDocument(); |
| + if (Settings* settings = doc.GetSettings()) { |
| + if (!settings->GetAllowCustomScrollbarInMainFrame() && |
| + layout_object->GetFrame() && layout_object->GetFrame()->IsMainFrame()) |
| + return nullptr; |
| } |
| - if (layout_object.StyleRef().HasPseudoStyle(kPseudoIdScrollbar)) |
| - return layout_object; |
| + // Try the <body> element first as a scrollbar source. |
| + Element* body = doc.body(); |
| + if (body && body->GetLayoutObject() && |
| + body->GetLayoutObject()->Style()->HasPseudoStyle(kPseudoIdScrollbar)) |
| + return body->GetLayoutObject(); |
| - if (ShadowRoot* shadow_root = node->ContainingShadowRoot()) { |
| - if (shadow_root->GetType() == ShadowRootType::kUserAgent) { |
| - if (LayoutObject* host_layout_object = |
| - shadow_root->host().GetLayoutObject()) |
| - return *host_layout_object; |
| - } |
| + // If the <body> didn't have a custom style, then the root element might. |
| + Element* doc_element = doc.documentElement(); |
| + if (doc_element && doc_element->GetLayoutObject() && |
| + doc_element->GetLayoutObject()->Style()->HasPseudoStyle( |
| + kPseudoIdScrollbar)) |
| + return doc_element->GetLayoutObject(); |
| + } |
| + |
| + if (layout_object->StyleRef().HasPseudoStyle(kPseudoIdScrollbar)) |
| + return layout_object; |
| + |
| + if (ShadowRoot* shadow_root = node->ContainingShadowRoot()) { |
| + if (shadow_root->GetType() == ShadowRootType::kUserAgent) { |
| + if (LayoutObject* host_layout_object = |
| + shadow_root->host().GetLayoutObject()) |
| + return host_layout_object; |
| } |
| } |
| - return layout_object; |
| + return nullptr; |
| } |
| bool PaintLayerScrollableArea::NeedsScrollbarReconstruction() const { |
| - const LayoutObject& style_source = ScrollbarStyleSource(Box()); |
| - bool should_use_custom = |
| - style_source.IsBox() && |
| - style_source.StyleRef().HasPseudoStyle(kPseudoIdScrollbar); |
| + LayoutObject* style_source = nullptr; |
| + bool should_use_custom = ShouldUseCustomScrollbars(style_source); |
| bool has_any_scrollbar = HasScrollbar(); |
| bool has_custom = |
| (HasHorizontalScrollbar() && |
| @@ -1266,12 +1267,15 @@ bool PaintLayerScrollableArea::NeedsScrollbarReconstruction() const { |
| bool did_custom_scrollbar_owner_changed = false; |
| if (HasHorizontalScrollbar() && HorizontalScrollbar()->IsCustomScrollbar()) { |
| - if (style_source != ToLayoutScrollbar(HorizontalScrollbar())->StyleSource()) |
| + if (style_source && |
| + *style_source != |
| + ToLayoutScrollbar(HorizontalScrollbar())->StyleSource()) |
| did_custom_scrollbar_owner_changed = true; |
| } |
| if (HasVerticalScrollbar() && VerticalScrollbar()->IsCustomScrollbar()) { |
| - if (style_source != ToLayoutScrollbar(VerticalScrollbar())->StyleSource()) |
| + if (style_source && |
| + *style_source != ToLayoutScrollbar(VerticalScrollbar())->StyleSource()) |
| did_custom_scrollbar_owner_changed = true; |
| } |
| @@ -1462,12 +1466,13 @@ void PaintLayerScrollableArea::UpdateScrollCornerStyle() { |
| if (!scroll_corner_ && HasOverlayScrollbars()) |
| return; |
| - const LayoutObject& style_source = ScrollbarStyleSource(Box()); |
| + const LayoutObject* style_source = LayoutObjectForScrollbars(); |
| + |
| RefPtr<ComputedStyle> corner = |
| - Box().HasOverflowClip() |
| - ? style_source.GetUncachedPseudoStyle( |
| + Box().HasOverflowClip() && style_source |
| + ? style_source->GetUncachedPseudoStyle( |
| PseudoStyleRequest(kPseudoIdScrollbarCorner), |
| - style_source.Style()) |
| + style_source->Style()) |
| : PassRefPtr<ComputedStyle>(nullptr); |
| if (corner) { |
| if (!scroll_corner_) { |
| @@ -1625,11 +1630,12 @@ void PaintLayerScrollableArea::UpdateResizerStyle() { |
| if (!resizer_ && !Box().CanResize()) |
| return; |
| - const LayoutObject& style_source = ScrollbarStyleSource(Box()); |
| + const LayoutObject* style_source = LayoutObjectForScrollbars(); |
| + |
| RefPtr<ComputedStyle> resizer = |
| - Box().HasOverflowClip() |
| - ? style_source.GetUncachedPseudoStyle( |
| - PseudoStyleRequest(kPseudoIdResizer), style_source.Style()) |
| + Box().HasOverflowClip() && style_source |
| + ? style_source->GetUncachedPseudoStyle( |
| + PseudoStyleRequest(kPseudoIdResizer), style_source->Style()) |
| : PassRefPtr<ComputedStyle>(nullptr); |
| if (resizer) { |
| if (!resizer_) { |
| @@ -2085,55 +2091,17 @@ void PaintLayerScrollableArea::ScrollbarManager::SetHasVerticalScrollbar( |
| } |
| } |
| -Scrollbar* PaintLayerScrollableArea::ScrollbarManager::CreateScrollbar( |
| +void PaintLayerScrollableArea::WillRemoveScrollbar( |
| + Scrollbar& scrollbar, |
| ScrollbarOrientation orientation) { |
| - DCHECK(orientation == kHorizontalScrollbar ? !h_bar_is_attached_ |
| - : !v_bar_is_attached_); |
| - Scrollbar* scrollbar = nullptr; |
| - const LayoutObject& style_source = |
| - ScrollbarStyleSource(ScrollableArea()->Box()); |
| - bool has_custom_scrollbar_style = |
| - style_source.IsBox() && |
| - style_source.StyleRef().HasPseudoStyle(kPseudoIdScrollbar); |
| - if (has_custom_scrollbar_style) { |
| - DCHECK(style_source.GetNode() && style_source.GetNode()->IsElementNode()); |
| - scrollbar = LayoutScrollbar::CreateCustomScrollbar( |
| - ScrollableArea(), orientation, ToElement(style_source.GetNode())); |
| - } else { |
| - ScrollbarControlSize scrollbar_size = kRegularScrollbar; |
| - if (style_source.StyleRef().HasAppearance()) { |
| - scrollbar_size = LayoutTheme::GetTheme().ScrollbarControlSizeForPart( |
| - style_source.StyleRef().Appearance()); |
| - } |
| - scrollbar = Scrollbar::Create( |
| - ScrollableArea(), orientation, scrollbar_size, |
| - &ScrollableArea()->Box().GetFrame()->GetPage()->GetChromeClient()); |
| - } |
| - ScrollableArea()->Box().GetDocument().View()->AddScrollbar(scrollbar); |
| - return scrollbar; |
| -} |
| - |
| -void PaintLayerScrollableArea::ScrollbarManager::DestroyScrollbar( |
| - ScrollbarOrientation orientation) { |
| - Member<Scrollbar>& scrollbar = |
| - orientation == kHorizontalScrollbar ? h_bar_ : v_bar_; |
| - DCHECK(orientation == kHorizontalScrollbar ? !h_bar_is_attached_ |
| - : !v_bar_is_attached_); |
| - if (!scrollbar) |
| - return; |
| - |
| - ScrollableArea()->SetScrollbarNeedsPaintInvalidation(orientation); |
| + SetScrollbarNeedsPaintInvalidation(orientation); |
| if (orientation == kHorizontalScrollbar) |
| - ScrollableArea()->rebuild_horizontal_scrollbar_layer_ = true; |
| + rebuild_horizontal_scrollbar_layer_ = true; |
| else |
| - ScrollableArea()->rebuild_vertical_scrollbar_layer_ = true; |
| - |
| - if (!scrollbar->IsCustomScrollbar()) |
| - ScrollableArea()->WillRemoveScrollbar(*scrollbar, orientation); |
| + rebuild_vertical_scrollbar_layer_ = true; |
| - ScrollableArea()->Box().GetDocument().View()->RemoveScrollbar(scrollbar); |
| - scrollbar->DisconnectFromScrollableArea(); |
| - scrollbar = nullptr; |
| + PaintInvalidationCapableScrollableArea::WillRemoveScrollbar(scrollbar, |
| + orientation); |
| } |
| uint64_t PaintLayerScrollableArea::Id() const { |