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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm

Issue 2576563002: [Mac] Reverse the omnibox in RTL (Closed)
Patch Set: Review comments Created 3 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
OLDNEW
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
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 leading side.
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 trailing side.
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
155 *remaining_frame = frame; 159 // Flip all frames in RTL.
156 return left_count; 160 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) {
161 for (NSRect& rect : *decoration_frames)
162 rect.origin.x = NSWidth(frame) - NSWidth(rect) - NSMinX(rect);
163 text_frame->origin.x =
164 NSWidth(frame) - NSWidth(*text_frame) - NSMinX(*text_frame);
165 leading_count = decorations->size() - leading_count;
166 }
167
168 return leading_count;
157 } 169 }
158 170
159 } // namespace 171 } // namespace
160 172
161 @implementation AutocompleteTextFieldCell 173 @implementation AutocompleteTextFieldCell
162 174
163 @synthesize isPopupMode = isPopupMode_; 175 @synthesize isPopupMode = isPopupMode_;
164 @synthesize singlePixelLineWidth = singlePixelLineWidth_; 176 @synthesize singlePixelLineWidth = singlePixelLineWidth_;
165 177
166 - (CGFloat)topTextFrameOffset { 178 - (CGFloat)topTextFrameOffset {
(...skipping 17 matching lines...) Expand all
184 } 196 }
185 197
186 - (void)clearTrackingArea { 198 - (void)clearTrackingArea {
187 for (auto& decoration : mouseTrackingDecorations_) 199 for (auto& decoration : mouseTrackingDecorations_)
188 decoration->RemoveTrackingArea(); 200 decoration->RemoveTrackingArea();
189 201
190 mouseTrackingDecorations_.clear(); 202 mouseTrackingDecorations_.clear();
191 } 203 }
192 204
193 - (void)clearDecorations { 205 - (void)clearDecorations {
194 leftDecorations_.clear(); 206 leadingDecorations_.clear();
195 rightDecorations_.clear(); 207 trailingDecorations_.clear();
196 [self clearTrackingArea]; 208 [self clearTrackingArea];
197 } 209 }
198 210
199 - (void)addLeftDecoration:(LocationBarDecoration*)decoration { 211 - (void)addLeadingDecoration:(LocationBarDecoration*)decoration {
200 leftDecorations_.push_back(decoration); 212 leadingDecorations_.push_back(decoration);
201 } 213 }
202 214
203 - (void)addRightDecoration:(LocationBarDecoration*)decoration { 215 - (void)addTrailingDecoration:(LocationBarDecoration*)decoration {
204 rightDecorations_.push_back(decoration); 216 trailingDecorations_.push_back(decoration);
205 } 217 }
206 218
207 - (CGFloat)availableWidthInFrame:(const NSRect)frame { 219 - (CGFloat)availableWidthInFrame:(const NSRect)frame {
208 std::vector<LocationBarDecoration*> decorations; 220 std::vector<LocationBarDecoration*> decorations;
209 std::vector<NSRect> decorationFrames; 221 std::vector<NSRect> decorationFrames;
210 NSRect textFrame; 222 NSRect textFrame;
211 CalculatePositionsInFrame(frame, leftDecorations_, rightDecorations_, 223 CalculatePositionsInFrame(frame, leadingDecorations_, trailingDecorations_,
212 &decorations, &decorationFrames, &textFrame); 224 &decorations, &decorationFrames, &textFrame);
213 225
214 return NSWidth(textFrame); 226 return NSWidth(textFrame);
215 } 227 }
216 228
217 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration 229 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration
218 inFrame:(NSRect)cellFrame { 230 inFrame:(NSRect)cellFrame {
219 // Short-circuit if the decoration is known to be not visible. 231 // Short-circuit if the decoration is known to be not visible.
220 if (aDecoration && !aDecoration->IsVisible()) 232 if (aDecoration && !aDecoration->IsVisible())
221 return NSZeroRect; 233 return NSZeroRect;
222 234
223 // Layout the decorations. 235 // Layout the decorations.
224 std::vector<LocationBarDecoration*> decorations; 236 std::vector<LocationBarDecoration*> decorations;
225 std::vector<NSRect> decorationFrames; 237 std::vector<NSRect> decorationFrames;
226 NSRect textFrame; 238 NSRect textFrame;
227 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, 239 CalculatePositionsInFrame(cellFrame, leadingDecorations_,
228 &decorations, &decorationFrames, &textFrame); 240 trailingDecorations_, &decorations,
241 &decorationFrames, &textFrame);
229 242
230 // Find our decoration and return the corresponding frame. 243 // Find our decoration and return the corresponding frame.
231 std::vector<LocationBarDecoration*>::const_iterator iter = 244 std::vector<LocationBarDecoration*>::const_iterator iter =
232 std::find(decorations.begin(), decorations.end(), aDecoration); 245 std::find(decorations.begin(), decorations.end(), aDecoration);
233 if (iter != decorations.end()) { 246 if (iter != decorations.end()) {
234 const size_t index = iter - decorations.begin(); 247 const size_t index = iter - decorations.begin();
235 return decorationFrames[index]; 248 return decorationFrames[index];
236 } 249 }
237 250
238 // Decorations which are not visible should have been filtered out 251 // Decorations which are not visible should have been filtered out
239 // at the top, but return |NSZeroRect| rather than a 0-width rect 252 // at the top, but return |NSZeroRect| rather than a 0-width rect
240 // for consistency. 253 // for consistency.
241 NOTREACHED(); 254 NOTREACHED();
242 return NSZeroRect; 255 return NSZeroRect;
243 } 256 }
244 257
245 - (NSRect)backgroundFrameForDecoration:(LocationBarDecoration*)decoration 258 - (NSRect)backgroundFrameForDecoration:(LocationBarDecoration*)decoration
246 inFrame:(NSRect)cellFrame 259 inFrame:(NSRect)cellFrame
247 isLeftDecoration:(BOOL*)isLeftDecoration { 260 isLeftDecoration:(BOOL*)isLeftDecoration {
248 NSRect decorationFrame = 261 NSRect decorationFrame =
249 [self frameForDecoration:decoration inFrame:cellFrame]; 262 [self frameForDecoration:decoration inFrame:cellFrame];
263 std::vector<LocationBarDecoration*>& left_decorations =
264 cocoa_l10n_util::ShouldDoExperimentalRTLLayout() ? trailingDecorations_
265 : leadingDecorations_;
250 *isLeftDecoration = 266 *isLeftDecoration =
251 std::find(leftDecorations_.begin(), leftDecorations_.end(), decoration) != 267 std::find(left_decorations.begin(), left_decorations.end(), decoration) !=
252 leftDecorations_.end(); 268 left_decorations.end();
253 return decoration->GetBackgroundFrame(decorationFrame); 269 return decoration->GetBackgroundFrame(decorationFrame);
254 } 270 }
255 271
256 // Overriden to account for the decorations. 272 // Overriden to account for the decorations.
257 - (NSRect)textFrameForFrame:(NSRect)cellFrame { 273 - (NSRect)textFrameForFrame:(NSRect)cellFrame {
258 // Get the frame adjusted for decorations. 274 // Get the frame adjusted for decorations.
259 std::vector<LocationBarDecoration*> decorations; 275 std::vector<LocationBarDecoration*> decorations;
260 std::vector<NSRect> decorationFrames; 276 std::vector<NSRect> decorationFrames;
261 NSRect textFrame = [super textFrameForFrame:cellFrame]; 277 NSRect textFrame = [super textFrameForFrame:cellFrame];
262 CalculatePositionsInFrame(textFrame, leftDecorations_, rightDecorations_, 278 CalculatePositionsInFrame(textFrame, leadingDecorations_,
263 &decorations, &decorationFrames, &textFrame); 279 trailingDecorations_, &decorations,
280 &decorationFrames, &textFrame);
264 281
265 // The text needs to be slightly higher than its default position to match the 282 // 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 283 // 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 284 // 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 285 // after computing decoration positions because the decorations are already
269 // correctly positioned. The spec also calls for positioning the text 1pt to 286 // correctly positioned. The spec also calls for positioning the text 1pt to
270 // the right of its default position. 287 // the right of its default position.
271 textFrame.origin.x += 1; 288 textFrame.origin.x += 1;
272 textFrame.size.width -= 1; 289 textFrame.size.width -= 1;
273 textFrame.origin.y -= singlePixelLineWidth_; 290 textFrame.origin.y -= singlePixelLineWidth_;
274 291
275 // NOTE: This function must closely match the logic in 292 // NOTE: This function must closely match the logic in
276 // |-drawInteriorWithFrame:inView:|. 293 // |-drawInteriorWithFrame:inView:|.
277 294
278 return textFrame; 295 return textFrame;
279 } 296 }
280 297
281 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { 298 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame {
282 std::vector<LocationBarDecoration*> decorations; 299 std::vector<LocationBarDecoration*> decorations;
283 std::vector<NSRect> decorationFrames; 300 std::vector<NSRect> decorationFrames;
284 NSRect textFrame; 301 NSRect textFrame;
285 size_t left_count = 302 size_t left_count = CalculatePositionsInFrame(
286 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, 303 cellFrame, leadingDecorations_, trailingDecorations_, &decorations,
287 &decorations, &decorationFrames, &textFrame); 304 &decorationFrames, &textFrame);
288 305
289 // Determine the left-most extent for the i-beam cursor. 306 // Determine the left-most extent for the i-beam cursor.
290 CGFloat minX = NSMinX(textFrame); 307 CGFloat minX = NSMinX(textFrame);
291 for (size_t index = left_count; index--; ) { 308 for (size_t index = left_count; index--; ) {
292 if (decorations[index]->AcceptsMousePress()) 309 if (decorations[index]->AcceptsMousePress())
293 break; 310 break;
294 311
295 // If at leftmost decoration, expand to edge of cell. 312 // If at leftmost decoration, expand to edge of cell.
296 if (!index) 313 if (!index)
297 minX = NSMinX(cellFrame); 314 minX = NSMinX(cellFrame);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 393
377 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 394 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
378 ui::ScopedCGContextSmoothFonts fontSmoothing; 395 ui::ScopedCGContextSmoothFonts fontSmoothing;
379 [super drawInteriorWithFrame:cellFrame inView:controlView]; 396 [super drawInteriorWithFrame:cellFrame inView:controlView];
380 397
381 // NOTE: This method must closely match the logic in |-textFrameForFrame:|. 398 // NOTE: This method must closely match the logic in |-textFrameForFrame:|.
382 std::vector<LocationBarDecoration*> decorations; 399 std::vector<LocationBarDecoration*> decorations;
383 std::vector<NSRect> decorationFrames; 400 std::vector<NSRect> decorationFrames;
384 NSRect workingFrame; 401 NSRect workingFrame;
385 402
386 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, 403 CalculatePositionsInFrame(cellFrame, leadingDecorations_,
387 &decorations, &decorationFrames, &workingFrame); 404 trailingDecorations_, &decorations,
405 &decorationFrames, &workingFrame);
388 406
389 // Draw the decorations. Do this after drawing the interior because the 407 // Draw the decorations. Do this after drawing the interior because the
390 // field editor's background rect overlaps the right edge of the security 408 // field editor's background rect overlaps the right edge of the security
391 // decoration's hover rounded rect. 409 // decoration's hover rounded rect.
392 for (size_t i = 0; i < decorations.size(); ++i) { 410 for (size_t i = 0; i < decorations.size(); ++i) {
393 if (decorations[i]) { 411 if (decorations[i]) {
394 decorations[i]->DrawWithBackgroundInFrame(decorationFrames[i], 412 decorations[i]->DrawWithBackgroundInFrame(decorationFrames[i],
395 controlView); 413 controlView);
396 } 414 }
397 } 415 }
398 } 416 }
399 417
400 - (BOOL)canDropAtLocationInWindow:(NSPoint)location 418 - (BOOL)canDropAtLocationInWindow:(NSPoint)location
401 ofView:(AutocompleteTextField*)controlView { 419 ofView:(AutocompleteTextField*)controlView {
402 NSRect cellFrame = [controlView bounds]; 420 NSRect cellFrame = [controlView bounds];
403 const NSPoint locationInView = 421 const NSPoint locationInView =
404 [controlView convertPoint:location fromView:nil]; 422 [controlView convertPoint:location fromView:nil];
405 423
406 // If we have decorations, the drop can't occur at their horizontal padding. 424 NSRect textFrame;
407 if (!leftDecorations_.empty() && locationInView.x < kLeftDecorationXOffset) 425 std::vector<LocationBarDecoration*> decorations;
408 return false; 426 std::vector<NSRect> decorationFrames;
409 427 CalculatePositionsInFrame(cellFrame, leadingDecorations_,
410 if (!rightDecorations_.empty() && 428 trailingDecorations_, &decorations,
411 locationInView.x > NSWidth(cellFrame) - kRightDecorationXOffset) { 429 &decorationFrames, &textFrame);
412 return false; 430 return NSPointInRect(locationInView, textFrame);
413 }
414
415 LocationBarDecoration* decoration =
416 [self decorationForLocationInWindow:location
417 inRect:cellFrame
418 ofView:controlView];
419 return !decoration;
420 } 431 }
421 432
422 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent 433 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent
423 inRect:(NSRect)cellFrame 434 inRect:(NSRect)cellFrame
424 ofView:(AutocompleteTextField*)controlView 435 ofView:(AutocompleteTextField*)controlView
425 { 436 {
426 return [self decorationForLocationInWindow:[theEvent locationInWindow] 437 return [self decorationForLocationInWindow:[theEvent locationInWindow]
427 inRect:cellFrame 438 inRect:cellFrame
428 ofView:controlView]; 439 ofView:controlView];
429 } 440 }
430 441
431 - (LocationBarDecoration*)decorationForLocationInWindow:(NSPoint)location 442 - (LocationBarDecoration*)decorationForLocationInWindow:(NSPoint)location
432 inRect:(NSRect)cellFrame 443 inRect:(NSRect)cellFrame
433 ofView:(AutocompleteTextField*) 444 ofView:(AutocompleteTextField*)
434 controlView { 445 controlView {
435 const BOOL flipped = [controlView isFlipped]; 446 const BOOL flipped = [controlView isFlipped];
436 const NSPoint locationInView = 447 const NSPoint locationInView =
437 [controlView convertPoint:location fromView:nil]; 448 [controlView convertPoint:location fromView:nil];
438 449
439 std::vector<LocationBarDecoration*> decorations; 450 std::vector<LocationBarDecoration*> decorations;
440 std::vector<NSRect> decorationFrames; 451 std::vector<NSRect> decorationFrames;
441 NSRect textFrame; 452 NSRect textFrame;
442 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, 453 CalculatePositionsInFrame(cellFrame, leadingDecorations_,
443 &decorations, &decorationFrames, &textFrame); 454 trailingDecorations_, &decorations,
455 &decorationFrames, &textFrame);
444 456
445 for (size_t i = 0; i < decorations.size(); ++i) { 457 for (size_t i = 0; i < decorations.size(); ++i) {
446 if (NSMouseInRect(locationInView, decorationFrames[i], flipped)) 458 if (NSMouseInRect(locationInView, decorationFrames[i], flipped))
447 return decorations[i]; 459 return decorations[i];
448 } 460 }
449 461
450 return NULL; 462 return NULL;
451 } 463 }
452 464
453 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent 465 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 draggedDecoration_->SetActive(false); 675 draggedDecoration_->SetActive(false);
664 draggedDecoration_ = nullptr; 676 draggedDecoration_ = nullptr;
665 } 677 }
666 678
667 - (void)updateMouseTrackingAndToolTipsInRect:(NSRect)cellFrame 679 - (void)updateMouseTrackingAndToolTipsInRect:(NSRect)cellFrame
668 ofView: 680 ofView:
669 (AutocompleteTextField*)controlView { 681 (AutocompleteTextField*)controlView {
670 std::vector<LocationBarDecoration*> decorations; 682 std::vector<LocationBarDecoration*> decorations;
671 std::vector<NSRect> decorationFrames; 683 std::vector<NSRect> decorationFrames;
672 NSRect textFrame; 684 NSRect textFrame;
673 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, 685 CalculatePositionsInFrame(cellFrame, leadingDecorations_,
674 &decorations, &decorationFrames, &textFrame); 686 trailingDecorations_, &decorations,
687 &decorationFrames, &textFrame);
675 [self clearTrackingArea]; 688 [self clearTrackingArea];
676 689
677 for (size_t i = 0; i < decorations.size(); ++i) { 690 for (size_t i = 0; i < decorations.size(); ++i) {
678 CrTrackingArea* trackingArea = 691 CrTrackingArea* trackingArea =
679 decorations[i]->SetupTrackingArea(decorationFrames[i], controlView); 692 decorations[i]->SetupTrackingArea(decorationFrames[i], controlView);
680 if (trackingArea) 693 if (trackingArea)
681 mouseTrackingDecorations_.push_back(decorations[i]); 694 mouseTrackingDecorations_.push_back(decorations[i]);
682 695
683 NSString* tooltip = decorations[i]->GetToolTip(); 696 NSString* tooltip = decorations[i]->GetToolTip();
684 if ([tooltip length] > 0) 697 if ([tooltip length] > 0)
(...skipping 30 matching lines...) Expand all
715 728
716 @end 729 @end
717 730
718 @implementation AutocompleteTextFieldCell (TestingAPI) 731 @implementation AutocompleteTextFieldCell (TestingAPI)
719 732
720 - (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations { 733 - (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations {
721 return mouseTrackingDecorations_; 734 return mouseTrackingDecorations_;
722 } 735 }
723 736
724 @end 737 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698