summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 01:53:43 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 01:53:43 +0000
commit1c658ef8ae0835ecffc1f4061c00e84b2ddea927 (patch)
treec3103572ba65ef829112dcd341d77396f02a8cb4 /chrome
parent588dab08d67e949c216ebb1048877dca0d9118bf (diff)
downloadchromium_src-1c658ef8ae0835ecffc1f4061c00e84b2ddea927.zip
chromium_src-1c658ef8ae0835ecffc1f4061c00e84b2ddea927.tar.gz
chromium_src-1c658ef8ae0835ecffc1f4061c00e84b2ddea927.tar.bz2
Mac: Fill in geolocation bubble from model.
xib changes: Removed everything above the horizontal line and put an empty NSView there, as container for the geo stuff (maybe later, there should be only one xib file for all bubble types and the container should be filled from the bubble model in all cases. Not in this CL.) http://imgur.com/AtXiq BUG=11246 TEST=Start chromium with --enable-geolocation. Go to http://maxheapsize.com/static/html5geolocationdemo.html , click "Allow" or "Deny". Bubble should appear. It should behave like on windows or linux (except that it has buttons instead of links. We only use links for stuff that opens web pages on clicking on OS X.) Review URL: http://codereview.chromium.org/1542001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/nibs/ContentBubbleGeolocation.xib195
-rw-r--r--chrome/browser/cocoa/content_blocked_bubble_controller.h3
-rw-r--r--chrome/browser/cocoa/content_blocked_bubble_controller.mm120
3 files changed, 147 insertions, 171 deletions
diff --git a/chrome/app/nibs/ContentBubbleGeolocation.xib b/chrome/app/nibs/ContentBubbleGeolocation.xib
index 2eb0367..170d02f 100644
--- a/chrome/app/nibs/ContentBubbleGeolocation.xib
+++ b/chrome/app/nibs/ContentBubbleGeolocation.xib
@@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="28"/>
+ <integer value="4"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -37,7 +37,7 @@
<object class="NSWindowTemplate" id="1005">
<int key="NSWindowStyleMask">15</int>
<int key="NSWindowBacking">2</int>
- <string key="NSWindowRect">{{196, 364}, {316, 146}}</string>
+ <string key="NSWindowRect">{{196, 422}, {316, 88}}</string>
<int key="NSWTFlags">536873984</int>
<string key="NSWindowTitle">Window</string>
<string key="NSWindowClass">InfoBubbleWindow</string>
@@ -53,58 +53,6 @@
<int key="NSvFlags">274</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSTextField" id="266815090">
- <reference key="NSNextResponder" ref="301729179"/>
- <int key="NSvFlags">268</int>
- <string key="NSFrame">{{17, 112}, {282, 14}}</string>
- <reference key="NSSuperview" ref="301729179"/>
- <bool key="NSEnabled">YES</bool>
- <object class="NSTextFieldCell" key="NSCell" id="157361777">
- <int key="NSCellFlags">67239424</int>
- <int key="NSCellFlags2">272760832</int>
- <string key="NSContents">^IDS_GEOLOCATION_BUBBLE_SECTION_ALLOWED</string>
- <object class="NSFont" key="NSSupport" id="26">
- <string key="NSName">LucidaGrande</string>
- <double key="NSSize">1.100000e+01</double>
- <int key="NSfFlags">3100</int>
- </object>
- <reference key="NSControlView" ref="266815090"/>
- <object class="NSColor" key="NSBackgroundColor" id="538238921">
- <int key="NSColorSpace">6</int>
- <string key="NSCatalogName">System</string>
- <string key="NSColorName">controlColor</string>
- <object class="NSColor" key="NSColor">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MC42NjY2NjY2OQA</bytes>
- </object>
- </object>
- <object class="NSColor" key="NSTextColor" id="1045173010">
- <int key="NSColorSpace">6</int>
- <string key="NSCatalogName">System</string>
- <string key="NSColorName">controlTextColor</string>
- <object class="NSColor" key="NSColor">
- <int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MAA</bytes>
- </object>
- </object>
- </object>
- </object>
- <object class="NSTextField" id="796713408">
- <reference key="NSNextResponder" ref="301729179"/>
- <int key="NSvFlags">268</int>
- <string key="NSFrame">{{17, 90}, {282, 14}}</string>
- <reference key="NSSuperview" ref="301729179"/>
- <bool key="NSEnabled">YES</bool>
- <object class="NSTextFieldCell" key="NSCell" id="824436824">
- <int key="NSCellFlags">67239424</int>
- <int key="NSCellFlags2">272760832</int>
- <string key="NSContents">^IDS_GEOLOCATION_BUBBLE_SECTION_DENIED</string>
- <reference key="NSSupport" ref="26"/>
- <reference key="NSControlView" ref="796713408"/>
- <reference key="NSBackgroundColor" ref="538238921"/>
- <reference key="NSTextColor" ref="1045173010"/>
- </object>
- </object>
<object class="NSBox" id="913795455">
<reference key="NSNextResponder" ref="301729179"/>
<int key="NSvFlags">36</int>
@@ -154,7 +102,11 @@
<int key="NSCellFlags">67239424</int>
<int key="NSCellFlags2">134348800</int>
<string key="NSContents">^IDS_GEOLOCATION_BUBBLE_MANAGE_LINK</string>
- <reference key="NSSupport" ref="26"/>
+ <object class="NSFont" key="NSSupport" id="26">
+ <string key="NSName">LucidaGrande</string>
+ <double key="NSSize">1.100000e+01</double>
+ <int key="NSfFlags">3100</int>
+ </object>
<reference key="NSControlView" ref="91589614"/>
<int key="NSButtonFlags">-2038284033</int>
<int key="NSButtonFlags2">129</int>
@@ -199,49 +151,20 @@
<reference key="NSSuperview" ref="301729179"/>
<string key="NSClassName">GTMWidthBasedTweaker</string>
</object>
- <object class="NSButton" id="78007284">
- <reference key="NSNextResponder" ref="301729179"/>
- <int key="NSvFlags">268</int>
- <string key="NSFrame">{{20, 52}, {137, 17}}</string>
- <reference key="NSSuperview" ref="301729179"/>
- <bool key="NSEnabled">YES</bool>
- <object class="NSButtonCell" key="NSCell" id="812065">
- <int key="NSCellFlags">-1543373312</int>
- <int key="NSCellFlags2">134348800</int>
- <string key="NSContents">^IDS_GEOLOCATION_BUBBLE_CLEAR_LINK</string>
- <reference key="NSSupport" ref="26"/>
- <reference key="NSControlView" ref="78007284"/>
- <int key="NSButtonFlags">-2038152961</int>
- <int key="NSButtonFlags2">164</int>
- <string key="NSAlternateContents"/>
- <string key="NSKeyEquivalent"/>
- <int key="NSPeriodicDelay">400</int>
- <int key="NSPeriodicInterval">75</int>
- </object>
- </object>
- <object class="NSTextField" id="388109161">
+ <object class="NSCustomView" id="1034822360">
<reference key="NSNextResponder" ref="301729179"/>
- <int key="NSvFlags">268</int>
- <string key="NSFrame">{{222, 55}, {77, 14}}</string>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{20, 54}, {276, 14}}</string>
<reference key="NSSuperview" ref="301729179"/>
- <bool key="NSEnabled">YES</bool>
- <object class="NSTextFieldCell" key="NSCell" id="159762990">
- <int key="NSCellFlags">68288064</int>
- <int key="NSCellFlags2">272761856</int>
- <string key="NSContents">Not done yet.</string>
- <reference key="NSSupport" ref="26"/>
- <reference key="NSControlView" ref="388109161"/>
- <reference key="NSBackgroundColor" ref="538238921"/>
- <reference key="NSTextColor" ref="1045173010"/>
- </object>
+ <string key="NSClassName">NSView</string>
</object>
</object>
- <string key="NSFrameSize">{316, 146}</string>
+ <string key="NSFrameSize">{316, 88}</string>
<reference key="NSSuperview" ref="1006"/>
<string key="NSClassName">InfoBubbleView</string>
</object>
</object>
- <string key="NSFrameSize">{316, 146}</string>
+ <string key="NSFrameSize">{316, 88}</string>
<reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
@@ -313,6 +236,14 @@
</object>
<int key="connectionID">26</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">contentsContainer_</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="1034822360"/>
+ </object>
+ <int key="connectionID">43</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -366,31 +297,14 @@
<reference key="object" ref="301729179"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="266815090"/>
<reference ref="913795455"/>
<reference ref="395762087"/>
<reference ref="730386640"/>
- <reference ref="796713408"/>
- <reference ref="78007284"/>
- <reference ref="388109161"/>
+ <reference ref="1034822360"/>
</object>
<reference key="parent" ref="1006"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">7</int>
- <reference key="object" ref="266815090"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="157361777"/>
- </object>
- <reference key="parent" ref="301729179"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">8</int>
- <reference key="object" ref="157361777"/>
- <reference key="parent" ref="266815090"/>
- </object>
- <object class="IBObjectRecord">
<int key="objectID">20</int>
<reference key="object" ref="670916757"/>
<reference key="parent" ref="1002"/>
@@ -452,47 +366,10 @@
<reference key="parent" ref="91589614"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">31</int>
- <reference key="object" ref="796713408"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="824436824"/>
- </object>
- <reference key="parent" ref="301729179"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">32</int>
- <reference key="object" ref="824436824"/>
- <reference key="parent" ref="796713408"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">35</int>
- <reference key="object" ref="78007284"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="812065"/>
- </object>
- <reference key="parent" ref="301729179"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">36</int>
- <reference key="object" ref="812065"/>
- <reference key="parent" ref="78007284"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">37</int>
- <reference key="object" ref="388109161"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="159762990"/>
- </object>
+ <int key="objectID">42</int>
+ <reference key="object" ref="1034822360"/>
<reference key="parent" ref="301729179"/>
</object>
- <object class="IBObjectRecord">
- <int key="objectID">38</int>
- <reference key="object" ref="159762990"/>
- <reference key="parent" ref="388109161"/>
- </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -516,24 +393,17 @@
<string>2.IBPluginDependency</string>
<string>20.IBPluginDependency</string>
<string>21.IBPluginDependency</string>
- <string>31.IBPluginDependency</string>
- <string>32.IBPluginDependency</string>
- <string>35.IBPluginDependency</string>
- <string>36.IBPluginDependency</string>
- <string>37.IBPluginDependency</string>
- <string>38.IBPluginDependency</string>
<string>4.IBPluginDependency</string>
- <string>7.IBPluginDependency</string>
- <string>8.IBPluginDependency</string>
+ <string>42.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{345, 550}, {316, 146}}</string>
+ <string>{{92, 411}, {316, 88}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{345, 550}, {316, 146}}</string>
+ <string>{{92, 411}, {316, 88}}</string>
<boolean value="NO"/>
<string>{196, 240}</string>
<string>{{357, 418}, {480, 270}}</string>
@@ -547,13 +417,6 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -576,7 +439,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">38</int>
+ <int key="maxID">44</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -621,12 +484,14 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>allowBlockRadioGroup_</string>
<string>bubble_</string>
+ <string>contentsContainer_</string>
<string>titleLabel_</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSMatrix</string>
<string>InfoBubbleView</string>
+ <string>NSView</string>
<string>NSTextField</string>
</object>
</object>
diff --git a/chrome/browser/cocoa/content_blocked_bubble_controller.h b/chrome/browser/cocoa/content_blocked_bubble_controller.h
index bf09603..6b325a4 100644
--- a/chrome/browser/cocoa/content_blocked_bubble_controller.h
+++ b/chrome/browser/cocoa/content_blocked_bubble_controller.h
@@ -31,6 +31,9 @@ typedef std::map<NSButton*, int> PopupLinks;
IBOutlet NSTextField* titleLabel_;
IBOutlet NSMatrix* allowBlockRadioGroup_;
+ // The container for the bubble contents of the geolocation bubble.
+ IBOutlet NSView* contentsContainer_;
+
scoped_ptr<ContentSettingBubbleModel> contentSettingBubbleModel_;
content_blocked_bubble::PopupLinks popupLinks_;
}
diff --git a/chrome/browser/cocoa/content_blocked_bubble_controller.mm b/chrome/browser/cocoa/content_blocked_bubble_controller.mm
index 3d92b55..ae3a3e6 100644
--- a/chrome/browser/cocoa/content_blocked_bubble_controller.mm
+++ b/chrome/browser/cocoa/content_blocked_bubble_controller.mm
@@ -41,6 +41,19 @@ const int kLinkLineHeight = kLinkHeight + kLinkPadding;
// Space between popup list and surrounding UI elements.
const int kLinkOuterPadding = 8;
+// Height of each of the labels in the geolocation bubble.
+const int kGeoLabelHeight = 14;
+
+// Height of the "Clear" button in the geolocation bubble.
+const int kGeoClearButtonHeight = 17;
+
+// General padding between elements in the geolocation bubble.
+const int kGeoPadding = 8;
+
+// Padding between host names in the geolocation bubble.
+const int kGeoHostPadding = 4;
+
+
// Like |ReplaceStringPlaceholders(const string16&, const string16&, size_t*)|,
// but for a NSString formatString.
NSString* ReplaceNSStringPlaceholders(NSString* formatString,
@@ -52,6 +65,24 @@ NSString* ReplaceNSStringPlaceholders(NSString* formatString,
offset));
}
+void SetControlSize(NSControl* control, NSControlSize controlSize) {
+ CGFloat fontSize = [NSFont systemFontSizeForControlSize:controlSize];
+ NSCell* cell = [control cell];
+ NSFont* font = [NSFont fontWithName:[[cell font] fontName] size:fontSize];
+ [cell setFont:font];
+ [cell setControlSize:controlSize];
+}
+
+// Returns an autoreleased NSTextField that is configured to look like a Label
+// looks in Interface Builder.
+NSTextField* LabelWithFrame(NSString* text, const NSRect& frame) {
+ NSTextField* label = [[NSTextField alloc] initWithFrame:frame];
+ [label setStringValue:text];
+ [label setSelectable:NO];
+ [label setBezeled:NO];
+ return [label autorelease];
+}
+
} // namespace
@interface ContentBlockedBubbleController(Private)
@@ -65,7 +96,9 @@ NSString* ReplaceNSStringPlaceholders(NSString* formatString,
- (void)initializeTitle;
- (void)initializeRadioGroup;
- (void)initializePopupList;
+- (void)initializeGeoLists;
- (void)popupLinkClicked:(id)sender;
+- (void)clearGeolocationForCurrentHost:(id)sender;
@end
@implementation ContentBlockedBubbleController
@@ -120,16 +153,16 @@ NSString* ReplaceNSStringPlaceholders(NSString* formatString,
- (void)initializeTitle {
if (!titleLabel_)
- return; // Make valgrind happy for now.
+ return;
// Layout title post-localization.
- CGFloat titleDeltaY = [GTMUILocalizerAndLayoutTweaker
+ CGFloat deltaY = [GTMUILocalizerAndLayoutTweaker
sizeToFitFixedWidthTextField:titleLabel_];
NSRect windowFrame = [[self window] frame];
- windowFrame.size.height += titleDeltaY;
+ windowFrame.size.height += deltaY;
[[self window] setFrame:windowFrame display:NO];
NSRect titleFrame = [titleLabel_ frame];
- titleFrame.origin.y -= titleDeltaY;
+ titleFrame.origin.y -= deltaY;
[titleLabel_ setFrame:titleFrame];
}
@@ -248,6 +281,73 @@ NSString* ReplaceNSStringPlaceholders(NSString* formatString,
}
}
+- (void)initializeGeoLists {
+ // Cocoa has its origin in the lower left corner. This means elements are
+ // added from bottom to top, which explains why loops run backwards and the
+ // order of operations is the other way than on Linux/Windows.
+ const ContentSettingBubbleModel::BubbleContent& content =
+ contentSettingBubbleModel_->bubble_content();
+ NSRect containerFrame = [contentsContainer_ frame];
+ NSRect frame = NSMakeRect(0, 0, containerFrame.size.width, kGeoLabelHeight);
+
+ // "Clear" button.
+ if (!content.clear_link.empty()) {
+ NSRect buttonFrame = NSMakeRect(0, 0,
+ containerFrame.size.width,
+ kGeoClearButtonHeight);
+ NSButton* button = [[NSButton alloc] initWithFrame:buttonFrame];
+ [button setTitle:base::SysUTF8ToNSString(content.clear_link)];
+ [button setTarget:self];
+ [button setAction:@selector(clearGeolocationForCurrentHost:)];
+ [button setBezelStyle:NSRoundRectBezelStyle];
+ SetControlSize(button, NSSmallControlSize);
+ [button sizeToFit];
+ [contentsContainer_ addSubview:button];
+
+ frame.origin.y = NSMaxY([button frame]) + kGeoPadding;
+ }
+
+ typedef
+ std::vector<ContentSettingBubbleModel::DomainList>::const_reverse_iterator
+ GeolocationGroupIterator;
+ for (GeolocationGroupIterator i = content.domain_lists.rbegin();
+ i != content.domain_lists.rend(); ++i) {
+ // Add all hosts in the current domain list.
+ for (std::set<std::string>::const_reverse_iterator j = i->hosts.rbegin();
+ j != i->hosts.rend(); ++j) {
+ NSTextField* title = LabelWithFrame(base::SysUTF8ToNSString(*j), frame);
+ SetControlSize(title, NSSmallControlSize);
+ [contentsContainer_ addSubview:title];
+
+ frame.origin.y = NSMaxY(frame) + kGeoHostPadding +
+ [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title];
+ }
+ if (!i->hosts.empty())
+ frame.origin.y += kGeoPadding - kGeoHostPadding;
+
+ // Add the domain list's title.
+ NSTextField* title =
+ LabelWithFrame(base::SysUTF8ToNSString(i->title), frame);
+ SetControlSize(title, NSSmallControlSize);
+ [contentsContainer_ addSubview:title];
+
+ frame.origin.y = NSMaxY(frame) + kGeoPadding +
+ [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title];
+ }
+
+ CGFloat containerHeight = frame.origin.y;
+ // Undo last padding.
+ if (!content.domain_lists.empty())
+ containerHeight -= kGeoPadding;
+
+ // Resize container to fit its subviews, and window to fit the container.
+ NSRect windowFrame = [[self window] frame];
+ windowFrame.size.height += containerHeight - containerFrame.size.height;
+ [[self window] setFrame:windowFrame display:NO];
+ containerFrame.size.height = containerHeight;
+ [contentsContainer_ setFrame:containerFrame];
+}
+
- (void)awakeFromNib {
DCHECK([self window]);
DCHECK_EQ(self, [[self window] delegate]);
@@ -258,9 +358,12 @@ NSString* ReplaceNSStringPlaceholders(NSString* formatString,
[self initializeTitle];
if (allowBlockRadioGroup_) // not bound in cookie bubble xib
[self initializeRadioGroup];
- if (contentSettingBubbleModel_->content_type()
- == CONTENT_SETTINGS_TYPE_POPUPS)
+ if (contentSettingBubbleModel_->content_type() ==
+ CONTENT_SETTINGS_TYPE_POPUPS)
[self initializePopupList];
+ if (contentSettingBubbleModel_->content_type() ==
+ CONTENT_SETTINGS_TYPE_GEOLOCATION)
+ [self initializeGeoLists];
}
///////////////////////////////////////////////////////////////////////////////
@@ -353,4 +456,9 @@ NSString* ReplaceNSStringPlaceholders(NSString* formatString,
contentSettingBubbleModel_->OnPopupClicked(i->second);
}
+- (void)clearGeolocationForCurrentHost:(id)sender {
+ contentSettingBubbleModel_->OnClearLinkClicked();
+ [self close];
+}
+
@end // ContentBlockedBubbleController