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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
|
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "ThemeMac.h"
#import "BlockExceptions.h"
#import "GraphicsContext.h"
#import "LocalCurrentGraphicsContext.h"
#import "ScrollView.h"
#import "WebCoreSystemInterface.h"
#include <wtf/StdLibExtras.h>
using namespace std;
// This is a view whose sole purpose is to tell AppKit that it's flipped.
@interface WebCoreFlippedView : NSView
@end
@implementation WebCoreFlippedView
- (BOOL)isFlipped
{
return YES;
}
- (NSText *)currentEditor
{
return nil;
}
@end
// FIXME: Default buttons really should be more like push buttons and not like buttons.
namespace WebCore {
enum {
topMargin,
rightMargin,
bottomMargin,
leftMargin
};
Theme* platformTheme()
{
DEFINE_STATIC_LOCAL(ThemeMac, themeMac, ());
return &themeMac;
}
// Helper functions used by a bunch of different control parts.
static NSControlSize controlSizeForFont(const Font& font)
{
int fontSize = font.pixelSize();
if (fontSize >= 16)
return NSRegularControlSize;
if (fontSize >= 11)
return NSSmallControlSize;
return NSMiniControlSize;
}
static LengthSize sizeFromNSControlSize(NSControlSize nsControlSize, const LengthSize& zoomedSize, float zoomFactor, const IntSize* sizes)
{
IntSize controlSize = sizes[nsControlSize];
if (zoomFactor != 1.0f)
controlSize = IntSize(controlSize.width() * zoomFactor, controlSize.height() * zoomFactor);
LengthSize result = zoomedSize;
if (zoomedSize.width().isIntrinsicOrAuto() && controlSize.width() > 0)
result.setWidth(Length(controlSize.width(), Fixed));
if (zoomedSize.height().isIntrinsicOrAuto() && controlSize.height() > 0)
result.setHeight(Length(controlSize.height(), Fixed));
return result;
}
static LengthSize sizeFromFont(const Font& font, const LengthSize& zoomedSize, float zoomFactor, const IntSize* sizes)
{
return sizeFromNSControlSize(controlSizeForFont(font), zoomedSize, zoomFactor, sizes);
}
static void setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minZoomedSize, float zoomFactor)
{
NSControlSize size;
if (minZoomedSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomFactor) &&
minZoomedSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height() * zoomFactor))
size = NSRegularControlSize;
else if (minZoomedSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width() * zoomFactor) &&
minZoomedSize.height() >= static_cast<int>(sizes[NSSmallControlSize].height() * zoomFactor))
size = NSSmallControlSize;
else
size = NSMiniControlSize;
if (size != [cell controlSize]) // Only update if we have to, since AppKit does work even if the size is the same.
[cell setControlSize:size];
}
static void updateStates(NSCell* cell, ControlStates states)
{
// Hover state is not supported by Aqua.
// Pressed state
bool oldPressed = [cell isHighlighted];
bool pressed = states & PressedState;
if (pressed != oldPressed)
[cell setHighlighted:pressed];
// Enabled state
bool oldEnabled = [cell isEnabled];
bool enabled = states & EnabledState;
if (enabled != oldEnabled)
[cell setEnabled:enabled];
// Focused state
bool oldFocused = [cell showsFirstResponder];
bool focused = states & FocusState;
if (focused != oldFocused)
[cell setShowsFirstResponder:focused];
// Checked and Indeterminate
bool oldIndeterminate = [cell state] == NSMixedState;
bool indeterminate = (states & IndeterminateState);
bool checked = states & CheckedState;
bool oldChecked = [cell state] == NSOnState;
if (oldIndeterminate != indeterminate || checked != oldChecked)
[cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSOffState)];
// Window inactive state does not need to be checked explicitly, since we paint parented to
// a view in a window whose key state can be detected.
}
static IntRect inflateRect(const IntRect& zoomedRect, const IntSize& zoomedSize, const int* margins, float zoomFactor)
{
// Only do the inflation if the available width/height are too small. Otherwise try to
// fit the glow/check space into the available box's width/height.
int widthDelta = zoomedRect.width() - (zoomedSize.width() + margins[leftMargin] * zoomFactor + margins[rightMargin] * zoomFactor);
int heightDelta = zoomedRect.height() - (zoomedSize.height() + margins[topMargin] * zoomFactor + margins[bottomMargin] * zoomFactor);
IntRect result(zoomedRect);
if (widthDelta < 0) {
result.setX(result.x() - margins[leftMargin] * zoomFactor);
result.setWidth(result.width() - widthDelta);
}
if (heightDelta < 0) {
result.setY(result.y() - margins[topMargin] * zoomFactor);
result.setHeight(result.height() - heightDelta);
}
return result;
}
// Checkboxes
static const IntSize* checkboxSizes()
{
static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(10, 10) };
return sizes;
}
static const int* checkboxMargins(NSControlSize controlSize)
{
static const int margins[3][4] =
{
{ 3, 4, 4, 2 },
{ 4, 3, 3, 3 },
{ 4, 3, 3, 3 },
};
return margins[controlSize];
}
static LengthSize checkboxSize(const Font& font, const LengthSize& zoomedSize, float zoomFactor)
{
// If the width and height are both specified, then we have nothing to do.
if (!zoomedSize.width().isIntrinsicOrAuto() && !zoomedSize.height().isIntrinsicOrAuto())
return zoomedSize;
// Use the font size to determine the intrinsic width of the control.
return sizeFromFont(font, zoomedSize, zoomFactor, checkboxSizes());
}
static NSButtonCell *checkbox(ControlStates states, const IntRect& zoomedRect, float zoomFactor)
{
static NSButtonCell *checkboxCell;
if (!checkboxCell) {
checkboxCell = [[NSButtonCell alloc] init];
[checkboxCell setButtonType:NSSwitchButton];
[checkboxCell setTitle:nil];
[checkboxCell setAllowsMixedState:YES];
[checkboxCell setFocusRingType:NSFocusRingTypeExterior];
}
// Set the control size based off the rectangle we're painting into.
setControlSize(checkboxCell, checkboxSizes(), zoomedRect.size(), zoomFactor);
// Update the various states we respond to.
updateStates(checkboxCell, states);
return checkboxCell;
}
// FIXME: Share more code with radio buttons.
static void paintCheckbox(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS
// Determine the width and height needed for the control and prepare the cell for painting.
NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor);
LocalCurrentGraphicsContext localContext(context);
context->save();
NSControlSize controlSize = [checkboxCell controlSize];
IntSize zoomedSize = checkboxSizes()[controlSize];
zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, checkboxMargins(controlSize), zoomFactor);
if (zoomFactor != 1.0f) {
inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
context->translate(inflatedRect.x(), inflatedRect.y());
context->scale(FloatSize(zoomFactor, zoomFactor));
context->translate(-inflatedRect.x(), -inflatedRect.y());
}
[checkboxCell drawWithFrame:NSRect(inflatedRect) inView:ThemeMac::ensuredView(scrollView)];
[checkboxCell setControlView:nil];
context->restore();
END_BLOCK_OBJC_EXCEPTIONS
}
// Radio Buttons
static const IntSize* radioSizes()
{
static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(10, 10) };
return sizes;
}
static const int* radioMargins(NSControlSize controlSize)
{
static const int margins[3][4] =
{
{ 2, 2, 4, 2 },
{ 3, 2, 3, 2 },
{ 1, 0, 2, 0 },
};
return margins[controlSize];
}
static LengthSize radioSize(const Font& font, const LengthSize& zoomedSize, float zoomFactor)
{
// If the width and height are both specified, then we have nothing to do.
if (!zoomedSize.width().isIntrinsicOrAuto() && !zoomedSize.height().isIntrinsicOrAuto())
return zoomedSize;
// Use the font size to determine the intrinsic width of the control.
return sizeFromFont(font, zoomedSize, zoomFactor, radioSizes());
}
static NSButtonCell *radio(ControlStates states, const IntRect& zoomedRect, float zoomFactor)
{
static NSButtonCell *radioCell;
if (!radioCell) {
radioCell = [[NSButtonCell alloc] init];
[radioCell setButtonType:NSRadioButton];
[radioCell setTitle:nil];
[radioCell setFocusRingType:NSFocusRingTypeExterior];
}
// Set the control size based off the rectangle we're painting into.
setControlSize(radioCell, radioSizes(), zoomedRect.size(), zoomFactor);
// Update the various states we respond to.
updateStates(radioCell, states);
return radioCell;
}
static void paintRadio(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
{
// Determine the width and height needed for the control and prepare the cell for painting.
NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor);
LocalCurrentGraphicsContext localContext(context);
context->save();
NSControlSize controlSize = [radioCell controlSize];
IntSize zoomedSize = radioSizes()[controlSize];
zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(controlSize), zoomFactor);
if (zoomFactor != 1.0f) {
inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
context->translate(inflatedRect.x(), inflatedRect.y());
context->scale(FloatSize(zoomFactor, zoomFactor));
context->translate(-inflatedRect.x(), -inflatedRect.y());
}
BEGIN_BLOCK_OBJC_EXCEPTIONS
[radioCell drawWithFrame:NSRect(inflatedRect) inView:ThemeMac::ensuredView(scrollView)];
[radioCell setControlView:nil];
END_BLOCK_OBJC_EXCEPTIONS
context->restore();
}
// Buttons
// Buttons really only constrain height. They respect width.
static const IntSize* buttonSizes()
{
static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };
return sizes;
}
#if ENABLE(DATALIST)
static const IntSize* listButtonSizes()
{
static const IntSize sizes[3] = { IntSize(21, 21), IntSize(19, 18), IntSize(17, 16) };
return sizes;
}
#endif
static const int* buttonMargins(NSControlSize controlSize)
{
static const int margins[3][4] =
{
{ 4, 6, 7, 6 },
{ 4, 5, 6, 5 },
{ 0, 1, 1, 1 },
};
return margins[controlSize];
}
static void setupButtonCell(NSButtonCell *&buttonCell, ControlPart part, ControlStates states, const IntRect& zoomedRect, float zoomFactor)
{
if (!buttonCell) {
buttonCell = [[NSButtonCell alloc] init];
[buttonCell setTitle:nil];
[buttonCell setButtonType:NSMomentaryPushInButton];
if (states & DefaultState)
[buttonCell setKeyEquivalent:@"\r"];
}
// Set the control size based off the rectangle we're painting into.
const IntSize* sizes = buttonSizes();
#if ENABLE(DATALIST)
if (part == ListButtonPart) {
[buttonCell setBezelStyle:NSRoundedDisclosureBezelStyle];
sizes = listButtonSizes();
} else
#endif
if (part == SquareButtonPart || zoomedRect.height() > buttonSizes()[NSRegularControlSize].height() * zoomFactor) {
// Use the square button
if ([buttonCell bezelStyle] != NSShadowlessSquareBezelStyle)
[buttonCell setBezelStyle:NSShadowlessSquareBezelStyle];
} else if ([buttonCell bezelStyle] != NSRoundedBezelStyle)
[buttonCell setBezelStyle:NSRoundedBezelStyle];
setControlSize(buttonCell, sizes, zoomedRect.size(), zoomFactor);
// Update the various states we respond to.
updateStates(buttonCell, states);
}
static NSButtonCell *button(ControlPart part, ControlStates states, const IntRect& zoomedRect, float zoomFactor)
{
bool isDefault = states & DefaultState;
static NSButtonCell *cells[2];
setupButtonCell(cells[isDefault], part, states, zoomedRect, zoomFactor);
return cells[isDefault];
}
static void paintButton(ControlPart part, ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS
// Determine the width and height needed for the control and prepare the cell for painting.
NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor);
LocalCurrentGraphicsContext localContext(context);
NSControlSize controlSize = [buttonCell controlSize];
#if ENABLE(DATALIST)
IntSize zoomedSize = (part == ListButtonPart ? listButtonSizes() : buttonSizes())[controlSize];
#else
IntSize zoomedSize = buttonSizes()[controlSize];
#endif
zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain width, so the zoomed width can just be honored.
zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
IntRect inflatedRect = zoomedRect;
if ([buttonCell bezelStyle] == NSRoundedBezelStyle) {
// Center the button within the available space.
if (inflatedRect.height() > zoomedSize.height()) {
inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomedSize.height()) / 2);
inflatedRect.setHeight(zoomedSize.height());
}
// Now inflate it to account for the shadow.
inflatedRect = inflateRect(inflatedRect, zoomedSize, buttonMargins(controlSize), zoomFactor);
if (zoomFactor != 1.0f) {
inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
context->translate(inflatedRect.x(), inflatedRect.y());
context->scale(FloatSize(zoomFactor, zoomFactor));
context->translate(-inflatedRect.x(), -inflatedRect.y());
}
}
NSView *view = ThemeMac::ensuredView(scrollView);
NSWindow *window = [view window];
NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell];
if (states & DefaultState) {
[window setDefaultButtonCell:buttonCell];
wkAdvanceDefaultButtonPulseAnimation(buttonCell);
} else if ([previousDefaultButtonCell isEqual:buttonCell])
[window setDefaultButtonCell:nil];
[buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
[buttonCell setControlView:nil];
if (![previousDefaultButtonCell isEqual:buttonCell])
[window setDefaultButtonCell:previousDefaultButtonCell];
END_BLOCK_OBJC_EXCEPTIONS
}
// Stepper
static const IntSize* stepperSizes()
{
static const IntSize sizes[3] = { IntSize(19, 27), IntSize(15, 22), IntSize(13, 15) };
return sizes;
}
// We don't use controlSizeForFont() for steppers because the stepper height
// should be equal to or less than the corresponding text field height,
static NSControlSize stepperControlSizeForFont(const Font& font)
{
int fontSize = font.pixelSize();
if (fontSize >= 18)
return NSRegularControlSize;
if (fontSize >= 13)
return NSSmallControlSize;
return NSMiniControlSize;
}
static NSStepperCell* stepper(ControlStates states, const IntRect& zoomedRect, float zoomFactor)
{
static NSStepperCell* cell = [[NSStepperCell alloc] init];
setControlSize(cell, stepperSizes(), zoomedRect.size(), zoomFactor);
updateStates(cell, states);
if (states & PressedState && states & SpinUpState) {
// FIXME: There is no way to draw a NSSteperCell with the up button hilighted.
// Disables the hilight of the down button if the up button is pressed.
[cell setHighlighted:NO];
}
return cell;
}
static void paintStepper(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
{
NSStepperCell* cell = stepper(states, zoomedRect, zoomFactor);
context->save();
NSControlSize controlSize = [cell controlSize];
IntSize zoomedSize = stepperSizes()[controlSize];
IntRect rect(zoomedRect);
if (zoomFactor != 1.0f) {
rect.setWidth(rect.width() / zoomFactor);
rect.setHeight(rect.height() / zoomFactor);
context->translate(rect.x(), rect.y());
context->scale(FloatSize(zoomFactor, zoomFactor));
context->translate(-rect.x(), -rect.y());
}
BEGIN_BLOCK_OBJC_EXCEPTIONS
[cell drawWithFrame:NSRect(rect) inView:ThemeMac::ensuredView(scrollView)];
[cell setControlView:nil];
END_BLOCK_OBJC_EXCEPTIONS
context->restore();
}
// This will ensure that we always return a valid NSView, even if ScrollView doesn't have an associated document NSView.
// If the ScrollView doesn't have an NSView, we will return a fake NSView whose sole purpose is to tell AppKit that it's flipped.
NSView *ThemeMac::ensuredView(ScrollView* scrollView)
{
if (NSView *documentView = scrollView->documentView())
return documentView;
// Use a fake flipped view.
static NSView *flippedView = [[WebCoreFlippedView alloc] init];
return flippedView;
}
// Theme overrides
int ThemeMac::baselinePositionAdjustment(ControlPart part) const
{
if (part == CheckboxPart || part == RadioPart)
return -2;
return Theme::baselinePositionAdjustment(part);
}
FontDescription ThemeMac::controlFont(ControlPart part, const Font& font, float zoomFactor) const
{
switch (part) {
case PushButtonPart: {
FontDescription fontDescription;
fontDescription.setIsAbsoluteSize(true);
fontDescription.setGenericFamily(FontDescription::SerifFamily);
NSFont* nsFont = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSizeForFont(font)]];
fontDescription.firstFamily().setFamily([nsFont familyName]);
fontDescription.setComputedSize([nsFont pointSize] * zoomFactor);
fontDescription.setSpecifiedSize([nsFont pointSize] * zoomFactor);
return fontDescription;
}
default:
return Theme::controlFont(part, font, zoomFactor);
}
}
LengthSize ThemeMac::controlSize(ControlPart part, const Font& font, const LengthSize& zoomedSize, float zoomFactor) const
{
switch (part) {
case CheckboxPart:
return checkboxSize(font, zoomedSize, zoomFactor);
case RadioPart:
return radioSize(font, zoomedSize, zoomFactor);
case PushButtonPart:
// Height is reset to auto so that specified heights can be ignored.
return sizeFromFont(font, LengthSize(zoomedSize.width(), Length()), zoomFactor, buttonSizes());
#if ENABLE(DATALIST)
case ListButtonPart:
return sizeFromFont(font, LengthSize(zoomedSize.width(), Length()), zoomFactor, listButtonSizes());
#endif
case InnerSpinButtonPart:
// We don't use inner spin buttons on Mac.
return LengthSize(Length(Fixed), Length(Fixed));
case OuterSpinButtonPart:
if (!zoomedSize.width().isIntrinsicOrAuto() && !zoomedSize.height().isIntrinsicOrAuto())
return zoomedSize;
return sizeFromNSControlSize(stepperControlSizeForFont(font), zoomedSize, zoomFactor, stepperSizes());
default:
return zoomedSize;
}
}
LengthSize ThemeMac::minimumControlSize(ControlPart part, const Font& font, float zoomFactor) const
{
switch (part) {
case SquareButtonPart:
case DefaultButtonPart:
case ButtonPart:
case ListButtonPart:
return LengthSize(Length(0, Fixed), Length(static_cast<int>(15 * zoomFactor), Fixed));
case InnerSpinButtonPart:
// We don't use inner spin buttons on Mac.
return LengthSize(Length(Fixed), Length(Fixed));
case OuterSpinButtonPart: {
IntSize base = stepperSizes()[NSMiniControlSize];
return LengthSize(Length(static_cast<int>(base.width() * zoomFactor), Fixed),
Length(static_cast<int>(base.height() * zoomFactor), Fixed));
}
default:
return Theme::minimumControlSize(part, font, zoomFactor);
}
}
LengthBox ThemeMac::controlBorder(ControlPart part, const Font& font, const LengthBox& zoomedBox, float zoomFactor) const
{
switch (part) {
case SquareButtonPart:
case DefaultButtonPart:
case ButtonPart:
case ListButtonPart:
return LengthBox(0, zoomedBox.right().value(), 0, zoomedBox.left().value());
default:
return Theme::controlBorder(part, font, zoomedBox, zoomFactor);
}
}
LengthBox ThemeMac::controlPadding(ControlPart part, const Font& font, const LengthBox& zoomedBox, float zoomFactor) const
{
switch (part) {
case PushButtonPart: {
// Just use 8px. AppKit wants to use 11px for mini buttons, but that padding is just too large
// for real-world Web sites (creating a huge necessary minimum width for buttons whose space is
// by definition constrained, since we select mini only for small cramped environments.
// This also guarantees the HTML <button> will match our rendering by default, since we're using a consistent
// padding.
const int padding = 8 * zoomFactor;
return LengthBox(0, padding, 0, padding);
}
default:
return Theme::controlPadding(part, font, zoomedBox, zoomFactor);
}
}
void ThemeMac::inflateControlPaintRect(ControlPart part, ControlStates states, IntRect& zoomedRect, float zoomFactor) const
{
BEGIN_BLOCK_OBJC_EXCEPTIONS
switch (part) {
case CheckboxPart: {
// We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox
// shadow" and the check. We don't consider this part of the bounds of the control in WebKit.
NSCell *cell = checkbox(states, zoomedRect, zoomFactor);
NSControlSize controlSize = [cell controlSize];
IntSize zoomedSize = checkboxSizes()[controlSize];
zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
zoomedRect = inflateRect(zoomedRect, zoomedSize, checkboxMargins(controlSize), zoomFactor);
break;
}
case RadioPart: {
// We inflate the rect as needed to account for padding included in the cell to accommodate the radio button
// shadow". We don't consider this part of the bounds of the control in WebKit.
NSCell *cell = radio(states, zoomedRect, zoomFactor);
NSControlSize controlSize = [cell controlSize];
IntSize zoomedSize = radioSizes()[controlSize];
zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
zoomedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(controlSize), zoomFactor);
break;
}
case PushButtonPart:
case DefaultButtonPart:
case ButtonPart: {
NSButtonCell *cell = button(part, states, zoomedRect, zoomFactor);
NSControlSize controlSize = [cell controlSize];
// We inflate the rect as needed to account for the Aqua button's shadow.
if ([cell bezelStyle] == NSRoundedBezelStyle) {
IntSize zoomedSize = buttonSizes()[controlSize];
zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain width, so the zoomed width can just be honored.
zoomedRect = inflateRect(zoomedRect, zoomedSize, buttonMargins(controlSize), zoomFactor);
}
break;
}
case OuterSpinButtonPart: {
static const int stepperMargin[4] = { 0, 0, 0, 0};
NSCell *cell = stepper(states, zoomedRect, zoomFactor);
NSControlSize controlSize = [cell controlSize];
IntSize zoomedSize = stepperSizes()[controlSize];
zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
zoomedRect = inflateRect(zoomedRect, zoomedSize, stepperMargin, zoomFactor);
break;
}
default:
break;
}
END_BLOCK_OBJC_EXCEPTIONS
}
void ThemeMac::paint(ControlPart part, ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) const
{
switch (part) {
case CheckboxPart:
paintCheckbox(states, context, zoomedRect, zoomFactor, scrollView);
break;
case RadioPart:
paintRadio(states, context, zoomedRect, zoomFactor, scrollView);
break;
case PushButtonPart:
case DefaultButtonPart:
case ButtonPart:
case SquareButtonPart:
case ListButtonPart:
paintButton(part, states, context, zoomedRect, zoomFactor, scrollView);
break;
case OuterSpinButtonPart:
paintStepper(states, context, zoomedRect, zoomFactor, scrollView);
break;
default:
break;
}
}
}
|