Commit fe64b085 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Create BadgeTypeForInfobarType()

This implements the InfobarType => BadgeType conversion in a shared
util target.

Bug: none
Change-Id: Ib7848c4b9ab79e7d9c605d6c6131c62b4327c8c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1974758
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727235}
parent 99aa60e9
...@@ -44,6 +44,7 @@ source_set("badge_public") { ...@@ -44,6 +44,7 @@ source_set("badge_public") {
":public", ":public",
"//base", "//base",
"//ios/chrome/browser/ui/badges:public", "//ios/chrome/browser/ui/badges:public",
"//ios/chrome/browser/ui/badges:util",
] ]
} }
......
...@@ -5,16 +5,16 @@ ...@@ -5,16 +5,16 @@
#import "ios/chrome/browser/infobars/infobar_badge_model.h" #import "ios/chrome/browser/infobars/infobar_badge_model.h"
#import "base/logging.h" #import "base/logging.h"
#include "ios/chrome/browser/ui/badges/badge_type_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface InfobarBadgeModel () @interface InfobarBadgeModel () {
// The badge's type.
// The type of Infobar associated with this badge. BadgeType _badgeType;
@property(nonatomic, assign) InfobarType infobarType; }
@end @end
@implementation InfobarBadgeModel @implementation InfobarBadgeModel
...@@ -29,9 +29,10 @@ ...@@ -29,9 +29,10 @@
self = [super init]; self = [super init];
if (self) { if (self) {
_tappable = YES; _tappable = YES;
_infobarType = type;
_badgeState = BadgeStateNone; _badgeState = BadgeStateNone;
_fullScreen = NO; _fullScreen = NO;
_badgeType = BadgeTypeForInfobarType(type);
DCHECK_NE(BadgeType::kBadgeTypeNone, _badgeType);
} }
return self; return self;
} }
...@@ -39,19 +40,7 @@ ...@@ -39,19 +40,7 @@
#pragma mark - BadgeViewModel #pragma mark - BadgeViewModel
- (BadgeType)badgeType { - (BadgeType)badgeType {
switch (self.infobarType) { return _badgeType;
case InfobarType::kInfobarTypePasswordSave:
return BadgeType::kBadgeTypePasswordSave;
case InfobarType::kInfobarTypePasswordUpdate:
return BadgeType::kBadgeTypePasswordUpdate;
case InfobarType::kInfobarTypeSaveCard:
return BadgeType::kBadgeTypeSaveCard;
case InfobarType::kInfobarTypeTranslate:
return BadgeType::kBadgeTypeTranslate;
default:
NOTREACHED() << "This infobar should not have a badge";
return BadgeType::kBadgeTypeNone;
}
} }
@end @end
...@@ -12,6 +12,18 @@ source_set("public") { ...@@ -12,6 +12,18 @@ source_set("public") {
] ]
} }
source_set("util") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"badge_type_util.cc",
"badge_type_util.h",
]
deps = [
":public",
"//ios/chrome/browser/infobars:public",
]
}
source_set("badges") { source_set("badges") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/ui/badges/badge_type_util.h"
BadgeType BadgeTypeForInfobarType(InfobarType infobar_type) {
switch (infobar_type) {
case InfobarType::kInfobarTypePasswordSave:
return BadgeType::kBadgeTypePasswordSave;
case InfobarType::kInfobarTypePasswordUpdate:
return BadgeType::kBadgeTypePasswordUpdate;
case InfobarType::kInfobarTypeSaveCard:
return BadgeType::kBadgeTypeSaveCard;
case InfobarType::kInfobarTypeTranslate:
return BadgeType::kBadgeTypeTranslate;
default:
return BadgeType::kBadgeTypeNone;
}
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_BADGES_BADGE_TYPE_UTIL_H_
#define IOS_CHROME_BROWSER_UI_BADGES_BADGE_TYPE_UTIL_H_
#import "ios/chrome/browser/infobars/infobar_type.h"
#import "ios/chrome/browser/ui/badges/badge_type.h"
// Returns the corresponding BadgeType for |infobar_type|, or kBadgeTypeNone
// if that InfobarType does not support badges.
BadgeType BadgeTypeForInfobarType(InfobarType infobar_type);
#endif // IOS_CHROME_BROWSER_UI_BADGES_BADGE_TYPE_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment