Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: third_party/WebKit/Source/core/frame/LocalFrameView.cpp

Issue 2942163002: [Refactor] Moved scrollbar creation and deletion to ScrollbarManager (Closed)
Patch Set: change ShouldUseCustomScrollbars Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Dirk Mueller <mueller@kde.org> 5 * 2000 Dirk Mueller <mueller@kde.org>
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * Copyright (C) 2009 Google Inc. All rights reserved. 9 * Copyright (C) 2009 Google Inc. All rights reserved.
10 * 10 *
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 scrollable_area_->DidAddScrollbar(*v_bar_, kVerticalScrollbar); 470 scrollable_area_->DidAddScrollbar(*v_bar_, kVerticalScrollbar);
471 v_bar_->StyleChanged(); 471 v_bar_->StyleChanged();
472 } else { 472 } else {
473 v_bar_is_attached_ = 0; 473 v_bar_is_attached_ = 0;
474 DestroyScrollbar(kVerticalScrollbar); 474 DestroyScrollbar(kVerticalScrollbar);
475 } 475 }
476 476
477 scrollable_area_->SetScrollCornerNeedsPaintInvalidation(); 477 scrollable_area_->SetScrollCornerNeedsPaintInvalidation();
478 } 478 }
479 479
480 Scrollbar* LocalFrameView::ScrollbarManager::CreateScrollbar(
481 ScrollbarOrientation orientation) {
482 Element* custom_scrollbar_element = nullptr;
483 LayoutBox* box = scrollable_area_->GetLayoutBox();
484 if (box->GetDocument().View()->ShouldUseCustomScrollbars(
485 custom_scrollbar_element)) {
486 return LayoutScrollbar::CreateCustomScrollbar(
487 scrollable_area_.Get(), orientation, custom_scrollbar_element);
488 }
489
490 // Nobody set a custom style, so we just use a native scrollbar.
491 return Scrollbar::Create(scrollable_area_.Get(), orientation,
492 kRegularScrollbar,
493 &box->GetFrame()->GetPage()->GetChromeClient());
494 }
495
496 void LocalFrameView::ScrollbarManager::DestroyScrollbar(
497 ScrollbarOrientation orientation) {
498 Member<Scrollbar>& scrollbar =
499 orientation == kHorizontalScrollbar ? h_bar_ : v_bar_;
500 DCHECK(orientation == kHorizontalScrollbar ? !h_bar_is_attached_
501 : !v_bar_is_attached_);
502 if (!scrollbar)
503 return;
504
505 scrollable_area_->WillRemoveScrollbar(*scrollbar, orientation);
506 scrollbar->DisconnectFromScrollableArea();
507 scrollbar = nullptr;
508 }
509
510 void LocalFrameView::RecalculateCustomScrollbarStyle() { 480 void LocalFrameView::RecalculateCustomScrollbarStyle() {
511 bool did_style_change = false; 481 bool did_style_change = false;
512 if (HorizontalScrollbar() && HorizontalScrollbar()->IsCustomScrollbar()) { 482 if (HorizontalScrollbar() && HorizontalScrollbar()->IsCustomScrollbar()) {
513 HorizontalScrollbar()->StyleChanged(); 483 HorizontalScrollbar()->StyleChanged();
514 did_style_change = true; 484 did_style_change = true;
515 } 485 }
516 if (VerticalScrollbar() && VerticalScrollbar()->IsCustomScrollbar()) { 486 if (VerticalScrollbar() && VerticalScrollbar()->IsCustomScrollbar()) {
517 VerticalScrollbar()->StyleChanged(); 487 VerticalScrollbar()->StyleChanged();
518 did_style_change = true; 488 did_style_change = true;
519 } 489 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 644
675 ScrollbarMode new_horizontal_mode = horizontal_scrollbar_mode_; 645 ScrollbarMode new_horizontal_mode = horizontal_scrollbar_mode_;
676 if (can_have_scrollbars && horizontal_scrollbar_mode_ == kScrollbarAlwaysOff) 646 if (can_have_scrollbars && horizontal_scrollbar_mode_ == kScrollbarAlwaysOff)
677 new_horizontal_mode = kScrollbarAuto; 647 new_horizontal_mode = kScrollbarAuto;
678 else if (!can_have_scrollbars) 648 else if (!can_have_scrollbars)
679 new_horizontal_mode = kScrollbarAlwaysOff; 649 new_horizontal_mode = kScrollbarAlwaysOff;
680 650
681 SetScrollbarModes(new_horizontal_mode, new_vertical_mode); 651 SetScrollbarModes(new_horizontal_mode, new_vertical_mode);
682 } 652 }
683 653
684 bool LocalFrameView::ShouldUseCustomScrollbars( 654 LayoutObject* LocalFrameView::LayoutObjectForScrollbars() const {
685 Element*& custom_scrollbar_element) const {
686 custom_scrollbar_element = nullptr;
687
688 if (Settings* settings = frame_->GetSettings()) { 655 if (Settings* settings = frame_->GetSettings()) {
689 if (!settings->GetAllowCustomScrollbarInMainFrame() && 656 if (!settings->GetAllowCustomScrollbarInMainFrame() &&
690 frame_->IsMainFrame()) 657 frame_->IsMainFrame())
691 return false; 658 return nullptr;
bokan 2017/06/27 17:48:52 No need to have this case here, PLSA::LayoutObject
692 }
693 Document* doc = frame_->GetDocument();
694
695 // Try the <body> element first as a scrollbar source.
696 Element* body = doc ? doc->body() : 0;
697 if (body && body->GetLayoutObject() &&
698 body->GetLayoutObject()->Style()->HasPseudoStyle(kPseudoIdScrollbar)) {
699 custom_scrollbar_element = body;
700 return true;
701 } 659 }
702 660
703 // If the <body> didn't have a custom style, then the root element might. 661 LayoutViewItem layout_view_item = GetLayoutViewItem();
704 Element* doc_element = doc ? doc->documentElement() : 0; 662 if (layout_view_item.IsNull())
705 if (doc_element && doc_element->GetLayoutObject() && 663 return nullptr;
706 doc_element->GetLayoutObject()->Style()->HasPseudoStyle(
707 kPseudoIdScrollbar)) {
708 custom_scrollbar_element = doc_element;
709 return true;
710 }
711 664
712 return false; 665 return layout_view_item.GetScrollableArea()->LayoutObjectForScrollbars();
713 } 666 }
714 667
715 Scrollbar* LocalFrameView::CreateScrollbar(ScrollbarOrientation orientation) { 668 Scrollbar* LocalFrameView::CreateScrollbar(ScrollbarOrientation orientation) {
716 return scrollbar_manager_.CreateScrollbar(orientation); 669 return scrollbar_manager_.CreateScrollbar(orientation);
717 } 670 }
718 671
719 void LocalFrameView::SetContentsSize(const IntSize& size) { 672 void LocalFrameView::SetContentsSize(const IntSize& size) {
720 if (size == ContentsSize()) 673 if (size == ContentsSize())
721 return; 674 return;
722 675
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after
2184 2137
2185 void LocalFrameView::ScrollbarExistenceMaybeChanged() { 2138 void LocalFrameView::ScrollbarExistenceMaybeChanged() {
2186 // We check to make sure the view is attached to a frame() as this method can 2139 // We check to make sure the view is attached to a frame() as this method can
2187 // be triggered before the view is attached by LocalFrame::createView(...) 2140 // be triggered before the view is attached by LocalFrame::createView(...)
2188 // setting various values such as setScrollBarModes(...) for example. An 2141 // setting various values such as setScrollBarModes(...) for example. An
2189 // ASSERT is triggered when a view is layout before being attached to a 2142 // ASSERT is triggered when a view is layout before being attached to a
2190 // frame(). 2143 // frame().
2191 if (!GetFrame().View()) 2144 if (!GetFrame().View())
2192 return; 2145 return;
2193 2146
2194 Element* custom_scrollbar_element = nullptr; 2147 LayoutObject* style_source = nullptr;
2195
2196 bool uses_overlay_scrollbars = 2148 bool uses_overlay_scrollbars =
2197 ScrollbarTheme::GetTheme().UsesOverlayScrollbars() && 2149 ScrollbarTheme::GetTheme().UsesOverlayScrollbars() &&
2198 !ShouldUseCustomScrollbars(custom_scrollbar_element); 2150 !ShouldUseCustomScrollbars(style_source);
2199 2151
2200 if (!uses_overlay_scrollbars && NeedsLayout()) 2152 if (!uses_overlay_scrollbars && NeedsLayout())
2201 UpdateLayout(); 2153 UpdateLayout();
2202 2154
2203 if (!GetLayoutViewItem().IsNull() && GetLayoutViewItem().UsesCompositing()) { 2155 if (!GetLayoutViewItem().IsNull() && GetLayoutViewItem().UsesCompositing()) {
2204 GetLayoutViewItem().Compositor()->FrameViewScrollbarsExistenceDidChange(); 2156 GetLayoutViewItem().Compositor()->FrameViewScrollbarsExistenceDidChange();
2205 2157
2206 if (!uses_overlay_scrollbars) 2158 if (!uses_overlay_scrollbars)
2207 GetLayoutViewItem().Compositor()->FrameViewDidChangeSize(); 2159 GetLayoutViewItem().Compositor()->FrameViewDidChangeSize();
2208 } 2160 }
(...skipping 2145 matching lines...) Expand 10 before | Expand all | Expand 10 after
4354 has_vertical_scrollbar != new_has_vertical_scrollbar; 4306 has_vertical_scrollbar != new_has_vertical_scrollbar;
4355 if (!scrollbar_existence_changed) 4307 if (!scrollbar_existence_changed)
4356 return false; 4308 return false;
4357 4309
4358 scrollbar_manager_.SetHasHorizontalScrollbar(new_has_horizontal_scrollbar); 4310 scrollbar_manager_.SetHasHorizontalScrollbar(new_has_horizontal_scrollbar);
4359 scrollbar_manager_.SetHasVerticalScrollbar(new_has_vertical_scrollbar); 4311 scrollbar_manager_.SetHasVerticalScrollbar(new_has_vertical_scrollbar);
4360 4312
4361 if (scrollbars_suppressed_) 4313 if (scrollbars_suppressed_)
4362 return true; 4314 return true;
4363 4315
4364 Element* custom_scrollbar_element = nullptr; 4316 LayoutObject* style_source = nullptr;
4365 bool uses_overlay_scrollbars = 4317 bool uses_overlay_scrollbars =
4366 ScrollbarTheme::GetTheme().UsesOverlayScrollbars() && 4318 ScrollbarTheme::GetTheme().UsesOverlayScrollbars() &&
4367 !ShouldUseCustomScrollbars(custom_scrollbar_element); 4319 !ShouldUseCustomScrollbars(style_source);
4368 4320
4369 if (!uses_overlay_scrollbars) 4321 if (!uses_overlay_scrollbars)
4370 SetNeedsLayout(); 4322 SetNeedsLayout();
4371 4323
4372 ScrollbarExistenceMaybeChanged(); 4324 ScrollbarExistenceMaybeChanged();
4373 return true; 4325 return true;
4374 } 4326 }
4375 4327
4376 bool LocalFrameView::NeedsScrollbarReconstruction() const { 4328 bool LocalFrameView::NeedsScrollbarReconstruction() const {
4377 Scrollbar* scrollbar = HorizontalScrollbar(); 4329 Scrollbar* scrollbar = HorizontalScrollbar();
4378 if (!scrollbar) 4330 if (!scrollbar)
4379 scrollbar = VerticalScrollbar(); 4331 scrollbar = VerticalScrollbar();
4380 if (!scrollbar) { 4332 if (!scrollbar) {
4381 // We have no scrollbar to reconstruct. 4333 // We have no scrollbar to reconstruct.
4382 return false; 4334 return false;
4383 } 4335 }
4384 Element* style_source = nullptr; 4336 LayoutObject* style_source = nullptr;
4337
4385 bool needs_custom = ShouldUseCustomScrollbars(style_source); 4338 bool needs_custom = ShouldUseCustomScrollbars(style_source);
4386 bool is_custom = scrollbar->IsCustomScrollbar(); 4339 bool is_custom = scrollbar->IsCustomScrollbar();
4387 if (needs_custom != is_custom) { 4340 if (needs_custom != is_custom) {
4388 // We have a native scrollbar that should be custom, or vice versa. 4341 // We have a native scrollbar that should be custom, or vice versa.
4389 return true; 4342 return true;
4390 } 4343 }
4391 if (!needs_custom) { 4344 if (!needs_custom) {
4392 // We have a native scrollbar that should remain native. 4345 // We have a native scrollbar that should remain native.
4393 return false; 4346 return false;
4394 } 4347 }
4395 DCHECK(needs_custom && is_custom); 4348 DCHECK(needs_custom && is_custom);
4396 DCHECK(style_source); 4349 DCHECK(style_source);
4397 if (ToLayoutScrollbar(scrollbar)->StyleSource() != 4350 if (ToLayoutScrollbar(scrollbar)->StyleSource() != style_source) {
4398 style_source->GetLayoutObject()) {
4399 // We have a custom scrollbar with a stale m_owner. 4351 // We have a custom scrollbar with a stale m_owner.
4400 return true; 4352 return true;
4401 } 4353 }
4402 return false; 4354 return false;
4403 } 4355 }
4404 4356
4405 bool LocalFrameView::ShouldIgnoreOverflowHidden() const { 4357 bool LocalFrameView::ShouldIgnoreOverflowHidden() const {
4406 return frame_->GetSettings()->GetIgnoreMainFrameOverflowHiddenQuirk() && 4358 return frame_->GetSettings()->GetIgnoreMainFrameOverflowHiddenQuirk() &&
4407 frame_->IsMainFrame(); 4359 frame_->IsMainFrame();
4408 } 4360 }
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
5479 void LocalFrameView::SetAnimationHost( 5431 void LocalFrameView::SetAnimationHost(
5480 std::unique_ptr<CompositorAnimationHost> host) { 5432 std::unique_ptr<CompositorAnimationHost> host) {
5481 animation_host_ = std::move(host); 5433 animation_host_ = std::move(host);
5482 } 5434 }
5483 5435
5484 LayoutUnit LocalFrameView::CaretWidth() const { 5436 LayoutUnit LocalFrameView::CaretWidth() const {
5485 return LayoutUnit(GetChromeClient()->WindowToViewportScalar(1)); 5437 return LayoutUnit(GetChromeClient()->WindowToViewportScalar(1));
5486 } 5438 }
5487 5439
5488 } // namespace blink 5440 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698