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

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

Issue 427009: Preliminary work toward page actions on Mac. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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
« no previous file with comments | « no previous file | chrome/browser/cocoa/autocomplete_text_field_cell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #import "chrome/browser/cocoa/autocomplete_text_field.h" 5 #import "chrome/browser/cocoa/autocomplete_text_field.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" 8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
9 9
10 @implementation AutocompleteTextField 10 @implementation AutocompleteTextField
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // editor the default NSTextField code detects if the hit is in the 58 // editor the default NSTextField code detects if the hit is in the
59 // field editor area, and if so sets the selection to {0,0} to clear 59 // field editor area, and if so sets the selection to {0,0} to clear
60 // the selection before forwarding the event to the field editor for 60 // the selection before forwarding the event to the field editor for
61 // processing (it will set the cursor position). This also starts the 61 // processing (it will set the cursor position). This also starts the
62 // click-drag selection machinery. 62 // click-drag selection machinery.
63 // 63 //
64 // This code does the same thing for cases where the click was in the 64 // This code does the same thing for cases where the click was in the
65 // decoration area. This allows the user to click-drag starting from 65 // decoration area. This allows the user to click-drag starting from
66 // a decoration area and get the expected selection behaviour, 66 // a decoration area and get the expected selection behaviour,
67 // likewise for multiple clicks in those areas. 67 // likewise for multiple clicks in those areas.
68 - (void)mouseDown:(NSEvent *)theEvent { 68 - (void)mouseDown:(NSEvent*)theEvent {
69 const NSPoint locationInWindow = [theEvent locationInWindow]; 69 const NSPoint locationInWindow = [theEvent locationInWindow];
70 const NSPoint location = [self convertPoint:locationInWindow fromView:nil]; 70 const NSPoint location = [self convertPoint:locationInWindow fromView:nil];
71 71
72 AutocompleteTextFieldCell* cell = [self autocompleteTextFieldCell]; 72 AutocompleteTextFieldCell* cell = [self autocompleteTextFieldCell];
73 const NSRect textFrame([cell textFrameForFrame:[self bounds]]); 73 const NSRect textFrame([cell textFrameForFrame:[self bounds]]);
74 74
75 // A version of the textFrame which extends across the field's 75 // A version of the textFrame which extends across the field's
76 // entire width. 76 // entire width.
77 const NSRect bounds([self bounds]); 77 const NSRect bounds([self bounds]);
78 const NSRect fullFrame(NSMakeRect(bounds.origin.x, textFrame.origin.y, 78 const NSRect fullFrame(NSMakeRect(bounds.origin.x, textFrame.origin.y,
(...skipping 22 matching lines...) Expand all
101 NSEvent* currentEvent = [NSApp currentEvent]; 101 NSEvent* currentEvent = [NSApp currentEvent];
102 if ([currentEvent type] == NSLeftMouseUp && 102 if ([currentEvent type] == NSLeftMouseUp &&
103 ![editor selectedRange].length) { 103 ![editor selectedRange].length) {
104 [editor selectAll:nil]; 104 [editor selectAll:nil];
105 } 105 }
106 } 106 }
107 107
108 return; 108 return;
109 } 109 }
110 110
111 // Check to see if the user clicked the security hint icon in the cell. If so, 111 // If the user clicked the security hint icon in the cell, display the page
112 // we need to display the page info window. 112 // info window.
113 const NSRect hintIconFrame = [cell securityImageFrameForFrame:[self bounds]]; 113 const NSRect hintIconFrame = [cell securityImageFrameForFrame:[self bounds]];
114 if (NSMouseInRect(location, hintIconFrame, [self isFlipped])) { 114 if (NSMouseInRect(location, hintIconFrame, [self isFlipped])) {
115 [cell onSecurityIconMousePressed]; 115 [cell onSecurityIconMousePressed];
116 return; 116 return;
117 } 117 }
118 118
119 // If the user clicked a Page Action icon, execute its action.
120 const NSRect iconFrame([self bounds]);
121 const size_t pageActionCount = [cell pageActionCount];
122 for (size_t i = 0; i < pageActionCount; ++i) {
123 NSRect pageActionFrame = [cell pageActionFrameForIndex:i inFrame:iconFrame];
124 if (NSMouseInRect(location, pageActionFrame, [self isFlipped])) {
125 // TODO(pamg): Do we need to send the event?
126 [cell onPageActionMousePressedIn:pageActionFrame forIndex:i];
127 return;
128 }
129 }
130
119 NSText* editor = [self currentEditor]; 131 NSText* editor = [self currentEditor];
120 132
121 // We should only be here if we accepted first-responder status and 133 // We should only be here if we accepted first-responder status and
122 // have a field editor. If one of these fires, it means some 134 // have a field editor. If one of these fires, it means some
123 // assumptions are being broken. 135 // assumptions are being broken.
124 DCHECK(editor != nil); 136 DCHECK(editor != nil);
125 DCHECK([editor isDescendantOf:self]); 137 DCHECK([editor isDescendantOf:self]);
126 138
127 // -becomeFirstResponder does a select-all, which we don't want 139 // -becomeFirstResponder does a select-all, which we don't want
128 // because it can lead to a dragged-text situation. Clear the 140 // because it can lead to a dragged-text situation. Clear the
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if ([self window]) { 244 if ([self window]) {
233 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 245 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
234 [nc addObserver:self 246 [nc addObserver:self
235 selector:@selector(windowDidResignKey:) 247 selector:@selector(windowDidResignKey:)
236 name:NSWindowDidResignKeyNotification 248 name:NSWindowDidResignKeyNotification
237 object:[self window]]; 249 object:[self window]];
238 } 250 }
239 } 251 }
240 252
241 @end 253 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/cocoa/autocomplete_text_field_cell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698