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 front-most leading |
Sidney San Martín
2016/12/16 00:05:54
The use of “front” and “back” in this CL are confu
Sidney San Martín
2016/12/16 00:09:40
Sorry, I didn't mean to imply "front" → "outermost
lgrey
2016/12/20 19:41:03
Done.
| |
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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, |remaining_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). |left_decorations| is |
111 // a set of decorations for the left-hand side of the cell, |right_decorations| | 113 // a set of decorations for the left-hand side of the cell, |right_decorations| |
112 // for the right-hand side. | 114 // 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. As a convenience returns |
116 // the index of the first right-hand decoration. | 118 // the index of the first right-hand decoration. |
Sidney San Martín
2016/12/16 00:05:54
This comment needs to be updated too.
lgrey
2016/12/20 19:41:03
Done.
| |
117 size_t CalculatePositionsInFrame( | 119 size_t CalculatePositionsInFrame( |
118 NSRect frame, | 120 NSRect frame, |
119 const std::vector<LocationBarDecoration*>& left_decorations, | 121 const std::vector<LocationBarDecoration*>& leading_decorations, |
120 const std::vector<LocationBarDecoration*>& right_decorations, | 122 const std::vector<LocationBarDecoration*>& trailing_decorations, |
121 std::vector<LocationBarDecoration*>* decorations, | 123 std::vector<LocationBarDecoration*>* decorations, |
122 std::vector<NSRect>* decoration_frames, | 124 std::vector<NSRect>* decoration_frames, |
123 NSRect* remaining_frame) { | 125 NSRect* remaining_frame) { |
124 decorations->clear(); | 126 decorations->clear(); |
125 decoration_frames->clear(); | 127 decoration_frames->clear(); |
126 | 128 |
127 // Layout |left_decorations| against the LHS. | 129 BOOL is_rtl = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); |
Sidney San Martín
2016/12/16 00:05:54
The large number of is_rtl checks in the CL smell
lgrey
2016/12/20 19:41:03
Done.
| |
128 CalculatePositionsHelper(frame, left_decorations, NSMinXEdge, | 130 // Layout left decorations (leading in LTR, trailing in RTL) against the LHS. |
129 kLeftDecorationXOffset, decorations, | 131 CGFloat left_padding = |
130 decoration_frames, &frame); | 132 is_rtl ? kTrailingDecorationXPadding : kLeadingDecorationXPadding; |
133 const std::vector<LocationBarDecoration*>& left_decorations = | |
134 is_rtl ? trailing_decorations : leading_decorations; | |
135 CalculatePositionsHelper(frame, left_decorations, NSMinXEdge, left_padding, | |
136 decorations, decoration_frames, &frame); | |
131 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 137 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
132 | 138 |
133 // Capture the number of visible left-hand decorations. | 139 // Capture the number of visible left-hand decorations. |
134 const size_t left_count = decorations->size(); | 140 const size_t left_count = decorations->size(); |
Sidney San Martín
2016/12/16 00:05:54
It was unexpected to see "left" pop up here. It lo
lgrey
2016/12/20 19:41:03
Done.
| |
135 | 141 |
142 // Layout right decorations against the RHS. | |
143 CGFloat right_padding = | |
144 is_rtl ? kLeadingDecorationXPadding : kTrailingDecorationXPadding; | |
145 const std::vector<LocationBarDecoration*>& right_decorations = | |
146 is_rtl ? leading_decorations : trailing_decorations; | |
147 | |
148 CalculatePositionsHelper(frame, right_decorations, NSMaxXEdge, right_padding, | |
149 decorations, decoration_frames, &frame); | |
150 DCHECK_EQ(decorations->size(), decoration_frames->size()); | |
151 | |
152 // Reverse the trailing decorations so that overall everything is | |
153 // sorted back to front. | |
154 const size_t leading_count = | |
155 is_rtl ? decorations->size() - left_count : left_count; | |
136 // Extend the text frame so that it slightly overlaps the rightmost left | 156 // Extend the text frame so that it slightly overlaps the rightmost left |
137 // decoration. | 157 // decoration. |
138 if (left_count) { | 158 if (leading_count) { |
139 frame.origin.x -= kTextFrameDecorationOverlap; | 159 if (!is_rtl) |
160 frame.origin.x -= kTextFrameDecorationOverlap; | |
Sidney San Martín
2016/12/16 00:05:54
This is also a good example. It takes some thought
lgrey
2016/12/20 19:41:03
Done.
| |
140 frame.size.width += kTextFrameDecorationOverlap; | 161 frame.size.width += kTextFrameDecorationOverlap; |
141 } | 162 } |
142 | 163 |
143 // Layout |right_decorations| against the RHS. | |
144 CalculatePositionsHelper(frame, right_decorations, NSMaxXEdge, | |
145 kRightDecorationXOffset, decorations, | |
146 decoration_frames, &frame); | |
147 DCHECK_EQ(decorations->size(), decoration_frames->size()); | |
148 | |
149 // Reverse the right-hand decorations so that overall everything is | |
150 // sorted left to right. | |
151 std::reverse(decorations->begin() + left_count, decorations->end()); | 164 std::reverse(decorations->begin() + left_count, decorations->end()); |
152 std::reverse(decoration_frames->begin() + left_count, | 165 std::reverse(decoration_frames->begin() + left_count, |
153 decoration_frames->end()); | 166 decoration_frames->end()); |
154 | 167 |
155 *remaining_frame = frame; | 168 *remaining_frame = frame; |
156 return left_count; | 169 return left_count; |
157 } | 170 } |
158 | 171 |
159 } // namespace | 172 } // namespace |
160 | 173 |
(...skipping 23 matching lines...) Expand all Loading... | |
184 } | 197 } |
185 | 198 |
186 - (void)clearTrackingArea { | 199 - (void)clearTrackingArea { |
187 for (auto& decoration : mouseTrackingDecorations_) | 200 for (auto& decoration : mouseTrackingDecorations_) |
188 decoration->RemoveTrackingArea(); | 201 decoration->RemoveTrackingArea(); |
189 | 202 |
190 mouseTrackingDecorations_.clear(); | 203 mouseTrackingDecorations_.clear(); |
191 } | 204 } |
192 | 205 |
193 - (void)clearDecorations { | 206 - (void)clearDecorations { |
194 leftDecorations_.clear(); | 207 leadingDecorations_.clear(); |
195 rightDecorations_.clear(); | 208 trailingDecorations_.clear(); |
196 [self clearTrackingArea]; | 209 [self clearTrackingArea]; |
197 } | 210 } |
198 | 211 |
199 - (void)addLeftDecoration:(LocationBarDecoration*)decoration { | 212 - (void)addLeadingDecoration:(LocationBarDecoration*)decoration { |
200 leftDecorations_.push_back(decoration); | 213 leadingDecorations_.push_back(decoration); |
201 } | 214 } |
202 | 215 |
203 - (void)addRightDecoration:(LocationBarDecoration*)decoration { | 216 - (void)addTrailingDecoration:(LocationBarDecoration*)decoration { |
204 rightDecorations_.push_back(decoration); | 217 trailingDecorations_.push_back(decoration); |
205 } | 218 } |
206 | 219 |
207 - (CGFloat)availableWidthInFrame:(const NSRect)frame { | 220 - (CGFloat)availableWidthInFrame:(const NSRect)frame { |
208 std::vector<LocationBarDecoration*> decorations; | 221 std::vector<LocationBarDecoration*> decorations; |
209 std::vector<NSRect> decorationFrames; | 222 std::vector<NSRect> decorationFrames; |
210 NSRect textFrame; | 223 NSRect textFrame; |
211 CalculatePositionsInFrame(frame, leftDecorations_, rightDecorations_, | 224 CalculatePositionsInFrame(frame, leadingDecorations_, trailingDecorations_, |
212 &decorations, &decorationFrames, &textFrame); | 225 &decorations, &decorationFrames, &textFrame); |
213 | 226 |
214 return NSWidth(textFrame); | 227 return NSWidth(textFrame); |
215 } | 228 } |
216 | 229 |
217 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration | 230 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration |
218 inFrame:(NSRect)cellFrame { | 231 inFrame:(NSRect)cellFrame { |
219 // Short-circuit if the decoration is known to be not visible. | 232 // Short-circuit if the decoration is known to be not visible. |
220 if (aDecoration && !aDecoration->IsVisible()) | 233 if (aDecoration && !aDecoration->IsVisible()) |
221 return NSZeroRect; | 234 return NSZeroRect; |
222 | 235 |
223 // Layout the decorations. | 236 // Layout the decorations. |
224 std::vector<LocationBarDecoration*> decorations; | 237 std::vector<LocationBarDecoration*> decorations; |
225 std::vector<NSRect> decorationFrames; | 238 std::vector<NSRect> decorationFrames; |
226 NSRect textFrame; | 239 NSRect textFrame; |
227 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 240 CalculatePositionsInFrame(cellFrame, leadingDecorations_, |
228 &decorations, &decorationFrames, &textFrame); | 241 trailingDecorations_, &decorations, |
242 &decorationFrames, &textFrame); | |
229 | 243 |
230 // Find our decoration and return the corresponding frame. | 244 // Find our decoration and return the corresponding frame. |
231 std::vector<LocationBarDecoration*>::const_iterator iter = | 245 std::vector<LocationBarDecoration*>::const_iterator iter = |
232 std::find(decorations.begin(), decorations.end(), aDecoration); | 246 std::find(decorations.begin(), decorations.end(), aDecoration); |
233 if (iter != decorations.end()) { | 247 if (iter != decorations.end()) { |
234 const size_t index = iter - decorations.begin(); | 248 const size_t index = iter - decorations.begin(); |
235 return decorationFrames[index]; | 249 return decorationFrames[index]; |
236 } | 250 } |
237 | 251 |
238 // Decorations which are not visible should have been filtered out | 252 // Decorations which are not visible should have been filtered out |
239 // at the top, but return |NSZeroRect| rather than a 0-width rect | 253 // at the top, but return |NSZeroRect| rather than a 0-width rect |
240 // for consistency. | 254 // for consistency. |
241 NOTREACHED(); | 255 NOTREACHED(); |
242 return NSZeroRect; | 256 return NSZeroRect; |
243 } | 257 } |
244 | 258 |
245 - (NSRect)backgroundFrameForDecoration:(LocationBarDecoration*)decoration | 259 - (NSRect)backgroundFrameForDecoration:(LocationBarDecoration*)decoration |
246 inFrame:(NSRect)cellFrame | 260 inFrame:(NSRect)cellFrame |
247 isLeftDecoration:(BOOL*)isLeftDecoration { | 261 isLeftDecoration:(BOOL*)isLeftDecoration { |
248 NSRect decorationFrame = | 262 NSRect decorationFrame = |
249 [self frameForDecoration:decoration inFrame:cellFrame]; | 263 [self frameForDecoration:decoration inFrame:cellFrame]; |
264 std::vector<LocationBarDecoration*>& left_decorations = | |
265 cocoa_l10n_util::ShouldDoExperimentalRTLLayout() ? trailingDecorations_ | |
266 : leadingDecorations_; | |
250 *isLeftDecoration = | 267 *isLeftDecoration = |
251 std::find(leftDecorations_.begin(), leftDecorations_.end(), decoration) != | 268 std::find(left_decorations.begin(), left_decorations.end(), decoration) != |
252 leftDecorations_.end(); | 269 left_decorations.end(); |
253 return decoration->GetBackgroundFrame(decorationFrame); | 270 return decoration->GetBackgroundFrame(decorationFrame); |
254 } | 271 } |
255 | 272 |
256 // Overriden to account for the decorations. | 273 // Overriden to account for the decorations. |
257 - (NSRect)textFrameForFrame:(NSRect)cellFrame { | 274 - (NSRect)textFrameForFrame:(NSRect)cellFrame { |
258 // Get the frame adjusted for decorations. | 275 // Get the frame adjusted for decorations. |
259 std::vector<LocationBarDecoration*> decorations; | 276 std::vector<LocationBarDecoration*> decorations; |
260 std::vector<NSRect> decorationFrames; | 277 std::vector<NSRect> decorationFrames; |
261 NSRect textFrame = [super textFrameForFrame:cellFrame]; | 278 NSRect textFrame = [super textFrameForFrame:cellFrame]; |
262 CalculatePositionsInFrame(textFrame, leftDecorations_, rightDecorations_, | 279 CalculatePositionsInFrame(textFrame, leadingDecorations_, |
263 &decorations, &decorationFrames, &textFrame); | 280 trailingDecorations_, &decorations, |
281 &decorationFrames, &textFrame); | |
264 | 282 |
265 // The text needs to be slightly higher than its default position to match the | 283 // 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 | 284 // 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 | 285 // 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 | 286 // after computing decoration positions because the decorations are already |
269 // correctly positioned. The spec also calls for positioning the text 1pt to | 287 // correctly positioned. The spec also calls for positioning the text 1pt to |
270 // the right of its default position. | 288 // the right of its default position. |
271 textFrame.origin.x += 1; | 289 textFrame.origin.x += 1; |
272 textFrame.size.width -= 1; | 290 textFrame.size.width -= 1; |
273 textFrame.origin.y -= singlePixelLineWidth_; | 291 textFrame.origin.y -= singlePixelLineWidth_; |
274 | 292 |
275 // NOTE: This function must closely match the logic in | 293 // NOTE: This function must closely match the logic in |
276 // |-drawInteriorWithFrame:inView:|. | 294 // |-drawInteriorWithFrame:inView:|. |
277 | 295 |
278 return textFrame; | 296 return textFrame; |
279 } | 297 } |
280 | 298 |
281 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { | 299 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { |
282 std::vector<LocationBarDecoration*> decorations; | 300 std::vector<LocationBarDecoration*> decorations; |
283 std::vector<NSRect> decorationFrames; | 301 std::vector<NSRect> decorationFrames; |
284 NSRect textFrame; | 302 NSRect textFrame; |
285 size_t left_count = | 303 size_t left_count = CalculatePositionsInFrame( |
286 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 304 cellFrame, leadingDecorations_, trailingDecorations_, &decorations, |
287 &decorations, &decorationFrames, &textFrame); | 305 &decorationFrames, &textFrame); |
288 | 306 |
289 // Determine the left-most extent for the i-beam cursor. | 307 // Determine the left-most extent for the i-beam cursor. |
290 CGFloat minX = NSMinX(textFrame); | 308 CGFloat minX = NSMinX(textFrame); |
291 for (size_t index = left_count; index--; ) { | 309 for (size_t index = left_count; index--; ) { |
292 if (decorations[index]->AcceptsMousePress()) | 310 if (decorations[index]->AcceptsMousePress()) |
293 break; | 311 break; |
294 | 312 |
295 // If at leftmost decoration, expand to edge of cell. | 313 // If at leftmost decoration, expand to edge of cell. |
296 if (!index) | 314 if (!index) |
297 minX = NSMinX(cellFrame); | 315 minX = NSMinX(cellFrame); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 394 |
377 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 395 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
378 ui::ScopedCGContextSmoothFonts fontSmoothing; | 396 ui::ScopedCGContextSmoothFonts fontSmoothing; |
379 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 397 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
380 | 398 |
381 // NOTE: This method must closely match the logic in |-textFrameForFrame:|. | 399 // NOTE: This method must closely match the logic in |-textFrameForFrame:|. |
382 std::vector<LocationBarDecoration*> decorations; | 400 std::vector<LocationBarDecoration*> decorations; |
383 std::vector<NSRect> decorationFrames; | 401 std::vector<NSRect> decorationFrames; |
384 NSRect workingFrame; | 402 NSRect workingFrame; |
385 | 403 |
386 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 404 CalculatePositionsInFrame(cellFrame, leadingDecorations_, |
387 &decorations, &decorationFrames, &workingFrame); | 405 trailingDecorations_, &decorations, |
406 &decorationFrames, &workingFrame); | |
388 | 407 |
389 // Draw the decorations. Do this after drawing the interior because the | 408 // Draw the decorations. Do this after drawing the interior because the |
390 // field editor's background rect overlaps the right edge of the security | 409 // field editor's background rect overlaps the right edge of the security |
391 // decoration's hover rounded rect. | 410 // decoration's hover rounded rect. |
392 for (size_t i = 0; i < decorations.size(); ++i) { | 411 for (size_t i = 0; i < decorations.size(); ++i) { |
393 if (decorations[i]) { | 412 if (decorations[i]) { |
394 decorations[i]->DrawWithBackgroundInFrame(decorationFrames[i], | 413 decorations[i]->DrawWithBackgroundInFrame(decorationFrames[i], |
395 controlView); | 414 controlView); |
396 } | 415 } |
397 } | 416 } |
398 } | 417 } |
399 | 418 |
400 - (BOOL)canDropAtLocationInWindow:(NSPoint)location | 419 - (BOOL)canDropAtLocationInWindow:(NSPoint)location |
401 ofView:(AutocompleteTextField*)controlView { | 420 ofView:(AutocompleteTextField*)controlView { |
402 NSRect cellFrame = [controlView bounds]; | 421 NSRect cellFrame = [controlView bounds]; |
403 const NSPoint locationInView = | 422 const NSPoint locationInView = |
404 [controlView convertPoint:location fromView:nil]; | 423 [controlView convertPoint:location fromView:nil]; |
405 | 424 |
406 // If we have decorations, the drop can't occur at their horizontal padding. | 425 CGFloat leftEdge = 0; |
407 if (!leftDecorations_.empty() && locationInView.x < kLeftDecorationXOffset) | 426 CGFloat rightEdge = NSWidth(cellFrame); |
427 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); | |
Sidney San Martín
2016/12/16 00:05:54
is_rtl — but it would be nicer if it could be elim
lgrey
2016/12/20 19:41:03
Done.
| |
428 if (!leadingDecorations_.empty()) { | |
429 if (isRTL) | |
430 rightEdge -= kLeadingDecorationXPadding; | |
431 else | |
432 leftEdge += kLeadingDecorationXPadding; | |
433 } | |
434 if (!trailingDecorations_.empty()) { | |
435 if (isRTL) | |
436 leftEdge += kTrailingDecorationXPadding; | |
437 else | |
438 rightEdge -= kTrailingDecorationXPadding; | |
439 } | |
440 if (locationInView.x < leftEdge) | |
408 return false; | 441 return false; |
409 | 442 |
410 if (!rightDecorations_.empty() && | 443 if (locationInView.x > rightEdge) { |
411 locationInView.x > NSWidth(cellFrame) - kRightDecorationXOffset) { | |
412 return false; | 444 return false; |
413 } | 445 } |
414 | 446 |
415 LocationBarDecoration* decoration = | 447 LocationBarDecoration* decoration = |
416 [self decorationForLocationInWindow:location | 448 [self decorationForLocationInWindow:location |
417 inRect:cellFrame | 449 inRect:cellFrame |
418 ofView:controlView]; | 450 ofView:controlView]; |
419 return !decoration; | 451 return !decoration; |
420 } | 452 } |
421 | 453 |
(...skipping 10 matching lines...) Expand all Loading... | |
432 inRect:(NSRect)cellFrame | 464 inRect:(NSRect)cellFrame |
433 ofView:(AutocompleteTextField*) | 465 ofView:(AutocompleteTextField*) |
434 controlView { | 466 controlView { |
435 const BOOL flipped = [controlView isFlipped]; | 467 const BOOL flipped = [controlView isFlipped]; |
436 const NSPoint locationInView = | 468 const NSPoint locationInView = |
437 [controlView convertPoint:location fromView:nil]; | 469 [controlView convertPoint:location fromView:nil]; |
438 | 470 |
439 std::vector<LocationBarDecoration*> decorations; | 471 std::vector<LocationBarDecoration*> decorations; |
440 std::vector<NSRect> decorationFrames; | 472 std::vector<NSRect> decorationFrames; |
441 NSRect textFrame; | 473 NSRect textFrame; |
442 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 474 CalculatePositionsInFrame(cellFrame, leadingDecorations_, |
443 &decorations, &decorationFrames, &textFrame); | 475 trailingDecorations_, &decorations, |
476 &decorationFrames, &textFrame); | |
444 | 477 |
445 for (size_t i = 0; i < decorations.size(); ++i) { | 478 for (size_t i = 0; i < decorations.size(); ++i) { |
446 if (NSMouseInRect(locationInView, decorationFrames[i], flipped)) | 479 if (NSMouseInRect(locationInView, decorationFrames[i], flipped)) |
447 return decorations[i]; | 480 return decorations[i]; |
448 } | 481 } |
449 | 482 |
450 return NULL; | 483 return NULL; |
451 } | 484 } |
452 | 485 |
453 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent | 486 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { | 685 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { |
653 return NSDragOperationCopy; | 686 return NSDragOperationCopy; |
654 } | 687 } |
655 | 688 |
656 - (void)updateMouseTrackingAndToolTipsInRect:(NSRect)cellFrame | 689 - (void)updateMouseTrackingAndToolTipsInRect:(NSRect)cellFrame |
657 ofView: | 690 ofView: |
658 (AutocompleteTextField*)controlView { | 691 (AutocompleteTextField*)controlView { |
659 std::vector<LocationBarDecoration*> decorations; | 692 std::vector<LocationBarDecoration*> decorations; |
660 std::vector<NSRect> decorationFrames; | 693 std::vector<NSRect> decorationFrames; |
661 NSRect textFrame; | 694 NSRect textFrame; |
662 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 695 CalculatePositionsInFrame(cellFrame, leadingDecorations_, |
663 &decorations, &decorationFrames, &textFrame); | 696 trailingDecorations_, &decorations, |
697 &decorationFrames, &textFrame); | |
664 [self clearTrackingArea]; | 698 [self clearTrackingArea]; |
665 | 699 |
666 for (size_t i = 0; i < decorations.size(); ++i) { | 700 for (size_t i = 0; i < decorations.size(); ++i) { |
667 CrTrackingArea* trackingArea = | 701 CrTrackingArea* trackingArea = |
668 decorations[i]->SetupTrackingArea(decorationFrames[i], controlView); | 702 decorations[i]->SetupTrackingArea(decorationFrames[i], controlView); |
669 if (trackingArea) | 703 if (trackingArea) |
670 mouseTrackingDecorations_.push_back(decorations[i]); | 704 mouseTrackingDecorations_.push_back(decorations[i]); |
671 | 705 |
672 NSString* tooltip = decorations[i]->GetToolTip(); | 706 NSString* tooltip = decorations[i]->GetToolTip(); |
673 if ([tooltip length] > 0) | 707 if ([tooltip length] > 0) |
(...skipping 30 matching lines...) Expand all Loading... | |
704 | 738 |
705 @end | 739 @end |
706 | 740 |
707 @implementation AutocompleteTextFieldCell (TestingAPI) | 741 @implementation AutocompleteTextFieldCell (TestingAPI) |
708 | 742 |
709 - (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations { | 743 - (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations { |
710 return mouseTrackingDecorations_; | 744 return mouseTrackingDecorations_; |
711 } | 745 } |
712 | 746 |
713 @end | 747 @end |
OLD | NEW |