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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.mm

Issue 12095074: Media Galleries: Keep media gallery permission dialogs in sync with the gallery (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix nit Created 7 years, 10 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 | Annotate | Revision Log
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 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" 5 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h"
6 6
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" 8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h"
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h"
10 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" 10 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 iter != permissions.rend(); iter++) { 146 iter != permissions.rend(); iter++) {
147 const MediaGalleryPrefInfo* gallery = &iter->second.pref_info; 147 const MediaGalleryPrefInfo* gallery = &iter->second.pref_info;
148 NSString* unique_id = GetUniqueIDForGallery(gallery); 148 NSString* unique_id = GetUniqueIDForGallery(gallery);
149 if ([[[checkbox cell] representedObject] isEqual:unique_id]) { 149 if ([[[checkbox cell] representedObject] isEqual:unique_id]) {
150 controller_->DidToggleGallery(gallery, [checkbox state] == NSOnState); 150 controller_->DidToggleGallery(gallery, [checkbox state] == NSOnState);
151 break; 151 break;
152 } 152 }
153 } 153 }
154 } 154 }
155 155
156 NSButton* MediaGalleriesDialogCocoa::CheckboxForGallery(
157 const MediaGalleryPrefInfo* gallery) {
158 NSString* unique_id = GetUniqueIDForGallery(gallery);
159 for (NSButton* button in checkboxes_.get()) {
160 if ([[[button cell] representedObject] isEqual:unique_id])
161 return button;
162 }
163 return nil;
164 }
165
156 void MediaGalleriesDialogCocoa::UpdateGalleryCheckbox( 166 void MediaGalleriesDialogCocoa::UpdateGalleryCheckbox(
157 NSButton* checkbox, 167 NSButton* checkbox,
158 const MediaGalleryPrefInfo* gallery, 168 const MediaGalleryPrefInfo* gallery,
159 bool permitted) { 169 bool permitted) {
160 CGFloat y_pos = 0; 170 CGFloat y_pos = 0;
161 if (checkbox) { 171 if (checkbox) {
162 y_pos = NSMinY([checkbox frame]); 172 y_pos = NSMinY([checkbox frame]);
163 } else { 173 } else {
164 if ([checkboxes_ count] > 0) 174 if ([checkboxes_ count] > 0)
165 y_pos = NSMaxY([[checkboxes_ lastObject] frame]) + kCheckboxMargin; 175 y_pos = NSMaxY([[checkboxes_ lastObject] frame]) + kCheckboxMargin;
(...skipping 27 matching lines...) Expand all
193 203
194 void MediaGalleriesDialogCocoa::UpdateCheckboxContainerFrame() { 204 void MediaGalleriesDialogCocoa::UpdateCheckboxContainerFrame() {
195 NSRect rect = NSMakeRect( 205 NSRect rect = NSMakeRect(
196 0, 0, kCheckboxMaxWidth, NSMaxY([[checkboxes_ lastObject] frame])); 206 0, 0, kCheckboxMaxWidth, NSMaxY([[checkboxes_ lastObject] frame]));
197 [checkbox_container_ setFrame:rect]; 207 [checkbox_container_ setFrame:rect];
198 } 208 }
199 209
200 void MediaGalleriesDialogCocoa::UpdateGallery( 210 void MediaGalleriesDialogCocoa::UpdateGallery(
201 const MediaGalleryPrefInfo* gallery, 211 const MediaGalleryPrefInfo* gallery,
202 bool permitted) { 212 bool permitted) {
203 NSButton* checkbox = nil; 213 NSButton* checkbox = CheckboxForGallery(gallery);
204 NSString* unique_id = GetUniqueIDForGallery(gallery);
205
206 for (NSButton* button in checkboxes_.get()) {
207 if ([[[button cell] representedObject] isEqual:unique_id]) {
208 checkbox = button;
209 break;
210 }
211 }
212
213 UpdateGalleryCheckbox(checkbox, gallery, permitted); 214 UpdateGalleryCheckbox(checkbox, gallery, permitted);
214 UpdateCheckboxContainerFrame(); 215 UpdateCheckboxContainerFrame();
215 [alert_ layout]; 216 [alert_ layout];
216 } 217 }
218
219 void MediaGalleriesDialogCocoa::ForgetGallery(
220 const MediaGalleryPrefInfo* gallery) {
221 NSButton* checkbox = CheckboxForGallery(gallery);
222 if (!checkbox)
223 return;
224
225 // Remove checkbox and reposition the entries below it.
226 NSUInteger i = [checkboxes_ indexOfObject:checkbox];
227 [checkboxes_ removeObjectAtIndex:i];
228 for (; i < [checkboxes_ count]; ++i) {
229 CGFloat y_pos = 0;
230 if (i > 0) {
231 y_pos = NSMaxY([[checkboxes_ objectAtIndex:i - 1] frame]) +
232 kCheckboxMargin;
233 }
234 checkbox = [checkboxes_ objectAtIndex:i];
235 NSRect rect = [checkbox bounds];
236 rect.origin.y = y_pos;
237 [checkbox setFrame:rect];
238 }
239 UpdateCheckboxContainerFrame();
240 [alert_ layout];
241 }
217 242
218 void MediaGalleriesDialogCocoa::OnConstrainedWindowClosed( 243 void MediaGalleriesDialogCocoa::OnConstrainedWindowClosed(
219 ConstrainedWindowMac* window) { 244 ConstrainedWindowMac* window) {
220 controller_->DialogFinished(accepted_); 245 controller_->DialogFinished(accepted_);
221 } 246 }
222 247
223 // static 248 // static
224 MediaGalleriesDialog* MediaGalleriesDialog::Create( 249 MediaGalleriesDialog* MediaGalleriesDialog::Create(
225 MediaGalleriesDialogController* controller) { 250 MediaGalleriesDialogController* controller) {
226 scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller( 251 scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller(
227 [[MediaGalleriesCocoaController alloc] init]); 252 [[MediaGalleriesCocoaController alloc] init]);
228 return new MediaGalleriesDialogCocoa(controller, cocoa_controller); 253 return new MediaGalleriesDialogCocoa(controller, cocoa_controller);
229 } 254 }
230 255
231 } // namespace chrome 256 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698