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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacOverlayAPI.mm

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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 85 }
86 } 86 }
87 } 87 }
88 88
89 @end 89 @end
90 90
91 namespace blink { 91 namespace blink {
92 92
93 typedef HashMap<ScrollbarThemeClient*, RetainPtr<WebCoreScrollbarObserver> > Scr ollbarPainterMap; 93 typedef HashMap<ScrollbarThemeClient*, RetainPtr<WebCoreScrollbarObserver> > Scr ollbarPainterMap;
94 94
95 static ScrollbarPainterMap* scrollbarPainterMap() 95 static ScrollbarPainterMap& scrollbarPainterMap()
96 { 96 {
97 static ScrollbarPainterMap* map = new ScrollbarPainterMap; 97 static ScrollbarPainterMap* map = new ScrollbarPainterMap;
98 return map; 98 return *map;
99 } 99 }
100 100
101 static bool supportsExpandedScrollbars() 101 static bool supportsExpandedScrollbars()
102 { 102 {
103 // FIXME: This is temporary until all platforms that support ScrollbarPainte r support this part of the API. 103 // FIXME: This is temporary until all platforms that support ScrollbarPainte r support this part of the API.
104 static bool globalSupportsExpandedScrollbars = [NSClassFromString(@"NSScroll erImp") instancesRespondToSelector:@selector(setExpanded:)]; 104 static bool globalSupportsExpandedScrollbars = [NSClassFromString(@"NSScroll erImp") instancesRespondToSelector:@selector(setExpanded:)];
105 return globalSupportsExpandedScrollbars; 105 return globalSupportsExpandedScrollbars;
106 } 106 }
107 107
108 void ScrollbarThemeMacOverlayAPI::registerScrollbar(ScrollbarThemeClient* scroll bar) 108 void ScrollbarThemeMacOverlayAPI::registerScrollbar(ScrollbarThemeClient& scroll bar)
109 { 109 {
110 ScrollbarThemeMacCommon::registerScrollbar(scrollbar); 110 ScrollbarThemeMacCommon::registerScrollbar(scrollbar);
111 111
112 bool isHorizontal = scrollbar->orientation() == HorizontalScrollbar; 112 bool isHorizontal = scrollbar.orientation() == HorizontalScrollbar;
113 ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scr ollerImpWithStyle:recommendedScrollerStyle() controlSize:(NSControlSize)scrollba r->controlSize() horizontal:isHorizontal replacingScrollerImp:nil]; 113 ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scr ollerImpWithStyle:recommendedScrollerStyle() controlSize:(NSControlSize)scrollba r.controlSize() horizontal:isHorizontal replacingScrollerImp:nil];
114 RetainPtr<WebCoreScrollbarObserver> observer = [[WebCoreScrollbarObserver al loc] initWithScrollbar:scrollbar painter:scrollbarPainter]; 114 RetainPtr<WebCoreScrollbarObserver> observer = [[WebCoreScrollbarObserver al loc] initWithScrollbar:&scrollbar painter:scrollbarPainter];
115 115
116 scrollbarPainterMap()->add(scrollbar, observer); 116 scrollbarPainterMap().add(&scrollbar, observer);
117 updateEnabledState(scrollbar); 117 updateEnabledState(scrollbar);
118 updateScrollbarOverlayStyle(scrollbar); 118 updateScrollbarOverlayStyle(scrollbar);
119 } 119 }
120 120
121 void ScrollbarThemeMacOverlayAPI::unregisterScrollbar(ScrollbarThemeClient* scro llbar) 121 void ScrollbarThemeMacOverlayAPI::unregisterScrollbar(ScrollbarThemeClient& scro llbar)
122 { 122 {
123 scrollbarPainterMap()->remove(scrollbar); 123 scrollbarPainterMap().remove(&scrollbar);
124 124
125 ScrollbarThemeMacCommon::unregisterScrollbar(scrollbar); 125 ScrollbarThemeMacCommon::unregisterScrollbar(scrollbar);
126 } 126 }
127 127
128 void ScrollbarThemeMacOverlayAPI::setNewPainterForScrollbar(ScrollbarThemeClient * scrollbar, ScrollbarPainter newPainter) 128 void ScrollbarThemeMacOverlayAPI::setNewPainterForScrollbar(ScrollbarThemeClient & scrollbar, ScrollbarPainter newPainter)
129 { 129 {
130 RetainPtr<WebCoreScrollbarObserver> observer = [[WebCoreScrollbarObserver al loc] initWithScrollbar:scrollbar painter:newPainter]; 130 RetainPtr<WebCoreScrollbarObserver> observer = [[WebCoreScrollbarObserver al loc] initWithScrollbar:&scrollbar painter:newPainter];
131 scrollbarPainterMap()->set(scrollbar, observer); 131 scrollbarPainterMap().set(&scrollbar, observer);
132 updateEnabledState(scrollbar); 132 updateEnabledState(scrollbar);
133 updateScrollbarOverlayStyle(scrollbar); 133 updateScrollbarOverlayStyle(scrollbar);
134 } 134 }
135 135
136 ScrollbarPainter ScrollbarThemeMacOverlayAPI::painterForScrollbar(const Scrollba rThemeClient* scrollbar) const 136 ScrollbarPainter ScrollbarThemeMacOverlayAPI::painterForScrollbar(const Scrollba rThemeClient& scrollbar) const
137 { 137 {
138 return [scrollbarPainterMap()->get(const_cast<ScrollbarThemeClient*>(scrollb ar)).get() painter]; 138 return [scrollbarPainterMap().get(const_cast<ScrollbarThemeClient*>(&scrollb ar)).get() painter];
139 } 139 }
140 140
141 void ScrollbarThemeMacOverlayAPI::paintTrackBackground(GraphicsContext* context, const ScrollbarThemeClient* scrollbar, const IntRect& rect) { 141 void ScrollbarThemeMacOverlayAPI::paintTrackBackground(GraphicsContext& context, const ScrollbarThemeClient& scrollbar, const IntRect& rect) {
142 if (DrawingRecorder::useCachedDrawingIfPossible(*context, *scrollbar, Displa yItem::ScrollbarTrackBackground)) 142 if (DrawingRecorder::useCachedDrawingIfPossible(context, scrollbar, DisplayI tem::ScrollbarTrackBackground))
143 return; 143 return;
144 144
145 DrawingRecorder recorder(*context, *scrollbar, DisplayItem::ScrollbarTrackBa ckground, rect); 145 DrawingRecorder recorder(context, scrollbar, DisplayItem::ScrollbarTrackBack ground, rect);
146 146
147 ASSERT(isOverlayAPIAvailable()); 147 ASSERT(isOverlayAPIAvailable());
148 148
149 GraphicsContextStateSaver stateSaver(*context); 149 GraphicsContextStateSaver stateSaver(context);
150 context->translate(rect.x(), rect.y()); 150 context.translate(rect.x(), rect.y());
151 LocalCurrentGraphicsContext localContext(context, IntRect(IntPoint(), rect.s ize())); 151 LocalCurrentGraphicsContext localContext(&context, IntRect(IntPoint(), rect. size()));
152 152
153 CGRect frameRect = scrollbar->frameRect(); 153 CGRect frameRect = scrollbar.frameRect();
154 ScrollbarPainter scrollbarPainter = painterForScrollbar(scrollbar); 154 ScrollbarPainter scrollbarPainter = painterForScrollbar(scrollbar);
155 [scrollbarPainter setEnabled:scrollbar->enabled()]; 155 [scrollbarPainter setEnabled:scrollbar.enabled()];
156 [scrollbarPainter setBoundsSize: NSSizeFromCGSize(frameRect.size)]; 156 [scrollbarPainter setBoundsSize: NSSizeFromCGSize(frameRect.size)];
157 NSRect trackRect = NSMakeRect(0, 0, frameRect.size.width, frameRect.size.hei ght); 157 NSRect trackRect = NSMakeRect(0, 0, frameRect.size.width, frameRect.size.hei ght);
158 [scrollbarPainter drawKnobSlotInRect:trackRect highlight:NO]; 158 [scrollbarPainter drawKnobSlotInRect:trackRect highlight:NO];
159 } 159 }
160 160
161 void ScrollbarThemeMacOverlayAPI::paintThumb(GraphicsContext* context, const Scr ollbarThemeClient* scrollbar, const IntRect& rect) { 161 void ScrollbarThemeMacOverlayAPI::paintThumb(GraphicsContext& context, const Scr ollbarThemeClient& scrollbar, const IntRect& rect) {
162 if (DrawingRecorder::useCachedDrawingIfPossible(*context, *scrollbar, Displa yItem::ScrollbarThumb)) 162 if (DrawingRecorder::useCachedDrawingIfPossible(context, scrollbar, DisplayI tem::ScrollbarThumb))
163 return; 163 return;
164 164
165 // Expand dirty rect to allow for scroll thumb anti-aliasing in minimum thum b size case. 165 // Expand dirty rect to allow for scroll thumb anti-aliasing in minimum thum b size case.
166 IntRect dirtyRect = IntRect(rect); 166 IntRect dirtyRect = IntRect(rect);
167 dirtyRect.inflate(1); 167 dirtyRect.inflate(1);
168 DrawingRecorder recorder(*context, *scrollbar, DisplayItem::ScrollbarThumb, dirtyRect); 168 DrawingRecorder recorder(context, scrollbar, DisplayItem::ScrollbarThumb, di rtyRect);
169 169
170 ASSERT(isOverlayAPIAvailable()); 170 ASSERT(isOverlayAPIAvailable());
171 171
172 GraphicsContextStateSaver stateSaver(*context); 172 GraphicsContextStateSaver stateSaver(context);
173 context->translate(rect.x(), rect.y()); 173 context.translate(rect.x(), rect.y());
174 LocalCurrentGraphicsContext localContext(context, IntRect(IntPoint(), rect.s ize())); 174 LocalCurrentGraphicsContext localContext(&context, IntRect(IntPoint(), rect. size()));
175 175
176 ScrollbarPainter scrollbarPainter = painterForScrollbar(scrollbar); 176 ScrollbarPainter scrollbarPainter = painterForScrollbar(scrollbar);
177 [scrollbarPainter setEnabled:scrollbar->enabled()]; 177 [scrollbarPainter setEnabled:scrollbar.enabled()];
178 [scrollbarPainter setBoundsSize:NSSizeFromCGSize(rect.size())]; 178 [scrollbarPainter setBoundsSize:NSSizeFromCGSize(rect.size())];
179 [scrollbarPainter setDoubleValue:0]; 179 [scrollbarPainter setDoubleValue:0];
180 [scrollbarPainter setKnobProportion:1]; 180 [scrollbarPainter setKnobProportion:1];
181 181
182 CGFloat oldKnobAlpha = [scrollbarPainter knobAlpha]; 182 CGFloat oldKnobAlpha = [scrollbarPainter knobAlpha];
183 [scrollbarPainter setKnobAlpha:1]; 183 [scrollbarPainter setKnobAlpha:1];
184 184
185 if (scrollbar->enabled()) 185 if (scrollbar.enabled())
186 [scrollbarPainter drawKnob]; 186 [scrollbarPainter drawKnob];
187 187
188 // If this state is not set, then moving the cursor over the scrollbar area will only cause the 188 // If this state is not set, then moving the cursor over the scrollbar area will only cause the
189 // scrollbar to engorge when moved over the top of the scrollbar area. 189 // scrollbar to engorge when moved over the top of the scrollbar area.
190 [scrollbarPainter setBoundsSize: NSSizeFromCGSize(scrollbar->frameRect().siz e())]; 190 [scrollbarPainter setBoundsSize: NSSizeFromCGSize(scrollbar.frameRect().size ())];
191 [scrollbarPainter setKnobAlpha:oldKnobAlpha]; 191 [scrollbarPainter setKnobAlpha:oldKnobAlpha];
192 } 192 }
193 193
194 int ScrollbarThemeMacOverlayAPI::scrollbarThickness(ScrollbarControlSize control Size) 194 int ScrollbarThemeMacOverlayAPI::scrollbarThickness(ScrollbarControlSize control Size)
195 { 195 {
196 NSControlSize nsControlSize = static_cast<NSControlSize>(controlSize); 196 NSControlSize nsControlSize = static_cast<NSControlSize>(controlSize);
197 ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scr ollerImpWithStyle:recommendedScrollerStyle() controlSize:nsControlSize horizonta l:NO replacingScrollerImp:nil]; 197 ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scr ollerImpWithStyle:recommendedScrollerStyle() controlSize:nsControlSize horizonta l:NO replacingScrollerImp:nil];
198 BOOL wasExpanded = NO; 198 BOOL wasExpanded = NO;
199 if (supportsExpandedScrollbars()) { 199 if (supportsExpandedScrollbars()) {
200 wasExpanded = [scrollbarPainter isExpanded]; 200 wasExpanded = [scrollbarPainter isExpanded];
201 [scrollbarPainter setExpanded:YES]; 201 [scrollbarPainter setExpanded:YES];
202 } 202 }
203 int thickness = [scrollbarPainter trackBoxWidth]; 203 int thickness = [scrollbarPainter trackBoxWidth];
204 if (supportsExpandedScrollbars()) 204 if (supportsExpandedScrollbars())
205 [scrollbarPainter setExpanded:wasExpanded]; 205 [scrollbarPainter setExpanded:wasExpanded];
206 return thickness; 206 return thickness;
207 } 207 }
208 208
209 bool ScrollbarThemeMacOverlayAPI::usesOverlayScrollbars() const 209 bool ScrollbarThemeMacOverlayAPI::usesOverlayScrollbars() const
210 { 210 {
211 return recommendedScrollerStyle() == NSScrollerStyleOverlay; 211 return recommendedScrollerStyle() == NSScrollerStyleOverlay;
212 } 212 }
213 213
214 void ScrollbarThemeMacOverlayAPI::updateScrollbarOverlayStyle(const ScrollbarThe meClient* scrollbar) 214 void ScrollbarThemeMacOverlayAPI::updateScrollbarOverlayStyle(const ScrollbarThe meClient& scrollbar)
215 { 215 {
216 ScrollbarPainter painter = painterForScrollbar(scrollbar); 216 ScrollbarPainter painter = painterForScrollbar(scrollbar);
217 switch (scrollbar->scrollbarOverlayStyle()) { 217 switch (scrollbar.scrollbarOverlayStyle()) {
218 case ScrollbarOverlayStyleDefault: 218 case ScrollbarOverlayStyleDefault:
219 [painter setKnobStyle:NSScrollerKnobStyleDefault]; 219 [painter setKnobStyle:NSScrollerKnobStyleDefault];
220 break; 220 break;
221 case ScrollbarOverlayStyleDark: 221 case ScrollbarOverlayStyleDark:
222 [painter setKnobStyle:NSScrollerKnobStyleDark]; 222 [painter setKnobStyle:NSScrollerKnobStyleDark];
223 break; 223 break;
224 case ScrollbarOverlayStyleLight: 224 case ScrollbarOverlayStyleLight:
225 [painter setKnobStyle:NSScrollerKnobStyleLight]; 225 [painter setKnobStyle:NSScrollerKnobStyleLight];
226 break; 226 break;
227 } 227 }
228 } 228 }
229 229
230 ScrollbarButtonsPlacement ScrollbarThemeMacOverlayAPI::buttonsPlacement() const 230 ScrollbarButtonsPlacement ScrollbarThemeMacOverlayAPI::buttonsPlacement() const
231 { 231 {
232 return ScrollbarButtonsPlacementNone; 232 return ScrollbarButtonsPlacementNone;
233 } 233 }
234 234
235 bool ScrollbarThemeMacOverlayAPI::hasThumb(const ScrollbarThemeClient* scrollbar ) 235 bool ScrollbarThemeMacOverlayAPI::hasThumb(const ScrollbarThemeClient& scrollbar )
236 { 236 {
237 ScrollbarPainter painter = painterForScrollbar(scrollbar); 237 ScrollbarPainter painter = painterForScrollbar(scrollbar);
238 int minLengthForThumb = [painter knobMinLength] + [painter trackOverlapEndIn set] + [painter knobOverlapEndInset] 238 int minLengthForThumb = [painter knobMinLength] + [painter trackOverlapEndIn set] + [painter knobOverlapEndInset]
239 + 2 * ([painter trackEndInset] + [painter knobEndInset]); 239 + 2 * ([painter trackEndInset] + [painter knobEndInset]);
240 return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScroll bar ? 240 return scrollbar.enabled() && (scrollbar.orientation() == HorizontalScrollba r ?
241 scrollbar->width() : 241 scrollbar.width() :
242 scrollbar->height()) >= minLengthForThumb; 242 scrollbar.height()) >= minLengthForThumb;
243 } 243 }
244 244
245 IntRect ScrollbarThemeMacOverlayAPI::backButtonRect(const ScrollbarThemeClient* scrollbar, ScrollbarPart part, bool painting) 245 IntRect ScrollbarThemeMacOverlayAPI::backButtonRect(const ScrollbarThemeClient& scrollbar, ScrollbarPart part, bool painting)
246 { 246 {
247 ASSERT(buttonsPlacement() == ScrollbarButtonsPlacementNone); 247 ASSERT(buttonsPlacement() == ScrollbarButtonsPlacementNone);
248 return IntRect(); 248 return IntRect();
249 } 249 }
250 250
251 IntRect ScrollbarThemeMacOverlayAPI::forwardButtonRect(const ScrollbarThemeClien t* scrollbar, ScrollbarPart part, bool painting) 251 IntRect ScrollbarThemeMacOverlayAPI::forwardButtonRect(const ScrollbarThemeClien t& scrollbar, ScrollbarPart part, bool painting)
252 { 252 {
253 ASSERT(buttonsPlacement() == ScrollbarButtonsPlacementNone); 253 ASSERT(buttonsPlacement() == ScrollbarButtonsPlacementNone);
254 return IntRect(); 254 return IntRect();
255 } 255 }
256 256
257 IntRect ScrollbarThemeMacOverlayAPI::trackRect(const ScrollbarThemeClient* scrol lbar, bool painting) 257 IntRect ScrollbarThemeMacOverlayAPI::trackRect(const ScrollbarThemeClient& scrol lbar, bool painting)
258 { 258 {
259 ASSERT(!hasButtons(scrollbar)); 259 ASSERT(!hasButtons(scrollbar));
260 return scrollbar->frameRect(); 260 return scrollbar.frameRect();
261 } 261 }
262 262
263 int ScrollbarThemeMacOverlayAPI::minimumThumbLength(const ScrollbarThemeClient* scrollbar) 263 int ScrollbarThemeMacOverlayAPI::minimumThumbLength(const ScrollbarThemeClient& scrollbar)
264 { 264 {
265 return [painterForScrollbar(scrollbar) knobMinLength]; 265 return [painterForScrollbar(scrollbar) knobMinLength];
266 } 266 }
267 267
268 void ScrollbarThemeMacOverlayAPI::updateEnabledState(const ScrollbarThemeClient* scrollbar) 268 void ScrollbarThemeMacOverlayAPI::updateEnabledState(const ScrollbarThemeClient& scrollbar)
269 { 269 {
270 [painterForScrollbar(scrollbar) setEnabled:scrollbar->enabled()]; 270 [painterForScrollbar(scrollbar) setEnabled:scrollbar.enabled()];
271 } 271 }
272 272
273 float ScrollbarThemeMacOverlayAPI::thumbOpacity(const ScrollbarThemeClient* scro llbar) const { 273 float ScrollbarThemeMacOverlayAPI::thumbOpacity(const ScrollbarThemeClient& scro llbar) const {
274 ScrollbarPainter scrollbarPainter = painterForScrollbar(scrollbar); 274 ScrollbarPainter scrollbarPainter = painterForScrollbar(scrollbar);
275 return [scrollbarPainter knobAlpha]; 275 return [scrollbarPainter knobAlpha];
276 } 276 }
277 277
278 } // namespace blink 278 } // namespace blink
279 279
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698