forked from facebook/chisel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fblldbviewhelpers.py
89 lines (70 loc) · 3.74 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
#!/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
def flushCoreAnimationTransaction():
lldb.debugger.HandleCommand('expr (void)[CATransaction flush]')
def setViewHidden(object, hidden):
lldb.debugger.HandleCommand('expr (void)[' + object + ' setHidden:' + str(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)
lldb.debugger.HandleCommand('expr (void)[%s setTag:(NSInteger)%s]' % (mask, viewOrLayer))
lldb.debugger.HandleCommand('expr (void)[%s setBackgroundColor:[UIColor %sColor]]' % (mask, color))
lldb.debugger.HandleCommand('expr (void)[%s setAlpha:(CGFloat)%s]' % (mask, alpha))
lldb.debugger.HandleCommand('expr (void)[%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))
lldb.debugger.HandleCommand('expr (void)[%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 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 len(viewDescription) == 0:
return None
currentPrefix = ""
builder = ""
for viewDescription in recursiveDescription:
builder += currentPrefix + viewDescription + "\n"
currentPrefix += " | "
return builder