Chromium Code Reviews| Index: chrome/browser/ui/cocoa/location_bar/search_token_decoration.mm |
| diff --git a/chrome/browser/ui/cocoa/location_bar/search_token_decoration.mm b/chrome/browser/ui/cocoa/location_bar/search_token_decoration.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6478f85dc2b4b59ad18f6d9ecc9e726af13a354b |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/location_bar/search_token_decoration.mm |
| @@ -0,0 +1,38 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "chrome/browser/ui/cocoa/location_bar/search_token_decoration.h" |
| + |
| +#import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util_mac.h" |
| + |
| +SearchTokenDecoration::SearchTokenDecoration() { |
| +} |
| + |
| +SearchTokenDecoration::~SearchTokenDecoration() { |
| +} |
| + |
| +void SearchTokenDecoration::DrawInFrame(NSRect frame, NSView* control_view) { |
| + NSRect text_rect = NSInsetRect(frame, 0, 4); |
|
kuan
2013/01/23 17:01:32
why 4?
sail
2013/01/27 21:11:07
Done.
This is used to vertically center text. Each
|
| + [GetAttributedString() drawInRect:text_rect]; |
| +} |
| + |
| +CGFloat SearchTokenDecoration::GetWidthForSpace(CGFloat width) { |
| + CGFloat desired_width = [GetAttributedString() size].width; |
| + if (desired_width > width) |
| + return kOmittedWidth; |
| + return desired_width; |
|
kuan
2013/01/23 17:01:32
where do u handle the long query string scenario?
sail
2013/01/27 21:11:07
Done.
My original patch didn't have this functiona
|
| +} |
| + |
| +NSAttributedString* SearchTokenDecoration::GetAttributedString() const { |
| + NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: |
| + OmniboxViewMac::GetFieldFont(), NSFontAttributeName, |
| + [NSColor lightGrayColor], NSForegroundColorAttributeName, |
| + nil]; |
| + NSString* string = l10n_util::GetNSStringF(IDS_OMNIBOX_SEARCH_TOKEN_TEXT, |
| + search_provider_name_); |
| + return [[[NSAttributedString alloc] initWithString:string |
| + attributes:attributes] autorelease]; |
| +} |