OLD | NEW |
1 // Copyright (c) 2010 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 #include <cmath> | 5 #include <cmath> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 7 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #import "chrome/browser/ui/cocoa/image_utils.h" | 12 #import "chrome/browser/ui/cocoa/image_utils.h" |
13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources_standard.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "skia/ext/skia_utils_mac.h" | 15 #include "skia/ext/skia_utils_mac.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // How far to inset the hint text area from sides. | 21 // How far to inset the hint text area from sides. |
22 const CGFloat kHintTextYInset = 4.0; | 22 const CGFloat kHintTextYInset = 4.0; |
23 | 23 |
(...skipping 26 matching lines...) Expand all Loading... |
50 text_color, NSForegroundColorAttributeName, | 50 text_color, NSForegroundColorAttributeName, |
51 nil]; | 51 nil]; |
52 attributes_.reset([attributes retain]); | 52 attributes_.reset([attributes retain]); |
53 } | 53 } |
54 | 54 |
55 KeywordHintDecoration::~KeywordHintDecoration() { | 55 KeywordHintDecoration::~KeywordHintDecoration() { |
56 } | 56 } |
57 | 57 |
58 NSImage* KeywordHintDecoration::GetHintImage() { | 58 NSImage* KeywordHintDecoration::GetHintImage() { |
59 if (!hint_image_) { | 59 if (!hint_image_) { |
60 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance(). | 60 hint_image_.reset([ResourceBundle::GetSharedInstance(). |
61 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); | 61 GetNativeImageNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB) retain]); |
62 if (skiaBitmap) | |
63 hint_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]); | |
64 } | 62 } |
65 return hint_image_; | 63 return hint_image_; |
66 } | 64 } |
67 | 65 |
68 void KeywordHintDecoration::SetKeyword(const string16& short_name, | 66 void KeywordHintDecoration::SetKeyword(const string16& short_name, |
69 bool is_extension_keyword) { | 67 bool is_extension_keyword) { |
70 // KEYWORD_HINT is a message like "Press [tab] to search <site>". | 68 // KEYWORD_HINT is a message like "Press [tab] to search <site>". |
71 // [tab] is a parameter to be replaced by an image. "<site>" is | 69 // [tab] is a parameter to be replaced by an image. "<site>" is |
72 // derived from |short_name|. | 70 // derived from |short_name|. |
73 std::vector<size_t> content_param_offsets; | 71 std::vector<size_t> content_param_offsets; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 [hint_suffix_ sizeWithAttributes:attributes_].width; | 149 [hint_suffix_ sizeWithAttributes:attributes_].width; |
152 | 150 |
153 // Right-justify the text within the remaining space, so it | 151 // Right-justify the text within the remaining space, so it |
154 // doesn't get too close to the image relative to a following | 152 // doesn't get too close to the image relative to a following |
155 // decoration. | 153 // decoration. |
156 suffix_rect.origin.x = NSMaxX(suffix_rect) - suffix_width; | 154 suffix_rect.origin.x = NSMaxX(suffix_rect) - suffix_width; |
157 DCHECK_GE(NSWidth(suffix_rect), suffix_width); | 155 DCHECK_GE(NSWidth(suffix_rect), suffix_width); |
158 [hint_suffix_ drawInRect:suffix_rect withAttributes:attributes_]; | 156 [hint_suffix_ drawInRect:suffix_rect withAttributes:attributes_]; |
159 } | 157 } |
160 } | 158 } |
OLD | NEW |