summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 02:30:05 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 02:30:05 +0000
commit29193b9b0af28ed636ebad88d82f3e32466b3f76 (patch)
tree064e2e8ee3e001274f6f1975bedf3096b48e4b7f /chrome/browser/cocoa
parent4b196999d76e86cf0f0b418cf260c2bfb41bc4de (diff)
downloadchromium_src-29193b9b0af28ed636ebad88d82f3e32466b3f76.zip
chromium_src-29193b9b0af28ed636ebad88d82f3e32466b3f76.tar.gz
chromium_src-29193b9b0af28ed636ebad88d82f3e32466b3f76.tar.bz2
[Mac] Show the page info window after clicking the security icon in the URL bar
BUG=22922 TEST=Go to https://twitter.com, click the lock icon, see page info window. Review URL: http://codereview.chromium.org/222020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28221 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field.h4
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field.mm11
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell.h3
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell.mm36
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm34
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_unittest.mm12
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h1
7 files changed, 86 insertions, 15 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field.h b/chrome/browser/cocoa/autocomplete_text_field.h
index f850a27..be88561 100644
--- a/chrome/browser/cocoa/autocomplete_text_field.h
+++ b/chrome/browser/cocoa/autocomplete_text_field.h
@@ -49,6 +49,10 @@ class AutocompleteTextFieldObserver {
// Called when the user initiates a "paste and go" or "paste and
// search" into |field_|.
virtual void OnPasteAndGo() = 0;
+
+ // Called when the user clicks the hint icon (i.e. the security icon) in the
+ // location bar.
+ virtual void OnSecurityIconClicked() = 0;
};
@interface AutocompleteTextField : NSTextField {
diff --git a/chrome/browser/cocoa/autocomplete_text_field.mm b/chrome/browser/cocoa/autocomplete_text_field.mm
index 1f2c23f4..60a7a56 100644
--- a/chrome/browser/cocoa/autocomplete_text_field.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field.mm
@@ -94,7 +94,8 @@
const NSPoint locationInWindow = [theEvent locationInWindow];
const NSPoint location = [self convertPoint:locationInWindow fromView:nil];
- const NSRect textFrame = [[self cell] textFrameForFrame:[self bounds]];
+ AutocompleteTextFieldCell* cell = [self cell];
+ const NSRect textFrame([cell textFrameForFrame:[self bounds]]);
// A version of the textFrame which extends across the field's
// entire width.
@@ -132,6 +133,14 @@
return;
}
+ // Check to see if the user clicked the hint icon in the cell. If so, we need
+ // to display the page info window.
+ const NSRect hintIconFrame = [cell hintImageFrameForFrame:[self bounds]];
+ if (NSMouseInRect(location, hintIconFrame, [self isFlipped])) {
+ observer_->OnSecurityIconClicked();
+ return;
+ }
+
NSText* editor = [self currentEditor];
// We should only be here if we accepted first-responder status and
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.h b/chrome/browser/cocoa/autocomplete_text_field_cell.h
index b8d931f..47fbb52 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell.h
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell.h
@@ -68,6 +68,9 @@
// corresponds to the frame with our added decorations sliced off.
- (NSRect)textFrameForFrame:(NSRect)cellFrame;
+// Return the portion of the cell to use for displaing the |hintIcon_|.
+- (NSRect)hintImageFrameForFrame:(NSRect)cellFrame;
+
@end
// Internal methods here exposed for unit testing.
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
index 585a1dd..10ae6f4 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
@@ -254,6 +254,25 @@ const NSInteger kHintIconHorizontalPad = 5;
return [super drawingRectForBounds:[self textFrameForFrame:theRect]];
}
+- (NSRect)hintImageFrameForFrame:(NSRect)cellFrame {
+ // We'll draw the entire image
+ const NSSize imageRect([hintIcon_ size]);
+
+ // Move the rect that we're drawing into to the far right
+ cellFrame.origin.x += cellFrame.size.width - imageRect.width;
+ // Add back the padding
+ cellFrame.origin.x -= kHintIconHorizontalPad;
+
+ // Center the image vertically in the frame
+ cellFrame.origin.y +=
+ floor((cellFrame.size.height - imageRect.height) / 2);
+
+ // Set the drawing size to the image size
+ cellFrame.size = imageRect;
+
+ return cellFrame;
+}
+
- (void)drawHintWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
DCHECK(hintString_);
@@ -296,25 +315,14 @@ const NSInteger kHintIconHorizontalPad = 5;
}
- (void)drawHintIconWithFrame:(NSRect)cellFrame
- inView:(NSView*)controlView {
+ 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;
+ const NSRect hintFrame([self hintImageFrameForFrame:cellFrame]);
[hintIcon_ setFlipped:[controlView isFlipped]];
- [hintIcon_ drawInRect:cellFrame
+ [hintIcon_ drawInRect:hintFrame
fromRect:imageRect
operation:NSCompositeSourceOver
fraction:1.0];
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
index 076789f..ef8d415 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
@@ -355,4 +355,38 @@ TEST_F(AutocompleteTextFieldCellTest, DrawingRectForBounds) {
EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
}
+// Test that the security icon is at the right side of the cell.
+TEST_F(AutocompleteTextFieldCellTest, HintImageFrame) {
+ AutocompleteTextFieldCell* cell =
+ static_cast<AutocompleteTextFieldCell*>([view_ cell]);
+ const NSRect bounds([view_ bounds]);
+ scoped_nsobject<NSImage> hintIcon(
+ [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]);
+
+ NSRect iconRect = [cell hintImageFrameForFrame:bounds];
+ EXPECT_TRUE(NSIsEmptyRect(iconRect));
+
+ // Save the starting frame for after clear.
+ const NSRect originalIconRect(iconRect);
+
+ [cell setHintIcon:hintIcon];
+ iconRect = [cell hintImageFrameForFrame:bounds];
+ EXPECT_FALSE(NSIsEmptyRect(iconRect));
+ EXPECT_TRUE(NSContainsRect(bounds, iconRect));
+
+ // Make sure we are right of the |drawingRect|.
+ NSRect drawingRect = [cell drawingRectForBounds:bounds];
+ EXPECT_LE(NSMaxX(drawingRect), NSMinX(iconRect));
+
+ // Make sure we're right of the |textFrame|.
+ NSRect textFrame = [cell textFrameForFrame:bounds];
+ EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect));
+
+ // Make sure we clear correctly.
+ [cell setHintIcon:nil];
+ iconRect = [cell hintImageFrameForFrame:bounds];
+ EXPECT_TRUE(NSEqualRects(iconRect, originalIconRect));
+ EXPECT_TRUE(NSIsEmptyRect(iconRect));
+}
+
} // namespace
diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
index 41cbe21..d5d1b9f0 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
@@ -517,6 +517,18 @@ TEST_F(AutocompleteTextFieldTest, TripleClickSelectsAll) {
EXPECT_EQ(selectedRange.length, [[field_ stringValue] length]);
}
+TEST_F(AutocompleteTextFieldTest, SecurityIconMouseDown) {
+ AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
+ scoped_nsobject<NSImage> hintIcon(
+ [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]);
+ [cell setHintIcon:hintIcon.get()];
+ NSRect iconFrame([cell hintImageFrameForFrame:[field_ bounds]]);
+ NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)));
+ NSEvent* event(Event(field_, location, NSLeftMouseDown, 1));
+ EXPECT_CALL(field_observer_, OnSecurityIconClicked());
+ [field_ mouseDown:event];
+}
+
} // namespace
@implementation AutocompleteTextFieldTestDelegate
diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h b/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h
index 9aef620..c3a617e 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h
+++ b/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h
@@ -37,6 +37,7 @@ class MockAutocompleteTextFieldObserver : public AutocompleteTextFieldObserver {
MOCK_METHOD0(CanPasteAndGo, bool());
MOCK_METHOD0(GetPasteActionStringId, int());
MOCK_METHOD0(OnPasteAndGo, void());
+ MOCK_METHOD0(OnSecurityIconClicked, void());
};
} // namespace