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

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

Issue 1608001: [Mac] Line up omnibox popup under field. (Closed)
Patch Set: Wordsmith and test fix. Created 10 years, 8 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_cell.h" 5 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "gfx/font.h" 9 #include "gfx/font.h"
10 10
(...skipping 27 matching lines...) Expand all
38 // The amount of padding on either side reserved for drawing an icon. 38 // The amount of padding on either side reserved for drawing an icon.
39 const NSInteger kIconHorizontalPad = 3; 39 const NSInteger kIconHorizontalPad = 3;
40 40
41 // How far to shift bounding box of hint icon label down from top of field. 41 // How far to shift bounding box of hint icon label down from top of field.
42 const NSInteger kIconLabelYOffset = 7; 42 const NSInteger kIconLabelYOffset = 7;
43 43
44 // How far the editor insets itself, for purposes of determining if 44 // How far the editor insets itself, for purposes of determining if
45 // decorations need to be trimmed. 45 // decorations need to be trimmed.
46 const CGFloat kEditorHorizontalInset = 3.0; 46 const CGFloat kEditorHorizontalInset = 3.0;
47 47
48 const CGFloat kLocationIconXOffset = 3.0; 48 // Cause the location icon to line up above the icons in the popup.
49 const CGFloat kLocationIconXOffset = 9.0;
50 const CGFloat kLocationIconXPad = 5.0;
49 51
50 // Conveniences to centralize width+offset calculations. 52 // Conveniences to centralize width+offset calculations.
51 CGFloat WidthForHint(NSAttributedString* hintString) { 53 CGFloat WidthForHint(NSAttributedString* hintString) {
52 return kHintXOffset + ceil([hintString size].width); 54 return kHintXOffset + ceil([hintString size].width);
53 } 55 }
54 CGFloat WidthForKeyword(NSAttributedString* keywordString) { 56 CGFloat WidthForKeyword(NSAttributedString* keywordString) {
55 return kKeywordXOffset + ceil([keywordString size].width) + 57 return kKeywordXOffset + ceil([keywordString size].width) +
56 2 * kKeywordTokenInset; 58 2 * kKeywordTokenInset;
57 } 59 }
58 60
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 283
282 // Overriden to account for the hint strings and hint icons. 284 // Overriden to account for the hint strings and hint icons.
283 - (NSRect)textFrameForFrame:(NSRect)cellFrame { 285 - (NSRect)textFrameForFrame:(NSRect)cellFrame {
284 NSRect textFrame([super textFrameForFrame:cellFrame]); 286 NSRect textFrame([super textFrameForFrame:cellFrame]);
285 287
286 // TODO(shess): Check the set of exclusions in |LocationBarViewMac|. 288 // TODO(shess): Check the set of exclusions in |LocationBarViewMac|.
287 // If |keywordString_| takes precedence over other cases, then this 289 // If |keywordString_| takes precedence over other cases, then this
288 // code could be made simpler. 290 // code could be made simpler.
289 if (!keywordString_ && locationIconView_ && locationIconView_->IsVisible()) { 291 if (!keywordString_ && locationIconView_ && locationIconView_->IsVisible()) {
290 const NSSize imageSize = locationIconView_->GetImageSize(); 292 const NSSize imageSize = locationIconView_->GetImageSize();
291 textFrame.origin.x += imageSize.width; 293 const CGFloat locationIconWidth =
292 textFrame.size.width -= imageSize.width; 294 kLocationIconXOffset + kLocationIconXPad + imageSize.width;
295 textFrame.origin.x += locationIconWidth;
296 textFrame.size.width -= locationIconWidth;
293 } 297 }
294 298
295 if (hintString_) { 299 if (hintString_) {
296 DCHECK(!keywordString_); 300 DCHECK(!keywordString_);
297 const CGFloat hintWidth(WidthForHint(hintString_)); 301 const CGFloat hintWidth(WidthForHint(hintString_));
298 302
299 // TODO(shess): This could be better. Show the hint until the 303 // TODO(shess): This could be better. Show the hint until the
300 // non-hint text bumps against it? 304 // non-hint text bumps against it?
301 if (hintWidth < NSWidth(textFrame)) { 305 if (hintWidth < NSWidth(textFrame)) {
302 textFrame.size.width -= hintWidth; 306 textFrame.size.width -= hintWidth;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 icon = [self iconForEvent:theEvent inRect:cellFrame ofView:controlView]; 526 icon = [self iconForEvent:theEvent inRect:cellFrame ofView:controlView];
523 if (icon) { 527 if (icon) {
524 [icon view]->OnMousePressed([icon rect]); 528 [icon view]->OnMousePressed([icon rect]);
525 return YES; 529 return YES;
526 } 530 }
527 531
528 return NO; 532 return NO;
529 } 533 }
530 534
531 @end 535 @end
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_popup_view_mac.mm ('k') | chrome/browser/cocoa/toolbar_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698