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

Side by Side Diff: third_party/WebKit/Source/core/paint/ScrollbarManager.cpp

Issue 2942163002: [Refactor] Moved scrollbar creation and deletion to ScrollbarManager (Closed)
Patch Set: bokan and skobes comments addressed 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/paint/ScrollbarManager.h" 5 #include "core/paint/ScrollbarManager.h"
6 6
7 #include "core/frame/LocalFrame.h"
8 #include "core/frame/LocalFrameView.h"
9 #include "core/layout/LayoutBox.h"
10 #include "core/layout/LayoutObject.h"
11 #include "core/layout/LayoutScrollbar.h"
12 #include "core/layout/LayoutTheme.h"
13 #include "core/page/ChromeClient.h"
14 #include "core/page/Page.h"
15 #include "core/paint/PaintLayerScrollableArea.h"
16
7 namespace blink { 17 namespace blink {
8 18
9 ScrollbarManager::ScrollbarManager(ScrollableArea& scrollable_area) 19 ScrollbarManager::ScrollbarManager(ScrollableArea& scrollable_area)
10 : scrollable_area_(&scrollable_area), 20 : scrollable_area_(&scrollable_area),
11 h_bar_is_attached_(0), 21 h_bar_is_attached_(0),
12 v_bar_is_attached_(0) {} 22 v_bar_is_attached_(0) {}
13 23
14 DEFINE_TRACE(ScrollbarManager) { 24 DEFINE_TRACE(ScrollbarManager) {
15 visitor->Trace(scrollable_area_); 25 visitor->Trace(scrollable_area_);
16 visitor->Trace(h_bar_); 26 visitor->Trace(h_bar_);
17 visitor->Trace(v_bar_); 27 visitor->Trace(v_bar_);
18 } 28 }
19 29
20 void ScrollbarManager::Dispose() { 30 void ScrollbarManager::Dispose() {
21 h_bar_is_attached_ = v_bar_is_attached_ = 0; 31 h_bar_is_attached_ = v_bar_is_attached_ = 0;
22 DestroyScrollbar(kHorizontalScrollbar); 32 DestroyScrollbar(kHorizontalScrollbar);
23 DestroyScrollbar(kVerticalScrollbar); 33 DestroyScrollbar(kVerticalScrollbar);
24 } 34 }
25 35
36 Scrollbar* ScrollbarManager::CreateScrollbar(ScrollbarOrientation orientation) {
37 DCHECK(scrollable_area_->GetLayoutBox());
38 DCHECK(orientation == kHorizontalScrollbar ? !h_bar_is_attached_
39 : !v_bar_is_attached_);
40 LayoutObject* layout_object_for_style =
41 scrollable_area_->LayoutObjectForScrollbarStyle();
42
43 Scrollbar* scrollbar = nullptr;
44 if (layout_object_for_style &&
45 layout_object_for_style->HasCustomScrollbarStyle()) {
46 DCHECK(!layout_object_for_style->IsLayoutView());
47 scrollbar = LayoutScrollbar::CreateCustomScrollbar(
48 scrollable_area_.Get(), orientation,
49 ToElement(layout_object_for_style->GetNode()));
50 } else {
51 ScrollbarControlSize scrollbar_size = kRegularScrollbar;
52
53 if (layout_object_for_style &&
54 layout_object_for_style->StyleRef().HasAppearance() &&
55 scrollable_area_->IsPaintLayerScrollableArea()) {
56 scrollbar_size = LayoutTheme::GetTheme().ScrollbarControlSizeForPart(
57 layout_object_for_style->StyleRef().Appearance());
58 }
59
60 scrollbar =
61 Scrollbar::Create(scrollable_area_.Get(), orientation, scrollbar_size,
62 &scrollable_area_->GetLayoutBox()
63 ->GetFrame()
64 ->GetPage()
65 ->GetChromeClient());
66 }
67
68 scrollable_area_->GetLayoutBox()->GetDocument().View()->AddScrollbar(
69 scrollbar);
70
71 return scrollbar;
72 }
73
74 void ScrollbarManager::DestroyScrollbar(ScrollbarOrientation orientation) {
75 Member<Scrollbar>& scrollbar =
76 orientation == kHorizontalScrollbar ? h_bar_ : v_bar_;
77 DCHECK(orientation == kHorizontalScrollbar ? !h_bar_is_attached_
78 : !v_bar_is_attached_);
79 if (!scrollbar)
80 return;
81
82 scrollable_area_->WillRemoveScrollbar(*scrollbar, orientation);
83
84 scrollable_area_->GetLayoutBox()->GetDocument().View()->RemoveScrollbar(
85 scrollbar);
86
87 scrollbar->DisconnectFromScrollableArea();
88 scrollbar = nullptr;
89 }
90
26 } // namespace blink 91 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/ScrollbarManager.h ('k') | third_party/WebKit/Source/platform/scroll/ScrollableArea.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698