OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
11 #include "base/mac/mac_logging.h" | 11 #include "base/mac/mac_logging.h" |
12 #include "chrome/browser/search/search.h" | 12 #include "chrome/browser/search/search.h" |
13 #include "chrome/browser/themes/theme_service.h" | 13 #include "chrome/browser/themes/theme_service.h" |
| 14 #include "chrome/browser/ui/cocoa/l10n_util.h" |
14 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 15 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
15 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 16 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
16 #import "chrome/browser/ui/cocoa/themed_window.h" | 17 #import "chrome/browser/ui/cocoa/themed_window.h" |
17 #include "chrome/grit/theme_resources.h" | 18 #include "chrome/grit/theme_resources.h" |
18 #import "extensions/common/feature_switch.h" | 19 #import "extensions/common/feature_switch.h" |
19 #import "third_party/mozilla/NSPasteboard+Utils.h" | 20 #import "third_party/mozilla/NSPasteboard+Utils.h" |
20 #import "ui/base/cocoa/appkit_utils.h" | 21 #import "ui/base/cocoa/appkit_utils.h" |
21 #import "ui/base/cocoa/tracking_area.h" | 22 #import "ui/base/cocoa/tracking_area.h" |
22 #import "ui/base/cocoa/nsview_additions.h" | 23 #import "ui/base/cocoa/nsview_additions.h" |
23 #include "ui/base/cocoa/scoped_cg_context_smooth_fonts.h" | 24 #include "ui/base/cocoa/scoped_cg_context_smooth_fonts.h" |
24 #include "ui/base/material_design/material_design_controller.h" | 25 #include "ui/base/material_design/material_design_controller.h" |
25 | 26 |
26 using extensions::FeatureSwitch; | 27 using extensions::FeatureSwitch; |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // Matches the clipping radius of |GradientButtonCell|. | 31 // Matches the clipping radius of |GradientButtonCell|. |
31 const CGFloat kCornerRadius = 3.0; | 32 const CGFloat kCornerRadius = 3.0; |
32 | 33 |
33 // How far to inset the left- and right-hand decorations from the field's | 34 // How far to inset the left- and right-hand decorations from the field's |
34 // bounds. | 35 // bounds. |
35 const CGFloat kRightDecorationXOffset = 2.0; | 36 const CGFloat kTrailingDecorationXPadding = 2.0; |
36 const CGFloat kLeftDecorationXOffset = 1.0; | 37 const CGFloat kLeadingDecorationXPadding = 1.0; |
37 | 38 |
38 // How much the text frame needs to overlap the rightmost left decoration. | 39 // How much the text frame needs to overlap the outermost leading |
| 40 // decoration. |
39 const CGFloat kTextFrameDecorationOverlap = 5.0; | 41 const CGFloat kTextFrameDecorationOverlap = 5.0; |
40 | 42 |
41 // How long to wait for mouse-up on the location icon before assuming | 43 // How long to wait for mouse-up on the location icon before assuming |
42 // that the user wants to drag. | 44 // that the user wants to drag. |
43 const NSTimeInterval kLocationIconDragTimeout = 0.25; | 45 const NSTimeInterval kLocationIconDragTimeout = 0.25; |
44 | 46 |
45 // Calculate the positions for a set of decorations. |frame| is the | 47 // Calculate the positions for a set of decorations. |frame| is the |
46 // overall frame to do layout in, |remaining_frame| will get the | 48 // overall frame to do layout in, |remaining_frame| will get the |
47 // left-over space. |all_decorations| is the set of decorations to | 49 // left-over space. |all_decorations| is the set of decorations to |
48 // lay out, |decorations| will be set to the decorations which are | 50 // lay out, |decorations| will be set to the decorations which are |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 101 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
100 } | 102 } |
101 } | 103 } |
102 } | 104 } |
103 | 105 |
104 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 106 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
105 *remaining_frame = frame; | 107 *remaining_frame = frame; |
106 } | 108 } |
107 | 109 |
108 // Helper function for calculating placement of decorations w/in the cell. | 110 // Helper function for calculating placement of decorations w/in the cell. |
109 // |frame| is the cell's boundary rectangle, |remaining_frame| will get any | 111 // |frame| is the cell's boundary rectangle, |text_frame| will get any |
110 // space left after decorations are laid out (for text). |left_decorations| is | 112 // space left after decorations are laid out (for text). |
111 // a set of decorations for the left-hand side of the cell, |right_decorations| | 113 // |leading_decorations| is a set of decorations for the leading side of |
112 // for the right-hand side. | 114 // the cell, |trailing_decorations| for the right-hand side. |
113 // |decorations| will contain the resulting visible decorations, and | 115 // |decorations| will contain the resulting visible decorations, and |
114 // |decoration_frames| will contain their frames in the same coordinates as | 116 // |decoration_frames| will contain their frames in the same coordinates as |
115 // |frame|. Decorations will be ordered left to right. As a convenience returns | 117 // |frame|. Decorations will be ordered left to right in LTR, and right to |
116 // the index of the first right-hand decoration. | 118 // left. |
| 119 // As a convenience, returns the index of the first right-hand decoration. |
117 size_t CalculatePositionsInFrame( | 120 size_t CalculatePositionsInFrame( |
118 NSRect frame, | 121 const NSRect frame, |
119 const std::vector<LocationBarDecoration*>& left_decorations, | 122 const std::vector<LocationBarDecoration*>& leading_decorations, |
120 const std::vector<LocationBarDecoration*>& right_decorations, | 123 const std::vector<LocationBarDecoration*>& trailing_decorations, |
121 std::vector<LocationBarDecoration*>* decorations, | 124 std::vector<LocationBarDecoration*>* decorations, |
122 std::vector<NSRect>* decoration_frames, | 125 std::vector<NSRect>* decoration_frames, |
123 NSRect* remaining_frame) { | 126 NSRect* text_frame) { |
124 decorations->clear(); | 127 decorations->clear(); |
125 decoration_frames->clear(); | 128 decoration_frames->clear(); |
| 129 *text_frame = frame; |
126 | 130 |
127 // Layout |left_decorations| against the LHS. | 131 // Layout |leading_decorations| against the LHS. |
128 CalculatePositionsHelper(frame, left_decorations, NSMinXEdge, | 132 CalculatePositionsHelper(*text_frame, leading_decorations, NSMinXEdge, |
129 kLeftDecorationXOffset, decorations, | 133 kLeadingDecorationXPadding, decorations, |
130 decoration_frames, &frame); | 134 decoration_frames, text_frame); |
131 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 135 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
132 | 136 |
133 // Capture the number of visible left-hand decorations. | 137 // Capture the number of visible leading decorations. |
134 const size_t left_count = decorations->size(); | 138 size_t leading_count = decorations->size(); |
135 | 139 |
136 // Extend the text frame so that it slightly overlaps the rightmost left | 140 // Extend the text frame so that it slightly overlaps the rightmost left |
137 // decoration. | 141 // decoration. |
138 if (left_count) { | 142 if (leading_count) { |
139 frame.origin.x -= kTextFrameDecorationOverlap; | 143 text_frame->origin.x -= kTextFrameDecorationOverlap; |
140 frame.size.width += kTextFrameDecorationOverlap; | 144 text_frame->size.width += kTextFrameDecorationOverlap; |
141 } | 145 } |
142 | 146 |
143 // Layout |right_decorations| against the RHS. | 147 // Layout |trailing_decorations| against the RHS. |
144 CalculatePositionsHelper(frame, right_decorations, NSMaxXEdge, | 148 CalculatePositionsHelper(*text_frame, trailing_decorations, NSMaxXEdge, |
145 kRightDecorationXOffset, decorations, | 149 kTrailingDecorationXPadding, decorations, |
146 decoration_frames, &frame); | 150 decoration_frames, text_frame); |
147 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 151 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
148 | 152 |
149 // Reverse the right-hand decorations so that overall everything is | 153 // Reverse the right-hand decorations so that overall everything is |
150 // sorted left to right. | 154 // sorted left to right. |
151 std::reverse(decorations->begin() + left_count, decorations->end()); | 155 std::reverse(decorations->begin() + leading_count, decorations->end()); |
152 std::reverse(decoration_frames->begin() + left_count, | 156 std::reverse(decoration_frames->begin() + leading_count, |
153 decoration_frames->end()); | 157 decoration_frames->end()); |
154 | 158 // Flip all frames in RTL. |
155 *remaining_frame = frame; | 159 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { |
156 return left_count; | 160 for (NSRect& rect : *decoration_frames) |
| 161 rect.origin.x = NSWidth(frame) - NSWidth(rect) - NSMinX(rect); |
| 162 text_frame->origin.x = |
| 163 NSWidth(frame) - NSWidth(*text_frame) - NSMinX(*text_frame); |
| 164 leading_count = decorations->size() - leading_count; |
| 165 } |
| 166 return leading_count; |
157 } | 167 } |
158 | 168 |
159 } // namespace | 169 } // namespace |
160 | 170 |
161 @implementation AutocompleteTextFieldCell | 171 @implementation AutocompleteTextFieldCell |
162 | 172 |
163 @synthesize isPopupMode = isPopupMode_; | 173 @synthesize isPopupMode = isPopupMode_; |
164 @synthesize singlePixelLineWidth = singlePixelLineWidth_; | 174 @synthesize singlePixelLineWidth = singlePixelLineWidth_; |
165 | 175 |
166 - (CGFloat)topTextFrameOffset { | 176 - (CGFloat)topTextFrameOffset { |
(...skipping 17 matching lines...) Expand all Loading... |
184 } | 194 } |
185 | 195 |
186 - (void)clearTrackingArea { | 196 - (void)clearTrackingArea { |
187 for (auto& decoration : mouseTrackingDecorations_) | 197 for (auto& decoration : mouseTrackingDecorations_) |
188 decoration->RemoveTrackingArea(); | 198 decoration->RemoveTrackingArea(); |
189 | 199 |
190 mouseTrackingDecorations_.clear(); | 200 mouseTrackingDecorations_.clear(); |
191 } | 201 } |
192 | 202 |
193 - (void)clearDecorations { | 203 - (void)clearDecorations { |
194 leftDecorations_.clear(); | 204 leadingDecorations_.clear(); |
195 rightDecorations_.clear(); | 205 trailingDecorations_.clear(); |
196 [self clearTrackingArea]; | 206 [self clearTrackingArea]; |
197 } | 207 } |
198 | 208 |
199 - (void)addLeftDecoration:(LocationBarDecoration*)decoration { | 209 - (void)addLeadingDecoration:(LocationBarDecoration*)decoration { |
200 leftDecorations_.push_back(decoration); | 210 leadingDecorations_.push_back(decoration); |
201 } | 211 } |
202 | 212 |
203 - (void)addRightDecoration:(LocationBarDecoration*)decoration { | 213 - (void)addTrailingDecoration:(LocationBarDecoration*)decoration { |
204 rightDecorations_.push_back(decoration); | 214 trailingDecorations_.push_back(decoration); |
205 } | 215 } |
206 | 216 |
207 - (CGFloat)availableWidthInFrame:(const NSRect)frame { | 217 - (CGFloat)availableWidthInFrame:(const NSRect)frame { |
208 std::vector<LocationBarDecoration*> decorations; | 218 std::vector<LocationBarDecoration*> decorations; |
209 std::vector<NSRect> decorationFrames; | 219 std::vector<NSRect> decorationFrames; |
210 NSRect textFrame; | 220 NSRect textFrame; |
211 CalculatePositionsInFrame(frame, leftDecorations_, rightDecorations_, | 221 CalculatePositionsInFrame(frame, leadingDecorations_, trailingDecorations_, |
212 &decorations, &decorationFrames, &textFrame); | 222 &decorations, &decorationFrames, &textFrame); |
213 | 223 |
214 return NSWidth(textFrame); | 224 return NSWidth(textFrame); |
215 } | 225 } |
216 | 226 |
217 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration | 227 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration |
218 inFrame:(NSRect)cellFrame { | 228 inFrame:(NSRect)cellFrame { |
219 // Short-circuit if the decoration is known to be not visible. | 229 // Short-circuit if the decoration is known to be not visible. |
220 if (aDecoration && !aDecoration->IsVisible()) | 230 if (aDecoration && !aDecoration->IsVisible()) |
221 return NSZeroRect; | 231 return NSZeroRect; |
222 | 232 |
223 // Layout the decorations. | 233 // Layout the decorations. |
224 std::vector<LocationBarDecoration*> decorations; | 234 std::vector<LocationBarDecoration*> decorations; |
225 std::vector<NSRect> decorationFrames; | 235 std::vector<NSRect> decorationFrames; |
226 NSRect textFrame; | 236 NSRect textFrame; |
227 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 237 CalculatePositionsInFrame(cellFrame, leadingDecorations_, |
228 &decorations, &decorationFrames, &textFrame); | 238 trailingDecorations_, &decorations, |
| 239 &decorationFrames, &textFrame); |
229 | 240 |
230 // Find our decoration and return the corresponding frame. | 241 // Find our decoration and return the corresponding frame. |
231 std::vector<LocationBarDecoration*>::const_iterator iter = | 242 std::vector<LocationBarDecoration*>::const_iterator iter = |
232 std::find(decorations.begin(), decorations.end(), aDecoration); | 243 std::find(decorations.begin(), decorations.end(), aDecoration); |
233 if (iter != decorations.end()) { | 244 if (iter != decorations.end()) { |
234 const size_t index = iter - decorations.begin(); | 245 const size_t index = iter - decorations.begin(); |
235 return decorationFrames[index]; | 246 return decorationFrames[index]; |
236 } | 247 } |
237 | 248 |
238 // Decorations which are not visible should have been filtered out | 249 // Decorations which are not visible should have been filtered out |
239 // at the top, but return |NSZeroRect| rather than a 0-width rect | 250 // at the top, but return |NSZeroRect| rather than a 0-width rect |
240 // for consistency. | 251 // for consistency. |
241 NOTREACHED(); | 252 NOTREACHED(); |
242 return NSZeroRect; | 253 return NSZeroRect; |
243 } | 254 } |
244 | 255 |
245 - (NSRect)backgroundFrameForDecoration:(LocationBarDecoration*)decoration | 256 - (NSRect)backgroundFrameForDecoration:(LocationBarDecoration*)decoration |
246 inFrame:(NSRect)cellFrame | 257 inFrame:(NSRect)cellFrame |
247 isLeftDecoration:(BOOL*)isLeftDecoration { | 258 isLeftDecoration:(BOOL*)isLeftDecoration { |
248 NSRect decorationFrame = | 259 NSRect decorationFrame = |
249 [self frameForDecoration:decoration inFrame:cellFrame]; | 260 [self frameForDecoration:decoration inFrame:cellFrame]; |
| 261 std::vector<LocationBarDecoration*>& left_decorations = |
| 262 cocoa_l10n_util::ShouldDoExperimentalRTLLayout() ? trailingDecorations_ |
| 263 : leadingDecorations_; |
250 *isLeftDecoration = | 264 *isLeftDecoration = |
251 std::find(leftDecorations_.begin(), leftDecorations_.end(), decoration) != | 265 std::find(left_decorations.begin(), left_decorations.end(), decoration) != |
252 leftDecorations_.end(); | 266 left_decorations.end(); |
253 return decoration->GetBackgroundFrame(decorationFrame); | 267 return decoration->GetBackgroundFrame(decorationFrame); |
254 } | 268 } |
255 | 269 |
256 // Overriden to account for the decorations. | 270 // Overriden to account for the decorations. |
257 - (NSRect)textFrameForFrame:(NSRect)cellFrame { | 271 - (NSRect)textFrameForFrame:(NSRect)cellFrame { |
258 // Get the frame adjusted for decorations. | 272 // Get the frame adjusted for decorations. |
259 std::vector<LocationBarDecoration*> decorations; | 273 std::vector<LocationBarDecoration*> decorations; |
260 std::vector<NSRect> decorationFrames; | 274 std::vector<NSRect> decorationFrames; |
261 NSRect textFrame = [super textFrameForFrame:cellFrame]; | 275 NSRect textFrame = [super textFrameForFrame:cellFrame]; |
262 CalculatePositionsInFrame(textFrame, leftDecorations_, rightDecorations_, | 276 CalculatePositionsInFrame(textFrame, leadingDecorations_, |
263 &decorations, &decorationFrames, &textFrame); | 277 trailingDecorations_, &decorations, |
| 278 &decorationFrames, &textFrame); |
264 | 279 |
265 // The text needs to be slightly higher than its default position to match the | 280 // The text needs to be slightly higher than its default position to match the |
266 // Material Design spec. It turns out this adjustment is equal to the single | 281 // Material Design spec. It turns out this adjustment is equal to the single |
267 // pixel line width (so 1 on non-Retina, 0.5 on Retina). Make this adjustment | 282 // pixel line width (so 1 on non-Retina, 0.5 on Retina). Make this adjustment |
268 // after computing decoration positions because the decorations are already | 283 // after computing decoration positions because the decorations are already |
269 // correctly positioned. The spec also calls for positioning the text 1pt to | 284 // correctly positioned. The spec also calls for positioning the text 1pt to |
270 // the right of its default position. | 285 // the right of its default position. |
271 textFrame.origin.x += 1; | 286 textFrame.origin.x += 1; |
272 textFrame.size.width -= 1; | 287 textFrame.size.width -= 1; |
273 textFrame.origin.y -= singlePixelLineWidth_; | 288 textFrame.origin.y -= singlePixelLineWidth_; |
274 | 289 |
275 // NOTE: This function must closely match the logic in | 290 // NOTE: This function must closely match the logic in |
276 // |-drawInteriorWithFrame:inView:|. | 291 // |-drawInteriorWithFrame:inView:|. |
277 | 292 |
278 return textFrame; | 293 return textFrame; |
279 } | 294 } |
280 | 295 |
281 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { | 296 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { |
282 std::vector<LocationBarDecoration*> decorations; | 297 std::vector<LocationBarDecoration*> decorations; |
283 std::vector<NSRect> decorationFrames; | 298 std::vector<NSRect> decorationFrames; |
284 NSRect textFrame; | 299 NSRect textFrame; |
285 size_t left_count = | 300 size_t left_count = CalculatePositionsInFrame( |
286 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 301 cellFrame, leadingDecorations_, trailingDecorations_, &decorations, |
287 &decorations, &decorationFrames, &textFrame); | 302 &decorationFrames, &textFrame); |
288 | 303 |
289 // Determine the left-most extent for the i-beam cursor. | 304 // Determine the left-most extent for the i-beam cursor. |
290 CGFloat minX = NSMinX(textFrame); | 305 CGFloat minX = NSMinX(textFrame); |
291 for (size_t index = left_count; index--; ) { | 306 for (size_t index = left_count; index--; ) { |
292 if (decorations[index]->AcceptsMousePress()) | 307 if (decorations[index]->AcceptsMousePress()) |
293 break; | 308 break; |
294 | 309 |
295 // If at leftmost decoration, expand to edge of cell. | 310 // If at leftmost decoration, expand to edge of cell. |
296 if (!index) | 311 if (!index) |
297 minX = NSMinX(cellFrame); | 312 minX = NSMinX(cellFrame); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 391 |
377 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 392 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
378 ui::ScopedCGContextSmoothFonts fontSmoothing; | 393 ui::ScopedCGContextSmoothFonts fontSmoothing; |
379 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 394 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
380 | 395 |
381 // NOTE: This method must closely match the logic in |-textFrameForFrame:|. | 396 // NOTE: This method must closely match the logic in |-textFrameForFrame:|. |
382 std::vector<LocationBarDecoration*> decorations; | 397 std::vector<LocationBarDecoration*> decorations; |
383 std::vector<NSRect> decorationFrames; | 398 std::vector<NSRect> decorationFrames; |
384 NSRect workingFrame; | 399 NSRect workingFrame; |
385 | 400 |
386 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 401 CalculatePositionsInFrame(cellFrame, leadingDecorations_, |
387 &decorations, &decorationFrames, &workingFrame); | 402 trailingDecorations_, &decorations, |
| 403 &decorationFrames, &workingFrame); |
388 | 404 |
389 // Draw the decorations. Do this after drawing the interior because the | 405 // Draw the decorations. Do this after drawing the interior because the |
390 // field editor's background rect overlaps the right edge of the security | 406 // field editor's background rect overlaps the right edge of the security |
391 // decoration's hover rounded rect. | 407 // decoration's hover rounded rect. |
392 for (size_t i = 0; i < decorations.size(); ++i) { | 408 for (size_t i = 0; i < decorations.size(); ++i) { |
393 if (decorations[i]) { | 409 if (decorations[i]) { |
394 decorations[i]->DrawWithBackgroundInFrame(decorationFrames[i], | 410 decorations[i]->DrawWithBackgroundInFrame(decorationFrames[i], |
395 controlView); | 411 controlView); |
396 } | 412 } |
397 } | 413 } |
398 } | 414 } |
399 | 415 |
400 - (BOOL)canDropAtLocationInWindow:(NSPoint)location | 416 - (BOOL)canDropAtLocationInWindow:(NSPoint)location |
401 ofView:(AutocompleteTextField*)controlView { | 417 ofView:(AutocompleteTextField*)controlView { |
402 NSRect cellFrame = [controlView bounds]; | 418 NSRect cellFrame = [controlView bounds]; |
403 const NSPoint locationInView = | 419 const NSPoint locationInView = |
404 [controlView convertPoint:location fromView:nil]; | 420 [controlView convertPoint:location fromView:nil]; |
405 | 421 |
406 // If we have decorations, the drop can't occur at their horizontal padding. | 422 NSRect textFrame; |
407 if (!leftDecorations_.empty() && locationInView.x < kLeftDecorationXOffset) | 423 std::vector<LocationBarDecoration*> decorations; |
408 return false; | 424 std::vector<NSRect> decorationFrames; |
409 | 425 CalculatePositionsInFrame(cellFrame, leadingDecorations_, |
410 if (!rightDecorations_.empty() && | 426 trailingDecorations_, &decorations, |
411 locationInView.x > NSWidth(cellFrame) - kRightDecorationXOffset) { | 427 &decorationFrames, &textFrame); |
412 return false; | 428 return NSPointInRect(locationInView, textFrame); |
413 } | |
414 | |
415 LocationBarDecoration* decoration = | |
416 [self decorationForLocationInWindow:location | |
417 inRect:cellFrame | |
418 ofView:controlView]; | |
419 return !decoration; | |
420 } | 429 } |
421 | 430 |
422 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent | 431 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent |
423 inRect:(NSRect)cellFrame | 432 inRect:(NSRect)cellFrame |
424 ofView:(AutocompleteTextField*)controlView | 433 ofView:(AutocompleteTextField*)controlView |
425 { | 434 { |
426 return [self decorationForLocationInWindow:[theEvent locationInWindow] | 435 return [self decorationForLocationInWindow:[theEvent locationInWindow] |
427 inRect:cellFrame | 436 inRect:cellFrame |
428 ofView:controlView]; | 437 ofView:controlView]; |
429 } | 438 } |
430 | 439 |
431 - (LocationBarDecoration*)decorationForLocationInWindow:(NSPoint)location | 440 - (LocationBarDecoration*)decorationForLocationInWindow:(NSPoint)location |
432 inRect:(NSRect)cellFrame | 441 inRect:(NSRect)cellFrame |
433 ofView:(AutocompleteTextField*) | 442 ofView:(AutocompleteTextField*) |
434 controlView { | 443 controlView { |
435 const BOOL flipped = [controlView isFlipped]; | 444 const BOOL flipped = [controlView isFlipped]; |
436 const NSPoint locationInView = | 445 const NSPoint locationInView = |
437 [controlView convertPoint:location fromView:nil]; | 446 [controlView convertPoint:location fromView:nil]; |
438 | 447 |
439 std::vector<LocationBarDecoration*> decorations; | 448 std::vector<LocationBarDecoration*> decorations; |
440 std::vector<NSRect> decorationFrames; | 449 std::vector<NSRect> decorationFrames; |
441 NSRect textFrame; | 450 NSRect textFrame; |
442 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 451 CalculatePositionsInFrame(cellFrame, leadingDecorations_, |
443 &decorations, &decorationFrames, &textFrame); | 452 trailingDecorations_, &decorations, |
| 453 &decorationFrames, &textFrame); |
444 | 454 |
445 for (size_t i = 0; i < decorations.size(); ++i) { | 455 for (size_t i = 0; i < decorations.size(); ++i) { |
446 if (NSMouseInRect(locationInView, decorationFrames[i], flipped)) | 456 if (NSMouseInRect(locationInView, decorationFrames[i], flipped)) |
447 return decorations[i]; | 457 return decorations[i]; |
448 } | 458 } |
449 | 459 |
450 return NULL; | 460 return NULL; |
451 } | 461 } |
452 | 462 |
453 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent | 463 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 draggedDecoration_->SetActive(false); | 673 draggedDecoration_->SetActive(false); |
664 draggedDecoration_ = nullptr; | 674 draggedDecoration_ = nullptr; |
665 } | 675 } |
666 | 676 |
667 - (void)updateMouseTrackingAndToolTipsInRect:(NSRect)cellFrame | 677 - (void)updateMouseTrackingAndToolTipsInRect:(NSRect)cellFrame |
668 ofView: | 678 ofView: |
669 (AutocompleteTextField*)controlView { | 679 (AutocompleteTextField*)controlView { |
670 std::vector<LocationBarDecoration*> decorations; | 680 std::vector<LocationBarDecoration*> decorations; |
671 std::vector<NSRect> decorationFrames; | 681 std::vector<NSRect> decorationFrames; |
672 NSRect textFrame; | 682 NSRect textFrame; |
673 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 683 CalculatePositionsInFrame(cellFrame, leadingDecorations_, |
674 &decorations, &decorationFrames, &textFrame); | 684 trailingDecorations_, &decorations, |
| 685 &decorationFrames, &textFrame); |
675 [self clearTrackingArea]; | 686 [self clearTrackingArea]; |
676 | 687 |
677 for (size_t i = 0; i < decorations.size(); ++i) { | 688 for (size_t i = 0; i < decorations.size(); ++i) { |
678 CrTrackingArea* trackingArea = | 689 CrTrackingArea* trackingArea = |
679 decorations[i]->SetupTrackingArea(decorationFrames[i], controlView); | 690 decorations[i]->SetupTrackingArea(decorationFrames[i], controlView); |
680 if (trackingArea) | 691 if (trackingArea) |
681 mouseTrackingDecorations_.push_back(decorations[i]); | 692 mouseTrackingDecorations_.push_back(decorations[i]); |
682 | 693 |
683 NSString* tooltip = decorations[i]->GetToolTip(); | 694 NSString* tooltip = decorations[i]->GetToolTip(); |
684 if ([tooltip length] > 0) | 695 if ([tooltip length] > 0) |
(...skipping 30 matching lines...) Expand all Loading... |
715 | 726 |
716 @end | 727 @end |
717 | 728 |
718 @implementation AutocompleteTextFieldCell (TestingAPI) | 729 @implementation AutocompleteTextFieldCell (TestingAPI) |
719 | 730 |
720 - (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations { | 731 - (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations { |
721 return mouseTrackingDecorations_; | 732 return mouseTrackingDecorations_; |
722 } | 733 } |
723 | 734 |
724 @end | 735 @end |
OLD | NEW |