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

Unified Diff: chrome/browser/ui/cocoa/infobars/media_stream_infobar_controller.mm

Issue 10802090: fixed the distorted behavior on the mediastreaminfobar on Mac (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ready for review. Created 8 years, 5 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/infobars/media_stream_infobar_controller.mm
diff --git a/chrome/browser/ui/cocoa/infobars/media_stream_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/media_stream_infobar_controller.mm
index 2bcc58de65678e8b0224391fe1aa393844b427b2..2ef71b283d3d680fe0db3f3c5a7b29028022152c 100644
--- a/chrome/browser/ui/cocoa/infobars/media_stream_infobar_controller.mm
+++ b/chrome/browser/ui/cocoa/infobars/media_stream_infobar_controller.mm
@@ -12,11 +12,15 @@
#include "chrome/browser/media/media_stream_devices_menu_model.h"
#include "chrome/browser/ui/cocoa/hover_close_button.h"
#include "chrome/browser/ui/cocoa/infobars/infobar.h"
+#import "chrome/browser/ui/cocoa/infobars/infobar_utilities.h"
#include "chrome/browser/ui/media_stream_infobar_delegate.h"
#include "grit/generated_resources.h"
#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#include "ui/base/l10n/l10n_util.h"
+using InfoBarUtilities::CreateLabel;
+using InfoBarUtilities::MoveControl;
+using InfoBarUtilities::VerifyControlOrderAndSpacing;
using l10n_util::GetNSStringWithFixup;
static const CGFloat kSpaceBetweenControls = 8;
Scott Hess - ex-Googler 2012/07/25 18:28:15 Should use of this also be replaced by spaceBetwee
no longer working on chromium 2012/07/26 10:17:47 removed
@@ -53,11 +57,17 @@ void SizeAndPlaceControl(NSView* toModify, NSView* anchor, bool after) {
- (void)setLabelTexts;
// Populates the device menu with device id:s.
-- (void)rebuildDeviceMenu;
+- (void)rebuildDeviceMenu:(BOOL)hideTitle;
// Arranges all buttons and pup-up menu relative each other.
- (void)arrangeInfobarLayout;
+// Create all the components for the infobar.
+- (void)constructView;
+
+// Used for setting the correct styles on each label and button.
+- (NSArray*)allControls;
+
@end
@@ -67,22 +77,6 @@ void SizeAndPlaceControl(NSView* toModify, NSView* anchor, bool after) {
owner:(InfoBarTabHelper*)owner {
if (self = [super initWithDelegate:delegate owner:owner]) {
deviceMenuModel_.reset(new MediaStreamDevicesMenuModel(delegate));
-
- label1_.reset([[NSTextField alloc] init]);
- [label1_ setEditable:NO];
- [label1_ setDrawsBackground:NO];
- [label1_ setBordered:NO];
-
- [okButton_ setBezelStyle:NSTexturedRoundedBezelStyle];
- [cancelButton_ setBezelStyle:NSTexturedRoundedBezelStyle];
-
- deviceMenu_.reset([[NSPopUpButton alloc] init]);
- [deviceMenu_ setBezelStyle:NSTexturedRoundedBezelStyle];
- [deviceMenu_ setAutoresizingMask:NSViewMaxXMargin];
- [[deviceMenu_ cell] setArrowPosition:NSPopUpArrowAtBottom];
- NSMenu* menu = [deviceMenu_ menu];
- [menu setDelegate:nil];
- [menu setAutoenablesItems:NO];
}
return self;
}
@@ -120,30 +114,32 @@ void SizeAndPlaceControl(NSView* toModify, NSView* anchor, bool after) {
- (IBAction)deviceMenuChanged:(id)item {
// Notify the menu model about the change and rebuild the menu.
deviceMenuModel_->ExecuteCommand([item tag]);
- [self rebuildDeviceMenu];
+ [self rebuildDeviceMenu:NO];
}
- (void)addAdditionalControls {
- // Get a frame to use as inital frame for all buttons.
- NSRect initFrame = [okButton_ frame];
-
- // Setup up the text label and add the device menu to the infobar.
- // TODO(mflodman) Use |label_| instead.
- [label1_ setFrame:[label_ frame]];
- [[label_ superview] replaceSubview:label_ with:label1_.get()];
- label_.reset();
+ // Create all the components for the infobar.
+ [self constructView];
- [deviceMenu_ setFrame:initFrame];
- [infoBarView_ addSubview:deviceMenu_];
+ // Get layout information from the NIB.
+ NSRect cancelButtonFrame = [cancelButton_ frame];
+ NSRect okButtonFrame = [okButton_ frame];
- // Add text to all buttons and the text field.
- [self setLabelTexts];
+ spaceBetweenControls_ = NSMaxX(cancelButtonFrame) < NSMinX(okButtonFrame) ?
+ NSMinX(okButtonFrame) - NSMaxX(cancelButtonFrame) :
+ NSMinX(cancelButtonFrame) - NSMaxX(okButtonFrame);
Scott Hess - ex-Googler 2012/07/25 18:28:15 There are cases in our UI where the effective boun
no longer working on chromium 2012/07/26 10:17:47 The condition is to guarantee that the spaceBetwee
Scott Hess - ex-Googler 2012/07/26 19:39:41 Hmm. I read the condition as making sure that it
// Arrange the initial layout.
[self arrangeInfobarLayout];
- // Build the device popup menu.
- [self rebuildDeviceMenu];
+ // Add and configure controls that are visible in all modes.
+ [deviceMenu_ setAutoresizingMask:NSViewMinXMargin];
Scott Hess - ex-Googler 2012/07/25 18:28:15 Can this line move to the initialization section i
no longer working on chromium 2012/07/26 10:17:47 Done.
+ // Add "options" popup z-ordered below all other controls so when we
+ // resize the toolbar it doesn't hide them.
+ [infoBarView_ addSubview:deviceMenu_
+ positioned:NSWindowBelow
+ relativeTo:nil];
Scott Hess - ex-Googler 2012/07/25 18:28:15 Logically, this feels like it belongs somewhere el
no longer working on chromium 2012/07/26 10:17:47 Done.
+ [GTMUILocalizerAndLayoutTweaker sizeToFitView:deviceMenu_];
Scott Hess - ex-Googler 2012/07/25 18:28:15 This seems like it might be contrary to your -size
no longer working on chromium 2012/07/26 10:17:47 removed this -sizeToFit function here.
// Make sure we get notified of infobar view size changes.
// TODO(mflodman) Find if there is a way to use 'setAutorezingMask' instead.
@@ -188,23 +184,81 @@ void SizeAndPlaceControl(NSView* toModify, NSView* anchor, bool after) {
// Set correct size for text frame.
[GTMUILocalizerAndLayoutTweaker sizeToFitView:label1_];
- // Place |okButton_| to the right of the text field.
- SizeAndPlaceControl(okButton_, label1_, true);
+ // From left to right: label_, okButton_, cancelButton_ and deviceMenu_.
Scott Hess - ex-Googler 2012/07/25 18:28:15 The comment implies that it's label, cancel, ok.
no longer working on chromium 2012/07/26 10:17:47 thanks. In linux and windows, the cancel button is
+ MoveControl(label1_, cancelButton_, spaceBetweenControls_, true);
+ MoveControl(cancelButton_, okButton_, spaceBetweenControls_, true);
+
+ // Build the device option popup menu.
+ [deviceMenu_ setHidden:NO];
+ [self rebuildDeviceMenu:NO];
+ [[deviceMenu_ cell] setArrowPosition:NSPopUpArrowAtBottom];
+ [deviceMenu_ sizeToFit];
+ MoveControl(closeButton_, deviceMenu_, spaceBetweenControls_, false);
+
+ // Hide the deviceMenu_ in case there is overlap.
Scott Hess - ex-Googler 2012/07/25 18:28:15 I think the comment could be clearer, it's only hi
no longer working on chromium 2012/07/26 10:17:47 Done.
+ if (!VerifyControlOrderAndSpacing(okButton_, deviceMenu_)) {
+ [self rebuildDeviceMenu:YES];
Scott Hess - ex-Googler 2012/07/25 18:28:15 I think that this would make more sense if you had
no longer working on chromium 2012/07/26 10:17:47 Good idea, then we don't need to rebuild the menu
+ NSRect oldFrame = [deviceMenu_ frame];
+ oldFrame.size.width = NSHeight(oldFrame);
+ [deviceMenu_ setFrame:oldFrame];
Scott Hess - ex-Googler 2012/07/25 18:28:15 Does -sizeToFit work here? Or does that allow thi
no longer working on chromium 2012/07/26 10:17:47 Thanks for pointing it out. -sizeToFit works the s
+ [[deviceMenu_ cell] setArrowPosition:NSPopUpArrowAtCenter];
+ MoveControl(closeButton_, deviceMenu_, spaceBetweenControls_, false);
+ if (!VerifyControlOrderAndSpacing(okButton_, deviceMenu_)) {
+ [deviceMenu_ setHidden:YES];
+ }
+ }
+}
+
+- (void)constructView {
+ // Use the ok button frame as inital frame for all components.
+ NSRect initFrame = [okButton_ frame];
+
+ // Setup up the text label and add the device menu to the infobar.
+ // TODO(mflodman) Use |label_| instead.
+ label1_.reset([[NSTextField alloc] init]);
+ [label1_ setEditable:NO];
+ [label1_ setDrawsBackground:NO];
+ [label1_ setBordered:NO];
+ [label1_ setFrame:[label_ frame]];
+ [[label_ superview] replaceSubview:label_ with:label1_.get()];
+ label_.reset();
+
+ deviceMenu_.reset([[NSPopUpButton alloc] initWithFrame:initFrame
+ pullsDown:YES]);
+ [deviceMenu_ setBezelStyle:NSTexturedRoundedBezelStyle];
+ NSMenu* menu = [deviceMenu_ menu];
+ [menu setDelegate:nil];
+ [menu setAutoenablesItems:NO];
+
+ // Add text to all buttons and the text field.
+ [self setLabelTexts];
- // Place |cancelButton| to the right of [okButton_|.
- SizeAndPlaceControl(cancelButton_, okButton_, true);
+ // Set each of the label and buttons to the NSTexturedRoundedBezelStyle
+ // (metal-looking) style.
+ NSArray* allControls = [self allControls];
Scott Hess - ex-Googler 2012/07/25 18:28:15 Is -allControls used anywhere else. As things cur
no longer working on chromium 2012/07/26 10:17:47 Done.
+ for (NSControl* control in allControls) {
+ if (![control isKindOfClass:[NSButton class]])
+ continue;
+ NSButton* button = (NSButton*)control;
+ [button setBezelStyle:NSTexturedRoundedBezelStyle];
+ if ([button isKindOfClass:[NSPopUpButton class]]) {
+ [[button cell] setArrowPosition:NSPopUpArrowAtBottom];
Scott Hess - ex-Googler 2012/07/25 18:28:15 My guess is that at one point you had deviceMenu_
no longer working on chromium 2012/07/26 10:17:47 sorry for the uncleaned debug code, I had moved th
+ }
+ }
+}
- // |deviceMenu_| is floating to the right, besides |closeButton_|.
- SizeAndPlaceControl(deviceMenu_, closeButton_, false);
+- (NSArray*)allControls {
+ return [NSArray arrayWithObjects:label1_.get(), okButton_,
+ cancelButton_, nil];
}
-- (void)rebuildDeviceMenu {
+- (void)rebuildDeviceMenu:(BOOL)hideTitle {
// Remove all old menu items and rebuild from scratch.
[deviceMenu_ removeAllItems];
NSMenu* menu = [deviceMenu_ menu];
// Add title item.
- NSString* menuTitle = GetNSStringWithFixup(
+ NSString* menuTitle = hideTitle ? @"" : GetNSStringWithFixup(
IDS_MEDIA_CAPTURE_DEVICES_MENU_TITLE);
NSMenuItem* titleItem =
[menu addItemWithTitle:menuTitle

Powered by Google App Engine
This is Rietveld 408576698