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

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollbarThemeNonMacCommon.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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2008, 2009 Google Inc. 3 * Copyright (C) 2008, 2009 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
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 17 matching lines...) Expand all
28 #include "platform/scroll/ScrollbarThemeNonMacCommon.h" 28 #include "platform/scroll/ScrollbarThemeNonMacCommon.h"
29 29
30 #include "platform/PlatformMouseEvent.h" 30 #include "platform/PlatformMouseEvent.h"
31 #include "platform/graphics/GraphicsContextStateSaver.h" 31 #include "platform/graphics/GraphicsContextStateSaver.h"
32 #include "platform/graphics/paint/DrawingRecorder.h" 32 #include "platform/graphics/paint/DrawingRecorder.h"
33 #include "platform/scroll/ScrollableArea.h" 33 #include "platform/scroll/ScrollableArea.h"
34 #include "platform/scroll/ScrollbarThemeClient.h" 34 #include "platform/scroll/ScrollbarThemeClient.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 bool ScrollbarThemeNonMacCommon::hasThumb(const ScrollbarThemeClient* scrollbar) 38 bool ScrollbarThemeNonMacCommon::hasThumb(const ScrollbarThemeClient& scrollbar)
39 { 39 {
40 // This method is just called as a paint-time optimization to see if 40 // This method is just called as a paint-time optimization to see if
41 // painting the thumb can be skipped. We don't have to be exact here. 41 // painting the thumb can be skipped. We don't have to be exact here.
42 return thumbLength(scrollbar) > 0; 42 return thumbLength(scrollbar) > 0;
43 } 43 }
44 44
45 IntRect ScrollbarThemeNonMacCommon::backButtonRect(const ScrollbarThemeClient* s crollbar, ScrollbarPart part, bool) 45 IntRect ScrollbarThemeNonMacCommon::backButtonRect(const ScrollbarThemeClient& s crollbar, ScrollbarPart part, bool)
46 { 46 {
47 // Windows and Linux just have single arrows. 47 // Windows and Linux just have single arrows.
48 if (part == BackButtonEndPart) 48 if (part == BackButtonEndPart)
49 return IntRect(); 49 return IntRect();
50 50
51 IntSize size = buttonSize(scrollbar); 51 IntSize size = buttonSize(scrollbar);
52 return IntRect(scrollbar->x(), scrollbar->y(), size.width(), size.height()); 52 return IntRect(scrollbar.x(), scrollbar.y(), size.width(), size.height());
53 } 53 }
54 54
55 IntRect ScrollbarThemeNonMacCommon::forwardButtonRect(const ScrollbarThemeClient * scrollbar, ScrollbarPart part, bool) 55 IntRect ScrollbarThemeNonMacCommon::forwardButtonRect(const ScrollbarThemeClient & scrollbar, ScrollbarPart part, bool)
56 { 56 {
57 // Windows and Linux just have single arrows. 57 // Windows and Linux just have single arrows.
58 if (part == ForwardButtonStartPart) 58 if (part == ForwardButtonStartPart)
59 return IntRect(); 59 return IntRect();
60 60
61 IntSize size = buttonSize(scrollbar); 61 IntSize size = buttonSize(scrollbar);
62 int x, y; 62 int x, y;
63 if (scrollbar->orientation() == HorizontalScrollbar) { 63 if (scrollbar.orientation() == HorizontalScrollbar) {
64 x = scrollbar->x() + scrollbar->width() - size.width(); 64 x = scrollbar.x() + scrollbar.width() - size.width();
65 y = scrollbar->y(); 65 y = scrollbar.y();
66 } else { 66 } else {
67 x = scrollbar->x(); 67 x = scrollbar.x();
68 y = scrollbar->y() + scrollbar->height() - size.height(); 68 y = scrollbar.y() + scrollbar.height() - size.height();
69 } 69 }
70 return IntRect(x, y, size.width(), size.height()); 70 return IntRect(x, y, size.width(), size.height());
71 } 71 }
72 72
73 IntRect ScrollbarThemeNonMacCommon::trackRect(const ScrollbarThemeClient* scroll bar, bool) 73 IntRect ScrollbarThemeNonMacCommon::trackRect(const ScrollbarThemeClient& scroll bar, bool)
74 { 74 {
75 // The track occupies all space between the two buttons. 75 // The track occupies all space between the two buttons.
76 IntSize bs = buttonSize(scrollbar); 76 IntSize bs = buttonSize(scrollbar);
77 int thickness = scrollbarThickness(scrollbar->controlSize()); 77 int thickness = scrollbarThickness(scrollbar.controlSize());
78 if (scrollbar->orientation() == HorizontalScrollbar) { 78 if (scrollbar.orientation() == HorizontalScrollbar) {
79 if (scrollbar->width() <= 2 * bs.width()) 79 if (scrollbar.width() <= 2 * bs.width())
80 return IntRect(); 80 return IntRect();
81 return IntRect(scrollbar->x() + bs.width(), scrollbar->y(), scrollbar->w idth() - 2 * bs.width(), thickness); 81 return IntRect(scrollbar.x() + bs.width(), scrollbar.y(), scrollbar.widt h() - 2 * bs.width(), thickness);
82 } 82 }
83 if (scrollbar->height() <= 2 * bs.height()) 83 if (scrollbar.height() <= 2 * bs.height())
84 return IntRect(); 84 return IntRect();
85 return IntRect(scrollbar->x(), scrollbar->y() + bs.height(), thickness, scro llbar->height() - 2 * bs.height()); 85 return IntRect(scrollbar.x(), scrollbar.y() + bs.height(), thickness, scroll bar.height() - 2 * bs.height());
86 } 86 }
87 87
88 void ScrollbarThemeNonMacCommon::paintTrackBackground(GraphicsContext* context, const ScrollbarThemeClient* scrollbar, const IntRect& rect) 88 void ScrollbarThemeNonMacCommon::paintTrackBackground(GraphicsContext& context, const ScrollbarThemeClient& scrollbar, const IntRect& rect)
89 { 89 {
90 // Just assume a forward track part. We only paint the track as a single pie ce when there is no thumb. 90 // Just assume a forward track part. We only paint the track as a single pie ce when there is no thumb.
91 if (!hasThumb(scrollbar)) 91 if (!hasThumb(scrollbar))
92 paintTrackPiece(context, scrollbar, rect, ForwardTrackPart); 92 paintTrackPiece(context, scrollbar, rect, ForwardTrackPart);
93 } 93 }
94 94
95 void ScrollbarThemeNonMacCommon::paintTickmarks(GraphicsContext* context, const ScrollbarThemeClient* scrollbar, const IntRect& rect) 95 void ScrollbarThemeNonMacCommon::paintTickmarks(GraphicsContext& context, const ScrollbarThemeClient& scrollbar, const IntRect& rect)
96 { 96 {
97 if (scrollbar->orientation() != VerticalScrollbar) 97 if (scrollbar.orientation() != VerticalScrollbar)
98 return; 98 return;
99 99
100 if (rect.height() <= 0 || rect.width() <= 0) 100 if (rect.height() <= 0 || rect.width() <= 0)
101 return; 101 return;
102 102
103 // Get the tickmarks for the frameview. 103 // Get the tickmarks for the frameview.
104 Vector<IntRect> tickmarks; 104 Vector<IntRect> tickmarks;
105 scrollbar->getTickmarks(tickmarks); 105 scrollbar.getTickmarks(tickmarks);
106 if (!tickmarks.size()) 106 if (!tickmarks.size())
107 return; 107 return;
108 108
109 if (DrawingRecorder::useCachedDrawingIfPossible(*context, *scrollbar, Displa yItem::ScrollbarTickmarks)) 109 if (DrawingRecorder::useCachedDrawingIfPossible(context, scrollbar, DisplayI tem::ScrollbarTickmarks))
110 return; 110 return;
111 111
112 DrawingRecorder recorder(*context, *scrollbar, DisplayItem::ScrollbarTickmar ks, rect); 112 DrawingRecorder recorder(context, scrollbar, DisplayItem::ScrollbarTickmarks , rect);
113 GraphicsContextStateSaver stateSaver(*context); 113 GraphicsContextStateSaver stateSaver(context);
114 context->setShouldAntialias(false); 114 context.setShouldAntialias(false);
115 115
116 for (Vector<IntRect>::const_iterator i = tickmarks.begin(); i != tickmarks.e nd(); ++i) { 116 for (Vector<IntRect>::const_iterator i = tickmarks.begin(); i != tickmarks.e nd(); ++i) {
117 // Calculate how far down (in %) the tick-mark should appear. 117 // Calculate how far down (in %) the tick-mark should appear.
118 const float percent = static_cast<float>(i->y()) / scrollbar->totalSize( ); 118 const float percent = static_cast<float>(i->y()) / scrollbar.totalSize() ;
119 119
120 // Calculate how far down (in pixels) the tick-mark should appear. 120 // Calculate how far down (in pixels) the tick-mark should appear.
121 const int yPos = rect.y() + (rect.height() * percent); 121 const int yPos = rect.y() + (rect.height() * percent);
122 122
123 FloatRect tickRect(rect.x(), yPos, rect.width(), 3); 123 FloatRect tickRect(rect.x(), yPos, rect.width(), 3);
124 context->fillRect(tickRect, Color(0xCC, 0xAA, 0x00, 0xFF)); 124 context.fillRect(tickRect, Color(0xCC, 0xAA, 0x00, 0xFF));
125 125
126 FloatRect tickStroke(rect.x(), yPos + 1, rect.width(), 1); 126 FloatRect tickStroke(rect.x(), yPos + 1, rect.width(), 1);
127 context->fillRect(tickStroke, Color(0xFF, 0xDD, 0x00, 0xFF)); 127 context.fillRect(tickStroke, Color(0xFF, 0xDD, 0x00, 0xFF));
128 } 128 }
129 } 129 }
130 130
131 } // namespace blink 131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698