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

Side by Side Diff: content/test/layout_tests/runner/WebTestThemeEngineMac.mm

Issue 110533009: Import TestRunner library into chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years 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
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /*
6 * Copyright (C) 2010 Google Inc. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Google Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include "content/test/layout_tests/runner/WebTestThemeEngineMac.h"
36
37 #include "third_party/WebKit/public/platform/WebCanvas.h"
38 #include "third_party/WebKit/public/platform/WebRect.h"
39 #include "skia/ext/skia_utils_mac.h"
40 #import <AppKit/NSAffineTransform.h>
41 #import <AppKit/NSGraphicsContext.h>
42 #import <AppKit/NSScroller.h>
43 #import <AppKit/NSWindow.h>
44 #include <Carbon/Carbon.h>
45
46 using blink::WebCanvas;
47 using blink::WebRect;
48 using blink::WebThemeEngine;
49
50 // We can't directly tell the NSScroller to draw itself as active or inactive,
51 // instead we have to make it a child of an (in)active window. This class lets
52 // us fake that parent window.
53 @interface FakeActiveWindow : NSWindow {
54 @private
55 BOOL hasActiveControls;
56 }
57 + (NSWindow*)alwaysActiveWindow;
58 + (NSWindow*)alwaysInactiveWindow;
59 - (id)initWithActiveControls:(BOOL)_hasActiveControls;
60 - (BOOL)_hasActiveControls;
61 @end
62
63 @implementation FakeActiveWindow
64
65 static NSWindow* alwaysActiveWindow = nil;
66 static NSWindow* alwaysInactiveWindow = nil;
67
68 + (NSWindow*)alwaysActiveWindow
69 {
70 if (alwaysActiveWindow == nil)
71 alwaysActiveWindow = [[self alloc] initWithActiveControls:YES];
72 return alwaysActiveWindow;
73 }
74
75 + (NSWindow*)alwaysInactiveWindow
76 {
77 if (alwaysInactiveWindow == nil)
78 alwaysInactiveWindow = [[self alloc] initWithActiveControls:NO];
79 return alwaysInactiveWindow;
80 }
81
82 - (id)initWithActiveControls:(BOOL)_hasActiveControls
83 {
84 self = [super init];
85 hasActiveControls = _hasActiveControls;
86 return self;
87 }
88
89 - (BOOL)_hasActiveControls
90 {
91 return hasActiveControls;
92 }
93
94 @end
95
96 namespace WebTestRunner {
97
98 namespace {
99
100 ThemeTrackEnableState stateToHIEnableState(WebThemeEngine::State state)
101 {
102 switch (state) {
103 case WebThemeEngine::StateDisabled:
104 return kThemeTrackDisabled;
105 case WebThemeEngine::StateInactive:
106 return kThemeTrackInactive;
107 default:
108 return kThemeTrackActive;
109 }
110 }
111
112 }
113
114 void WebTestThemeEngineMac::paintScrollbarThumb(
115 WebCanvas* canvas,
116 WebThemeEngine::State state,
117 WebThemeEngine::Size size,
118 const WebRect& rect,
119 const WebThemeEngine::ScrollbarInfo& scrollbarInfo)
120 {
121 // To match the Mac port, we still use HITheme for inner scrollbars.
122 if (scrollbarInfo.parent == WebThemeEngine::ScrollbarParentRenderLayer)
123 paintHIThemeScrollbarThumb(canvas, state, size, rect, scrollbarInfo);
124 else
125 paintNSScrollerScrollbarThumb(canvas, state, size, rect, scrollbarInfo);
126 }
127
128 // Duplicated from webkit/glue/webthemeengine_impl_mac.cc in the downstream
129 // Chromium WebThemeEngine implementation.
130 void WebTestThemeEngineMac::paintHIThemeScrollbarThumb(
131 WebCanvas* canvas,
132 WebThemeEngine::State state,
133 WebThemeEngine::Size size,
134 const WebRect& rect,
135 const WebThemeEngine::ScrollbarInfo& scrollbarInfo)
136 {
137 HIThemeTrackDrawInfo trackInfo;
138 trackInfo.version = 0;
139 trackInfo.kind = size == WebThemeEngine::SizeRegular ? kThemeMediumScrollBar : kThemeSmallScrollBar;
140 trackInfo.bounds = CGRectMake(rect.x, rect.y, rect.width, rect.height);
141 trackInfo.min = 0;
142 trackInfo.max = scrollbarInfo.maxValue;
143 trackInfo.value = scrollbarInfo.currentValue;
144 trackInfo.trackInfo.scrollbar.viewsize = scrollbarInfo.visibleSize;
145 trackInfo.attributes = 0;
146 if (scrollbarInfo.orientation == WebThemeEngine::ScrollbarOrientationHorizon tal)
147 trackInfo.attributes |= kThemeTrackHorizontal;
148
149 trackInfo.enableState = stateToHIEnableState(state);
150
151 trackInfo.trackInfo.scrollbar.pressState =
152 state == WebThemeEngine::StatePressed ? kThemeThumbPressed : 0;
153 trackInfo.attributes |= (kThemeTrackShowThumb | kThemeTrackHideTrack);
154 gfx::SkiaBitLocker bitLocker(canvas);
155 CGContextRef cgContext = bitLocker.cgContext();
156 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal);
157 }
158
159 void WebTestThemeEngineMac::paintNSScrollerScrollbarThumb(
160 WebCanvas* canvas,
161 WebThemeEngine::State state,
162 WebThemeEngine::Size size,
163 const WebRect& rect,
164 const WebThemeEngine::ScrollbarInfo& scrollbarInfo)
165 {
166 [NSGraphicsContext saveGraphicsState];
167 NSScroller* scroller = [[NSScroller alloc] initWithFrame:NSMakeRect(rect.x, rect.y, rect.width, rect.height)];
168 [scroller setEnabled:state != WebThemeEngine::StateDisabled];
169 if (state == WebThemeEngine::StateInactive)
170 [[[FakeActiveWindow alwaysInactiveWindow] contentView] addSubview:scroll er];
171 else
172 [[[FakeActiveWindow alwaysActiveWindow] contentView] addSubview:scroller ];
173
174 [scroller setControlSize:size == WebThemeEngine::SizeRegular ? NSRegularCont rolSize : NSSmallControlSize];
175
176 double value = double(scrollbarInfo.currentValue) / double(scrollbarInfo.max Value);
177 [scroller setDoubleValue: value];
178
179 float knobProportion = float(scrollbarInfo.visibleSize) / float(scrollbarInf o.totalSize);
180 [scroller setKnobProportion: knobProportion];
181
182 gfx::SkiaBitLocker bitLocker(canvas);
183 CGContextRef cgContext = bitLocker.cgContext();
184 NSGraphicsContext* nsGraphicsContext = [NSGraphicsContext graphicsContextWit hGraphicsPort:cgContext flipped:YES];
185 [NSGraphicsContext setCurrentContext:nsGraphicsContext];
186
187 // Despite passing in frameRect() to the scroller, it always draws at (0, 0) .
188 // Force it to draw in the right location by translating the whole graphics
189 // context.
190 CGContextSaveGState(cgContext);
191 NSAffineTransform *transform = [NSAffineTransform transform];
192 [transform translateXBy:rect.x yBy:rect.y];
193 [transform concat];
194
195 [scroller drawKnob];
196 CGContextRestoreGState(cgContext);
197
198 [scroller release];
199
200 [NSGraphicsContext restoreGraphicsState];
201 }
202
203 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698