Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
      3  * Copyright (C) 2008, 2009 Google, Inc.
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     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
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  */
     20 
     21 #import "config.h"
     22 #import "RenderThemeChromiumMac.h"
     23 #import "PaintInfo.h"
     24 #import "PlatformBridge.h"
     25 #import "RenderMediaControlsChromium.h"
     26 #import "UserAgentStyleSheets.h"
     27 #import <Carbon/Carbon.h>
     28 #import <Cocoa/Cocoa.h>
     29 #import <wtf/RetainPtr.h>
     30 #import <wtf/StdLibExtras.h>
     31 #import <math.h>
     32 
     33 @interface RTCMFlippedView : NSView
     34 {}
     35 
     36 - (BOOL)isFlipped;
     37 - (NSText *)currentEditor;
     38 
     39 @end
     40 
     41 @implementation RTCMFlippedView
     42 
     43 - (BOOL)isFlipped {
     44     return [[NSGraphicsContext currentContext] isFlipped];
     45 }
     46 
     47 - (NSText *)currentEditor {
     48     return nil;
     49 }
     50 
     51 @end
     52 
     53 namespace WebCore {
     54 
     55 NSView* FlippedView()
     56 {
     57     static NSView* view = [[RTCMFlippedView alloc] init];
     58     return view;
     59 }
     60 
     61 PassRefPtr<RenderTheme> RenderTheme::themeForPage(Page*)
     62 {
     63     static RenderTheme* rt = RenderThemeChromiumMac::create().releaseRef();
     64     return rt;
     65 }
     66 
     67 PassRefPtr<RenderTheme> RenderThemeChromiumMac::create()
     68 {
     69     return adoptRef(new RenderThemeChromiumMac);
     70 }
     71 
     72 bool RenderThemeChromiumMac::usesTestModeFocusRingColor() const
     73 {
     74     return PlatformBridge::layoutTestMode();
     75 }
     76 
     77 NSView* RenderThemeChromiumMac::documentViewFor(RenderObject*) const
     78 {
     79     return FlippedView();
     80 }
     81 
     82 // Updates the control tint (a.k.a. active state) of |cell| (from |o|).
     83 // In the Chromium port, the renderer runs as a background process and controls'
     84 // NSCell(s) lack a parent NSView. Therefore controls don't have their tint
     85 // color updated correctly when the application is activated/deactivated.
     86 // FocusController's setActive() is called when the application is
     87 // activated/deactivated, which causes a repaint at which time this code is
     88 // called.
     89 // This function should be called before drawing any NSCell-derived controls,
     90 // unless you're sure it isn't needed.
     91 void RenderThemeChromiumMac::updateActiveState(NSCell* cell, const RenderObject* o)
     92 {
     93     NSControlTint oldTint = [cell controlTint];
     94     NSControlTint tint = isActive(o) ? [NSColor currentControlTint] :
     95                                        static_cast<NSControlTint>(NSClearControlTint);
     96 
     97     if (tint != oldTint)
     98         [cell setControlTint:tint];
     99 }
    100 
    101 #if ENABLE(VIDEO)
    102 
    103 void RenderThemeChromiumMac::adjustMediaSliderThumbSize(RenderObject* o) const
    104 {
    105     RenderMediaControlsChromium::adjustMediaSliderThumbSize(o);
    106 }
    107 
    108 bool RenderThemeChromiumMac::paintMediaPlayButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
    109 {
    110     return RenderMediaControlsChromium::paintMediaControlsPart(MediaPlayButton, object, paintInfo, rect);
    111 }
    112 
    113 bool RenderThemeChromiumMac::paintMediaMuteButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
    114 {
    115     return RenderMediaControlsChromium::paintMediaControlsPart(MediaMuteButton, object, paintInfo, rect);
    116 }
    117 
    118 bool RenderThemeChromiumMac::paintMediaSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
    119 {
    120     return RenderMediaControlsChromium::paintMediaControlsPart(MediaSlider, object, paintInfo, rect);
    121 }
    122 
    123 bool RenderThemeChromiumMac::paintMediaControlsBackground(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
    124 {
    125     return RenderMediaControlsChromium::paintMediaControlsPart(MediaTimelineContainer, object, paintInfo, rect);
    126 }
    127 
    128 String RenderThemeChromiumMac::extraMediaControlsStyleSheet()
    129 {
    130     return String(mediaControlsChromiumUserAgentStyleSheet, sizeof(mediaControlsChromiumUserAgentStyleSheet));
    131 }
    132 
    133 #if ENABLE(FULLSCREEN_API)
    134 String RenderThemeChromiumMac::extraFullScreenStyleSheet()
    135 {
    136     // FIXME: Chromium may wish to style its default media controls differently in fullscreen.
    137     return String();
    138 }
    139 #endif
    140 
    141 bool RenderThemeChromiumMac::paintMediaVolumeSliderContainer(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
    142 {
    143     return true;
    144 }
    145 
    146 bool RenderThemeChromiumMac::paintMediaVolumeSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
    147 {
    148     return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSlider, object, paintInfo, rect);
    149 }
    150 
    151 bool RenderThemeChromiumMac::paintMediaVolumeSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
    152 {
    153     return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSliderThumb, object, paintInfo, rect);
    154 }
    155 
    156 bool RenderThemeChromiumMac::paintMediaSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
    157 {
    158     return RenderMediaControlsChromium::paintMediaControlsPart(MediaSliderThumb, object, paintInfo, rect);
    159 }
    160 
    161 IntPoint RenderThemeChromiumMac::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
    162 {
    163     return RenderTheme::volumeSliderOffsetFromMuteButton(muteButtonBox, size);
    164 }
    165 #endif
    166 
    167 } // namespace WebCore
    168