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

Unified Diff: chrome/browser/cocoa/location_bar/selected_keyword_decoration.mm

Issue 2805070: [Mac] First part of Omnibox decoration refactor. Enable ev bubble. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: comment clarification Created 10 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/location_bar/selected_keyword_decoration.mm
diff --git a/chrome/browser/cocoa/location_bar/selected_keyword_decoration.mm b/chrome/browser/cocoa/location_bar/selected_keyword_decoration.mm
new file mode 100644
index 0000000000000000000000000000000000000000..ebb62bf83c5dc61f1581b7af1f3a7ec15e36d338
--- /dev/null
+++ b/chrome/browser/cocoa/location_bar/selected_keyword_decoration.mm
@@ -0,0 +1,67 @@
+// Copyright (c) 2010 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/cocoa/location_bar/selected_keyword_decoration.h"
+
+#include "app/l10n_util_mac.h"
+#include "base/utf_string_conversions.h"
+#import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
+#import "chrome/browser/cocoa/image_utils.h"
+#include "chrome/browser/location_bar_util.h"
+#include "grit/theme_resources.h"
+#include "grit/generated_resources.h"
+
+SelectedKeywordDecoration::SelectedKeywordDecoration(NSFont* font)
+ : BubbleDecoration(font) {
+ search_image_.reset(
+ [AutocompleteEditViewMac::ImageForResource(IDR_OMNIBOX_SEARCH) retain]);
+
+ // Matches the color of the highlighted line in the popup.
+ NSColor* background_color = [NSColor selectedControlColor];
+
+ // Match focus ring's inner color.
+ NSColor* border_color =
+ [[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5];
+ SetColors(border_color, background_color, [NSColor blackColor]);
+}
+
+CGFloat SelectedKeywordDecoration::GetWidthForSpace(CGFloat width) {
+ const CGFloat full_width =
+ GetWidthForImageAndLabel(search_image_, full_string_);
+ if (full_width <= width) {
+ SetImage(search_image_);
+ SetLabel(full_string_);
+ return full_width;
+ }
+
+ SetImage(nil);
+ const CGFloat no_image_width = GetWidthForImageAndLabel(nil, full_string_);
+ if (no_image_width <= width || !partial_string_) {
+ SetLabel(full_string_);
+ return no_image_width;
+ }
+
+ SetLabel(partial_string_);
+ return GetWidthForImageAndLabel(nil, partial_string_);
+}
+
+void SelectedKeywordDecoration::SetKeyword(const std::wstring& short_name,
+ bool is_extension_keyword) {
+ const std::wstring min_name(
+ location_bar_util::CalculateMinString(short_name));
+ const int message_id = is_extension_keyword ?
+ IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT;
+
+ // The text will be like "Search <name>:". "<name>" is a parameter
+ // derived from |short_name|.
+ full_string_.reset(
+ [l10n_util::GetNSStringF(message_id, WideToUTF16(short_name)) copy]);
+
+ if (min_name.empty()) {
+ partial_string_.reset();
+ } else {
+ partial_string_.reset(
+ [l10n_util::GetNSStringF(message_id, WideToUTF16(min_name)) copy]);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698