OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, 2009, 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "public/platform/WebRect.h" | 42 #include "public/platform/WebRect.h" |
43 #include "public/platform/WebThemeEngine.h" | 43 #include "public/platform/WebThemeEngine.h" |
44 | 44 |
45 namespace blink { | 45 namespace blink { |
46 | 46 |
47 static bool useMockTheme() | 47 static bool useMockTheme() |
48 { | 48 { |
49 return LayoutTestSupport::isRunningLayoutTest(); | 49 return LayoutTestSupport::isRunningLayoutTest(); |
50 } | 50 } |
51 | 51 |
52 ScrollbarTheme* ScrollbarTheme::nativeTheme() | 52 ScrollbarTheme& ScrollbarTheme::nativeTheme() |
53 { | 53 { |
54 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { | 54 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { |
55 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme
Overlay::AllowHitTest)); | 55 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme
Overlay::AllowHitTest)); |
56 return &theme; | 56 return theme; |
57 } | 57 } |
58 | 58 |
59 DEFINE_STATIC_LOCAL(ScrollbarThemeAura, theme, ()); | 59 DEFINE_STATIC_LOCAL(ScrollbarThemeAura, theme, ()); |
60 return &theme; | 60 return theme; |
61 } | 61 } |
62 | 62 |
63 int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize) | 63 int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize) |
64 { | 64 { |
65 // Horiz and Vert scrollbars are the same thickness. | 65 // Horiz and Vert scrollbars are the same thickness. |
66 // In unit tests we don't have the mock theme engine (because of layering vi
olations), so we hard code the size (see bug 327470). | 66 // In unit tests we don't have the mock theme engine (because of layering vi
olations), so we hard code the size (see bug 327470). |
67 if (useMockTheme()) | 67 if (useMockTheme()) |
68 return 15; | 68 return 15; |
69 IntSize scrollbarSize = Platform::current()->themeEngine()->getSize(WebTheme
Engine::PartScrollbarVerticalTrack); | 69 IntSize scrollbarSize = Platform::current()->themeEngine()->getSize(WebTheme
Engine::PartScrollbarVerticalTrack); |
70 return scrollbarSize.width(); | 70 return scrollbarSize.width(); |
71 } | 71 } |
72 | 72 |
73 void ScrollbarThemeAura::paintTrackPiece(GraphicsContext* gc, const ScrollbarThe
meClient* scrollbar, const IntRect& rect, ScrollbarPart partType) | 73 void ScrollbarThemeAura::paintTrackPiece(GraphicsContext& gc, const ScrollbarThe
meClient& scrollbar, const IntRect& rect, ScrollbarPart partType) |
74 { | 74 { |
75 DisplayItem::Type displayItemType = trackPiecePartToDisplayItemType(partType
); | 75 DisplayItem::Type displayItemType = trackPiecePartToDisplayItemType(partType
); |
76 if (DrawingRecorder::useCachedDrawingIfPossible(*gc, *scrollbar, displayItem
Type)) | 76 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy
pe)) |
77 return; | 77 return; |
78 | 78 |
79 DrawingRecorder recorder(*gc, *scrollbar, displayItemType, rect); | 79 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); |
80 | 80 |
81 WebThemeEngine::State state = scrollbar->hoveredPart() == partType ? WebThem
eEngine::StateHover : WebThemeEngine::StateNormal; | 81 WebThemeEngine::State state = scrollbar.hoveredPart() == partType ? WebTheme
Engine::StateHover : WebThemeEngine::StateNormal; |
82 | 82 |
83 if (useMockTheme() && !scrollbar->enabled()) | 83 if (useMockTheme() && !scrollbar.enabled()) |
84 state = WebThemeEngine::StateDisabled; | 84 state = WebThemeEngine::StateDisabled; |
85 | 85 |
86 IntRect alignRect = trackRect(scrollbar, false); | 86 IntRect alignRect = trackRect(scrollbar, false); |
87 WebThemeEngine::ExtraParams extraParams; | 87 WebThemeEngine::ExtraParams extraParams; |
88 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart); | 88 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart); |
89 extraParams.scrollbarTrack.trackX = alignRect.x(); | 89 extraParams.scrollbarTrack.trackX = alignRect.x(); |
90 extraParams.scrollbarTrack.trackY = alignRect.y(); | 90 extraParams.scrollbarTrack.trackY = alignRect.y(); |
91 extraParams.scrollbarTrack.trackWidth = alignRect.width(); | 91 extraParams.scrollbarTrack.trackWidth = alignRect.width(); |
92 extraParams.scrollbarTrack.trackHeight = alignRect.height(); | 92 extraParams.scrollbarTrack.trackHeight = alignRect.height(); |
93 Platform::current()->themeEngine()->paint(gc->canvas(), scrollbar->orientati
on() == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalTrack : Web
ThemeEngine::PartScrollbarVerticalTrack, state, WebRect(rect), &extraParams); | 93 Platform::current()->themeEngine()->paint(gc.canvas(), scrollbar.orientation
() == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalTrack : WebTh
emeEngine::PartScrollbarVerticalTrack, state, WebRect(rect), &extraParams); |
94 } | 94 } |
95 | 95 |
96 void ScrollbarThemeAura::paintButton(GraphicsContext* gc, const ScrollbarThemeCl
ient* scrollbar, const IntRect& rect, ScrollbarPart part) | 96 void ScrollbarThemeAura::paintButton(GraphicsContext& gc, const ScrollbarThemeCl
ient& scrollbar, const IntRect& rect, ScrollbarPart part) |
97 { | 97 { |
98 WebThemeEngine::Part paintPart; | 98 WebThemeEngine::Part paintPart; |
99 WebThemeEngine::State state = WebThemeEngine::StateNormal; | 99 WebThemeEngine::State state = WebThemeEngine::StateNormal; |
100 bool checkMin = false; | 100 bool checkMin = false; |
101 bool checkMax = false; | 101 bool checkMax = false; |
102 | 102 |
103 if (scrollbar->orientation() == HorizontalScrollbar) { | 103 if (scrollbar.orientation() == HorizontalScrollbar) { |
104 if (part == BackButtonStartPart) { | 104 if (part == BackButtonStartPart) { |
105 paintPart = WebThemeEngine::PartScrollbarLeftArrow; | 105 paintPart = WebThemeEngine::PartScrollbarLeftArrow; |
106 checkMin = true; | 106 checkMin = true; |
107 } else if (useMockTheme() && part != ForwardButtonEndPart) { | 107 } else if (useMockTheme() && part != ForwardButtonEndPart) { |
108 return; | 108 return; |
109 } else { | 109 } else { |
110 paintPart = WebThemeEngine::PartScrollbarRightArrow; | 110 paintPart = WebThemeEngine::PartScrollbarRightArrow; |
111 checkMax = true; | 111 checkMax = true; |
112 } | 112 } |
113 } else { | 113 } else { |
114 if (part == BackButtonStartPart) { | 114 if (part == BackButtonStartPart) { |
115 paintPart = WebThemeEngine::PartScrollbarUpArrow; | 115 paintPart = WebThemeEngine::PartScrollbarUpArrow; |
116 checkMin = true; | 116 checkMin = true; |
117 } else if (useMockTheme() && part != ForwardButtonEndPart) { | 117 } else if (useMockTheme() && part != ForwardButtonEndPart) { |
118 return; | 118 return; |
119 } else { | 119 } else { |
120 paintPart = WebThemeEngine::PartScrollbarDownArrow; | 120 paintPart = WebThemeEngine::PartScrollbarDownArrow; |
121 checkMax = true; | 121 checkMax = true; |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 DisplayItem::Type displayItemType = buttonPartToDisplayItemType(part); | 125 DisplayItem::Type displayItemType = buttonPartToDisplayItemType(part); |
126 if (DrawingRecorder::useCachedDrawingIfPossible(*gc, *scrollbar, displayItem
Type)) | 126 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy
pe)) |
127 return; | 127 return; |
128 | 128 |
129 DrawingRecorder recorder(*gc, *scrollbar, displayItemType, rect); | 129 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); |
130 | 130 |
131 if (useMockTheme() && !scrollbar->enabled()) { | 131 if (useMockTheme() && !scrollbar.enabled()) { |
132 state = WebThemeEngine::StateDisabled; | 132 state = WebThemeEngine::StateDisabled; |
133 } else if (!useMockTheme() && ((checkMin && (scrollbar->currentPos() <= 0)) | 133 } else if (!useMockTheme() && ((checkMin && (scrollbar.currentPos() <= 0)) |
134 || (checkMax && scrollbar->currentPos() >= scrollbar->maximum()))) { | 134 || (checkMax && scrollbar.currentPos() >= scrollbar.maximum()))) { |
135 state = WebThemeEngine::StateDisabled; | 135 state = WebThemeEngine::StateDisabled; |
136 } else { | 136 } else { |
137 if (part == scrollbar->pressedPart()) | 137 if (part == scrollbar.pressedPart()) |
138 state = WebThemeEngine::StatePressed; | 138 state = WebThemeEngine::StatePressed; |
139 else if (part == scrollbar->hoveredPart()) | 139 else if (part == scrollbar.hoveredPart()) |
140 state = WebThemeEngine::StateHover; | 140 state = WebThemeEngine::StateHover; |
141 } | 141 } |
142 Platform::current()->themeEngine()->paint(gc->canvas(), paintPart, state, We
bRect(rect), 0); | 142 Platform::current()->themeEngine()->paint(gc.canvas(), paintPart, state, Web
Rect(rect), 0); |
143 } | 143 } |
144 | 144 |
145 void ScrollbarThemeAura::paintThumb(GraphicsContext* gc, const ScrollbarThemeCli
ent* scrollbar, const IntRect& rect) | 145 void ScrollbarThemeAura::paintThumb(GraphicsContext& gc, const ScrollbarThemeCli
ent& scrollbar, const IntRect& rect) |
146 { | 146 { |
147 if (DrawingRecorder::useCachedDrawingIfPossible(*gc, *scrollbar, DisplayItem
::ScrollbarThumb)) | 147 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, DisplayItem::
ScrollbarThumb)) |
148 return; | 148 return; |
149 | 149 |
150 DrawingRecorder recorder(*gc, *scrollbar, DisplayItem::ScrollbarThumb, rect)
; | 150 DrawingRecorder recorder(gc, scrollbar, DisplayItem::ScrollbarThumb, rect); |
151 | 151 |
152 WebThemeEngine::State state; | 152 WebThemeEngine::State state; |
153 WebCanvas* canvas = gc->canvas(); | 153 WebCanvas* canvas = gc.canvas(); |
154 if (scrollbar->pressedPart() == ThumbPart) | 154 if (scrollbar.pressedPart() == ThumbPart) |
155 state = WebThemeEngine::StatePressed; | 155 state = WebThemeEngine::StatePressed; |
156 else if (scrollbar->hoveredPart() == ThumbPart) | 156 else if (scrollbar.hoveredPart() == ThumbPart) |
157 state = WebThemeEngine::StateHover; | 157 state = WebThemeEngine::StateHover; |
158 else | 158 else |
159 state = WebThemeEngine::StateNormal; | 159 state = WebThemeEngine::StateNormal; |
160 Platform::current()->themeEngine()->paint(canvas, scrollbar->orientation() =
= HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalThumb : WebThemeE
ngine::PartScrollbarVerticalThumb, state, WebRect(rect), 0); | 160 Platform::current()->themeEngine()->paint(canvas, scrollbar.orientation() ==
HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalThumb : WebThemeEn
gine::PartScrollbarVerticalThumb, state, WebRect(rect), 0); |
161 } | 161 } |
162 | 162 |
163 IntSize ScrollbarThemeAura::buttonSize(const ScrollbarThemeClient* scrollbar) | 163 IntSize ScrollbarThemeAura::buttonSize(const ScrollbarThemeClient& scrollbar) |
164 { | 164 { |
165 if (scrollbar->orientation() == VerticalScrollbar) { | 165 if (scrollbar.orientation() == VerticalScrollbar) { |
166 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin
e::PartScrollbarUpArrow); | 166 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin
e::PartScrollbarUpArrow); |
167 return IntSize(size.width(), scrollbar->height() < 2 * size.height() ? s
crollbar->height() / 2 : size.height()); | 167 return IntSize(size.width(), scrollbar.height() < 2 * size.height() ? sc
rollbar.height() / 2 : size.height()); |
168 } | 168 } |
169 | 169 |
170 // HorizontalScrollbar | 170 // HorizontalScrollbar |
171 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P
artScrollbarLeftArrow); | 171 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P
artScrollbarLeftArrow); |
172 return IntSize(scrollbar->width() < 2 * size.width() ? scrollbar->width() /
2 : size.width(), size.height()); | 172 return IntSize(scrollbar.width() < 2 * size.width() ? scrollbar.width() / 2
: size.width(), size.height()); |
173 } | 173 } |
174 | 174 |
175 int ScrollbarThemeAura::minimumThumbLength(const ScrollbarThemeClient* scrollbar
) | 175 int ScrollbarThemeAura::minimumThumbLength(const ScrollbarThemeClient& scrollbar
) |
176 { | 176 { |
177 if (scrollbar->orientation() == VerticalScrollbar) { | 177 if (scrollbar.orientation() == VerticalScrollbar) { |
178 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin
e::PartScrollbarVerticalThumb); | 178 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin
e::PartScrollbarVerticalThumb); |
179 return size.height(); | 179 return size.height(); |
180 } | 180 } |
181 | 181 |
182 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P
artScrollbarHorizontalThumb); | 182 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P
artScrollbarHorizontalThumb); |
183 return size.width(); | 183 return size.width(); |
184 } | 184 } |
185 | 185 |
186 } // namespace blink | 186 } // namespace blink |
OLD | NEW |