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

Side by Side Diff: chrome/browser/cocoa/autocomplete_text_field.mm

Issue 222020: [Mac] Show the page info window after clicking the security icon in the URL bar (Closed)
Patch Set: Unit tests Created 11 years, 2 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/autocomplete_text_field.h" 5 #include "chrome/browser/cocoa/autocomplete_text_field.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/cocoa/autocomplete_text_field_cell.h" 8 #include "chrome/browser/cocoa/autocomplete_text_field_cell.h"
9 9
10 @implementation AutocompleteTextField 10 @implementation AutocompleteTextField
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // click-drag selection machinery. 87 // click-drag selection machinery.
88 // 88 //
89 // This code does the same thing for cases where the click was in the 89 // This code does the same thing for cases where the click was in the
90 // decoration area. This allows the user to click-drag starting from 90 // decoration area. This allows the user to click-drag starting from
91 // a decoration area and get the expected selection behaviour, 91 // a decoration area and get the expected selection behaviour,
92 // likewise for multiple clicks in those areas. 92 // likewise for multiple clicks in those areas.
93 - (void)mouseDown:(NSEvent *)theEvent { 93 - (void)mouseDown:(NSEvent *)theEvent {
94 const NSPoint locationInWindow = [theEvent locationInWindow]; 94 const NSPoint locationInWindow = [theEvent locationInWindow];
95 const NSPoint location = [self convertPoint:locationInWindow fromView:nil]; 95 const NSPoint location = [self convertPoint:locationInWindow fromView:nil];
96 96
97 const NSRect textFrame = [[self cell] textFrameForFrame:[self bounds]]; 97 AutocompleteTextFieldCell* cell = [self cell];
98 const NSRect textFrame([cell textFrameForFrame:[self bounds]]);
98 99
99 // A version of the textFrame which extends across the field's 100 // A version of the textFrame which extends across the field's
100 // entire width. 101 // entire width.
101 const NSRect bounds([self bounds]); 102 const NSRect bounds([self bounds]);
102 const NSRect fullFrame(NSMakeRect(bounds.origin.x, textFrame.origin.y, 103 const NSRect fullFrame(NSMakeRect(bounds.origin.x, textFrame.origin.y,
103 bounds.size.width, textFrame.size.height)); 104 bounds.size.width, textFrame.size.height));
104 105
105 // If the mouse is in the editing area, or above or below where the 106 // If the mouse is in the editing area, or above or below where the
106 // editing area would be if we didn't add decorations, forward to 107 // editing area would be if we didn't add decorations, forward to
107 // NSTextField -mouseDown: because it does the right thing. The 108 // NSTextField -mouseDown: because it does the right thing. The
(...skipping 17 matching lines...) Expand all
125 NSEvent* currentEvent = [NSApp currentEvent]; 126 NSEvent* currentEvent = [NSApp currentEvent];
126 if ([currentEvent type] == NSLeftMouseUp && 127 if ([currentEvent type] == NSLeftMouseUp &&
127 ![editor selectedRange].length) { 128 ![editor selectedRange].length) {
128 [editor selectAll:nil]; 129 [editor selectAll:nil];
129 } 130 }
130 } 131 }
131 132
132 return; 133 return;
133 } 134 }
134 135
136 // Check to see if the user clicked the hint icon in the cell. If so, we need
137 // to display the page info window.
138 const NSRect hintIconFrame = [cell hintImageFrameForFrame:[self bounds]];
139 if (NSMouseInRect(location, hintIconFrame, [self isFlipped])) {
140 observer_->OnSecurityIconClicked();
141 return;
142 }
143
135 NSText* editor = [self currentEditor]; 144 NSText* editor = [self currentEditor];
136 145
137 // We should only be here if we accepted first-responder status and 146 // We should only be here if we accepted first-responder status and
138 // have a field editor. If one of these fires, it means some 147 // have a field editor. If one of these fires, it means some
139 // assumptions are being broken. 148 // assumptions are being broken.
140 DCHECK(editor != nil); 149 DCHECK(editor != nil);
141 DCHECK([editor isDescendantOf:self]); 150 DCHECK([editor isDescendantOf:self]);
142 151
143 // -becomeFirstResponder does a select-all, which we don't want 152 // -becomeFirstResponder does a select-all, which we don't want
144 // because it can lead to a dragged-text situation. Clear the 153 // because it can lead to a dragged-text situation. Clear the
145 // selection (any valid empty selection will do). 154 // selection (any valid empty selection will do).
146 [editor setSelectedRange:NSMakeRange(0, 0)]; 155 [editor setSelectedRange:NSMakeRange(0, 0)];
147 156
148 // If the event is to the right of the editing area, scroll the 157 // If the event is to the right of the editing area, scroll the
149 // field editor to the end of the content so that the selection 158 // field editor to the end of the content so that the selection
150 // doesn't initiate from somewhere in the middle of the text. 159 // doesn't initiate from somewhere in the middle of the text.
151 if (location.x > NSMaxX(textFrame)) { 160 if (location.x > NSMaxX(textFrame)) {
152 [editor scrollRangeToVisible:NSMakeRange([[self stringValue] length], 0)]; 161 [editor scrollRangeToVisible:NSMakeRange([[self stringValue] length], 0)];
153 } 162 }
154 163
155 [editor mouseDown:theEvent]; 164 [editor mouseDown:theEvent];
156 } 165 }
157 166
158 @end 167 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698