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 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
|
/*
* Copyright (C) 2007, 2008 Apple Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include "RenderThemeSafari.h"
#if USE(SAFARI_THEME)
#include "CSSValueKeywords.h"
#include "Document.h"
#include "Element.h"
#include "Frame.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HTMLInputElement.h"
#include "HTMLMediaElement.h"
#include "HTMLNames.h"
#include "RenderSlider.h"
#include "RenderView.h"
#include "RetainPtr.h"
#include "SoftLinking.h"
#include "cssstyleselector.h"
#include <CoreGraphics/CoreGraphics.h>
using std::min;
// FIXME: The platform-independent code in this class should be factored out and merged with RenderThemeMac.
namespace WebCore {
using namespace HTMLNames;
using namespace SafariTheme;
enum {
topMargin,
rightMargin,
bottomMargin,
leftMargin
};
enum {
topPadding,
rightPadding,
bottomPadding,
leftPadding
};
RenderTheme* theme()
{
static RenderThemeSafari safariTheme;
return &safariTheme;
}
#if !defined(NDEBUG) && defined(USE_DEBUG_SAFARI_THEME)
SOFT_LINK_DEBUG_LIBRARY(SafariTheme)
#else
SOFT_LINK_LIBRARY(SafariTheme)
#endif
SOFT_LINK(SafariTheme, paintThemePart, void, __stdcall, (ThemePart part, CGContextRef context, const CGRect& rect, NSControlSize size, ThemeControlState state), (part, context, rect, size, state))
#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 2
SOFT_LINK(SafariTheme, STPaintProgressIndicator, void, APIENTRY, (ProgressIndicatorType type, CGContextRef context, const CGRect& rect, NSControlSize size, ThemeControlState state, float value), (type, context, rect, size, state, value))
#endif
ThemeControlState RenderThemeSafari::determineState(RenderObject* o) const
{
ThemeControlState result = 0;
if (isActive(o))
result |= SafariTheme::ActiveState;
if (isEnabled(o) && !isReadOnlyControl(o))
result |= SafariTheme::EnabledState;
if (isPressed(o))
result |= SafariTheme::PressedState;
if (isChecked(o))
result |= SafariTheme::CheckedState;
if (isIndeterminate(o))
result |= SafariTheme::IndeterminateCheckedState;
if (isFocused(o))
result |= SafariTheme::FocusedState;
if (isDefault(o))
result |= SafariTheme::DefaultState;
return result;
}
static NSControlSize controlSizeFromRect(const IntRect& rect, const IntSize sizes[])
{
if (sizes[NSRegularControlSize].height() == rect.height())
return NSRegularControlSize;
else if (sizes[NSMiniControlSize].height() == rect.height())
return NSMiniControlSize;
return NSSmallControlSize;
}
RenderThemeSafari::RenderThemeSafari()
{
}
RenderThemeSafari::~RenderThemeSafari()
{
}
Color RenderThemeSafari::platformActiveSelectionBackgroundColor() const
{
return Color(181, 213, 255);
}
Color RenderThemeSafari::platformInactiveSelectionBackgroundColor() const
{
return Color(212, 212, 212);
}
Color RenderThemeSafari::activeListBoxSelectionBackgroundColor() const
{
// FIXME: This should probably just be a darker version of the platformActiveSelectionBackgroundColor
return Color(56, 117, 215);
}
static float systemFontSizeForControlSize(NSControlSize controlSize)
{
static float sizes[] = { 13.0f, 11.0f, 9.0f };
return sizes[controlSize];
}
void RenderThemeSafari::systemFont(int propId, FontDescription& fontDescription) const
{
static FontDescription systemFont;
static FontDescription smallSystemFont;
static FontDescription menuFont;
static FontDescription labelFont;
static FontDescription miniControlFont;
static FontDescription smallControlFont;
static FontDescription controlFont;
FontDescription* cachedDesc;
float fontSize = 0;
switch (propId) {
case CSSValueSmallCaption:
cachedDesc = &smallSystemFont;
if (!smallSystemFont.isAbsoluteSize())
fontSize = systemFontSizeForControlSize(NSSmallControlSize);
break;
case CSSValueMenu:
cachedDesc = &menuFont;
if (!menuFont.isAbsoluteSize())
fontSize = systemFontSizeForControlSize(NSRegularControlSize);
break;
case CSSValueStatusBar:
cachedDesc = &labelFont;
if (!labelFont.isAbsoluteSize())
fontSize = 10.0f;
break;
case CSSValueWebkitMiniControl:
cachedDesc = &miniControlFont;
if (!miniControlFont.isAbsoluteSize())
fontSize = systemFontSizeForControlSize(NSMiniControlSize);
break;
case CSSValueWebkitSmallControl:
cachedDesc = &smallControlFont;
if (!smallControlFont.isAbsoluteSize())
fontSize = systemFontSizeForControlSize(NSSmallControlSize);
break;
case CSSValueWebkitControl:
cachedDesc = &controlFont;
if (!controlFont.isAbsoluteSize())
fontSize = systemFontSizeForControlSize(NSRegularControlSize);
break;
default:
cachedDesc = &systemFont;
if (!systemFont.isAbsoluteSize())
fontSize = 13.0f;
}
if (fontSize) {
cachedDesc->setIsAbsoluteSize(true);
cachedDesc->setGenericFamily(FontDescription::NoFamily);
cachedDesc->firstFamily().setFamily("Lucida Grande");
cachedDesc->setSpecifiedSize(fontSize);
cachedDesc->setWeight(FontWeightNormal);
cachedDesc->setItalic(false);
}
fontDescription = *cachedDesc;
}
bool RenderThemeSafari::isControlStyled(const RenderStyle* style, const BorderData& border,
const FillLayer& background, const Color& backgroundColor) const
{
// If we didn't find SafariTheme.dll we won't be able to paint any themed controls.
if (!SafariThemeLibrary())
return true;
if (style->appearance() == TextFieldAppearance || style->appearance() == TextAreaAppearance || style->appearance() == ListboxAppearance)
return style->border() != border;
return RenderTheme::isControlStyled(style, border, background, backgroundColor);
}
void RenderThemeSafari::adjustRepaintRect(const RenderObject* o, IntRect& r)
{
NSControlSize controlSize = controlSizeForFont(o->style());
switch (o->style()->appearance()) {
case CheckboxAppearance: {
// 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.
r = inflateRect(r, checkboxSizes()[controlSize], checkboxMargins(controlSize));
break;
}
case RadioAppearance: {
// 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.
r = inflateRect(r, radioSizes()[controlSize], radioMargins(controlSize));
break;
}
case PushButtonAppearance:
case DefaultButtonAppearance:
case ButtonAppearance: {
// 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.
if (r.height() <= buttonSizes()[NSRegularControlSize].height())
r = inflateRect(r, buttonSizes()[controlSize], buttonMargins(controlSize));
break;
}
case MenulistAppearance: {
r = inflateRect(r, popupButtonSizes()[controlSize], popupButtonMargins(controlSize));
break;
}
default:
break;
}
}
IntRect RenderThemeSafari::inflateRect(const IntRect& r, const IntSize& size, const int* margins) const
{
// 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 = r.width() - (size.width() + margins[leftMargin] + margins[rightMargin]);
int heightDelta = r.height() - (size.height() + margins[topMargin] + margins[bottomMargin]);
IntRect result(r);
if (widthDelta < 0) {
result.setX(result.x() - margins[leftMargin]);
result.setWidth(result.width() - widthDelta);
}
if (heightDelta < 0) {
result.setY(result.y() - margins[topMargin]);
result.setHeight(result.height() - heightDelta);
}
return result;
}
short RenderThemeSafari::baselinePosition(const RenderObject* o) const
{
if (o->style()->appearance() == CheckboxAppearance || o->style()->appearance() == RadioAppearance)
return o->marginTop() + o->height() - 2; // The baseline is 2px up from the bottom of the checkbox/radio in AppKit.
return RenderTheme::baselinePosition(o);
}
bool RenderThemeSafari::controlSupportsTints(const RenderObject* o) const
{
if (!isEnabled(o))
return false;
// Checkboxes only have tint when checked.
if (o->style()->appearance() == CheckboxAppearance)
return isChecked(o);
// For now assume other controls have tint if enabled.
return true;
}
NSControlSize RenderThemeSafari::controlSizeForFont(RenderStyle* style) const
{
int fontSize = style->fontSize();
if (fontSize >= 16)
return NSRegularControlSize;
if (fontSize >= 11)
return NSSmallControlSize;
return NSMiniControlSize;
}
/*
void RenderThemeSafari::setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minSize)
{
NSControlSize size;
if (minSize.width() >= sizes[NSRegularControlSize].width() &&
minSize.height() >= sizes[NSRegularControlSize].height())
size = NSRegularControlSize;
else if (minSize.width() >= sizes[NSSmallControlSize].width() &&
minSize.height() >= sizes[NSSmallControlSize].height())
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];
}
*/
IntSize RenderThemeSafari::sizeForFont(RenderStyle* style, const IntSize* sizes) const
{
return sizes[controlSizeForFont(style)];
}
IntSize RenderThemeSafari::sizeForSystemFont(RenderStyle* style, const IntSize* sizes) const
{
return sizes[controlSizeForSystemFont(style)];
}
void RenderThemeSafari::setSizeFromFont(RenderStyle* style, const IntSize* sizes) const
{
// FIXME: Check is flawed, since it doesn't take min-width/max-width into account.
IntSize size = sizeForFont(style, sizes);
if (style->width().isIntrinsicOrAuto() && size.width() > 0)
style->setWidth(Length(size.width(), Fixed));
if (style->height().isAuto() && size.height() > 0)
style->setHeight(Length(size.height(), Fixed));
}
void RenderThemeSafari::setFontFromControlSize(CSSStyleSelector* selector, RenderStyle* style, NSControlSize controlSize) const
{
FontDescription fontDescription;
fontDescription.setIsAbsoluteSize(true);
fontDescription.setGenericFamily(FontDescription::SerifFamily);
float fontSize = systemFontSizeForControlSize(controlSize);
fontDescription.firstFamily().setFamily("Lucida Grande");
fontDescription.setComputedSize(fontSize);
fontDescription.setSpecifiedSize(fontSize);
// Reset line height
style->setLineHeight(RenderStyle::initialLineHeight());
if (style->setFontDescription(fontDescription))
style->font().update(selector->fontSelector());
}
NSControlSize RenderThemeSafari::controlSizeForSystemFont(RenderStyle* style) const
{
int fontSize = style->fontSize();
if (fontSize >= 13)
return NSRegularControlSize;
if (fontSize >= 11)
return NSSmallControlSize;
return NSMiniControlSize;
}
bool RenderThemeSafari::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
NSControlSize controlSize = controlSizeForFont(o->style());
IntRect inflatedRect = inflateRect(r, checkboxSizes()[controlSize], checkboxMargins(controlSize));
paintThemePart(CheckboxPart, paintInfo.context->platformContext(), inflatedRect, controlSize, determineState(o));
return false;
}
const IntSize* RenderThemeSafari::checkboxSizes() const
{
static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(10, 10) };
return sizes;
}
const int* RenderThemeSafari::checkboxMargins(NSControlSize controlSize) const
{
static const int margins[3][4] =
{
{ 2, 2, 2, 2 },
{ 2, 2, 2, 1 },
{ 1, 0, 0, 0 },
};
return margins[controlSize];
}
void RenderThemeSafari::setCheckboxSize(RenderStyle* style) const
{
// If the width and height are both specified, then we have nothing to do.
if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
return;
// Use the font size to determine the intrinsic width of the control.
setSizeFromFont(style, checkboxSizes());
}
bool RenderThemeSafari::paintRadio(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
NSControlSize controlSize = controlSizeForFont(o->style());
IntRect inflatedRect = inflateRect(r, radioSizes()[controlSize], radioMargins(controlSize));
paintThemePart(RadioButtonPart, paintInfo.context->platformContext(), inflatedRect, controlSize, determineState(o));
return false;
}
const IntSize* RenderThemeSafari::radioSizes() const
{
static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(10, 10) };
return sizes;
}
const int* RenderThemeSafari::radioMargins(NSControlSize controlSize) const
{
static const int margins[3][4] =
{
{ 1, 2, 2, 2 },
{ 0, 1, 2, 1 },
{ 0, 0, 1, 0 },
};
return margins[controlSize];
}
void RenderThemeSafari::setRadioSize(RenderStyle* style) const
{
// If the width and height are both specified, then we have nothing to do.
if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
return;
// Use the font size to determine the intrinsic width of the control.
setSizeFromFont(style, radioSizes());
}
void RenderThemeSafari::setButtonPaddingFromControlSize(RenderStyle* style, NSControlSize size) const
{
// 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 HTML4 <button> will match our rendering by default, since we're using a consistent
// padding.
const int padding = 8;
style->setPaddingLeft(Length(padding, Fixed));
style->setPaddingRight(Length(padding, Fixed));
style->setPaddingTop(Length(0, Fixed));
style->setPaddingBottom(Length(0, Fixed));
}
void RenderThemeSafari::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
// There are three appearance constants for buttons.
// (1) Push-button is the constant for the default Aqua system button. Push buttons will not scale vertically and will not allow
// custom fonts or colors. <input>s use this constant. This button will allow custom colors and font weights/variants but won't
// scale vertically.
// (2) square-button is the constant for the square button. This button will allow custom fonts and colors and will scale vertically.
// (3) Button is the constant that means "pick the best button as appropriate." <button>s use this constant. This button will
// also scale vertically and allow custom fonts and colors. It will attempt to use Aqua if possible and will make this determination
// solely on the rectangle of the control.
// Determine our control size based off our font.
NSControlSize controlSize = controlSizeForFont(style);
if (style->appearance() == PushButtonAppearance) {
// Ditch the border.
style->resetBorder();
// Height is locked to auto.
style->setHeight(Length(Auto));
// White-space is locked to pre
style->setWhiteSpace(PRE);
// Set the button's vertical size.
setButtonSize(style);
// Add in the padding that we'd like to use.
setButtonPaddingFromControlSize(style, controlSize);
// Our font is locked to the appropriate system font size for the control. To clarify, we first use the CSS-specified font to figure out
// a reasonable control size, but once that control size is determined, we throw that font away and use the appropriate
// system font for the control size instead.
setFontFromControlSize(selector, style, controlSize);
} else {
// Set a min-height so that we can't get smaller than the mini button.
style->setMinHeight(Length(15, Fixed));
// Reset the top and bottom borders.
style->resetBorderTop();
style->resetBorderBottom();
}
}
const IntSize* RenderThemeSafari::buttonSizes() const
{
static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };
return sizes;
}
const int* RenderThemeSafari::buttonMargins(NSControlSize controlSize) const
{
static const int margins[3][4] =
{
{ 4, 6, 7, 6 },
{ 4, 5, 6, 5 },
{ 0, 1, 1, 1 },
};
return margins[controlSize];
}
void RenderThemeSafari::setButtonSize(RenderStyle* style) const
{
// If the width and height are both specified, then we have nothing to do.
if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
return;
// Use the font size to determine the intrinsic width of the control.
setSizeFromFont(style, buttonSizes());
}
bool RenderThemeSafari::paintButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
// We inflate the rect as needed to account for padding included in the cell to accommodate the button
// shadow. We don't consider this part of the bounds of the control in WebKit.
NSControlSize controlSize = controlSizeFromRect(r, buttonSizes());
IntRect inflatedRect = r;
ThemePart part;
if (r.height() <= buttonSizes()[NSRegularControlSize].height()) {
// Push button
part = PushButtonPart;
IntSize size = buttonSizes()[controlSize];
size.setWidth(r.width());
// Center the button within the available space.
if (inflatedRect.height() > size.height()) {
inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - size.height()) / 2);
inflatedRect.setHeight(size.height());
}
// Now inflate it to account for the shadow.
inflatedRect = inflateRect(inflatedRect, size, buttonMargins(controlSize));
} else
part = SquareButtonPart;
paintThemePart(part, paintInfo.context->platformContext(), inflatedRect, controlSize, determineState(o));
return false;
}
bool RenderThemeSafari::paintTextField(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
paintThemePart(TextFieldPart, paintInfo.context->platformContext(), r, (NSControlSize)0, determineState(o) & ~FocusedState);
return false;
}
void RenderThemeSafari::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const
{
}
bool RenderThemeSafari::paintCapsLockIndicator(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 1
ASSERT(SafariThemeLibrary());
if (paintInfo.context->paintingDisabled())
return true;
paintThemePart(CapsLockPart, paintInfo.context->platformContext(), r, (NSControlSize)0, (ThemeControlState)0);
return false;
#else
return true;
#endif
}
bool RenderThemeSafari::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
paintThemePart(TextAreaPart, paintInfo.context->platformContext(), r, (NSControlSize)0, determineState(o) & ~FocusedState);
return false;
}
void RenderThemeSafari::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const
{
}
const int* RenderThemeSafari::popupButtonMargins(NSControlSize size) const
{
static const int margins[3][4] =
{
{ 2, 3, 3, 3 },
{ 1, 3, 3, 3 },
{ 0, 1, 0, 1 }
};
return margins[size];
}
const IntSize* RenderThemeSafari::popupButtonSizes() const
{
static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };
return sizes;
}
const int* RenderThemeSafari::popupButtonPadding(NSControlSize size) const
{
static const int padding[3][4] =
{
{ 2, 26, 3, 8 },
{ 2, 23, 3, 8 },
{ 2, 22, 3, 10 }
};
return padding[size];
}
bool RenderThemeSafari::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& info, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
NSControlSize controlSize = controlSizeFromRect(r, popupButtonSizes());
IntRect inflatedRect = r;
IntSize size = popupButtonSizes()[controlSize];
size.setWidth(r.width());
// Now inflate it to account for the shadow.
if (r.width() >= minimumMenuListSize(o->style()))
inflatedRect = inflateRect(inflatedRect, size, popupButtonMargins(controlSize));
paintThemePart(DropDownButtonPart, info.context->platformContext(), inflatedRect, controlSize, determineState(o));
return false;
}
const float baseFontSize = 11.0f;
const float baseArrowHeight = 5.0f;
const float baseArrowWidth = 7.0f;
const int arrowPaddingLeft = 5;
const int arrowPaddingRight = 5;
const int paddingBeforeSeparator = 4;
const int baseBorderRadius = 5;
const int styledPopupPaddingLeft = 8;
const int styledPopupPaddingTop = 1;
const int styledPopupPaddingBottom = 2;
static void TopGradientInterpolate(void* info, const CGFloat* inData, CGFloat* outData)
{
static float dark[4] = { 1.0f, 1.0f, 1.0f, 0.4f };
static float light[4] = { 1.0f, 1.0f, 1.0f, 0.15f };
float a = inData[0];
int i = 0;
for (i = 0; i < 4; i++)
outData[i] = (1.0f - a) * dark[i] + a * light[i];
}
static void BottomGradientInterpolate(void* info, const CGFloat* inData, CGFloat* outData)
{
static float dark[4] = { 1.0f, 1.0f, 1.0f, 0.0f };
static float light[4] = { 1.0f, 1.0f, 1.0f, 0.3f };
float a = inData[0];
int i = 0;
for (i = 0; i < 4; i++)
outData[i] = (1.0f - a) * dark[i] + a * light[i];
}
static void MainGradientInterpolate(void* info, const CGFloat* inData, CGFloat* outData)
{
static float dark[4] = { 0.0f, 0.0f, 0.0f, 0.15f };
static float light[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
float a = inData[0];
int i = 0;
for (i = 0; i < 4; i++)
outData[i] = (1.0f - a) * dark[i] + a * light[i];
}
static void TrackGradientInterpolate(void* info, const CGFloat* inData, CGFloat* outData)
{
static float dark[4] = { 0.0f, 0.0f, 0.0f, 0.678f };
static float light[4] = { 0.0f, 0.0f, 0.0f, 0.13f };
float a = inData[0];
int i = 0;
for (i = 0; i < 4; i++)
outData[i] = (1.0f - a) * dark[i] + a * light[i];
}
void RenderThemeSafari::paintMenuListButtonGradients(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
CGContextRef context = paintInfo.context->platformContext();
paintInfo.context->save();
int radius = o->style()->borderTopLeftRadius().width();
RetainPtr<CGColorSpaceRef> cspace(AdoptCF, CGColorSpaceCreateDeviceRGB());
FloatRect topGradient(r.x(), r.y(), r.width(), r.height() / 2.0f);
struct CGFunctionCallbacks topCallbacks = { 0, TopGradientInterpolate, NULL };
RetainPtr<CGFunctionRef> topFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &topCallbacks));
RetainPtr<CGShadingRef> topShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(topGradient.x(), topGradient.y()), CGPointMake(topGradient.x(), topGradient.bottom()), topFunction.get(), false, false));
FloatRect bottomGradient(r.x() + radius, r.y() + r.height() / 2.0f, r.width() - 2.0f * radius, r.height() / 2.0f);
struct CGFunctionCallbacks bottomCallbacks = { 0, BottomGradientInterpolate, NULL };
RetainPtr<CGFunctionRef> bottomFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &bottomCallbacks));
RetainPtr<CGShadingRef> bottomShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(bottomGradient.x(), bottomGradient.y()), CGPointMake(bottomGradient.x(), bottomGradient.bottom()), bottomFunction.get(), false, false));
struct CGFunctionCallbacks mainCallbacks = { 0, MainGradientInterpolate, NULL };
RetainPtr<CGFunctionRef> mainFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &mainCallbacks));
RetainPtr<CGShadingRef> mainShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(r.x(), r.y()), CGPointMake(r.x(), r.bottom()), mainFunction.get(), false, false));
RetainPtr<CGShadingRef> leftShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(r.x(), r.y()), CGPointMake(r.x() + radius, r.y()), mainFunction.get(), false, false));
RetainPtr<CGShadingRef> rightShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(r.right(), r.y()), CGPointMake(r.right() - radius, r.y()), mainFunction.get(), false, false));
paintInfo.context->save();
CGContextClipToRect(context, r);
paintInfo.context->addRoundedRectClip(r,
o->style()->borderTopLeftRadius(), o->style()->borderTopRightRadius(),
o->style()->borderBottomLeftRadius(), o->style()->borderBottomRightRadius());
CGContextDrawShading(context, mainShading.get());
paintInfo.context->restore();
paintInfo.context->save();
CGContextClipToRect(context, topGradient);
paintInfo.context->addRoundedRectClip(enclosingIntRect(topGradient),
o->style()->borderTopLeftRadius(), o->style()->borderTopRightRadius(),
IntSize(), IntSize());
CGContextDrawShading(context, topShading.get());
paintInfo.context->restore();
paintInfo.context->save();
CGContextClipToRect(context, bottomGradient);
paintInfo.context->addRoundedRectClip(enclosingIntRect(bottomGradient),
IntSize(), IntSize(),
o->style()->borderBottomLeftRadius(), o->style()->borderBottomRightRadius());
CGContextDrawShading(context, bottomShading.get());
paintInfo.context->restore();
paintInfo.context->save();
CGContextClipToRect(context, r);
paintInfo.context->addRoundedRectClip(r,
o->style()->borderTopLeftRadius(), o->style()->borderTopRightRadius(),
o->style()->borderBottomLeftRadius(), o->style()->borderBottomRightRadius());
CGContextDrawShading(context, leftShading.get());
CGContextDrawShading(context, rightShading.get());
paintInfo.context->restore();
paintInfo.context->restore();
}
bool RenderThemeSafari::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
paintInfo.context->save();
IntRect bounds = IntRect(r.x() + o->style()->borderLeftWidth(),
r.y() + o->style()->borderTopWidth(),
r.width() - o->style()->borderLeftWidth() - o->style()->borderRightWidth(),
r.height() - o->style()->borderTopWidth() - o->style()->borderBottomWidth());
// Draw the gradients to give the styled popup menu a button appearance
paintMenuListButtonGradients(o, paintInfo, bounds);
// Since we actually know the size of the control here, we restrict the font scale to make sure the arrow will fit vertically in the bounds
float fontScale = min(o->style()->fontSize() / baseFontSize, bounds.height() / baseArrowHeight);
float centerY = bounds.y() + bounds.height() / 2.0f;
float arrowHeight = baseArrowHeight * fontScale;
float arrowWidth = baseArrowWidth * fontScale;
float leftEdge = bounds.right() - arrowPaddingRight - arrowWidth;
if (bounds.width() < arrowWidth + arrowPaddingLeft)
return false;
paintInfo.context->setFillColor(o->style()->color());
paintInfo.context->setStrokeColor(NoStroke);
FloatPoint arrow[3];
arrow[0] = FloatPoint(leftEdge, centerY - arrowHeight / 2.0f);
arrow[1] = FloatPoint(leftEdge + arrowWidth, centerY - arrowHeight / 2.0f);
arrow[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY + arrowHeight / 2.0f);
// Draw the arrow
paintInfo.context->drawConvexPolygon(3, arrow, true);
Color leftSeparatorColor(0, 0, 0, 40);
Color rightSeparatorColor(255, 255, 255, 40);
// FIXME: Should the separator thickness and space be scaled up by fontScale?
int separatorSpace = 2;
int leftEdgeOfSeparator = static_cast<int>(leftEdge - arrowPaddingLeft); // FIXME: Round?
// Draw the separator to the left of the arrows
paintInfo.context->setStrokeThickness(1.0f);
paintInfo.context->setStrokeStyle(SolidStroke);
paintInfo.context->setStrokeColor(leftSeparatorColor);
paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator, bounds.y()),
IntPoint(leftEdgeOfSeparator, bounds.bottom()));
paintInfo.context->setStrokeColor(rightSeparatorColor);
paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.y()),
IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.bottom()));
paintInfo.context->restore();
return false;
}
void RenderThemeSafari::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
NSControlSize controlSize = controlSizeForFont(style);
style->resetBorder();
style->resetPadding();
// Height is locked to auto.
style->setHeight(Length(Auto));
// White-space is locked to pre
style->setWhiteSpace(PRE);
// Set the foreground color to black or gray when we have the aqua look.
// Cast to RGB32 is to work around a compiler bug.
style->setColor(e->isEnabled() ? static_cast<RGBA32>(Color::black) : Color::darkGray);
// Set the button's vertical size.
setButtonSize(style);
// Our font is locked to the appropriate system font size for the control. To clarify, we first use the CSS-specified font to figure out
// a reasonable control size, but once that control size is determined, we throw that font away and use the appropriate
// system font for the control size instead.
setFontFromControlSize(selector, style, controlSize);
}
int RenderThemeSafari::popupInternalPaddingLeft(RenderStyle* style) const
{
if (style->appearance() == MenulistAppearance)
return popupButtonPadding(controlSizeForFont(style))[leftPadding];
if (style->appearance() == MenulistButtonAppearance)
return styledPopupPaddingLeft;
return 0;
}
int RenderThemeSafari::popupInternalPaddingRight(RenderStyle* style) const
{
if (style->appearance() == MenulistAppearance)
return popupButtonPadding(controlSizeForFont(style))[rightPadding];
if (style->appearance() == MenulistButtonAppearance) {
float fontScale = style->fontSize() / baseFontSize;
float arrowWidth = baseArrowWidth * fontScale;
return static_cast<int>(ceilf(arrowWidth + arrowPaddingLeft + arrowPaddingRight + paddingBeforeSeparator));
}
return 0;
}
int RenderThemeSafari::popupInternalPaddingTop(RenderStyle* style) const
{
if (style->appearance() == MenulistAppearance)
return popupButtonPadding(controlSizeForFont(style))[topPadding];
if (style->appearance() == MenulistButtonAppearance)
return styledPopupPaddingTop;
return 0;
}
int RenderThemeSafari::popupInternalPaddingBottom(RenderStyle* style) const
{
if (style->appearance() == MenulistAppearance)
return popupButtonPadding(controlSizeForFont(style))[bottomPadding];
if (style->appearance() == MenulistButtonAppearance)
return styledPopupPaddingBottom;
return 0;
}
void RenderThemeSafari::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
float fontScale = style->fontSize() / baseFontSize;
style->resetPadding();
style->setBorderRadius(IntSize(int(baseBorderRadius + fontScale - 1), int(baseBorderRadius + fontScale - 1))); // FIXME: Round up?
const int minHeight = 15;
style->setMinHeight(Length(minHeight, Fixed));
style->setLineHeight(RenderStyle::initialLineHeight());
}
const IntSize* RenderThemeSafari::menuListSizes() const
{
static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0) };
return sizes;
}
int RenderThemeSafari::minimumMenuListSize(RenderStyle* style) const
{
return sizeForSystemFont(style, menuListSizes()).width();
}
const int trackWidth = 5;
const int trackRadius = 2;
bool RenderThemeSafari::paintSliderTrack(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
IntRect bounds = r;
if (o->style()->appearance() == SliderHorizontalAppearance ||
o->style()->appearance() == MediaSliderAppearance) {
bounds.setHeight(trackWidth);
bounds.setY(r.y() + r.height() / 2 - trackWidth / 2);
} else if (o->style()->appearance() == SliderVerticalAppearance) {
bounds.setWidth(trackWidth);
bounds.setX(r.x() + r.width() / 2 - trackWidth / 2);
}
CGContextRef context = paintInfo.context->platformContext();
RetainPtr<CGColorSpaceRef> cspace(AdoptCF, CGColorSpaceCreateDeviceRGB());
paintInfo.context->save();
CGContextClipToRect(context, bounds);
struct CGFunctionCallbacks mainCallbacks = { 0, TrackGradientInterpolate, NULL };
RetainPtr<CGFunctionRef> mainFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &mainCallbacks));
RetainPtr<CGShadingRef> mainShading;
if (o->style()->appearance() == SliderVerticalAppearance)
mainShading.adoptCF(CGShadingCreateAxial(cspace.get(), CGPointMake(bounds.x(), bounds.bottom()), CGPointMake(bounds.right(), bounds.bottom()), mainFunction.get(), false, false));
else
mainShading.adoptCF(CGShadingCreateAxial(cspace.get(), CGPointMake(bounds.x(), bounds.y()), CGPointMake(bounds.x(), bounds.bottom()), mainFunction.get(), false, false));
IntSize radius(trackRadius, trackRadius);
paintInfo.context->addRoundedRectClip(bounds,
radius, radius,
radius, radius);
CGContextDrawShading(context, mainShading.get());
paintInfo.context->restore();
return false;
}
void RenderThemeSafari::adjustSliderThumbStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
style->setBoxShadow(0);
}
const float verticalSliderHeightPadding = 0.1f;
bool RenderThemeSafari::paintSliderThumb(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
ASSERT(o->parent()->isSlider());
bool pressed = static_cast<RenderSlider*>(o->parent())->inDragMode();
ThemeControlState state = determineState(o->parent());
state &= ~SafariTheme::PressedState;
if (pressed)
state |= SafariTheme::PressedState;
paintThemePart(SliderThumbPart, paintInfo.context->platformContext(), r, NSSmallControlSize, state);
return false;
}
const int sliderThumbWidth = 15;
const int sliderThumbHeight = 15;
const int mediaSliderThumbWidth = 13;
const int mediaSliderThumbHeight = 14;
void RenderThemeSafari::adjustSliderThumbSize(RenderObject* o) const
{
if (o->style()->appearance() == SliderThumbHorizontalAppearance || o->style()->appearance() == SliderThumbVerticalAppearance) {
o->style()->setWidth(Length(sliderThumbWidth, Fixed));
o->style()->setHeight(Length(sliderThumbHeight, Fixed));
} else if (o->style()->appearance() == MediaSliderThumbAppearance) {
o->style()->setWidth(Length(mediaSliderThumbWidth, Fixed));
o->style()->setHeight(Length(mediaSliderThumbHeight, Fixed));
}
}
bool RenderThemeSafari::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
paintThemePart(SearchFieldPart, paintInfo.context->platformContext(), r, controlSizeFromRect(r, searchFieldSizes()), determineState(o));
return false;
}
const IntSize* RenderThemeSafari::searchFieldSizes() const
{
static const IntSize sizes[3] = { IntSize(0, 22), IntSize(0, 19), IntSize(0, 15) };
return sizes;
}
void RenderThemeSafari::setSearchFieldSize(RenderStyle* style) const
{
// If the width and height are both specified, then we have nothing to do.
if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
return;
// Use the font size to determine the intrinsic width of the control.
setSizeFromFont(style, searchFieldSizes());
}
void RenderThemeSafari::adjustSearchFieldStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
// Override border.
style->resetBorder();
const short borderWidth = 2;
style->setBorderLeftWidth(borderWidth);
style->setBorderLeftStyle(INSET);
style->setBorderRightWidth(borderWidth);
style->setBorderRightStyle(INSET);
style->setBorderBottomWidth(borderWidth);
style->setBorderBottomStyle(INSET);
style->setBorderTopWidth(borderWidth);
style->setBorderTopStyle(INSET);
// Override height.
style->setHeight(Length(Auto));
setSearchFieldSize(style);
// Override padding size to match AppKit text positioning.
const int padding = 1;
style->setPaddingLeft(Length(padding, Fixed));
style->setPaddingRight(Length(padding, Fixed));
style->setPaddingTop(Length(padding, Fixed));
style->setPaddingBottom(Length(padding, Fixed));
NSControlSize controlSize = controlSizeForFont(style);
setFontFromControlSize(selector, style, controlSize);
}
bool RenderThemeSafari::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect&)
{
ASSERT(SafariThemeLibrary());
Node* input = o->node()->shadowAncestorNode();
ASSERT(input);
RenderObject* renderer = input->renderer();
ASSERT(renderer);
IntRect searchRect = renderer->absoluteBoundingBoxRect();
paintThemePart(SearchFieldCancelButtonPart, paintInfo.context->platformContext(), searchRect, controlSizeFromRect(searchRect, searchFieldSizes()), determineState(o));
return false;
}
const IntSize* RenderThemeSafari::cancelButtonSizes() const
{
static const IntSize sizes[3] = { IntSize(16, 13), IntSize(13, 11), IntSize(13, 9) };
return sizes;
}
void RenderThemeSafari::adjustSearchFieldCancelButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
IntSize size = sizeForSystemFont(style, cancelButtonSizes());
style->setWidth(Length(size.width(), Fixed));
style->setHeight(Length(size.height(), Fixed));
}
const IntSize* RenderThemeSafari::resultsButtonSizes() const
{
static const IntSize sizes[3] = { IntSize(19, 13), IntSize(17, 11), IntSize(17, 9) };
return sizes;
}
const int emptyResultsOffset = 9;
void RenderThemeSafari::adjustSearchFieldDecorationStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
IntSize size = sizeForSystemFont(style, resultsButtonSizes());
style->setWidth(Length(size.width() - emptyResultsOffset, Fixed));
style->setHeight(Length(size.height(), Fixed));
}
bool RenderThemeSafari::paintSearchFieldDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&)
{
return false;
}
void RenderThemeSafari::adjustSearchFieldResultsDecorationStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
IntSize size = sizeForSystemFont(style, resultsButtonSizes());
style->setWidth(Length(size.width(), Fixed));
style->setHeight(Length(size.height(), Fixed));
}
bool RenderThemeSafari::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect&)
{
ASSERT(SafariThemeLibrary());
Node* input = o->node()->shadowAncestorNode();
ASSERT(input);
RenderObject* renderer = input->renderer();
ASSERT(renderer);
IntRect searchRect = renderer->absoluteBoundingBoxRect();
paintThemePart(SearchFieldResultsDecorationPart, paintInfo.context->platformContext(), searchRect, controlSizeFromRect(searchRect, searchFieldSizes()), determineState(o));
return false;
}
const int resultsArrowWidth = 5;
void RenderThemeSafari::adjustSearchFieldResultsButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
IntSize size = sizeForSystemFont(style, resultsButtonSizes());
style->setWidth(Length(size.width() + resultsArrowWidth, Fixed));
style->setHeight(Length(size.height(), Fixed));
}
bool RenderThemeSafari::paintSearchFieldResultsButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect&)
{
ASSERT(SafariThemeLibrary());
Node* input = o->node()->shadowAncestorNode();
ASSERT(input);
RenderObject* renderer = input->renderer();
ASSERT(renderer);
IntRect searchRect = renderer->absoluteBoundingBoxRect();
paintThemePart(SearchFieldResultsButtonPart, paintInfo.context->platformContext(), searchRect, controlSizeFromRect(searchRect, searchFieldSizes()), determineState(o));
return false;
}
#if ENABLE(VIDEO)
bool RenderThemeSafari::paintMediaFullscreenButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 2
ASSERT(SafariThemeLibrary());
paintThemePart(MediaFullscreenButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
#endif
return false;
}
bool RenderThemeSafari::paintMediaMuteButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
Node* node = o->element();
Node* mediaNode = node ? node->shadowAncestorNode() : 0;
if (!mediaNode || (!mediaNode->hasTagName(videoTag) && !mediaNode->hasTagName(audioTag)))
return false;
HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(mediaNode);
if (!mediaElement)
return false;
#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 2
ASSERT(SafariThemeLibrary());
paintThemePart(mediaElement->muted() ? MediaUnMuteButtonPart : MediaMuteButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
#endif
return false;
}
bool RenderThemeSafari::paintMediaPlayButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
Node* node = o->element();
Node* mediaNode = node ? node->shadowAncestorNode() : 0;
if (!mediaNode || (!mediaNode->hasTagName(videoTag) && !mediaNode->hasTagName(audioTag)))
return false;
HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(mediaNode);
if (!mediaElement)
return false;
#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 2
ASSERT(SafariThemeLibrary());
paintThemePart(mediaElement->canPlay() ? MediaPlayButtonPart : MediaPauseButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
#endif
return false;
}
bool RenderThemeSafari::paintMediaSeekBackButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 2
ASSERT(SafariThemeLibrary());
paintThemePart(MediaSeekBackButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
#endif
return false;
}
bool RenderThemeSafari::paintMediaSeekForwardButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 2
ASSERT(SafariThemeLibrary());
paintThemePart(MediaSeekForwardButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
#endif
return false;
}
bool RenderThemeSafari::paintMediaSliderTrack(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
Node* node = o->element();
Node* mediaNode = node ? node->shadowAncestorNode() : 0;
if (!mediaNode || (!mediaNode->hasTagName(videoTag) && !mediaNode->hasTagName(audioTag)))
return false;
HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(mediaNode);
if (!mediaElement)
return false;
float percentLoaded = 0;
if (MediaPlayer* player = mediaElement->player())
if (player->duration())
percentLoaded = player->maxTimeBuffered() / player->duration();
#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 2
ASSERT(SafariThemeLibrary());
STPaintProgressIndicator(SafariTheme::MediaType, paintInfo.context->platformContext(), r, NSRegularControlSize, 0, percentLoaded);
#endif
return false;
}
bool RenderThemeSafari::paintMediaSliderThumb(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
{
ASSERT(SafariThemeLibrary());
#if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 2
paintThemePart(MediaSliderThumbPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
#endif
return false;
}
#endif
} // namespace WebCore
#endif // #if USE(SAFARI_THEME)
|