Skip to content

Commit d8ec016

Browse files
committed
2010-12-30 Mihai Parparita <mihaip@chromium.org>
Reviewed by Kent Tamura. [Chromium] Add WebThemeEngineDRTMac so that Chromium DRT scrollbar rendering can match the Mac port's https://bugs.webkit.org/show_bug.cgi?id=51728 Add implementation of the Mac WebThemeEngine that uses an NSScroller to render top-level scrollbars. This makes them match the Mac port's use of an NSScrollView, which means that we'll be able to share more pixel baselines. The new rendering code will not be activated until the USE_WEB_THEME_ENGINE_TO_PAINT_THUMB #define is fliped in ScrollbarThemeChromiumMac. * DumpRenderTree/DumpRenderTree.gypi: * DumpRenderTree/chromium/TestShellMac.mm: (platformInit): * DumpRenderTree/chromium/WebThemeEngineDRTMac.h: Added. * DumpRenderTree/chromium/WebThemeEngineDRTMac.mm: Added. (+[FakeActiveWindow alwaysActiveWindow]): (+[FakeActiveWindow alwaysInactiveWindow]): (-[FakeActiveWindow initWithActiveControls:]): (-[FakeActiveWindow _hasActiveControls]): (WebThemeEngineDRTMac::paintScrollbarThumb): (stateToHIEnableState): (WebThemeEngineDRTMac::paintHIThemeScrollbarThumb): (WebThemeEngineDRTMac::paintNSScrollerScrollbarThumb): 2010-12-30 Mihai Parparita <mihaip@chromium.org> Reviewed by Kent Tamura. [Chromium] Add WebThemeEngineDRTMac so that Chromium DRT scrollbar rendering can match the Mac port's https://bugs.webkit.org/show_bug.cgi?id=51728 Roll DEPS to pick up WebThemeEngine changes. * DEPS: Canonical link: https://commits.webkit.org/65160@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@74821 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 5762573 commit d8ec016

7 files changed

Lines changed: 296 additions & 1 deletion

File tree

Tools/ChangeLog

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
2010-12-30 Mihai Parparita <mihaip@chromium.org>
2+
3+
Reviewed by Kent Tamura.
4+
5+
[Chromium] Add WebThemeEngineDRTMac so that Chromium DRT scrollbar rendering can match the Mac port's
6+
https://bugs.webkit.org/show_bug.cgi?id=51728
7+
8+
Add implementation of the Mac WebThemeEngine that uses an NSScroller
9+
to render top-level scrollbars. This makes them match the Mac port's
10+
use of an NSScrollView, which means that we'll be able to share more
11+
pixel baselines.
12+
13+
The new rendering code will not be activated until the
14+
USE_WEB_THEME_ENGINE_TO_PAINT_THUMB #define is fliped in
15+
ScrollbarThemeChromiumMac.
16+
17+
* DumpRenderTree/DumpRenderTree.gypi:
18+
* DumpRenderTree/chromium/TestShellMac.mm:
19+
(platformInit):
20+
* DumpRenderTree/chromium/WebThemeEngineDRTMac.h: Added.
21+
* DumpRenderTree/chromium/WebThemeEngineDRTMac.mm: Added.
22+
(+[FakeActiveWindow alwaysActiveWindow]):
23+
(+[FakeActiveWindow alwaysInactiveWindow]):
24+
(-[FakeActiveWindow initWithActiveControls:]):
25+
(-[FakeActiveWindow _hasActiveControls]):
26+
(WebThemeEngineDRTMac::paintScrollbarThumb):
27+
(stateToHIEnableState):
28+
(WebThemeEngineDRTMac::paintHIThemeScrollbarThumb):
29+
(WebThemeEngineDRTMac::paintNSScrollerScrollbarThumb):
30+
131
2010-12-30 Konstantin Tokarev <annulen@yandex.ru>
232

333
Reviewed by David Kilzer.

Tools/DumpRenderTree/DumpRenderTree.gypi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
'chromium/WebThemeEngineDRTWin.h',
6868
],
6969
}],
70+
['OS=="mac"', {
71+
'drt_files': [
72+
'chromium/WebThemeEngineDRTMac.mm',
73+
'chromium/WebThemeEngineDRTMac.h',
74+
],
75+
}],
7076
],
7177
}
7278
}

Tools/DumpRenderTree/chromium/TestShellMac.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
#include "config.h"
3232

3333
#include "TestShell.h"
34+
#include "WebThemeEngineDRTMac.h"
3435
#include "webkit/support/webkit_support.h"
3536
#import <AppKit/AppKit.h>
3637

38+
static WebThemeEngineDRTMac themeEngine;
39+
3740
// A class to be the target/selector of the "watchdog" thread that ensures
3841
// pages timeout if they take too long and tells the test harness via stdout.
3942
@interface WatchDogTarget : NSObject {
@@ -126,6 +129,7 @@ - (void)run:(id)ignore
126129

127130
void platformInit(int*, char***)
128131
{
132+
webkit_support::SetThemeEngine(&themeEngine);
129133
}
130134

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

WebKit/chromium/ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2010-12-30 Mihai Parparita <mihaip@chromium.org>
2+
3+
Reviewed by Kent Tamura.
4+
5+
[Chromium] Add WebThemeEngineDRTMac so that Chromium DRT scrollbar rendering can match the Mac port's
6+
https://bugs.webkit.org/show_bug.cgi?id=51728
7+
8+
Roll DEPS to pick up WebThemeEngine changes.
9+
10+
* DEPS:
11+
112
2010-12-29 Sheriff Bot <webkit.review.bot@gmail.com>
213

314
Unreviewed, rolling out r74735.

WebKit/chromium/DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
vars = {
3434
'chromium_svn': 'http://src.chromium.org/svn/trunk/src',
35-
'chromium_rev': '68558'
35+
'chromium_rev': '70319'
3636
}
3737

3838
deps = {

0 commit comments

Comments
 (0)