| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/renderer/test_runner/WebTestThemeEngineMock.h" | 5 #include "content/shell/renderer/test_runner/mock_web_theme_engine.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "skia/ext/platform_canvas.h" | 8 #include "skia/ext/platform_canvas.h" |
| 9 #include "third_party/WebKit/public/platform/WebRect.h" | 9 #include "third_party/WebKit/public/platform/WebRect.h" |
| 10 #include "third_party/WebKit/public/platform/WebSize.h" | 10 #include "third_party/WebKit/public/platform/WebSize.h" |
| 11 #include "third_party/skia/include/core/SkRect.h" | 11 #include "third_party/skia/include/core/SkRect.h" |
| 12 | 12 |
| 13 using blink::WebCanvas; | 13 using blink::WebCanvas; |
| 14 using blink::WebColor; | 14 using blink::WebColor; |
| 15 using blink::WebRect; | 15 using blink::WebRect; |
| 16 using blink::WebThemeEngine; | 16 using blink::WebThemeEngine; |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 static const SkColor edgeColor = SK_ColorBLACK; | 20 namespace { |
| 21 static const SkColor readOnlyColor = SkColorSetRGB(0xe9, 0xc2, 0xa6); | 21 |
| 22 const SkColor edgeColor = SK_ColorBLACK; |
| 23 const SkColor readOnlyColor = SkColorSetRGB(0xe9, 0xc2, 0xa6); |
| 24 |
| 25 } // namespace |
| 22 | 26 |
| 23 SkColor bgColors(WebThemeEngine::State state) { | 27 SkColor bgColors(WebThemeEngine::State state) { |
| 24 switch (state) { | 28 switch (state) { |
| 25 case WebThemeEngine::StateDisabled: | 29 case WebThemeEngine::StateDisabled: |
| 26 return SkColorSetRGB(0xc9, 0xc9, 0xc9); | 30 return SkColorSetRGB(0xc9, 0xc9, 0xc9); |
| 27 case WebThemeEngine::StateHover: | 31 case WebThemeEngine::StateHover: |
| 28 return SkColorSetRGB(0x43, 0xf9, 0xff); | 32 return SkColorSetRGB(0x43, 0xf9, 0xff); |
| 29 case WebThemeEngine::StateNormal: | 33 case WebThemeEngine::StateNormal: |
| 30 return SkColorSetRGB(0x89, 0xc4, 0xff); | 34 return SkColorSetRGB(0x89, 0xc4, 0xff); |
| 31 case WebThemeEngine::StatePressed: | 35 case WebThemeEngine::StatePressed: |
| 32 return SkColorSetRGB(0xa9, 0xff, 0x12); | 36 return SkColorSetRGB(0xa9, 0xff, 0x12); |
| 33 case WebThemeEngine::StateFocused: | 37 case WebThemeEngine::StateFocused: |
| 34 return SkColorSetRGB(0x00, 0xf3, 0xac); | 38 return SkColorSetRGB(0x00, 0xf3, 0xac); |
| 35 case WebThemeEngine::StateReadonly: | 39 case WebThemeEngine::StateReadonly: |
| 36 return SkColorSetRGB(0xf3, 0xe0, 0xd0); | 40 return SkColorSetRGB(0xf3, 0xe0, 0xd0); |
| 37 default: | 41 default: |
| 38 NOTREACHED(); | 42 NOTREACHED(); |
| 39 } | 43 } |
| 40 return SkColorSetRGB(0x00, 0x00, 0xff); | 44 return SkColorSetRGB(0x00, 0x00, 0xff); |
| 41 } | 45 } |
| 42 | 46 |
| 43 blink::WebSize WebTestThemeEngineMock::getSize(WebThemeEngine::Part part) | 47 blink::WebSize MockWebThemeEngine::getSize(WebThemeEngine::Part part) { |
| 44 { | |
| 45 // FIXME: We use this constant to indicate we are being asked for the size o
f | 48 // FIXME: We use this constant to indicate we are being asked for the size o
f |
| 46 // a part that we don't expect to be asked about. We return a garbage value | 49 // a part that we don't expect to be asked about. We return a garbage value |
| 47 // rather than just asserting because this code doesn't have access to eithe
r | 50 // rather than just asserting because this code doesn't have access to eithe
r |
| 48 // WTF or base to raise an assertion or do any logging :(. | 51 // WTF or base to raise an assertion or do any logging :(. |
| 49 const blink::WebSize invalidPartSize = blink::WebSize(100, 100); | 52 const blink::WebSize invalidPartSize = blink::WebSize(100, 100); |
| 50 | 53 |
| 51 switch (part) { | 54 switch (part) { |
| 52 case WebThemeEngine::PartScrollbarLeftArrow: | 55 case WebThemeEngine::PartScrollbarLeftArrow: |
| 53 return blink::WebSize(17, 15); | 56 return blink::WebSize(17, 15); |
| 54 case WebThemeEngine::PartScrollbarRightArrow: | 57 case WebThemeEngine::PartScrollbarRightArrow: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 70 return blink::WebSize(13, 13); | 73 return blink::WebSize(13, 13); |
| 71 case WebThemeEngine::PartSliderThumb: | 74 case WebThemeEngine::PartSliderThumb: |
| 72 return blink::WebSize(11, 21); | 75 return blink::WebSize(11, 21); |
| 73 case WebThemeEngine::PartInnerSpinButton: | 76 case WebThemeEngine::PartInnerSpinButton: |
| 74 return blink::WebSize(15, 8); | 77 return blink::WebSize(15, 8); |
| 75 default: | 78 default: |
| 76 return invalidPartSize; | 79 return invalidPartSize; |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 | 82 |
| 80 static SkIRect webRectToSkIRect(const WebRect& webRect) | 83 static SkIRect webRectToSkIRect(const WebRect& webRect) { |
| 81 { | |
| 82 SkIRect irect; | 84 SkIRect irect; |
| 83 irect.set(webRect.x, webRect.y, | 85 irect.set(webRect.x, webRect.y, |
| 84 webRect.x + webRect.width - 1, webRect.y + webRect.height - 1); | 86 webRect.x + webRect.width - 1, webRect.y + webRect.height - 1); |
| 85 return irect; | 87 return irect; |
| 86 } | 88 } |
| 87 | 89 |
| 88 static SkIRect validate(const SkIRect& rect, WebThemeEngine::Part part) | 90 static SkIRect validate(const SkIRect& rect, WebThemeEngine::Part part) { |
| 89 { | |
| 90 switch (part) { | 91 switch (part) { |
| 91 case WebThemeEngine::PartCheckbox: | 92 case WebThemeEngine::PartCheckbox: |
| 92 case WebThemeEngine::PartRadio: { | 93 case WebThemeEngine::PartRadio: { |
| 93 SkIRect retval = rect; | 94 SkIRect retval = rect; |
| 94 | 95 |
| 95 // The maximum width and height is 13. | 96 // The maximum width and height is 13. |
| 96 // Center the square in the passed rectangle. | 97 // Center the square in the passed rectangle. |
| 97 const int maxControlSize = 13; | 98 const int maxControlSize = 13; |
| 98 int controlSize = std::min(rect.width(), rect.height()); | 99 int controlSize = std::min(rect.width(), rect.height()); |
| 99 controlSize = std::min(controlSize, maxControlSize); | 100 controlSize = std::min(controlSize, maxControlSize); |
| 100 | 101 |
| 101 retval.fLeft = rect.fLeft + (rect.width() / 2) - (controlSize / 2); | 102 retval.fLeft = rect.fLeft + (rect.width() / 2) - (controlSize / 2); |
| 102 retval.fRight = retval.fLeft + controlSize - 1; | 103 retval.fRight = retval.fLeft + controlSize - 1; |
| 103 retval.fTop = rect.fTop + (rect.height() / 2) - (controlSize / 2); | 104 retval.fTop = rect.fTop + (rect.height() / 2) - (controlSize / 2); |
| 104 retval.fBottom = retval.fTop + controlSize - 1; | 105 retval.fBottom = retval.fTop + controlSize - 1; |
| 105 | 106 |
| 106 return retval; | 107 return retval; |
| 107 } | 108 } |
| 108 default: | 109 default: |
| 109 return rect; | 110 return rect; |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 | 114 void box(SkCanvas* canvas, const SkIRect& rect, SkColor fillColor) { |
| 114 void box(SkCanvas *canvas, const SkIRect& rect, SkColor fillColor) | |
| 115 { | |
| 116 SkPaint paint; | 115 SkPaint paint; |
| 117 | 116 |
| 118 paint.setStyle(SkPaint::kFill_Style); | 117 paint.setStyle(SkPaint::kFill_Style); |
| 119 paint.setColor(fillColor); | 118 paint.setColor(fillColor); |
| 120 canvas->drawIRect(rect, paint); | 119 canvas->drawIRect(rect, paint); |
| 121 | 120 |
| 122 paint.setColor(edgeColor); | 121 paint.setColor(edgeColor); |
| 123 paint.setStyle(SkPaint::kStroke_Style); | 122 paint.setStyle(SkPaint::kStroke_Style); |
| 124 canvas->drawIRect(rect, paint); | 123 canvas->drawIRect(rect, paint); |
| 125 } | 124 } |
| 126 | 125 |
| 127 void line(SkCanvas *canvas, int x0, int y0, int x1, int y1, SkColor color) | 126 void line(SkCanvas* canvas, int x0, int y0, int x1, int y1, SkColor color) { |
| 128 { | |
| 129 SkPaint paint; | 127 SkPaint paint; |
| 130 paint.setColor(color); | 128 paint.setColor(color); |
| 131 canvas->drawLine(SkIntToScalar(x0), SkIntToScalar(y0), | 129 canvas->drawLine(SkIntToScalar(x0), |
| 132 SkIntToScalar(x1), SkIntToScalar(y1), paint); | 130 SkIntToScalar(y0), |
| 131 SkIntToScalar(x1), |
| 132 SkIntToScalar(y1), |
| 133 paint); |
| 133 } | 134 } |
| 134 | 135 |
| 135 void triangle(SkCanvas *canvas, | 136 void triangle(SkCanvas* canvas, |
| 136 int x0, int y0, | 137 int x0, |
| 137 int x1, int y1, | 138 int y0, |
| 138 int x2, int y2, | 139 int x1, |
| 139 SkColor color) | 140 int y1, |
| 140 { | 141 int x2, |
| 142 int y2, |
| 143 SkColor color) { |
| 141 SkPath path; | 144 SkPath path; |
| 142 SkPaint paint; | 145 SkPaint paint; |
| 143 | 146 |
| 144 paint.setColor(color); | 147 paint.setColor(color); |
| 145 paint.setStyle(SkPaint::kFill_Style); | 148 paint.setStyle(SkPaint::kFill_Style); |
| 146 path.incReserve(4); | 149 path.incReserve(4); |
| 147 path.moveTo(SkIntToScalar(x0), SkIntToScalar(y0)); | 150 path.moveTo(SkIntToScalar(x0), SkIntToScalar(y0)); |
| 148 path.lineTo(SkIntToScalar(x1), SkIntToScalar(y1)); | 151 path.lineTo(SkIntToScalar(x1), SkIntToScalar(y1)); |
| 149 path.lineTo(SkIntToScalar(x2), SkIntToScalar(y2)); | 152 path.lineTo(SkIntToScalar(x2), SkIntToScalar(y2)); |
| 150 path.close(); | 153 path.close(); |
| 151 canvas->drawPath(path, paint); | 154 canvas->drawPath(path, paint); |
| 152 | 155 |
| 153 paint.setColor(edgeColor); | 156 paint.setColor(edgeColor); |
| 154 paint.setStyle(SkPaint::kStroke_Style); | 157 paint.setStyle(SkPaint::kStroke_Style); |
| 155 canvas->drawPath(path, paint); | 158 canvas->drawPath(path, paint); |
| 156 } | 159 } |
| 157 | 160 |
| 158 void roundRect(SkCanvas *canvas, SkIRect irect, SkColor color) | 161 void roundRect(SkCanvas* canvas, SkIRect irect, SkColor color) { |
| 159 { | |
| 160 SkRect rect; | 162 SkRect rect; |
| 161 SkScalar radius = SkIntToScalar(5); | 163 SkScalar radius = SkIntToScalar(5); |
| 162 SkPaint paint; | 164 SkPaint paint; |
| 163 | 165 |
| 164 rect.set(irect); | 166 rect.set(irect); |
| 165 paint.setColor(color); | 167 paint.setColor(color); |
| 166 paint.setStyle(SkPaint::kFill_Style); | 168 paint.setStyle(SkPaint::kFill_Style); |
| 167 canvas->drawRoundRect(rect, radius, radius, paint); | 169 canvas->drawRoundRect(rect, radius, radius, paint); |
| 168 | 170 |
| 169 paint.setColor(edgeColor); | 171 paint.setColor(edgeColor); |
| 170 paint.setStyle(SkPaint::kStroke_Style); | 172 paint.setStyle(SkPaint::kStroke_Style); |
| 171 canvas->drawRoundRect(rect, radius, radius, paint); | 173 canvas->drawRoundRect(rect, radius, radius, paint); |
| 172 } | 174 } |
| 173 | 175 |
| 174 void oval(SkCanvas* canvas, SkIRect irect, SkColor color) | 176 void oval(SkCanvas* canvas, SkIRect irect, SkColor color) { |
| 175 { | |
| 176 SkRect rect; | 177 SkRect rect; |
| 177 SkPaint paint; | 178 SkPaint paint; |
| 178 | 179 |
| 179 rect.set(irect); | 180 rect.set(irect); |
| 180 paint.setColor(color); | 181 paint.setColor(color); |
| 181 paint.setStyle(SkPaint::kFill_Style); | 182 paint.setStyle(SkPaint::kFill_Style); |
| 182 canvas->drawOval(rect, paint); | 183 canvas->drawOval(rect, paint); |
| 183 | 184 |
| 184 paint.setColor(edgeColor); | 185 paint.setColor(edgeColor); |
| 185 paint.setStyle(SkPaint::kStroke_Style); | 186 paint.setStyle(SkPaint::kStroke_Style); |
| 186 canvas->drawOval(rect, paint); | 187 canvas->drawOval(rect, paint); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void circle(SkCanvas *canvas, SkIRect irect, SkScalar radius, SkColor color) | 190 void circle(SkCanvas* canvas, SkIRect irect, SkScalar radius, SkColor color) { |
| 190 { | |
| 191 int left = irect.fLeft; | 191 int left = irect.fLeft; |
| 192 int width = irect.width(); | 192 int width = irect.width(); |
| 193 int height = irect.height(); | 193 int height = irect.height(); |
| 194 int top = irect.fTop; | 194 int top = irect.fTop; |
| 195 | 195 |
| 196 SkScalar cy = SkIntToScalar(top + height / 2); | 196 SkScalar cy = SkIntToScalar(top + height / 2); |
| 197 SkScalar cx = SkIntToScalar(left + width / 2); | 197 SkScalar cx = SkIntToScalar(left + width / 2); |
| 198 SkPaint paint; | 198 SkPaint paint; |
| 199 | 199 |
| 200 paint.setColor(color); | 200 paint.setColor(color); |
| 201 paint.setStyle(SkPaint::kFill_Style); | 201 paint.setStyle(SkPaint::kFill_Style); |
| 202 canvas->drawCircle(cx, cy, radius, paint); | 202 canvas->drawCircle(cx, cy, radius, paint); |
| 203 | 203 |
| 204 paint.setColor(edgeColor); | 204 paint.setColor(edgeColor); |
| 205 paint.setStyle(SkPaint::kStroke_Style); | 205 paint.setStyle(SkPaint::kStroke_Style); |
| 206 canvas->drawCircle(cx, cy, radius, paint); | 206 canvas->drawCircle(cx, cy, radius, paint); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void nestedBoxes(SkCanvas *canvas, | 209 void nestedBoxes(SkCanvas* canvas, |
| 210 SkIRect irect, | 210 SkIRect irect, |
| 211 int indentLeft, | 211 int indentLeft, |
| 212 int indentTop, | 212 int indentTop, |
| 213 int indentRight, | 213 int indentRight, |
| 214 int indentBottom, | 214 int indentBottom, |
| 215 SkColor outerColor, | 215 SkColor outerColor, |
| 216 SkColor innerColor) | 216 SkColor innerColor) { |
| 217 { | |
| 218 SkIRect lirect; | 217 SkIRect lirect; |
| 219 box(canvas, irect, outerColor); | 218 box(canvas, irect, outerColor); |
| 220 lirect.set(irect.fLeft + indentLeft, | 219 lirect.set(irect.fLeft + indentLeft, |
| 221 irect.fTop + indentTop, | 220 irect.fTop + indentTop, |
| 222 irect.fRight - indentRight, | 221 irect.fRight - indentRight, |
| 223 irect.fBottom - indentBottom); | 222 irect.fBottom - indentBottom); |
| 224 box(canvas, lirect, innerColor); | 223 box(canvas, lirect, innerColor); |
| 225 } | 224 } |
| 226 | 225 |
| 227 void insetBox(SkCanvas* canvas, | 226 void insetBox(SkCanvas* canvas, |
| 228 SkIRect irect, | 227 SkIRect irect, |
| 229 int indentLeft, | 228 int indentLeft, |
| 230 int indentTop, | 229 int indentTop, |
| 231 int indentRight, | 230 int indentRight, |
| 232 int indentBottom, | 231 int indentBottom, |
| 233 SkColor color) { | 232 SkColor color) { |
| 234 SkIRect lirect; | 233 SkIRect lirect; |
| 235 lirect.set(irect.fLeft + indentLeft, | 234 lirect.set(irect.fLeft + indentLeft, |
| 236 irect.fTop + indentTop, | 235 irect.fTop + indentTop, |
| 237 irect.fRight - indentRight, | 236 irect.fRight - indentRight, |
| 238 irect.fBottom - indentBottom); | 237 irect.fBottom - indentBottom); |
| 239 box(canvas, lirect, color); | 238 box(canvas, lirect, color); |
| 240 } | 239 } |
| 241 | 240 |
| 242 void markState(SkCanvas *canvas, SkIRect irect, WebThemeEngine::State state) | 241 void markState(SkCanvas* canvas, SkIRect irect, WebThemeEngine::State state) { |
| 243 { | |
| 244 int left = irect.fLeft; | 242 int left = irect.fLeft; |
| 245 int right = irect.fRight; | 243 int right = irect.fRight; |
| 246 int top = irect.fTop; | 244 int top = irect.fTop; |
| 247 int bottom = irect.fBottom; | 245 int bottom = irect.fBottom; |
| 248 | 246 |
| 249 // The length of a triangle side for the corner marks. | 247 // The length of a triangle side for the corner marks. |
| 250 const int triangleSize = 5; | 248 const int triangleSize = 5; |
| 251 | 249 |
| 252 switch (state) { | 250 switch (state) { |
| 253 case WebThemeEngine::StateDisabled: | 251 case WebThemeEngine::StateDisabled: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 edgeColor); | 289 edgeColor); |
| 292 break; | 290 break; |
| 293 | 291 |
| 294 default: | 292 default: |
| 295 // FIXME: Should we do something here to indicate that we got an invalid
state? | 293 // FIXME: Should we do something here to indicate that we got an invalid
state? |
| 296 // Unfortunately, we can't assert because we don't have access to WTF or
base. | 294 // Unfortunately, we can't assert because we don't have access to WTF or
base. |
| 297 break; | 295 break; |
| 298 } | 296 } |
| 299 } | 297 } |
| 300 | 298 |
| 301 void WebTestThemeEngineMock::paint( | 299 void MockWebThemeEngine::paint(blink::WebCanvas* canvas, |
| 302 blink::WebCanvas* canvas, | 300 WebThemeEngine::Part part, |
| 303 WebThemeEngine::Part part, | 301 WebThemeEngine::State state, |
| 304 WebThemeEngine::State state, | 302 const blink::WebRect& rect, |
| 305 const blink::WebRect& rect, | 303 const WebThemeEngine::ExtraParams* extraParams) { |
| 306 const WebThemeEngine::ExtraParams* extraParams) | |
| 307 { | |
| 308 SkIRect irect = webRectToSkIRect(rect); | 304 SkIRect irect = webRectToSkIRect(rect); |
| 309 SkPaint paint; | 305 SkPaint paint; |
| 310 | 306 |
| 311 // Indent amounts for the check in a checkbox or radio button. | 307 // Indent amounts for the check in a checkbox or radio button. |
| 312 const int checkIndent = 3; | 308 const int checkIndent = 3; |
| 313 | 309 |
| 314 // Indent amounts for short and long sides of the scrollbar notches. | 310 // Indent amounts for short and long sides of the scrollbar notches. |
| 315 const int notchLongOffset = 1; | 311 const int notchLongOffset = 1; |
| 316 const int notchShortOffset = 4; | 312 const int notchShortOffset = 4; |
| 317 const int noOffset = 0; | 313 const int noOffset = 0; |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 break; | 635 break; |
| 640 } | 636 } |
| 641 default: | 637 default: |
| 642 // FIXME: Should we do something here to indicate that we got an invalid
part? | 638 // FIXME: Should we do something here to indicate that we got an invalid
part? |
| 643 // Unfortunately, we can't assert because we don't have access to WTF or
base. | 639 // Unfortunately, we can't assert because we don't have access to WTF or
base. |
| 644 break; | 640 break; |
| 645 } | 641 } |
| 646 } | 642 } |
| 647 | 643 |
| 648 } // namespace content | 644 } // namespace content |
| OLD | NEW |