Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1047)

Unified Diff: chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.mm

Issue 2206693002: Improve settings override bubble to indicate policy installed extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase master Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.mm
diff --git a/chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.mm b/chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.mm
index 12e764ff5fe88632829e183c0dfded575b19f53e..cb0a5721d351d0a78f2f1833ae42b5a53e1e891d 100644
--- a/chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.mm
+++ b/chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.mm
@@ -16,7 +16,11 @@
#include "third_party/skia/include/core/SkColor.h"
#import "ui/base/cocoa/controls/hyperlink_button_cell.h"
#import "ui/base/cocoa/hover_button.h"
+#include "ui/base/resource/resource_bundle.h"
#import "ui/base/cocoa/window_size_constants.h"
+#include "ui/gfx/color_palette.h"
+#include "ui/gfx/image/image_skia_util_mac.h"
+#include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_mac.h"
@@ -59,7 +63,9 @@ CGFloat kMinWidth = 320.0;
@synthesize actionButton = actionButton_;
@synthesize itemList = itemList_;
@synthesize dismissButton = dismissButton_;
-@synthesize learnMoreButton = learnMoreButton_;
+@synthesize link = link_;
+@synthesize label = label_;
+@synthesize iconView = iconView_;
- (id)initWithParentWindow:(NSWindow*)parentWindow
anchorPoint:(NSPoint)anchorPoint
@@ -177,29 +183,52 @@ CGFloat kMinWidth = 320.0;
- (void)layout {
// First, construct the pieces of the bubble that have a fixed width: the
- // heading, and the button strip (the learn more link, the action button, and
- // the dismiss button).
+ // heading, and the button strip (the extra view (icon and/or (linked) text),
+ // the action button, and the dismiss button).
NSTextField* heading =
[self addTextFieldWithString:delegate_->GetHeadingText()
fontSize:13.0
alignment:NSLeftTextAlignment];
NSSize headingSize = [heading frame].size;
- base::string16 learnMore = delegate_->GetLearnMoreButtonText();
- NSSize learnMoreSize = NSZeroSize;
- if (!learnMore.empty()) { // The "learn more" link is optional.
- NSAttributedString* learnMoreString =
- [self attributedStringWithString:learnMore
- fontSize:13.0
- alignment:NSLeftTextAlignment];
- learnMoreButton_ =
- [[HyperlinkButtonCell buttonWithString:learnMoreString.string] retain];
- [learnMoreButton_ setTarget:self];
- [learnMoreButton_ setAction:@selector(onButtonClicked:)];
- [[[self window] contentView] addSubview:learnMoreButton_];
- [learnMoreButton_ sizeToFit];
- learnMoreSize = NSMakeSize(NSWidth([learnMoreButton_ frame]),
- NSHeight([learnMoreButton_ frame]));
+ std::unique_ptr<ToolbarActionsBarBubbleDelegate::ExtraViewInfo>
+ extra_view_info = delegate_->GetExtraViewInfo();
+
+ gfx::VectorIconId resource_id = extra_view_info->resource_id;
+
+ NSSize extraViewIconSize = NSZeroSize;
+ // The extra view icon is optional.
+ if (resource_id != gfx::VectorIconId::VECTOR_ICON_NONE) {
+ NSImage* i =
Devlin 2016/10/20 17:04:07 nit: it's nicer to use more descriptive names when
catmullings 2016/10/21 03:49:28 Done.
+ gfx::Image(gfx::CreateVectorIcon(resource_id, 16, gfx::kChromeIconGrey))
Devlin 2016/10/20 00:23:42 What is this 16?
catmullings 2016/10/21 03:49:29 I'm following the pattern/format from here: https:
+ .ToNSImage();
+ NSRect frame = NSMakeRect(0, 0, i.size.width, i.size.height);
+ iconView_ = [[NSImageView alloc] initWithFrame:frame];
+ [iconView_ setImage:i];
+ extraViewIconSize = i.size;
Devlin 2016/10/20 17:04:07 nit: I'd prefer we use the view's frame's size her
catmullings 2016/10/21 03:49:29 Done.
+
+ [[[self window] contentView] addSubview:iconView_];
+ }
+
+ NSSize extraViewTextSize = NSZeroSize;
+ const base::string16& text = extra_view_info->text;
+ if (!text.empty()) { // The extra view text is optional.
+ if (extra_view_info->is_text_linked) {
+ NSAttributedString* linkString =
+ [self attributedStringWithString:text
+ fontSize:13.0
+ alignment:NSLeftTextAlignment];
+ link_ = [[HyperlinkButtonCell buttonWithString:linkString.string] retain];
+ [link_ setTarget:self];
+ [link_ setAction:@selector(onButtonClicked:)];
+ [[[self window] contentView] addSubview:link_];
+ [link_ sizeToFit];
+ } else {
+ label_ = [self addTextFieldWithString:text
+ fontSize:13.0
+ alignment:NSLeftTextAlignment];
+ }
+ extraViewTextSize = label_ ? [label_ frame].size : [link_ frame].size;
}
base::string16 cancelStr = delegate_->GetDismissButtonText();
@@ -230,8 +259,10 @@ CGFloat kMinWidth = 320.0;
buttonStripWidth += actionButtonSize.width + kButtonPadding;
if (dismissButton_)
buttonStripWidth += dismissButtonSize.width + kButtonPadding;
- if (learnMoreButton_)
- buttonStripWidth += learnMoreSize.width + kButtonPadding;
+ if (iconView_)
+ buttonStripWidth += extraViewIconSize.width + kButtonPadding;
+ if (link_ || label_)
+ buttonStripWidth += extraViewTextSize.width + kButtonPadding;
CGFloat headingWidth = headingSize.width;
CGFloat windowWidth =
@@ -287,13 +318,27 @@ CGFloat kMinWidth = 320.0;
dismissButtonSize.height)];
currentMaxWidth -= (dismissButtonSize.width + kButtonPadding);
}
- if (learnMoreButton_) {
- CGFloat learnMoreHeight =
- currentHeight + (buttonStripHeight - learnMoreSize.height) / 2.0;
- [learnMoreButton_ setFrame:NSMakeRect(kHorizontalPadding,
- learnMoreHeight,
- learnMoreSize.width,
- learnMoreSize.height)];
+ if (label_ || link_) {
+ CGFloat extraViewTextHeight =
+ currentHeight + (buttonStripHeight - extraViewTextSize.height) / 2.0;
+ NSRect frame = NSMakeRect(currentMaxWidth - extraViewTextSize.width,
+ extraViewTextHeight, extraViewTextSize.width,
+ extraViewTextSize.height);
+ if (link_) {
+ [link_ setFrame:frame];
+ } else {
+ [label_ setFrame:frame];
+ }
+ currentMaxWidth -= extraViewTextSize.width + kButtonPadding;
+ }
+ if (iconView_) {
+ CGFloat extraViewIconHeight =
+ currentHeight + (buttonStripHeight - extraViewIconSize.height) / 2.0;
+
+ [iconView_
+ setFrame:NSMakeRect(kHorizontalPadding, extraViewIconHeight,
+ extraViewIconSize.width, extraViewIconSize.height)];
+ currentMaxWidth -= extraViewIconSize.width + kButtonPadding;
}
// Buttons have some inherit padding of their own, so we don't need quite as
// much space here.
@@ -336,7 +381,7 @@ CGFloat kMinWidth = 320.0;
return;
ToolbarActionsBarBubbleDelegate::CloseAction action =
ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE;
- if (learnMoreButton_ && sender == learnMoreButton_) {
+ if (link_ && sender == link_) {
action = ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE;
} else if (dismissButton_ && sender == dismissButton_) {
action = ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION;

Powered by Google App Engine
This is Rietveld 408576698