forked from facebook/chisel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fblldbviewhelpers.py
116 lines (92 loc) · 4.72 KB
/
fblldbviewhelpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python
# Copyright (c) 2014, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
import lldb
import fblldbbase as fb
import fblldbobjcruntimehelpers as runtimeHelpers
def flushCoreAnimationTransaction():
fb.evaluateEffect('[CATransaction flush]')
def setViewHidden(object, hidden):
fb.evaluateEffect('[{} setHidden:{}]'.format(object, int(hidden)))
flushCoreAnimationTransaction()
def maskView(viewOrLayer, color, alpha):
unmaskView(viewOrLayer)
window = fb.evaluateExpression('(UIWindow *)[[UIApplication sharedApplication] keyWindow]')
origin = convertPoint(0, 0, viewOrLayer, window)
size = fb.evaluateExpressionValue('(CGSize)((CGRect)[(id)%s frame]).size' % viewOrLayer)
rectExpr = '(CGRect){{%s, %s}, {%s, %s}}' % (origin.GetChildMemberWithName('x').GetValue(),
origin.GetChildMemberWithName('y').GetValue(),
size.GetChildMemberWithName('width').GetValue(),
size.GetChildMemberWithName('height').GetValue())
mask = fb.evaluateExpression('(id)[[UIView alloc] initWithFrame:%s]' % rectExpr)
fb.evaluateEffect('[%s setTag:(NSInteger)%s]' % (mask, viewOrLayer))
fb.evaluateEffect('[%s setBackgroundColor:[UIColor %sColor]]' % (mask, color))
fb.evaluateEffect('[%s setAlpha:(CGFloat)%s]' % (mask, alpha))
fb.evaluateEffect('[%s addSubview:%s]' % (window, mask))
flushCoreAnimationTransaction()
def unmaskView(viewOrLayer):
window = fb.evaluateExpression('(UIWindow *)[[UIApplication sharedApplication] keyWindow]')
mask = fb.evaluateExpression('(UIView *)[%s viewWithTag:(NSInteger)%s]' % (window, viewOrLayer))
fb.evaluateEffect('[%s removeFromSuperview]' % mask)
flushCoreAnimationTransaction()
def convertPoint(x, y, fromViewOrLayer, toViewOrLayer):
fromLayer = convertToLayer(fromViewOrLayer)
toLayer = convertToLayer(toViewOrLayer)
return fb.evaluateExpressionValue('(CGPoint)[%s convertPoint:(CGPoint){ .x = %s, .y = %s } toLayer:(CALayer *)%s]' % (fromLayer, x, y, toLayer))
def convertToLayer(viewOrLayer):
if fb.evaluateBooleanExpression('[(id)%s isKindOfClass:(Class)[CALayer class]]' % viewOrLayer):
return viewOrLayer
elif fb.evaluateBooleanExpression('[(id)%s respondsToSelector:(SEL)@selector(layer)]' % viewOrLayer):
return fb.evaluateExpression('(CALayer *)[%s layer]' % viewOrLayer)
else:
raise Exception('Argument must be a CALayer, UIView, or NSView.')
def isUIView(obj):
return not runtimeHelpers.isMacintoshArch() and fb.evaluateBooleanExpression('[(id)%s isKindOfClass:(Class)[UIView class]]' % obj)
def isNSView(obj):
return runtimeHelpers.isMacintoshArch() and fb.evaluateBooleanExpression('[(id)%s isKindOfClass:(Class)[NSView class]]' % obj)
def isView(obj):
return isUIView(obj) or isNSView(obj)
# Generates a BFS of the views tree starting at the given view as root.
# Yields a tuple of the current view in the tree and its level (view, level)
def subviewsOfView(view):
views = [(view, 0)]
yield views[0]
while views:
(view, level) = views.pop(0)
subviews = fb.evaluateExpression('(id)[%s subviews]' % view)
subviewsCount = int(fb.evaluateExpression('(int)[(id)%s count]' % subviews))
for i in xrange(subviewsCount):
subview = fb.evaluateExpression('(id)[%s objectAtIndex:%i]' % (subviews, i))
views.append((subview, level+1))
yield (subview, level+1)
def upwardsRecursiveDescription(view, maxDepth=0):
if not fb.evaluateBooleanExpression('[(id)%s isKindOfClass:(Class)[UIView class]]' % view) and not fb.evaluateBooleanExpression('[(id)%s isKindOfClass:(Class)[NSView class]]' % view):
return None
currentView = view
recursiveDescription = []
depth = 0
while currentView and (maxDepth <= 0 or depth <= maxDepth):
depth += 1
viewDescription = fb.evaluateExpressionValue('(id)[%s debugDescription]' % (currentView)).GetObjectDescription()
currentView = fb.evaluateExpression('(void*)[%s superview]' % (currentView))
try:
if int(currentView, 0) == 0:
currentView = None
except:
currentView = None
if viewDescription:
recursiveDescription.insert(0, viewDescription)
if not len(viewDescription):
return None
currentPrefix = ""
builder = ""
for viewDescription in recursiveDescription:
builder += currentPrefix + viewDescription + "\n"
currentPrefix += " | "
return builder
def slowAnimation(speed=1):
fb.evaluateEffect('[[[UIApplication sharedApplication] windows] setValue:@(%s) forKeyPath:@"layer.speed"]' % speed)