summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorhawk@chromium.org <hawk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-16 00:26:37 +0000
committerhawk@chromium.org <hawk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-16 00:26:37 +0000
commit0018067c7afbdf516d1845b35a3a245d96910f66 (patch)
tree4be869c69201a6f3804560fa5e9c1136e8755a82 /chrome/browser
parent738fae30536f358b22bbcb6a72d9f0c54bf6cf6a (diff)
downloadchromium_src-0018067c7afbdf516d1845b35a3a245d96910f66.zip
chromium_src-0018067c7afbdf516d1845b35a3a245d96910f66.tar.gz
chromium_src-0018067c7afbdf516d1845b35a3a245d96910f66.tar.bz2
Add SSL icons on Mac OS X
BUG=14899 TEST=https sites have a lock icon in the address field, plain http sites do not Review URL: http://codereview.chromium.org/199072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26307 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell.h6
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell.mm45
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm41
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.h6
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.mm25
5 files changed, 122 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.h b/chrome/browser/cocoa/autocomplete_text_field_cell.h
index 9723226..9bca85d 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell.h
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell.h
@@ -37,6 +37,9 @@
// YES if the info cell has been changed in a way which would result
// in the cell needing to be laid out again.
BOOL fieldEditorNeedsReset_;
+
+ // Icon that represents the state of the SSL connection
+ scoped_nsobject<NSImage> hintIcon_;
}
@property BOOL fieldEditorNeedsReset;
@@ -56,6 +59,8 @@
- (void)setSearchHintString:(NSString*)aString;
- (void)clearKeywordAndHint;
+- (void)setHintIcon:(NSImage*)icon;
+
// Return the portion of the cell to show the text cursor over.
- (NSRect)textCursorFrameForFrame:(NSRect)cellFrame;
@@ -69,5 +74,6 @@
@property(readonly) NSAttributedString* keywordString;
@property(readonly) NSAttributedString* hintString;
+@property(readonly) NSImage* hintIcon;
@end
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
index e065c14..d93e518 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
@@ -39,6 +39,9 @@ const NSInteger kKeywordHintImageBaseline = -6;
// use that.
const NSInteger kBaselineOffset = 4;
+// The amount of padding on either side reserved for drawing the hint icon
+const NSInteger kHintIconHorizontalPad = 5;
+
} // namespace
@implementation AutocompleteTextFieldCell
@@ -156,6 +159,15 @@ const NSInteger kBaselineOffset = 4;
}
}
+- (void)setHintIcon:(NSImage*)icon {
+ if (icon != hintIcon_) {
+ hintIcon_.reset([icon retain]);
+ if (!keywordString_ && !hintString_) {
+ fieldEditorNeedsReset_ = YES;
+ }
+ }
+}
+
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
DCHECK([controlView isFlipped]);
[[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set];
@@ -219,6 +231,12 @@ const NSInteger kBaselineOffset = 4;
textFrame.origin.x += keywordWidth;
textFrame.size.width = NSMaxX(cellFrame) - NSMinX(textFrame);
}
+ } else if (hintIcon_) {
+ CGFloat width = [hintIcon_ size].width;
+ width += kHintIconHorizontalPad * 2;
+ if (width < NSWidth(cellFrame)) {
+ textFrame.size.width -= width;
+ }
}
return textFrame;
@@ -265,11 +283,38 @@ const NSInteger kBaselineOffset = 4;
[keywordString_.get() drawInRect:infoFrame];
}
+- (void)drawHintIconWithFrame:(NSRect)cellFrame
+ inView:(NSView*)controlView {
+ // We'll draw the entire image
+ NSRect imageRect = NSZeroRect;
+ imageRect.size = [hintIcon_ size];
+
+ // Move the rect that we're drawing into to the far right
+ cellFrame.origin.x += cellFrame.size.width - imageRect.size.width;
+ // Add back the padding
+ cellFrame.origin.x -= kHintIconHorizontalPad;
+
+ // Center the image vertically in the frame
+ cellFrame.origin.y +=
+ floor((cellFrame.size.height - imageRect.size.height) / 2);
+
+ // Set the drawing size to the image size
+ cellFrame.size = imageRect.size;
+
+ [hintIcon_ setFlipped:[controlView isFlipped]];
+ [hintIcon_ drawInRect:cellFrame
+ fromRect:imageRect
+ operation:NSCompositeSourceOver
+ fraction:1.0];
+}
+
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
if (hintString_) {
[self drawHintWithFrame:cellFrame inView:controlView];
} else if (keywordString_) {
[self drawKeywordWithFrame:cellFrame inView:controlView];
+ } else if (hintIcon_) {
+ [self drawHintIconWithFrame:cellFrame inView:controlView];
}
[super drawInteriorWithFrame:[self textFrameForFrame:cellFrame]
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
index 0f6c801..8a6b4cd 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
@@ -135,6 +135,31 @@ TEST_F(AutocompleteTextFieldCellTest, KeywordString) {
EXPECT_FALSE([cell fieldEditorNeedsReset]);
}
+TEST_F(AutocompleteTextFieldCellTest, SecurityIcon) {
+ AutocompleteTextFieldCell* cell =
+ static_cast<AutocompleteTextFieldCell*>([view_ cell]);
+
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ NSImage* image1 = [NSImage imageNamed:@"NSApplicationIcon"];
+ // Setting a security icon will need a reset.
+ [cell setHintIcon:image1];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing the security icon needs a reset.
+ NSImage* image2 = [NSImage imageNamed:@"NSComputer"];
+ [cell setHintIcon:image2];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing to an identical security icon doesn't need a reset.
+ [cell setHintIcon:image2];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+}
+
// Test that transitions between various modes set the reset flag.
TEST_F(AutocompleteTextFieldCellTest, Transitions) {
AutocompleteTextFieldCell* cell =
@@ -261,6 +286,22 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) {
EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame));
EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
+
+ // Hint icon takes up space on the right
+ [cell setHintIcon:[NSImage imageNamed:@"NSComputer"]];
+ textFrame = [cell textFrameForFrame:bounds];
+ EXPECT_FALSE(NSIsEmptyRect(textFrame));
+ EXPECT_TRUE(NSContainsRect(bounds, textFrame));
+ EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds));
+ EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
+
+ // Search hint text takes precedence over the hint icon; the text frame
+ // should be smaller in order to accomodate the text that is wider than
+ // the icon.
+ [cell setSearchHintString:@"Search hint"];
+ NSRect textFrameWithHintText = [cell textFrameForFrame:bounds];
+ EXPECT_TRUE(NSContainsRect(textFrame, textFrameWithHintText));
+ EXPECT_LT(NSWidth(textFrameWithHintText), NSWidth(textFrame));
}
} // namespace
diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h
index d765a83..e305544 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.h
+++ b/chrome/browser/cocoa/location_bar_view_mac.h
@@ -12,6 +12,7 @@
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
#include "chrome/browser/location_bar.h"
+#include "chrome/browser/toolbar_model.h"
@class AutocompleteTextField;
class BubblePositioner;
@@ -84,6 +85,9 @@ class LocationBarViewMac : public AutocompleteEditController,
NSImage* image);
private:
+ // Set the SSL icon we should be showing.
+ void SetSecurityIcon(ToolbarModel::Icon icon);
+
scoped_ptr<AutocompleteEditViewMac> edit_view_;
CommandUpdater* command_updater_; // Weak, owned by Browser.
@@ -100,6 +104,8 @@ class LocationBarViewMac : public AutocompleteEditController,
Profile* profile_;
+ ToolbarModel* toolbar_model_; // Weak, owned by Browser.
+
// Image used in drawing keyword hint.
scoped_nsobject<NSImage> tab_button_image_;
diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm
index 42262ee..0701752 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar_view_mac.mm
@@ -57,6 +57,7 @@ LocationBarViewMac::LocationBarViewMac(
field_(field),
disposition_(CURRENT_TAB),
profile_(profile),
+ toolbar_model_(toolbar_model),
transition_(PageTransition::TYPED) {
}
@@ -108,6 +109,7 @@ void LocationBarViewMac::SaveStateToContents(TabContents* contents) {
void LocationBarViewMac::Update(const TabContents* contents,
bool should_restore_state) {
+ SetSecurityIcon(toolbar_model_->GetIcon());
// AutocompleteEditView restores state if the tab is non-NULL.
edit_view_->Update(should_restore_state ? contents : NULL);
}
@@ -222,7 +224,8 @@ void LocationBarViewMac::OnChanged() {
}
void LocationBarViewMac::OnInputInProgress(bool in_progress) {
- NOTIMPLEMENTED();
+ toolbar_model_->set_input_in_progress(in_progress);
+ Update(NULL, false);
}
void LocationBarViewMac::OnSetFocus() {
@@ -262,3 +265,23 @@ NSImage* LocationBarViewMac::GetTabButtonImage() {
}
return tab_button_image_;
}
+
+void LocationBarViewMac::SetSecurityIcon(ToolbarModel::Icon security_icon) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
+ switch (security_icon) {
+ case ToolbarModel::LOCK_ICON:
+ [cell setHintIcon:rb.GetNSImageNamed(IDR_LOCK)];
+ break;
+ case ToolbarModel::WARNING_ICON:
+ [cell setHintIcon:rb.GetNSImageNamed(IDR_WARNING)];
+ break;
+ case ToolbarModel::NO_ICON:
+ [cell setHintIcon:nil];
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ [field_ resetFieldEditorFrameIfNeeded];
+}