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

Side by Side Diff: third_party/WebKit/Source/core/paint/ThemePainterMac.mm

Issue 2309593002: Factor code from ThemeMac into ThemeMacPainter. (Closed)
Patch Set: none Created 4 years, 3 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
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 "core/paint/ThemePainterMac.h" 21 #import "core/paint/ThemePainterMac.h"
22 22
23 #import "core/frame/FrameView.h"
23 #import "core/layout/LayoutProgress.h" 24 #import "core/layout/LayoutProgress.h"
24 #import "core/layout/LayoutThemeMac.h" 25 #import "core/layout/LayoutThemeMac.h"
25 #import "core/layout/LayoutView.h" 26 #import "core/layout/LayoutView.h"
26 #import "core/paint/PaintInfo.h" 27 #import "core/paint/PaintInfo.h"
27 #import "platform/geometry/FloatRoundedRect.h" 28 #import "platform/geometry/FloatRoundedRect.h"
28 #import "platform/graphics/BitmapImage.h" 29 #import "platform/graphics/BitmapImage.h"
29 #import "platform/graphics/GraphicsContextStateSaver.h" 30 #import "platform/graphics/GraphicsContextStateSaver.h"
30 #import "platform/graphics/Image.h" 31 #import "platform/graphics/Image.h"
31 #import "platform/graphics/ImageBuffer.h" 32 #import "platform/graphics/ImageBuffer.h"
33 #import "platform/mac/BlockExceptions.h"
32 #import "platform/mac/ColorMac.h" 34 #import "platform/mac/ColorMac.h"
33 #import "platform/mac/LocalCurrentGraphicsContext.h" 35 #import "platform/mac/LocalCurrentGraphicsContext.h"
34 #import "platform/mac/ThemeMac.h" 36 #import "platform/mac/ThemeMac.h"
35 #import "platform/mac/WebCoreNSCellExtras.h" 37 #import "platform/mac/WebCoreNSCellExtras.h"
36 #import <AvailabilityMacros.h> 38 #import <AvailabilityMacros.h>
37 #import <Carbon/Carbon.h> 39 #import <Carbon/Carbon.h>
38 #import <Cocoa/Cocoa.h> 40 #import <Cocoa/Cocoa.h>
39 #import <math.h> 41 #import <math.h>
40 42
41 // The methods in this file are specific to the Mac OS X platform. 43 // The methods in this file are specific to the Mac OS X platform.
42 44
43 // Forward declare Mac SPIs. 45 // Forward declare Mac SPIs.
44 extern "C" { 46 extern "C" {
45 void _NSDrawCarbonThemeBezel(NSRect frame, BOOL enabled, BOOL flipped); 47 void _NSDrawCarbonThemeBezel(NSRect frame, BOOL enabled, BOOL flipped);
46 // Request for public API: rdar://13787640 48 // Request for public API: rdar://13787640
47 void _NSDrawCarbonThemeListBox(NSRect frame, BOOL enabled, BOOL flipped, BOOL al ways_yes); 49 void _NSDrawCarbonThemeListBox(NSRect frame, BOOL enabled, BOOL flipped, BOOL al ways_yes);
48 } 50 }
49 51
50 namespace blink { 52 namespace blink {
51 53
52 ThemePainterMac::ThemePainterMac(LayoutThemeMac& layoutTheme, Theme* platformThe me) 54 ThemePainterMac::ThemePainterMac(LayoutThemeMac& layoutTheme)
53 : ThemePainter(platformTheme) 55 : ThemePainter()
54 , m_layoutTheme(layoutTheme) 56 , m_layoutTheme(layoutTheme)
55 { 57 {
56 } 58 }
57 59
58 bool ThemePainterMac::paintTextField(const LayoutObject& o, const PaintInfo& pai ntInfo, const IntRect& r) 60 bool ThemePainterMac::paintTextField(const LayoutObject& o, const PaintInfo& pai ntInfo, const IntRect& r)
59 { 61 {
60 LocalCurrentGraphicsContext localContext(paintInfo.context, r); 62 LocalCurrentGraphicsContext localContext(paintInfo.context, r);
61 63
62 #if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1070 64 #if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1070
63 bool useNSTextFieldCell = o.styleRef().hasAppearance() 65 bool useNSTextFieldCell = o.styleRef().hasAppearance()
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 paintInfo.context.clipOut(xPath); 549 paintInfo.context.clipOut(xPath);
548 paintInfo.context.rotate(deg2rad(-45.0)); 550 paintInfo.context.rotate(deg2rad(-45.0));
549 paintInfo.context.translate(-centerX, -centerY); 551 paintInfo.context.translate(-centerX, -centerY);
550 552
551 paintInfo.context.setFillColor(fillColor); 553 paintInfo.context.setFillColor(fillColor);
552 paintInfo.context.fillEllipse(unzoomedRect); 554 paintInfo.context.fillEllipse(unzoomedRect);
553 555
554 return false; 556 return false;
555 } 557 }
556 558
559 // FIXME: Share more code with radio buttons.
560 bool ThemePainterMac::paintCheckbox(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& zoomedRect)
561 {
562 BEGIN_BLOCK_OBJC_EXCEPTIONS
563
564 ControlStates states = LayoutTheme::controlStatesForLayoutObject(object);
565 float zoomFactor = object.styleRef().effectiveZoom();
566
567 // Determine the width and height needed for the control and prepare the cel l for painting.
568 NSButtonCell *checkboxCell = ThemeMac::checkbox(states, zoomedRect, zoomFact or);
569 GraphicsContextStateSaver stateSaver(paintInfo.context);
570
571 NSControlSize controlSize = [checkboxCell controlSize];
572 IntSize zoomedSize = ThemeMac::checkboxSizes()[controlSize];
573 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
574 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
575 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, ThemeMa c::checkboxMargins(controlSize), zoomFactor);
576
577 if (zoomFactor != 1.0f) {
578 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
579 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
580 paintInfo.context.translate(inflatedRect.x(), inflatedRect.y());
581 paintInfo.context.scale(zoomFactor, zoomFactor);
582 paintInfo.context.translate(-inflatedRect.x(), -inflatedRect.y());
583 }
584
585 LocalCurrentGraphicsContext localContext(paintInfo.context, ThemeMac::inflat eRectForFocusRing(inflatedRect));
586 NSView* view = ThemeMac::ensuredView(object.view()->frameView());
587 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view];
588 if (states & FocusControlState)
589 [checkboxCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view ];
590 [checkboxCell setControlView:nil];
591
592 END_BLOCK_OBJC_EXCEPTIONS
593 return false;
594 }
595
596 bool ThemePainterMac::paintRadio(const LayoutObject& object, const PaintInfo& pa intInfo, const IntRect& zoomedRect)
597 {
598 ControlStates states = LayoutTheme::controlStatesForLayoutObject(object);
599 float zoomFactor = object.styleRef().effectiveZoom();
600
601 // Determine the width and height needed for the control and prepare the cel l for painting.
602 NSButtonCell *radioCell = ThemeMac::radio(states, zoomedRect, zoomFactor);
603 GraphicsContextStateSaver stateSaver(paintInfo.context);
604
605 NSControlSize controlSize = [radioCell controlSize];
606 IntSize zoomedSize = ThemeMac::radioSizes()[controlSize];
607 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
608 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
609 IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, ThemeMa c::radioMargins(controlSize), zoomFactor);
610
611 if (zoomFactor != 1.0f) {
612 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
613 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
614 paintInfo.context.translate(inflatedRect.x(), inflatedRect.y());
615 paintInfo.context.scale(zoomFactor, zoomFactor);
616 paintInfo.context.translate(-inflatedRect.x(), -inflatedRect.y());
617 }
618
619 LocalCurrentGraphicsContext localContext(paintInfo.context, ThemeMac::inflat eRectForFocusRing(inflatedRect));
620 BEGIN_BLOCK_OBJC_EXCEPTIONS
621 NSView* view = ThemeMac::ensuredView(object.view()->frameView());
622 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view];
623 if (states & FocusControlState)
624 [radioCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view];
625 [radioCell setControlView:nil];
626 END_BLOCK_OBJC_EXCEPTIONS
627
628 return false;
629 }
630
631 bool ThemePainterMac::paintButton(const LayoutObject& object, const PaintInfo& p aintInfo, const IntRect& zoomedRect)
632 {
633 BEGIN_BLOCK_OBJC_EXCEPTIONS
634
635 ControlStates states = LayoutTheme::controlStatesForLayoutObject(object);
636 float zoomFactor = object.styleRef().effectiveZoom();
637
638 // Determine the width and height needed for the control and prepare the cel l for painting.
639 NSButtonCell *buttonCell = ThemeMac::button(object.styleRef().appearance(), states, zoomedRect, zoomFactor);
640 GraphicsContextStateSaver stateSaver(paintInfo.context);
641
642 NSControlSize controlSize = [buttonCell controlSize];
643 IntSize zoomedSize = ThemeMac::buttonSizes()[controlSize];
644 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain wid th, so the zoomed width can just be honored.
645 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
646 IntRect inflatedRect = zoomedRect;
647 if ([buttonCell bezelStyle] == NSRoundedBezelStyle) {
648 // Center the button within the available space.
649 if (inflatedRect.height() > zoomedSize.height()) {
650 inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomed Size.height()) / 2);
651 inflatedRect.setHeight(zoomedSize.height());
652 }
653
654 // Now inflate it to account for the shadow.
655 inflatedRect = ThemeMac::inflateRect(inflatedRect, zoomedSize, ThemeMac: :buttonMargins(controlSize), zoomFactor);
656
657 if (zoomFactor != 1.0f) {
658 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
659 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
660 paintInfo.context.translate(inflatedRect.x(), inflatedRect.y());
661 paintInfo.context.scale(zoomFactor, zoomFactor);
662 paintInfo.context.translate(-inflatedRect.x(), -inflatedRect.y());
663 }
664 }
665
666 LocalCurrentGraphicsContext localContext(paintInfo.context, ThemeMac::inflat eRectForFocusRing(inflatedRect));
667 NSView* view = ThemeMac::ensuredView(object.view()->frameView());
668
669 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
670 if (states & FocusControlState)
671 [buttonCell cr_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view];
672 [buttonCell setControlView:nil];
673
674 END_BLOCK_OBJC_EXCEPTIONS
675 return false;
676 }
677
678 static ThemeDrawState convertControlStatesToThemeDrawState(ThemeButtonKind kind, ControlStates states)
679 {
680 if (states & ReadOnlyControlState)
681 return kThemeStateUnavailableInactive;
682 if (!(states & EnabledControlState))
683 return kThemeStateUnavailableInactive;
684
685 // Do not process PressedState if !EnabledControlState or ReadOnlyControlSta te.
686 if (states & PressedControlState) {
687 if (kind == kThemeIncDecButton || kind == kThemeIncDecButtonSmall || kin d == kThemeIncDecButtonMini)
688 return states & SpinUpControlState ? kThemeStatePressedUp : kThemeSt atePressedDown;
689 return kThemeStatePressed;
690 }
691 return kThemeStateActive;
692 }
693
694 bool ThemePainterMac::paintInnerSpinButton(const LayoutObject& object, const Pai ntInfo& paintInfo, const IntRect& zoomedRect)
695 {
696 ControlStates states = LayoutTheme::controlStatesForLayoutObject(object);
697 float zoomFactor = object.styleRef().effectiveZoom();
698
699 // We don't use NSStepperCell because there are no ways to draw an
700 // NSStepperCell with the up button highlighted.
701
702 HIThemeButtonDrawInfo drawInfo;
703 drawInfo.version = 0;
704 drawInfo.state = convertControlStatesToThemeDrawState(kThemeIncDecButton, st ates);
705 drawInfo.adornment = kThemeAdornmentDefault;
706 ControlSize controlSize = ThemeMac::controlSizeFromPixelSize(ThemeMac::stepp erSizes(), zoomedRect.size(), zoomFactor);
707 if (controlSize == NSSmallControlSize)
708 drawInfo.kind = kThemeIncDecButtonSmall;
709 else if (controlSize == NSMiniControlSize)
710 drawInfo.kind = kThemeIncDecButtonMini;
711 else
712 drawInfo.kind = kThemeIncDecButton;
713
714 IntRect rect(zoomedRect);
715 GraphicsContextStateSaver stateSaver(paintInfo.context);
716 if (zoomFactor != 1.0f) {
717 rect.setWidth(rect.width() / zoomFactor);
718 rect.setHeight(rect.height() / zoomFactor);
719 paintInfo.context.translate(rect.x(), rect.y());
720 paintInfo.context.scale(zoomFactor, zoomFactor);
721 paintInfo.context.translate(-rect.x(), -rect.y());
722 }
723 CGRect bounds(rect);
724 CGRect backgroundBounds;
725 HIThemeGetButtonBackgroundBounds(&bounds, &drawInfo, &backgroundBounds);
726 // Center the stepper rectangle in the specified area.
727 backgroundBounds.origin.x = bounds.origin.x + (bounds.size.width - backgroun dBounds.size.width) / 2;
728 if (backgroundBounds.size.height < bounds.size.height) {
729 int heightDiff = clampTo<int>(bounds.size.height - backgroundBounds.size .height);
730 backgroundBounds.origin.y = bounds.origin.y + (heightDiff / 2) + 1;
731 }
732
733 LocalCurrentGraphicsContext localContext(paintInfo.context, rect);
734 HIThemeDrawButton(&backgroundBounds, &drawInfo, localContext.cgContext(), kH IThemeOrientationNormal, 0);
735 return false;
736 }
737
738
557 } // namespace blink 739 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/ThemePainterMac.h ('k') | third_party/WebKit/Source/platform/mac/ThemeMac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698