ChatCallMessageCell.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2017-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "ChatCallMessageCell.h"
  21. #import "SystemMessage.h"
  22. #import "ZSWTappableLabel.h"
  23. #import "UILabel+Markup.h"
  24. #import "ChatDefines.h"
  25. #import "UserSettings.h"
  26. #import "UIImage+ColoredImage.h"
  27. #import "ImageUtils.h"
  28. #import "QBPopupMenuItem.h"
  29. #import "QBPopupMenu.h"
  30. #import "Contact.h"
  31. #import "UIDefines.h"
  32. #import "TextStyleUtils.h"
  33. #import "BundleUtil.h"
  34. #import "Utils.h"
  35. #import "ServerConnector.h"
  36. #import "ChatTableDataSource.h"
  37. static CGFloat sideMargin = 2.0f;
  38. static CGFloat ZSWTappableLabelSpace = 16.0f;
  39. static ColorTheme currentTheme;
  40. @implementation ChatCallMessageCell {
  41. ZSWTappableLabel *titleLabel;
  42. ZSWTappableLabel *descriptionLabel;
  43. UIImageView *imageView;
  44. UIImageView *callIcon;
  45. UIAccessibilityElement *cellElement;
  46. NSString *titleText;
  47. NSString *descriptionText;
  48. }
  49. + (CGFloat)heightForMessage:(BaseMessage*)message forTableWidth:(CGFloat)tableWidth {
  50. CGSize titleSize;
  51. CGSize descriptionSize;
  52. CGSize maxSize = CGSizeMake([ChatMessageCell maxContentWidthForTableWidth:tableWidth] - ZSWTappableLabelSpace - sideMargin, CGFLOAT_MAX);
  53. NSString *text = [(SystemMessage *)message format];
  54. NSString *description = [(SystemMessage *)message callDetail];
  55. static ZSWTappableLabel *dummyTitleLabel = nil;
  56. if (dummyTitleLabel == nil) {
  57. dummyTitleLabel = [ChatCallMessageCell makeAttributedLabelWithFrame:CGRectMake(0.0, 0.0, maxSize.width, maxSize.height)];
  58. }
  59. dummyTitleLabel.font = [UIFont boldSystemFontOfSize:[ChatMessageCell textFontSize]];
  60. static dispatch_once_t onceToken;
  61. static BOOL canOpenPhoneLinks;
  62. dispatch_once(&onceToken, ^{
  63. canOpenPhoneLinks = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:0"]];
  64. });
  65. NSString *spaces = @"";
  66. for (int i = 0; i < (dummyTitleLabel.font.pointSize / 2.2); i++) {
  67. spaces = [NSString stringWithFormat:@"%@ ", spaces];
  68. }
  69. text = [NSString stringWithFormat:@"%@%@",spaces, [(SystemMessage *)message format]];
  70. NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithAttributedString:[dummyTitleLabel applyMarkupFor:[TextStyleUtils makeAttributedStringFromString:text withFont:dummyTitleLabel.font textColor:nil isOwn:true application:[UIApplication sharedApplication]]]];
  71. dummyTitleLabel.attributedText = titleString;
  72. titleSize = [dummyTitleLabel sizeThatFits:maxSize];
  73. static ZSWTappableLabel *dummyDescriptionLabel = nil;
  74. if (dummyDescriptionLabel == nil) {
  75. dummyDescriptionLabel = [ChatCallMessageCell makeAttributedLabelWithFrame:CGRectMake(0.0, 0.0, maxSize.width, maxSize.height)];
  76. }
  77. dummyDescriptionLabel.font = [UIFont systemFontOfSize:[ChatMessageCell textFontSize] - 2.0];
  78. if (description == nil || description.length == 0) {
  79. description = @" ";
  80. }
  81. dummyDescriptionLabel.attributedText = [dummyDescriptionLabel applyMarkupFor:[TextStyleUtils makeAttributedStringFromString:description withFont:dummyDescriptionLabel.font textColor:nil isOwn:true application:[UIApplication sharedApplication]]];
  82. descriptionSize = [dummyDescriptionLabel sizeThatFits:maxSize];
  83. return titleSize.height + descriptionSize.height;
  84. }
  85. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier transparent:(BOOL)transparent
  86. {
  87. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier transparent:transparent];
  88. if (self) {
  89. // Create message text label
  90. titleLabel = [ChatCallMessageCell makeAttributedLabelWithFrame:self.bounds];
  91. descriptionLabel = [ChatCallMessageCell makeAttributedLabelWithFrame:self.bounds];
  92. descriptionLabel.textAlignment = NSTextAlignmentRight;
  93. imageView = [UIImageView new];
  94. imageView.contentMode = UIViewContentModeCenter;
  95. imageView.image = [ImageUtils imageWithImage:[UIImage imageNamed:@"ThreemaPhone" inColor:[UIColor whiteColor]] scaledToSize:CGSizeMake(25, 25)];
  96. imageView.clipsToBounds = YES;
  97. callIcon = [UIImageView new];
  98. callIcon.contentMode = UIViewContentModeScaleAspectFit;
  99. [self.contentView addSubview:titleLabel];
  100. [self.contentView addSubview:descriptionLabel];
  101. [self.contentView addSubview:imageView];
  102. [self.contentView addSubview:callIcon];
  103. UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
  104. tgr.numberOfTapsRequired = 1;
  105. [self addGestureRecognizer:tgr];
  106. if (self.dtgr != nil) {
  107. [tgr requireGestureRecognizerToFail:self.dtgr];
  108. }
  109. self.statusImage.hidden = YES;
  110. }
  111. return self;
  112. }
  113. - (void)setupColors {
  114. [super setupColors];
  115. titleLabel.textColor = [Colors fontNormal];
  116. descriptionLabel.textColor = [Colors fontNormal];
  117. [self updateLinkColors];
  118. }
  119. - (void)updateLinkColors {
  120. if (currentTheme != [Colors getTheme]) {
  121. currentTheme = [Colors getTheme];
  122. titleLabel.attributedText = [titleLabel applyMarkupFor:[TextStyleUtils makeAttributedStringFromString:titleText withFont:titleLabel.font textColor:nil isOwn:self.message.isOwn.boolValue application:[UIApplication sharedApplication]]];
  123. descriptionLabel.attributedText = [descriptionLabel applyMarkupFor:[TextStyleUtils makeAttributedStringFromString:descriptionText withFont:descriptionLabel.font textColor:nil isOwn:self.message.isOwn.boolValue application:[UIApplication sharedApplication]]];
  124. }
  125. }
  126. - (void)layoutSubviews {
  127. CGFloat messageTextWidth;
  128. if (@available(iOS 11.0, *)) {
  129. messageTextWidth = [ChatMessageCell maxContentWidthForTableWidth:self.safeAreaLayoutGuide.layoutFrame.size.width];
  130. } else {
  131. messageTextWidth = [ChatMessageCell maxContentWidthForTableWidth:self.frame.size.width];
  132. }
  133. CGSize titleSize = [titleLabel sizeThatFits:CGSizeMake(messageTextWidth, CGFLOAT_MAX)];
  134. CGSize descriptionSize = [descriptionLabel sizeThatFits:CGSizeMake(messageTextWidth, CGFLOAT_MAX)];
  135. CGFloat callImageWidth = 40.0f;
  136. CGSize bubbleSize = CGSizeMake(MAX(titleSize.width, descriptionSize.width), titleSize.height + descriptionSize.height);
  137. [self setBubbleContentSize:bubbleSize];
  138. [super layoutSubviews];
  139. CGFloat x;
  140. if (self.message.isOwn.boolValue) {
  141. x = self.contentView.frame.size.width-bubbleSize.width-21.0f-sideMargin;
  142. } else {
  143. x = 20.0f + self.contentLeftOffset;
  144. }
  145. CGFloat y = 14.0f;
  146. if (descriptionSize.height == 0 || [descriptionLabel.text isEqualToString:@" "]) {
  147. titleLabel.frame = CGRectMake(x, (y/2) + (bubbleSize.height/2) - (titleSize.height/2), bubbleSize.width, titleSize.height);
  148. descriptionLabel.hidden = YES;
  149. } else {
  150. titleLabel.frame = CGRectMake(x, y - (ZSWTappableLabelSpace/2), bubbleSize.width, titleSize.height + (ZSWTappableLabelSpace/3));
  151. descriptionLabel.frame = CGRectMake(x, titleLabel.frame.origin.y + titleLabel.frame.size.height - (ZSWTappableLabelSpace/1.5), bubbleSize.width, descriptionSize.height + ZSWTappableLabelSpace);
  152. descriptionLabel.hidden = NO;
  153. }
  154. CAShapeLayer * maskLayer = [CAShapeLayer layer];
  155. if (self.message.isOwn.boolValue) {
  156. imageView.frame = CGRectMake(self.msgBackground.frame.origin.x, self.msgBackground.frame.origin.y + 1.0, callImageWidth, self.msgBackground.frame.size.height - 7.0);
  157. maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: imageView.bounds byRoundingCorners: UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii: (CGSize){10.0, 10.}].CGPath;
  158. } else {
  159. imageView.frame = CGRectMake(self.msgBackground.frame.origin.x + self.msgBackground.frame.size.width - callImageWidth, self.msgBackground.frame.origin.y + 1, callImageWidth, self.msgBackground.frame.size.height - 7.0);
  160. maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: imageView.bounds byRoundingCorners: UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii: (CGSize){10.0, 10.}].CGPath;
  161. }
  162. imageView.layer.mask = maskLayer;
  163. imageView.backgroundColor = [Colors bubbleCallButton];
  164. CGFloat lineHeight = titleLabel.font.lineHeight;
  165. if (descriptionSize.height == 0 || [descriptionLabel.text isEqualToString:@" "]) {
  166. callIcon.frame = CGRectMake(titleLabel.frame.origin.x, titleLabel.frame.origin.y + lineHeight - titleLabel.font.pointSize - 2.0, (titleLabel.font.pointSize/2)*3, titleLabel.font.pointSize);
  167. } else {
  168. callIcon.frame = CGRectMake(titleLabel.frame.origin.x, titleLabel.frame.origin.y + lineHeight - titleLabel.font.pointSize, (titleLabel.font.pointSize/2)*3, titleLabel.font.pointSize);
  169. }
  170. }
  171. - (NSString *)accessibilityLabelForContent {
  172. return [NSString stringWithFormat:@"%@, %@", titleLabel.text, descriptionLabel.text];
  173. }
  174. - (void)setMessage:(BaseMessage *)newMessage {
  175. [super setMessage:newMessage];
  176. NSError *error;
  177. SystemMessage *systemMessage = (SystemMessage *)self.message;
  178. if (systemMessage.arg) {
  179. NSDictionary *argDict = [NSJSONSerialization JSONObjectWithData:systemMessage.arg options:NSJSONReadingAllowFragments error:&error];
  180. if (error) {
  181. self.message.isOwn = @0;
  182. } else {
  183. self.message.isOwn = argDict[@"CallInitiator"];
  184. }
  185. } else {
  186. self.message.isOwn = @1;
  187. }
  188. NSString *spaces = @"";
  189. for (int i = 0; i < (titleLabel.font.pointSize / 2.2); i++) {
  190. spaces = [NSString stringWithFormat:@"%@ ", spaces];
  191. }
  192. titleText = [NSString stringWithFormat:@"%@%@",spaces, [systemMessage format]];
  193. descriptionText = systemMessage.callDetail;
  194. if (descriptionText == nil || descriptionText.length == 0) {
  195. descriptionText = @" ";
  196. }
  197. titleLabel.font = [UIFont boldSystemFontOfSize:[ChatMessageCell textFontSize]];
  198. descriptionLabel.font = [UIFont systemFontOfSize:[ChatMessageCell textFontSize] - 2.0];
  199. NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithAttributedString:[titleLabel applyMarkupFor:[TextStyleUtils makeAttributedStringFromString:titleText withFont:titleLabel.font textColor:nil isOwn:self.message.isOwn.boolValue application:[UIApplication sharedApplication]]]];
  200. switch ([systemMessage.type integerValue]) {
  201. case kSystemMessageCallEnded:
  202. if (systemMessage.haveCallTime) {
  203. if (!self.message.isOwn.boolValue) {
  204. callIcon.image = [UIImage imageNamed:@"CallDownGreen" inColor:[Colors green]];
  205. } else {
  206. callIcon.image = [UIImage imageNamed:@"CallUpGreen" inColor:[Colors green]];
  207. }
  208. } else {
  209. if (!self.message.isOwn.boolValue) {
  210. callIcon.image = [UIImage imageNamed:@"CallLeftRed"];
  211. } else {
  212. callIcon.image = [UIImage imageNamed:@"CallUpRed"];
  213. }
  214. }
  215. break;
  216. case kSystemMessageCallRejected:
  217. if (!self.message.isOwn.boolValue) {
  218. callIcon.image = [UIImage imageNamed:@"CallLeftOrange"];
  219. } else {
  220. callIcon.image = [UIImage imageNamed:@"CallRightRed"];
  221. }
  222. break;
  223. case kSystemMessageCallRejectedBusy:
  224. if (!self.message.isOwn.boolValue) {
  225. callIcon.image = [UIImage imageNamed:@"CallLeftRed"];
  226. } else {
  227. callIcon.image = [UIImage imageNamed:@"CallRightRed"];
  228. }
  229. break;
  230. case kSystemMessageCallRejectedTimeout:
  231. if (!self.message.isOwn.boolValue) {
  232. callIcon.image = [UIImage imageNamed:@"CallLeftRed"];
  233. } else {
  234. callIcon.image = [UIImage imageNamed:@"CallRightRed"];
  235. }
  236. break;
  237. case kSystemMessageCallRejectedDisabled:
  238. callIcon.image = [UIImage imageNamed:@"CallRightRed"];
  239. break;
  240. case kSystemMessageCallMissed:
  241. callIcon.image = [UIImage imageNamed:@"CallLeftRed"];
  242. break;
  243. default:
  244. callIcon.image = [UIImage imageNamed:@"CallUpGreen" inColor:[Colors green]];
  245. break;
  246. }
  247. titleLabel.attributedText = titleString;
  248. descriptionLabel.attributedText = [descriptionLabel applyMarkupFor:[TextStyleUtils makeAttributedStringFromString:descriptionText withFont:descriptionLabel.font textColor:nil isOwn:self.message.isOwn.boolValue application:[UIApplication sharedApplication]]];
  249. if (self.message.isOwn.boolValue) {
  250. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  251. descriptionLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  252. } else {
  253. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  254. descriptionLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
  255. }
  256. cellElement = nil;
  257. [self setNeedsLayout];
  258. }
  259. + (ZSWTappableLabel*)makeAttributedLabelWithFrame:(CGRect)rect {
  260. ZSWTappableLabel *label = [[ZSWTappableLabel alloc] initWithFrame:rect];
  261. label.clearsContextBeforeDrawing = NO;
  262. label.backgroundColor = [UIColor clearColor];
  263. label.numberOfLines = 0;
  264. label.lineBreakMode = NSLineBreakByWordWrapping;
  265. label.font = [ChatMessageCell textFont];
  266. label.contentMode = UIViewContentModeScaleToFill;
  267. return label;
  268. }
  269. #pragma mark - Private functions
  270. + (NSAttributedString*)attachmentWithImage:(UIImage*)attachment label:(UILabel *)label boundsImage:(BOOL)boundsImage {
  271. NSTextAttachment* textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
  272. textAttachment.image = attachment;
  273. if (boundsImage) {
  274. textAttachment.bounds = CGRectMake(0.0, -label.font.pointSize/6, label.font.pointSize, label.font.pointSize);
  275. }
  276. NSAttributedString* string = [NSAttributedString attributedStringWithAttachment:textAttachment];
  277. return string;
  278. }
  279. - (void)handleTap:(UIGestureRecognizer *)gestureRecognizer {
  280. CGPoint p = [gestureRecognizer locationInView:self];
  281. if (CGRectContainsPoint(self.msgBackground.frame, p)) {
  282. if ([UserSettings sharedUserSettings].enableThreemaCall && is64Bit == 1) {
  283. if (gestureRecognizer.state == UIGestureRecognizerStateEnded && self.editing == NO) {
  284. if ([ServerConnector sharedServerConnector].connectionState == ConnectionStateLoggedIn) {
  285. NSString *message = [NSString stringWithFormat:NSLocalizedString(@"call_contact_alert", nil), self.chatVc.conversation.contact.displayName];
  286. UIAlertController *errAlert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
  287. [errAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"call", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  288. [self.chatVc startVoipCall:false];
  289. }]];
  290. [errAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
  291. }]];
  292. [self.chatVc presentViewController:errAlert animated:YES completion:nil];
  293. } else {
  294. // Alert no internet connection
  295. NSString *title = NSLocalizedString(@"cannot_connect_title", nil);
  296. NSString *message = NSLocalizedString(@"cannot_connect_message", nil);
  297. [UIAlertTemplate showAlertWithOwner:self.chatVc title:title message:message actionOk:nil];
  298. }
  299. } else {
  300. UITableView *tableView = (UITableView *)self.superview;
  301. CGPoint p2 = [gestureRecognizer locationInView:tableView];
  302. NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:p2];
  303. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  304. if (cell.selected) {
  305. [tableView deselectRowAtIndexPath:indexPath animated:NO];
  306. [((ChatTableDataSource *) tableView.dataSource) tableView:tableView didDeselectRowAtIndexPath:indexPath];
  307. } else {
  308. [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  309. [((ChatTableDataSource *) tableView.dataSource) tableView:tableView didSelectRowAtIndexPath:indexPath];
  310. }
  311. }
  312. }
  313. } else {
  314. if (self.editing) {
  315. UITableView *tableView = (UITableView *)self.superview;
  316. CGPoint p2 = [gestureRecognizer locationInView:tableView];
  317. NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:p2];
  318. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  319. if (cell.selected) {
  320. [tableView deselectRowAtIndexPath:indexPath animated:NO];
  321. [((ChatTableDataSource *) tableView.dataSource) tableView:tableView didDeselectRowAtIndexPath:indexPath];
  322. } else {
  323. [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
  324. [((ChatTableDataSource *) tableView.dataSource) tableView:tableView didSelectRowAtIndexPath:indexPath];
  325. }
  326. }
  327. }
  328. }
  329. #pragma mark - Override functions
  330. - (void)updateStatusImage {
  331. self.statusImage.hidden = YES;
  332. [self setNeedsLayout];
  333. }
  334. - (UIImage*)bubbleImageWithHighlight:(BOOL)bubbleHighlight {
  335. if (self.shouldHideBubbleBackground) {
  336. return nil;
  337. }
  338. if (self.message.isOwn.boolValue) {
  339. NSString *name = @"ChatBubbleSentMask";
  340. if (bubbleHighlight) {
  341. return [[UIImage imageNamed:name inColor:[Colors bubbleSent]] stretchableImageWithLeftCapWidth:15 topCapHeight:13];
  342. } else {
  343. return [[UIImage imageNamed:name inColor:[Colors bubbleSent]] stretchableImageWithLeftCapWidth:15 topCapHeight:13];
  344. }
  345. } else {
  346. NSString *name = @"ChatBubbleReceivedMask";
  347. if (bubbleHighlight) {
  348. return [[UIImage imageNamed:name inColor:[Colors bubbleReceived]] stretchableImageWithLeftCapWidth:23 topCapHeight:15];
  349. } else {
  350. return [[UIImage imageNamed:name inColor:[Colors bubbleReceived]] stretchableImageWithLeftCapWidth:23 topCapHeight:15];
  351. }
  352. }
  353. }
  354. - (void)setBubbleContentSize:(CGSize)size {
  355. CGFloat bgWidthMargin = 34.0f;
  356. CGFloat bgHeightMargin = 16.0f;
  357. CGFloat callImageWidth = 40.0f;
  358. self.bubbleSize = CGSizeMake(size.width+bgWidthMargin+callImageWidth, size.height+bgHeightMargin);
  359. }
  360. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
  361. if (action == @selector(deleteMessage:)) {
  362. return YES;
  363. } else {
  364. return NO;
  365. }
  366. }
  367. - (NSString *)textForQuote {
  368. return titleText;
  369. }
  370. #pragma mark - ZSWTappableLabel delegate
  371. - (void)tappableLabel:(ZSWTappableLabel *)tappableLabel tappedAtIndex:(NSInteger)idx withAttributes:(NSDictionary *)attributes {
  372. }
  373. - (void)tappableLabel:(ZSWTappableLabel *)tappableLabel longPressedAtIndex:(NSInteger)idx withAttributes:(NSDictionary<NSString *,id> *)attributes {
  374. }
  375. - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
  376. if (self.editing) {
  377. // don't event forward to label
  378. return self;
  379. }
  380. return [super hitTest:point withEvent:event];
  381. }
  382. #pragma mark - UIAccessibilityContainer
  383. - (BOOL)isAccessibilityElement {
  384. return NO;
  385. }
  386. - (NSInteger)accessibilityElementCount {
  387. return [titleLabel accessibilityElementCount]+1;
  388. }
  389. - (id)accessibilityElementAtIndex:(NSInteger)index {
  390. // Fake an additional last element that encompasses the entire cell
  391. // and adds additional information about the message.
  392. if (index == ([titleLabel accessibilityElementCount])) {
  393. return [self cellElement];
  394. } else {
  395. return [titleLabel accessibilityElementAtIndex:index];
  396. }
  397. }
  398. - (NSInteger)indexOfAccessibilityElement:(id)element {
  399. if (element == [self cellElement])
  400. return [titleLabel accessibilityElementCount];
  401. else
  402. return [titleLabel indexOfAccessibilityElement:element];
  403. }
  404. - (UIAccessibilityElement*)cellElement {
  405. if (cellElement == nil) {
  406. cellElement = [[UIAccessibilityElement alloc] initWithAccessibilityContainer:self];
  407. cellElement.accessibilityLabel = [self accessibilityLabel];
  408. cellElement.accessibilityTraits = UIAccessibilityTraitStaticText;
  409. }
  410. cellElement.accessibilityFrame = [self convertRect:self.bounds toView:nil];
  411. return cellElement;
  412. }
  413. @end