| 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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 // Matches the clipping radius of |GradientButtonCell|. | 30 // Matches the clipping radius of |GradientButtonCell|. |
| 31 const CGFloat kCornerRadius = 3.0; | 31 const CGFloat kCornerRadius = 3.0; |
| 32 | 32 |
| 33 // How far to inset the left- and right-hand decorations from the field's | 33 // How far to inset the left- and right-hand decorations from the field's |
| 34 // bounds. | 34 // bounds. |
| 35 const CGFloat kRightDecorationXOffset = 2.0; | 35 const CGFloat kRightDecorationXOffset = 2.0; |
| 36 const CGFloat kLeftDecorationXOffset = 1.0; | 36 const CGFloat kLeftDecorationXOffset = 1.0; |
| 37 | 37 |
| 38 // How much the text frame needs to overlap the rightmost left decoration. | 38 // How much the text frame needs to overlap the rightmost left decoration. |
| 39 const CGFloat kTextFrameDecorationOverlap = 5.0; | 39 const CGFloat kTextFrameDecorationOverlap = 4.0; |
| 40 |
| 41 // How much the text in the cell should be offset from its left. |
| 42 const CGFloat kTitleFrameXOffset = 1.0; |
| 40 | 43 |
| 41 // How long to wait for mouse-up on the location icon before assuming | 44 // How long to wait for mouse-up on the location icon before assuming |
| 42 // that the user wants to drag. | 45 // that the user wants to drag. |
| 43 const NSTimeInterval kLocationIconDragTimeout = 0.25; | 46 const NSTimeInterval kLocationIconDragTimeout = 0.25; |
| 44 | 47 |
| 45 // Calculate the positions for a set of decorations. |frame| is the | 48 // Calculate the positions for a set of decorations. |frame| is the |
| 46 // overall frame to do layout in, |remaining_frame| will get the | 49 // overall frame to do layout in, |remaining_frame| will get the |
| 47 // left-over space. |all_decorations| is the set of decorations to | 50 // left-over space. |all_decorations| is the set of decorations to |
| 48 // lay out, |decorations| will be set to the decorations which are | 51 // lay out, |decorations| will be set to the decorations which are |
| 49 // visible and which fit, in the same order as |all_decorations|, | 52 // visible and which fit, in the same order as |all_decorations|, |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 decorations[i]->DrawWithBackgroundInFrame(decorationFrames[i], | 391 decorations[i]->DrawWithBackgroundInFrame(decorationFrames[i], |
| 389 controlView); | 392 controlView); |
| 390 } | 393 } |
| 391 } | 394 } |
| 392 | 395 |
| 393 // NOTE: This function must closely match the logic in | 396 // NOTE: This function must closely match the logic in |
| 394 // |-textFrameForFrame:|. | 397 // |-textFrameForFrame:|. |
| 395 | 398 |
| 396 // Superclass draws text portion WRT original |cellFrame|. | 399 // Superclass draws text portion WRT original |cellFrame|. |
| 397 ui::ScopedCGContextSmoothFonts fontSmoothing; | 400 ui::ScopedCGContextSmoothFonts fontSmoothing; |
| 398 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 401 NSAttributedString* attrString = self.attributedStringValue; |
| 402 [attrString drawInRect:[self titleRectForBounds:cellFrame]]; |
| 403 } |
| 404 |
| 405 - (NSRect)titleRectForBounds:(NSRect)rect { |
| 406 NSRect titleRect = [super titleRectForBounds:rect]; |
| 407 titleRect.origin.x += kTitleFrameXOffset; |
| 408 titleRect.size.width -= kTitleFrameXOffset; |
| 409 return titleRect; |
| 399 } | 410 } |
| 400 | 411 |
| 401 - (BOOL)canDropAtLocationInWindow:(NSPoint)location | 412 - (BOOL)canDropAtLocationInWindow:(NSPoint)location |
| 402 ofView:(AutocompleteTextField*)controlView { | 413 ofView:(AutocompleteTextField*)controlView { |
| 403 NSRect cellFrame = [controlView bounds]; | 414 NSRect cellFrame = [controlView bounds]; |
| 404 const NSPoint locationInView = | 415 const NSPoint locationInView = |
| 405 [controlView convertPoint:location fromView:nil]; | 416 [controlView convertPoint:location fromView:nil]; |
| 406 | 417 |
| 407 // If we have decorations, the drop can't occur at their horizontal padding. | 418 // If we have decorations, the drop can't occur at their horizontal padding. |
| 408 if (!leftDecorations_.empty() && locationInView.x < kLeftDecorationXOffset) | 419 if (!leftDecorations_.empty() && locationInView.x < kLeftDecorationXOffset) |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 | 716 |
| 706 @end | 717 @end |
| 707 | 718 |
| 708 @implementation AutocompleteTextFieldCell (TestingAPI) | 719 @implementation AutocompleteTextFieldCell (TestingAPI) |
| 709 | 720 |
| 710 - (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations { | 721 - (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations { |
| 711 return mouseTrackingDecorations_; | 722 return mouseTrackingDecorations_; |
| 712 } | 723 } |
| 713 | 724 |
| 714 @end | 725 @end |
| OLD | NEW |