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

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

Issue 525098: [Mac] Implements context menus for Page Actions. Introduces a reusable subcla... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Final changes before submit. Created 10 years, 11 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 | 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 #import "chrome/browser/cocoa/browser_window_controller.h" 9 #import "chrome/browser/cocoa/browser_window_controller.h"
10 #import "chrome/browser/cocoa/toolbar_controller.h" 10 #import "chrome/browser/cocoa/toolbar_controller.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // field editor area, and if so sets the selection to {0,0} to clear 63 // field editor area, and if so sets the selection to {0,0} to clear
64 // the selection before forwarding the event to the field editor for 64 // the selection before forwarding the event to the field editor for
65 // processing (it will set the cursor position). This also starts the 65 // processing (it will set the cursor position). This also starts the
66 // click-drag selection machinery. 66 // click-drag selection machinery.
67 // 67 //
68 // This code does the same thing for cases where the click was in the 68 // This code does the same thing for cases where the click was in the
69 // decoration area. This allows the user to click-drag starting from 69 // decoration area. This allows the user to click-drag starting from
70 // a decoration area and get the expected selection behaviour, 70 // a decoration area and get the expected selection behaviour,
71 // likewise for multiple clicks in those areas. 71 // likewise for multiple clicks in those areas.
72 - (void)mouseDown:(NSEvent*)theEvent { 72 - (void)mouseDown:(NSEvent*)theEvent {
73 const NSPoint locationInWindow = [theEvent locationInWindow]; 73 const NSPoint location =
74 const NSPoint location = [self convertPoint:locationInWindow fromView:nil]; 74 [self convertPoint:[theEvent locationInWindow] fromView:nil];
75 const NSRect bounds([self bounds]);
75 76
76 AutocompleteTextFieldCell* cell = [self autocompleteTextFieldCell]; 77 AutocompleteTextFieldCell* cell = [self autocompleteTextFieldCell];
77 const NSRect textFrame([cell textFrameForFrame:[self bounds]]); 78 const NSRect textFrame([cell textFrameForFrame:bounds]);
78 79
79 // A version of the textFrame which extends across the field's 80 // A version of the textFrame which extends across the field's
80 // entire width. 81 // entire width.
81 const NSRect bounds([self bounds]); 82
82 const NSRect fullFrame(NSMakeRect(bounds.origin.x, textFrame.origin.y, 83 const NSRect fullFrame(NSMakeRect(bounds.origin.x, textFrame.origin.y,
83 bounds.size.width, textFrame.size.height)); 84 bounds.size.width, textFrame.size.height));
84 85
85 // If the mouse is in the editing area, or above or below where the 86 // If the mouse is in the editing area, or above or below where the
86 // editing area would be if we didn't add decorations, forward to 87 // editing area would be if we didn't add decorations, forward to
87 // NSTextField -mouseDown: because it does the right thing. The 88 // NSTextField -mouseDown: because it does the right thing. The
88 // above/below test is needed because NSTextView treats mouse events 89 // above/below test is needed because NSTextView treats mouse events
89 // above/below as select-to-end-in-that-direction, which makes 90 // above/below as select-to-end-in-that-direction, which makes
90 // things janky. 91 // things janky.
91 if (NSMouseInRect(location, textFrame, [self isFlipped]) || 92 BOOL flipped = [self isFlipped];
92 !NSMouseInRect(location, fullFrame, [self isFlipped])) { 93 if (NSMouseInRect(location, textFrame, flipped) ||
94 !NSMouseInRect(location, fullFrame, flipped)) {
93 [super mouseDown:theEvent]; 95 [super mouseDown:theEvent];
94 96
95 // After the event has been handled, if the current event is a 97 // After the event has been handled, if the current event is a
96 // mouse up and no selection was created (the mouse didn't move), 98 // mouse up and no selection was created (the mouse didn't move),
97 // select the entire field. 99 // select the entire field.
98 // NOTE(shess): This does not interfere with single-clicking to 100 // NOTE(shess): This does not interfere with single-clicking to
99 // place caret after a selection is made. An NSTextField only has 101 // place caret after a selection is made. An NSTextField only has
100 // a selection when it has a field editor. The field editor is an 102 // a selection when it has a field editor. The field editor is an
101 // NSText subview, which will receive the -mouseDown: in that 103 // NSText subview, which will receive the -mouseDown: in that
102 // case, and this code will never fire. 104 // case, and this code will never fire.
103 NSText* editor = [self currentEditor]; 105 NSText* editor = [self currentEditor];
104 if (editor) { 106 if (editor) {
105 NSEvent* currentEvent = [NSApp currentEvent]; 107 NSEvent* currentEvent = [NSApp currentEvent];
106 if ([currentEvent type] == NSLeftMouseUp && 108 if ([currentEvent type] == NSLeftMouseUp &&
107 ![editor selectedRange].length) { 109 ![editor selectedRange].length) {
108 [editor selectAll:nil]; 110 [editor selectAll:nil];
109 } 111 }
110 } 112 }
111 113
112 return; 114 return;
113 } 115 }
114 116
115 // If the user clicked the security hint icon in the cell, display the page 117 // If the user clicked the security hint icon in the cell, display the page
116 // info window. 118 // info window.
117 const NSRect hintIconFrame = [cell securityImageFrameForFrame:[self bounds]]; 119 const NSRect hintIconFrame = [cell securityImageFrameForFrame:bounds];
118 if (NSMouseInRect(location, hintIconFrame, [self isFlipped])) { 120 if (NSMouseInRect(location, hintIconFrame, flipped)) {
119 [cell onSecurityIconMousePressed]; 121 [cell onSecurityIconMousePressed];
120 return; 122 return;
121 } 123 }
122 124
123 // If the user clicked a Page Action icon, execute its action. 125 const BOOL ctrlKey = ([theEvent modifierFlags] & NSControlKeyMask) != 0;
124 const NSRect iconFrame([self bounds]); 126 NSLog(@"Control key pressed? => %d", ctrlKey);
127 // If the user left-clicked a Page Action icon, execute its action.
125 const size_t pageActionCount = [cell pageActionCount]; 128 const size_t pageActionCount = [cell pageActionCount];
126 for (size_t i = 0; i < pageActionCount; ++i) { 129 for (size_t i = 0; i < pageActionCount; ++i) {
127 NSRect pageActionFrame = [cell pageActionFrameForIndex:i inFrame:iconFrame]; 130 NSRect pageActionFrame = [cell pageActionFrameForIndex:i inFrame:bounds];
128 if (NSMouseInRect(location, pageActionFrame, [self isFlipped])) { 131 if (NSMouseInRect(location, pageActionFrame, flipped) && !ctrlKey) {
129 // TODO(pamg): Do we need to send the event?
130 [cell onPageActionMousePressedIn:pageActionFrame forIndex:i]; 132 [cell onPageActionMousePressedIn:pageActionFrame forIndex:i];
131 return; 133 return;
132 } 134 }
133 } 135 }
134 136
135 NSText* editor = [self currentEditor]; 137 NSText* editor = [self currentEditor];
136 138
137 // We should only be here if we accepted first-responder status and 139 // 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 140 // have a field editor. If one of these fires, it means some
139 // assumptions are being broken. 141 // assumptions are being broken.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 - (void)draggingExited:(id<NSDraggingInfo>)sender { 325 - (void)draggingExited:(id<NSDraggingInfo>)sender {
324 return [dropHandler_ draggingExited:sender]; 326 return [dropHandler_ draggingExited:sender];
325 } 327 }
326 328
327 // (URLDropTarget protocol) 329 // (URLDropTarget protocol)
328 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { 330 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
329 return [dropHandler_ performDragOperation:sender]; 331 return [dropHandler_ performDragOperation:sender];
330 } 332 }
331 333
332 @end 334 @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