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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollbarThemeOverlay.cpp

Issue 1511003003: Use refs for non-null GraphicsContext, Scrollbar, etc. in scrollbar related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarRemove
Patch Set: yet another mac fix Created 5 years 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 int ScrollbarThemeOverlay::scrollbarMargin() const 66 int ScrollbarThemeOverlay::scrollbarMargin() const
67 { 67 {
68 return m_scrollbarMargin; 68 return m_scrollbarMargin;
69 } 69 }
70 70
71 bool ScrollbarThemeOverlay::usesOverlayScrollbars() const 71 bool ScrollbarThemeOverlay::usesOverlayScrollbars() const
72 { 72 {
73 return true; 73 return true;
74 } 74 }
75 75
76 int ScrollbarThemeOverlay::thumbPosition(const ScrollbarThemeClient* scrollbar) 76 int ScrollbarThemeOverlay::thumbPosition(const ScrollbarThemeClient& scrollbar)
77 { 77 {
78 if (!scrollbar->totalSize()) 78 if (!scrollbar.totalSize())
79 return 0; 79 return 0;
80 80
81 int trackLen = trackLength(scrollbar); 81 int trackLen = trackLength(scrollbar);
82 float proportion = static_cast<float>(scrollbar->currentPos()) / scrollbar-> totalSize(); 82 float proportion = static_cast<float>(scrollbar.currentPos()) / scrollbar.to talSize();
83 return round(proportion * trackLen); 83 return round(proportion * trackLen);
84 } 84 }
85 85
86 int ScrollbarThemeOverlay::thumbLength(const ScrollbarThemeClient* scrollbar) 86 int ScrollbarThemeOverlay::thumbLength(const ScrollbarThemeClient& scrollbar)
87 { 87 {
88 int trackLen = trackLength(scrollbar); 88 int trackLen = trackLength(scrollbar);
89 89
90 if (!scrollbar->totalSize()) 90 if (!scrollbar.totalSize())
91 return trackLen; 91 return trackLen;
92 92
93 float proportion = static_cast<float>(scrollbar->visibleSize()) / scrollbar- >totalSize(); 93 float proportion = static_cast<float>(scrollbar.visibleSize()) / scrollbar.t otalSize();
94 int length = round(proportion * trackLen); 94 int length = round(proportion * trackLen);
95 length = std::min(std::max(length, minimumThumbLength(scrollbar)), trackLen) ; 95 length = std::min(std::max(length, minimumThumbLength(scrollbar)), trackLen) ;
96 return length; 96 return length;
97 } 97 }
98 98
99 bool ScrollbarThemeOverlay::hasThumb(const ScrollbarThemeClient* scrollbar) 99 bool ScrollbarThemeOverlay::hasThumb(const ScrollbarThemeClient& scrollbar)
100 { 100 {
101 return true; 101 return true;
102 } 102 }
103 103
104 IntRect ScrollbarThemeOverlay::backButtonRect(const ScrollbarThemeClient*, Scrol lbarPart, bool) 104 IntRect ScrollbarThemeOverlay::backButtonRect(const ScrollbarThemeClient&, Scrol lbarPart, bool)
105 { 105 {
106 return IntRect(); 106 return IntRect();
107 } 107 }
108 108
109 IntRect ScrollbarThemeOverlay::forwardButtonRect(const ScrollbarThemeClient*, Sc rollbarPart, bool) 109 IntRect ScrollbarThemeOverlay::forwardButtonRect(const ScrollbarThemeClient&, Sc rollbarPart, bool)
110 { 110 {
111 return IntRect(); 111 return IntRect();
112 } 112 }
113 113
114 IntRect ScrollbarThemeOverlay::trackRect(const ScrollbarThemeClient* scrollbar, bool) 114 IntRect ScrollbarThemeOverlay::trackRect(const ScrollbarThemeClient& scrollbar, bool)
115 { 115 {
116 IntRect rect = scrollbar->frameRect(); 116 IntRect rect = scrollbar.frameRect();
117 if (scrollbar->orientation() == HorizontalScrollbar) 117 if (scrollbar.orientation() == HorizontalScrollbar)
118 rect.inflateX(-m_scrollbarMargin); 118 rect.inflateX(-m_scrollbarMargin);
119 else 119 else
120 rect.inflateY(-m_scrollbarMargin); 120 rect.inflateY(-m_scrollbarMargin);
121 return rect; 121 return rect;
122 } 122 }
123 123
124 int ScrollbarThemeOverlay::thumbThickness(const ScrollbarThemeClient*) 124 int ScrollbarThemeOverlay::thumbThickness(const ScrollbarThemeClient&)
125 { 125 {
126 return m_thumbThickness; 126 return m_thumbThickness;
127 } 127 }
128 128
129 void ScrollbarThemeOverlay::paintThumb(GraphicsContext* context, const Scrollbar ThemeClient* scrollbar, const IntRect& rect) 129 void ScrollbarThemeOverlay::paintThumb(GraphicsContext& context, const Scrollbar ThemeClient& scrollbar, const IntRect& rect)
130 { 130 {
131 if (DrawingRecorder::useCachedDrawingIfPossible(*context, *scrollbar, Displa yItem::ScrollbarThumb)) 131 if (DrawingRecorder::useCachedDrawingIfPossible(context, scrollbar, DisplayI tem::ScrollbarThumb))
132 return; 132 return;
133 133
134 DrawingRecorder recorder(*context, *scrollbar, DisplayItem::ScrollbarThumb, rect); 134 DrawingRecorder recorder(context, scrollbar, DisplayItem::ScrollbarThumb, re ct);
135 135
136 IntRect thumbRect = rect; 136 IntRect thumbRect = rect;
137 if (scrollbar->orientation() == HorizontalScrollbar) { 137 if (scrollbar.orientation() == HorizontalScrollbar) {
138 thumbRect.setHeight(thumbRect.height() - m_scrollbarMargin); 138 thumbRect.setHeight(thumbRect.height() - m_scrollbarMargin);
139 } else { 139 } else {
140 thumbRect.setWidth(thumbRect.width() - m_scrollbarMargin); 140 thumbRect.setWidth(thumbRect.width() - m_scrollbarMargin);
141 if (scrollbar->isLeftSideVerticalScrollbar()) 141 if (scrollbar.isLeftSideVerticalScrollbar())
142 thumbRect.setX(thumbRect.x() + m_scrollbarMargin); 142 thumbRect.setX(thumbRect.x() + m_scrollbarMargin);
143 } 143 }
144 144
145 if (m_useSolidColor) { 145 if (m_useSolidColor) {
146 context->fillRect(thumbRect, m_color); 146 context.fillRect(thumbRect, m_color);
147 return; 147 return;
148 } 148 }
149 149
150 WebThemeEngine::State state = WebThemeEngine::StateNormal; 150 WebThemeEngine::State state = WebThemeEngine::StateNormal;
151 if (scrollbar->pressedPart() == ThumbPart) 151 if (scrollbar.pressedPart() == ThumbPart)
152 state = WebThemeEngine::StatePressed; 152 state = WebThemeEngine::StatePressed;
153 else if (scrollbar->hoveredPart() == ThumbPart) 153 else if (scrollbar.hoveredPart() == ThumbPart)
154 state = WebThemeEngine::StateHover; 154 state = WebThemeEngine::StateHover;
155 155
156 WebCanvas* canvas = context->canvas(); 156 WebCanvas* canvas = context.canvas();
157 157
158 WebThemeEngine::Part part = WebThemeEngine::PartScrollbarHorizontalThumb; 158 WebThemeEngine::Part part = WebThemeEngine::PartScrollbarHorizontalThumb;
159 if (scrollbar->orientation() == VerticalScrollbar) 159 if (scrollbar.orientation() == VerticalScrollbar)
160 part = WebThemeEngine::PartScrollbarVerticalThumb; 160 part = WebThemeEngine::PartScrollbarVerticalThumb;
161 161
162 Platform::current()->themeEngine()->paint(canvas, part, state, WebRect(rect) , 0); 162 Platform::current()->themeEngine()->paint(canvas, part, state, WebRect(rect) , 0);
163 } 163 }
164 164
165 ScrollbarPart ScrollbarThemeOverlay::hitTest(const ScrollbarThemeClient* scrollb ar, const IntPoint& position) 165 ScrollbarPart ScrollbarThemeOverlay::hitTest(const ScrollbarThemeClient& scrollb ar, const IntPoint& position)
166 { 166 {
167 if (m_allowHitTest == DisallowHitTest) 167 if (m_allowHitTest == DisallowHitTest)
168 return NoPart; 168 return NoPart;
169 169
170 return ScrollbarTheme::hitTest(scrollbar, position); 170 return ScrollbarTheme::hitTest(scrollbar, position);
171 } 171 }
172 172
173 ScrollbarTheme* ScrollbarThemeOverlay::mobileTheme() 173 ScrollbarThemeOverlay& ScrollbarThemeOverlay::mobileTheme()
174 { 174 {
175 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (3, 3, ScrollbarThemeOverl ay::DisallowHitTest, Color(128, 128, 128, 128))); 175 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (3, 3, ScrollbarThemeOverl ay::DisallowHitTest, Color(128, 128, 128, 128)));
176 return &theme; 176 return theme;
177 } 177 }
178 178
179 } // namespace blink 179 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scroll/ScrollbarThemeOverlay.h ('k') | third_party/WebKit/Source/web/InspectorOverlay.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698