Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: Source/core/layout/LayoutThemeMac.mm

Issue 1102353008: Split ThemePainter out of LayoutTheme (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: themePainter() -> theme().painter() Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/layout/LayoutThemeMac.h ('k') | Source/core/paint/BoxPainter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google, Inc. 3 * Copyright (C) 2008, 2009 Google, Inc.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #import "config.h" 21 #import "config.h"
22 #import "core/layout/LayoutThemeMac.h" 22 #import "core/layout/LayoutThemeMac.h"
23 23
24 #import "core/CSSValueKeywords.h" 24 #import "core/CSSValueKeywords.h"
25 #import "core/HTMLNames.h" 25 #import "core/HTMLNames.h"
26 #import "core/css/CSSValueList.h"
27 #import "core/dom/Document.h"
28 #import "core/dom/Element.h"
29 #import "core/fileapi/FileList.h" 26 #import "core/fileapi/FileList.h"
30 #import "core/frame/FrameView.h"
31 #import "core/html/HTMLInputElement.h"
32 #import "core/html/HTMLMediaElement.h"
33 #import "core/html/HTMLMeterElement.h" 27 #import "core/html/HTMLMeterElement.h"
34 #import "core/html/TimeRanges.h"
35 #import "core/html/shadow/MediaControlElements.h"
36 #import "core/layout/LayoutSlider.h"
37 #import "core/layout/LayoutMedia.h"
38 #import "core/layout/LayoutMediaControls.h"
39 #import "core/layout/LayoutMeter.h" 28 #import "core/layout/LayoutMeter.h"
40 #import "core/layout/LayoutProgress.h" 29 #import "core/layout/LayoutProgress.h"
41 #import "core/layout/LayoutView.h" 30 #import "core/layout/LayoutView.h"
42 #import "core/paint/PaintInfo.h" 31 #import "core/paint/MediaControlsPainter.h"
43 #import "core/style/AuthorStyleInfo.h" 32 #import "core/style/AuthorStyleInfo.h"
44 #import "core/style/ShadowList.h" 33 #import "core/style/ShadowList.h"
45 #import "platform/LayoutTestSupport.h" 34 #import "platform/LayoutTestSupport.h"
46 #import "platform/PlatformResourceLoader.h" 35 #import "platform/PlatformResourceLoader.h"
47 #import "platform/SharedBuffer.h"
48 #import "platform/geometry/FloatRoundedRect.h"
49 #import "platform/graphics/BitmapImage.h" 36 #import "platform/graphics/BitmapImage.h"
50 #import "platform/graphics/GraphicsContextStateSaver.h"
51 #import "platform/graphics/Image.h"
52 #import "platform/graphics/ImageBuffer.h"
53 #import "platform/mac/ColorMac.h" 37 #import "platform/mac/ColorMac.h"
54 #import "platform/mac/LocalCurrentGraphicsContext.h" 38 #import "platform/mac/LocalCurrentGraphicsContext.h"
55 #import "platform/mac/ThemeMac.h" 39 #import "platform/mac/ThemeMac.h"
56 #import "platform/mac/WebCoreNSCellExtras.h" 40 #import "platform/mac/WebCoreNSCellExtras.h"
57 #import "platform/text/PlatformLocale.h" 41 #import "platform/text/PlatformLocale.h"
58 #import "platform/text/StringTruncator.h" 42 #import "platform/text/StringTruncator.h"
59 #import <AvailabilityMacros.h> 43 #import <AvailabilityMacros.h>
60 #import <Carbon/Carbon.h> 44 #import <Carbon/Carbon.h>
61 #import <Cocoa/Cocoa.h> 45 #import <Cocoa/Cocoa.h>
62 #import <math.h> 46 #import <math.h>
63 #import <wtf/RetainPtr.h>
64 #import <wtf/StdLibExtras.h>
65 47
66 // The methods in this file are specific to the Mac OS X platform. 48 // The methods in this file are specific to the Mac OS X platform.
67 49
68 // We estimate the animation rate of a Mac OS X progress bar is 33 fps.
69 // Hard code the value here because we haven't found API for it.
70 const double progressAnimationFrameRate = 0.033;
71
72 // Mac OS X progress bar animation seems to have 256 frames.
73 const double progressAnimationNumFrames = 256;
74
75 @interface LayoutThemeNotificationObserver : NSObject 50 @interface LayoutThemeNotificationObserver : NSObject
76 { 51 {
77 blink::LayoutTheme *_theme; 52 blink::LayoutTheme *_theme;
78 } 53 }
79 54
80 - (id)initWithTheme:(blink::LayoutTheme *)theme; 55 - (id)initWithTheme:(blink::LayoutTheme *)theme;
81 - (void)systemColorsDidChange:(NSNotification *)notification; 56 - (void)systemColorsDidChange:(NSNotification *)notification;
82 57
83 @end 58 @end
84 59
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 - (BOOL)isFlipped { 108 - (BOOL)isFlipped {
134 return [[NSGraphicsContext currentContext] isFlipped]; 109 return [[NSGraphicsContext currentContext] isFlipped];
135 } 110 }
136 111
137 - (NSText *)currentEditor { 112 - (NSText *)currentEditor {
138 return nil; 113 return nil;
139 } 114 }
140 115
141 @end 116 @end
142 117
143 // Forward declare Mac SPIs.
144 extern "C" {
145 void _NSDrawCarbonThemeBezel(NSRect frame, BOOL enabled, BOOL flipped);
146 // Request for public API: rdar://13787640
147 void _NSDrawCarbonThemeListBox(NSRect frame, BOOL enabled, BOOL flipped, BOOL al ways_yes);
148 }
149
150 namespace blink { 118 namespace blink {
151 119
152 using namespace HTMLNames; 120 using namespace HTMLNames;
153 121
154 LayoutThemeMac::LayoutThemeMac() 122 LayoutThemeMac::LayoutThemeMac()
155 : m_notificationObserver(AdoptNS, [[LayoutThemeNotificationObserver alloc] i nitWithTheme:this]) 123 : m_notificationObserver(AdoptNS, [[LayoutThemeNotificationObserver alloc] i nitWithTheme:this])
124 , m_painter(*this)
156 { 125 {
157 [[NSNotificationCenter defaultCenter] addObserver:m_notificationObserver.get () 126 [[NSNotificationCenter defaultCenter] addObserver:m_notificationObserver.get ()
158 selector:@selector(systemColorsDidC hange:) 127 selector:@selector(systemColorsDidC hange:)
159 name:NSSystemColorsDidChangeNot ification 128 name:NSSystemColorsDidChangeNot ification
160 object:nil]; 129 object:nil];
161 } 130 }
162 131
163 LayoutThemeMac::~LayoutThemeMac() 132 LayoutThemeMac::~LayoutThemeMac()
164 { 133 {
165 [[NSNotificationCenter defaultCenter] removeObserver:m_notificationObserver. get()]; 134 [[NSNotificationCenter defaultCenter] removeObserver:m_notificationObserver. get()];
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 // like the control is styled. 451 // like the control is styled.
483 if (style.appearance() == MenulistPart && style.effectiveZoom() != 1.0f) 452 if (style.appearance() == MenulistPart && style.effectiveZoom() != 1.0f)
484 return true; 453 return true;
485 // FIXME: NSSearchFieldCell doesn't work well when scaled. 454 // FIXME: NSSearchFieldCell doesn't work well when scaled.
486 if (style.appearance() == SearchFieldPart && style.effectiveZoom() != 1) 455 if (style.appearance() == SearchFieldPart && style.effectiveZoom() != 1)
487 return true; 456 return true;
488 457
489 return LayoutTheme::isControlStyled(style, authorStyle); 458 return LayoutTheme::isControlStyled(style, authorStyle);
490 } 459 }
491 460
492 const int sliderThumbShadowBlur = 1;
493
494 void LayoutThemeMac::adjustPaintInvalidationRect(const LayoutObject* o, IntRect& r) 461 void LayoutThemeMac::adjustPaintInvalidationRect(const LayoutObject* o, IntRect& r)
495 { 462 {
496 ControlPart part = o->style()->appearance(); 463 ControlPart part = o->style()->appearance();
497 464
498 #if USE(NEW_THEME) 465 #if USE(NEW_THEME)
499 switch (part) { 466 switch (part) {
500 case CheckboxPart: 467 case CheckboxPart:
501 case RadioPart: 468 case RadioPart:
502 case PushButtonPart: 469 case PushButtonPart:
503 case SquareButtonPart: 470 case SquareButtonPart:
(...skipping 11 matching lines...) Expand all
515 setPopupButtonCellState(o, r); 482 setPopupButtonCellState(o, r);
516 IntSize size = popupButtonSizes()[[popupButton() controlSize]]; 483 IntSize size = popupButtonSizes()[[popupButton() controlSize]];
517 size.setHeight(size.height() * zoomLevel); 484 size.setHeight(size.height() * zoomLevel);
518 size.setWidth(r.width()); 485 size.setWidth(r.width());
519 r = ThemeMac::inflateRect(r, size, popupButtonMargins(), zoomLevel); 486 r = ThemeMac::inflateRect(r, size, popupButtonMargins(), zoomLevel);
520 } else if (part == SliderThumbHorizontalPart || part == SliderThumbVerticalP art) { 487 } else if (part == SliderThumbHorizontalPart || part == SliderThumbVerticalP art) {
521 r.setHeight(r.height() + sliderThumbShadowBlur); 488 r.setHeight(r.height() + sliderThumbShadowBlur);
522 } 489 }
523 } 490 }
524 491
525 FloatRect LayoutThemeMac::convertToPaintingRect(const LayoutObject* inputLayoutO bject, const LayoutObject* partLayoutObject, const FloatRect& inputRect, const I ntRect& r) const
526 {
527 FloatRect partRect(inputRect);
528
529 // Compute an offset between the part layoutObject and the input layoutObjec t.
530 FloatSize offsetFromInputLayoutObject;
531 const LayoutObject* layoutObject = partLayoutObject;
532 while (layoutObject && layoutObject != inputLayoutObject) {
533 LayoutObject* containingLayoutObject = layoutObject->container();
534 offsetFromInputLayoutObject -= roundedIntSize(layoutObject->offsetFromCo ntainer(containingLayoutObject, LayoutPoint()));
535 layoutObject = containingLayoutObject;
536 }
537 // If the input layoutObject was not a container, something went wrong.
538 ASSERT(layoutObject == inputLayoutObject);
539 // Move the rect into partLayoutObject's coords.
540 partRect.move(offsetFromInputLayoutObject);
541 // Account for the local drawing offset (tx, ty).
542 partRect.move(r.x(), r.y());
543
544 return partRect;
545 }
546
547 void LayoutThemeMac::updateCheckedState(NSCell* cell, const LayoutObject* o) 492 void LayoutThemeMac::updateCheckedState(NSCell* cell, const LayoutObject* o)
548 { 493 {
549 bool oldIndeterminate = [cell state] == NSMixedState; 494 bool oldIndeterminate = [cell state] == NSMixedState;
550 bool indeterminate = isIndeterminate(o); 495 bool indeterminate = isIndeterminate(o);
551 bool checked = isChecked(o); 496 bool checked = isChecked(o);
552 497
553 if (oldIndeterminate != indeterminate) { 498 if (oldIndeterminate != indeterminate) {
554 [cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSO ffState)]; 499 [cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSO ffState)];
555 return; 500 return;
556 } 501 }
(...skipping 30 matching lines...) Expand all
587 NSControlSize LayoutThemeMac::controlSizeForFont(const ComputedStyle& style) con st 532 NSControlSize LayoutThemeMac::controlSizeForFont(const ComputedStyle& style) con st
588 { 533 {
589 int fontSize = style.fontSize(); 534 int fontSize = style.fontSize();
590 if (fontSize >= 16) 535 if (fontSize >= 16)
591 return NSRegularControlSize; 536 return NSRegularControlSize;
592 if (fontSize >= 11) 537 if (fontSize >= 11)
593 return NSSmallControlSize; 538 return NSSmallControlSize;
594 return NSMiniControlSize; 539 return NSMiniControlSize;
595 } 540 }
596 541
597 // We don't use controlSizeForFont() for search field decorations because it
598 // needs to fit into the search field. The font size will already be modified by
599 // setFontFromControlSize() called on the search field.
600 static NSControlSize searchFieldControlSizeForFont(const ComputedStyle& style)
601 {
602 int fontSize = style.fontSize();
603 if (fontSize >= 13)
604 return NSRegularControlSize;
605 if (fontSize >= 11)
606 return NSSmallControlSize;
607 return NSMiniControlSize;
608 }
609
610 void LayoutThemeMac::setControlSize(NSCell* cell, const IntSize* sizes, const In tSize& minSize, float zoomLevel) 542 void LayoutThemeMac::setControlSize(NSCell* cell, const IntSize* sizes, const In tSize& minSize, float zoomLevel)
611 { 543 {
612 NSControlSize size; 544 NSControlSize size;
613 if (minSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomLevel) && 545 if (minSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomLevel) &&
614 minSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height( ) * zoomLevel)) 546 minSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height( ) * zoomLevel))
615 size = NSRegularControlSize; 547 size = NSRegularControlSize;
616 else if (minSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width () * zoomLevel) && 548 else if (minSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width () * zoomLevel) &&
617 minSize.height() >= static_cast<int>(sizes[NSSmallControlSize].heig ht() * zoomLevel)) 549 minSize.height() >= static_cast<int>(sizes[NSSmallControlSize].heig ht() * zoomLevel))
618 size = NSSmallControlSize; 550 size = NSSmallControlSize;
619 else 551 else
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 float zoomLevel = style.effectiveZoom(); 609 float zoomLevel = style.effectiveZoom();
678 if (zoomLevel != 1) 610 if (zoomLevel != 1)
679 fontSize /= zoomLevel; 611 fontSize /= zoomLevel;
680 if (fontSize >= [NSFont systemFontSizeForControlSize:NSRegularControlSize]) 612 if (fontSize >= [NSFont systemFontSizeForControlSize:NSRegularControlSize])
681 return NSRegularControlSize; 613 return NSRegularControlSize;
682 if (fontSize >= [NSFont systemFontSizeForControlSize:NSSmallControlSize]) 614 if (fontSize >= [NSFont systemFontSizeForControlSize:NSSmallControlSize])
683 return NSSmallControlSize; 615 return NSSmallControlSize;
684 return NSMiniControlSize; 616 return NSMiniControlSize;
685 } 617 }
686 618
687 bool LayoutThemeMac::paintTextField(LayoutObject* o, const PaintInfo& paintInfo, const IntRect& r)
688 {
689 LocalCurrentGraphicsContext localContext(paintInfo.context, r);
690
691 #if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1070
692 bool useNSTextFieldCell = o->style()->hasAppearance()
693 && o->style()->visitedDependentColor(CSSPropertyBackgroundColor) == Colo r::white
694 && !o->style()->hasBackgroundImage();
695
696 // We do not use NSTextFieldCell to draw styled text fields on Lion and
697 // SnowLeopard because there are a number of bugs on those platforms that
698 // require NSTextFieldCell to be in charge of painting its own
699 // background. We need WebCore to paint styled backgrounds, so we'll use
700 // this AppKit SPI function instead.
701 if (!useNSTextFieldCell) {
702 _NSDrawCarbonThemeBezel(r, isEnabled(o) && !isReadOnlyControl(o), YES);
703 return false;
704 }
705 #endif
706
707 NSTextFieldCell *textField = this->textField();
708
709 GraphicsContextStateSaver stateSaver(*paintInfo.context);
710
711 [textField setEnabled:(isEnabled(o) && !isReadOnlyControl(o))];
712 [textField drawWithFrame:NSRect(r) inView:documentViewFor(o)];
713
714 [textField setControlView:nil];
715
716 return false;
717 }
718
719 bool LayoutThemeMac::paintCapsLockIndicator(LayoutObject*, const PaintInfo& pain tInfo, const IntRect& r)
720 {
721 // This draws the caps lock indicator as it was done by
722 // WKDrawCapsLockIndicator.
723 LocalCurrentGraphicsContext localContext(paintInfo.context, r);
724 CGContextRef c = localContext.cgContext();
725 CGMutablePathRef shape = CGPathCreateMutable();
726
727 // To draw the caps lock indicator, draw the shape into a small
728 // square that is then scaled to the size of r.
729 const CGFloat kSquareSize = 17;
730
731 // Create a rounted square shape.
732 CGPathMoveToPoint(shape, NULL, 16.5, 4.5);
733 CGPathAddArc(shape, NULL, 12.5, 12.5, 4, 0, M_PI_2, false);
734 CGPathAddArc(shape, NULL, 4.5, 12.5, 4, M_PI_2, M_PI, false);
735 CGPathAddArc(shape, NULL, 4.5, 4.5, 4, M_PI, 3*M_PI/2, false);
736 CGPathAddArc(shape, NULL, 12.5, 4.5, 4, 3*M_PI/2, 0, false);
737
738 // Draw the arrow - note this is drawing in a flipped coordinate system, so
739 // the arrow is pointing down.
740 CGPathMoveToPoint(shape, NULL, 8.5, 2); // Tip point.
741 CGPathAddLineToPoint(shape, NULL, 4, 7);
742 CGPathAddLineToPoint(shape, NULL, 6.25, 7);
743 CGPathAddLineToPoint(shape, NULL, 6.25, 10.25);
744 CGPathAddLineToPoint(shape, NULL, 10.75, 10.25);
745 CGPathAddLineToPoint(shape, NULL, 10.75, 7);
746 CGPathAddLineToPoint(shape, NULL, 13, 7);
747 CGPathAddLineToPoint(shape, NULL, 8.5, 2);
748
749 // Draw the rectangle that underneath (or above in the flipped system) the
750 // arrow.
751 CGPathAddLineToPoint(shape, NULL, 10.75, 12);
752 CGPathAddLineToPoint(shape, NULL, 6.25, 12);
753 CGPathAddLineToPoint(shape, NULL, 6.25, 14.25);
754 CGPathAddLineToPoint(shape, NULL, 10.75, 14.25);
755 CGPathAddLineToPoint(shape, NULL, 10.75, 12);
756
757 // Scale and translate the shape.
758 CGRect cgr = r;
759 CGFloat maxX = CGRectGetMaxX(cgr);
760 CGFloat minY = CGRectGetMinY(cgr);
761 CGFloat heightScale = r.height() / kSquareSize;
762 CGAffineTransform transform = CGAffineTransformMake(
763 heightScale, 0, // A B
764 0, heightScale, // C D
765 maxX - r.height(), minY); // Tx Ty
766
767 CGMutablePathRef paintPath = CGPathCreateMutable();
768 CGPathAddPath(paintPath, &transform, shape);
769 CGPathRelease(shape);
770
771 CGContextSetRGBFillColor(c, 0, 0, 0, 0.4);
772 CGContextBeginPath(c);
773 CGContextAddPath(c, paintPath);
774 CGContextFillPath(c);
775 CGPathRelease(paintPath);
776
777 return false;
778 }
779
780 bool LayoutThemeMac::paintTextArea(LayoutObject* o, const PaintInfo& paintInfo, const IntRect& r)
781 {
782 LocalCurrentGraphicsContext localContext(paintInfo.context, r);
783 _NSDrawCarbonThemeListBox(r, isEnabled(o) && !isReadOnlyControl(o), YES, YES );
784 return false;
785 }
786
787 const int* LayoutThemeMac::popupButtonMargins() const 619 const int* LayoutThemeMac::popupButtonMargins() const
788 { 620 {
789 static const int margins[3][4] = 621 static const int margins[3][4] =
790 { 622 {
791 { 0, 3, 1, 3 }, 623 { 0, 3, 1, 3 },
792 { 0, 3, 2, 3 }, 624 { 0, 3, 2, 3 },
793 { 0, 1, 0, 1 } 625 { 0, 1, 0, 1 }
794 }; 626 };
795 return margins[[popupButton() controlSize]]; 627 return margins[[popupButton() controlSize]];
796 } 628 }
797 629
798 const IntSize* LayoutThemeMac::popupButtonSizes() const 630 const IntSize* LayoutThemeMac::popupButtonSizes() const
799 { 631 {
800 static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) }; 632 static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };
801 return sizes; 633 return sizes;
802 } 634 }
803 635
804 const int* LayoutThemeMac::popupButtonPadding(NSControlSize size) const 636 const int* LayoutThemeMac::popupButtonPadding(NSControlSize size) const
805 { 637 {
806 static const int padding[3][4] = 638 static const int padding[3][4] =
807 { 639 {
808 { 2, 26, 3, 8 }, 640 { 2, 26, 3, 8 },
809 { 2, 23, 3, 8 }, 641 { 2, 23, 3, 8 },
810 { 2, 22, 3, 10 } 642 { 2, 22, 3, 10 }
811 }; 643 };
812 return padding[size]; 644 return padding[size];
813 } 645 }
814 646
815 bool LayoutThemeMac::paintMenuList(LayoutObject* o, const PaintInfo& paintInfo, const IntRect& r)
816 {
817 setPopupButtonCellState(o, r);
818
819 NSPopUpButtonCell* popupButton = this->popupButton();
820
821 float zoomLevel = o->style()->effectiveZoom();
822 IntSize size = popupButtonSizes()[[popupButton controlSize]];
823 size.setHeight(size.height() * zoomLevel);
824 size.setWidth(r.width());
825
826 // Now inflate it to account for the shadow.
827 IntRect inflatedRect = r;
828 if (r.width() >= minimumMenuListSize(o->styleRef()))
829 inflatedRect = ThemeMac::inflateRect(inflatedRect, size, popupButtonMarg ins(), zoomLevel);
830
831 LocalCurrentGraphicsContext localContext(paintInfo.context, ThemeMac::inflat eRectForFocusRing(inflatedRect));
832 GraphicsContextStateSaver stateSaver(*paintInfo.context);
833
834 // On Leopard, the cell will draw outside of the given rect, so we have to
835 // clip to the rect.
836 paintInfo.context->clip(inflatedRect);
837
838 if (zoomLevel != 1.0f) {
839 inflatedRect.setWidth(inflatedRect.width() / zoomLevel);
840 inflatedRect.setHeight(inflatedRect.height() / zoomLevel);
841 paintInfo.context->translate(inflatedRect.x(), inflatedRect.y());
842 paintInfo.context->scale(zoomLevel, zoomLevel);
843 paintInfo.context->translate(-inflatedRect.x(), -inflatedRect.y());
844 }
845
846 NSView *view = documentViewFor(o);
847 [popupButton drawWithFrame:inflatedRect inView:view];
848 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
849 if (isFocused(o) && o->style()->outlineStyleIsAuto())
850 [popupButton _web_drawFocusRingWithFrame:inflatedRect inView:view];
851 #endif
852 [popupButton setControlView:nil];
853
854 return false;
855 }
856
857 IntSize LayoutThemeMac::meterSizeForBounds(const LayoutMeter* layoutMeter, const IntRect& bounds) const 647 IntSize LayoutThemeMac::meterSizeForBounds(const LayoutMeter* layoutMeter, const IntRect& bounds) const
858 { 648 {
859 if (NoControlPart == layoutMeter->style()->appearance()) 649 if (NoControlPart == layoutMeter->style()->appearance())
860 return bounds.size(); 650 return bounds.size();
861 651
862 NSLevelIndicatorCell* cell = levelIndicatorFor(layoutMeter); 652 NSLevelIndicatorCell* cell = levelIndicatorFor(layoutMeter);
863 // Makes enough room for cell's intrinsic size. 653 // Makes enough room for cell's intrinsic size.
864 NSSize cellSize = [cell cellSizeForBounds:IntRect(IntPoint(), bounds.size()) ]; 654 NSSize cellSize = [cell cellSizeForBounds:IntRect(IntPoint(), bounds.size()) ];
865 return IntSize(bounds.width() < cellSize.width ? cellSize.width : bounds.wid th(), 655 return IntSize(bounds.width() < cellSize.width ? cellSize.width : bounds.wid th(),
866 bounds.height() < cellSize.height ? cellSize.height : bounds. height()); 656 bounds.height() < cellSize.height ? cellSize.height : bounds. height());
867 } 657 }
868 658
869 bool LayoutThemeMac::paintMeter(LayoutObject* layoutObject, const PaintInfo& pai ntInfo, const IntRect& rect)
870 {
871 if (!layoutObject->isMeter())
872 return true;
873
874 LocalCurrentGraphicsContext localContext(paintInfo.context, rect);
875
876 NSLevelIndicatorCell* cell = levelIndicatorFor(toLayoutMeter(layoutObject));
877 GraphicsContextStateSaver stateSaver(*paintInfo.context);
878
879 [cell drawWithFrame:rect inView:documentViewFor(layoutObject)];
880 [cell setControlView:nil];
881 return false;
882 }
883
884 bool LayoutThemeMac::supportsMeter(ControlPart part) const 659 bool LayoutThemeMac::supportsMeter(ControlPart part) const
885 { 660 {
886 switch (part) { 661 switch (part) {
887 case RelevancyLevelIndicatorPart: 662 case RelevancyLevelIndicatorPart:
888 case DiscreteCapacityLevelIndicatorPart: 663 case DiscreteCapacityLevelIndicatorPart:
889 case RatingLevelIndicatorPart: 664 case RatingLevelIndicatorPart:
890 case MeterPart: 665 case MeterPart:
891 case ContinuousCapacityLevelIndicatorPart: 666 case ContinuousCapacityLevelIndicatorPart:
892 return true; 667 return true;
893 default: 668 default:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 double LayoutThemeMac::animationRepeatIntervalForProgressBar() const 754 double LayoutThemeMac::animationRepeatIntervalForProgressBar() const
980 { 755 {
981 return progressAnimationFrameRate; 756 return progressAnimationFrameRate;
982 } 757 }
983 758
984 double LayoutThemeMac::animationDurationForProgressBar() const 759 double LayoutThemeMac::animationDurationForProgressBar() const
985 { 760 {
986 return progressAnimationNumFrames * progressAnimationFrameRate; 761 return progressAnimationNumFrames * progressAnimationFrameRate;
987 } 762 }
988 763
989 bool LayoutThemeMac::paintProgressBar(LayoutObject* layoutObject, const PaintInf o& paintInfo, const IntRect& rect)
990 {
991 if (!layoutObject->isProgress())
992 return true;
993
994 float zoomLevel = layoutObject->style()->effectiveZoom();
995 NSControlSize controlSize = controlSizeForFont(layoutObject->styleRef());
996 IntSize size = progressBarSizes()[controlSize];
997 size.setHeight(size.height() * zoomLevel);
998 size.setWidth(rect.width());
999
1000 // Now inflate it to account for the shadow.
1001 IntRect inflatedRect = rect;
1002 if (rect.height() <= minimumProgressBarHeight(layoutObject->styleRef()))
1003 inflatedRect = ThemeMac::inflateRect(inflatedRect, size, progressBarMarg ins(controlSize), zoomLevel);
1004
1005 LayoutProgress* layoutProgress = toLayoutProgress(layoutObject);
1006 HIThemeTrackDrawInfo trackInfo;
1007 trackInfo.version = 0;
1008 if (controlSize == NSRegularControlSize)
1009 trackInfo.kind = layoutProgress->position() < 0 ? kThemeLargeIndetermina teBar : kThemeLargeProgressBar;
1010 else
1011 trackInfo.kind = layoutProgress->position() < 0 ? kThemeMediumIndetermin ateBar : kThemeMediumProgressBar;
1012
1013 trackInfo.bounds = IntRect(IntPoint(), inflatedRect.size());
1014 trackInfo.min = 0;
1015 trackInfo.max = std::numeric_limits<SInt32>::max();
1016 trackInfo.value = lround(layoutProgress->position() * nextafter(trackInfo.ma x, 0));
1017 trackInfo.trackInfo.progress.phase = lround(layoutProgress->animationProgres s() * nextafter(progressAnimationNumFrames, 0));
1018 trackInfo.attributes = kThemeTrackHorizontal;
1019 trackInfo.enableState = isActive(layoutObject) ? kThemeTrackActive : kThemeT rackInactive;
1020 trackInfo.reserved = 0;
1021 trackInfo.filler1 = 0;
1022
1023 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(inflatedRect.size());
1024 if (!imageBuffer)
1025 return true;
1026
1027 LocalCurrentGraphicsContext localContext(imageBuffer->context(), IntRect(Int Point(), inflatedRect.size()));
1028 CGContextRef cgContext = localContext.cgContext();
1029 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal);
1030
1031 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1032
1033 if (!layoutProgress->style()->isLeftToRightDirection()) {
1034 paintInfo.context->translate(2 * inflatedRect.x() + inflatedRect.width() , 0);
1035 paintInfo.context->scale(-1, 1);
1036 }
1037
1038 paintInfo.context->drawImageBuffer(imageBuffer.get(),
1039 FloatRect(inflatedRect.location(), imageBuffer->size()));
1040 return false;
1041 }
1042
1043 const float baseFontSize = 11.0f;
1044 const float baseArrowHeight = 4.0f;
1045 const float baseArrowWidth = 5.0f;
1046 const float baseSpaceBetweenArrows = 2.0f;
1047 const int arrowPaddingLeft = 6;
1048 const int arrowPaddingRight = 6;
1049 const int paddingBeforeSeparator = 4;
1050 const int baseBorderRadius = 5;
1051 const int styledPopupPaddingLeft = 8;
1052 const int styledPopupPaddingTop = 1;
1053 const int styledPopupPaddingBottom = 2;
1054
1055 bool LayoutThemeMac::paintMenuListButton(LayoutObject* o, const PaintInfo& paint Info, const IntRect& r)
1056 {
1057 IntRect bounds = IntRect(r.x() + o->style()->borderLeftWidth(),
1058 r.y() + o->style()->borderTopWidth(),
1059 r.width() - o->style()->borderLeftWidth() - o->styl e()->borderRightWidth(),
1060 r.height() - o->style()->borderTopWidth() - o->styl e()->borderBottomWidth());
1061 // Since we actually know the size of the control here, we restrict the font
1062 // scale to make sure the arrows will fit vertically in the bounds
1063 float fontScale = std::min(o->style()->fontSize() / baseFontSize, bounds.hei ght() / (baseArrowHeight * 2 + baseSpaceBetweenArrows));
1064 float centerY = bounds.y() + bounds.height() / 2.0f;
1065 float arrowHeight = baseArrowHeight * fontScale;
1066 float arrowWidth = baseArrowWidth * fontScale;
1067 float leftEdge = bounds.maxX() - arrowPaddingRight * o->style()->effectiveZo om() - arrowWidth;
1068 float spaceBetweenArrows = baseSpaceBetweenArrows * fontScale;
1069
1070 if (bounds.width() < arrowWidth + arrowPaddingLeft * o->style()->effectiveZo om())
1071 return false;
1072
1073 Color color = o->style()->visitedDependentColor(CSSPropertyColor);
1074
1075 FloatPoint arrow1[3];
1076 arrow1[0] = FloatPoint(leftEdge, centerY - spaceBetweenArrows / 2.0f);
1077 arrow1[1] = FloatPoint(leftEdge + arrowWidth, centerY - spaceBetweenArrows / 2.0f);
1078 arrow1[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY - spaceBetweenA rrows / 2.0f - arrowHeight);
1079
1080 // Draw the top arrow.
1081 paintInfo.context->fillPolygon(3, arrow1, color, true);
1082
1083 FloatPoint arrow2[3];
1084 arrow2[0] = FloatPoint(leftEdge, centerY + spaceBetweenArrows / 2.0f);
1085 arrow2[1] = FloatPoint(leftEdge + arrowWidth, centerY + spaceBetweenArrows / 2.0f);
1086 arrow2[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY + spaceBetweenA rrows / 2.0f + arrowHeight);
1087
1088 // Draw the bottom arrow.
1089 paintInfo.context->fillPolygon(3, arrow2, color, true);
1090 return false;
1091 }
1092
1093 static const IntSize* menuListButtonSizes() 764 static const IntSize* menuListButtonSizes()
1094 { 765 {
1095 static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) }; 766 static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };
1096 return sizes; 767 return sizes;
1097 } 768 }
1098 769
1099 void LayoutThemeMac::adjustMenuListStyle(ComputedStyle& style, Element* e) const 770 void LayoutThemeMac::adjustMenuListStyle(ComputedStyle& style, Element* e) const
1100 { 771 {
1101 NSControlSize controlSize = controlSizeForFont(style); 772 NSControlSize controlSize = controlSizeForFont(style);
1102 773
(...skipping 14 matching lines...) Expand all
1117 setSizeFromFont(style, menuListButtonSizes()); 788 setSizeFromFont(style, menuListButtonSizes());
1118 789
1119 // Our font is locked to the appropriate system font size for the 790 // Our font is locked to the appropriate system font size for the
1120 // control. To clarify, we first use the CSS-specified font to figure out a 791 // control. To clarify, we first use the CSS-specified font to figure out a
1121 // reasonable control size, but once that control size is determined, we 792 // reasonable control size, but once that control size is determined, we
1122 // throw that font away and use the appropriate system font for the control 793 // throw that font away and use the appropriate system font for the control
1123 // size instead. 794 // size instead.
1124 setFontFromControlSize(style, controlSize); 795 setFontFromControlSize(style, controlSize);
1125 } 796 }
1126 797
1127 const int autofillPopupHorizontalPadding = 4; 798 static const int autofillPopupHorizontalPadding = 4;
799 static const int paddingBeforeSeparator = 4;
800 static const int baseBorderRadius = 5;
801 static const int styledPopupPaddingLeft = 8;
802 static const int styledPopupPaddingTop = 1;
803 static const int styledPopupPaddingBottom = 2;
1128 804
1129 // These functions are called with MenuListPart or MenulistButtonPart appearance 805 // These functions are called with MenuListPart or MenulistButtonPart appearance
1130 // by LayoutMenuList, or with TextFieldPart appearance by 806 // by LayoutMenuList, or with TextFieldPart appearance by
1131 // AutofillPopupMenuClient. We assume only AutofillPopupMenuClient gives 807 // AutofillPopupMenuClient. We assume only AutofillPopupMenuClient gives
1132 // TexfieldPart appearance here. We want to change only Autofill padding. In 808 // TexfieldPart appearance here. We want to change only Autofill padding. In
1133 // the future, we have to separate Autofill popup window logic from WebKit to 809 // the future, we have to separate Autofill popup window logic from WebKit to
1134 // Chromium. 810 // Chromium.
1135 int LayoutThemeMac::popupInternalPaddingLeft(const ComputedStyle& style) const 811 int LayoutThemeMac::popupInternalPaddingLeft(const ComputedStyle& style) const
1136 { 812 {
1137 if (style.appearance() == TextFieldPart) 813 if (style.appearance() == TextFieldPart)
1138 return autofillPopupHorizontalPadding; 814 return autofillPopupHorizontalPadding;
1139 815
1140 if (style.appearance() == MenulistPart) 816 if (style.appearance() == MenulistPart)
1141 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::LeftMargi n] * style.effectiveZoom(); 817 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::LeftMargi n] * style.effectiveZoom();
1142 if (style.appearance() == MenulistButtonPart) 818 if (style.appearance() == MenulistButtonPart)
1143 return styledPopupPaddingLeft * style.effectiveZoom(); 819 return styledPopupPaddingLeft * style.effectiveZoom();
1144 return 0; 820 return 0;
1145 } 821 }
1146 822
1147 int LayoutThemeMac::popupInternalPaddingRight(const ComputedStyle& style) const 823 int LayoutThemeMac::popupInternalPaddingRight(const ComputedStyle& style) const
1148 { 824 {
1149 if (style.appearance() == TextFieldPart) 825 if (style.appearance() == TextFieldPart)
1150 return autofillPopupHorizontalPadding; 826 return autofillPopupHorizontalPadding;
1151 827
1152 if (style.appearance() == MenulistPart) 828 if (style.appearance() == MenulistPart)
1153 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::RightMarg in] * style.effectiveZoom(); 829 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::RightMarg in] * style.effectiveZoom();
1154 if (style.appearance() == MenulistButtonPart) { 830 if (style.appearance() == MenulistButtonPart) {
1155 float fontScale = style.fontSize() / baseFontSize; 831 float fontScale = style.fontSize() / baseFontSize;
1156 float arrowWidth = baseArrowWidth * fontScale; 832 float arrowWidth = menuListBaseArrowWidth * fontScale;
1157 return static_cast<int>(ceilf(arrowWidth + (arrowPaddingLeft + arrowPadd ingRight + paddingBeforeSeparator) * style.effectiveZoom())); 833 return static_cast<int>(ceilf(arrowWidth + (menuListArrowPaddingLeft + m enuListArrowPaddingRight + paddingBeforeSeparator) * style.effectiveZoom()));
1158 } 834 }
1159 return 0; 835 return 0;
1160 } 836 }
1161 837
1162 int LayoutThemeMac::popupInternalPaddingTop(const ComputedStyle& style) const 838 int LayoutThemeMac::popupInternalPaddingTop(const ComputedStyle& style) const
1163 { 839 {
1164 if (style.appearance() == MenulistPart) 840 if (style.appearance() == MenulistPart)
1165 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::TopMargin ] * style.effectiveZoom(); 841 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::TopMargin ] * style.effectiveZoom();
1166 if (style.appearance() == MenulistButtonPart) 842 if (style.appearance() == MenulistButtonPart)
1167 return styledPopupPaddingTop * style.effectiveZoom(); 843 return styledPopupPaddingTop * style.effectiveZoom();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 { 887 {
1212 static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0 ) }; 888 static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0 ) };
1213 return sizes; 889 return sizes;
1214 } 890 }
1215 891
1216 int LayoutThemeMac::minimumMenuListSize(const ComputedStyle& style) const 892 int LayoutThemeMac::minimumMenuListSize(const ComputedStyle& style) const
1217 { 893 {
1218 return sizeForSystemFont(style, menuListSizes()).width(); 894 return sizeForSystemFont(style, menuListSizes()).width();
1219 } 895 }
1220 896
1221 const int sliderTrackWidth = 5;
1222 const int sliderTrackBorderWidth = 1;
1223
1224 bool LayoutThemeMac::paintSliderTrack(LayoutObject* o, const PaintInfo& paintInf o, const IntRect& r)
1225 {
1226 paintSliderTicks(o, paintInfo, r);
1227
1228 float zoomLevel = o->style()->effectiveZoom();
1229 FloatRect unzoomedRect = r;
1230
1231 if (o->style()->appearance() == SliderHorizontalPart || o->style()->appeara nce() == MediaSliderPart) {
1232 unzoomedRect.setY(ceilf(unzoomedRect.y() + unzoomedRect.height() / 2 - z oomLevel * sliderTrackWidth / 2));
1233 unzoomedRect.setHeight(zoomLevel * sliderTrackWidth);
1234 } else if (o->style()->appearance() == SliderVerticalPart) {
1235 unzoomedRect.setX(ceilf(unzoomedRect.x() + unzoomedRect.width() / 2 - zo omLevel * sliderTrackWidth / 2));
1236 unzoomedRect.setWidth(zoomLevel * sliderTrackWidth);
1237 }
1238
1239 if (zoomLevel != 1) {
1240 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1241 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1242 }
1243
1244 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1245 if (zoomLevel != 1) {
1246 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1247 paintInfo.context->scale(zoomLevel, zoomLevel);
1248 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1249 }
1250
1251 Color fillColor(205, 205, 205);
1252 Color borderGradientTopColor(109, 109, 109);
1253 Color borderGradientBottomColor(181, 181, 181);
1254 Color shadowColor(0, 0, 0, 118);
1255
1256 if (!isEnabled(o)) {
1257 Color tintColor(255, 255, 255, 128);
1258 fillColor = fillColor.blend(tintColor);
1259 borderGradientTopColor = borderGradientTopColor.blend(tintColor);
1260 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor);
1261 shadowColor = shadowColor.blend(tintColor);
1262 }
1263
1264 Color tintColor;
1265 if (!isEnabled(o))
1266 tintColor = Color(255, 255, 255, 128);
1267
1268 bool isVerticalSlider = o->style()->appearance() == SliderVerticalPart;
1269
1270 int fillRadiusSize = (sliderTrackWidth - sliderTrackBorderWidth) / 2;
1271 IntSize fillRadius(fillRadiusSize, fillRadiusSize);
1272 IntRect fillBounds = enclosedIntRect(unzoomedRect);
1273 FloatRoundedRect fillRect(fillBounds, fillRadius, fillRadius, fillRadius, fi llRadius);
1274 paintInfo.context->fillRoundedRect(fillRect, fillColor);
1275
1276 IntSize shadowOffset(isVerticalSlider ? 1 : 0,
1277 isVerticalSlider ? 0 : 1);
1278 int shadowBlur = 3;
1279 int shadowSpread = 0;
1280 paintInfo.context->save();
1281 paintInfo.context->drawInnerShadow(fillRect, shadowColor, shadowOffset, shad owBlur, shadowSpread);
1282 paintInfo.context->restore();
1283
1284 RefPtr<Gradient> borderGradient = Gradient::create(fillBounds.minXMinYCorner (),
1285 isVerticalSlider ? fillBounds.maxXMinYCorner() : fillBounds.minXMaxYCorn er());
1286 borderGradient->addColorStop(0.0, borderGradientTopColor);
1287 borderGradient->addColorStop(1.0, borderGradientBottomColor);
1288 Path borderPath;
1289 FloatRect borderRect(unzoomedRect);
1290 borderRect.inflate(-sliderTrackBorderWidth / 2.0);
1291 float borderRadiusSize = (isVerticalSlider ? borderRect.width() : borderRect .height()) / 2;
1292 FloatSize borderRadius(borderRadiusSize, borderRadiusSize);
1293 borderPath.addRoundedRect(borderRect, borderRadius, borderRadius, borderRadi us, borderRadius);
1294 paintInfo.context->setStrokeGradient(borderGradient);
1295 paintInfo.context->setStrokeThickness(sliderTrackBorderWidth);
1296 paintInfo.context->strokePath(borderPath);
1297 return false;
1298 }
1299
1300 const int sliderThumbWidth = 15;
1301 const int sliderThumbHeight = 15;
1302 const int sliderThumbBorderWidth = 1;
1303
1304 bool LayoutThemeMac::paintSliderThumb(LayoutObject* o, const PaintInfo& paintInf o, const IntRect& r)
1305 {
1306 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1307 float zoomLevel = o->style()->effectiveZoom();
1308
1309 FloatRect unzoomedRect(r.x(), r.y(), sliderThumbWidth, sliderThumbHeight);
1310 if (zoomLevel != 1.0f) {
1311 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1312 paintInfo.context->scale(zoomLevel, zoomLevel);
1313 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1314 }
1315
1316 Color fillGradientTopColor(250, 250, 250);
1317 Color fillGradientUpperMiddleColor(244, 244, 244);
1318 Color fillGradientLowerMiddleColor(236, 236, 236);
1319 Color fillGradientBottomColor(238, 238, 238);
1320 Color borderGradientTopColor(151, 151, 151);
1321 Color borderGradientBottomColor(128, 128, 128);
1322 Color shadowColor(0, 0, 0, 36);
1323
1324 if (!isEnabled(o)) {
1325 Color tintColor(255, 255, 255, 128);
1326 fillGradientTopColor = fillGradientTopColor.blend(tintColor);
1327 fillGradientUpperMiddleColor = fillGradientUpperMiddleColor.blend(tintCo lor);
1328 fillGradientLowerMiddleColor = fillGradientLowerMiddleColor.blend(tintCo lor);
1329 fillGradientBottomColor = fillGradientBottomColor.blend(tintColor);
1330 borderGradientTopColor = borderGradientTopColor.blend(tintColor);
1331 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor);
1332 shadowColor = shadowColor.blend(tintColor);
1333 } else if (isPressed(o)) {
1334 Color tintColor(0, 0, 0, 32);
1335 fillGradientTopColor = fillGradientTopColor.blend(tintColor);
1336 fillGradientUpperMiddleColor = fillGradientUpperMiddleColor.blend(tintCo lor);
1337 fillGradientLowerMiddleColor = fillGradientLowerMiddleColor.blend(tintCo lor);
1338 fillGradientBottomColor = fillGradientBottomColor.blend(tintColor);
1339 borderGradientTopColor = borderGradientTopColor.blend(tintColor);
1340 borderGradientBottomColor = borderGradientBottomColor.blend(tintColor);
1341 shadowColor = shadowColor.blend(tintColor);
1342 }
1343
1344 FloatRect borderBounds = unzoomedRect;
1345 borderBounds.inflate(sliderThumbBorderWidth / 2.0);
1346
1347 borderBounds.inflate(-sliderThumbBorderWidth);
1348 FloatSize shadowOffset(0, 1);
1349 paintInfo.context->setShadow(shadowOffset, sliderThumbShadowBlur, shadowColo r);
1350 paintInfo.context->setFillColor(Color::black);
1351 paintInfo.context->fillEllipse(borderBounds);
1352 paintInfo.context->clearShadow();
1353
1354 IntRect fillBounds = enclosedIntRect(unzoomedRect);
1355 RefPtr<Gradient> fillGradient = Gradient::create(fillBounds.minXMinYCorner() , fillBounds.minXMaxYCorner());
1356 fillGradient->addColorStop(0.0, fillGradientTopColor);
1357 fillGradient->addColorStop(0.52, fillGradientUpperMiddleColor);
1358 fillGradient->addColorStop(0.52, fillGradientLowerMiddleColor);
1359 fillGradient->addColorStop(1.0, fillGradientBottomColor);
1360 paintInfo.context->setFillGradient(fillGradient);
1361 paintInfo.context->fillEllipse(borderBounds);
1362
1363 RefPtr<Gradient> borderGradient = Gradient::create(fillBounds.minXMinYCorner (), fillBounds.minXMaxYCorner());
1364 borderGradient->addColorStop(0.0, borderGradientTopColor);
1365 borderGradient->addColorStop(1.0, borderGradientBottomColor);
1366 paintInfo.context->setStrokeGradient(borderGradient);
1367 paintInfo.context->setStrokeThickness(sliderThumbBorderWidth);
1368 paintInfo.context->strokeEllipse(borderBounds);
1369
1370 if (isFocused(o)) {
1371 Path borderPath;
1372 borderPath.addEllipse(borderBounds);
1373 paintInfo.context->drawFocusRing(borderPath, 5, -2, focusRingColor());
1374 }
1375
1376 return false;
1377 }
1378
1379 bool LayoutThemeMac::paintSearchField(LayoutObject* o, const PaintInfo& paintInf o, const IntRect& r)
1380 {
1381 LocalCurrentGraphicsContext localContext(paintInfo.context, r);
1382
1383 NSSearchFieldCell* search = this->search();
1384 setSearchCellState(o, r);
1385 [search setControlSize:searchFieldControlSizeForFont(o->styleRef())];
1386
1387 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1388
1389 float zoomLevel = o->style()->effectiveZoom();
1390
1391 IntRect unzoomedRect = r;
1392
1393 if (zoomLevel != 1.0f) {
1394 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1395 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1396 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1397 paintInfo.context->scale(zoomLevel, zoomLevel);
1398 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1399 }
1400
1401 // Set the search button to nil before drawing. Then reset it so we can
1402 // draw it later.
1403 [search setSearchButtonCell:nil];
1404
1405 [search drawWithFrame:NSRect(unzoomedRect) inView:documentViewFor(o)];
1406
1407 [search setControlView:nil];
1408 [search resetSearchButtonCell];
1409
1410 return false;
1411 }
1412
1413 void LayoutThemeMac::setSearchCellState(LayoutObject* o, const IntRect&) 897 void LayoutThemeMac::setSearchCellState(LayoutObject* o, const IntRect&)
1414 { 898 {
1415 NSSearchFieldCell* search = this->search(); 899 NSSearchFieldCell* search = this->search();
1416 900
1417 // Update the various states we respond to. 901 // Update the various states we respond to.
1418 updateActiveState(search, o); 902 updateActiveState(search, o);
1419 updateEnabledState(search, o); 903 updateEnabledState(search, o);
1420 updateFocusedState(search, o); 904 updateFocusedState(search, o);
1421 } 905 }
1422 906
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 style.setPaddingLeft(Length(horizontalPadding, Fixed)); 953 style.setPaddingLeft(Length(horizontalPadding, Fixed));
1470 style.setPaddingRight(Length(horizontalPadding, Fixed)); 954 style.setPaddingRight(Length(horizontalPadding, Fixed));
1471 style.setPaddingTop(Length(verticalPadding, Fixed)); 955 style.setPaddingTop(Length(verticalPadding, Fixed));
1472 style.setPaddingBottom(Length(verticalPadding, Fixed)); 956 style.setPaddingBottom(Length(verticalPadding, Fixed));
1473 957
1474 setFontFromControlSize(style, controlSize); 958 setFontFromControlSize(style, controlSize);
1475 959
1476 style.setBoxShadow(nullptr); 960 style.setBoxShadow(nullptr);
1477 } 961 }
1478 962
1479 bool LayoutThemeMac::paintSearchFieldCancelButton(LayoutObject* o, const PaintIn fo& paintInfo, const IntRect& r)
1480 {
1481 if (!o->node())
1482 return false;
1483 Element* input = o->node()->shadowHost();
1484 if (!input)
1485 input = toElement(o->node());
1486
1487 if (!input->layoutObject()->isBox())
1488 return false;
1489
1490 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1491
1492 float zoomLevel = o->style()->effectiveZoom();
1493 FloatRect unzoomedRect(r);
1494 if (zoomLevel != 1.0f) {
1495 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1496 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1497 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1498 paintInfo.context->scale(zoomLevel, zoomLevel);
1499 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1500 }
1501
1502 Color fillColor(200, 200, 200);
1503
1504 if (isPressed(o)) {
1505 Color tintColor(0, 0, 0, 32);
1506 fillColor = fillColor.blend(tintColor);
1507 }
1508
1509 float centerX = unzoomedRect.x() + unzoomedRect.width() / 2;
1510 float centerY = unzoomedRect.y() + unzoomedRect.height() / 2;
1511 // The line width is 3px on a regular sized, high DPI NSCancelButtonCell
1512 // (which is 28px wide).
1513 float lineWidth = unzoomedRect.width() * 3 / 28;
1514 // The line length is 16px on a regular sized, high DPI NSCancelButtonCell.
1515 float lineLength = unzoomedRect.width() * 16 / 28;
1516
1517 Path xPath;
1518 FloatSize lineRectRadius(lineWidth / 2, lineWidth / 2);
1519 xPath.addRoundedRect(FloatRect(-lineLength / 2, -lineWidth / 2, lineLength, lineWidth),
1520 lineRectRadius, lineRectRadius, lineRectRadius, lineRectRadius);
1521 xPath.addRoundedRect(FloatRect(-lineWidth / 2, -lineLength / 2, lineWidth, l ineLength),
1522 lineRectRadius, lineRectRadius, lineRectRadius, lineRectRadius);
1523
1524 paintInfo.context->translate(centerX, centerY);
1525 paintInfo.context->rotate(deg2rad(45.0));
1526 paintInfo.context->clipOut(xPath);
1527 paintInfo.context->rotate(deg2rad(-45.0));
1528 paintInfo.context->translate(-centerX, -centerY);
1529
1530 paintInfo.context->setFillColor(fillColor);
1531 paintInfo.context->fillEllipse(unzoomedRect);
1532
1533 return false;
1534 }
1535
1536 const IntSize* LayoutThemeMac::cancelButtonSizes() const 963 const IntSize* LayoutThemeMac::cancelButtonSizes() const
1537 { 964 {
1538 static const IntSize sizes[3] = { IntSize(14, 14), IntSize(11, 11), IntSize( 9, 9) }; 965 static const IntSize sizes[3] = { IntSize(14, 14), IntSize(11, 11), IntSize( 9, 9) };
1539 return sizes; 966 return sizes;
1540 } 967 }
1541 968
1542 void LayoutThemeMac::adjustSearchFieldCancelButtonStyle(ComputedStyle& style, El ement*) const 969 void LayoutThemeMac::adjustSearchFieldCancelButtonStyle(ComputedStyle& style, El ement*) const
1543 { 970 {
1544 IntSize size = sizeForSystemFont(style, cancelButtonSizes()); 971 IntSize size = sizeForSystemFont(style, cancelButtonSizes());
1545 style.setWidth(Length(size.width(), Fixed)); 972 style.setWidth(Length(size.width(), Fixed));
(...skipping 10 matching lines...) Expand all
1556 void LayoutThemeMac::adjustSearchFieldDecorationStyle(ComputedStyle& style, Elem ent*) const 983 void LayoutThemeMac::adjustSearchFieldDecorationStyle(ComputedStyle& style, Elem ent*) const
1557 { 984 {
1558 NSControlSize controlSize = controlSizeForSystemFont(style); 985 NSControlSize controlSize = controlSizeForSystemFont(style);
1559 IntSize searchFieldSize = searchFieldSizes()[controlSize]; 986 IntSize searchFieldSize = searchFieldSizes()[controlSize];
1560 int width = searchFieldSize.height() / 2 - searchFieldBorderWidth - searchFi eldHorizontalPaddings()[controlSize]; 987 int width = searchFieldSize.height() / 2 - searchFieldBorderWidth - searchFi eldHorizontalPaddings()[controlSize];
1561 style.setWidth(Length(width, Fixed)); 988 style.setWidth(Length(width, Fixed));
1562 style.setHeight(Length(0, Fixed)); 989 style.setHeight(Length(0, Fixed));
1563 style.setBoxShadow(nullptr); 990 style.setBoxShadow(nullptr);
1564 } 991 }
1565 992
1566 bool LayoutThemeMac::paintSearchFieldDecoration(LayoutObject*, const PaintInfo&, const IntRect&)
1567 {
1568 return false;
1569 }
1570
1571 void LayoutThemeMac::adjustSearchFieldResultsDecorationStyle(ComputedStyle& styl e, Element*) const 993 void LayoutThemeMac::adjustSearchFieldResultsDecorationStyle(ComputedStyle& styl e, Element*) const
1572 { 994 {
1573 IntSize size = sizeForSystemFont(style, resultsButtonSizes()); 995 IntSize size = sizeForSystemFont(style, resultsButtonSizes());
1574 style.setWidth(Length(size.width(), Fixed)); 996 style.setWidth(Length(size.width(), Fixed));
1575 style.setHeight(Length(size.height(), Fixed)); 997 style.setHeight(Length(size.height(), Fixed));
1576 style.setBoxShadow(nullptr); 998 style.setBoxShadow(nullptr);
1577 } 999 }
1578 1000
1579 bool LayoutThemeMac::paintSearchFieldResultsDecoration(LayoutObject* o, const Pa intInfo& paintInfo, const IntRect& r)
1580 {
1581 if (!o->node())
1582 return false;
1583 Node* input = o->node()->shadowHost();
1584 if (!input)
1585 input = o->node();
1586 if (!input->layoutObject()->isBox())
1587 return false;
1588
1589 GraphicsContextStateSaver stateSaver(*paintInfo.context);
1590
1591 float zoomLevel = o->style()->effectiveZoom();
1592 FloatRect unzoomedRect(r);
1593 if (zoomLevel != 1) {
1594 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1595 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1596 paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());
1597 paintInfo.context->scale(zoomLevel, zoomLevel);
1598 paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1599 }
1600
1601 LocalCurrentGraphicsContext localContext(paintInfo.context, r);
1602
1603 NSSearchFieldCell* search = this->search();
1604 setSearchCellState(input->layoutObject(), r);
1605 [search setControlSize:searchFieldControlSizeForFont(o->styleRef())];
1606 if ([search searchMenuTemplate] != nil)
1607 [search setSearchMenuTemplate:nil];
1608
1609 updateActiveState([search searchButtonCell], o);
1610
1611 [[search searchButtonCell] drawWithFrame:unzoomedRect inView:documentViewFor (o)];
1612 [[search searchButtonCell] setControlView:nil];
1613 return false;
1614 }
1615
1616 IntSize LayoutThemeMac::sliderTickSize() const 1001 IntSize LayoutThemeMac::sliderTickSize() const
1617 { 1002 {
1618 return IntSize(1, 3); 1003 return IntSize(1, 3);
1619 } 1004 }
1620 1005
1621 int LayoutThemeMac::sliderTickOffsetFromTrackCenter() const 1006 int LayoutThemeMac::sliderTickOffsetFromTrackCenter() const
1622 { 1007 {
1623 return -9; 1008 return -9;
1624 } 1009 }
1625 1010
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1757 [cell setControlTint:tint]; 1142 [cell setControlTint:tint];
1758 } 1143 }
1759 1144
1760 bool LayoutThemeMac::shouldShowPlaceholderWhenFocused() const 1145 bool LayoutThemeMac::shouldShowPlaceholderWhenFocused() const
1761 { 1146 {
1762 return true; 1147 return true;
1763 } 1148 }
1764 1149
1765 void LayoutThemeMac::adjustMediaSliderThumbSize(ComputedStyle& style) const 1150 void LayoutThemeMac::adjustMediaSliderThumbSize(ComputedStyle& style) const
1766 { 1151 {
1767 LayoutMediaControls::adjustMediaSliderThumbSize(style); 1152 MediaControlsPainter::adjustMediaSliderThumbSize(style);
1768 }
1769
1770 bool LayoutThemeMac::paintMediaPlayButton(LayoutObject* object, const PaintInfo& paintInfo, const IntRect& rect)
1771 {
1772 return LayoutMediaControls::paintMediaControlsPart(MediaPlayButton, object, paintInfo, rect);
1773 }
1774
1775 bool LayoutThemeMac::paintMediaOverlayPlayButton(LayoutObject* object, const Pai ntInfo& paintInfo, const IntRect& rect)
1776 {
1777 return LayoutMediaControls::paintMediaControlsPart(MediaOverlayPlayButton, o bject, paintInfo, rect);
1778 }
1779
1780 bool LayoutThemeMac::paintMediaMuteButton(LayoutObject* object, const PaintInfo& paintInfo, const IntRect& rect)
1781 {
1782 return LayoutMediaControls::paintMediaControlsPart(MediaMuteButton, object, paintInfo, rect);
1783 }
1784
1785 bool LayoutThemeMac::paintMediaSliderTrack(LayoutObject* object, const PaintInfo & paintInfo, const IntRect& rect)
1786 {
1787 return LayoutMediaControls::paintMediaControlsPart(MediaSlider, object, pain tInfo, rect);
1788 } 1153 }
1789 1154
1790 String LayoutThemeMac::extraFullScreenStyleSheet() 1155 String LayoutThemeMac::extraFullScreenStyleSheet()
1791 { 1156 {
1792 // FIXME: Chromium may wish to style its default media controls differently in fullscreen. 1157 // FIXME: Chromium may wish to style its default media controls differently in fullscreen.
1793 return String(); 1158 return String();
1794 } 1159 }
1795 1160
1796 String LayoutThemeMac::extraDefaultStyleSheet() 1161 String LayoutThemeMac::extraDefaultStyleSheet()
1797 { 1162 {
1798 return LayoutTheme::extraDefaultStyleSheet() + 1163 return LayoutTheme::extraDefaultStyleSheet() +
1799 loadResourceAsASCIIString("themeChromium.css") + 1164 loadResourceAsASCIIString("themeChromium.css") +
1800 loadResourceAsASCIIString("themeInputMultipleFields.css") + 1165 loadResourceAsASCIIString("themeInputMultipleFields.css") +
1801 loadResourceAsASCIIString("themeMac.css"); 1166 loadResourceAsASCIIString("themeMac.css");
1802 } 1167 }
1803 1168
1804 bool LayoutThemeMac::paintMediaVolumeSliderContainer(LayoutObject* object, const PaintInfo& paintInfo, const IntRect& rect)
1805 {
1806 return true;
1807 }
1808
1809 bool LayoutThemeMac::paintMediaVolumeSliderTrack(LayoutObject* object, const Pai ntInfo& paintInfo, const IntRect& rect)
1810 {
1811 return LayoutMediaControls::paintMediaControlsPart(MediaVolumeSlider, object , paintInfo, rect);
1812 }
1813
1814 bool LayoutThemeMac::paintMediaVolumeSliderThumb(LayoutObject* object, const Pai ntInfo& paintInfo, const IntRect& rect)
1815 {
1816 return LayoutMediaControls::paintMediaControlsPart(MediaVolumeSliderThumb, o bject, paintInfo, rect);
1817 }
1818
1819 bool LayoutThemeMac::paintMediaSliderThumb(LayoutObject* object, const PaintInfo & paintInfo, const IntRect& rect)
1820 {
1821 return LayoutMediaControls::paintMediaControlsPart(MediaSliderThumb, object, paintInfo, rect);
1822 }
1823
1824 String LayoutThemeMac::formatMediaControlsTime(float time) const
1825 {
1826 return LayoutMediaControls::formatMediaControlsTime(time);
1827 }
1828
1829 String LayoutThemeMac::formatMediaControlsCurrentTime(float currentTime, float d uration) const
1830 {
1831 return LayoutMediaControls::formatMediaControlsCurrentTime(currentTime, dura tion);
1832 }
1833
1834 bool LayoutThemeMac::paintMediaFullscreenButton(LayoutObject* object, const Pain tInfo& paintInfo, const IntRect& rect)
1835 {
1836 return LayoutMediaControls::paintMediaControlsPart(MediaEnterFullscreenButto n, object, paintInfo, rect);
1837 }
1838
1839 bool LayoutThemeMac::paintMediaToggleClosedCaptionsButton(LayoutObject* object, const PaintInfo& paintInfo, const IntRect& rect)
1840 {
1841 return LayoutMediaControls::paintMediaControlsPart(MediaShowClosedCaptionsBu tton, object, paintInfo, rect);
1842 }
1843
1844 bool LayoutThemeMac::shouldUseFallbackTheme(const ComputedStyle& style) const 1169 bool LayoutThemeMac::shouldUseFallbackTheme(const ComputedStyle& style) const
1845 { 1170 {
1846 ControlPart part = style.appearance(); 1171 ControlPart part = style.appearance();
1847 if (part == CheckboxPart || part == RadioPart) 1172 if (part == CheckboxPart || part == RadioPart)
1848 return style.effectiveZoom() != 1; 1173 return style.effectiveZoom() != 1;
1849 return false; 1174 return false;
1850 } 1175 }
1851 1176
1852 } // namespace blink 1177 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutThemeMac.h ('k') | Source/core/paint/BoxPainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698