summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell/test_shell_webthemeengine.cc
blob: b9e0308c3eb0b812277cc689bbf8db654d7fb488 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file implements a simple generic version of the WebKitThemeEngine,
// Since WebThemeEngine is unfortunately defined in terms of the Windows
// Theme parameters and values, we need to translate all the values into
// generic equivalents that we can more easily understand. This file does
// that translation (acting as a Facade design pattern) and then uses
// TestShellWebTheme::Control for the actual rendering of the widgets.
//

#include "webkit/tools/test_shell/test_shell_webthemeengine.h"

// Although all this code is generic, we include these headers
// to pull in the Windows #defines for the parts and states of
// the controls.
#include <vsstyle.h>
#include <windows.h>

#include "base/logging.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCanvas.h"
#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
#include "webkit/tools/test_shell/test_shell_webthemecontrol.h"
#include "third_party/skia/include/core/SkRect.h"

#ifndef CHECK_EQ
#define CHECK_EQ(a, b) CHECK((a) == (b))
#endif

// We define this for clarity, although there really should be a DFCS_NORMAL
// in winuser.h.
namespace {
  const int kDFCSNormal = 0x0000;
}

using WebKit::WebCanvas;
using WebKit::WebColor;
using WebKit::WebRect;

namespace TestShellWebTheme {

SkIRect webRectToSkIRect(const WebRect &web_rect) {
  SkIRect irect;
  irect.set(web_rect.x, web_rect.y, web_rect.x + web_rect.width,
            web_rect.y + web_rect.height);
  return irect;
}

void drawControl(WebCanvas *canvas, const WebRect &rect, Control::Type ctype,
                 Control::State cstate) {
  Control control(canvas, webRectToSkIRect(rect), ctype, cstate);
  control.draw();
}

void drawTextField(WebCanvas *canvas, const WebRect &rect,
                   Control::Type ctype, Control::State cstate,
                   bool draw_edges, bool fill_content_area, WebColor color) {
  Control control(canvas, webRectToSkIRect(rect), ctype, cstate);
  control.drawTextField(draw_edges, fill_content_area, color);
}

void Engine::paintButton(WebCanvas* canvas, int part, int state,
                         int classic_state, const WebRect& rect) {
  Control::Type ctype = Control::kUnknown_Type;
  Control::State cstate = Control::kUnknown_State;

  if (part == BP_CHECKBOX) {
    switch (state) {
      case CBS_UNCHECKEDNORMAL:
        CHECK_EQ(classic_state, kDFCSNormal);
        ctype = Control::kUncheckedBox_Type;
        cstate = Control::kNormal_State;
        break;
      case CBS_UNCHECKEDHOT:
        CHECK_EQ(classic_state, DFCS_BUTTONCHECK | DFCS_HOT);
        ctype = Control::kUncheckedBox_Type;
        cstate = Control::kHot_State;
        break;
      case CBS_UNCHECKEDPRESSED:
        CHECK_EQ(classic_state, DFCS_BUTTONCHECK | DFCS_PUSHED);
        ctype = Control::kUncheckedBox_Type;
        cstate = Control::kPressed_State;
        break;
      case CBS_UNCHECKEDDISABLED:
        CHECK_EQ(classic_state, DFCS_BUTTONCHECK | DFCS_INACTIVE);
        ctype = Control::kUncheckedBox_Type;
        cstate = Control::kDisabled_State;
        break;
      case CBS_CHECKEDNORMAL:
        CHECK_EQ(classic_state, DFCS_BUTTONCHECK | DFCS_CHECKED);
        ctype = Control::kCheckedBox_Type;
        cstate = Control::kNormal_State;
        break;
      case CBS_CHECKEDHOT:
        CHECK_EQ(classic_state, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_HOT);
        ctype = Control::kCheckedBox_Type;
        cstate = Control::kHot_State;
        break;
      case CBS_CHECKEDPRESSED:
        CHECK_EQ(classic_state, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_PUSHED);
        ctype = Control::kCheckedBox_Type;
        cstate = Control::kPressed_State;
        break;
      case CBS_CHECKEDDISABLED:
        CHECK_EQ(classic_state,
                 DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_INACTIVE);
        ctype = Control::kCheckedBox_Type;
        cstate = Control::kDisabled_State;
        break;
      default:
        NOTREACHED();
        break;
    }
  } else if (BP_RADIOBUTTON == part) {
    switch (state) {
      case RBS_UNCHECKEDNORMAL:
        CHECK_EQ(classic_state, DFCS_BUTTONRADIO);
        ctype = Control::kUncheckedRadio_Type;
        cstate = Control::kNormal_State;
        break;
      case RBS_UNCHECKEDHOT:
        CHECK_EQ(classic_state, DFCS_BUTTONRADIO | DFCS_HOT);
        ctype = Control::kUncheckedRadio_Type;
        cstate = Control::kHot_State;
        break;
      case RBS_UNCHECKEDPRESSED:
        CHECK_EQ(classic_state, DFCS_BUTTONRADIO | DFCS_PUSHED);
        ctype = Control::kUncheckedRadio_Type;
        cstate = Control::kPressed_State;
        break;
      case RBS_UNCHECKEDDISABLED:
        CHECK_EQ(classic_state, DFCS_BUTTONRADIO | DFCS_INACTIVE);
        ctype = Control::kUncheckedRadio_Type;
        cstate = Control::kDisabled_State;
        break;
      case RBS_CHECKEDNORMAL:
        CHECK_EQ(classic_state, DFCS_BUTTONRADIO | DFCS_CHECKED);
        ctype = Control::kCheckedRadio_Type;
        cstate = Control::kNormal_State;
        break;
      case RBS_CHECKEDHOT:
        CHECK_EQ(classic_state, DFCS_BUTTONRADIO | DFCS_CHECKED | DFCS_HOT);
        ctype = Control::kCheckedRadio_Type;
        cstate = Control::kHot_State;
        break;
      case RBS_CHECKEDPRESSED:
        CHECK_EQ(classic_state, DFCS_BUTTONRADIO | DFCS_CHECKED | DFCS_PUSHED);
        ctype = Control::kCheckedRadio_Type;
        cstate = Control::kPressed_State;
        break;
      case RBS_CHECKEDDISABLED:
        CHECK_EQ(classic_state,
                 DFCS_BUTTONRADIO | DFCS_CHECKED | DFCS_INACTIVE);
        ctype = Control::kCheckedRadio_Type;
        cstate = Control::kDisabled_State;
        break;
      default:
        NOTREACHED();
        break;
    }
  } else if (BP_PUSHBUTTON == part) {
    switch (state) {
      case PBS_NORMAL:
        CHECK_EQ(classic_state, DFCS_BUTTONPUSH);
        ctype = Control::kPushButton_Type;
        cstate = Control::kNormal_State;
        break;
      case PBS_HOT:
        CHECK_EQ(classic_state, DFCS_BUTTONPUSH | DFCS_HOT);
        ctype = Control::kPushButton_Type;
        cstate = Control::kHot_State;
        break;
      case PBS_PRESSED:
        CHECK_EQ(classic_state, DFCS_BUTTONPUSH | DFCS_PUSHED);
        ctype = Control::kPushButton_Type;
        cstate = Control::kPressed_State;
        break;
      case PBS_DISABLED:
        CHECK_EQ(classic_state, DFCS_BUTTONPUSH | DFCS_INACTIVE);
        ctype = Control::kPushButton_Type;
        cstate = Control::kDisabled_State;
        break;
      case PBS_DEFAULTED:
        CHECK_EQ(classic_state, DFCS_BUTTONPUSH);
        ctype = Control::kPushButton_Type;
        cstate = Control::kFocused_State;
        break;
      default:
        NOTREACHED();
        break;
    }
  } else {
    NOTREACHED();
  }

  drawControl(canvas, rect, ctype, cstate);
}


void Engine::paintMenuList(WebCanvas* canvas, int part, int state,
                           int classic_state, const WebRect& rect) {
  Control::Type ctype = Control::kUnknown_Type;
  Control::State cstate = Control::kUnknown_State;

  if (CP_DROPDOWNBUTTON == part) {
    ctype = Control::kDropDownButton_Type;
    switch (state) {
      case CBXS_NORMAL:
        CHECK_EQ(classic_state, DFCS_MENUARROW);
        cstate = Control::kNormal_State;
        break;
      case CBXS_HOT:
        CHECK_EQ(classic_state, DFCS_MENUARROW | DFCS_HOT);
        cstate = Control::kHover_State;
        break;
      case CBXS_PRESSED:
        CHECK_EQ(classic_state, DFCS_MENUARROW | DFCS_PUSHED);
        cstate = Control::kPressed_State;
        break;
      case CBXS_DISABLED:
        CHECK_EQ(classic_state, DFCS_MENUARROW | DFCS_INACTIVE);
        cstate = Control::kDisabled_State;
        break;
      default:
        CHECK(false);
        break;
    }
  } else {
    CHECK(false);
  }

  drawControl(canvas, rect, ctype, cstate);
}

void Engine::paintScrollbarArrow(WebCanvas* canvas, int state,
                                 int classic_state, const WebRect& rect) {
  Control::Type ctype = Control::kUnknown_Type;
  Control::State cstate = Control::kUnknown_State;

  switch (state) {
    case ABS_UPNORMAL:
      CHECK_EQ(classic_state, DFCS_SCROLLUP);
      ctype = Control::kUpArrow_Type;
      cstate = Control::kNormal_State;
      break;
    case ABS_DOWNNORMAL:
      CHECK_EQ(classic_state, DFCS_SCROLLDOWN);
      ctype = Control::kDownArrow_Type;
      cstate = Control::kNormal_State;
      break;
    case ABS_LEFTNORMAL:
      CHECK_EQ(classic_state, DFCS_SCROLLLEFT);
      ctype = Control::kLeftArrow_Type;
      cstate = Control::kNormal_State;
      break;
    case ABS_RIGHTNORMAL:
      CHECK_EQ(classic_state, DFCS_SCROLLRIGHT);
      ctype = Control::kRightArrow_Type;
      cstate = Control::kNormal_State;
      break;
    case ABS_UPHOT:
      CHECK_EQ(classic_state, DFCS_SCROLLUP | DFCS_HOT);
      ctype = Control::kUpArrow_Type;
      cstate = Control::kHot_State;
      break;
    case ABS_DOWNHOT:
      CHECK_EQ(classic_state, DFCS_SCROLLDOWN | DFCS_HOT);
      ctype = Control::kDownArrow_Type;
      cstate = Control::kHot_State;
      break;
    case ABS_LEFTHOT:
      CHECK_EQ(classic_state, DFCS_SCROLLLEFT | DFCS_HOT);
      ctype = Control::kLeftArrow_Type;
      cstate = Control::kHot_State;
      break;
    case ABS_RIGHTHOT:
      CHECK_EQ(classic_state, DFCS_SCROLLRIGHT | DFCS_HOT);
      ctype = Control::kRightArrow_Type;
      cstate = Control::kHot_State;
      break;
    case ABS_UPHOVER:
      CHECK_EQ(classic_state, DFCS_SCROLLUP);
      ctype = Control::kUpArrow_Type;
      cstate = Control::kHover_State;
      break;
    case ABS_DOWNHOVER:
      CHECK_EQ(classic_state, DFCS_SCROLLDOWN);
      ctype = Control::kDownArrow_Type;
      cstate = Control::kHover_State;
      break;
    case ABS_LEFTHOVER:
      CHECK_EQ(classic_state, DFCS_SCROLLLEFT);
      ctype = Control::kLeftArrow_Type;
      cstate = Control::kHover_State;
      break;
    case ABS_RIGHTHOVER:
      CHECK_EQ(classic_state, DFCS_SCROLLRIGHT);
      ctype = Control::kRightArrow_Type;
      cstate = Control::kHover_State;
      break;
    case ABS_UPPRESSED:
      CHECK_EQ(classic_state, DFCS_SCROLLUP | DFCS_PUSHED | DFCS_FLAT);
      ctype = Control::kUpArrow_Type;
      cstate = Control::kPressed_State;
      break;
    case ABS_DOWNPRESSED:
      CHECK_EQ(classic_state, DFCS_SCROLLDOWN | DFCS_PUSHED | DFCS_FLAT);
      ctype = Control::kDownArrow_Type;
      cstate = Control::kPressed_State;
      break;
    case ABS_LEFTPRESSED:
      CHECK_EQ(classic_state, DFCS_SCROLLLEFT | DFCS_PUSHED | DFCS_FLAT);
      ctype = Control::kLeftArrow_Type;
      cstate = Control::kPressed_State;
      break;
    case ABS_RIGHTPRESSED:
      CHECK_EQ(classic_state, DFCS_SCROLLRIGHT | DFCS_PUSHED | DFCS_FLAT);
      ctype = Control::kRightArrow_Type;
      cstate = Control::kPressed_State;
      break;
    case ABS_UPDISABLED:
      CHECK_EQ(classic_state, DFCS_SCROLLUP | DFCS_INACTIVE);
      ctype = Control::kUpArrow_Type;
      cstate = Control::kDisabled_State;
      break;
    case ABS_DOWNDISABLED:
      CHECK_EQ(classic_state, DFCS_SCROLLDOWN | DFCS_INACTIVE);
      ctype = Control::kDownArrow_Type;
      cstate = Control::kDisabled_State;
      break;
    case ABS_LEFTDISABLED:
      CHECK_EQ(classic_state, DFCS_SCROLLLEFT | DFCS_INACTIVE);
      ctype = Control::kLeftArrow_Type;
      cstate = Control::kDisabled_State;
      break;
    case ABS_RIGHTDISABLED:
      CHECK_EQ(classic_state, DFCS_SCROLLRIGHT | DFCS_INACTIVE);
      ctype = Control::kRightArrow_Type;
      cstate = Control::kDisabled_State;
      break;
    default:
      NOTREACHED();
      break;
  }

  drawControl(canvas, rect, ctype, cstate);
}

void Engine::paintScrollbarThumb(WebCanvas* canvas, int part, int state,
                                 int classic_state, const WebRect& rect) {
  Control::Type ctype = Control::kUnknown_Type;
  Control::State cstate = Control::kUnknown_State;

  switch (part) {
    case SBP_THUMBBTNHORZ:
      ctype = Control::kHorizontalScrollThumb_Type;
      break;
    case SBP_THUMBBTNVERT:
      ctype = Control::kVerticalScrollThumb_Type;
      break;
    case SBP_GRIPPERHORZ:
      ctype = Control::kHorizontalScrollGrip_Type;
      break;
    case SBP_GRIPPERVERT:
      ctype = Control::kVerticalScrollGrip_Type;
      break;
    default:
      NOTREACHED();
      break;
  }

  switch (state) {
    case SCRBS_NORMAL:
      CHECK_EQ(classic_state, kDFCSNormal);
      cstate = Control::kNormal_State;
      break;
    case SCRBS_HOT:
      CHECK_EQ(classic_state, DFCS_HOT);
      cstate = Control::kHot_State;
      break;
    case SCRBS_HOVER:
      CHECK_EQ(classic_state, kDFCSNormal);
      cstate = Control::kHover_State;
      break;
    case SCRBS_PRESSED:
      CHECK_EQ(classic_state, kDFCSNormal);
      cstate = Control::kPressed_State;
      break;
    case SCRBS_DISABLED:
      NOTREACHED();  // This should never happen in practice.
      break;
    default:
      NOTREACHED();
      break;
  }

  drawControl(canvas, rect, ctype, cstate);
}

void Engine::paintScrollbarTrack(WebCanvas* canvas, int part, int state,
                                 int classic_state, const WebRect& rect,
                                 const WebRect& align_rect) {
  Control::Type ctype = Control::kUnknown_Type;
  Control::State cstate = Control::kUnknown_State;

  switch (part) {
    case SBP_UPPERTRACKHORZ:
      ctype = Control::kHorizontalScrollTrackBack_Type;
      break;
    case SBP_LOWERTRACKHORZ:
      ctype = Control::kHorizontalScrollTrackForward_Type;
      break;
    case SBP_UPPERTRACKVERT:
      ctype = Control::kVerticalScrollTrackBack_Type;
      break;
    case SBP_LOWERTRACKVERT:
      ctype = Control::kVerticalScrollTrackForward_Type;
      break;
    default:
      NOTREACHED();
      break;
  }

  switch (state) {
    case SCRBS_NORMAL:
      CHECK_EQ(classic_state, kDFCSNormal);
      cstate = Control::kNormal_State;
      break;
    case SCRBS_HOT:
      NOTREACHED();  // This should never happen in practice.
      break;
    case SCRBS_HOVER:
      CHECK_EQ(classic_state, kDFCSNormal);
      cstate = Control::kHover_State;
      break;
    case SCRBS_PRESSED:
      NOTREACHED();  // This should never happen in practice.
      break;
    case SCRBS_DISABLED:
      CHECK_EQ(classic_state, DFCS_INACTIVE);
      cstate = Control::kDisabled_State;
      break;
    default:
      CHECK(false);
      break;
  }

  drawControl(canvas, rect, ctype, cstate);
}

void Engine::paintTextField(WebCanvas* canvas, int part, int state,
                            int classic_state, const WebRect& rect,
                            WebColor color, bool fill_content_area,
                            bool draw_edges) {
  Control::Type ctype = Control::kUnknown_Type;
  Control::State cstate = Control::kUnknown_State;

  CHECK_EQ(EP_EDITTEXT, part);
  ctype = Control::kTextField_Type;

  switch (state) {
    case ETS_NORMAL:
      CHECK_EQ(classic_state, kDFCSNormal);
      cstate = Control::kNormal_State;
      break;
    case ETS_HOT:
      CHECK_EQ(classic_state, DFCS_HOT);
      cstate = Control::kHot_State;
      break;
    case ETS_DISABLED:
      CHECK_EQ(classic_state, DFCS_INACTIVE);
      cstate = Control::kDisabled_State;
      break;
    case ETS_SELECTED:
      CHECK_EQ(classic_state, DFCS_PUSHED);
      cstate = Control::kPressed_State;
      break;
    case ETS_FOCUSED:
      CHECK_EQ(classic_state, kDFCSNormal);
      cstate = Control::kFocused_State;
      break;
    case ETS_READONLY:
      CHECK_EQ(classic_state, kDFCSNormal);
      cstate = Control::kReadOnly_State;
      break;
    default:
      NOTREACHED();
      break;
  }

  drawTextField(canvas, rect, ctype, cstate, draw_edges, fill_content_area,
                color);
}

void Engine::paintTrackbar(WebCanvas* canvas, int part, int state,
                           int classic_state, const WebRect& rect) {
  Control::Type ctype = Control::kUnknown_Type;
  Control::State cstate = Control::kUnknown_State;

  if (TKP_THUMBBOTTOM == part) {
    ctype = Control::kHorizontalSliderThumb_Type;
    switch (state) {
      case TUS_NORMAL:
        CHECK_EQ(classic_state, kDFCSNormal);
        cstate = Control::kNormal_State;
        break;
      case TUS_HOT:
        CHECK_EQ(classic_state, DFCS_HOT);
        cstate = Control::kHot_State;
        break;
      case TUS_DISABLED:
        CHECK_EQ(classic_state, DFCS_INACTIVE);
        cstate = Control::kDisabled_State;
        break;
      case TUS_PRESSED:
        CHECK_EQ(classic_state, DFCS_PUSHED);
        cstate = Control::kPressed_State;
        break;
      default:
        NOTREACHED();
        break;
      }
  } else if (TKP_TRACK == part) {
    ctype = Control::kHorizontalSliderTrack_Type;
    CHECK_EQ(part, TUS_NORMAL);
    CHECK_EQ(classic_state, kDFCSNormal);
    cstate = Control::kNormal_State;
  } else {
    NOTREACHED();
  }

  drawControl(canvas, rect, ctype, cstate);
}

}  // namespace TestShellWebTheme