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

Side by Side Diff: chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.mm

Issue 1025503002: Use same base class for popup and plugin blocking UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix cocoa code Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h " 5 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h "
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 webContents:(content::WebContents*)webContents 203 webContents:(content::WebContents*)webContents
204 parentWindow:(NSWindow*)parentWindow 204 parentWindow:(NSWindow*)parentWindow
205 anchoredAt:(NSPoint)anchoredAt; 205 anchoredAt:(NSPoint)anchoredAt;
206 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame 206 - (NSButton*)hyperlinkButtonWithFrame:(NSRect)frame
207 title:(NSString*)title 207 title:(NSString*)title
208 icon:(NSImage*)icon 208 icon:(NSImage*)icon
209 referenceFrame:(NSRect)referenceFrame; 209 referenceFrame:(NSRect)referenceFrame;
210 - (void)initializeBlockedPluginsList; 210 - (void)initializeBlockedPluginsList;
211 - (void)initializeTitle; 211 - (void)initializeTitle;
212 - (void)initializeRadioGroup; 212 - (void)initializeRadioGroup;
213 - (void)initializePopupList; 213 - (void)initializeItemList;
214 - (void)initializeGeoLists; 214 - (void)initializeGeoLists;
215 - (void)initializeMediaMenus; 215 - (void)initializeMediaMenus;
216 - (void)initializeMIDISysExLists; 216 - (void)initializeMIDISysExLists;
217 - (void)sizeToFitLoadButton; 217 - (void)sizeToFitLoadButton;
218 - (void)initManageDoneButtons; 218 - (void)initManageDoneButtons;
219 - (void)removeInfoButton; 219 - (void)removeInfoButton;
220 - (void)popupLinkClicked:(id)sender; 220 - (void)popupLinkClicked:(id)sender;
221 - (void)clearGeolocationForCurrentHost:(id)sender; 221 - (void)clearGeolocationForCurrentHost:(id)sender;
222 - (void)clearMIDISysExForCurrentHost:(id)sender; 222 - (void)clearMIDISysExForCurrentHost:(id)sender;
223 @end 223 @end
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 if (NSWidth(buttonFrame) > maxWidth) 377 if (NSWidth(buttonFrame) > maxWidth)
378 buttonFrame.size.width = maxWidth; 378 buttonFrame.size.width = maxWidth;
379 379
380 [button setFrame:buttonFrame]; 380 [button setFrame:buttonFrame];
381 [button setTarget:self]; 381 [button setTarget:self];
382 [button setAction:@selector(popupLinkClicked:)]; 382 [button setAction:@selector(popupLinkClicked:)];
383 return button; 383 return button;
384 } 384 }
385 385
386 - (void)initializeBlockedPluginsList { 386 - (void)initializeBlockedPluginsList {
387 NSString* label = base::SysUTF16ToNSString( 387 int delta =
388 contentSettingBubbleModel_->bubble_content().plugin_names); 388 NSMinY([titleLabel_ frame]) - NSMinY([blockedResourcesField_ frame]);
389 [blockedResourcesField_ setStringValue:label]; 389 [blockedResourcesField_ removeFromSuperview];
390 NSRect frame = [[self window] frame];
391 frame.size.height -= delta;
392 [[self window] setFrame:frame display:NO];
390 } 393 }
meacer 2015/03/20 19:40:04 This is essentially a revert of https://codereview
msw 2015/03/20 22:06:33 I'm less familiar with Cocoa, can you get c/b/ui/c
391 394
392 - (void)initializePopupList { 395 - (void)initializeItemList {
393 // I didn't put the buttons into a NSMatrix because then they are only one 396 // I didn't put the buttons into a NSMatrix because then they are only one
394 // entity in the key view loop. This way, one can tab through all of them. 397 // entity in the key view loop. This way, one can tab through all of them.
395 const ContentSettingBubbleModel::PopupItems& popupItems = 398 const ContentSettingBubbleModel::ListItems& listItems =
396 contentSettingBubbleModel_->bubble_content().popup_items; 399 contentSettingBubbleModel_->bubble_content().list_items;
397 400
398 // Get the pre-resize frame of the radio group. Its origin is where the 401 // Get the pre-resize frame of the radio group. Its origin is where the
399 // popup list should go. 402 // popup list should go.
400 NSRect radioFrame = [allowBlockRadioGroup_ frame]; 403 NSRect radioFrame = [allowBlockRadioGroup_ frame];
401 404
402 // Make room for the popup list. The bubble view and its subviews autosize 405 // Make room for the popup list. The bubble view and its subviews autosize
403 // themselves when the window is enlarged. 406 // themselves when the window is enlarged.
404 // Heading and radio box are already 1 * kLinkOuterPadding apart in the nib, 407 // Heading and radio box are already 1 * kLinkOuterPadding apart in the nib,
405 // so only 1 * kLinkOuterPadding more is needed. 408 // so only 1 * kLinkOuterPadding more is needed.
406 int delta = popupItems.size() * kLinkLineHeight - kLinkPadding + 409 int delta =
407 kLinkOuterPadding; 410 listItems.size() * kLinkLineHeight - kLinkPadding + kLinkOuterPadding;
408 NSSize deltaSize = NSMakeSize(0, delta); 411 NSSize deltaSize = NSMakeSize(0, delta);
409 deltaSize = [[[self window] contentView] convertSize:deltaSize toView:nil]; 412 deltaSize = [[[self window] contentView] convertSize:deltaSize toView:nil];
410 NSRect windowFrame = [[self window] frame]; 413 NSRect windowFrame = [[self window] frame];
411 windowFrame.size.height += deltaSize.height; 414 windowFrame.size.height += deltaSize.height;
412 [[self window] setFrame:windowFrame display:NO]; 415 [[self window] setFrame:windowFrame display:NO];
413 416
414 // Create popup list. 417 // Create item list.
415 int topLinkY = NSMaxY(radioFrame) + delta - kLinkHeight; 418 int topLinkY = NSMaxY(radioFrame) + delta - kLinkHeight;
416 int row = 0; 419 int row = 0;
417 for (std::vector<ContentSettingBubbleModel::PopupItem>::const_iterator 420 for (std::vector<ContentSettingBubbleModel::ListItem>::const_iterator
418 it(popupItems.begin()); it != popupItems.end(); ++it, ++row) { 421 it(listItems.begin());
422 it != listItems.end(); ++it, ++row) {
419 NSImage* image = it->image.AsNSImage(); 423 NSImage* image = it->image.AsNSImage();
420
421 std::string title(it->title);
422 // The popup may not have committed a load yet, in which case it won't
msw 2015/03/20 22:06:33 Why did you remove this? Is this no longer an issu
meacer 2015/03/20 23:39:42 Removed from here as this check is already done at
msw 2015/03/21 00:25:19 Acknowledged.
423 // have a URL or title.
424 if (title.empty())
425 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE);
426
427 NSRect linkFrame = 424 NSRect linkFrame =
428 NSMakeRect(NSMinX(radioFrame), topLinkY - kLinkLineHeight * row, 425 NSMakeRect(NSMinX(radioFrame), topLinkY - kLinkLineHeight * row,
429 200, kLinkHeight); 426 200, kLinkHeight);
430 NSButton* button = [self 427 NSButton* button =
431 hyperlinkButtonWithFrame:linkFrame 428 [self hyperlinkButtonWithFrame:linkFrame
432 title:base::SysUTF8ToNSString(title) 429 title:base::SysUTF8ToNSString(it->title)
433 icon:image 430 icon:image
434 referenceFrame:radioFrame]; 431 referenceFrame:radioFrame];
435 [[self bubble] addSubview:button]; 432 [[self bubble] addSubview:button];
436 popupLinks_[button] = row; 433 popupLinks_[button] = row;
437 } 434 }
438 } 435 }
439 436
440 - (void)initializeGeoLists { 437 - (void)initializeGeoLists {
441 // Cocoa has its origin in the lower left corner. This means elements are 438 // Cocoa has its origin in the lower left corner. This means elements are
442 // added from bottom to top, which explains why loops run backwards and the 439 // added from bottom to top, which explains why loops run backwards and the
443 // order of operations is the other way than on Linux/Windows. 440 // order of operations is the other way than on Linux/Windows.
444 const ContentSettingBubbleModel::BubbleContent& content = 441 const ContentSettingBubbleModel::BubbleContent& content =
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 738
742 ContentSettingsType type = contentSettingBubbleModel_->content_type(); 739 ContentSettingsType type = contentSettingBubbleModel_->content_type();
743 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { 740 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) {
744 [self sizeToFitLoadButton]; 741 [self sizeToFitLoadButton];
745 [self initializeBlockedPluginsList]; 742 [self initializeBlockedPluginsList];
746 } 743 }
747 744
748 if (allowBlockRadioGroup_) // not bound in cookie bubble xib 745 if (allowBlockRadioGroup_) // not bound in cookie bubble xib
749 [self initializeRadioGroup]; 746 [self initializeRadioGroup];
750 747
751 if (type == CONTENT_SETTINGS_TYPE_POPUPS) 748 if (type == CONTENT_SETTINGS_TYPE_POPUPS ||
752 [self initializePopupList]; 749 type == CONTENT_SETTINGS_TYPE_PLUGINS)
750 [self initializeItemList];
753 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) 751 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
754 [self initializeGeoLists]; 752 [self initializeGeoLists];
755 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) 753 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM)
756 [self initializeMediaMenus]; 754 [self initializeMediaMenus];
757 if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) 755 if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX)
758 [self initializeMIDISysExLists]; 756 [self initializeMIDISysExLists];
759 } 757 }
760 758
761 /////////////////////////////////////////////////////////////////////////////// 759 ///////////////////////////////////////////////////////////////////////////////
762 // Actual application logic 760 // Actual application logic
763 761
764 - (IBAction)allowBlockToggled:(id)sender { 762 - (IBAction)allowBlockToggled:(id)sender {
765 NSButtonCell *selectedCell = [sender selectedCell]; 763 NSButtonCell *selectedCell = [sender selectedCell];
766 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1); 764 contentSettingBubbleModel_->OnRadioClicked([selectedCell tag] - 1);
767 } 765 }
768 766
769 - (void)popupLinkClicked:(id)sender { 767 - (void)popupLinkClicked:(id)sender {
770 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender)); 768 content_setting_bubble::PopupLinks::iterator i(popupLinks_.find(sender));
771 DCHECK(i != popupLinks_.end()); 769 DCHECK(i != popupLinks_.end());
772 contentSettingBubbleModel_->OnPopupClicked(i->second); 770 contentSettingBubbleModel_->OnListItemClicked(i->second);
773 } 771 }
774 772
775 - (void)clearGeolocationForCurrentHost:(id)sender { 773 - (void)clearGeolocationForCurrentHost:(id)sender {
776 contentSettingBubbleModel_->OnCustomLinkClicked(); 774 contentSettingBubbleModel_->OnCustomLinkClicked();
777 [self close]; 775 [self close];
778 } 776 }
779 777
780 - (void)clearMIDISysExForCurrentHost:(id)sender { 778 - (void)clearMIDISysExForCurrentHost:(id)sender {
781 contentSettingBubbleModel_->OnCustomLinkClicked(); 779 contentSettingBubbleModel_->OnCustomLinkClicked();
782 [self close]; 780 [self close];
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index))); 814 button, base::SysUTF16ToNSString(it->second->model->GetLabelAt(index)));
817 815
818 it->second->model->ExecuteCommand(index, 0); 816 it->second->model->ExecuteCommand(index, 0);
819 } 817 }
820 818
821 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus { 819 - (content_setting_bubble::MediaMenuPartsMap*)mediaMenus {
822 return &mediaMenus_; 820 return &mediaMenus_;
823 } 821 }
824 822
825 @end // ContentSettingBubbleController 823 @end // ContentSettingBubbleController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698