initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderThemeChromiumMac.mm
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 "PlatformSupport.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 PlatformSupport::layoutTestMode();
75 }
76
77 NSView* RenderThemeChromiumMac::documentViewFor(RenderObject*) const
78 {
79     return FlippedView();
80 }
81
82 const int autofillPopupHorizontalPadding = 4;
83
84 // These functions are called with MenuListPart or MenulistButtonPart appearance by RenderMenuList, or with TextFieldPart appearance by AutofillPopupMenuClient.
85 // We assume only AutofillPopupMenuClient gives TexfieldPart appearance here.
86 // We want to change only Autofill padding.
87 // In the future, we have to separate Autofill popup window logic from WebKit to Chromium.
88 int RenderThemeChromiumMac::popupInternalPaddingLeft(RenderStyle* style) const
89 {
90     if (style->appearance() == TextFieldPart)
91         return autofillPopupHorizontalPadding;
92
93     return RenderThemeMac::popupInternalPaddingLeft(style);
94 }
95
96 int RenderThemeChromiumMac::popupInternalPaddingRight(RenderStyle* style) const
97 {
98     if (style->appearance() == TextFieldPart)
99         return autofillPopupHorizontalPadding;
100
101     return RenderThemeMac::popupInternalPaddingRight(style);
102 }
103
104 // Updates the control tint (a.k.a. active state) of |cell| (from |o|).
105 // In the Chromium port, the renderer runs as a background process and controls'
106 // NSCell(s) lack a parent NSView. Therefore controls don't have their tint
107 // color updated correctly when the application is activated/deactivated.
108 // FocusController's setActive() is called when the application is
109 // activated/deactivated, which causes a repaint at which time this code is
110 // called.
111 // This function should be called before drawing any NSCell-derived controls,
112 // unless you're sure it isn't needed.
113 void RenderThemeChromiumMac::updateActiveState(NSCell* cell, const RenderObject* o)
114 {
115     NSControlTint oldTint = [cell controlTint];
116     NSControlTint tint = isActive(o) ? [NSColor currentControlTint] :
117                                        static_cast<NSControlTint>(NSClearControlTint);
118
119     if (tint != oldTint)
120         [cell setControlTint:tint];
121 }
122
123 #if ENABLE(VIDEO)
124
125 void RenderThemeChromiumMac::adjustMediaSliderThumbSize(RenderStyle* style) const
126 {
127     RenderMediaControlsChromium::adjustMediaSliderThumbSize(style);
128 }
129
130 bool RenderThemeChromiumMac::paintMediaPlayButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
131 {
132     return RenderMediaControlsChromium::paintMediaControlsPart(MediaPlayButton, object, paintInfo, rect);
133 }
134
135 bool RenderThemeChromiumMac::paintMediaMuteButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
136 {
137     return RenderMediaControlsChromium::paintMediaControlsPart(MediaMuteButton, object, paintInfo, rect);
138 }
139
140 bool RenderThemeChromiumMac::paintMediaSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
141 {
142     return RenderMediaControlsChromium::paintMediaControlsPart(MediaSlider, object, paintInfo, rect);
143 }
144
145 bool RenderThemeChromiumMac::paintMediaControlsBackground(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
146 {
147     return RenderMediaControlsChromium::paintMediaControlsPart(MediaTimelineContainer, object, paintInfo, rect);
148 }
149
150 String RenderThemeChromiumMac::extraMediaControlsStyleSheet()
151 {
152     return String(mediaControlsChromiumUserAgentStyleSheet, sizeof(mediaControlsChromiumUserAgentStyleSheet));
153 }
154
155 #if ENABLE(FULLSCREEN_API)
156 String RenderThemeChromiumMac::extraFullScreenStyleSheet()
157 {
158     // FIXME: Chromium may wish to style its default media controls differently in fullscreen.
159     return String();
160 }
161 #endif
162
163 String RenderThemeChromiumMac::extraDefaultStyleSheet()
164 {
165     return RenderThemeMac::extraDefaultStyleSheet() +
166            String(themeChromiumUserAgentStyleSheet, sizeof(themeChromiumUserAgentStyleSheet));
167 }
168
169
170 bool RenderThemeChromiumMac::paintMediaVolumeSliderContainer(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
171 {
172     return true;
173 }
174
175 bool RenderThemeChromiumMac::paintMediaVolumeSliderTrack(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
176 {
177     return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSlider, object, paintInfo, rect);
178 }
179
180 bool RenderThemeChromiumMac::paintMediaVolumeSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
181 {
182     return RenderMediaControlsChromium::paintMediaControlsPart(MediaVolumeSliderThumb, object, paintInfo, rect);
183 }
184
185 bool RenderThemeChromiumMac::paintMediaSliderThumb(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
186 {
187     return RenderMediaControlsChromium::paintMediaControlsPart(MediaSliderThumb, object, paintInfo, rect);
188 }
189
190 IntPoint RenderThemeChromiumMac::volumeSliderOffsetFromMuteButton(RenderBox* muteButtonBox, const IntSize& size) const
191 {
192     return RenderTheme::volumeSliderOffsetFromMuteButton(muteButtonBox, size);
193 }
194 #endif
195
196 } // namespace WebCore