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

Side by Side Diff: content/shell/renderer/test_runner/mock_web_theme_engine_mac.mm

Issue 647223002: Remove unused paintScrollbarThumb impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
(Empty)
1 // Copyright 2014 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 #include "content/shell/renderer/test_runner/mock_web_theme_engine_mac.h"
6
7 #import <AppKit/NSAffineTransform.h>
8 #import <AppKit/NSGraphicsContext.h>
9 #import <AppKit/NSScroller.h>
10 #import <AppKit/NSWindow.h>
11 #include <Carbon/Carbon.h>
12 #include "skia/ext/skia_utils_mac.h"
13 #include "third_party/WebKit/public/platform/WebCanvas.h"
14 #include "third_party/WebKit/public/platform/WebRect.h"
15
16 using blink::WebCanvas;
17 using blink::WebRect;
18 using blink::WebThemeEngine;
19
20 // We can't directly tell the NSScroller to draw itself as active or inactive,
21 // instead we have to make it a child of an (in)active window. This class lets
22 // us fake that parent window.
23 @interface FakeActiveWindow : NSWindow {
24 @private
25 BOOL hasActiveControls;
26 }
27 + (NSWindow*)alwaysActiveWindow;
28 + (NSWindow*)alwaysInactiveWindow;
29 - (id)initWithActiveControls:(BOOL)_hasActiveControls;
30 - (BOOL)_hasActiveControls;
31 @end
32
33 @implementation FakeActiveWindow
34
35 static NSWindow* alwaysActiveWindow = nil;
36 static NSWindow* alwaysInactiveWindow = nil;
37
38 + (NSWindow*)alwaysActiveWindow {
39 if (alwaysActiveWindow == nil)
40 alwaysActiveWindow = [[self alloc] initWithActiveControls:YES];
41 return alwaysActiveWindow;
42 }
43
44 + (NSWindow*)alwaysInactiveWindow {
45 if (alwaysInactiveWindow == nil)
46 alwaysInactiveWindow = [[self alloc] initWithActiveControls:NO];
47 return alwaysInactiveWindow;
48 }
49
50 - (id)initWithActiveControls:(BOOL)_hasActiveControls {
51 if ((self = [super initWithContentRect:NSMakeRect(0, 0, 100, 100)
52 styleMask:0
53 backing:NSBackingStoreBuffered
54 defer:YES])) {
55 hasActiveControls = _hasActiveControls;
56 }
57 return self;
58 }
59
60 - (BOOL)_hasActiveControls
61 {
62 return hasActiveControls;
63 }
64
65 @end
66
67 namespace content {
68
69 namespace {
70
71 ThemeTrackEnableState stateToHIEnableState(WebThemeEngine::State state) {
72 switch (state) {
73 case WebThemeEngine::StateDisabled:
74 return kThemeTrackDisabled;
75 case WebThemeEngine::StateInactive:
76 return kThemeTrackInactive;
77 default:
78 return kThemeTrackActive;
79 }
80 }
81
82 } // namespace
83
84 void MockWebThemeEngineMac::paintScrollbarThumb(
85 WebCanvas* canvas,
86 WebThemeEngine::State state,
87 WebThemeEngine::Size size,
88 const WebRect& rect,
89 const WebThemeEngine::ScrollbarInfo& scrollbarInfo) {
90 // To match the Mac port, we still use HITheme for inner scrollbars.
91 if (scrollbarInfo.parent == WebThemeEngine::ScrollbarParentRenderLayer)
92 paintHIThemeScrollbarThumb(canvas, state, size, rect, scrollbarInfo);
93 else
94 paintNSScrollerScrollbarThumb(canvas, state, size, rect, scrollbarInfo);
95 }
96
97 // Duplicated from webkit/glue/webthemeengine_impl_mac.cc in the downstream
98 // Chromium WebThemeEngine implementation.
99 void MockWebThemeEngineMac::paintHIThemeScrollbarThumb(
100 WebCanvas* canvas,
101 WebThemeEngine::State state,
102 WebThemeEngine::Size size,
103 const WebRect& rect,
104 const WebThemeEngine::ScrollbarInfo& scrollbarInfo) {
105 HIThemeTrackDrawInfo trackInfo;
106 trackInfo.version = 0;
107 trackInfo.kind = size == WebThemeEngine::SizeRegular ? kThemeMediumScrollBar : kThemeSmallScrollBar;
108 trackInfo.bounds = CGRectMake(rect.x, rect.y, rect.width, rect.height);
109 trackInfo.min = 0;
110 trackInfo.max = scrollbarInfo.maxValue;
111 trackInfo.value = scrollbarInfo.currentValue;
112 trackInfo.trackInfo.scrollbar.viewsize = scrollbarInfo.visibleSize;
113 trackInfo.attributes = 0;
114 if (scrollbarInfo.orientation == WebThemeEngine::ScrollbarOrientationHorizon tal)
115 trackInfo.attributes |= kThemeTrackHorizontal;
116
117 trackInfo.enableState = stateToHIEnableState(state);
118
119 trackInfo.trackInfo.scrollbar.pressState =
120 state == WebThemeEngine::StatePressed ? kThemeThumbPressed : 0;
121 trackInfo.attributes |= (kThemeTrackShowThumb | kThemeTrackHideTrack);
122 gfx::SkiaBitLocker bitLocker(canvas);
123 CGContextRef cgContext = bitLocker.cgContext();
124 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal);
125 }
126
127 void MockWebThemeEngineMac::paintNSScrollerScrollbarThumb(
128 WebCanvas* canvas,
129 WebThemeEngine::State state,
130 WebThemeEngine::Size size,
131 const WebRect& rect,
132 const WebThemeEngine::ScrollbarInfo& scrollbarInfo) {
133 [NSGraphicsContext saveGraphicsState];
134 NSScroller* scroller = [[NSScroller alloc] initWithFrame:NSMakeRect(rect.x, rect.y, rect.width, rect.height)];
135 [scroller setEnabled:state != WebThemeEngine::StateDisabled];
136 if (state == WebThemeEngine::StateInactive)
137 [[[FakeActiveWindow alwaysInactiveWindow] contentView] addSubview:scroll er];
138 else
139 [[[FakeActiveWindow alwaysActiveWindow] contentView] addSubview:scroller ];
140
141 [scroller setControlSize:size == WebThemeEngine::SizeRegular ? NSRegularCont rolSize : NSSmallControlSize];
142
143 double value = double(scrollbarInfo.currentValue) / double(scrollbarInfo.max Value);
144 [scroller setDoubleValue: value];
145
146 float knobProportion = float(scrollbarInfo.visibleSize) / float(scrollbarInf o.totalSize);
147 [scroller setKnobProportion: knobProportion];
148
149 gfx::SkiaBitLocker bitLocker(canvas);
150 CGContextRef cgContext = bitLocker.cgContext();
151 NSGraphicsContext* nsGraphicsContext = [NSGraphicsContext graphicsContextWit hGraphicsPort:cgContext flipped:YES];
152 [NSGraphicsContext setCurrentContext:nsGraphicsContext];
153
154 // Despite passing in frameRect() to the scroller, it always draws at (0, 0) .
155 // Force it to draw in the right location by translating the whole graphics
156 // context.
157 CGContextSaveGState(cgContext);
158 NSAffineTransform *transform = [NSAffineTransform transform];
159 [transform translateXBy:rect.x yBy:rect.y];
160 [transform concat];
161
162 [scroller drawKnob];
163 CGContextRestoreGState(cgContext);
164
165 [scroller release];
166
167 [NSGraphicsContext restoreGraphicsState];
168 }
169
170 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/mock_web_theme_engine_mac.h ('k') | content/shell/renderer/test_runner/test_interfaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698