| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/shell/renderer/test_runner/WebTestThemeEngineMac.h" | 5 #include "content/shell/renderer/test_runner/mock_web_theme_engine_mac.h" |
| 6 | 6 |
| 7 #import <AppKit/NSAffineTransform.h> | 7 #import <AppKit/NSAffineTransform.h> |
| 8 #import <AppKit/NSGraphicsContext.h> | 8 #import <AppKit/NSGraphicsContext.h> |
| 9 #import <AppKit/NSScroller.h> | 9 #import <AppKit/NSScroller.h> |
| 10 #import <AppKit/NSWindow.h> | 10 #import <AppKit/NSWindow.h> |
| 11 #include <Carbon/Carbon.h> | 11 #include <Carbon/Carbon.h> |
| 12 #include "skia/ext/skia_utils_mac.h" | 12 #include "skia/ext/skia_utils_mac.h" |
| 13 #include "third_party/WebKit/public/platform/WebCanvas.h" | 13 #include "third_party/WebKit/public/platform/WebCanvas.h" |
| 14 #include "third_party/WebKit/public/platform/WebRect.h" | 14 #include "third_party/WebKit/public/platform/WebRect.h" |
| 15 | 15 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 28 + (NSWindow*)alwaysInactiveWindow; | 28 + (NSWindow*)alwaysInactiveWindow; |
| 29 - (id)initWithActiveControls:(BOOL)_hasActiveControls; | 29 - (id)initWithActiveControls:(BOOL)_hasActiveControls; |
| 30 - (BOOL)_hasActiveControls; | 30 - (BOOL)_hasActiveControls; |
| 31 @end | 31 @end |
| 32 | 32 |
| 33 @implementation FakeActiveWindow | 33 @implementation FakeActiveWindow |
| 34 | 34 |
| 35 static NSWindow* alwaysActiveWindow = nil; | 35 static NSWindow* alwaysActiveWindow = nil; |
| 36 static NSWindow* alwaysInactiveWindow = nil; | 36 static NSWindow* alwaysInactiveWindow = nil; |
| 37 | 37 |
| 38 + (NSWindow*)alwaysActiveWindow | 38 + (NSWindow*)alwaysActiveWindow { |
| 39 { | |
| 40 if (alwaysActiveWindow == nil) | 39 if (alwaysActiveWindow == nil) |
| 41 alwaysActiveWindow = [[self alloc] initWithActiveControls:YES]; | 40 alwaysActiveWindow = [[self alloc] initWithActiveControls:YES]; |
| 42 return alwaysActiveWindow; | 41 return alwaysActiveWindow; |
| 43 } | 42 } |
| 44 | 43 |
| 45 + (NSWindow*)alwaysInactiveWindow | 44 + (NSWindow*)alwaysInactiveWindow { |
| 46 { | |
| 47 if (alwaysInactiveWindow == nil) | 45 if (alwaysInactiveWindow == nil) |
| 48 alwaysInactiveWindow = [[self alloc] initWithActiveControls:NO]; | 46 alwaysInactiveWindow = [[self alloc] initWithActiveControls:NO]; |
| 49 return alwaysInactiveWindow; | 47 return alwaysInactiveWindow; |
| 50 } | 48 } |
| 51 | 49 |
| 52 - (id)initWithActiveControls:(BOOL)_hasActiveControls | 50 - (id)initWithActiveControls:(BOOL)_hasActiveControls { |
| 53 { | |
| 54 if ((self = [super initWithContentRect:NSMakeRect(0, 0, 100, 100) | 51 if ((self = [super initWithContentRect:NSMakeRect(0, 0, 100, 100) |
| 55 styleMask:0 | 52 styleMask:0 |
| 56 backing:NSBackingStoreBuffered | 53 backing:NSBackingStoreBuffered |
| 57 defer:YES])) { | 54 defer:YES])) { |
| 58 hasActiveControls = _hasActiveControls; | 55 hasActiveControls = _hasActiveControls; |
| 59 } | 56 } |
| 60 return self; | 57 return self; |
| 61 } | 58 } |
| 62 | 59 |
| 63 - (BOOL)_hasActiveControls | 60 - (BOOL)_hasActiveControls |
| 64 { | 61 { |
| 65 return hasActiveControls; | 62 return hasActiveControls; |
| 66 } | 63 } |
| 67 | 64 |
| 68 @end | 65 @end |
| 69 | 66 |
| 70 namespace content { | 67 namespace content { |
| 71 | 68 |
| 72 namespace { | 69 namespace { |
| 73 | 70 |
| 74 ThemeTrackEnableState stateToHIEnableState(WebThemeEngine::State state) | 71 ThemeTrackEnableState stateToHIEnableState(WebThemeEngine::State state) { |
| 75 { | 72 switch (state) { |
| 76 switch (state) { | |
| 77 case WebThemeEngine::StateDisabled: | 73 case WebThemeEngine::StateDisabled: |
| 78 return kThemeTrackDisabled; | 74 return kThemeTrackDisabled; |
| 79 case WebThemeEngine::StateInactive: | 75 case WebThemeEngine::StateInactive: |
| 80 return kThemeTrackInactive; | 76 return kThemeTrackInactive; |
| 81 default: | 77 default: |
| 82 return kThemeTrackActive; | 78 return kThemeTrackActive; |
| 83 } | 79 } |
| 84 } | 80 } |
| 85 | 81 |
| 86 } // namespace | 82 } // namespace |
| 87 | 83 |
| 88 void WebTestThemeEngineMac::paintScrollbarThumb( | 84 void MockWebThemeEngineMac::paintScrollbarThumb( |
| 89 WebCanvas* canvas, | 85 WebCanvas* canvas, |
| 90 WebThemeEngine::State state, | 86 WebThemeEngine::State state, |
| 91 WebThemeEngine::Size size, | 87 WebThemeEngine::Size size, |
| 92 const WebRect& rect, | 88 const WebRect& rect, |
| 93 const WebThemeEngine::ScrollbarInfo& scrollbarInfo) | 89 const WebThemeEngine::ScrollbarInfo& scrollbarInfo) { |
| 94 { | |
| 95 // To match the Mac port, we still use HITheme for inner scrollbars. | 90 // To match the Mac port, we still use HITheme for inner scrollbars. |
| 96 if (scrollbarInfo.parent == WebThemeEngine::ScrollbarParentRenderLayer) | 91 if (scrollbarInfo.parent == WebThemeEngine::ScrollbarParentRenderLayer) |
| 97 paintHIThemeScrollbarThumb(canvas, state, size, rect, scrollbarInfo); | 92 paintHIThemeScrollbarThumb(canvas, state, size, rect, scrollbarInfo); |
| 98 else | 93 else |
| 99 paintNSScrollerScrollbarThumb(canvas, state, size, rect, scrollbarInfo); | 94 paintNSScrollerScrollbarThumb(canvas, state, size, rect, scrollbarInfo); |
| 100 } | 95 } |
| 101 | 96 |
| 102 // Duplicated from webkit/glue/webthemeengine_impl_mac.cc in the downstream | 97 // Duplicated from webkit/glue/webthemeengine_impl_mac.cc in the downstream |
| 103 // Chromium WebThemeEngine implementation. | 98 // Chromium WebThemeEngine implementation. |
| 104 void WebTestThemeEngineMac::paintHIThemeScrollbarThumb( | 99 void MockWebThemeEngineMac::paintHIThemeScrollbarThumb( |
| 105 WebCanvas* canvas, | 100 WebCanvas* canvas, |
| 106 WebThemeEngine::State state, | 101 WebThemeEngine::State state, |
| 107 WebThemeEngine::Size size, | 102 WebThemeEngine::Size size, |
| 108 const WebRect& rect, | 103 const WebRect& rect, |
| 109 const WebThemeEngine::ScrollbarInfo& scrollbarInfo) | 104 const WebThemeEngine::ScrollbarInfo& scrollbarInfo) { |
| 110 { | |
| 111 HIThemeTrackDrawInfo trackInfo; | 105 HIThemeTrackDrawInfo trackInfo; |
| 112 trackInfo.version = 0; | 106 trackInfo.version = 0; |
| 113 trackInfo.kind = size == WebThemeEngine::SizeRegular ? kThemeMediumScrollBar
: kThemeSmallScrollBar; | 107 trackInfo.kind = size == WebThemeEngine::SizeRegular ? kThemeMediumScrollBar
: kThemeSmallScrollBar; |
| 114 trackInfo.bounds = CGRectMake(rect.x, rect.y, rect.width, rect.height); | 108 trackInfo.bounds = CGRectMake(rect.x, rect.y, rect.width, rect.height); |
| 115 trackInfo.min = 0; | 109 trackInfo.min = 0; |
| 116 trackInfo.max = scrollbarInfo.maxValue; | 110 trackInfo.max = scrollbarInfo.maxValue; |
| 117 trackInfo.value = scrollbarInfo.currentValue; | 111 trackInfo.value = scrollbarInfo.currentValue; |
| 118 trackInfo.trackInfo.scrollbar.viewsize = scrollbarInfo.visibleSize; | 112 trackInfo.trackInfo.scrollbar.viewsize = scrollbarInfo.visibleSize; |
| 119 trackInfo.attributes = 0; | 113 trackInfo.attributes = 0; |
| 120 if (scrollbarInfo.orientation == WebThemeEngine::ScrollbarOrientationHorizon
tal) | 114 if (scrollbarInfo.orientation == WebThemeEngine::ScrollbarOrientationHorizon
tal) |
| 121 trackInfo.attributes |= kThemeTrackHorizontal; | 115 trackInfo.attributes |= kThemeTrackHorizontal; |
| 122 | 116 |
| 123 trackInfo.enableState = stateToHIEnableState(state); | 117 trackInfo.enableState = stateToHIEnableState(state); |
| 124 | 118 |
| 125 trackInfo.trackInfo.scrollbar.pressState = | 119 trackInfo.trackInfo.scrollbar.pressState = |
| 126 state == WebThemeEngine::StatePressed ? kThemeThumbPressed : 0; | 120 state == WebThemeEngine::StatePressed ? kThemeThumbPressed : 0; |
| 127 trackInfo.attributes |= (kThemeTrackShowThumb | kThemeTrackHideTrack); | 121 trackInfo.attributes |= (kThemeTrackShowThumb | kThemeTrackHideTrack); |
| 128 gfx::SkiaBitLocker bitLocker(canvas); | 122 gfx::SkiaBitLocker bitLocker(canvas); |
| 129 CGContextRef cgContext = bitLocker.cgContext(); | 123 CGContextRef cgContext = bitLocker.cgContext(); |
| 130 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal); | 124 HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal); |
| 131 } | 125 } |
| 132 | 126 |
| 133 void WebTestThemeEngineMac::paintNSScrollerScrollbarThumb( | 127 void MockWebThemeEngineMac::paintNSScrollerScrollbarThumb( |
| 134 WebCanvas* canvas, | 128 WebCanvas* canvas, |
| 135 WebThemeEngine::State state, | 129 WebThemeEngine::State state, |
| 136 WebThemeEngine::Size size, | 130 WebThemeEngine::Size size, |
| 137 const WebRect& rect, | 131 const WebRect& rect, |
| 138 const WebThemeEngine::ScrollbarInfo& scrollbarInfo) | 132 const WebThemeEngine::ScrollbarInfo& scrollbarInfo) { |
| 139 { | |
| 140 [NSGraphicsContext saveGraphicsState]; | 133 [NSGraphicsContext saveGraphicsState]; |
| 141 NSScroller* scroller = [[NSScroller alloc] initWithFrame:NSMakeRect(rect.x,
rect.y, rect.width, rect.height)]; | 134 NSScroller* scroller = [[NSScroller alloc] initWithFrame:NSMakeRect(rect.x,
rect.y, rect.width, rect.height)]; |
| 142 [scroller setEnabled:state != WebThemeEngine::StateDisabled]; | 135 [scroller setEnabled:state != WebThemeEngine::StateDisabled]; |
| 143 if (state == WebThemeEngine::StateInactive) | 136 if (state == WebThemeEngine::StateInactive) |
| 144 [[[FakeActiveWindow alwaysInactiveWindow] contentView] addSubview:scroll
er]; | 137 [[[FakeActiveWindow alwaysInactiveWindow] contentView] addSubview:scroll
er]; |
| 145 else | 138 else |
| 146 [[[FakeActiveWindow alwaysActiveWindow] contentView] addSubview:scroller
]; | 139 [[[FakeActiveWindow alwaysActiveWindow] contentView] addSubview:scroller
]; |
| 147 | 140 |
| 148 [scroller setControlSize:size == WebThemeEngine::SizeRegular ? NSRegularCont
rolSize : NSSmallControlSize]; | 141 [scroller setControlSize:size == WebThemeEngine::SizeRegular ? NSRegularCont
rolSize : NSSmallControlSize]; |
| 149 | 142 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 168 | 161 |
| 169 [scroller drawKnob]; | 162 [scroller drawKnob]; |
| 170 CGContextRestoreGState(cgContext); | 163 CGContextRestoreGState(cgContext); |
| 171 | 164 |
| 172 [scroller release]; | 165 [scroller release]; |
| 173 | 166 |
| 174 [NSGraphicsContext restoreGraphicsState]; | 167 [NSGraphicsContext restoreGraphicsState]; |
| 175 } | 168 } |
| 176 | 169 |
| 177 } // namespace content | 170 } // namespace content |
| OLD | NEW |